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() {
}
};
- 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,
end: function( event, options ) {
toggle.call( this, false, options );
+ },
+
+ _teardown: function( options ) {
+ options.parentTarget && options.parentTarget.removeChild( options.canvas );
}
};
});
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 );
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" );
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.
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" );
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 ) {