src/js/libs/popcorn.mediafragment.js
branchpopcorn-port
changeset 263 2d87a07fa3d0
parent 216 d1e891627286
equal deleted inserted replaced
262:dfac630f82db 263:2d87a07fa3d0
     2 
     2 
     3 (function ( Popcorn ) {
     3 (function ( Popcorn ) {
     4 
     4 
     5   /**
     5   /**
     6    * Mediafragment popcorn plug-in
     6    * Mediafragment popcorn plug-in
     7    * Adds (limited) support for mediafragment requests 
     7    * Adds (limited) support for mediafragment requests
     8    * to a popcorn video.  
     8    * to a popcorn video.
     9    * @param {Object} options
     9    * @param {Object} options
    10    *
    10    *
    11   **/
    11   **/
    12     Popcorn.plugin( "mediafragment" , {
    12     Popcorn.plugin( "mediafragment" , {
    13 
    13 
    19           website: "http://neyret.fr/~karim"
    19           website: "http://neyret.fr/~karim"
    20         },
    20         },
    21         options: {
    21         options: {
    22         }
    22         }
    23       },
    23       },
    24       
    24 
    25     _setup: function( options ) {
    25     _setup: function( options ) {
    26         var advanceTime = function() {
    26         var advanceTime = function() {
    27               var url = window.location.href;
    27               var url = window.location.href;
    28               
    28 
    29               if ( url.split("#")[1] != null ) {
    29               if ( url.split( "#" )[ 1 ] != null ) {
    30                   pageoffset = url.split( "#" )[1];							
    30                   pageoffset = url.split( "#" )[1];
    31                   
    31 
    32                   if ( pageoffset.substring( 2 ) != null ) {
    32                   if ( pageoffset.substring( 2 ) != null ) {
    33                     var offsettime = pageoffset.substring( 2 );						
    33                     var offsettime = pageoffset.substring( 2 );
    34                     this.currentTime(parseFloat(offsettime));
    34                     this.currentTime( parseFloat( offsettime ) );
    35                   }							
    35                   }
    36               }
    36               }
    37         }
    37         }
    38         
    38 
    39         var updateTime = function() {
    39         var updateTime = function() {
    40             splitArr = window.location.href.split("#")			
    40             var history = window.history;
    41             history.replaceState({}, "", splitArr[0] + "#t=" + this.currentTime().toFixed(2));
    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 ) );
    42         };
    47         };
    43         
    48 
    44         this.listen( 'loadedmetadata', advanceTime );        
    49         this.listen( "loadedmetadata", advanceTime );
    45         this.listen("pause", updateTime);
    50         this.listen( "pause", updateTime );
    46         this.listen("seeked", updateTime);
    51         this.listen( "seeked", updateTime );
    47         
       
    48     },
    52     },
    49 
    53 
    50     _teardown: function( options ) {
    54     _teardown: function( options ) {
    51       // FIXME: anything to implement here ?
    55       // FIXME: anything to implement here ?
    52     }
    56     }