]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
stopped the plugin from polling window.Processing in a setTimeout. now executes a...
authorChristopher De Cairos <chris.decairos@gmail.com>
Thu, 8 Sep 2011 14:55:57 +0000 (10:55 -0400)
committerChristopher De Cairos <chris.decairos@gmail.com>
Wed, 14 Sep 2011 17:47:52 +0000 (13:47 -0400)
plugins/processing/popcorn.processing.js

index e1ddc5c82fa23152b05dbec26e64c2c23c45be57..3d55019608dfb75cb4d78222774623b2371d9f4f 100644 (file)
   Popcorn.plugin( "processing" , function ( options ) {
 
     var init = function( context ) {
-    
-      var initProcessing,
-        canvas;
-
-      if ( !window.Processing ) {
-
-        Popcorn.getScript( "http://processingjs.org/content/download/processing-js-1.2.1/processing-1.2.1.min.js" );
-      }
-
-      options.parentTarget = document.getElementById( options.target );
-      
-      if ( !options.parentTarget && Popcorn.plugin.debug ) {
-        throw new Error( "target container doesn't exist" );
-      }
-      
-      initProcessing = function() {
+        
+      function scriptReady() {
         var addListeners = function() {
           context.listen( "pause", function () {
             if ( options.canvas.style.display === "inline" ) {
           });
         };
         
-        if ( window.Processing ) {
+        if ( options.sketch ) {
+
+          Popcorn.xhr({
+            url: options.sketch,
+            dataType: "text",
+            success: function( responseCode ) {
+              options.codeReady = true;
+              options.processingCode = responseCode;
+              options.pjsInstance = new Processing( options.canvas, options.processingCode );
+              options.pjsInstance.noLoop();
+              options.seeking = false;
+              context.listen( "seeking", function() {
+                 options._running && options.canvas.style.display === "inline" && options.noPause && options.pjsInstance.loop();
+              });
 
-          options.pjsInstance = new Processing( options.canvas, options.processingCode );
-          options.pjsInstance.noLoop();
-          options.seeking = false;
-          context.listen( "seeking", function() {
-             options._running && options.canvas.style.display === "inline" && options.noPause && options.pjsInstance.loop();
-          });
+              options._running && !context.media.paused && options.pjsInstance.loop();
+              
+              options.noPause = options.noPause || false;
+              !options.noPause && addListeners(); 
+              options.codeReady = true;
 
-          options._running && !context.media.paused && options.pjsInstance.loop();
+            }
+          });
+        } else if ( Popcorn.plugin.debug ) {
           
-          options.noPause = options.noPause || false;
-          !options.noPause && addListeners(); 
-          options.codeReady = true;         
-        } else {
-          setTimeout ( function() {
-            initProcessing.call( this );
-            }, 10 );
-        }
-      };
-      
-      canvas = document.createElement( "canvas" );
-      canvas.id = Popcorn.guid( options.target + "-sketch-" );
-      canvas[ "data-processing-sources" ] =  options.sketch;
-      canvas.style.display = "none";   
-      options.canvas = canvas;
-      
-      options.parentTarget && options.parentTarget.appendChild( options.canvas );
-
-      if ( options.sketch ) {
-
-        Popcorn.xhr({
-          url: options.sketch,
-          dataType: "text",
-          success: function( responseCode ) {
-            options.codeReady = true;
-            options.processingCode = responseCode;
-            initProcessing();
-          }
-        });
-      } else {
-
-        if ( Popcorn.plugin.debug ) {
           throw new Error( "options.sketch is undefined" );
+          return;
         }
+        
       }
+
+      if ( !window.Processing ) {
+
+        Popcorn.getScript( "http://processingjs.org/content/download/processing-js-1.2.1/processing-1.2.1.min.js", scriptReady );
+      } else {
+      
+        scriptReady();
+      }
+
     };
 
     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";   
+        options.canvas = canvas;
+        
+        options.parentTarget && options.parentTarget.appendChild( options.canvas );
 
         init( this );
       },
 
         options.codeReady && !this.media.paused && options.pjsInstance.loop();
         options.canvas.style.display = "inline";
+
       },
 
       end: function( event, options ) {