From: Anna Sobiepanek Date: Sun, 5 Dec 2010 17:53:40 +0000 (-0500) Subject: rework and added unit tests [#160] X-Git-Tag: v0.2~69 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=1f3fd808513c878a9c82b247d8d7c1771f6ace7a;p=popcorn-js.git rework and added unit tests [#160] --- diff --git a/plugins/webpage/popcorn.webpage.html b/plugins/webpage/popcorn.webpage.html new file mode 100644 index 0000000..3363d04 --- /dev/null +++ b/plugins/webpage/popcorn.webpage.html @@ -0,0 +1,35 @@ + + + + Popcorn WebPage Plug-in Demo + + + + + + +

Popcorn WebPage Plug-in Demo

+

A Webpage displaying webmademovies.org will appear at 2 seconds and disappear at 5 seconds.

+
+ +
+
+ +
+ + diff --git a/plugins/webpage/popcorn.webpage.js b/plugins/webpage/popcorn.webpage.js new file mode 100644 index 0000000..b582552 --- /dev/null +++ b/plugins/webpage/popcorn.webpage.js @@ -0,0 +1,54 @@ +(function (Popcorn) { + /** + * Webpages popcorn plug-in + * Creates an iframe showing a website specified by the user + * Options parameter will need a start, duration or out, and src. + * Start is the time that you want this plug-in to execute + * Out is the time that you want this plug-in to stop executing [not currently implemented] + * Duration can be used instead of out to state how long you want the plug-in to execute for + * Target is the id of the document element that the iframe needs to be attached to + * @param {Object} options + * @param {Object} object element to be added to the list + */ + Popcorn.plugin( "webpages" , function ( options ) { + + var iframe = document.createElement('iframe'), + page = [], + context = this.video; + + // set the style of the iframe + iframe.setAttribute('width', "100%"); + iframe.setAttribute('height', "100%"); + + + + // get the options that the user included + if ( typeof options === "object" && "join" in options ) { + page = options; + } else { + page.push(options); + } + + this.listen("timeupdate", function (event) { + // loop threw all of the webpages + Popcorn.forEach(page, function ( thispage ) { + + var temp = document.getElementById( thispage.target ); + iframe.setAttribute('id', thispage.id); + var exists = document.getElementById( thispage.id ); + + if ( this.currentTime() >= thispage.start && !exists && this.currentTime() <= thispage.end) { + //div.innerHTML = div.innerHTML + thispage.html; + // set the source of the webpage that this plugin should display + iframe.setAttribute('src', thispage.src); + temp.appendChild(iframe); + } + + if ( this.currentTime() >= thispage.end && exists) { + temp.removeChild(iframe); + } + }, this); + }); + }); + +})(Popcorn); \ No newline at end of file diff --git a/plugins/webpage/popcorn.webpage.unit.html b/plugins/webpage/popcorn.webpage.unit.html new file mode 100644 index 0000000..58ed2aa --- /dev/null +++ b/plugins/webpage/popcorn.webpage.unit.html @@ -0,0 +1,51 @@ + + + + Popcorn API + + + + + + + + + + + +

Popcorn Webpage UI

+

+
+

+
    +
    + + + + + +
    + + + + + + diff --git a/plugins/webpage/popcorn.webpage.unit.js b/plugins/webpage/popcorn.webpage.unit.js new file mode 100644 index 0000000..e094fd6 --- /dev/null +++ b/plugins/webpage/popcorn.webpage.unit.js @@ -0,0 +1,21 @@ +$(function(){ + + test("Popcorn Webpage Plugin", function () { + + + // needs expectation + + var popped = Popcorn("#video"); + + popped.webpages(); + + + ok( 'data' in popped, "popped has the data prop and therefore is a Popcorn object" ) + + ok( 'webpages' in popped, "webpages is a mehtod of the popped instance"); + + ok( typeof popped.webpages === "function" , "webpages is in the plugins registry"); + + + }); +}); \ No newline at end of file diff --git a/plugins/webpage/webpage.js b/plugins/webpage/webpage.js new file mode 100644 index 0000000..7578d52 --- /dev/null +++ b/plugins/webpage/webpage.js @@ -0,0 +1,15 @@ +document.addEventListener('DOMContentLoaded', function () { + var p = Popcorn('#video'); + + p.play(); + + + p.webpages({ + id: "webpages-a", + start: 2, // seconds + end: 5, // seconds + src: 'http://www.webmademovies.org', + target: 'webpagediv' + }); + +}, false);