]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
webpage plugin and tests [#160]
authorAnna Sobiepanek <annaopensource@gmail.com>
Thu, 9 Dec 2010 19:51:11 +0000 (14:51 -0500)
committerAnna Sobiepanek <annaopensource@gmail.com>
Thu, 9 Dec 2010 19:51:11 +0000 (14:51 -0500)
plugins/webpage/popcorn.webpage.html
plugins/webpage/popcorn.webpage.js
plugins/webpage/popcorn.webpage.unit.html
plugins/webpage/popcorn.webpage.unit.js

index f9fdf1fb88edff21bb09c40a744c423ad01345ca..8d93137413f0ea4e8d8af6a98a7d301a0c0a23a1 100644 (file)
@@ -9,17 +9,17 @@
     document.addEventListener('DOMContentLoaded', function () {
       var p = Popcorn('#video')
       .play() 
-      .webpages({
+      .webpage({
         id: "webpages-a", 
         start: 5, // seconds
         end: 15, // seconds
         src: 'http://www.webmademovies.org',
         target: 'webpagediv'
       } )
-      .webpages({
+      .webpage({
         id: "webpages-b", 
         start: 20, // seconds
-        end: 25, // seconds
+        end: 45, // seconds
         src: 'http://zenit.senecac.on.ca/wiki/index.php/Processing.js',
         target: 'webpagediv2'
       } );
 </head>
 <body>
   <h1 id="qunit-header">Popcorn WebPage Plug-in Demo</h1>
-  <p> A Webpage displaying webmademovies.org will appear at 0 seconds and disappear at 5 seconds.</p>
+  <p> A Webpage displaying webmademovies.org will appear at 5 seconds and disappear at 15 seconds.</p>
+  <p> A Webpage displaying zenit Processing.js wiki will appear at 20 seconds and disappear at 45 seconds.</p>
   <div>
     <video id='video' 
       controls preload='none' 
       width= '250px'
-      poster="http://media.w3.org/2010/05/sintel/poster.png"> 
+      poster="../../test/poster.png"> 
 
       <source id='mp4'
-        src="http://media.w3.org/2010/05/sintel/trailer.mp4"
+        src="../../test/trailer.mp4"
         type='video/mp4; codecs="avc1, mp4a"'> 
 
       <source id='ogv'
-        src="http://media.w3.org/2010/05/sintel/trailer.ogv"
+        src="../../test/trailer.ogv"
         type='video/ogg; codecs="theora, vorbis"'> 
 
       <p>Your user agent does not support the HTML5 Video element.</p> 
index e7db024e396c89ece241daafbec38d72d9e09ea2..d34dc9d37cd2d821167820055e4a0fe742a331cc 100644 (file)
@@ -1,48 +1,64 @@
+// PLUGIN: WEBPAGE
+
 (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.
+   * Options parameter will need a start, end, id, target 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
+   * End is the time that you want this plug-in to stop executing 
+   * Id is the id that you want assigned to the iframe
+   * 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 website that you want the iframe to display
    *
    * @param {Object} options
+   * 
+   * Example:
+     var p = Popcorn('#video')
+        .webpage({
+          id: "webpages-a", 
+          start: 5, // seconds
+          end: 15, // seconds
+          src: 'http://www.webmademovies.org',
+          target: 'webpagediv'
+        } )
    *
    */
-  Popcorn.plugin( "webpages" , function ( options ) {
-    
-    var exists,
-        iframe  = document.createElement( 'iframe' ),
-        page    = [], 
-        temp    = document.getElementById( options.target );
-          
-    // set the style of the iframe
+  Popcorn.plugin( "webpage" , (function(){
+      
+    var exists, iframe, temp;
+    iframe  = document.createElement( 'iframe' ),
     iframe.setAttribute('width', "100%");
     iframe.setAttribute('height', "100%");
-    iframe.id  = options.id;
-    iframe.src = options.src;
-   
-    // listen function will add/remove the iframe from the page at the appropriate times
-    this.listen("timeupdate", function (event) {
-      exists  = document.getElementById( options.id );
-      if ( this.currentTime() >= options.start && !exists &&  this.currentTime() <= options.end ) {
+    
+    
+    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 );
+        iframe.id  = options.id;
+        iframe.src = options.src;
         temp.appendChild(iframe);
-      }
-      // remove the iframe if the current time of the video is greater than 
-      // the end time specified by the user 
-      if ( this.currentTime() >= options.end  && exists ) {           
-        temp.removeChild(iframe);
-      }
-      // if the user seeks to a time before the webpage command
-      // ensure that the iframe was removed
-      if ( this.currentTime() < options.start && exists ) {
+      },
+      /**
+       * @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.removeChild(iframe);
       }
-    });
+      
+    };
     
-    return this;
-  });
+  })());
 
-})(Popcorn);
\ No newline at end of file
+})( Popcorn );
\ No newline at end of file
index 7ae70c97155f2ecc77ffc4b68f652de493a9fea1..238ff9d67fd621811a6ac4730f8fad5a342e36e4 100644 (file)
   <div id="qunit-testrunner-toolbar"></div>
   <h2 id="qunit-userAgent"></h2>
   <ol id="qunit-tests"></ol>
-  <div id="qunit-fixture">
-    
-    
-
-  
-  
-  </div>
-  
+  <div id="qunit-fixture">  </div>
   
-  <video id='video'
+  <video id='video' 
     controls preload='none' 
-    width ='200'
-    poster="http://media.w3.org/2010/05/sintel/poster.png"> 
+    width= '250px'
+    poster="../../test/poster.png"> 
 
     <source id='mp4'
-      src="http://media.w3.org/2010/05/sintel/trailer.mp4"
+      src="../../test/trailer.mp4"
       type='video/mp4; codecs="avc1, mp4a"'> 
 
     <source id='ogv'
-      src="http://media.w3.org/2010/05/sintel/trailer.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="webpagediv"></div>  
+  <div id="webpagediv"></div>  
 </body>
 </html>
index b5f2f189bbd74657e1f88c1235228bcdc81f2d6c..436e48362c0d10d62ce9cf0465efdd52f241e152 100644 (file)
@@ -1,39 +1,80 @@
 test("Popcorn Webpage Plugin", function () {
   
-  var popped = Popcorn("#video")
-      expects = 2, 
-      count = 0
-    ;
+  var popped = Popcorn("#video"),
+      expects = 11, 
+      count = 0,
+      iframeInterval,
+      iframeInterval2,
+      iframeInterval3,
+      iframeInterval4;
   
   expect(expects);
   
   function plus() {
-    if( ++count===expects) {
+    if ( ++count===expects) {
       start();
     }
   }
   
   stop();
+   
+  ok ('webpage' in popped, "webpages is a mehtod of the popped instance");
+  plus();
   
-  
-  ok( 'webpages' in popped, "webpages is a mehtod of the popped instance");
+  ok (document.getElementsByTagName('iframe').length === 0, "initially, there is no iframes on the page" );
   plus();
   
-  popped.webpages({
+  popped.webpage({
       id: "webpages-a", 
-      start: 1, // seconds
-      end: 30, // seconds
-      src: 'http://www.webmademovies.org',
+      start: 5, // seconds
+      end: 25, // seconds
+      src: 'http://webmademovies.org',
       target: 'webpagediv'
-    }).play();
-  
+    })
+    .webpage({
+      id: "webpages-b", 
+      start: 35, // seconds
+      end: 50, // seconds
+      src: 'http://zenit.senecac.on.ca/wiki/index.php/Processing.js',
+      target: 'webpagediv'
+    })
+    .play();
   
   
-  setTimeout(function() {
-    ok( !!document.getElementsByTagName('iframe')[0], "iframe was created" );
-    plus();
+  iframeInterval = setInterval( function() {
+    if( popped.currentTime() > 5 && popped.currentTime() <= 25 ) {
+      ok (!!document.getElementsByTagName('iframe')[0], "iframe was created" );
+      plus();
+      ok (document.getElementsByTagName('iframe').length === 1, "there is only one iframe on the page" );
+      plus();
+      ok (document.getElementsByTagName('iframe')[0].id === "webpages-a", "iframe has the id 'webpages-a'" );
+      plus();
+      ok (document.getElementsByTagName('iframe')[0].src === "http://webmademovies.org/", "iframe has the src 'http://webmademovies.org/'" );
+      plus();
+      clearInterval( iframeInterval );
+    }
   }, 5000);
   
+  iframeInterval2 = setInterval( function() {
+    if( popped.currentTime() > 25 && popped.currentTime() < 35  ) {
+      ok (document.getElementsByTagName('iframe').length === 0, "the iframe has been removed" );
+      plus();
+      clearInterval( iframeInterval2 );
+    }
+  }, 5000);
   
+  iframeInterval3 = setInterval( function() {
+    if( popped.currentTime() > 35 && popped.currentTime() <= 50 ) {
+      ok (!!document.getElementsByTagName('iframe')[0], "iframe was created" );
+      plus();
+      ok (document.getElementsByTagName('iframe').length === 1, "there is only one iframe on the page" );
+      plus();
+      ok (document.getElementsByTagName('iframe')[0].id === "webpages-b", "iframe has the id 'webpages-b'" );
+      plus();
+      ok (document.getElementsByTagName('iframe')[0].src === "http://zenit.senecac.on.ca/wiki/index.php/Processing.js", "iframe has the src 'http://zenit.senecac.on.ca/wiki/index.php/Processing.js'" );
+      plus();
+      clearInterval( iframeInterval3 );
+    }
+  }, 5000);
   
 });