]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#319] DRY out Popcorn.removePlugin()
authorrwldrn <waldron.rick@gmail.com>
Wed, 9 Feb 2011 19:55:30 +0000 (14:55 -0500)
committerrwldrn <waldron.rick@gmail.com>
Wed, 9 Feb 2011 19:55:30 +0000 (14:55 -0500)
popcorn.js
test/popcorn.unit.js
test/popcorn.unit.setup.js

index 0c5b01f971d3779a7ff566274a19f5a5239ac363..ffc80d54fe9121ca8eb6548055b3783953a3b2ba 100644 (file)
     removePlugin: function( name ) {
 
       var byStart = this.data.trackEvents.byStart, 
-          byEnd = this.data.trackEvents.byEnd;
+          byEnd = this.data.trackEvents.byEnd, 
+          idx, rl, sl;
   
       delete Popcorn.p[ name ];
   
       // remove plugin reference from registry
-      for ( var r = 0, rl = Popcorn.registry.length; r < rl; r++ ) {
-        if ( Popcorn.registry[r].type === name ) {
-          Popcorn.registry.splice(r, 1);
+      for ( idx = 0, rl = Popcorn.registry.length; idx < rl; idx++ ) {
+        if ( Popcorn.registry[ idx ].type === name ) {
+          Popcorn.registry.splice( idx, 1 );
           break; // plugin found, stop checking
         }
       }
 
       // remove all trackEvents
-      for ( var s = 0, sl = byStart.length; s < sl; s++ ) {
-        if ( byStart[s] && byStart[s]._natives && byStart[s]._natives.type === name ) {
-          byStart.splice( s, 1 );
-          s--; sl--; // update for loop if something removed, but keep checking
-          if ( this.data.trackEvents.startIndex <= s ) {
-            this.data.trackEvents.startIndex--; // write test for this
-          }
-        }
-      }
-      for ( var e = 0, el = byEnd.length; e < el; e++ ) {
-        if ( byEnd[e] && byEnd[e]._natives && byEnd[e]._natives.type === name ) {
-          byEnd.splice( e, 1 );
-          e--; el--; // update for loop if something removed, but keep checking
-          if ( this.data.trackEvents.endIndex <= e ) {
-            this.data.trackEvents.endIndex--; // write test for this
+      for ( idx = 0, sl = byStart.length; idx < sl; idx++ ) {
+        
+        if ( ( byStart[ idx ] && byEnd[ idx ] ) && 
+                ( byStart[ idx ]._natives && byStart[ idx ]._natives.type === name ) && 
+                  ( byEnd[ idx ]._natives && byEnd[ idx ]._natives.type === name ) ) {
+          
+          byStart.splice( idx, 1 );
+          byEnd.splice( idx, 1 );
+          
+          // update for loop if something removed, but keep checking
+          idx--; sl--; 
+          if ( this.data.trackEvents.startIndex <= idx ) {
+            this.data.trackEvents.startIndex--;
+            this.data.trackEvents.endIndex--;
           }
         }
       }
index ac2bfea081c503972f3e1413c4c2d5301a5b5a00..03fe9247b63dcba59b0ec1db925512ecba2c1c2f 100644 (file)
@@ -1403,12 +1403,13 @@ module("Popcorn Test Runner End");
 test("Last Check", function () {
   
   //   ALWAYS RUN LAST
-  
-  expect(1)
   try {  
     
     equals( Setup.getGlobalSize(), Setup.globalSize + 1 , "Popcorn API did not leak");
-    plus();
+    
+    if ( !Setup.globalDiff.length ) {
+      //console.log(Setup.globalDiff);
+    }
     
   } catch (e) {};
   
index 07e68fd38dc1af204f8820d4ba4b510f1c9571ec..79f4a1c262aed215be31dee1bf3c3e23561573b3 100644 (file)
@@ -1,59 +1,74 @@
-//  suppress console log errors
-if ( !window['console'] ) {
-  var console = {}, 
-      methods = 'log debug info warn error exception assert dir dirxml trace group groupEnd groupCollapsed time timeEnd profile profileEnd count clear notifyFirebug getFirebugElement firebug element'.split(' ');
-  
-  for ( var m in methods ) {
-    console[ methods[m] ] = function () {
-      //Array.prototype.slice.call(arguments)
-    };
-  }  
-}
-
-
-(function (global) { 
-  
-  //  Store the number of global properties that exist prior to Popcorn API definition
-  
-  var Setup = {
-    globalSize: 0
-  };
-
-  Setup.getGlobalSize = function() {
-
-    var size = 0;
-
-    for( var p in window ) {
-      if ( p !== "_firebug" ) {
-        size++;
-      }
-    }
-
-    //  account for self
-    size++;
-    
-    //  Store the number of global properties internally
-    if ( !Setup.globalSize ) {
-      Setup.globalSize = size;
-    }
-
-    return size;
-  };
-  
-  
-  
-  Setup.eventset  = "loadstart progress suspend emptied stalled play pause " + 
-                          "loadedmetadata loadeddata waiting playing canplay canplaythrough " + 
-                          "seeking seeked timeupdate ended ratechange durationchange volumechange";
-  
-  Setup.events = Setup.eventset.split(/\s+/g);                              
-
-  
-  
-  global.Setup = Setup;
-
-})(window);
-
-
-Setup.getGlobalSize();
-
+//  suppress console log errors\r
+if ( !window['console'] ) {\r
+  var console = {}, \r
+      methods = 'log debug info warn error exception assert dir dirxml trace group groupEnd groupCollapsed time timeEnd profile profileEnd count clear notifyFirebug getFirebugElement firebug element'.split(' ');\r
+  \r
+  for ( var m in methods ) {\r
+    console[ methods[m] ] = function () {\r
+      //Array.prototype.slice.call(arguments)\r
+    };\r
+  }  \r
+}\r
+\r
+\r
+(function (global) { \r
+  \r
+  //  Store the number of global properties that exist prior to Popcorn API definition\r
+  \r
+  var Setup = {\r
+    hasRun: false, \r
+    globalSize: 0, \r
+    globalCache: [], \r
+    globalDiff: []\r
+  };\r
+\r
+  Setup.getGlobalSize = function() {\r
+\r
+    var size = 0;\r
+\r
+    for( var p in window ) {\r
+      if ( p !== "_firebug" ) {\r
+        size++;\r
+        \r
+        if ( !Setup.hasRun ) {\r
+          Setup.globalCache.push( p );\r
+        } else {\r
+          if ( Setup.globalCache.indexOf( p ) === -1 ) {\r
+            Setup.globalDiff.push( p );\r
+          }\r
+        }\r
+      }\r
+    }\r
+\r
+    //  account for self\r
+    size++;\r
+    \r
+    //  Store the number of global properties internally\r
+    if ( !Setup.globalSize ) {\r
+      Setup.globalSize = size;\r
+    }\r
+    \r
+    if ( !Setup.hasRun ) {\r
+      Setup.hasRun = true;\r
+    }\r
+    \r
+    return size;\r
+  };\r
+  \r
+  \r
+  \r
+  Setup.eventset  = "loadstart progress suspend emptied stalled play pause " + \r
+                          "loadedmetadata loadeddata waiting playing canplay canplaythrough " + \r
+                          "seeking seeked timeupdate ended ratechange durationchange volumechange";\r
+  \r
+  Setup.events = Setup.eventset.split(/\s+/g);                              \r
+\r
+  \r
+  \r
+  global.Setup = Setup;\r
+\r
+})(window);\r
+\r
+\r
+Setup.getGlobalSize();\r
+\r