]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#384] Added another option to specify the direction of the timeline
authorDavid Seifried <david.c.seifried@gmail.com>
Mon, 20 Jun 2011 20:52:27 +0000 (16:52 -0400)
committerDavid Seifried <david.c.seifried@gmail.com>
Mon, 20 Jun 2011 20:52:27 +0000 (16:52 -0400)
plugins/timeline/popcorn.timeline.html
plugins/timeline/popcorn.timeline.js

index 0dfcc7e337db463689c56f6b1c74bf6e2fa8b225..e6dc422fe4793d5f6909c0d7d2ab7e0f73a3527a 100644 (file)
         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>" 
+        innerHTML: "Click here for <a href='http://www.google.ca'>Google</a>" ,
+        direction: "down"
       } )
       .timeline({
         start: 3, // 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>" 
+        innerHTML: "Maybe a button? <button onClick=\"window.location.href='http://www.google.com'\">Click Me</button>",
+        direction: "down"
       } )
      .timeline({
         start: 7, // seconds
@@ -30,7 +32,8 @@
         target: "timeline",
         title: "3x as interesting",
         text: "this is some interesting text that goes inside",
-        innerHTML: ""
+        innerHTML: "",
+        direction: "down"
       } )
      .timeline({
         start: 9, // seconds
                         "<td>row 2, cell 1</td>" +
                        " <td>row 2, cell 2</td>" +
                       "</tr>" +
-                    "</table>"
+                    "</table>",
+        direction: "down"
       } )
       .timeline({
         start: 14, // seconds
         target: "timeline",
         title: "5x as interesting",
         text: "this is some interesting text that goes inside",
-        innerHTML: "Click here for <a href='http://www.apple.com'>Apple</a>"
+        innerHTML: "Click here for <a href='http://www.apple.com'>Apple</a>",
+        direction: "down"
       } )
       .timeline({
         start: 18, // seconds
         target: "timeline",
         title: "6x as interesting",
         text: "this is some interesting text that goes inside",
-        innerHTML: ""
+        innerHTML: "",
+        direction: "down"
       } );
     }, false);
   </script>
index dd693a2486d5f63ed2924f88c30084893ba545e5..416096484067b21d624d865dcd021f241ae3f092 100644 (file)
@@ -11,6 +11,7 @@
      * -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
+     * -direction specifies whether the timeline will grow from the top or the bottom, receives input as "UP" or "DOWN"
      * @param {Object} options
      *
      * Example:
@@ -39,7 +40,6 @@
   Popcorn.plugin( "timeline" , function( options ) {
 
     var target = document.getElementById( options.target );
-    target.style.float = "left";
     target.style.width = "400px";
     target.style.height = "200px";
     target.style.overflow = "auto";
     // that already exists in the parent div gets overwritten
     var newdiv = document.createElement( "div" );
     newdiv.style.display = "none";
-    newdiv.id = "timelineDiv"+i;
+    newdiv.id = "timelineDiv" + i;
+
+    options.direction = ( options.direction.toLowerCase()  === "up" || options.direction.toLowerCase()  === "down" )
+                      ? options.direction : "up";
 
     if ( target ) {
 
       target.appendChild( newdiv );
 
       // if this isnt the first div added to the target div
-      if( i ){
-
+      if( i && options.direction.length === 2 ){
         // insert the current div before the previous div inserted
         target.insertBefore( newdiv, document.getElementById( "timelineDiv" + ( i - 1 ) ) );
-       }
+      }
+
+      target.scrollTop = options.direction.toLowerCase() === "down" ? 0 : target.scrollHeight;
     }
     
     i++;
     
     return {
 
-      start: function( event, options ){
+      start: function( event, options ) {
         newdiv.style.display = "block";
       },
  
-      end: function( event, options ){
+      end: function( event, options ) {
         newdiv.style.display = "none";
       },