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