]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
Adjusted formatting per rwldrn's comments
authorbrianchirls <brian@chirls.com>
Tue, 6 Sep 2011 18:27:02 +0000 (14:27 -0400)
committerbrianchirls <brian@chirls.com>
Tue, 6 Sep 2011 18:27:02 +0000 (14:27 -0400)
popcorn.js

index 982957a3d89b325f1400df6235937cd4d8ac7435..4a48bdfb5f2319fee912e0cffad3351549205081 100644 (file)
@@ -35,8 +35,8 @@
       global.mozRequestAnimationFrame    || 
       global.oRequestAnimationFrame      || 
       global.msRequestAnimationFrame     || 
-      function(/* function */ callback, /* DOMElement */ element){
-        global.setTimeout(callback, 16);
+      function( callback, element){
+        global.setTimeout( callback, 16 );
       };
   }()),
 
             start: -1,
             end: -1
           }],
-          animating:[],
+          animating: [],
           startIndex: 0,
           endIndex: 0,
           previousUpdateTime: -1
           });
 
           if ( that.options.frameAnimation ) {
+            // if Popcorn is created with frameAnimation option set to true,
+            // requestAnimFrame is used instead of "timeupdate" media event.
+            // This is for greater frame time accuracy, theoretically up to
+            // 60 frames per second as opposed to 4
 
             var animate = function () {
               Popcorn.timeUpdate( that, event );
               that.trigger( "timeupdate" );
 
-              requestAnimFrame(animate);
+              requestAnimFrame( animate );
             };
 
-            requestAnimFrame(animate);
+            requestAnimFrame( animate );
 
           } else {
 
 
     });
 
-    Popcorn.forEach( obj.data.trackEvents.animating, function( o, i, context ) {
-      // Preserve the original start/end trackEvents
-      if ( !o._id ) {
-        animating.push( obj.data.trackEvents.animating[i] );
-      }
+    if ( obj.data.trackEvents.animating.length ) {
+      Popcorn.forEach( obj.data.trackEvents.animating, function( o, i, context ) {
+        // Preserve the original start/end trackEvents
+        if ( !o._id ) {
+          animating.push( obj.data.trackEvents.animating[i] );
+        }
 
-      // Filter for user track events (vs system track events)
-      if ( o._id ) {
+        // 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] );
+          // Filter for the trackevent to remove
+          if ( o._id !== trackId ) {
+            animating.push( obj.data.trackEvents.animating[i] );
+          }
         }
-      }
 
-    });
+      });
+    }
 
     //  Update
     if ( indexWasAt <= obj.data.trackEvents.startIndex ) {
             tracksByStart[ tracks.startIndex ]._running = true;
             tracksByStart[ tracks.startIndex ]._natives.start.call( obj, event, tracksByStart[ tracks.startIndex ] );
 
-            if (tracksByStart[ tracks.startIndex ]._natives.frame) {
-              tracksAnimating.push(tracksByStart[ tracks.startIndex ]);
+            if ( tracksByStart[ tracks.startIndex ]._natives.frame ) {
+              tracksAnimating.push( tracksByStart[ tracks.startIndex ] );
             }
           }
           tracks.startIndex++;
         }
       }
 
-      while (animIndex < tracksAnimating.length) {
-        if (tracksAnimating[animIndex]._running == false) {
-          tracksAnimating.splice(animIndex,1);
+      while ( animIndex < tracksAnimating.length ) {
+        if ( !tracksAnimating[animIndex]._running ) {
+          tracksAnimating.splice( animIndex, 1 );
         } else {
-          tracksAnimating[animIndex]._natives.frame.call( obj, event, tracksAnimating[animIndex], currentTime );
+          tracksAnimating[ animIndex ]._natives.frame.call( obj, event, tracksAnimating[ animIndex ], currentTime );
           animIndex++;
         }
       }
             tracksByEnd[ tracks.endIndex ]._running = true;
             tracksByEnd[ tracks.endIndex ]._natives.start.call( obj, event, tracksByEnd[tracks.endIndex] );
 
-            if (tracksByEnd[ tracks.endIndex ]._natives.frame) {
-              tracksAnimating.push(tracksByEnd[ tracks.endIndex ]);
+            if ( tracksByEnd[ tracks.endIndex ]._natives.frame ) {
+              tracksAnimating.push( tracksByEnd[ tracks.endIndex ] );
             }
           }
           tracks.endIndex--;
         }
       }
 
-      while (animIndex < tracksAnimating.length) {
-        if (tracksAnimating[animIndex]._running == false) {
-          tracksAnimating.splice(animIndex,1);
+      while ( animIndex < tracksAnimating.length ) {
+        if ( !tracksAnimating[animIndex]._running ) {
+          tracksAnimating.splice( animIndex, 1 );
         } else {
-          tracksAnimating[animIndex]._natives.frame.call( obj, event, tracksAnimating[animIndex], currentTime );
+          tracksAnimating[ animIndex ]._natives.frame.call( obj, event, tracksAnimating[ animIndex ], currentTime );
           animIndex++;
         }
       }
     //remove all animating events
     for ( idx = 0, sl = animating.length; idx < sl; idx++ ) {
 
-      if ( ( animating[ idx ] && animating[ idx ]._natives && animating[ idx ]._natives.type === name ) ) {
+      if ( animating[ idx ] && animating[ idx ]._natives && animating[ idx ]._natives.type === name ) {
 
         animating.splice( idx, 1 );