From: Christopher De Cairos Date: Mon, 20 Jun 2011 16:35:54 +0000 (-0400) Subject: fixed pause issue, style issues, tightened up unit tests, added documentation X-Git-Tag: v0.7^2~31^2~3 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=23bbf2719de3bc32cde53332dc170bcfbd261b38;p=popcorn-js.git fixed pause issue, style issues, tightened up unit tests, added documentation --- diff --git a/plugins/processing/popcorn.processing.html b/plugins/processing/popcorn.processing.html index c6ec6a6..e4974f0 100644 --- a/plugins/processing/popcorn.processing.html +++ b/plugins/processing/popcorn.processing.html @@ -2,7 +2,6 @@ Popcorn processing Plug-in Simple Demo - diff --git a/plugins/processing/popcorn.processing.js b/plugins/processing/popcorn.processing.js index e5d8277..3fee167 100644 --- a/plugins/processing/popcorn.processing.js +++ b/plugins/processing/popcorn.processing.js @@ -1,15 +1,37 @@ -// PLUGIN: Processing /** -* Processing popcorn plug-in -*/ + * 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. + * -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 + * -noLoop [optional] specifies whether a sketch should continue to loop when the video is paused or seeking. + * + * @param {Object} options + * + * Example: + var p = Popcorn( "#video" ) + .processing({ + start: 5, + end: 10, + target: "processing-div", + sketch: "processingSketch.pjs", + noLoop: true + }); + * + */ -(function (Popcorn) { +(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"; @@ -19,7 +41,7 @@ instance.noLoop(); } } else { - setTimeout ( function() { + setTimeout (function() { toggle.call( this, on, options ); }, 10 ); } @@ -39,12 +61,13 @@ var popcorn = context, initProcessing, parentTarget = document.getElementById( options.target ); + if ( parentTarget.tagName === "CANVAS" ) { options.canvas = parentTarget; } else if ( parentTarget.tagName === "DIV" ) { options.canvas = document.createElement( "canvas" ); // +new Date() is used here to create unique id's for canvas' within the same div. - options.canvas.id = options.target + "Sketch" + (+new Date()); + options.canvas.id = options.target + "Sketch" + ( +new Date() ); options.canvas.setAttribute( "data-processing-sources", options.sketch ); parentTarget.appendChild( options.canvas ); } @@ -65,7 +88,7 @@ if ( options.canvas.style.display === "inline" ) { options.pjsInstance.noLoop(); } - } ); + }); popcorn.listen( "play", function() { if ( options.canvas.style.display === "inline" ) { options.pjsInstance.loop(); @@ -75,7 +98,14 @@ if ( codeReady && window.Processing ) { options.pjsInstance = new Processing( options.canvas, processingCode ); - !options.noPause && addListeners(); + popcorn.listen( "seeking", function() { + if ( options.canvas.style.display === "inline" && options.noPause ) { + options.pjsInstance.loop(); + } + }); + + options.noPause = options.noPause || false; + !options.noPause && addListeners(); options.isReady = true; } else { setTimeout ( initProcessing, 10 ); diff --git a/plugins/processing/popcorn.processing.unit.js b/plugins/processing/popcorn.processing.unit.js index 2fc4813..01cd2dc 100644 --- a/plugins/processing/popcorn.processing.unit.js +++ b/plugins/processing/popcorn.processing.unit.js @@ -3,8 +3,8 @@ test( "Processing plugin tests", function() { expects = 18, count = 0, processingDiv = document.getElementById( "processing-div" ), - processingDiv2= document.getElementById( "processing-div-2" ), - processingDiv3= document.getElementById( "processing-div-3" ), + processingDiv2 = document.getElementById( "processing-div-2" ), + processingDiv3 = document.getElementById( "processing-div-3" ), canvases = []; expect( expects ); @@ -31,42 +31,42 @@ test( "Processing plugin tests", function() { popped.processing({ start: 0, - end: 3, + end: 1, target: "processing-div", sketch: "test.pjs" }) .processing({ - start: 4, - end: 7, + start: 1, + end: 3, target: "processing-div-2", sketch: "test2.pjs" }) .processing({ - start: 4, - end: 7, + start: 3, + end: 4, target: "processing-div-3", sketch: "test.pjs" }) - .exec( 1.5, function() { + .exec( 0.5, function() { equals( processingDiv.children[ 0 ].style.display, "inline", "canvas '" + processingDiv.children[ 0 ].id + "' is displayed" ); plus(); //TODO: David Humphrey has written code that allows for listening to events on Processing instances. when // it lands In the next processing release we'll be able to detect if a processing instance is looping or not. // this is required in order to test the noPause functionality (automatically) }) - .exec( 5, function() { + .exec( 1.5, function() { equals( processingDiv.children[ 0 ].style.display, "none", "canvas '" + processingDiv.children[ 0 ].id + "' is hidden" ); plus(); - equals( processingDiv2.children[ 0 ].style.display, "inline", "canvas '" + processingDiv.children[ 0 ].id + "' is displayed" ); + equals( processingDiv2.children[ 0 ].style.display, "inline", "canvas '" + processingDiv2.children[ 0 ].id + "' is displayed" ); plus(); - equals( processingDiv3.children[ 0 ].style.display, "inline", "canvas '" + processingDiv.children[ 0 ].id + "' is displayed" ); + equals( processingDiv3.children[ 0 ].style.display, "none", "canvas '" + processingDiv3.children[ 0 ].id + "' is hidden" ); plus(); - }).exec( 7.5, function() { + }).exec( 3.5, function() { equals( processingDiv.children[ 0 ].style.display, "none", "canvas '" + processingDiv.children[ 0 ].id + "' is hidden" ); plus(); - equals( processingDiv2.children[ 0 ].style.display, "none", "canvas '" + processingDiv.children[ 0 ].id + "' is hidden" ); + equals( processingDiv2.children[ 0 ].style.display, "none", "canvas '" + processingDiv2.children[ 0 ].id + "' is hidden" ); plus(); - equals( processingDiv3.children[ 0 ].style.display, "none", "canvas '" + processingDiv.children[ 0 ].id + "' is hidden" ); + equals( processingDiv3.children[ 0 ].style.display, "inline", "canvas '" + processingDiv3.children[ 0 ].id + "' is displayed" ); plus(); });