]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
added footnote plugin and unit tests [#167 state:peer-review-requested]
authorAnna Sobiepanek <annaopensource@gmail.com>
Thu, 9 Dec 2010 22:06:45 +0000 (17:06 -0500)
committerAnna Sobiepanek <annaopensource@gmail.com>
Thu, 9 Dec 2010 22:06:45 +0000 (17:06 -0500)
plugins/footnote/popcorn.footnote.html [new file with mode: 0644]
plugins/footnote/popcorn.footnote.js [new file with mode: 0644]
plugins/footnote/popcorn.footnote.unit.html [new file with mode: 0644]
plugins/footnote/popcorn.footnote.unit.js [new file with mode: 0644]

diff --git a/plugins/footnote/popcorn.footnote.html b/plugins/footnote/popcorn.footnote.html
new file mode 100644 (file)
index 0000000..0f9e0c4
--- /dev/null
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Popcorn footnote Plug-in Demo</title>
+  
+  <script src="../../popcorn.js"></script>
+  <script src="popcorn.footnote.js"></script>
+  <script>
+    document.addEventListener('DOMContentLoaded', function () {
+      var p = Popcorn('#video')
+      .play() 
+      .footnote({
+        start: 5, // seconds
+        end: 15, // seconds
+        text: 'This video made exclusively for drumbeat.org',
+        target: 'footnotediv'
+      } )
+      .footnote({
+        start: 20, // seconds
+        end: 45, // seconds
+        text: 'Visit webmademovies.org for more details',
+        target: 'footnotediv'
+      } )
+
+    }, false);
+
+  </script>
+</head>
+<body>
+  <h1 id="qunit-header">Popcorn Footnore Plug-in Demo</h1>
+  <p> A footnote displaying This video made exclusively for drumbeat.org' will appear at 5 seconds and disappear at 15 seconds.</p>
+  <p> A footnote displaying 'Visit webmademovies.org for more details' will appear at 20 seconds and disappear at 45 seconds.</p>
+  <div>
+    <video id='video' 
+      controls preload='none' 
+      width= '250px'
+      poster="../../test/poster.png"> 
+
+      <source id='mp4'
+        src="../../test/trailer.mp4"
+        type='video/mp4; codecs="avc1, mp4a"'> 
+
+      <source id='ogv'
+        src="../../test/trailer.ogv"
+        type='video/ogg; codecs="theora, vorbis"'> 
+
+      <p>Your user agent does not support the HTML5 Video element.</p> 
+
+    </video> 
+  </div>
+  <div id="footnotediv" width="50%" height="50%">
+  </div>
+</body>
+</html>
diff --git a/plugins/footnote/popcorn.footnote.js b/plugins/footnote/popcorn.footnote.js
new file mode 100644 (file)
index 0000000..b4d90a7
--- /dev/null
@@ -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 (file)
index 0000000..6777a99
--- /dev/null
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Popcorn API</title>
+  <link rel="stylesheet" href="../../test/qunit/qunit.css" type="text/css" media="screen">
+  <script src="../../test/qunit/qunit.js"></script>
+  <!-- 
+    do not move - this must be called immediately prior to 
+    popcorn-api-draft.js
+  -->
+  
+  <script src="../../popcorn.js"></script>
+  <script src="popcorn.footnote.js"></script>
+
+  <script src="popcorn.footnote.unit.js"></script>
+</head>
+<body>
+  <h1 id="qunit-header">Popcorn Footnote Plugin</h1>
+  <h2 id="qunit-banner"></h2>
+  <div id="qunit-testrunner-toolbar"></div>
+  <h2 id="qunit-userAgent"></h2>
+  <ol id="qunit-tests"></ol>
+  <div id="qunit-fixture">  </div>
+  
+  <video id='video' 
+    controls preload='none' 
+    width= '250px'
+    poster="../../test/poster.png"> 
+
+    <source id='mp4'
+      src="../../test/trailer.mp4"
+      type='video/mp4; codecs="avc1, mp4a"'> 
+
+    <source id='ogv'
+      src="../../test/trailer.ogv"
+      type='video/ogg; codecs="theora, vorbis"'> 
+
+    <p>Your user agent does not support the HTML5 Video element.</p> 
+
+  </video> 
+  <div id="footnotediv"></div>  
+</body>
+</html>
diff --git a/plugins/footnote/popcorn.footnote.unit.js b/plugins/footnote/popcorn.footnote.unit.js
new file mode 100644 (file)
index 0000000..12fe5e3
--- /dev/null
@@ -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);
+  
+});