]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#63] image plugin with unit tests
authorScottDowne <sdowne@learn.senecac.on.ca>
Wed, 22 Dec 2010 20:12:58 +0000 (15:12 -0500)
committerScottDowne <sdowne@learn.senecac.on.ca>
Wed, 22 Dec 2010 20:12:58 +0000 (15:12 -0500)
plugins/image/popcorn.image.html [new file with mode: 0644]
plugins/image/popcorn.image.js [new file with mode: 0644]
plugins/image/popcorn.image.unit.html [new file with mode: 0644]
plugins/image/popcorn.image.unit.js [new file with mode: 0644]

diff --git a/plugins/image/popcorn.image.html b/plugins/image/popcorn.image.html
new file mode 100644 (file)
index 0000000..2ce3a7c
--- /dev/null
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Popcorn Image Plug-in Demo</title>
+  
+  <script src="../../popcorn.js"></script>
+  <script src="popcorn.image.js"></script>
+  <script>
+    document.addEventListener('DOMContentLoaded', function () {
+      var p = Popcorn('#video')
+      .play() 
+      .image({
+        start: 5, // seconds
+        end: 15, // seconds
+        href: 'http://www.drumbeat.org/',
+        src: 'http://www.drumbeat.org/sites/default/files/domain-2/drumbeat_logo.png',
+        target: 'imagediv'
+      } )
+      .image({
+        start: 20, // seconds
+        end: 45, // seconds
+        href: 'http://www.drumbeat.org/webmademovies',
+        src: 'http://patriciabergeron.net/wp-content/uploads/web.made_.movie_marquee.gif',
+        target: 'imagediv'
+      } );
+
+    }, false);
+
+  </script>
+</head>
+<body>
+  <h1 id="qunit-header">Popcorn Image Plug-in Demo</h1>
+  <p> An image will appear at 5 seconds and disappear at 15 seconds.</p>
+  <p> An image will appear at 20 seconds and disappear at 45 seconds.</p>
+  <div>
+    <video id='video' 
+      controls
+      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="imagediv">
+  </div>
+</body>
+</html>
diff --git a/plugins/image/popcorn.image.js b/plugins/image/popcorn.image.js
new file mode 100644 (file)
index 0000000..8a71319
--- /dev/null
@@ -0,0 +1,84 @@
+// PLUGIN: IMAGE
+
+(function (Popcorn) {
+  
+  /**
+   * Images popcorn plug-in 
+   * Creates an iframe showing a website specified by the user
+   * Options parameter will need a start, end, id, target and src.
+   * 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 
+   * href is the url of the destination of a link
+   * Target is the id of the document element that the iframe needs to be attached to, 
+   * this target element must exist on the DOM
+   * Src is the url of the image that you want to display
+   *
+   * @param {Object} options
+   * 
+   * Example:
+     var p = Popcorn('#video')
+        .image({
+          start: 5, // seconds
+          end: 15, // seconds
+          href: 'http://www.drumbeat.org/',
+          src: 'http://www.drumbeat.org/sites/default/files/domain-2/drumbeat_logo.png',
+          target: 'imagediv'
+        } )
+   *
+   */
+  Popcorn.plugin( "image", {
+
+      manifest: {
+        about:{
+          name: "Popcorn image Plugin",
+          version: "0.1",
+          author: "Scott Downe",
+          website: "http://scottdowne.wordpress.com/"
+        },
+        options:{
+          start :  {elem:'input', type:'number', label:'In'},
+          end :    {elem:'input', type:'number', label:'Out'},
+          href :   {elem:'input', type:'text',   label:'URL'},
+          target : {elem:'input', type:'text',   label:'HTML Element id'},
+          src :    {elem:'input', type:'text',   label:'URL'}
+        }
+      },
+
+      _setup: function( options ) {
+
+        options.link = document.createElement( 'a' );
+        options.link.style.display = "none"; // display none by default
+        options.link.href = options.href;
+        options.link.target = "_blank";
+
+        document.getElementById( options.target ).appendChild( options.link ); // add the widget's div to the target div
+
+        var img = document.createElement( 'img' );
+        img.src = options.src;
+
+        options.link.appendChild( img );
+        
+      },
+
+      /**
+       * @member image 
+       * 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.link.style.display = "inline";
+      },
+      /**
+       * @member image 
+       * 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 ) {
+        options.link.style.display = "none";
+      }
+          
+  });
+
+})( Popcorn );
diff --git a/plugins/image/popcorn.image.unit.html b/plugins/image/popcorn.image.unit.html
new file mode 100644 (file)
index 0000000..dc0f28d
--- /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.image.js"></script>
+
+  <script src="popcorn.image.unit.js"></script>
+</head>
+<body>
+  <h1 id="qunit-header">Popcorn Webpage UI</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
+    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="imagediv"></div>  
+</body>
+</html>
diff --git a/plugins/image/popcorn.image.unit.js b/plugins/image/popcorn.image.unit.js
new file mode 100644 (file)
index 0000000..e0238b5
--- /dev/null
@@ -0,0 +1,54 @@
+test("Popcorn Image Plugin", function () {
+  
+  var popped = Popcorn("#video"),
+      expects = 5,
+      count = 0,
+      interval,
+      interval2,
+      imagediv = document.getElementById('imagediv');
+  
+  expect( expects );
+  
+  function plus() {
+    if ( ++count === expects) {
+      start();
+    }
+  }
+
+  stop();
+ 
+  ok('image' in popped, "image is a method of the popped instance");
+  plus();
+
+  equals ( imagediv.innerHTML, "", "initially, there is nothing inside the imagediv" );
+  plus();
+  
+  popped.image({
+    start: 1, // seconds
+    end: 3, // seconds
+    href: 'http://www.drumbeat.org/',
+    src: 'http://www.drumbeat.org/sites/default/files/domain-2/drumbeat_logo.png',
+    target: 'imagediv'
+  } );
+
+  interval = setInterval( function() {
+    if( popped.currentTime() > 1 && popped.currentTime() < 3 ) {
+      ok( /display: inline;/.test( imagediv.innerHTML ), "Div contents are displayed" );
+      plus();
+      ok( /img/.test( imagediv.innerHTML ), "An image exists" );
+      plus();
+      clearInterval( interval );
+    }
+  }, 500);
+  
+  interval2 = setInterval( function() {
+    if( popped.currentTime() > 3 ) {
+      ok( /display: none;/.test( imagediv.innerHTML ), "Div contents are hidden again" );
+      plus();
+      clearInterval( interval2 );
+    }
+  }, 500);
+  
+  popped.play();
+  
+});