]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
processing plug-in no longer polls for Processing.
authorChristopher De Cairos <chris.decairos@gmail.com>
Wed, 14 Sep 2011 18:12:26 +0000 (14:12 -0400)
committerChristopher De Cairos <chris.decairos@gmail.com>
Wed, 14 Sep 2011 18:12:26 +0000 (14:12 -0400)
plugins/processing/popcorn.processing.js

index de7923e6b93f1483de19b113df3a8d444119f2f0..f15656baf8706b07e43103a6ee4bfb426ff0df18 100644 (file)
@@ -2,9 +2,9 @@
  * 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. 
+ * -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
  */
 
 (function ( Popcorn ) {
-                
-  var called = false;
 
   Popcorn.plugin( "processing" , function ( options ) {
-  
+
     var init = function( context ) {
 
       function scriptReady( options ) {
             }
           });
         };
-        
+
         if ( options.sketch ) {
 
           Popcorn.xhr({
             url: options.sketch,
             dataType: "text",
             success: function( responseCode ) {
-            
+
               options.codeReady = false;
-              
+
               var s = Processing.compile( responseCode );
-              s.onLoad = function() {
-                console.log( "onLoad Called" );
-                options.codeReady = true;
-                ( options._running && !context.media.paused && options.pjsInstance.loop() ) || options.pjsInstance.noLoop() ;
-              };
-              
               options.pjsInstance = new Processing( options.canvas, s );
               options.seeking = false;
-              
+              ( options._running && !context.media.paused && options.pjsInstance.loop() ) || options.pjsInstance.noLoop();
+
               context.listen( "seeking", function() {
                  options._running && options.canvas.style.display === "inline" && options.noPause && options.pjsInstance.loop();
               });
-  
-              options.noPause = options.noPause || false;
-              !options.noPause && addListeners(); 
 
+              options.noPause = options.noPause || false;
+              !options.noPause && addListeners();
+                                                       options.codeReady = true;
             }
           });
         } else if ( Popcorn.plugin.debug ) {
-          
-          throw new Error( "options.sketch is undefined" );
+
+          throw new Error( "Popcorn.Processing: options.sketch is undefined" );
           return;
         }
-        
-      }
 
-      if ( !window.Processing && !called ) {
+      }
 
+      if (!window.Processing) {
         Popcorn.getScript( "http://processingjs.org/content/download/processing-js-1.3.0/processing-1.3.0.js", function() {
           scriptReady( options )
         });
-        called = true;
       } else {
-        readyCheck = function() {
-          if ( window.Processing ) {
-            scriptReady( options );
-            return;
-          }
-         
-          setTimeout( readyCheck, 5 ); 
-        
-        };
-        
-        readyCheck();
-        
+        scriptReady( options );
       }
 
     };
     return {
 
       _setup: function( options ) {
-        
+
         options.codeReady = false;
-        
+
         options.parentTarget = document.getElementById( options.target );
-            
+
         if ( !options.parentTarget && Popcorn.plugin.debug ) {
           throw new Error( "target container doesn't exist" );
         }
-            
+
         var canvas = document.createElement( "canvas" );
         canvas.id = Popcorn.guid( options.target + "-sketch-" );
-        //canvas[ "data-processing-sources" ] =  options.sketch;
-        canvas.style.display = "none";   
+        canvas.style.display = "none";
         options.canvas = canvas;
-        
+
         options.parentTarget && options.parentTarget.appendChild( options.canvas );
 
         init( this );
       },
 
       end: function( event, options ) {
-        
+
         options.pjsInstance && options.pjsInstance.noLoop();
         options.canvas.style.display = "none";
       },
-      
+
       _teardown: function( options ) {
         options.pjsInstance && options.pjsInstance.exit();
         options.parentTarget && options.parentTarget.removeChild( options.canvas );