From: ScottDowne Date: Wed, 22 Dec 2010 20:12:58 +0000 (-0500) Subject: [#63] image plugin with unit tests X-Git-Tag: v0.2~22^2~5^2~4 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=842d7a17d91b69020d0ddb76f0a363edd9b31a9d;p=popcorn-js.git [#63] image plugin with unit tests --- diff --git a/plugins/image/popcorn.image.html b/plugins/image/popcorn.image.html new file mode 100644 index 0000000..2ce3a7c --- /dev/null +++ b/plugins/image/popcorn.image.html @@ -0,0 +1,56 @@ + + + + Popcorn Image Plug-in Demo + + + + + + +

Popcorn Image Plug-in Demo

+

An image will appear at 5 seconds and disappear at 15 seconds.

+

An image will appear at 20 seconds and disappear at 45 seconds.

+
+ +
+
+
+ + diff --git a/plugins/image/popcorn.image.js b/plugins/image/popcorn.image.js new file mode 100644 index 0000000..8a71319 --- /dev/null +++ b/plugins/image/popcorn.image.js @@ -0,0 +1,84 @@ +// PLUGIN: IMAGE + +(function (Popcorn) { + + /** + * Images popcorn plug-in + * Creates an iframe showing a website specified by the user + * Options parameter will need a start, end, id, target and src. + * Start is the time that you want this plug-in to execute + * End is the time that you want this plug-in to stop executing + * href is the url of the destination of a link + * Target is the id of the document element that the iframe needs to be attached to, + * this target element must exist on the DOM + * Src is the url of the image that you want to display + * + * @param {Object} options + * + * Example: + var p = Popcorn('#video') + .image({ + start: 5, // seconds + end: 15, // seconds + href: 'http://www.drumbeat.org/', + src: 'http://www.drumbeat.org/sites/default/files/domain-2/drumbeat_logo.png', + target: 'imagediv' + } ) + * + */ + Popcorn.plugin( "image", { + + manifest: { + about:{ + name: "Popcorn image Plugin", + version: "0.1", + author: "Scott Downe", + website: "http://scottdowne.wordpress.com/" + }, + options:{ + start : {elem:'input', type:'number', label:'In'}, + end : {elem:'input', type:'number', label:'Out'}, + href : {elem:'input', type:'text', label:'URL'}, + target : {elem:'input', type:'text', label:'HTML Element id'}, + src : {elem:'input', type:'text', label:'URL'} + } + }, + + _setup: function( options ) { + + options.link = document.createElement( 'a' ); + options.link.style.display = "none"; // display none by default + options.link.href = options.href; + options.link.target = "_blank"; + + document.getElementById( options.target ).appendChild( options.link ); // add the widget's div to the target div + + var img = document.createElement( 'img' ); + img.src = options.src; + + options.link.appendChild( img ); + + }, + + /** + * @member image + * The start function will be executed when the currentTime + * of the video reaches the start time provided by the + * options variable + */ + start: function( event, options ) { + options.link.style.display = "inline"; + }, + /** + * @member image + * The end function will be executed when the currentTime + * of the video reaches the end time provided by the + * options variable + */ + end: function( event, options ) { + options.link.style.display = "none"; + } + + }); + +})( Popcorn ); diff --git a/plugins/image/popcorn.image.unit.html b/plugins/image/popcorn.image.unit.html new file mode 100644 index 0000000..dc0f28d --- /dev/null +++ b/plugins/image/popcorn.image.unit.html @@ -0,0 +1,43 @@ + + + + Popcorn API + + + + + + + + + + +

Popcorn Webpage UI

+

+
+

+
    +
    + + +
    + + diff --git a/plugins/image/popcorn.image.unit.js b/plugins/image/popcorn.image.unit.js new file mode 100644 index 0000000..e0238b5 --- /dev/null +++ b/plugins/image/popcorn.image.unit.js @@ -0,0 +1,54 @@ +test("Popcorn Image Plugin", function () { + + var popped = Popcorn("#video"), + expects = 5, + count = 0, + interval, + interval2, + imagediv = document.getElementById('imagediv'); + + expect( expects ); + + function plus() { + if ( ++count === expects) { + start(); + } + } + + stop(); + + ok('image' in popped, "image is a method of the popped instance"); + plus(); + + equals ( imagediv.innerHTML, "", "initially, there is nothing inside the imagediv" ); + plus(); + + popped.image({ + start: 1, // seconds + end: 3, // seconds + href: 'http://www.drumbeat.org/', + src: 'http://www.drumbeat.org/sites/default/files/domain-2/drumbeat_logo.png', + target: 'imagediv' + } ); + + interval = setInterval( function() { + if( popped.currentTime() > 1 && popped.currentTime() < 3 ) { + ok( /display: inline;/.test( imagediv.innerHTML ), "Div contents are displayed" ); + plus(); + ok( /img/.test( imagediv.innerHTML ), "An image exists" ); + plus(); + clearInterval( interval ); + } + }, 500); + + interval2 = setInterval( function() { + if( popped.currentTime() > 3 ) { + ok( /display: none;/.test( imagediv.innerHTML ), "Div contents are hidden again" ); + plus(); + clearInterval( interval2 ); + } + }, 500); + + popped.play(); + +});