src/js/libs/popcorn.mediafragment.js
author hamidouk
Wed, 21 Dec 2011 11:22:47 +0100
branchlab-port
changeset 495 41a9f7b27952
parent 263 2d87a07fa3d0
permissions -rw-r--r--
added lab js source file.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
     1
// PLUGIN: Mediafragment
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
     2
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
     3
(function ( Popcorn ) {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
     4
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
     5
  /**
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
     6
   * Mediafragment popcorn plug-in
263
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
     7
   * Adds (limited) support for mediafragment requests
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
     8
   * to a popcorn video.
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
     9
   * @param {Object} options
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    10
   *
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    11
  **/
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    12
    Popcorn.plugin( "mediafragment" , {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    13
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    14
      manifest: {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    15
        about: {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    16
          name: "Popcorn mediafragment plugin",
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    17
          version: "0.1",
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    18
          author: "Karim Hamidou",
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    19
          website: "http://neyret.fr/~karim"
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    20
        },
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    21
        options: {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    22
        }
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    23
      },
263
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    24
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    25
    _setup: function( options ) {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    26
        var advanceTime = function() {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    27
              var url = window.location.href;
263
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    28
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    29
              if ( url.split( "#" )[ 1 ] != null ) {
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    30
                  pageoffset = url.split( "#" )[1];
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    31
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    32
                  if ( pageoffset.substring( 2 ) != null ) {
263
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    33
                    var offsettime = pageoffset.substring( 2 );
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    34
                    this.currentTime( parseFloat( offsettime ) );
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    35
                  }
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    36
              }
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    37
        }
263
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    38
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    39
        var updateTime = function() {
263
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    40
            var history = window.history;
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    41
            if ( !history.pushState ) {
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    42
              return false;
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    43
            }
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    44
            
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    45
            splitArr = window.location.href.split( "#" )
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    46
            history.replaceState( {}, "", splitArr[0] + "#t=" + this.currentTime().toFixed( 2 ) );
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    47
        };
263
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    48
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    49
        this.listen( "loadedmetadata", advanceTime );
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    50
        this.listen( "pause", updateTime );
2d87a07fa3d0 bumped plugin version to support non-html5 browsers.
hamidouk
parents: 216
diff changeset
    51
        this.listen( "seeked", updateTime );
216
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    52
    },
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    53
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    54
    _teardown: function( options ) {
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    55
      // FIXME: anything to implement here ?
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    56
    }
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    57
  });
d1e891627286 added and activated the mediafragment plugin?
hamidouk
parents:
diff changeset
    58
})( Popcorn );