From: Christopher De Cairos Date: Tue, 23 Aug 2011 20:15:29 +0000 (-0400) Subject: adds wrapper div to timeline, fixes teardown, fixes up/down, added tests, support... X-Git-Tag: v0.8^2~8^2~2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=de7229c11139d805f661eb9d9a808360f5493e51;p=popcorn-js.git adds wrapper div to timeline, fixes teardown, fixes up/down, added tests, support for multiple timelines on one page. --- diff --git a/plugins/timeline/popcorn.timeline.html b/plugins/timeline/popcorn.timeline.html index e6dc422..3d8a48b 100644 --- a/plugins/timeline/popcorn.timeline.html +++ b/plugins/timeline/popcorn.timeline.html @@ -16,7 +16,7 @@ title: "This is a title", text: "this is some interesting text that goes inside", innerHTML: "Click here for Google" , - direction: "down" + direction: "up" } ) .timeline({ start: 3, // seconds @@ -24,7 +24,7 @@ title: "double as interesting", text: "this is some interesting text that goes inside", innerHTML: "Maybe a button? ", - direction: "down" + direction: "up" } ) .timeline({ start: 7, // seconds @@ -33,41 +33,33 @@ title: "3x as interesting", text: "this is some interesting text that goes inside", innerHTML: "", - direction: "down" + direction: "up" } ) - .timeline({ - start: 9, // seconds - target: "timeline", - title: "4x as interesting", + .timeline({ + start: 1, // seconds + target: "timeline2", + title: "This is a title", text: "this is some interesting text that goes inside", - innerHTML: "perhaps tables " + - "" + - "" + - "" + - "" + - "" + - "" + - " " + - "" + - "
row 1, cell 1row 1, cell 2
row 2, cell 1row 2, cell 2
", + innerHTML: "Click here for Google" , direction: "down" } ) .timeline({ - start: 14, // seconds - target: "timeline", - title: "5x as interesting", + start: 3, // seconds + target: "timeline2", + title: "double as interesting", text: "this is some interesting text that goes inside", - innerHTML: "Click here for Apple", + innerHTML: "Maybe a button? ", direction: "down" } ) - .timeline({ - start: 18, // seconds - target: "timeline", - title: "6x as interesting", + .timeline({ + start: 7, // seconds + end: 700, + target: "timeline2", + title: "3x as interesting", text: "this is some interesting text that goes inside", innerHTML: "", direction: "down" - } ); + } ) }, false); @@ -93,7 +85,8 @@
-
+
+
diff --git a/plugins/timeline/popcorn.timeline.js b/plugins/timeline/popcorn.timeline.js index ddc1fc4..e7d56da 100644 --- a/plugins/timeline/popcorn.timeline.js +++ b/plugins/timeline/popcorn.timeline.js @@ -7,7 +7,7 @@ * 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 + * -Target is the id of the DOM element that you want the timeline 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 @@ -38,29 +38,47 @@ Popcorn.plugin( "timeline" , function( options ) { var target = document.getElementById( options.target ), - newdiv = document.createElement( "div" ); - - target.style.width = "400px"; - target.style.height = "200px"; - target.style.overflow = "auto"; + contentDiv = document.createElement( "div" ), + container, + goingUp; + + if ( target && !target.firstChild ) { + target.appendChild ( container = document.createElement( "div" ) ); + container.style.width = "inherit"; + container.style.height = "inherit"; + container.style.overflow = "auto"; + container.id = "timeline-container"; + } else { + container = target.firstChild; + } - newdiv.style.display = "none"; - newdiv.id = "timelineDiv" + i; + contentDiv.style.display = "none"; + contentDiv.id = "timelineDiv" + i; // Default to up if options.direction is non-existant or not up or down options.direction = options.direction || "up"; - if ( options.direction.toLowerCase() !== "up" || options.direction.toLowerCase() !== "down" ) { - options.direction = "up"; + if ( options.direction.toLowerCase() === "up" ) { + + goingUp = true; } + else if ( options.direction.toLowerCase() === "down" ) { - if ( target ) { - - target.appendChild( newdiv ); + goingUp = false; + } + else { + + goingUp = true; + } + if ( target && container ) { // if this isnt the first div added to the target div - if( options.direction.length === 2 ){ + if( goingUp ){ // insert the current div before the previous div inserted - target.insertBefore( newdiv, document.getElementById( "timelineDiv" + ( i - 1 ) ) ); + container.insertBefore( contentDiv, container.firstChild ); + } + else { + + container.appendChild( contentDiv ); } } @@ -70,27 +88,26 @@ // Default to empty if not used //options.innerHTML = options.innerHTML || ""; - newdiv.innerHTML = "

" + options.title + "
" + + contentDiv.innerHTML = "

" + options.title + "
" + "" + options.text + "
" + options.innerHTML; return { start: function( event, options ) { - newdiv.style.display = "block"; + contentDiv.style.display = "block"; if( options.direction === "down" ) { - target.scrollTop = target.scrollHeight; + container.scrollTop = container.scrollHeight; } }, end: function( event, options ) { - newdiv.style.display = "none"; + contentDiv.style.display = "none"; }, _teardown: function( options ) { - while ( target.firstChild ) { - target.removeChild( target.firstChild ); - } + + ( container && contentDiv ) && container.removeChild( contentDiv ) && !container.firstChild && target.removeChild( container ); } }; }, diff --git a/plugins/timeline/popcorn.timeline.unit.html b/plugins/timeline/popcorn.timeline.unit.html index 8adf467..488bf66 100644 --- a/plugins/timeline/popcorn.timeline.unit.html +++ b/plugins/timeline/popcorn.timeline.unit.html @@ -25,7 +25,8 @@

-
+
+
diff --git a/plugins/timeline/popcorn.timeline.unit.js b/plugins/timeline/popcorn.timeline.unit.js index cd680d5..f337149 100644 --- a/plugins/timeline/popcorn.timeline.unit.js +++ b/plugins/timeline/popcorn.timeline.unit.js @@ -1,9 +1,11 @@ test("Popcorn Timeline Plugin", function () { var popped = Popcorn( "#video" ), - expects = 8, - setupId, - count = 0; + expects = 17, + upIds = downIds = [], + count = 0, + timelineUp = document.getElementById( "timeline-up" ), + timelineDown = document.getElementById( "timeline-down" ); expect( expects ); @@ -15,48 +17,108 @@ test("Popcorn Timeline Plugin", function () { stop(); - ok ( 'timeline' in popped, "timeline is a method of the popped instance" ); + 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" ); + equals ( document.getElementById( "timeline-up" ).firstChild, undefined, "initially, there is nothing inside the 'timeline-up' feed" ); + plus(); + equals ( document.getElementById( "timeline-down" ).firstChild, undefined, "initially, there is nothing inside the 'timeline-down' feed" ); plus(); popped.timeline({ start: 1, // seconds - target: "timeline", + target: "timeline-up", title: "This is a title", text: "this is some interesting text that goes inside", - innerHTML: "Click here for Google" - } ) - .timeline({ + innerHTML: "Click here for Google" + } ); + upIds.push( popped.getLastTrackEventId() ); + + popped.timeline({ start: 2, // seconds - target: "timeline", + target: "timeline-up", title: "double as interesting", text: "this is some interesting text that goes inside", innerHTML: "Maybe a button? " - } ) - .volume(0); - - setupId = popped.getLastTrackEventId(); + } ); + upIds.push( popped.getLastTrackEventId() ); + + popped.timeline({ + start: 1, // seconds + target: "timeline-down", + title: "This is a title", + text: "this is some interesting text that goes inside", + innerHTML: "Maybe a button? ", + direction: "down" + } ); + downIds.push( popped.getLastTrackEventId() ); + + popped.timeline({ + start: 2, // seconds + target: "timeline-down", + title: "double as interesting", + text: "this is some interesting text that goes inside", + innerHTML: "Maybe a button? ", + direction: "down" + } ); + downIds.push( popped.getLastTrackEventId() ); + + popped.volume(0); - popped.exec( 2, function() { - ok ( document.getElementById( 'timelineDiv1' ), "First timeline is on the page" ); + popped.exec( 1.5, function() { + //up + 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" ); + equals ( document.getElementById("timelineDiv1" ).parentNode.parentNode.id, "timeline-up", "First timeline is inside the 'timeline-up' div" ); plus(); + + //down + ok ( document.getElementById( "timelineDiv3" ), "First timeline is on the page" ); + plus(); + equals ( document.getElementById("timelineDiv3" ).parentNode.parentNode.id, "timeline-down", "First Timeline is inside the 'timeline-down' div" ); + plus(); + }); - popped.exec( 3, function() { - ok ( document.getElementById( 'timelineDiv2' ), "Second timeline is on the page" ); + popped.exec( 2.5, function() { + //up + var timelinediv2 = document.getElementById( "timelineDiv2" ), + timelinediv4 = document.getElementById( "timelineDiv4" ); + ok ( timelinediv2, "Second timeline is on the page" ); + plus(); + equals ( timelinediv2 && timelinediv2.parentNode.parentNode.id, "timeline-up", "Second timelineDiv2 is inside the 'timeline-up' div" ); + plus(); + equals ( timelineUp.firstChild.firstChild.id, "timelineDiv2", "'timelineDiv2' is the first child in 'timeline-up'" ); + plus(); + + //down + + ok ( timelinediv4, "Second down timeline is on the page" ); + plus(); + equals ( timelinediv4.parentNode.parentNode.id, "timeline-down", "timelineDiv4 is inside the 'timeline-down' div" ); plus(); - equals ( document.getElementById( 'timelineDiv2' ).parentNode.id, "timeline", "Second timelineDiv2 is inside the 'timeline' div" ); + equals ( timelineDown.firstChild.firstChild.id, "timelineDiv3", "'timelineDiv3' is the first child in 'timeline-down'" ); plus(); }); popped.exec( 4, function() { - ok (document.getElementById( 'timelineDiv1' ).style.display !== "none" && - document.getElementById( 'timelineDiv2' ).style.display !== "none", "Both timelines are not visible" ); + ok (document.getElementById( "timelineDiv1" ).style.display !== "none" && + document.getElementById( "timelineDiv2" ).style.display !== "none", "Both timelines in 'timeline-up are not visible" ); plus(); - - popped.pause().removeTrackEvent( setupId ); - ok( !document.getElementById( 'timeline' ).children[ 0 ], "removed timeline was properly destroyed" ); + + ok (document.getElementById( "timelineDiv3" ).style.display !== "none" && + document.getElementById( "timelineDiv4" ).style.display !== "none", "Both timelines in 'timeline-down' are not visible" ); + plus(); + + var uid, did; + while ( uid = upIds.pop() ) { + popped.removeTrackEvent( uid ); + } + while ( did = downIds.pop() ) { + popped.removeTrackEvent( did ); + } + + popped.pause(); + equals( document.getElementById( "timeline-up" ).firstChild, null, "removed timeline was properly destroyed" ); + plus(); + equals( document.getElementById( "timeline-down" ).firstChild, null, "removed timeline was properly destroyed" ); plus(); });