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