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>" ,
- direction: "down"
+ direction: "up"
} )
.timeline({
start: 3, // seconds
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>",
- direction: "down"
+ direction: "up"
} )
.timeline({
start: 7, // seconds
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 <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>",
+ innerHTML: "Click here for <a href='http://www.google.ca'>Google</a>" ,
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 <a href='http://www.apple.com'>Apple</a>",
+ innerHTML: "Maybe a button? <button onClick=\"window.location.href='http://www.google.com'\">Click Me</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);
</script>
</head>
</video>
</div>
<div style="width:1000px">
- <div id="timeline"></div>
+ <div id="timeline" style="float:left;width: 250px; height: 250px;"></div>
+ <div id="timeline2" style="float:left;width: 250px; height: 250px;"></div>
</div>
</body>
</html>
* 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
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 );
}
}
// Default to empty if not used
//options.innerHTML = options.innerHTML || "";
- newdiv.innerHTML = "<p><span id='big'>" + options.title + "</span><br />" +
+ contentDiv.innerHTML = "<p><span id='big'>" + options.title + "</span><br />" +
"<span id='mid'>" + options.text + "</span><br />" + 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 );
}
};
},
<video id='video'
controls preload='none'
width= '250px'
- poster="../../test/poster.png">
+ poster="../../test/poster.png"
+ style="float: left;">
<source id='mp4'
src="../../test/trailer.mp4"
<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>
+ <div id="timeline-up" style="float:left;width:400px;height:200px;overflow:auto"></div>
+ <div id="timeline-down" style="float:left;width:400px;height:200px;overflow:auto"></div>
</body>
</html>
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 );
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 <a href='http://www.google.ca'>Google</a>"
- } )
- .timeline({
+ innerHTML: "Click here for <a href='http://www.google.ca'>Google</a>"
+ } );
+ 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? <button onClick=\"window.location.href='http://www.google.com'\">Click Me</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? <button onClick=\"window.location.href='http://www.google.com'\">Click Me</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? <button onClick=\"window.location.href='http://www.google.com'\">Click Me</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();
});