From: Christopher De Cairos Date: Tue, 27 Sep 2011 14:52:18 +0000 (-0400) Subject: Fixed issue in popcorndocs plugin, added unit tests X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=refs%2Fheads%2Ft627;p=popcorn-js.git Fixed issue in popcorndocs plugin, added unit tests --- diff --git a/plugins/popcorndoc/popcorn.popcorndoc.html b/plugins/popcorndoc/popcorn.popcorndoc.html new file mode 100644 index 0000000..9b23885 --- /dev/null +++ b/plugins/popcorndoc/popcorn.popcorndoc.html @@ -0,0 +1,58 @@ + + + + Popcorn popcorndoc Plug-in Demo + + + + + + +

Popcorn popcorndoc Plug-in Demo

+
+ +
+
+
+ + diff --git a/plugins/popcorndoc/popcorn.popcorndoc.js b/plugins/popcorndoc/popcorn.popcorndoc.js new file mode 100644 index 0000000..7791d38 --- /dev/null +++ b/plugins/popcorndoc/popcorn.popcorndoc.js @@ -0,0 +1,247 @@ +// PLUGIN: popcorndoc + +(function (Popcorn) { + + /** + * Github Gist popcorn plug-in + * Loads and allows lines of code in a gist to be highlighted, and examples run. + * + * @param {Object} options + * + * Example: + * var p = Popcorn('#video') + * .popcorndoc({ + * start: 5, // seconds + * end: 15, // seconds + * lines: '25', // line(s) to highlight and show + * target: 'gist-container', // DIV in which to load gist + * gistUrl: 'https://gist.github.com/289467' // URL of gist + * }) + * // The specified "line" can also be a list + * .popcorndoc({ + * start: 20, // seconds + * end: 25, // seconds + * lines: '26,29-32', // line(s) to highlight and show + * target: 'gist-container', // DIV in which to load gist + * gistUrl: 'https://gist.github.com/289467' // URL of gist + * }) + * // Highlighting can be removed + * .popcorndoc({ + * start: 20, // seconds + * end: 25, // seconds + * lines: null // line(s) to highlight and show + * target: 'gist-container', // DIV in which to load gist + * gistUrl: 'https://gist.github.com/289467' // URL of gist + * }); + * // Run the example. NOTE: should be last gist track. + * .popcorndoc({ + * start: 29, // seconds + * target: 'gist-container', // DIV in which to load gist + * gistUrl: 'https://gist.github.com/289467', // URL of gist + * runIn: 'iframe-container-div' // DIV in which to load the example in an iframe + * }); + */ + + /** + * script.js - https://github.com/kares/script.js + * + * http://www.apache.org/licenses/LICENSE-2.0.html + * @version 0.7-SNAPSHOT + */ +var script=function(){function n(e,b){var d=e.loaded,a=e.complete;if(e.defer){var c=document.createElement("script");c.src=e.src;if(e.type)c.type=e.type;e.charset&&c.setAttribute("charset",e.charset);var g=function(){if(!(d&&d.call(c,e.writes?h||void 0:void 0)===!1)){var b=document.getElementById(e.id);if(e.writes&&h){var g=function(a){c.nextSibling?c.parentNode.insertBefore(a,c.nextSibling):c.parentNode.appendChild(a)};b||(b=document.createElement("div"),g(b));b.style.display="none";b.innerHTML= +"
"+h.join("");b.removeChild(b.childNodes[0]);for(var f=b.childNodes[0];f;)b.removeChild(f),g(f),f=b.childNodes[0]}b&&b.parentNode.removeChild(b);a&&a.call(c)}},f=!1;c.onload=c.onreadystatechange=function(){if(!f&&(!this.readyState||this.readyState==="loaded"||this.readyState==="complete")){f=!0;c.onload=c.onreadystatechange=null;try{g()}finally{b&&b()}}};e.append(c)}else{c=document.getElementById(e.id);try{var i;d&&(i=d.call(c));i!==!1&&a&&a.call(c)}finally{if(e.idGenerated)c.id=null;b&&b()}}} +function i(){if(f&&!f.loading)f.loading=!0,function b(){if(f.length){var d=f.shift();if(d)if(d.writes){if(!j)j=document.write;if(!k)k=document.writeln;document.write=o;document.writeln=p;h=null;n(d,function(){if(j)document.write=j;if(k)document.writeln=k;h=k=j=null;b()})}else n(d),b();else b()}else delete f.loading}()}var h=null,o=function(){var e=arguments;e&&e[0]&&(h||(h=[]),h.push(e[0]))},p=function(e){o(e+"\n")},j,k,f=[],g,l=function(){g&&(g=null,i())};if(document.addEventListener)g=function(){document.removeEventListener("DOMContentLoaded", +g,!1);g=null;i()},document.addEventListener("DOMContentLoaded",g,!1),window.addEventListener("load",l,!1);else if(document.attachEvent){g=function(){document.readyState==="complete"&&(document.detachEvent("onreadystatechange",g),g=null,i())};document.attachEvent("onreadystatechange",g);window.attachEvent("onload",l);l=!1;try{l=window.frameElement==null}catch(r){}document.documentElement.doScroll&&l&&function b(){if(g){try{document.documentElement.doScroll("left")}catch(d){setTimeout(b,1);return}i()}}()}var m= +function(b){if(!b)throw"script : no arguments given";if(typeof b==="string")b={src:b};else if(!b.src)throw"script : 'src' is required";var d,a={},c=m.defaults;if(c)for(d in c)a[d]=c[d];for(d in b)a[d]=b[d];if(a.base&&a.src.substring(0,4)!=="http")d=a.base,c=a.base.length-1,d=d[c]=="/"?d.substring(0,c):d,a.src=d+"/"+a.src;if(a.onload!=null)a.onLoad=a.onLoad!=null?b.onload!=null?b.onload:b.onLoad!=null?b.onLoad:a.onload:a.onload,delete a.onload;if(typeof a.defer==="undefined")a.defer=a.onLoad;if(!a.id)a.id= +m._generateId(),a.idGenerated=!0;var h=a.append;if(typeof h==="string")a.append=function(a){document.getElementById(h).appendChild(a)};else if(h&&h.appendChild)a.append=function(a){h.appendChild(a)};if(a.writes==null)a.writes=!0;if(g){if(a.defer){if(b='
"+a.loadingHTML:' style="diplay: none;">',b+="
",!a.append)a.append=function(b){var c=document.getElementById(a.id);c.parentNode.insertBefore(b,c)}}else b=' + + + + + + + + +

