From: Anna Sobiepanek Date: Thu, 9 Dec 2010 22:06:45 +0000 (-0500) Subject: added footnote plugin and unit tests [#167 state:peer-review-requested] X-Git-Tag: v0.2~53^2~1 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=e090e78566909df3a78aecc8540044def7a74568;p=popcorn-js.git added footnote plugin and unit tests [#167 state:peer-review-requested] --- diff --git a/plugins/footnote/popcorn.footnote.html b/plugins/footnote/popcorn.footnote.html new file mode 100644 index 0000000..0f9e0c4 --- /dev/null +++ b/plugins/footnote/popcorn.footnote.html @@ -0,0 +1,54 @@ + + + + Popcorn footnote Plug-in Demo + + + + + + +

Popcorn Footnore Plug-in Demo

+

A footnote displaying This video made exclusively for drumbeat.org' will appear at 5 seconds and disappear at 15 seconds.

+

A footnote displaying 'Visit webmademovies.org for more details' will appear at 20 seconds and disappear at 45 seconds.

+
+ +
+
+
+ + diff --git a/plugins/footnote/popcorn.footnote.js b/plugins/footnote/popcorn.footnote.js new file mode 100644 index 0000000..b4d90a7 --- /dev/null +++ b/plugins/footnote/popcorn.footnote.js @@ -0,0 +1,58 @@ +// PLUGIN: WEBPAGE + +(function (Popcorn) { + + /** + * Footnote popcorn plug-in + * Adds text to an element on the page. + * Options parameter will need a start, end, target and text. + * 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 + * Text is the text that you want to appear in the target + * Target is the id of the document element that the text needs to be + * attached to, this target element must exist on the DOM + * + * Note: anything in the target element will be overwritten by the text + * specified by the user + * @param {Object} options + * + * Example: + var p = Popcorn('#video') + .footnote({ + start: 5, // seconds + end: 15, // seconds + text: 'This video made exclusively for drumbeat.org', + target: 'footnotediv' + } ) + * + */ + Popcorn.plugin( "footnote" , (function(){ + + var temp; + + return { + /** + * @member webpage + * 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){ + temp = document.getElementById( options.target ); + temp.innerHTML = options.text; + }, + /** + * @member webpage + * 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){ + temp.innerHTML = ""; + } + + }; + + })()); + +})( Popcorn ); \ No newline at end of file diff --git a/plugins/footnote/popcorn.footnote.unit.html b/plugins/footnote/popcorn.footnote.unit.html new file mode 100644 index 0000000..6777a99 --- /dev/null +++ b/plugins/footnote/popcorn.footnote.unit.html @@ -0,0 +1,43 @@ + + + + Popcorn API + + + + + + + + + + +

Popcorn Footnote Plugin

+

+
+

+
    +
    + + +
    + + diff --git a/plugins/footnote/popcorn.footnote.unit.js b/plugins/footnote/popcorn.footnote.unit.js new file mode 100644 index 0000000..12fe5e3 --- /dev/null +++ b/plugins/footnote/popcorn.footnote.unit.js @@ -0,0 +1,66 @@ +test("Popcorn Footnote Plugin", function () { + + var popped = Popcorn("#video"), + expects = 5, + count = 0, + iframeInterval, + iframeInterval2, + iframeInterval3, + iframeInterval4; + + expect(expects); + + function plus() { + if ( ++count===expects) { + start(); + } + } + + stop(); + + ok ('footnote' in popped, "footnote is a mehtod of the popped instance"); + plus(); + + ok ( document.getElementById('footnotediv').innerHTML === "", "initially, there is nothing inside the footnotediv" ); + plus(); + + popped.footnote({ + start: 5, // seconds + end: 15, // seconds + text: 'This video made exclusively for drumbeat.org', + target: 'footnotediv' + } ) + .footnote({ + start: 35, // seconds + end: 45, // seconds + text: 'Visit webmademovies.org for more details', + target: 'footnotediv' + } ) + .play(); + + + interval = setInterval( function() { + if( popped.currentTime() > 5 && popped.currentTime() <= 15 ) { + ok (document.getElementById('footnotediv').innerHTML === "This video made exclusively for drumbeat.org", "footnote displaing correct information" ); + plus(); + clearInterval( interval ); + } + }, 5000); + + interval2 = setInterval( function() { + if( popped.currentTime() > 15 && popped.currentTime() < 35 ) { + ok (document.getElementById('footnotediv').innerHTML === "", "footnote cleared properly" ); + plus(); + clearInterval( interval2 ); + } + }, 5000); + + interval3 = setInterval( function() { + if( popped.currentTime() > 35 && popped.currentTime() < 45 ) { + ok (document.getElementById('footnotediv').innerHTML === "Visit webmademovies.org for more details", "footnote displaing correct information" ); + plus(); + clearInterval( interval3 ); + } + }, 5000); + +});