]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#384] Initial version of the timeline plugin
authorDavid Seifried <david.c.seifried@gmail.com>
Mon, 6 Jun 2011 20:19:53 +0000 (16:19 -0400)
committerDavid Seifried <david.c.seifried@gmail.com>
Mon, 6 Jun 2011 20:19:53 +0000 (16:19 -0400)
plugins/timeline/popcorn.timeline.css
plugins/timeline/popcorn.timeline.html
plugins/timeline/popcorn.timeline.js
plugins/timeline/popcorn.timeline.unit.html [new file with mode: 0644]
plugins/timeline/popcorn.timeline.unit.js [new file with mode: 0644]

index cb94c543d02ad77cbbc0675ecb892fbc499be7ff..5835c3ab299e3034f2ee8e0a5ef91922c3427625 100644 (file)
@@ -1,52 +1,11 @@
-@charset "UTF-8";
-body {
-font-family: "Helvetica Neue", Helvetica, Arial;
-font-size:12px;
-}
-
-#footer {
-width: 100%;
-height: 20px;
-position: fixed;
-text-align:right;
-right: 0px;
-overflow: hidden;
-background-color:#000000;
-color: white;
-top: 0;
-border-bottom: 1px solid #333;
-padding: 10px;
-}
-#playback {
-width: 700px;
-left: 0px;
-top: 0px;
-z-index:100;
-}
-
-#details2 {
-color: #fff;
-padding: 7px;
-right: 0px;
-top: 0px;
-line-height: 180%;
-}
-#details3 {
-padding: 7px;
-right: 0px;
-top: 0px;
-line-height: 180%;
-border-top: 1px solid #333;
-}
 #big {
-font-size:24px;
-line-height: 130%;
+  font-size:24px;
+  line-height: 130%;
 }
+
 #mid {
-font-size: 16px;
+  font-size: 16px;
 }
 
-// Thanks again to Nic for this css
-
 
 
index 498162e3d540192d7935afc1ee6926816154fc46..65076555df32641565874219558ca22232413835 100644 (file)
@@ -5,7 +5,6 @@
   
   <script src="../../popcorn.js"></script>
   <script src="popcorn.timeline.js"></script>
-  <script src="popcorn.timeline.css"></script>
   <script>
     document.addEventListener('DOMContentLoaded', function () {
       var p = Popcorn('#video')
       .play()
       .timeline({
         start: 1, // seconds
-        end: 700,
         target: "timeline",
         title: "This is a title",
         text: "this is some interesting text that goes inside",
-        links: "and heres a link"
+        innerHTML: "Click here for <a href='http://www.google.ca'>Google</a>" 
       } )
       .timeline({
         start: 3, // seconds
-        end: 700,
         target: "timeline",
-        title: "and more interesting shit",
+        title: "double as interesting",
         text: "this is some interesting text that goes inside",
-        links: "and heres a link"
+        innerHTML: "Maybe a button? <button onClick=\"window.location.href='http://www.google.com'\">Click Me</button>" 
       } )
      .timeline({
         start: 7, // seconds
         target: "timeline",
         title: "3x as interesting",
         text: "this is some interesting text that goes inside",
-        links: "and heres a link"
+        innerHTML: ""
       } )
      .timeline({
         start: 9, // seconds
-        end: 700,
         target: "timeline",
         title: "4x as interesting",
         text: "this is some interesting text that goes inside",
-        links: "and heres a link"
+        innerHTML: "perhaps tables <table border='1'>" +
+                      "<tr>" +
+                        "<td>row 1, cell 1</td>" +
+                        "<td>row 1, cell 2</td>" +
+                      "</tr>" +
+                      "<tr>" +
+                        "<td>row 2, cell 1</td>" +
+                       " <td>row 2, cell 2</td>" +
+                      "</tr>" +
+                    "</table>"
       } )
       .timeline({
         start: 14, // seconds
-        end: 700,
         target: "timeline",
         title: "5x as interesting",
         text: "this is some interesting text that goes inside",
-        links: "and heres a link"
+        innerHTML: "Click here for <a href='http://www.apple.com'>Apple</a>"
       } )
       .timeline({
         start: 18, // seconds
-        end: 700,
         target: "timeline",
         title: "6x as interesting",
         text: "this is some interesting text that goes inside",
-        links: "and heres a link"
+        innerHTML: ""
       } );
     }, false);
   </script>
@@ -84,7 +87,7 @@
     </video>
   </div>
   <div style="width:1000px">
-    <div id="timeline" style="float:left;width:400px;height:200px;overflow:auto"><p>Vertical Feed:</p></div>
+    <div id="timeline" style="float:left;width:400px;height:200px;overflow:auto"></div>
   </div>
 </body>
 </html>
