From 78363b6d806f2f4f1ca9b2e47d63cf9b45e81db7 Mon Sep 17 00:00:00 2001 From: Christopher De Cairos Date: Thu, 23 Jun 2011 11:47:39 -0400 Subject: [PATCH] can only target divs now. perf fixes. _teardown method + tests --- plugins/processing/popcorn.processing.html | 4 +- plugins/processing/popcorn.processing.js | 29 ++++++--- .../processing/popcorn.processing.unit.html | 6 +- plugins/processing/popcorn.processing.unit.js | 63 ++++++++++++------- 4 files changed, 63 insertions(+), 39 deletions(-) diff --git a/plugins/processing/popcorn.processing.html b/plugins/processing/popcorn.processing.html index 36ffe9d..94bb360 100644 --- a/plugins/processing/popcorn.processing.html +++ b/plugins/processing/popcorn.processing.html @@ -35,7 +35,7 @@ start: 5, end: 15, sketch: "test2.pjs", - target: "processing-canvas", + target: "processing-div", noPause: false }); }, false); @@ -67,6 +67,4 @@
- - diff --git a/plugins/processing/popcorn.processing.js b/plugins/processing/popcorn.processing.js index c6f3635..ae849e6 100644 --- a/plugins/processing/popcorn.processing.js +++ b/plugins/processing/popcorn.processing.js @@ -59,7 +59,14 @@ var init = function( context ) { - var parentTarget = document.getElementById( options.target ), + var initProcessing, + canvas; + + options.parentTarget = document.getElementById( options.target ); + + if ( !options.parentTarget ) { + throw ( "target container doesn't exist" ); + } initProcessing = function() { var addListeners = function() { @@ -92,15 +99,13 @@ } }; - if ( parentTarget.tagName === "CANVAS" ) { - options.canvas = parentTarget; - } else if ( parentTarget.tagName === "DIV" ) { - options.canvas = document.createElement( "canvas" ); - parentTarget.appendChild( options.canvas ); - } - options.canvas.id = Popcorn.guid( options.target + "-sketch-" ); - options.canvas.setAttribute( "data-processing-sources", options.sketch ); - options.canvas.style.display = "none"; + 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.appendChild( options.canvas ); Popcorn.xhr({ url: options.sketch, @@ -150,6 +155,10 @@ end: function( event, options ) { toggle.call( this, false, options ); + }, + + _teardown: function( options ) { + options.parentTarget && options.parentTarget.removeChild( options.canvas ); } }; }); diff --git a/plugins/processing/popcorn.processing.unit.html b/plugins/processing/popcorn.processing.unit.html index a82a073..6dd7ad7 100644 --- a/plugins/processing/popcorn.processing.unit.html +++ b/plugins/processing/popcorn.processing.unit.html @@ -34,10 +34,8 @@ -
+
-
- -
+
diff --git a/plugins/processing/popcorn.processing.unit.js b/plugins/processing/popcorn.processing.unit.js index 42753aa..e68c6be 100644 --- a/plugins/processing/popcorn.processing.unit.js +++ b/plugins/processing/popcorn.processing.unit.js @@ -1,12 +1,13 @@ test( "Processing plugin tests", function() { var popped = Popcorn( "#video" ), - expects = 26, + expects = 31, count = 0, - processingDiv = document.getElementById( "processing-div" ), + processingDiv = document.getElementById( "processing-div-1" ), processingDiv2 = document.getElementById( "processing-div-2" ), processingDiv3 = document.getElementById( "processing-div-3" ), - processingCanvas = document.getElementById( "processing-canvas" ), - canvases = []; + processingDiv4 = document.getElementById( "processing-div-4" ), + canvases = [], + trackids = []; expect( expects ); @@ -21,7 +22,7 @@ test( "Processing plugin tests", function() { ok( "processing" in popped, "processing is a method of the popped instance" ); plus(); - equals( processingDiv.innerHTML, "", "'processing-div' is empty" ); + equals( processingDiv.innerHTML, "", "'processing-div-1' is empty" ); plus(); equals( processingDiv2.innerHTML, "", "'processing-div-2' is empty" ); @@ -30,41 +31,49 @@ test( "Processing plugin tests", function() { equals( processingDiv3.innerHTML, "", "'processing-div-3' is empty" ); plus(); - ok( processingCanvas, "'processing-canvas' is present in DOM" ); + equals( processingDiv4.innerHTML, "", "'processing-div-4' is empty" ); plus(); popped.processing({ start: 0, end: 1, - target: "processing-div", + target: "processing-div-1", sketch: "test.pjs" - }) - .processing({ + }); + trackids.push( popped.getLastTrackEventId() ); + + popped.processing({ start: 1, end: 3, target: "processing-div-2", sketch: "test2.pjs" - }) - .processing({ + }); + trackids.push( popped.getLastTrackEventId() ); + + popped.processing({ start: 3, end: 4, target: "processing-div-3", sketch: "test.pjs" - }) - .processing({ + }); + trackids.push( popped.getLastTrackEventId() ); + + popped.processing({ start: 3, end: 4, - target: "processing-canvas", + target: "processing-div-4", sketch: "test2.pjs" - }) - .exec( 0.5, function() { + }); + trackids.push( popped.getLastTrackEventId() ); + + popped.exec( 0.5, function() { equals( processingDiv.children[ 0 ].style.display, "inline", "canvas '" + processingDiv.children[ 0 ].id + "' is displayed" ); plus(); equals( processingDiv2.children[ 0 ].style.display, "none", "canvas '" + processingDiv2.children[ 0 ].id + "' is hidden" ); plus(); equals( processingDiv3.children[ 0 ].style.display, "none", "canvas '" + processingDiv3.children[ 0 ].id + "' is hidden" ); plus(); - equals( processingCanvas.style.display, "none", "canvas '" + processingCanvas.id + "' is hidden" ); + equals( processingDiv4.children[ 0 ].style.display, "none", "canvas '" + processingDiv4.children[ 0 ].id + "' is hidden" ); 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. @@ -77,7 +86,7 @@ test( "Processing plugin tests", function() { plus(); equals( processingDiv3.children[ 0 ].style.display, "none", "canvas '" + processingDiv3.children[ 0 ].id + "' is hidden" ); plus(); - equals( processingCanvas.style.display, "none", "canvas '" + processingCanvas.id + "' is hidden" ); + equals( processingDiv4.children[ 0 ].style.display, "none", "canvas '" + processingDiv4.children[ 0 ].id + "' is hidden" ); plus(); }).exec( 3.5, function() { equals( processingDiv.children[ 0 ].style.display, "none", "canvas '" + processingDiv.children[ 0 ].id + "' is hidden" ); @@ -86,17 +95,27 @@ test( "Processing plugin tests", function() { plus(); equals( processingDiv3.children[ 0 ].style.display, "inline", "canvas '" + processingDiv3.children[ 0 ].id + "' is displayed" ); plus(); - equals( processingCanvas.style.display, "inline", "canvas '" + processingCanvas.id + "' is displayed" ); + equals( processingDiv4.children[ 0 ].style.display, "inline", "canvas '" + processingDiv4.children[ 0 ].id + "' is displayed" ); plus(); + }).exec( 4.5, function() { + var idx = 5, div, id; + while ( --idx ) { + div = document.getElementById( "processing-div-" + ( idx ) ); + id = trackids.pop(); + popped.removeTrackEvent( id ); + ok ( !div.children[0], "track event was removed" ); + plus(); + } }); - //check that three canvases were created + ok( "processing" in popped, "processing is a method of the popped instance" ); + plus(); + + //check that four canvases were created canvases = document.querySelectorAll( "canvas" ); equals( canvases.length, 4, "four canvases are present" ); plus(); - var called = 0; - //enable this when ticket #583 lands //Popcorn.forEach( canvases, function( ctx, idx ) { [].forEach.call( canvases, function( ctx ) { -- 2.43.0