From: Christopher De Cairos Date: Wed, 14 Sep 2011 18:12:26 +0000 (-0400) Subject: processing plug-in no longer polls for Processing. X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=bb93ef31087241c5646376e792294cece163bb4c;p=popcorn-js.git processing plug-in no longer polls for Processing. --- diff --git a/plugins/processing/popcorn.processing.js b/plugins/processing/popcorn.processing.js index de7923e..f15656b 100644 --- a/plugins/processing/popcorn.processing.js +++ b/plugins/processing/popcorn.processing.js @@ -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 @@ -25,11 +25,9 @@ */ (function ( Popcorn ) { - - var called = false; Popcorn.plugin( "processing" , function ( options ) { - + var init = function( context ) { function scriptReady( options ) { @@ -45,62 +43,44 @@ } }); }; - + 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 ); } }; @@ -108,21 +88,20 @@ 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 ); @@ -136,11 +115,11 @@ }, 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 );