index 7d98c0c6b9df1ec447f181e3a71f47eaf189f5ef..de3a8a730b15ab5f040a41637f6411a1e1149d51 100644 (file)
@@ -1,13 +1,38 @@
 // PLUGIN: Timeline
 (function (Popcorn) {
 
-  var i = 0;
+  /**
+     * timeline popcorn plug-in
+     * Adds data associated with a certain time in the video, which creates a scrolling view of each item as the video progresses
+     * Options parameter will need a start, target, title, 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, tho for this plugin an end time may not be needed ( optional )
+     * -Target is the id of the DOM element that you want the map to appear in. This element must be in the DOM
+     * -Title is the title of the current timeline box
+     * -Text is text is simply related text that will be displayed
+     * -innerHTML gives the user the option to add things such as links, buttons and so on
+     * @param {Object} options
+     *
+     * Example:
+      var p = Popcorn("#video")
+        .timeline( {
+         start: 5, // seconds
+         target: "timeline",
+         title: "Seneca",
+         text: "Welcome to seneca",
+         innerHTML: "Click this link <a href='http://www.google.ca'>Google</a>"
+      } )
+    *
+  */
+
+  var i = 1;
    
-  var head = document.getElementsByTagName("head")[0];
-  var css = document.createElement('link');
+  //  Included simple css to make it look a bit nicer
+  var head = document.getElementsByTagName( "head" )[ 0 ];
+  var css = document.createElement( 'link' );
   css.type = "text/css";
   css.rel = "stylesheet";
-  css.href = "asdf.css";
+  css.href = "popcorn.timeline.css";
   head.insertBefore( css, head.firstChild );
 
 
     }
     
     i++;
-    
+
+    //  Default to empty if not used
+    //options.innerHTML = options.innerHTML || "";    
+
     newdiv.innerHTML = "<p><span id='big'>" + options.title + "</span><br />" +
-    "<span id='mid'>" + options.text + "<br />" +
-    "</span><a href='#'>" + options.links + "</a></p>";
+    "<span id='mid'>" + options.text + "<br />" + options.innerHTML;
     
     return {
 
         newdiv.setAttribute( "style", "display:block" );
       },
  
-      end: function(event, options){
+      end: function( event, options ){
         newdiv.setAttribute( "style", "display:none" );
+      },
+
+      _teardown: function( options ) {
+        while ( document.getElementById( options.target ).childNodes.length >= 1 )
+        {
+            document.getElementById( options.target ).removeChild( document.getElementById( options.target ).firstChild );       
+        }  
       }
     };
   },
     },
 
     options: {
-      start :  { elem:"input", type:"text", label:"In" },
-      end :    { elem:"input", type:"text", label:"Out" },
-      target : "feed-container",
-      text :   { elem:"input", type:"text", label:"text" }
+      start :      { elem:"input", type:"text", label:"In" },
+      end :        { elem:"input", type:"text", label:"Out" },
+      target :     "feed-container",
+      title :      { elem:"input", type:"text", label:"title" },
+      text :       { elem:"input", type:"text", label:"text" },
+      innerHTML:   { elem:"input", type:"text", label:"innerHTML" }
     }
   });
   
diff --git a/plugins/timeline/popcorn.timeline.unit.html b/plugins/timeline/popcorn.timeline.unit.html
new file mode 100644 (file)
index 0000000..8adf467
--- /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.timeline.js"></script>
+
+  <script src="popcorn.timeline.unit.js"></script>
+</head>
+<body>
+  <h1 id="qunit-header">Popcorn Timeline 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="timeline" style="float:left;width:400px;height:200px;overflow:auto"></div>  
+</body>
+</html>
diff --git a/plugins/timeline/popcorn.timeline.unit.js b/plugins/timeline/popcorn.timeline.unit.js
new file mode 100644 (file)
index 0000000..852ba78
--- /dev/null
@@ -0,0 +1,65 @@
+test("Popcorn Timeline Plugin", function () {
+  
+  var popped = Popcorn("#video"),
+      expects = 8,
+      setupId, 
+      count = 0;
+  
+  expect(expects);
+  
+  function plus() {
+    if ( ++count===expects) {
+      start();
+    }
+  }
+  
+  stop();
+
+    ok ('timeline' in popped, "timeline is a method of the popped instance");
+    plus();
+    ok ( document.getElementById('timeline').innerHTML === "", "initially, there is nothing inside the feed" );
+    plus();
+  
+    popped.timeline({
+      start: 1, // seconds
+      target: "timeline",
+      title: "This is a title",
+      text: "this is some interesting text that goes inside",
+      innerHTML: "Click here for <a href='http://www.google.ca'>Google</a>" 
+    } )
+    .timeline({
+      start: 2, // seconds
+      target: "timeline",
+      title: "double as interesting",
+      text: "this is some interesting text that goes inside",
+      innerHTML: "Maybe a button? <button onClick=\"window.location.href='http://www.google.com'\">Click Me</button>" 
+    } )
+    .volume(0);
+
+  setupId = popped.getLastTrackEventId();
+  
+  popped.exec( 2, function() {
+    ok (document.getElementById('timelineDiv1'), "First timeline is on the page" );
+    plus();
+    equals (document.getElementById('timelineDiv1').parentNode.id, "timeline", "First timeline is inside the 'timeline' div" );
+    plus();
+  });
+  popped.exec( 3, function() {
+    ok (document.getElementById('timelineDiv2'), "Second timeline is on the page" );
+    plus();
+    equals (document.getElementById('timelineDiv2').parentNode.id, "timeline", "Second timelineDiv2 is inside the 'timeline' div" );
+    plus();
+  });
+  popped.exec( 4, function() {
+    ok (document.getElementById('timelineDiv1').style.display !== "none" && 
+        document.getElementById('timelineDiv2').style.display !== "none", "Both timelines are not visible" );
+         plus();
+
+    popped.pause().removeTrackEvent( setupId );
+    ok( !document.getElementById('timeline').children[0], "removed timeline was properly destroyed"  );
+    plus();
+  });
+  
+  popped.play();
+  
+});