test/integration/allocine_dossier_independant/js/libs/popcorn.js
author cavaliet
Thu, 26 Apr 2012 12:09:56 +0200
changeset 878 c983360f0e7a
parent 819 9b8e68803f6f
permissions -rw-r--r--
SlideShareWidget better management of container.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     1
(function(global, document) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     2
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     3
  // Popcorn.js does not support archaic browsers
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     4
  if ( !document.addEventListener ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     5
    global.Popcorn = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     6
      isSupported: false
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     7
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     8
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
     9
    var methods = ( "forEach extend effects error guid sizeOf isArray nop position disable enable destroy " +
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    10
          "addTrackEvent removeTrackEvent getTrackEvents getTrackEvent getLastTrackEventId " +
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    11
          "timeUpdate plugin removePlugin compose effect parser xhr getJSONP getScript" ).split(/\s+/);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    12
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    13
    while ( methods.length ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    14
      global.Popcorn[ methods.shift() ] = function() {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    15
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    16
    return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    17
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    18
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    19
  var
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    20
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    21
  AP = Array.prototype,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    22
  OP = Object.prototype,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    23
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    24
  forEach = AP.forEach,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    25
  slice = AP.slice,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    26
  hasOwn = OP.hasOwnProperty,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    27
  toString = OP.toString,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    28
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    29
  // Copy global Popcorn (may not exist)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    30
  _Popcorn = global.Popcorn,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    31
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    32
  //  ID string matching
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    33
  rIdExp  = /^(#([\w\-\_\.]+))$/,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    34
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    35
  //  Ready fn cache
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    36
  readyStack = [],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    37
  readyBound = false,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    38
  readyFired = false,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    39
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    40
  //  Non-public internal data object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    41
  internal = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    42
    events: {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    43
      hash: {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    44
      apis: {}
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    45
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    46
  },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    47
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    48
  //  Non-public `requestAnimFrame`
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    49
  //  http://paulirish.com/2011/requestanimationframe-for-smart-animating/
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    50
  requestAnimFrame = (function(){
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    51
    return global.requestAnimationFrame ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    52
      global.webkitRequestAnimationFrame ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    53
      global.mozRequestAnimationFrame ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    54
      global.oRequestAnimationFrame ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    55
      global.msRequestAnimationFrame ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    56
      function( callback, element ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    57
        global.setTimeout( callback, 16 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    58
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    59
  }()),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    60
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    61
  refresh = function( obj ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    62
    var currentTime = obj.media.currentTime,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    63
      animation = obj.options.frameAnimation,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    64
      disabled = obj.data.disabled,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    65
      tracks = obj.data.trackEvents,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    66
      animating = tracks.animating,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    67
      start = tracks.startIndex,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    68
      registryByName = Popcorn.registryByName,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    69
      animIndex = 0,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    70
      byStart, natives, type;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    71
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    72
    start = Math.min( start + 1, tracks.byStart.length - 2 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    73
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    74
    while ( start > 0 && tracks.byStart[ start ] ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    75
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    76
      byStart = tracks.byStart[ start ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    77
      natives = byStart._natives;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    78
      type = natives && natives.type;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    79
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    80
      if ( !natives ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    81
          ( !!registryByName[ type ] || !!obj[ type ] ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    82
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    83
        if ( ( byStart.start <= currentTime && byStart.end > currentTime ) &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    84
                disabled.indexOf( type ) === -1 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    85
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    86
          if ( !byStart._running ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    87
            byStart._running = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    88
            natives.start.call( obj, null, byStart );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    89
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    90
            // if the 'frameAnimation' option is used,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    91
            // push the current byStart object into the `animating` cue
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    92
            if ( animation &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    93
                ( byStart && byStart._running && byStart.natives.frame ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    94
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    95
              natives.frame.call( obj, null, byStart, currentTime );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    96
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    97
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    98
        } else if ( byStart._running === true ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
    99
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   100
          byStart._running = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   101
          natives.end.call( obj, null, byStart );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   102
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   103
          if ( animation && byStart._natives.frame ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   104
            animIndex = animating.indexOf( byStart );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   105
            if ( animIndex >= 0 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   106
              animating.splice( animIndex, 1 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   107
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   108
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   109
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   110
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   111
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   112
      start--;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   113
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   114
  },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   115
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   116
  //  Declare constructor
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   117
  //  Returns an instance object.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   118
  Popcorn = function( entity, options ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   119
    //  Return new Popcorn object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   120
    return new Popcorn.p.init( entity, options || null );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   121
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   122
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   123
  //  Popcorn API version, automatically inserted via build system.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   124
  Popcorn.version = "@VERSION";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   125
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   126
  //  Boolean flag allowing a client to determine if Popcorn can be supported
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   127
  Popcorn.isSupported = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   128
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   129
  //  Instance caching
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   130
  Popcorn.instances = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   131
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   132
  //  Declare a shortcut (Popcorn.p) to and a definition of
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   133
  //  the new prototype for our Popcorn constructor
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   134
  Popcorn.p = Popcorn.prototype = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   135
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   136
    init: function( entity, options ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   137
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   138
      var matches;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   139
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   140
      //  Supports Popcorn(function () { /../ })
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   141
      //  Originally proposed by Daniel Brooks
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   142
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   143
      if ( typeof entity === "function" ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   144
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   145
        //  If document ready has already fired
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   146
        if ( document.readyState === "interactive" || document.readyState === "complete" ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   147
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   148
          entity( document, Popcorn );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   149
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   150
          return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   151
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   152
        //  Add `entity` fn to ready stack
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   153
        readyStack.push( entity );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   154
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   155
        //  This process should happen once per page load
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   156
        if ( !readyBound ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   157
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   158
          //  set readyBound flag
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   159
          readyBound = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   160
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   161
          var DOMContentLoaded  = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   162
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   163
            readyFired = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   164
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   165
            //  Remove global DOM ready listener
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   166
            document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   167
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   168
            //  Execute all ready function in the stack
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   169
            for ( var i = 0, readyStackLength = readyStack.length; i < readyStackLength; i++ ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   170
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   171
              readyStack[ i ].call( document, Popcorn );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   172
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   173
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   174
            //  GC readyStack
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   175
            readyStack = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   176
          };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   177
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   178
          //  Register global DOM ready listener
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   179
          document.addEventListener( "DOMContentLoaded", DOMContentLoaded, false );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   180
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   181
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   182
        return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   183
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   184
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   185
      //  Check if entity is a valid string id
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   186
      matches = rIdExp.exec( entity );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   187
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   188
      //  Get media element by id or object reference
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   189
      this.media = matches && matches.length && matches[ 2 ] ?
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   190
                     document.getElementById( matches[ 2 ] ) :
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   191
                     entity;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   192
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   193
      //  Create an audio or video element property reference
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   194
      this[ ( this.media.nodeName && this.media.nodeName.toLowerCase() ) || "video" ] = this.media;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   195
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   196
      //  Register new instance
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   197
      Popcorn.instances.push( this );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   198
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   199
      this.options = options || {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   200
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   201
      this.isDestroyed = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   202
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   203
      this.data = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   204
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   205
        // Executed by either timeupdate event or in rAF loop
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   206
        timeUpdate: Popcorn.nop,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   207
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   208
        // Allows disabling a plugin per instance
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   209
        disabled: [],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   210
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   211
        // Stores DOM event queues by type
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   212
        events: {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   213
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   214
        // Stores Special event hooks data
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   215
        hooks: {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   216
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   217
        // Store track event history data
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   218
        history: [],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   219
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   220
        // Stores ad-hoc state related data]
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   221
        state: {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   222
          volume: this.media.volume
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   223
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   224
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   225
        // Store track event object references by trackId
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   226
        trackRefs: {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   227
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   228
        // Playback track event queues
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   229
        trackEvents: {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   230
          byStart: [{
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   231
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   232
            start: -1,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   233
            end: -1
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   234
          }],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   235
          byEnd: [{
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   236
            start: -1,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   237
            end: -1
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   238
          }],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   239
          animating: [],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   240
          startIndex: 0,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   241
          endIndex: 0,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   242
          previousUpdateTime: -1
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   243
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   244
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   245
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   246
      //  Wrap true ready check
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   247
      var isReady = function( that ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   248
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   249
        var duration, videoDurationPlus;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   250
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   251
        if ( that.media.readyState >= 2 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   252
          //  Adding padding to the front and end of the arrays
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   253
          //  this is so we do not fall off either end
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   254
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   255
          duration = that.media.duration;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   256
          //  Check for no duration info (NaN)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   257
          videoDurationPlus = duration != duration ? Number.MAX_VALUE : duration + 1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   258
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   259
          Popcorn.addTrackEvent( that, {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   260
            start: videoDurationPlus,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   261
            end: videoDurationPlus
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   262
          });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   263
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   264
          if ( that.options.frameAnimation ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   265
            //  if Popcorn is created with frameAnimation option set to true,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   266
            //  requestAnimFrame is used instead of "timeupdate" media event.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   267
            //  This is for greater frame time accuracy, theoretically up to
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   268
            //  60 frames per second as opposed to ~4 ( ~every 15-250ms)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   269
            that.data.timeUpdate = function () {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   270
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   271
              Popcorn.timeUpdate( that, {} );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   272
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   273
              that.trigger( "timeupdate" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   274
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   275
              !that.isDestroyed && requestAnimFrame( that.data.timeUpdate );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   276
            };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   277
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   278
            !that.isDestroyed && requestAnimFrame( that.data.timeUpdate );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   279
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   280
          } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   281
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   282
            that.data.timeUpdate = function( event ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   283
              Popcorn.timeUpdate( that, event );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   284
            };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   285
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   286
            if ( !that.isDestroyed ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   287
              that.media.addEventListener( "timeupdate", that.data.timeUpdate, false );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   288
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   289
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   290
        } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   291
          global.setTimeout(function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   292
            isReady( that );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   293
          }, 1 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   294
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   295
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   296
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   297
      isReady( this );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   298
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   299
      return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   300
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   301
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   302
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   303
  //  Extend constructor prototype to instance prototype
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   304
  //  Allows chaining methods to instances
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   305
  Popcorn.p.init.prototype = Popcorn.p;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   306
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   307
  Popcorn.forEach = function( obj, fn, context ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   308
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   309
    if ( !obj || !fn ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   310
      return {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   311
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   312
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   313
    context = context || this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   314
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   315
    var key, len;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   316
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   317
    // Use native whenever possible
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   318
    if ( forEach && obj.forEach === forEach ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   319
      return obj.forEach( fn, context );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   320
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   321
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   322
    if ( toString.call( obj ) === "[object NodeList]" ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   323
      for ( key = 0, len = obj.length; key < len; key++ ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   324
        fn.call( context, obj[ key ], key, obj );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   325
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   326
      return obj;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   327
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   328
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   329
    for ( key in obj ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   330
      if ( hasOwn.call( obj, key ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   331
        fn.call( context, obj[ key ], key, obj );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   332
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   333
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   334
    return obj;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   335
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   336
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   337
  Popcorn.extend = function( obj ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   338
    var dest = obj, src = slice.call( arguments, 1 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   339
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   340
    Popcorn.forEach( src, function( copy ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   341
      for ( var prop in copy ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   342
        dest[ prop ] = copy[ prop ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   343
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   344
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   345
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   346
    return dest;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   347
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   348
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   349
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   350
  // A Few reusable utils, memoized onto Popcorn
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   351
  Popcorn.extend( Popcorn, {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   352
    noConflict: function( deep ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   353
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   354
      if ( deep ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   355
        global.Popcorn = _Popcorn;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   356
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   357
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   358
      return Popcorn;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   359
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   360
    error: function( msg ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   361
      throw new Error( msg );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   362
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   363
    guid: function( prefix ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   364
      Popcorn.guid.counter++;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   365
      return  ( prefix ? prefix : "" ) + ( +new Date() + Popcorn.guid.counter );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   366
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   367
    sizeOf: function( obj ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   368
      var size = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   369
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   370
      for ( var prop in obj ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   371
        size++;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   372
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   373
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   374
      return size;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   375
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   376
    isArray: Array.isArray || function( array ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   377
      return toString.call( array ) === "[object Array]";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   378
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   379
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   380
    nop: function() {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   381
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   382
    position: function( elem ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   383
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   384
      var clientRect = elem.getBoundingClientRect(),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   385
          bounds = {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   386
          doc = elem.ownerDocument,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   387
          docElem = document.documentElement,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   388
          body = document.body,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   389
          clientTop, clientLeft, scrollTop, scrollLeft, top, left;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   390
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   391
      //  Determine correct clientTop/Left
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   392
      clientTop = docElem.clientTop || body.clientTop || 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   393
      clientLeft = docElem.clientLeft || body.clientLeft || 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   394
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   395
      //  Determine correct scrollTop/Left
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   396
      scrollTop = ( global.pageYOffset && docElem.scrollTop || body.scrollTop );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   397
      scrollLeft = ( global.pageXOffset && docElem.scrollLeft || body.scrollLeft );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   398
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   399
      //  Temp top/left
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   400
      top = Math.ceil( clientRect.top + scrollTop - clientTop );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   401
      left = Math.ceil( clientRect.left + scrollLeft - clientLeft );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   402
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   403
      for ( var p in clientRect ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   404
        bounds[ p ] = Math.round( clientRect[ p ] );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   405
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   406
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   407
      return Popcorn.extend({}, bounds, { top: top, left: left });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   408
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   409
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   410
    disable: function( instance, plugin ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   411
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   412
      var disabled = instance.data.disabled;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   413
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   414
      if ( disabled.indexOf( plugin ) === -1 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   415
        disabled.push( plugin );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   416
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   417
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   418
      refresh( instance );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   419
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   420
      return instance;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   421
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   422
    enable: function( instance, plugin ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   423
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   424
      var disabled = instance.data.disabled,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   425
          index = disabled.indexOf( plugin );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   426
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   427
      if ( index > -1 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   428
        disabled.splice( index, 1 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   429
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   430
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   431
      refresh( instance );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   432
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   433
      return instance;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   434
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   435
    destroy: function( instance ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   436
      var events = instance.data.events,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   437
          singleEvent, item, fn;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   438
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   439
      //  Iterate through all events and remove them
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   440
      for ( item in events ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   441
        singleEvent = events[ item ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   442
        for ( fn in singleEvent ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   443
          delete singleEvent[ fn ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   444
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   445
        events[ item ] = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   446
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   447
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   448
      if ( !instance.isDestroyed ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   449
        instance.data.timeUpdate && instance.media.removeEventListener( "timeupdate", instance.data.timeUpdate, false );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   450
        instance.isDestroyed = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   451
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   452
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   453
  });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   454
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   455
  //  Memoized GUID Counter
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   456
  Popcorn.guid.counter = 1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   457
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   458
  //  Factory to implement getters, setters and controllers
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   459
  //  as Popcorn instance methods. The IIFE will create and return
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   460
  //  an object with defined methods
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   461
  Popcorn.extend(Popcorn.p, (function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   462
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   463
      var methods = "load play pause currentTime playbackRate volume duration preload playbackRate " +
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   464
                    "autoplay loop controls muted buffered readyState seeking paused played seekable ended",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   465
          ret = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   466
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   467
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   468
      //  Build methods, store in object that is returned and passed to extend
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   469
      Popcorn.forEach( methods.split( /\s+/g ), function( name ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   470
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   471
        ret[ name ] = function( arg ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   472
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   473
          if ( typeof this.media[ name ] === "function" ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   474
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   475
            // Support for shorthanded play(n)/pause(n) jump to currentTime
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   476
            // If arg is not null or undefined and called by one of the
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   477
            // allowed shorthandable methods, then set the currentTime
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   478
            // Supports time as seconds or SMPTE
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   479
            if ( arg != null && /play|pause/.test( name ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   480
              this.media.currentTime = Popcorn.util.toSeconds( arg );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   481
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   482
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   483
            this.media[ name ]();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   484
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   485
            return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   486
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   487
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   488
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   489
          if ( arg != null ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   490
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   491
            this.media[ name ] = arg;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   492
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   493
            return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   494
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   495
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   496
          return this.media[ name ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   497
        };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   498
      });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   499
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   500
      return ret;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   501
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   502
    })()
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   503
  );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   504
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   505
  Popcorn.forEach( "enable disable".split(" "), function( method ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   506
    Popcorn.p[ method ] = function( plugin ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   507
      return Popcorn[ method ]( this, plugin );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   508
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   509
  });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   510
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   511
  Popcorn.extend(Popcorn.p, {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   512
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   513
    //  Rounded currentTime
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   514
    roundTime: function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   515
      return -~this.media.currentTime;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   516
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   517
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   518
    //  Attach an event to a single point in time
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   519
    exec: function( time, fn ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   520
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   521
      //  Creating a one second track event with an empty end
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   522
      Popcorn.addTrackEvent( this, {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   523
        start: time,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   524
        end: time + 1,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   525
        _running: false,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   526
        _natives: {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   527
          start: fn || Popcorn.nop,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   528
          end: Popcorn.nop,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   529
          type: "exec"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   530
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   531
      });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   532
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   533
      return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   534
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   535
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   536
    // Mute the calling media, optionally toggle
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   537
    mute: function( toggle ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   538
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   539
      var event = toggle == null || toggle === true ? "muted" : "unmuted";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   540
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   541
      // If `toggle` is explicitly `false`,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   542
      // unmute the media and restore the volume level
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   543
      if ( event === "unmuted" ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   544
        this.media.muted = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   545
        this.media.volume = this.data.state.volume;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   546
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   547
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   548
      // If `toggle` is either null or undefined,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   549
      // save the current volume and mute the media element
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   550
      if ( event === "muted" ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   551
        this.data.state.volume = this.media.volume;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   552
        this.media.muted = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   553
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   554
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   555
      // Trigger either muted|unmuted event
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   556
      this.trigger( event );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   557
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   558
      return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   559
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   560
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   561
    // Convenience method, unmute the calling media
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   562
    unmute: function( toggle ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   563
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   564
      return this.mute( toggle == null ? false : !toggle );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   565
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   566
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   567
    // Get the client bounding box of an instance element
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   568
    position: function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   569
      return Popcorn.position( this.media );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   570
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   571
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   572
    // Toggle a plugin's playback behaviour (on or off) per instance
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   573
    toggle: function( plugin ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   574
      return Popcorn[ this.data.disabled.indexOf( plugin ) > -1 ? "enable" : "disable" ]( this, plugin );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   575
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   576
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   577
    // Set default values for plugin options objects per instance
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   578
    defaults: function( plugin, defaults ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   579
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   580
      // If an array of default configurations is provided,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   581
      // iterate and apply each to this instance
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   582
      if ( Popcorn.isArray( plugin ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   583
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   584
        Popcorn.forEach( plugin, function( obj ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   585
          for ( var name in obj ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   586
            this.defaults( name, obj[ name ] );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   587
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   588
        }, this );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   589
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   590
        return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   591
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   592
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   593
      if ( !this.options.defaults ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   594
        this.options.defaults = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   595
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   596
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   597
      if ( !this.options.defaults[ plugin ] ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   598
        this.options.defaults[ plugin ] = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   599
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   600
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   601
      Popcorn.extend( this.options.defaults[ plugin ], defaults );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   602
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   603
      return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   604
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   605
  });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   606
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   607
  Popcorn.Events  = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   608
    UIEvents: "blur focus focusin focusout load resize scroll unload",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   609
    MouseEvents: "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave click dblclick",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   610
    Events: "loadstart progress suspend emptied stalled play pause " +
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   611
            "loadedmetadata loadeddata waiting playing canplay canplaythrough " +
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   612
            "seeking seeked timeupdate ended ratechange durationchange volumechange"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   613
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   614
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   615
  Popcorn.Events.Natives = Popcorn.Events.UIEvents + " " +
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   616
                           Popcorn.Events.MouseEvents + " " +
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   617
                           Popcorn.Events.Events;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   618
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   619
  internal.events.apiTypes = [ "UIEvents", "MouseEvents", "Events" ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   620
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   621
  // Privately compile events table at load time
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   622
  (function( events, data ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   623
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   624
    var apis = internal.events.apiTypes,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   625
    eventsList = events.Natives.split( /\s+/g ),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   626
    idx = 0, len = eventsList.length, prop;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   627
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   628
    for( ; idx < len; idx++ ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   629
      data.hash[ eventsList[idx] ] = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   630
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   631
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   632
    apis.forEach(function( val, idx ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   633
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   634
      data.apis[ val ] = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   635
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   636
      var apiEvents = events[ val ].split( /\s+/g ),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   637
      len = apiEvents.length,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   638
      k = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   639
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   640
      for ( ; k < len; k++ ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   641
        data.apis[ val ][ apiEvents[ k ] ] = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   642
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   643
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   644
  })( Popcorn.Events, internal.events );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   645
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   646
  Popcorn.events = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   647
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   648
    isNative: function( type ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   649
      return !!internal.events.hash[ type ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   650
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   651
    getInterface: function( type ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   652
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   653
      if ( !Popcorn.events.isNative( type ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   654
        return false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   655
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   656
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   657
      var eventApi = internal.events,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   658
        apis = eventApi.apiTypes,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   659
        apihash = eventApi.apis,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   660
        idx = 0, len = apis.length, api, tmp;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   661
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   662
      for ( ; idx < len; idx++ ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   663
        tmp = apis[ idx ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   664
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   665
        if ( apihash[ tmp ][ type ] ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   666
          api = tmp;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   667
          break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   668
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   669
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   670
      return api;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   671
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   672
    //  Compile all native events to single array
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   673
    all: Popcorn.Events.Natives.split( /\s+/g ),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   674
    //  Defines all Event handling static functions
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   675
    fn: {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   676
      trigger: function( type, data ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   677
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   678
        var eventInterface, evt;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   679
        //  setup checks for custom event system
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   680
        if ( this.data.events[ type ] && Popcorn.sizeOf( this.data.events[ type ] ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   681
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   682
          eventInterface  = Popcorn.events.getInterface( type );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   683
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   684
          if ( eventInterface ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   685
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   686
            evt = document.createEvent( eventInterface );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   687
            evt.initEvent( type, true, true, global, 1 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   688
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   689
            this.media.dispatchEvent( evt );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   690
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   691
            return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   692
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   693
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   694
          //  Custom events
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   695
          Popcorn.forEach( this.data.events[ type ], function( obj, key ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   696
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   697
            obj.call( this, data );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   698
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   699
          }, this );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   700
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   701
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   702
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   703
        return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   704
      },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   705
      listen: function( type, fn ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   706
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   707
        var self = this,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   708
            hasEvents = true,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   709
            eventHook = Popcorn.events.hooks[ type ],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   710
            origType = type,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   711
            tmp;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   712
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   713
        if ( !this.data.events[ type ] ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   714
          this.data.events[ type ] = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   715
          hasEvents = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   716
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   717
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   718
        // Check and setup event hooks
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   719
        if ( eventHook ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   720
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   721
          // Execute hook add method if defined
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   722
          if ( eventHook.add ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   723
            eventHook.add.call( this, {}, fn );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   724
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   725
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   726
          // Reassign event type to our piggyback event type if defined
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   727
          if ( eventHook.bind ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   728
            type = eventHook.bind;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   729
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   730
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   731
          // Reassign handler if defined
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   732
          if ( eventHook.handler ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   733
            tmp = fn;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   734
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   735
            fn = function wrapper( event ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   736
              eventHook.handler.call( self, event, tmp );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   737
            };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   738
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   739
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   740
          // assume the piggy back event is registered
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   741
          hasEvents = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   742
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   743
          // Setup event registry entry
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   744
          if ( !this.data.events[ type ] ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   745
            this.data.events[ type ] = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   746
            // Toggle if the previous assumption was untrue
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   747
            hasEvents = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   748
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   749
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   750
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   751
        //  Register event and handler
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   752
        this.data.events[ type ][ fn.name || ( fn.toString() + Popcorn.guid() ) ] = fn;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   753
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   754
        // only attach one event of any type
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   755
        if ( !hasEvents && Popcorn.events.all.indexOf( type ) > -1 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   756
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   757
          this.media.addEventListener( type, function( event ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   758
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   759
            Popcorn.forEach( self.data.events[ type ], function( obj, key ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   760
              if ( typeof obj === "function" ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   761
                obj.call( self, event );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   762
              }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   763
            });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   764
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   765
          }, false);
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   766
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   767
        return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   768
      },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   769
      unlisten: function( type, fn ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   770
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   771
        if ( this.data.events[ type ] && this.data.events[ type ][ fn ] ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   772
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   773
          delete this.data.events[ type ][ fn ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   774
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   775
          return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   776
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   777
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   778
        this.data.events[ type ] = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   779
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   780
        return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   781
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   782
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   783
    hooks: {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   784
      canplayall: {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   785
        bind: "canplaythrough",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   786
        add: function( event, callback ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   787
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   788
          var state = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   789
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   790
          if ( this.media.readyState ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   791
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   792
            callback.call( this, event );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   793
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   794
            state = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   795
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   796
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   797
          this.data.hooks.canplayall = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   798
            fired: state
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   799
          };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   800
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   801
        // declare special handling instructions
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   802
        handler: function canplayall( event, callback ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   803
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   804
          if ( !this.data.hooks.canplayall.fired ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   805
            // trigger original user callback once
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   806
            callback.call( this, event );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   807
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   808
            this.data.hooks.canplayall.fired = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   809
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   810
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   811
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   812
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   813
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   814
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   815
  //  Extend Popcorn.events.fns (listen, unlisten, trigger) to all Popcorn instances
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   816
  Popcorn.forEach( [ "trigger", "listen", "unlisten" ], function( key ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   817
    Popcorn.p[ key ] = Popcorn.events.fn[ key ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   818
  });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   820
  // Internal Only - Adds track events to the instance object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   821
  Popcorn.addTrackEvent = function( obj, track ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   822
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   823
    // Determine if this track has default options set for it
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   824
    // If so, apply them to the track object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   825
    if ( track && track._natives && track._natives.type &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   826
        ( obj.options.defaults && obj.options.defaults[ track._natives.type ] ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   827
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   828
      track = Popcorn.extend( {}, obj.options.defaults[ track._natives.type ], track );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   829
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   830
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   831
    if ( track._natives ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   832
      //  Supports user defined track event id
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   833
      track._id = !track.id ? Popcorn.guid( track._natives.type ) : track.id;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   834
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   835
      //  Push track event ids into the history
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   836
      obj.data.history.push( track._id );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   837
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   838
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   839
    track.start = Popcorn.util.toSeconds( track.start, obj.options.framerate );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   840
    track.end   = Popcorn.util.toSeconds( track.end, obj.options.framerate );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   841
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   842
    //  Store this definition in an array sorted by times
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   843
    var byStart = obj.data.trackEvents.byStart,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   844
        byEnd = obj.data.trackEvents.byEnd,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   845
        startIndex, endIndex,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   846
        currentTime;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   847
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   848
    for ( startIndex = byStart.length - 1; startIndex >= 0; startIndex-- ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   849
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   850
      if ( track.start >= byStart[ startIndex ].start ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   851
        byStart.splice( startIndex + 1, 0, track );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   852
        break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   853
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   854
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   855
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   856
    for ( endIndex = byEnd.length - 1; endIndex >= 0; endIndex-- ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   857
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   858
      if ( track.end > byEnd[ endIndex ].end ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   859
        byEnd.splice( endIndex + 1, 0, track );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   860
        break;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   861
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   862
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   863
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   864
    // Display track event immediately if it's enabled and current
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   865
    if ( track._natives &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   866
        ( !!Popcorn.registryByName[ track._natives.type ] || !!obj[ track._natives.type ] ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   867
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   868
      currentTime = obj.media.currentTime;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   869
      if ( track.end > currentTime &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   870
        track.start <= currentTime &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   871
        obj.data.disabled.indexOf( track._natives.type ) === -1 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   872
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   873
        track._running = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   874
        track._natives.start.call( obj, null, track );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   875
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   876
        if ( obj.options.frameAnimation &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   877
          track._natives.frame ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   878
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   879
          obj.data.trackEvents.animating.push( track );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   880
          track._natives.frame.call( obj, null, track, currentTime );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   881
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   882
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   883
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   884
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   885
    // update startIndex and endIndex
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   886
    if ( startIndex <= obj.data.trackEvents.startIndex &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   887
      track.start <= obj.data.trackEvents.previousUpdateTime ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   888
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   889
      obj.data.trackEvents.startIndex++;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   890
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   891
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   892
    if ( endIndex <= obj.data.trackEvents.endIndex &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   893
      track.end < obj.data.trackEvents.previousUpdateTime ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   894
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   895
      obj.data.trackEvents.endIndex++;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   896
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   897
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   898
    this.timeUpdate( obj, null, true );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   899
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   900
    // Store references to user added trackevents in ref table
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   901
    if ( track._id ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   902
      Popcorn.addTrackEvent.ref( obj, track );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   903
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   904
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   905
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   906
  // Internal Only - Adds track event references to the instance object's trackRefs hash table
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   907
  Popcorn.addTrackEvent.ref = function( obj, track ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   908
    obj.data.trackRefs[ track._id ] = track;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   909
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   910
    return obj;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   911
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   912
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   913
  Popcorn.removeTrackEvent  = function( obj, trackId ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   914
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   915
    var historyLen = obj.data.history.length,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   916
        indexWasAt = 0,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   917
        byStart = [],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   918
        byEnd = [],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   919
        animating = [],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   920
        history = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   921
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   922
    Popcorn.forEach( obj.data.trackEvents.byStart, function( o, i, context ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   923
      // Preserve the original start/end trackEvents
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   924
      if ( !o._id ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   925
        byStart.push( obj.data.trackEvents.byStart[i] );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   926
        byEnd.push( obj.data.trackEvents.byEnd[i] );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   927
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   928
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   929
      // Filter for user track events (vs system track events)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   930
      if ( o._id ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   931
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   932
        // Filter for the trackevent to remove
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   933
        if ( o._id !== trackId ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   934
          byStart.push( obj.data.trackEvents.byStart[i] );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   935
          byEnd.push( obj.data.trackEvents.byEnd[i] );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   936
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   937
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   938
        //  Capture the position of the track being removed.
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   939
        if ( o._id === trackId ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   940
          indexWasAt = i;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   941
          o._natives._teardown && o._natives._teardown.call( obj, o );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   942
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   943
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   944
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   945
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   946
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   947
    if ( obj.data.trackEvents.animating.length ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   948
      Popcorn.forEach( obj.data.trackEvents.animating, function( o, i, context ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   949
        // Preserve the original start/end trackEvents
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   950
        if ( !o._id ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   951
          animating.push( obj.data.trackEvents.animating[i] );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   952
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   953
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   954
        // Filter for user track events (vs system track events)
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   955
        if ( o._id ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   956
          // Filter for the trackevent to remove
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   957
          if ( o._id !== trackId ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   958
            animating.push( obj.data.trackEvents.animating[i] );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   959
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   960
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   961
      });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   962
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   963
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   964
    //  Update
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   965
    if ( indexWasAt <= obj.data.trackEvents.startIndex ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   966
      obj.data.trackEvents.startIndex--;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   967
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   968
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   969
    if ( indexWasAt <= obj.data.trackEvents.endIndex ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   970
      obj.data.trackEvents.endIndex--;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   971
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   972
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   973
    obj.data.trackEvents.byStart = byStart;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   974
    obj.data.trackEvents.byEnd = byEnd;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   975
    obj.data.trackEvents.animating = animating;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   976
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   977
    for ( var i = 0; i < historyLen; i++ ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   978
      if ( obj.data.history[ i ] !== trackId ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   979
        history.push( obj.data.history[ i ] );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   980
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   981
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   982
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   983
    // Update ordered history array
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   984
    obj.data.history = history;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   985
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   986
    // Update track event references
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   987
    Popcorn.removeTrackEvent.ref( obj, trackId );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   988
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   989
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   990
  // Internal Only - Removes track event references from instance object's trackRefs hash table
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   991
  Popcorn.removeTrackEvent.ref = function( obj, trackId ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   992
    delete obj.data.trackRefs[ trackId ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   993
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   994
    return obj;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   995
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   996
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   997
  // Return an array of track events bound to this instance object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   998
  Popcorn.getTrackEvents = function( obj ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
   999
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1000
    var trackevents = [],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1001
      refs = obj.data.trackEvents.byStart,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1002
      length = refs.length,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1003
      idx = 0,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1004
      ref;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1005
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1006
    for ( ; idx < length; idx++ ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1007
      ref = refs[ idx ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1008
      // Return only user attributed track event references
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1009
      if ( ref._id ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1010
        trackevents.push( ref );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1011
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1012
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1013
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1014
    return trackevents;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1015
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1016
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1017
  // Internal Only - Returns an instance object's trackRefs hash table
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1018
  Popcorn.getTrackEvents.ref = function( obj ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1019
    return obj.data.trackRefs;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1020
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1021
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1022
  // Return a single track event bound to this instance object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1023
  Popcorn.getTrackEvent = function( obj, trackId ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1024
    return obj.data.trackRefs[ trackId ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1025
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1026
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1027
  // Internal Only - Returns an instance object's track reference by track id
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1028
  Popcorn.getTrackEvent.ref = function( obj, trackId ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1029
    return obj.data.trackRefs[ trackId ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1030
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1031
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1032
  Popcorn.getLastTrackEventId = function( obj ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1033
    return obj.data.history[ obj.data.history.length - 1 ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1034
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1035
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1036
  Popcorn.timeUpdate = function( obj, event ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1037
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1038
    var currentTime = obj.media.currentTime,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1039
        previousTime = obj.data.trackEvents.previousUpdateTime,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1040
        tracks = obj.data.trackEvents,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1041
        animating = tracks.animating,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1042
        end = tracks.endIndex,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1043
        start = tracks.startIndex,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1044
        animIndex = 0,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1045
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1046
        registryByName = Popcorn.registryByName,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1047
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1048
        byEnd, byStart, byAnimate, natives, type;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1049
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1050
    //  Playbar advancing
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1051
    if ( previousTime <= currentTime ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1052
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1053
      while ( tracks.byEnd[ end ] && tracks.byEnd[ end ].end <= currentTime ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1054
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1055
        byEnd = tracks.byEnd[ end ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1056
        natives = byEnd._natives;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1057
        type = natives && natives.type;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1058
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1059
        //  If plugin does not exist on this instance, remove it
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1060
        if ( !natives ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1061
            ( !!registryByName[ type ] ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1062
              !!obj[ type ] ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1063
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1064
          if ( byEnd._running === true ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1065
            byEnd._running = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1066
            natives.end.call( obj, event, byEnd );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1067
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1068
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1069
          end++;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1070
        } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1071
          // remove track event
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1072
          Popcorn.removeTrackEvent( obj, byEnd._id );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1073
          return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1074
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1075
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1076
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1077
      while ( tracks.byStart[ start ] && tracks.byStart[ start ].start <= currentTime ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1078
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1079
        byStart = tracks.byStart[ start ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1080
        natives = byStart._natives;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1081
        type = natives && natives.type;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1082
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1083
        //  If plugin does not exist on this instance, remove it
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1084
        if ( !natives ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1085
            ( !!registryByName[ type ] ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1086
              !!obj[ type ] ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1087
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1088
          if ( byStart.end > currentTime &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1089
                byStart._running === false &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1090
                  obj.data.disabled.indexOf( type ) === -1 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1091
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1092
            byStart._running = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1093
            natives.start.call( obj, event, byStart );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1094
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1095
            // If the `frameAnimation` option is used,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1096
            // push the current byStart object into the `animating` cue
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1097
            if ( obj.options.frameAnimation &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1098
                ( byStart && byStart._running && byStart._natives.frame ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1099
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1100
              animating.push( byStart );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1101
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1102
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1103
          start++;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1104
        } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1105
          // remove track event
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1106
          Popcorn.removeTrackEvent( obj, byStart._id );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1107
          return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1108
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1109
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1110
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1111
      // If the `frameAnimation` option is used, iterate the animating track
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1112
      // and execute the `frame` callback
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1113
      if ( obj.options.frameAnimation ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1114
        while ( animIndex < animating.length ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1115
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1116
          byAnimate = animating[ animIndex ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1117
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1118
          if ( !byAnimate._running ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1119
            animating.splice( animIndex, 1 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1120
          } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1121
            byAnimate._natives.frame.call( obj, event, byAnimate, currentTime );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1122
            animIndex++;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1123
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1124
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1125
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1126
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1127
    // Playbar receding
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1128
    } else if ( previousTime > currentTime ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1129
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1130
      while ( tracks.byStart[ start ] && tracks.byStart[ start ].start > currentTime ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1131
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1132
        byStart = tracks.byStart[ start ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1133
        natives = byStart._natives;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1134
        type = natives && natives.type;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1135
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1136
        // if plugin does not exist on this instance, remove it
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1137
        if ( !natives ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1138
            ( !!registryByName[ type ] ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1139
              !!obj[ type ] ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1140
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1141
          if ( byStart._running === true ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1142
            byStart._running = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1143
            natives.end.call( obj, event, byStart );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1144
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1145
          start--;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1146
        } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1147
          // remove track event
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1148
          Popcorn.removeTrackEvent( obj, byStart._id );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1149
          return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1150
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1151
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1152
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1153
      while ( tracks.byEnd[ end ] && tracks.byEnd[ end ].end > currentTime ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1154
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1155
        byEnd = tracks.byEnd[ end ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1156
        natives = byEnd._natives;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1157
        type = natives && natives.type;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1158
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1159
        // if plugin does not exist on this instance, remove it
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1160
        if ( !natives ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1161
            ( !!registryByName[ type ] ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1162
              !!obj[ type ] ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1163
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1164
          if ( byEnd.start <= currentTime &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1165
                byEnd._running === false  &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1166
                  obj.data.disabled.indexOf( type ) === -1 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1167
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1168
            byEnd._running = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1169
            natives.start.call( obj, event, byEnd );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1170
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1171
            // If the `frameAnimation` option is used,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1172
            // push the current byEnd object into the `animating` cue
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1173
            if ( obj.options.frameAnimation &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1174
                  ( byEnd && byEnd._running && byEnd._natives.frame ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1175
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1176
              animating.push( byEnd );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1177
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1178
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1179
          end--;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1180
        } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1181
          // remove track event
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1182
          Popcorn.removeTrackEvent( obj, byEnd._id );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1183
          return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1184
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1185
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1186
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1187
      // If the `frameAnimation` option is used, iterate the animating track
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1188
      // and execute the `frame` callback
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1189
      if ( obj.options.frameAnimation ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1190
        while ( animIndex < animating.length ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1191
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1192
          byAnimate = animating[ animIndex ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1193
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1194
          if ( !byAnimate._running ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1195
            animating.splice( animIndex, 1 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1196
          } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1197
            byAnimate._natives.frame.call( obj, event, byAnimate, currentTime );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1198
            animIndex++;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1199
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1200
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1201
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1202
    // time bar is not moving ( video is paused )
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1203
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1204
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1205
    tracks.endIndex = end;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1206
    tracks.startIndex = start;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1207
    tracks.previousUpdateTime = currentTime;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1208
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1209
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1210
  //  Map and Extend TrackEvent functions to all Popcorn instances
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1211
  Popcorn.extend( Popcorn.p, {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1212
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1213
    getTrackEvents: function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1214
      return Popcorn.getTrackEvents.call( null, this );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1215
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1216
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1217
    getTrackEvent: function( id ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1218
      return Popcorn.getTrackEvent.call( null, this, id );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1219
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1220
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1221
    getLastTrackEventId: function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1222
      return Popcorn.getLastTrackEventId.call( null, this );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1223
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1224
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1225
    removeTrackEvent: function( id ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1226
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1227
      Popcorn.removeTrackEvent.call( null, this, id );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1228
      return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1229
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1230
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1231
    removePlugin: function( name ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1232
      Popcorn.removePlugin.call( null, this, name );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1233
      return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1234
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1235
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1236
    timeUpdate: function( event ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1237
      Popcorn.timeUpdate.call( null, this, event );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1238
      return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1239
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1240
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1241
    destroy: function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1242
      Popcorn.destroy.call( null, this );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1243
      return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1244
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1245
  });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1246
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1247
  //  Plugin manifests
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1248
  Popcorn.manifest = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1249
  //  Plugins are registered
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1250
  Popcorn.registry = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1251
  Popcorn.registryByName = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1252
  //  An interface for extending Popcorn
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1253
  //  with plugin functionality
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1254
  Popcorn.plugin = function( name, definition, manifest ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1255
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1256
    if ( Popcorn.protect.natives.indexOf( name.toLowerCase() ) >= 0 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1257
      Popcorn.error( "'" + name + "' is a protected function name" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1258
      return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1259
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1260
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1261
    //  Provides some sugar, but ultimately extends
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1262
    //  the definition into Popcorn.p
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1263
    var reserved = [ "start", "end" ],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1264
        plugin = {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1265
        setup,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1266
        isfn = typeof definition === "function",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1267
        methods = [ "_setup", "_teardown", "start", "end", "frame" ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1268
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1269
    // combines calls of two function calls into one
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1270
    var combineFn = function( first, second ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1271
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1272
      first = first || Popcorn.nop;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1273
      second = second || Popcorn.nop;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1274
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1275
      return function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1276
        first.apply( this, arguments );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1277
        second.apply( this, arguments );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1278
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1279
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1280
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1281
    //  If `manifest` arg is undefined, check for manifest within the `definition` object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1282
    //  If no `definition.manifest`, an empty object is a sufficient fallback
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1283
    Popcorn.manifest[ name ] = manifest = manifest || definition.manifest || {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1284
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1285
    // apply safe, and empty default functions
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1286
    methods.forEach(function( method ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1287
      definition[ method ] = safeTry( definition[ method ] || Popcorn.nop, name );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1288
    });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1289
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1290
    var pluginFn = function( setup, options ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1291
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1292
      if ( !options ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1293
        return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1294
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1295
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1296
      //  Storing the plugin natives
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1297
      var natives = options._natives = {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1298
          compose = "",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1299
          defaults, originalOpts, manifestOpts, mergedSetupOpts;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1300
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1301
      Popcorn.extend( natives, setup );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1302
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1303
      options._natives.type = name;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1304
      options._running = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1305
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1306
      natives.start = natives.start || natives[ "in" ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1307
      natives.end = natives.end || natives[ "out" ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1308
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1309
      // extend teardown to always call end if running
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1310
      natives._teardown = combineFn(function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1311
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1312
        var args = slice.call( arguments );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1313
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1314
        // end function signature is not the same as teardown,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1315
        // put null on the front of arguments for the event parameter
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1316
        args.unshift( null );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1317
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1318
        // only call end if event is running
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1319
        args[ 1 ]._running && natives.end.apply( this, args );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1320
      }, natives._teardown );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1321
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1322
      // Check for previously set default options
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1323
      defaults = this.options.defaults && this.options.defaults[ options._natives && options._natives.type ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1324
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1325
      // default to an empty string if no effect exists
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1326
      // split string into an array of effects
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1327
      options.compose = options.compose && options.compose.split( " " ) || [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1328
      options.effect = options.effect && options.effect.split( " " ) || [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1329
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1330
      // join the two arrays together
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1331
      options.compose = options.compose.concat( options.effect );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1332
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1333
      options.compose.forEach(function( composeOption ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1334
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1335
        // if the requested compose is garbage, throw it away
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1336
        compose = Popcorn.compositions[ composeOption ] || {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1337
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1338
        // extends previous functions with compose function
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1339
        methods.forEach(function( method ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1340
          natives[ method ] = combineFn( natives[ method ], compose[ method ] );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1341
        });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1342
      });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1343
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1344
      //  Ensure a manifest object, an empty object is a sufficient fallback
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1345
      options._natives.manifest = manifest;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1346
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1347
      //  Checks for expected properties
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1348
      if ( !( "start" in options ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1349
        options.start = options[ "in" ] || 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1350
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1351
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1352
      if ( !( "end" in options ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1353
        options.end = options[ "out" ] || this.duration() || Number.MAX_VALUE;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1354
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1355
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1356
      // Merge with defaults if they exist, make sure per call is prioritized
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1357
      mergedSetupOpts = defaults ? Popcorn.extend( {}, defaults, options ) :
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1358
                          options;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1359
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1360
      // Resolves 239, 241, 242
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1361
      if ( !mergedSetupOpts.target ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1362
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1363
        //  Sometimes the manifest may be missing entirely
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1364
        //  or it has an options object that doesn't have a `target` property
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1365
        manifestOpts = "options" in manifest && manifest.options;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1366
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1367
        mergedSetupOpts.target = manifestOpts && "target" in manifestOpts && manifestOpts.target;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1368
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1369
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1370
      // Trigger _setup method if exists
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1371
      options._natives._setup && options._natives._setup.call( this, mergedSetupOpts );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1372
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1373
      // Create new track event for this instance
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1374
      Popcorn.addTrackEvent( this, Popcorn.extend( mergedSetupOpts, options ) );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1375
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1376
      //  Future support for plugin event definitions
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1377
      //  for all of the native events
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1378
      Popcorn.forEach( setup, function( callback, type ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1379
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1380
        if ( type !== "type" ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1381
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1382
          if ( reserved.indexOf( type ) === -1 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1383
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1384
            this.listen( type, callback );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1385
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1386
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1387
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1388
      }, this );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1389
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1390
      return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1391
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1392
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1393
    //  Assign new named definition
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1394
    plugin[ name ] = function( options ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1395
      return pluginFn.call( this, isfn ? definition.call( this, options ) : definition,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1396
                                  options );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1397
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1398
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1399
    //  Extend Popcorn.p with new named definition
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1400
    Popcorn.extend( Popcorn.p, plugin );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1401
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1402
    //  Push into the registry
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1403
    var entry = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1404
      fn: plugin[ name ],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1405
      definition: definition,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1406
      base: definition,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1407
      parents: [],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1408
      name: name
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1409
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1410
    Popcorn.registry.push(
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1411
       Popcorn.extend( plugin, entry, {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1412
        type: name
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1413
      })
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1414
    );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1415
    Popcorn.registryByName[ name ] = entry;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1416
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1417
    return plugin;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1418
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1419
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1420
  // Storage for plugin function errors
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1421
  Popcorn.plugin.errors = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1422
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1423
  // Returns wrapped plugin function
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1424
  function safeTry( fn, pluginName ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1425
    return function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1426
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1427
      //  When Popcorn.plugin.debug is true, do not suppress errors
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1428
      if ( Popcorn.plugin.debug ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1429
        return fn.apply( this, arguments );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1430
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1431
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1432
      try {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1433
        return fn.apply( this, arguments );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1434
      } catch ( ex ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1435
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1436
        // Push plugin function errors into logging queue
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1437
        Popcorn.plugin.errors.push({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1438
          plugin: pluginName,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1439
          thrown: ex,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1440
          source: fn.toString()
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1441
        });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1442
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1443
        // Trigger an error that the instance can listen for
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1444
        // and react to
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1445
        this.trigger( "error", Popcorn.plugin.errors );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1446
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1447
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1448
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1449
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1450
  // Debug-mode flag for plugin development
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1451
  Popcorn.plugin.debug = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1452
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1453
  //  removePlugin( type ) removes all tracks of that from all instances of popcorn
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1454
  //  removePlugin( obj, type ) removes all tracks of type from obj, where obj is a single instance of popcorn
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1455
  Popcorn.removePlugin = function( obj, name ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1456
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1457
    //  Check if we are removing plugin from an instance or from all of Popcorn
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1458
    if ( !name ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1459
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1460
      //  Fix the order
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1461
      name = obj;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1462
      obj = Popcorn.p;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1463
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1464
      if ( Popcorn.protect.natives.indexOf( name.toLowerCase() ) >= 0 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1465
        Popcorn.error( "'" + name + "' is a protected function name" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1466
        return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1467
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1468
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1469
      var registryLen = Popcorn.registry.length,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1470
          registryIdx;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1471
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1472
      // remove plugin reference from registry
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1473
      for ( registryIdx = 0; registryIdx < registryLen; registryIdx++ ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1474
        if ( Popcorn.registry[ registryIdx ].name === name ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1475
          Popcorn.registry.splice( registryIdx, 1 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1476
          delete Popcorn.registryByName[ name ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1477
          delete Popcorn.manifest[ name ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1478
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1479
          // delete the plugin
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1480
          delete obj[ name ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1481
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1482
          // plugin found and removed, stop checking, we are done
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1483
          return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1484
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1485
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1486
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1487
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1488
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1489
    var byStart = obj.data.trackEvents.byStart,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1490
        byEnd = obj.data.trackEvents.byEnd,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1491
        animating = obj.data.trackEvents.animating,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1492
        idx, sl;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1493
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1494
    // remove all trackEvents
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1495
    for ( idx = 0, sl = byStart.length; idx < sl; idx++ ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1496
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1497
      if ( ( byStart[ idx ] && byStart[ idx ]._natives && byStart[ idx ]._natives.type === name ) &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1498
                ( byEnd[ idx ] && byEnd[ idx ]._natives && byEnd[ idx ]._natives.type === name ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1499
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1500
        byStart[ idx ]._natives._teardown && byStart[ idx ]._natives._teardown.call( obj, byStart[ idx ] );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1501
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1502
        byStart.splice( idx, 1 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1503
        byEnd.splice( idx, 1 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1504
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1505
        // update for loop if something removed, but keep checking
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1506
        idx--; sl--;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1507
        if ( obj.data.trackEvents.startIndex <= idx ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1508
          obj.data.trackEvents.startIndex--;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1509
          obj.data.trackEvents.endIndex--;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1510
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1511
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1512
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1513
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1514
    //remove all animating events
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1515
    for ( idx = 0, sl = animating.length; idx < sl; idx++ ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1516
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1517
      if ( animating[ idx ] && animating[ idx ]._natives && animating[ idx ]._natives.type === name ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1518
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1519
        animating.splice( idx, 1 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1520
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1521
        // update for loop if something removed, but keep checking
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1522
        idx--; sl--;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1523
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1524
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1525
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1526
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1527
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1528
  Popcorn.compositions = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1529
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1530
  //  Plugin inheritance
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1531
  Popcorn.compose = function( name, definition, manifest ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1532
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1533
    //  If `manifest` arg is undefined, check for manifest within the `definition` object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1534
    //  If no `definition.manifest`, an empty object is a sufficient fallback
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1535
    Popcorn.manifest[ name ] = manifest = manifest || definition.manifest || {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1536
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1537
    // register the effect by name
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1538
    Popcorn.compositions[ name ] = definition;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1539
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1540
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1541
  Popcorn.plugin.effect = Popcorn.effect = Popcorn.compose;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1542
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1543
  // stores parsers keyed on filetype
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1544
  Popcorn.parsers = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1545
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1546
  // An interface for extending Popcorn
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1547
  // with parser functionality
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1548
  Popcorn.parser = function( name, type, definition ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1549
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1550
    if ( Popcorn.protect.natives.indexOf( name.toLowerCase() ) >= 0 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1551
      Popcorn.error( "'" + name + "' is a protected function name" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1552
      return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1553
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1554
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1555
    // fixes parameters for overloaded function call
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1556
    if ( typeof type === "function" && !definition ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1557
      definition = type;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1558
      type = "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1559
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1560
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1561
    if ( typeof definition !== "function" || typeof type !== "string" ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1562
      return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1563
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1564
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1565
    // Provides some sugar, but ultimately extends
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1566
    // the definition into Popcorn.p
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1567
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1568
    var natives = Popcorn.events.all,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1569
        parseFn,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1570
        parser = {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1571
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1572
    parseFn = function( filename, callback ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1573
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1574
      if ( !filename ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1575
        return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1576
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1577
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1578
      var that = this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1579
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1580
      Popcorn.xhr({
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1581
        url: filename,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1582
        dataType: type,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1583
        success: function( data ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1584
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1585
          var tracksObject = definition( data ),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1586
              tracksData,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1587
              tracksDataLen,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1588
              tracksDef,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1589
              idx = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1590
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1591
          tracksData = tracksObject.data || [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1592
          tracksDataLen = tracksData.length;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1593
          tracksDef = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1594
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1595
          //  If no tracks to process, return immediately
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1596
          if ( !tracksDataLen ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1597
            return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1598
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1599
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1600
          //  Create tracks out of parsed object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1601
          for ( ; idx < tracksDataLen; idx++ ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1602
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1603
            tracksDef = tracksData[ idx ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1604
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1605
            for ( var key in tracksDef ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1606
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1607
              if ( hasOwn.call( tracksDef, key ) && !!that[ key ] ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1608
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1609
                that[ key ]( tracksDef[ key ] );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1610
              }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1611
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1612
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1613
          if ( callback ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1614
            callback();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1615
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1616
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1617
      });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1618
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1619
      return this;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1620
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1621
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1622
    // Assign new named definition
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1623
    parser[ name ] = parseFn;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1624
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1625
    // Extend Popcorn.p with new named definition
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1626
    Popcorn.extend( Popcorn.p, parser );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1627
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1628
    // keys the function name by filetype extension
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1629
    //Popcorn.parsers[ name ] = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1630
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1631
    return parser;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1632
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1633
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1634
  Popcorn.player = function( name, player ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1635
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1636
    player = player || {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1637
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1638
    var playerFn = function( target, src, options ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1639
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1640
      options = options || {};
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1641
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1642
      // List of events
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1643
      var date = new Date() / 1000,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1644
          baselineTime = date,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1645
          currentTime = 0,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1646
          volume = 1,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1647
          muted = false,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1648
          events = {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1649
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1650
          // The container div of the resource
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1651
          container = document.getElementById( rIdExp.exec( target ) && rIdExp.exec( target )[ 2 ] ) ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1652
                        document.getElementById( target ) ||
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1653
                          target,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1654
          basePlayer = {},
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1655
          timeout,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1656
          popcorn;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1657
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1658
      // copies a div into the media object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1659
      for( var val in container ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1660
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1661
        if ( typeof container[ val ] === "object" ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1662
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1663
          basePlayer[ val ] = container[ val ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1664
        } else if ( typeof container[ val ] === "function" ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1665
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1666
          basePlayer[ val ] = (function( value ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1667
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1668
            // this is a stupid ugly kludgy hack in honour of Safari
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1669
            // in Safari a NodeList is a function, not an object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1670
            if ( "length" in container[ value ] && !container[ value ].call ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1671
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1672
              return container[ value ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1673
            } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1674
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1675
              return function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1676
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1677
                return container[ value ].apply( container, arguments );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1678
              };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1679
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1680
          }( val ));
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1681
        } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1682
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1683
          Popcorn.player.defineProperty( basePlayer, val, {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1684
            get: (function( value ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1685
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1686
              return function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1687
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1688
                return container[ value ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1689
              };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1690
            }( val )),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1691
            set: Popcorn.nop,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1692
            configurable: true
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1693
          });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1694
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1695
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1696
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1697
      var timeupdate = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1698
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1699
        date = new Date() / 1000;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1700
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1701
        if ( !basePlayer.paused ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1702
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1703
          basePlayer.currentTime = basePlayer.currentTime + ( date - baselineTime );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1704
          basePlayer.dispatchEvent( "timeupdate" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1705
          timeout = setTimeout( timeupdate, 10 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1706
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1707
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1708
        baselineTime = date;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1709
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1710
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1711
      basePlayer.play = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1712
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1713
        this.paused = false;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1714
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1715
        if ( basePlayer.readyState >= 4 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1716
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1717
          baselineTime = new Date() / 1000;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1718
          basePlayer.dispatchEvent( "play" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1719
          timeupdate();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1720
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1721
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1722
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1723
      basePlayer.pause = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1724
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1725
        this.paused = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1726
        basePlayer.dispatchEvent( "pause" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1727
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1728
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1729
      Popcorn.player.defineProperty( basePlayer, "currentTime", {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1730
        get: function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1731
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1732
          return currentTime;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1733
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1734
        set: function( val ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1735
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1736
          // make sure val is a number
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1737
          currentTime = +val;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1738
          basePlayer.dispatchEvent( "timeupdate" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1739
          return currentTime;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1740
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1741
        configurable: true
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1742
      });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1743
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1744
      Popcorn.player.defineProperty( basePlayer, "volume", {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1745
        get: function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1746
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1747
          return volume;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1748
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1749
        set: function( val ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1750
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1751
          // make sure val is a number
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1752
          volume = +val;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1753
          basePlayer.dispatchEvent( "volumechange" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1754
          return volume;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1755
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1756
        configurable: true
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1757
      });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1758
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1759
      Popcorn.player.defineProperty( basePlayer, "muted", {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1760
        get: function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1761
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1762
          return muted;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1763
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1764
        set: function( val ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1765
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1766
          // make sure val is a number
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1767
          muted = +val;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1768
          basePlayer.dispatchEvent( "volumechange" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1769
          return muted;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1770
        },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1771
        configurable: true
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1772
      });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1773
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1774
      // Adds an event listener to the object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1775
      basePlayer.addEventListener = function( evtName, fn ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1776
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1777
        if ( !events[ evtName ] ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1778
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1779
          events[ evtName ] = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1780
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1781
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1782
        events[ evtName ].push( fn );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1783
        return fn;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1784
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1785
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1786
      // Can take event object or simple string
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1787
      basePlayer.dispatchEvent = function( oEvent ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1788
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1789
        var evt,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1790
            self = this,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1791
            eventInterface,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1792
            eventName = oEvent.type;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1793
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1794
        // A string was passed, create event object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1795
        if ( !eventName ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1796
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1797
          eventName = oEvent;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1798
          eventInterface  = Popcorn.events.getInterface( eventName );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1799
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1800
          if ( eventInterface ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1801
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1802
            evt = document.createEvent( eventInterface );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1803
            evt.initEvent( eventName, true, true, window, 1 );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1804
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1805
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1806
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1807
        Popcorn.forEach( events[ eventName ], function( val ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1808
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1809
          val.call( self, evt, self );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1810
        });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1811
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1812
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1813
      // Attempt to get src from playerFn parameter
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1814
      basePlayer.src = src || "";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1815
      basePlayer.readyState = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1816
      basePlayer.duration = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1817
      basePlayer.paused = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1818
      basePlayer.ended = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1819
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1820
      if ( player._setup ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1821
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1822
        player._setup.call( basePlayer, options );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1823
      } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1824
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1825
        // there is no setup, which means there is nothing to load
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1826
        basePlayer.readyState = 4;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1827
        basePlayer.dispatchEvent( "load" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1828
        basePlayer.dispatchEvent( "loadeddata" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1829
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1830
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1831
      // when a custom player is loaded, load basePlayer state into custom player
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1832
      basePlayer.addEventListener( "load", function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1833
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1834
        // if a player is not ready before currentTime is called, this will set it after it is ready
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1835
        basePlayer.currentTime = currentTime;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1836
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1837
        // same as above with volume and muted
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1838
        basePlayer.volume = volume;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1839
        basePlayer.muted = muted;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1840
      });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1841
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1842
      basePlayer.addEventListener( "loadeddata", function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1843
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1844
        // if play was called before player ready, start playing video
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1845
        !basePlayer.paused && basePlayer.play();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1846
      });
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1847
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1848
      popcorn = new Popcorn.p.init( basePlayer, options );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1849
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1850
      return popcorn;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1851
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1852
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1853
    Popcorn[ name ] = Popcorn[ name ] || playerFn;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1854
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1855
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1856
  Popcorn.player.defineProperty = Object.defineProperty || function( object, description, options ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1857
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1858
    object.__defineGetter__( description, options.get || Popcorn.nop );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1859
    object.__defineSetter__( description, options.set || Popcorn.nop );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1860
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1861
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1862
  //  Cache references to reused RegExps
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1863
  var rparams = /\?/,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1864
  //  XHR Setup object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1865
  setup = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1866
    url: "",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1867
    data: "",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1868
    dataType: "",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1869
    success: Popcorn.nop,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1870
    type: "GET",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1871
    async: true,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1872
    xhr: function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1873
      return new global.XMLHttpRequest();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1874
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1875
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1876
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1877
  Popcorn.xhr = function( options ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1878
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1879
    options.dataType = options.dataType && options.dataType.toLowerCase() || null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1880
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1881
    if ( options.dataType &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1882
         ( options.dataType === "jsonp" || options.dataType === "script" ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1883
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1884
      Popcorn.xhr.getJSONP(
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1885
        options.url,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1886
        options.success,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1887
        options.dataType === "script"
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1888
      );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1889
      return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1890
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1891
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1892
    var settings = Popcorn.extend( {}, setup, options );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1893
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1894
    //  Create new XMLHttpRequest object
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1895
    settings.ajax  = settings.xhr();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1896
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1897
    if ( settings.ajax ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1898
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1899
      if ( settings.type === "GET" && settings.data ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1900
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1901
        //  append query string
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1902
        settings.url += ( rparams.test( settings.url ) ? "&" : "?" ) + settings.data;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1903
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1904
        //  Garbage collect and reset settings.data
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1905
        settings.data = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1906
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1907
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1908
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1909
      settings.ajax.open( settings.type, settings.url, settings.async );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1910
      settings.ajax.send( settings.data || null );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1911
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1912
      return Popcorn.xhr.httpData( settings );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1913
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1914
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1915
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1916
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1917
  Popcorn.xhr.httpData = function( settings ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1918
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1919
    var data, json = null,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1920
        parser, xml = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1921
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1922
    settings.ajax.onreadystatechange = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1923
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1924
      if ( settings.ajax.readyState === 4 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1925
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1926
        try {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1927
          json = JSON.parse( settings.ajax.responseText );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1928
        } catch( e ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1929
          //suppress
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1930
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1931
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1932
        data = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1933
          xml: settings.ajax.responseXML,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1934
          text: settings.ajax.responseText,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1935
          json: json
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1936
        };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1937
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1938
        // Normalize: data.xml is non-null in IE9 regardless of if response is valid xml
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1939
        if ( !data.xml || !data.xml.documentElement ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1940
          data.xml = null;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1941
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1942
          try {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1943
            parser = new DOMParser();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1944
            xml = parser.parseFromString( settings.ajax.responseText, "text/xml" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1945
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1946
            if ( !xml.getElementsByTagName( "parsererror" ).length ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1947
              data.xml = xml;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1948
            }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1949
          } catch ( e ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1950
            // data.xml remains null
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1951
          }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1952
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1953
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1954
        //  If a dataType was specified, return that type of data
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1955
        if ( settings.dataType ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1956
          data = data[ settings.dataType ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1957
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1958
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1959
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1960
        settings.success.call( settings.ajax, data );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1961
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1962
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1963
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1964
    return data;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1965
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1966
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1967
  Popcorn.xhr.getJSONP = function( url, success, isScript ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1968
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1969
    var head = document.head || document.getElementsByTagName( "head" )[ 0 ] || document.documentElement,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1970
      script = document.createElement( "script" ),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1971
      paramStr = url.split( "?" )[ 1 ],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1972
      isFired = false,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1973
      params = [],
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1974
      callback, parts, callparam;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1975
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1976
    if ( paramStr && !isScript ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1977
      params = paramStr.split( "&" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1978
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1979
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1980
    if ( params.length ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1981
      parts = params[ params.length - 1 ].split( "=" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1982
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1983
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1984
    callback = params.length ? ( parts[ 1 ] ? parts[ 1 ] : parts[ 0 ]  ) : "jsonp";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1985
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1986
    if ( !paramStr && !isScript ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1987
      url += "?callback=" + callback;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1988
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1989
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1990
    if ( callback && !isScript ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1991
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1992
      //  If a callback name already exists
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1993
      if ( !!window[ callback ] ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1994
        //  Create a new unique callback name
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1995
        callback = Popcorn.guid( callback );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1996
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1997
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1998
      //  Define the JSONP success callback globally
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  1999
      window[ callback ] = function( data ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2000
        // Fire success callbacks
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2001
        success && success( data );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2002
        isFired = true;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2003
      };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2004
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2005
      //  Replace callback param and callback name
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2006
      url = url.replace( parts.join( "=" ), parts[ 0 ] + "=" + callback );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2007
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2008
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2009
    script.onload = function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2010
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2011
      //  Handling remote script loading callbacks
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2012
      if ( isScript ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2013
        //  getScript
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2014
        success && success();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2015
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2016
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2017
      //  Executing for JSONP requests
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2018
      if ( isFired ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2019
        //  Garbage collect the callback
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2020
        delete window[ callback ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2021
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2022
      //  Garbage collect the script resource
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2023
      head.removeChild( script );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2024
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2025
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2026
    script.src = url;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2027
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2028
    head.insertBefore( script, head.firstChild );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2029
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2030
    return;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2031
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2032
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2033
  Popcorn.getJSONP = Popcorn.xhr.getJSONP;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2034
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2035
  Popcorn.getScript = Popcorn.xhr.getScript = function( url, success ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2036
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2037
    return Popcorn.xhr.getJSONP( url, success, true );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2038
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2039
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2040
  Popcorn.util = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2041
    // Simple function to parse a timestamp into seconds
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2042
    // Acceptable formats are:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2043
    // HH:MM:SS.MMM
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2044
    // HH:MM:SS;FF
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2045
    // Hours and minutes are optional. They default to 0
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2046
    toSeconds: function( timeStr, framerate ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2047
      // Hours and minutes are optional
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2048
      // Seconds must be specified
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2049
      // Seconds can be followed by milliseconds OR by the frame information
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2050
      var validTimeFormat = /^([0-9]+:){0,2}[0-9]+([.;][0-9]+)?$/,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2051
          errorMessage = "Invalid time format",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2052
          digitPairs, lastIndex, lastPair, firstPair,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2053
          frameInfo, frameTime;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2054
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2055
      if ( typeof timeStr === "number" ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2056
        return timeStr;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2057
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2058
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2059
      if ( typeof timeStr === "string" &&
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2060
            !validTimeFormat.test( timeStr ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2061
        Popcorn.error( errorMessage );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2062
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2063
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2064
      digitPairs = timeStr.split( ":" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2065
      lastIndex = digitPairs.length - 1;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2066
      lastPair = digitPairs[ lastIndex ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2067
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2068
      // Fix last element:
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2069
      if ( lastPair.indexOf( ";" ) > -1 ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2070
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2071
        frameInfo = lastPair.split( ";" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2072
        frameTime = 0;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2073
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2074
        if ( framerate && ( typeof framerate === "number" ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2075
          frameTime = parseFloat( frameInfo[ 1 ], 10 ) / framerate;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2076
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2077
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2078
        digitPairs[ lastIndex ] = parseInt( frameInfo[ 0 ], 10 ) + frameTime;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2079
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2080
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2081
      firstPair = digitPairs[ 0 ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2082
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2083
      return {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2084
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2085
        1: parseFloat( firstPair, 10 ),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2086
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2087
        2: ( parseInt( firstPair, 10 ) * 60 ) +
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2088
              parseFloat( digitPairs[ 1 ], 10 ),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2089
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2090
        3: ( parseInt( firstPair, 10 ) * 3600 ) +
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2091
            ( parseInt( digitPairs[ 1 ], 10 ) * 60 ) +
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2092
              parseFloat( digitPairs[ 2 ], 10 )
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2093
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2094
      }[ digitPairs.length || 1 ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2095
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2096
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2097
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2098
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2099
  // Initialize locale data
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2100
  // Based on http://en.wikipedia.org/wiki/Language_localisation#Language_tags_and_codes
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2101
  function initLocale( arg ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2102
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2103
    var locale = typeof arg === "string" ? arg : [ arg.language, arg.region ].join( "-" ),
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2104
        parts = locale.split( "-" );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2105
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2106
    // Setup locale data table
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2107
    return {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2108
      iso6391: locale,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2109
      language: parts[ 0 ] || "",
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2110
      region: parts[ 1 ] || ""
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2111
    };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2112
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2113
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2114
  // Declare locale data table
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2115
  var localeData = initLocale( global.navigator.userLanguage || global.navigator.language );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2116
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2117
  Popcorn.locale = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2118
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2119
    // Popcorn.locale.get()
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2120
    // returns reference to privately
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2121
    // defined localeData
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2122
    get: function() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2123
      return localeData;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2124
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2125
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2126
    // Popcorn.locale.set( string|object );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2127
    set: function( arg ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2128
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2129
      localeData = initLocale( arg );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2130
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2131
      Popcorn.locale.broadcast();
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2132
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2133
      return localeData;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2134
    },
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2135
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2136
    // Popcorn.locale.broadcast( type )
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2137
    // Sends events to all popcorn media instances that are
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2138
    // listening for locale events
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2139
    broadcast: function( type ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2140
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2141
      var instances = Popcorn.instances,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2142
          length = instances.length,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2143
          idx = 0,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2144
          instance;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2145
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2146
      type = type || "locale:changed";
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2147
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2148
      // Iterate all current instances
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2149
      for ( ; idx < length; idx++ ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2150
        instance = instances[ idx ];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2151
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2152
        // For those instances with locale event listeners,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2153
        // trigger a locale change event
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2154
        if ( type in instance.data.events  ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2155
          instance.trigger( type );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2156
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2157
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2158
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2159
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2160
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2161
  // alias for exec function
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2162
  Popcorn.p.cue = Popcorn.p.exec;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2163
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2164
  function getItems() {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2165
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2166
    var item,
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2167
        list = [];
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2168
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2169
    if ( Object.keys ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2170
      list = Object.keys( Popcorn.p );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2171
    } else {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2172
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2173
      for ( item in Popcorn.p ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2174
        if ( hasOwn.call( Popcorn.p, item ) ) {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2175
          list.push( item );
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2176
        }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2177
      }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2178
    }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2179
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2180
    return list.join( "," ).toLowerCase().split( ",");
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2181
  }
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2182
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2183
  //  Protected API methods
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2184
  Popcorn.protect = {
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2185
    natives: getItems()
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2186
  };
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2187
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2188
  //  Exposes Popcorn to global context
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2189
  global.Popcorn = Popcorn;
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2190
9b8e68803f6f add allocine player, and add an full test with this allocine player.
cavaliet
parents:
diff changeset
  2191
})(window, window.document);