]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#494] Optimize optional frameAnimation logic, wraps logic in conditional blocks
authorRick Waldron <waldron.rick@gmail.com>
Thu, 8 Sep 2011 13:57:01 +0000 (09:57 -0400)
committerRick Waldron <waldron.rick@gmail.com>
Thu, 8 Sep 2011 13:57:01 +0000 (09:57 -0400)
popcorn.js

index 6fc8ebbf685dd2ef733ad8eb6c9816068b9de9a2..9d0ec84c94143fdebc2324098eb96409a88b360c 100644 (file)
 
         // Filter for user track events (vs system track events)
         if ( o._id ) {
-
           // Filter for the trackevent to remove
           if ( o._id !== trackId ) {
             animating.push( obj.data.trackEvents.animating[i] );
           }
         }
-
       });
     }
 
     }
 
     obj.data.trackEvents.byStart = byStart;
-    obj.data.trackEvents.byEnd  = byEnd;
-    obj.data.trackEvents.animating  = animating;
+    obj.data.trackEvents.byEnd = byEnd;
+    obj.data.trackEvents.animating = animating;
 
     for ( var i = 0; i < historyLen; i++ ) {
       if ( obj.data.history[ i ] !== trackId ) {
     var currentTime = obj.media.currentTime,
         previousTime = obj.data.trackEvents.previousUpdateTime,
         tracks = obj.data.trackEvents,
-        tracksAnimating = tracks.animating,
+        animating = tracks.animating,
         end = tracks.endIndex,
         start = tracks.startIndex,
         animIndex = 0,
 
         registryByName = Popcorn.registryByName,
 
-        byEnd, byStart, natives, type;
+        byEnd, byStart, byAnimate, natives, type;
 
     //  Playbar advancing
     if ( previousTime < currentTime ) {
             byStart._running = true;
             natives.start.call( obj, event, byStart );
 
-            if ( byStart && byStart._running && byStart._natives.frame ) {
-              tracksAnimating.push( byStart );
+            // If the `frameAnimation` option is used,
+            // push the current byStart object into the `animating` cue
+            if ( obj.options.frameAnimation &&
+                ( byStart && byStart._running && byStart._natives.frame ) ) {
+
+              animating.push( byStart );
             }
           }
           start++;
         }
       }
 
-      while ( animIndex < tracksAnimating.length ) {
-        if ( !tracksAnimating[ animIndex ]._running ) {
-          tracksAnimating.splice( animIndex, 1 );
-        } else {
-          tracksAnimating[ animIndex ]._natives.frame.call( obj, event, tracksAnimating[ animIndex ], currentTime );
-          animIndex++;
+      // If the `frameAnimation` option is used, iterate the animating track
+      // and execute the `frame` callback
+      if ( obj.options.frameAnimation ) {
+        while ( animIndex < animating.length ) {
+
+          byAnimate = animating[ animIndex ];
+
+          if ( !byAnimate._running ) {
+            animating.splice( animIndex, 1 );
+          } else {
+            byAnimate._natives.frame.call( obj, event, byAnimate, currentTime );
+            animIndex++;
+          }
         }
       }
 
             byEnd._running = true;
             natives.start.call( obj, event, byEnd );
 
-            if ( byEnd && byEnd._running && byEnd._natives.frame ) {
-              tracksAnimating.push( byEnd );
+            // If the `frameAnimation` option is used,
+            // push the current byEnd object into the `animating` cue
+            if ( obj.options.frameAnimation &&
+                  ( byEnd && byEnd._running && byEnd._natives.frame ) ) {
+
+              animating.push( byEnd );
             }
           }
           end--;
         }
       }
 
-      while ( animIndex < tracksAnimating.length ) {
-        if ( !tracksAnimating[ animIndex ]._running ) {
-          tracksAnimating.splice( animIndex, 1 );
-        } else {
-          tracksAnimating[ animIndex ]._natives.frame.call( obj, event, tracksAnimating[ animIndex ], currentTime );
-          animIndex++;
+      // If the `frameAnimation` option is used, iterate the animating track
+      // and execute the `frame` callback
+      if ( obj.options.frameAnimation ) {
+        while ( animIndex < animating.length ) {
+
+          byAnimate = animating[ animIndex ];
+
+          if ( !byAnimate._running ) {
+            animating.splice( animIndex, 1 );
+          } else {
+            byAnimate._natives.frame.call( obj, event, byAnimate, currentTime );
+            animIndex++;
+          }
         }
       }
-
     // time bar is not moving ( video is paused )
     }