start: 2,
end: 10,
target: 'processing-div',
- sketch: 'test.pjs'
+ sketch: 'test.pjs',
+ noPause: true
} )
.processing({
start: 10,
end: 15,
target: 'processing-div2',
- sketch: 'test2.pjs'
+ sketch: 'test2.pjs',
+ noPause: false
} )
.processing({
start: 15,
end: 20,
sketch: 'test.pjs',
target: 'processing-div2',
+ noPause: true
} )
window.popped = p;
}, false);
</video>
</div>
<div id="processing-div" width="50%" height="50%">
- <hr />
</div>
<div id="processing-div2" width="50%" height="50%">
-
</div>
-
</body>
</html>
}
} else {
setTimeout ( function() {
- toggle.call ( this, on, options );
+ toggle.call( this, on, options );
}, 10 );
}
},
});
initProcessing = function() {
- if ( codeReady && window.Processing ) {
- options.pjsInstance = new Processing( options.canvas, processingCode );
+ var addListeners = function() {
popcorn.listen( "pause", function () {
if ( options.canvas.style.display === "inline" ) {
options.pjsInstance.noLoop();
options.pjsInstance.loop();
}
});
+ };
+
+ if ( codeReady && window.Processing ) {
+ options.pjsInstance = new Processing( options.canvas, processingCode );
+ !options.noPause && addListeners();
options.isReady = true;
+ options.isLooping = false;
} else {
setTimeout ( initProcessing, 10 );
}
options: {
start : { elem: "input", type: "text", label: "In" },
end : { elem: "input", type: "text", label: "Out" },
- control : { elem: "input", type: "text", label: "Control" },
target : { elem: "input", type: "text", label: "Target" },
sketch : { elem: "input", type: "text", label: "Sketch" },
- func : { elem: "input", type: "text", label: "Function" }
+ noPause : { elem: "select", options: [ "TRUE", "FALSE" ], label: "No Loop" }
}
},
},
start: function( event, options ) {
- toggle.call ( this, true, options );
+ toggle.call( this, true, options );
},
end: function( event, options ) {
- toggle.call ( this, false, options );
+ toggle.call( this, false, options );
}
};
});
<script src="popcorn.processing.unit.js"></script>
</head>
<body>
- <h1 id="qunit-header"></h1>
<h1 id="qunit-header">Popcorn processing Plug-in Demo</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
</video>
</div>
- <!--<div id="processing-div" width="50%" height="50%">
- <p> This is within a DIV and was created by sending a string in "sketch:</p>
- <p> > pause at 1 and resume at 5 seconds. </p>
- </div>
- <div id="processing-div2" width="50%" height="50%">
- <p> This is within a DIV and was created by sending a file in the sketch function</p>
- <p> > pause at 5 and resume at 10 seconds. Then Pause again at 20 to 25 seconds to test multiple instructions</p>
- </div>
- <p> This is within a Canvas and was created by it having it's own sketch file</p>
- <p> > pause at 10 and resume at 15 seconds. </p>
- <canvas id="processing-canvas2" datasrc="test2.pjs" width="100" height="100"></canvas></body>
-
- <hr>
- <strong> Call Function Test </strong>
- <div id="processing-div3" width="50%" height="50%">
- <p> This is within a DIV and was created by sending a file in the sketch function</p>
- <p> > change square to blue at 20 seconds. </p>
- </div>-->
+ <div id="processing-div" width="50%" height="50%"></div>
+ <div id="processing-div-2" width="50%" height="50%"></div>
+ <div id="processing-div-3" width="50%" height="50%"></div>
</html>
-//TODO: Write tests .. >.<
+test( "Processing plugin tests", function() {
+ var popped = Popcorn( "#video" ),
+ expects = 18,
+ count = 0,
+ processingDiv = document.getElementById( "processing-div" ),
+ processingDiv2= document.getElementById( "processing-div-2" ),
+ processingDiv3= document.getElementById( "processing-div-3" ),
+ canvases = [];
+
+ expect( expects );
+
+ function plus() {
+ if ( ++count === expects ) {
+ start();
+ }
+ }
+
+ stop();
+
+ ok( "processing" in popped, "processing is a method of the popped instance" );
+ plus();
+
+ equals( processingDiv.innerHTML, "", "'processing-div' is empty" );
+ plus();
+
+ equals( processingDiv2.innerHTML, "", "'processing-div-2' is empty" );
+ plus();
+
+ equals( processingDiv3.innerHTML, "", "'processing-div-3' is empty" );
+ plus();
+
+ popped.processing({
+ start: 0,
+ end: 3,
+ target: "processing-div",
+ sketch: "test.pjs"
+ })
+ .processing({
+ start: 4,
+ end: 7,
+ target: "processing-div-2",
+ sketch: "test2.pjs"
+ })
+ .processing({
+ start: 4,
+ end: 7,
+ target: "processing-div-3",
+ sketch: "test.pjs"
+ })
+ .exec( 1.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() {
+ 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" );
+ plus();
+ equals( processingDiv3.children[ 0 ].style.display, "inline", "canvas '" + processingDiv.children[ 0 ].id + "' is displayed" );
+ plus();
+ }).exec( 7.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" );
+ plus();
+ equals( processingDiv3.children[ 0 ].style.display, "none", "canvas '" + processingDiv.children[ 0 ].id + "' is hidden" );
+ plus();
+ });
+
+ //check that three canvases were created
+ canvases = document.getElementsByTagName( "canvas" );
+ equals( canvases.length, 3, "Three canvases are present" );
+ plus();
+
+ Popcorn.forEach( canvases, function( ctx ) {
+ var idCount = 0, i = -1, len = canvases.length;
+ for ( ; ++i < len; ){
+ if ( ctx.id === canvases[ i ].id ) {
+ idCount++;
+ }
+ }
+ equals( idCount, 1, ctx.id + " is a unique canvas id" );
+ plus();
+
+ equals( ctx.style.display, "none", ctx.id + " is hidden initially" );
+ plus();
+ });
+
+ popped.play();
+});