Popcorn popcorndocs Plugin

+

+
+

+
    +
    + + +
    + + diff --git a/plugins/popcorndoc/popcorn.popcorndoc.unit.js b/plugins/popcorndoc/popcorn.popcorndoc.unit.js new file mode 100644 index 0000000..11222a2 --- /dev/null +++ b/plugins/popcorndoc/popcorn.popcorndoc.unit.js @@ -0,0 +1,157 @@ +test( "popcorndoc existence", function(){ + + var popped = Popcorn( "#video" ).pause(); + + var expects = 2, + count = 0, + + plus = function() { + if ( ++count === expects ) { + start(); + Popcorn.destroy( popped ); + } + }; + + expect( expects ); + stop(); + + ok( popped.popcorndoc, "popcorndoc exists:" ); + plus(); + equals( typeof popped.popcorndoc, "function" , "Popcorn.popcorndoc is a function" ); + plus(); + +}); + +test( "popcorndoc functional tests", function() { + + var popped = Popcorn( "#video" ); + popped.pause().volume( 0 ); + + var expects = 20, + count = 0, + + plus = function() { + if ( ++count === expects ) { + Popcorn.destroy( popped ); + start(); + } + }; + + stop(); + + popped.popcorndoc({ + start: 1, + end: 2, + lines: '1', + target: 'gistdiv', + gistUrl: 'https://gist.github.com/289467' + }) + .popcorndoc({ + start: 1, + end: 2, + lines: '3-5', + target: 'gistdiv', + gistUrl: 'https://gist.github.com/289467' + }) + .popcorndoc({ + start: 2, + end: 3, + lines: '2,6-8', + target: 'gistdiv', + gistUrl: 'https://gist.github.com/289467' + }) + .popcorndoc({ + start: 3, + end: 4, + lines: '15-10', + target: 'gistdiv', + gistUrl: 'https://gist.github.com/289467' + }); + + var line, + lines = [], + i = 0; + + while( line = document.getElementById( "LC" + ( ++i ) ) ) { + lines.push( line ); + } + + popped.exec( 1.5, function() { + var line1 = document.getElementById( "LC1" ), + line3 = document.getElementById( "LC3" ), + line4 = document.getElementById( "LC4" ), + line5 = document.getElementById( "LC5" ); + + ok( line1.className.match( /popcorn-gist-highlighted/ ), "line 1 is highlighted" ); + plus(); + ok( line3.className.match( /popcorn-gist-highlighted/ ), "line 3 is highlighted" ); + plus(); + ok( line4.className.match( /popcorn-gist-highlighted/ ), "line 4 is highlighted" ); + plus(); + ok( line5.className.match( /popcorn-gist-highlighted/ ), "line 5 is highlighted" ); + plus(); + }) + .exec( 2.5, function() { + var line2 = document.getElementById( "LC2" ), + line6 = document.getElementById( "LC6" ), + line7 = document.getElementById( "LC7" ), + line8 = document.getElementById( "LC8" ), + line1 = document.getElementById( "LC1" ), + line3 = document.getElementById( "LC3" ), + line4 = document.getElementById( "LC4" ), + line5 = document.getElementById( "LC5" ); + + ok( !line1.className.match( /popcorn-gist-highlighted/ ), "line 1 is not highlighted" ); + plus(); + ok( !line3.className.match( /popcorn-gist-highlighted/ ), "line 3 is not highlighted" ); + plus(); + ok( !line4.className.match( /popcorn-gist-highlighted/ ), "line 4 is not highlighted" ); + plus(); + ok( !line5.className.match( /popcorn-gist-highlighted/ ), "line 5 is not highlighted" ); + plus(); + + ok( line2.className.match( /popcorn-gist-highlighted/ ), "line 2 is highlighted" ); + plus(); + ok( line6.className.match( /popcorn-gist-highlighted/ ), "line 6 is highlighted" ); + plus(); + ok( line7.className.match( /popcorn-gist-highlighted/ ), "line 7 is highlighted" ); + plus(); + ok( line8.className.match( /popcorn-gist-highlighted/ ), "line 8 is highlighted" ); + plus(); + }) + .exec( 3.5, function() { + var line15 = document.getElementById( "LC15" ), + line16 = document.getElementById( "LC16" ), + line2 = document.getElementById( "LC2" ), + line6 = document.getElementById( "LC6" ), + line7 = document.getElementById( "LC7" ), + line8 = document.getElementById( "LC8" ); + + ok( !line2.className.match( /popcorn-gist-highlighted/ ), "line 2 is not highlighted" ); + plus(); + ok( !line6.className.match( /popcorn-gist-highlighted/ ), "line 6 is not highlighted" ); + plus(); + ok( !line7.className.match( /popcorn-gist-highlighted/ ), "line 7 is not highlighted" ); + plus(); + ok( !line8.className.match( /popcorn-gist-highlighted/ ), "line 8 is not highlighted" ); + plus(); + + ok( line15.className.match( /popcorn-gist-highlighted/ ), "line 15 is highlighted, with bad range input" ); + plus(); + ok( line16.className.match( /popcorn-gist-highlighted/ ), "line 16 is highlighted as the fallback for an incorrect range" ); + plus(); + ok( !document.getElementById( "LC10" ).className.match( /popcorn-gist-highlighted/ ), "line 10 is NOT highlighted" ); + plus(); + }) + .exec( 4.5, function() { + var highlighted = 0 ; + for( var i = 0, len = lines.len; i < len; i++ ) { + lines[ i ].className.match( /popcorn.gist.highlighted/ ) && highlighted++; + } + equals( highlighted, 0, "0 lines are highlighted" ); + plus(); + + }); + + popped.play(); +}); \ No newline at end of file