From: Anna Sobiepanek Date: Fri, 7 Jan 2011 20:43:05 +0000 (-0500) Subject: tagThisPerson plugin with simple tests [#247 state:peer-review-requested] X-Git-Tag: v0.2~15^2~1^2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=d8dbe33a77612b2b51142aa91880aa33ce7880ce;p=popcorn-js.git tagThisPerson plugin with simple tests [#247 state:peer-review-requested] --- diff --git a/plugins/tagThisPerson/popcorn.tagThisPerson.html b/plugins/tagThisPerson/popcorn.tagThisPerson.html new file mode 100644 index 0000000..b746292 --- /dev/null +++ b/plugins/tagThisPerson/popcorn.tagThisPerson.html @@ -0,0 +1,62 @@ + + + + Popcorn tagThisPerson Plug-in Demo + + + + + + +

Popcorn tagThisPerson Plug-in Demo

+

A tag displaying Scott will appear at 0 seconds and disappear at 15 seconds.

+

A separate tag displaying Anna Sob will appear at 0 seconds and disappear at 10 seconds. At 5 seconds Scott will be appended to this tag.

+
+ +
+
+ +
+ + + diff --git a/plugins/tagThisPerson/popcorn.tagThisPerson.js b/plugins/tagThisPerson/popcorn.tagThisPerson.js new file mode 100644 index 0000000..de08976 --- /dev/null +++ b/plugins/tagThisPerson/popcorn.tagThisPerson.js @@ -0,0 +1,99 @@ +// PLUGIN: tagThisPerson + +(function (Popcorn) { + + /** + * tagThisPerson popcorn plug-in + * Adds people's names to an element on the page. + * Options parameter will need a start, end, target and person. + * 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 + * Person is the name of the person who you want to tag + * Target is the id of the document element that the text needs to be + * attached to, this target element must exist on the DOM + * + * @param {Object} options + * + * Example: + var p = Popcorn('#video') + .tagThisPerson({ + start: 5, // seconds + end: 15, // seconds + person: '@annasob', + target: 'tagdiv' + } ) + * + */ + Popcorn.plugin( "tagThisPerson" , (function(){ + + var peopleArray = []; + var People = function(){ + this.name = ""; + this.contains = {}; + this.toString = function(target) { + var r = []; + for ( var j in this.contains) { + if (this.contains.hasOwnProperty(j)) { + r.push(" " + this.contains[j]); + } + } + return r.toString(); + }; + }; + + return { + manifest: { + about:{ + name: "Popcorn tagThisPerson Plugin", + version: "0.1", + author: "@annasob", + website: "annasob.wordpress.com" + }, + options:{ + start : {elem:'input', type:'text', label:'In'}, + end : {elem:'input', type:'text', label:'Out'}, + target : 'tag-container', + text : {elem:'input', type:'text', label:'Text'} + } + }, + _setup: function(options) { + var exists = false; + // loop through the existing objects to ensure no duplicates + // the idea here is to have one object per unique options.target + for (var i = 0; i< peopleArray.length; i++) { + if (peopleArray[i].name === options.target ) { + options._p = peopleArray[i]; + exists = true; + break; + } + } + if (!exists) { + options._p = new People(); + options._p.name = options.target; + peopleArray.push(options._p ); + } + }, + /** + * @member tagThisPerson + * 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._p.contains[options.person] = options.person; + document.getElementById(options.target).innerHTML = options._p.toString(); + }, + /** + * @member tagThisPerson + * 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){ + delete options._p.contains[options.person]; + document.getElementById(options.target).innerHTML = options._p.toString(); + } + }; + })()); + +})( Popcorn ); \ No newline at end of file diff --git a/plugins/tagThisPerson/popcorn.tagThisPerson.unit.html b/plugins/tagThisPerson/popcorn.tagThisPerson.unit.html new file mode 100644 index 0000000..43e90b7 --- /dev/null +++ b/plugins/tagThisPerson/popcorn.tagThisPerson.unit.html @@ -0,0 +1,43 @@ + + + + Popcorn tagThisPerson test + + + + + + + + + + +

Popcorn tagThisPerson Plugin

+

+
+

+
    +
    + + +
    + + diff --git a/plugins/tagThisPerson/popcorn.tagThisPerson.unit.js b/plugins/tagThisPerson/popcorn.tagThisPerson.unit.js new file mode 100644 index 0000000..fc6ae2c --- /dev/null +++ b/plugins/tagThisPerson/popcorn.tagThisPerson.unit.js @@ -0,0 +1,73 @@ +test("Popcorn tagThisPerson Plugin", function () { + + var popped = Popcorn("#video"), + expects = 6, + count = 0, + interval, + interval2, + interval3, + tagdiv = document.getElementById('tagdiv'); + + expect(expects); + + function plus() { + if ( ++count===expects) { + start(); + } + } + + stop(); + + ok ('tagThisPerson' in popped, "tagThisPerson is a method of the popped instance"); + plus(); + + equals ( tagdiv.innerHTML, "", "initially, there is nothing inside the tagdiv" ); + plus(); + + popped.tagThisPerson({ + start: 0, // seconds + end: 5, // seconds + person: 'Anna Sob', + target: 'tagdiv' + } ) + .tagThisPerson({ + start: 3, // seconds + end: 10, // seconds + person: 'Scott', + target: 'tagdiv' + } ) + .volume(0) + .play(); + + + interval = setInterval( function() { + if( popped.currentTime() > 0 && popped.currentTime() <= 5 ) { + equals ( tagdiv.innerHTML.trim() , "Anna Sob" ,"tagdiv shows the first tag" ); + plus(); + clearInterval( interval ); + } + }, 2000); + + interval2 = setInterval( function() { + if( popped.currentTime() > 3 && popped.currentTime() < 5 ) { + equals ( tagdiv.innerHTML.trim() , "Anna Sob, Scott", "tagdiv shows the first & second tag" ); + plus(); + clearInterval( interval2 ); + } + }, 2000); + + interval3 = setInterval( function() { + if( popped.currentTime() > 5) { + equals ( tagdiv.innerHTML.trim() , "Scott" ,"tagdiv shows the second tag only" ); + plus(); + clearInterval( interval3 ); + } + }, 5000); + interval4 = setInterval( function() { + if( popped.currentTime() > 10) { + equals ( tagdiv.innerHTML , "" ,"tagdiv is now cleared" ); + plus(); + clearInterval( interval4 ); + } + }, 4000); +});