src/js/libs/popcorn.mediafragment.js
branchlab-port
changeset 500 a784e70993b3
parent 499 0a09ff3db7c2
child 501 63e7b66d2a80
equal deleted inserted replaced
499:0a09ff3db7c2 500:a784e70993b3
     1 // PLUGIN: Mediafragment
       
     2 
       
     3 (function ( Popcorn ) {
       
     4 
       
     5   /**
       
     6    * Mediafragment popcorn plug-in
       
     7    * Adds (limited) support for mediafragment requests
       
     8    * to a popcorn video.
       
     9    * @param {Object} options
       
    10    *
       
    11   **/
       
    12     Popcorn.plugin( "mediafragment" , {
       
    13 
       
    14       manifest: {
       
    15         about: {
       
    16           name: "Popcorn mediafragment plugin",
       
    17           version: "0.1",
       
    18           author: "Karim Hamidou",
       
    19           website: "http://neyret.fr/~karim"
       
    20         },
       
    21         options: {
       
    22         }
       
    23       },
       
    24 
       
    25     _setup: function( options ) {
       
    26         var advanceTime = function() {
       
    27               var url = window.location.href;
       
    28 
       
    29               if ( url.split( "#" )[ 1 ] != null ) {
       
    30                   pageoffset = url.split( "#" )[1];
       
    31 
       
    32                   if ( pageoffset.substring( 2 ) != null ) {
       
    33                     var offsettime = pageoffset.substring( 2 );
       
    34                     this.currentTime( parseFloat( offsettime ) );
       
    35                   }
       
    36               }
       
    37         }
       
    38 
       
    39         var updateTime = function() {
       
    40             var history = window.history;
       
    41             if ( !history.pushState ) {
       
    42               return false;
       
    43             }
       
    44             
       
    45             splitArr = window.location.href.split( "#" )
       
    46             history.replaceState( {}, "", splitArr[0] + "#t=" + this.currentTime().toFixed( 2 ) );
       
    47         };
       
    48 
       
    49         this.listen( "loadedmetadata", advanceTime );
       
    50         this.listen( "pause", updateTime );
       
    51         this.listen( "seeked", updateTime );
       
    52     },
       
    53 
       
    54     _teardown: function( options ) {
       
    55       // FIXME: anything to implement here ?
       
    56     }
       
    57   });
       
    58 })( Popcorn );