src/js/libs/popcorn.mediafragment.js
branchpopcorn-port
changeset 216 d1e891627286
child 263 2d87a07fa3d0
equal deleted inserted replaced
215:e03f5f886f52 216:d1e891627286
       
     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             splitArr = window.location.href.split("#")			
       
    41             history.replaceState({}, "", splitArr[0] + "#t=" + this.currentTime().toFixed(2));
       
    42         };
       
    43         
       
    44         this.listen( 'loadedmetadata', advanceTime );        
       
    45         this.listen("pause", updateTime);
       
    46         this.listen("seeked", updateTime);
       
    47         
       
    48     },
       
    49 
       
    50     _teardown: function( options ) {
       
    51       // FIXME: anything to implement here ?
       
    52     }
       
    53   });
       
    54 })( Popcorn );