From c81c046eab79a8503e518c99234a4077ced7113e Mon Sep 17 00:00:00 2001 From: ScottDowne Date: Thu, 6 Jan 2011 11:55:00 -0500 Subject: [PATCH] [#221] data-timeline-sources functionality upgraded --- popcorn.js | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/popcorn.js b/popcorn.js index 435cfb8..f9ebcc9 100644 --- a/popcorn.js +++ b/popcorn.js @@ -852,19 +852,34 @@ // Exposes Popcorn to global context global.Popcorn = Popcorn; - document.addEventListener('DOMContentLoaded', function () { - - var video = document.getElementsByTagName( 'video' ); - for ( var i = 0, l = video.length; i < l; i++ ) { - var ind = i, - videoSources = video[ind].getAttribute( 'data-timeline-sources' ); - if (videoSources) { - var p = Popcorn('#' + video[ind].getAttribute( 'id' ) ) - .parseXML( videoSources ) - .play(); - } - } + document.addEventListener( "DOMContentLoaded", function () { + + var videos = document.getElementsByTagName( "video" ); + + Popcorn.forEach( videos, function ( iter, key ) { - }, false); + var video = videos[ key ], + dataSources, popcornVideo; + + // Ensure we're looking at a dom node and that it has an id + // otherwise Popcorn won't be able to find the video element + if ( video.nodeType && video.nodeType === 1 && video.id ) { + + dataSources = video.getAttribute( "data-timeline-sources" ); + + // If the video has data sources, continue to load + if ( dataSources ) { + + // Set up the video and load in the datasources + popcornVideo = Popcorn( "#" + video.id ).parseXML( dataSources ); + + // Only play the video if it was specified to do so + if ( !!popcornVideo.autoplay ) { + popcornVideo.play(); + } + } + } + }); + }, false ); })(window, window.document); -- 2.43.0