]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#t612] processing.js loading fixes
authorScottDowne <sdowne@learn.senecac.on.ca>
Fri, 24 Jun 2011 17:33:34 +0000 (13:33 -0400)
committerScottDowne <sdowne@learn.senecac.on.ca>
Fri, 24 Jun 2011 17:33:34 +0000 (13:33 -0400)
plugins/gml/popcorn.gml.js
plugins/processing/popcorn.processing.js

index b847657e70e3ab0cb5a66b0c2214a2bbe4787e83..03e027c7bafc262ff26309e70f6e3d4d33dffdcc 100755 (executable)
@@ -2,7 +2,9 @@
 
 (function (Popcorn) {
 
-  var processingLoaded = false,
+  var processingLoader = {
+        readyState: 0
+      },
       gmlPlayer = function( $p ) {
 
         var _stroke = 0,
           dataReady();
         };
       };
-
-  Popcorn.getScript( "http://processingjs.org/content/download/processing-js-1.1.0/processing-1.1.0.js", function() {
-
-    processingLoaded = true;
-  });
   
   /**
    * Grafiti markup Language (GML) popcorn plug-in 
 
       document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( options.container );
 
+      if ( processingLoader.readyState === 0 ) {
+
+        processingLoader.readyState = 1;
+
+        if ( !window.Processing ) {
+
+          Popcorn.getScript( "http://processingjs.org/content/download/processing-js-1.2.1/processing-1.2.1.min.js", function() {
+
+            processingLoader.readyState = 2;
+          });
+        } else {
+
+          processingLoader.readyState = 2;
+        }
+      }
+
       // makes sure both processing.js and the gml data are loaded
       var readyCheck = function() {
 
-        if ( processingLoaded ) {
+        if ( processingLoader.readyState === 2 ) {
+
           Popcorn.getJSONP( "http://000000book.com/data/" + options.gmltag + ".json?callback=", function( data ) {
 
             options.pjsInstance = new Processing( options.container, gmlPlayer );
index 708ae9aa2849d31d6d8655eab4dc2692cf95ec1e..bfb52f4e4c95e5e1e1c64ce1be315463624def31 100644 (file)
 
 (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";
-        !this.media.paused && instance.loop();
-      } else {
-        canvas.style.display = "none";
-        instance.noLoop();
-      }
-    } else {
-      setTimeout (function() {
-        toggle.call( this, on, options );
-      }, 10 );
-    }
-  },
-
-  load = function() {
-    Popcorn.getScript( "http://processingjs.org/content/download/processing-js-1.2.1/processing-1.2.1.js", function() {
-      processingLoaded = true;
-    });
-  };
-
-  load();
+  var processingLoader = {
+        readyState: 0
+      },
+      toggle = function( on, options ) {
+        var instance = options.pjsInstance,
+            canvas = options.canvas;
+            
+        if ( canvas && options.isReady ) {
+          if ( on ) {
+            canvas.style.display = "inline";
+            !this.media.paused && instance.loop();
+          } else {
+            canvas.style.display = "none";
+            instance.noLoop();
+          }
+        } else {
+          setTimeout (function() {
+            toggle.call( this, on, options );
+          }, 10 );
+        }
+      };
 
   Popcorn.plugin( "processing" , function ( options ) {
 
     
       var initProcessing,
         canvas;
-      
+
+      if ( processingLoader.readyState === 0 ) {
+
+        processingLoader.readyState = 1;
+
+        if ( !window.Processing ) {
+
+          Popcorn.getScript( "http://processingjs.org/content/download/processing-js-1.2.1/processing-1.2.1.min.js", function() {
+
+            processingLoader.readyState = 2;
+          });
+        } else {
+
+          processingLoader.readyState = 2;
+        }
+      }
+
       options.parentTarget = document.getElementById( options.target );
       
       if ( !options.parentTarget ) {
@@ -82,7 +91,7 @@
           });
         };
         
-        if ( options.codeReady && window.Processing ) {
+        if ( options.codeReady && processingLoader.readyState === 2 ) {
           options.pjsInstance = new Processing( options.canvas, options.processingCode );
           options.pjsInstance.noLoop();
           context.listen( "seeking", function() {
       _setup: function( options ) {
         
         options.codeReady = false;
-        
-        var readyCheck = function() {
-          if ( !processingLoaded ) {
-            load();
-          }
-        };
-        readyCheck();
+
         init( this );
       },