]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
fixed id creation issue, modified html file.
authorChristopher De Cairos <chris.decairos@gmail.com>
Mon, 6 Jun 2011 15:55:44 +0000 (11:55 -0400)
committerChristopher De Cairos <chris.decairos@gmail.com>
Mon, 6 Jun 2011 15:55:44 +0000 (11:55 -0400)
plugins/processing/popcorn.processing.html
plugins/processing/popcorn.processing.js

index b8a4d22301b659c6d52995d1effa346ba92442ab..8348c6c466157bce33ed8018a344c4731c64292f 100644 (file)
         end: 5, // seconds
         control: 'pause',
         target: 'processing-div',
-        sketch: 'test.pjs'       
+        sketch: 'test2.pjs'       
       } )
       .processing({ // Div with sketch defined here
         start: 5, // seconds
         end: 10, // seconds
         control: 'pause',
         target: 'processing-div2',
-        sketch: 'test2.pjs'
+        sketch: 'test.pjs'
       } )
       .processing({  // Canvas with sketch hard-coded defined 
         start: 10, // seconds
         end: 15, // seconds
         control: 'pause',
-        sketch: 'test.pjs',
+        sketch: 'test2.pjs',
         target: 'processing-canvas2',  // we don't need a sketch because we are pausing a canvas that is hard coded
       } )
       .processing({ // Div with sketch defined here
         sketch: 'test2.pjs',
         target: 'processing-div2',  // Thest mulitple instructions for one sketch - Especially relevant here since the first time we are building a canvas
       } )
-      .processing({ // Div With a sketch defined as a file calling a function within the sketch 
-        start: 20, // seconds
-        control: 'function',
-        func: 'switch_status',
-        sketch: 'test.pjs',
-        target: 'processing-div3',
-      } )
     }, false);
 
   </script>
index c64baf115c4c8e48453ff3072663476aff75c365..94128d2dd991809db2e5f51e85ba4cd0500eace8 100644 (file)
             
         init = function() {
           if ( window.Processing ) {
-            if ( !types[ options.control ] ) {
-              throw ( "popcorn.processing plug-in ERROR: un-recognized control type '" + options.control + "' must be 'pause' or 'function'" );
-            }
-            if ( options.start >= options.end ) {
-              throw ( "popcorn.processing plug-in ERROR: invalid start and end pause timings '" + options.start + "' must be less than '" + options.end + "'" );
-            }
             parentTarget = document.getElementById( options.target );
-            if ( !parentTarget ) {
-              throw ( "popcorn.processing plug-in ERROR: Target '" + options.target + "' does not exist." );
-            } else {
-              if ( parentTarget.tagName === "CANVAS" ) {
-                canvas = parentTarget;
-              } else if ( parentTarget.tagName === "DIV" ) {
-                canvas = document.createElement( "canvas" );
-                canvas.id = options.target + "Sketch";
-                canvas.setAttribute( "data-processing-sources", options.sketch );
-                canvas.style.display = "none";
-                parentTarget.appendChild( canvas );
-              }
-              Popcorn.xhr({
-                url: options.sketch,
-                dataType: "text",
-                success: function( responseCode ) {
-                  codeReady = true;
-                  processingCode = responseCode;
-                }
-              });
-              
-              createCanvas = function() {
-                if ( codeReady ) {
-                  processingInstance = new Processing( canvas, processingCode );
-                } else {
-                  setTimeout ( createCanvas, 10 );
-                }
-              };
-              createCanvas();
+            if ( parentTarget.tagName === "CANVAS" ) {
+              canvas = parentTarget;
+            } else if ( parentTarget.tagName === "DIV" ) {
+              canvas = document.createElement( "canvas" );
+              // +new Date() is used here to create unique id's for canvas' within the same div.
+              canvas.id = options.target + "Sketch" + +new Date();
+              canvas.setAttribute( "data-processing-sources", options.sketch );
+              canvas.style.display = "none";
+              parentTarget.appendChild( canvas );
             }
+            Popcorn.xhr({
+              url: options.sketch,
+              dataType: "text",
+              success: function( responseCode ) {
+                codeReady = true;
+                processingCode = responseCode;
+              }
+            });
+            
+            createCanvas = function() {
+              if ( codeReady ) {
+                processingInstance = new Processing( canvas, processingCode );
+              } else {
+                setTimeout ( createCanvas, 10 );
+              }
+            };
+            createCanvas();
           } else {
             !processingLoaded && loadProcessing();
             setTimeout( init, 10 );