]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#724] Removes Popcorn instance management code. Retains only Popcorn.instances array
authorRick Waldron <waldron.rick@gmail.com>
Mon, 19 Sep 2011 15:47:06 +0000 (11:47 -0400)
committerRick Waldron <waldron.rick@gmail.com>
Mon, 19 Sep 2011 15:47:06 +0000 (11:47 -0400)
parsers/parserJSON/popcorn.parserJSON.unit.js
popcorn.js
test/popcorn.unit.js

index b63d04ac62adfc7faec6d409169d1f9280b20c63..dd05c5783860686fc8a45edf5778b04ecc06f34c 100644 (file)
@@ -85,7 +85,7 @@ test("Popcorn 0.3 JSON Parser Plugin - AUDIO", function () {
       trackData,
       trackEvents,
       interval,
-      audiocorn = Popcorn.getInstanceById("audio");
+      audiocorn = Popcorn("#audio");
 
   function plus() {
     if ( ++count === expects ) {
index e2c7320a73229cfaa39255e2c7fe59c740cf6e82..16f3e7570c8b09f55ff9d928535fa4df8ddb4433 100644 (file)
@@ -4,8 +4,7 @@
   if ( !document.addEventListener ) {
     global.Popcorn = {};
 
-    var methods = ( "removeInstance addInstance getInstanceById removeInstanceById " +
-          "forEach extend effects error guid sizeOf isArray nop position disable enable " +
+    var methods = ( "forEach extend effects error guid sizeOf isArray nop position disable enable " +
           "addTrackEvent removeTrackEvent getTrackEvents getTrackEvent getLastTrackEventId " +
           "timeUpdate plugin removePlugin compose effect parser xhr getJSONP getScript" ).split(/\s+/);
 
 
   //  Instance caching
   Popcorn.instances = [];
-  Popcorn.instanceIds = {};
-
-  Popcorn.removeInstance = function( instance ) {
-    //  If called prior to any instances being created
-    //  Return early to avoid splicing on nothing
-    if ( !Popcorn.instances.length ) {
-      return;
-    }
-
-    //  Remove instance from Popcorn.instances
-    Popcorn.instances.splice( Popcorn.instanceIds[ instance.id ], 1 );
-
-    //  Delete the instance id key
-    delete Popcorn.instanceIds[ instance.id ];
-
-    //  Return current modified instances
-    return Popcorn.instances;
-  };
-
-  //  Addes a Popcorn instance to the Popcorn instance array
-  Popcorn.addInstance = function( instance ) {
-
-    var instanceLen = Popcorn.instances.length,
-        instanceId = instance.media.id && instance.media.id;
-
-    //  If the media element has its own `id` use it, otherwise provide one
-    //  Ensure that instances have unique ids and unique entries
-    //  Uses `in` operator to avoid false positives on 0
-    instance.id = !( instanceId in Popcorn.instanceIds ) && instanceId ||
-                    "__popcorn" + instanceLen;
-
-    //  Create a reference entry for this instance
-    Popcorn.instanceIds[ instance.id ] = instanceLen;
-
-    //  Add this instance to the cache
-    Popcorn.instances.push( instance );
-
-    //  Return the current modified instances
-    return Popcorn.instances;
-  };
-
-  //  Request Popcorn object instance by id
-  Popcorn.getInstanceById = function( id ) {
-    return Popcorn.instances[ Popcorn.instanceIds[ id ] ];
-  };
-
-  //  Remove Popcorn object instance by id
-  Popcorn.removeInstanceById = function( id ) {
-    return Popcorn.removeInstance( Popcorn.instances[ Popcorn.instanceIds[ id ] ] );
-  };
 
   //  Declare a shortcut (Popcorn.p) to and a definition of
   //  the new prototype for our Popcorn constructor
       this[ ( this.media.nodeName && this.media.nodeName.toLowerCase() ) || "video" ] = this.media;
 
       //  Register new instance
-      Popcorn.addInstance( this );
+      Popcorn.instances.push( this );
 
       this.options = options || {};
 
index 6dfff8f4996c8d8ecd5150f130ac1e8564ec6b5d..bc87d45f1ae62aa86ecff3a4d70a04eee43d1500 100644 (file)
@@ -222,66 +222,6 @@ test("Popcorn.util.toSeconds" , function() {
   }
 });
 
-test("Instances", function() {
-  var expects = 11,
-      count   = 0,
-      instance;
-
-  expect(expects);
-
-  function plus(){
-    if ( ++count == expects ) {
-      start();
-    }
-  }
-
-  stop();
-
-  Popcorn("#video");
-
-  ok( typeof Popcorn.addInstance === "function" , "Popcorn.addInstance is a provided static function");
-  plus();
-
-  ok( typeof Popcorn.removeInstance === "function" , "Popcorn.removeInstance is a provided static function");
-  plus();
-
-  ok( typeof Popcorn.getInstanceById === "function" , "Popcorn.getInstanceById is a provided static function");
-  plus();
-
-  ok( typeof Popcorn.removeInstanceById === "function" , "Popcorn.removeInstanceById is a provided static function");
-  plus();
-
-  ok( typeof Popcorn.instanceIds === "object" , "Popcorn.instanceIds is a provided cache object");
-  plus();
-
-  ok( "length" in Popcorn.instances && "join" in Popcorn.instances, "Popcorn.instances is a provided cache array");
-  plus();
-
-  instance = Popcorn.getInstanceById("video");
-
-  ok( instance.video, "Stored instance as a `video` property" );
-  plus();
-
-  ok( instance.data, "Stored instance as a `data` property" );
-  plus();
-
-  ok( instance instanceof Popcorn, "Instance instanceof Popcorn" );
-  plus();
-
-  equal( Popcorn.instances.length, 2, "There are the correct number of Popcorn instances" );
-  plus();
-
-  //  Create another instance
-  Popcorn("#video");
-
-  //  Get a reference to remove
-  var remove = Popcorn.instances[1];
-
-  //  Remove and check the length of the currently cached instances
-  equal( Popcorn.removeInstanceById( remove.id ).length, 2, "Removing an instance by id: 1 instance remains" );
-  plus();
-});
-
 test("guid", function() {
 
   expect(6);
@@ -477,8 +417,6 @@ test("Popcorn.[addTrackEvent | removeTrackEvent].ref()", function() {
   });
 
   equal( Popcorn.sizeOf( popped.data.trackRefs ), 0, "There are 0 trackRefs in popped.data.trackRefs" );
-
-  //Popcorn.removeInstance( popped );
 });
 
 
@@ -812,7 +750,6 @@ test( "Popcorn.locale object", function() {
   function plus() {
     if ( ++count == expects ) {
       start();
-      Popcorn.removeInstance( $pop );
     }
   }
 
@@ -2909,8 +2846,6 @@ test("Popcorn.disable/enable/toggle (timeupdate)", function() {
   function plus() {
     if ( ++count === expects ) {
       start();
-
-      Popcorn.removeInstance( $pop );
       Popcorn.removePlugin( "toggler" );
     }
   }