]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
fixed pause issue, style issues, tightened up unit tests, added documentation
authorChristopher De Cairos <cadecairos@India.(none)>
Mon, 20 Jun 2011 16:35:54 +0000 (12:35 -0400)
committerChristopher De Cairos <cadecairos@India.(none)>
Mon, 20 Jun 2011 16:35:54 +0000 (12:35 -0400)
plugins/processing/popcorn.processing.html
plugins/processing/popcorn.processing.js
plugins/processing/popcorn.processing.unit.js

index c6ec6a6d3836542c3381325d3d664810eac4995f..e4974f0034a86e1b643d485ab91fd4a1948c509f 100644 (file)
@@ -2,7 +2,6 @@
 <head>
   
   <title>Popcorn processing Plug-in Simple Demo</title>
-  <!--<script src="./processing.js"></script> -->
   <script src="../../popcorn.js"></script>
   <script src="popcorn.processing.js"></script>
   
index e5d8277d56624b346645b5b7b3468372551026e0..3fee16710865ed6c1ae33da3629bf66f370043cb 100644 (file)
@@ -1,15 +1,37 @@
-// PLUGIN: Processing
 /**
-* Processing popcorn plug-in
-*/
+ * Processing Popcorn Plug-In
+ *
+ * This plugin adds a Processing.js sketch to be added to a target div or canvas.
+ * 
+ * Options parameter needs to specify start, end, target and  sketch attributes
+ * -Start is the time [in seconds] that you want the sketch to display and start looping. 
+ * -End is the time [in seconds] you want the sketch to become hidden and stop looping.
+ * -Target is the id of the div or canvas you want the target sketch to be displayed in. ( a target that is a div will have a canvas created and placed inside of it. )
+ * -Sketch specifies the filename of the Procesing code to be loaded into Processing.js
+ * -noLoop [optional] specifies whether a sketch should continue to loop when the video is paused or seeking.
+ *
+ * @param {Object} options
+ *
+ * Example:
+ var p = Popcorn( "#video" )
+ .processing({
+   start: 5,
+   end: 10,
+   target: "processing-div",
+   sketch: "processingSketch.pjs",
+   noLoop: true
+ });
+ *
+ */
 
-(function (Popcorn) {
+(function ( Popcorn ) {
 
   var processingLoaded = false,
 
     toggle = function( on, options ) {
       var instance = options.pjsInstance,
           canvas = options.canvas;
+          
       if ( canvas && options.isReady ) {
         if ( on ) {
           canvas.style.display = "inline";
@@ -19,7 +41,7 @@
           instance.noLoop();
         }
       } else {
-        setTimeout ( function() {
+        setTimeout (function() {
           toggle.call( this, on, options );
         }, 10 );
       }
       var popcorn = context,
       initProcessing,
       parentTarget = document.getElementById( options.target );
+      
       if ( parentTarget.tagName === "CANVAS" ) {
         options.canvas = parentTarget;
       } else if ( parentTarget.tagName === "DIV" ) {
         options.canvas = document.createElement( "canvas" );
         // +new Date() is used here to create unique id's for canvas' within the same div.
-        options.canvas.id = options.target + "Sketch" + (+new Date());
+        options.canvas.id = options.target + "Sketch" + ( +new Date() );
         options.canvas.setAttribute( "data-processing-sources", options.sketch );
         parentTarget.appendChild( options.canvas );
       }
@@ -65,7 +88,7 @@
             if ( options.canvas.style.display === "inline" ) {
               options.pjsInstance.noLoop();
             }
-          } );
+          });
           popcorn.listen( "play", function() {
             if ( options.canvas.style.display === "inline" ) {
               options.pjsInstance.loop();
         
         if ( codeReady && window.Processing ) {
           options.pjsInstance = new Processing( options.canvas, processingCode );
-          !options.noPause && addListeners();
+          popcorn.listen( "seeking", function() {
+            if ( options.canvas.style.display === "inline" && options.noPause ) {
+              options.pjsInstance.loop();
+            }
+          });
+          
+          options.noPause = options.noPause || false;
+          !options.noPause && addListeners();          
           options.isReady = true;
         } else {
           setTimeout ( initProcessing, 10 );
index 2fc4813fe295f778ce37a350650cad5740126255..01cd2dc33ee77e7262e746ebe08cf9e7b674d026 100644 (file)
@@ -3,8 +3,8 @@ test( "Processing plugin tests", function() {
       expects = 18,
       count = 0,
       processingDiv = document.getElementById( "processing-div" ),
-      processingDiv2= document.getElementById( "processing-div-2" ),
-      processingDiv3= document.getElementById( "processing-div-3" ),
+      processingDiv2 = document.getElementById( "processing-div-2" ),
+      processingDiv3 = document.getElementById( "processing-div-3" ),
       canvases = [];
 
   expect( expects );
@@ -31,42 +31,42 @@ test( "Processing plugin tests", function() {
 
   popped.processing({
     start: 0,
-    end: 3,
+    end: 1,
     target: "processing-div",
     sketch: "test.pjs"
   })
   .processing({
-    start: 4,
-    end: 7,
+    start: 1,
+    end: 3,
     target: "processing-div-2",
     sketch: "test2.pjs"
   })
   .processing({
-    start: 4,
-    end: 7,
+    start: 3,
+    end: 4,
     target: "processing-div-3",
     sketch: "test.pjs"
   })
-  .exec( 1.5, function() {
+  .exec( 0.5, function() {
     equals( processingDiv.children[ 0 ].style.display, "inline", "canvas '" + processingDiv.children[ 0 ].id + "' is displayed" );
     plus();
     //TODO: David Humphrey has written code that allows for listening to events on Processing instances. when 
     // it lands In the next processing release we'll be able to detect if a processing instance is looping or not.
     // this is required in order to test the noPause functionality (automatically)
   })
-  .exec( 5, function() {
+  .exec( 1.5, function() {
     equals( processingDiv.children[ 0 ].style.display, "none", "canvas '" + processingDiv.children[ 0 ].id + "' is hidden" );
     plus();
-    equals( processingDiv2.children[ 0 ].style.display, "inline", "canvas '" + processingDiv.children[ 0 ].id + "' is displayed" );
+    equals( processingDiv2.children[ 0 ].style.display, "inline", "canvas '" + processingDiv2.children[ 0 ].id + "' is displayed" );
     plus();
-    equals( processingDiv3.children[ 0 ].style.display, "inline", "canvas '" + processingDiv.children[ 0 ].id + "' is displayed" );
+    equals( processingDiv3.children[ 0 ].style.display, "none", "canvas '" + processingDiv3.children[ 0 ].id + "' is hidden" );
     plus();
-  }).exec( 7.5, function() {
+  }).exec( 3.5, function() {
     equals( processingDiv.children[ 0 ].style.display, "none", "canvas '" + processingDiv.children[ 0 ].id + "' is hidden" );
     plus();
-    equals( processingDiv2.children[ 0 ].style.display, "none", "canvas '" + processingDiv.children[ 0 ].id + "' is hidden" );
+    equals( processingDiv2.children[ 0 ].style.display, "none", "canvas '" + processingDiv2.children[ 0 ].id + "' is hidden" );
     plus();
-    equals( processingDiv3.children[ 0 ].style.display, "none", "canvas '" + processingDiv.children[ 0 ].id + "' is hidden" );
+    equals( processingDiv3.children[ 0 ].style.display, "inline", "canvas '" + processingDiv3.children[ 0 ].id + "' is displayed" );
     plus();
   });