]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
initial removePlugin
authorScottDowne <sdowne@learn.senecac.on.ca>
Mon, 13 Dec 2010 20:22:12 +0000 (15:22 -0500)
committerScottDowne <sdowne@learn.senecac.on.ca>
Mon, 13 Dec 2010 20:22:12 +0000 (15:22 -0500)
popcorn.js

index c99986402aaa2b87ebb25f5edb1a770522df9045..742e439d0506d9b45de044a1e4df8e407ed573a1 100644 (file)
   };
 
   Popcorn.addTrackEvent = function( obj, track ) {
-    console.log(obj);
     // Store this definition in an array sorted by times
     obj.data.trackEvents.byStart.push( track );
     obj.data.trackEvents.byEnd.push( track );
         }
       },
       removePlugin: function( name ) {
-        
+
+        var byStart = this.data.trackEvents.byStart, 
+            byEnd = this.data.trackEvents.byEnd;        
+
         this[name] = undef;
         
         // remove plugin reference from registry
         }
 
         // remove all trackEvents
-        for (var trackEvent in this.data.trackEvents) {
-          // still working on this, need to clear tracks, failing one test because of it
+        for (var i = 0, sl = byStart.length; i < sl; i++) {
+          if (byStart[i] && byStart[i].natives && byStart[i].natives.type === name) {
+            byStart.splice(i, 1);
+            i--; sl--; // update for loop if something removed, but keep checking
+            if (this.data.trackEvents.startIndex <= i) {
+              this.data.trackEvents.startIndex--; // write test for this
+            }
+          }
+        }
+        for (var i = 0, el = byEnd.length; i < el; i++) {
+          if (byEnd[i] && byEnd[i].natives && byEnd[i].natives.type === name) {
+            byEnd.splice(i, 1);
+            i--; el--; // update for loop if something removed, but keep checking
+            if (this.data.trackEvents.endIndex <= i) {
+              this.data.trackEvents.endIndex--; // write test for this
+            }
+          }
         }
 
       }