From: ScottDowne Date: Fri, 24 Jun 2011 17:33:34 +0000 (-0400) Subject: [#t612] processing.js loading fixes X-Git-Tag: v0.7^2~5^2~1 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=3db4172d790627b9f3eef7c1b0a2f1e12661b194;p=popcorn-js.git [#t612] processing.js loading fixes --- diff --git a/plugins/gml/popcorn.gml.js b/plugins/gml/popcorn.gml.js index b847657..03e027c 100755 --- a/plugins/gml/popcorn.gml.js +++ b/plugins/gml/popcorn.gml.js @@ -2,7 +2,9 @@ (function (Popcorn) { - var processingLoaded = false, + var processingLoader = { + readyState: 0 + }, gmlPlayer = function( $p ) { var _stroke = 0, @@ -122,11 +124,6 @@ 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 @@ -165,10 +162,27 @@ 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 ); diff --git a/plugins/processing/popcorn.processing.js b/plugins/processing/popcorn.processing.js index 708ae9a..bfb52f4 100644 --- a/plugins/processing/popcorn.processing.js +++ b/plugins/processing/popcorn.processing.js @@ -26,34 +26,27 @@ (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 ) { @@ -61,7 +54,23 @@ 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() { @@ -139,13 +148,7 @@ _setup: function( options ) { options.codeReady = false; - - var readyCheck = function() { - if ( !processingLoaded ) { - load(); - } - }; - readyCheck(); + init( this ); },