]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#221] data-timeline-sources functionality upgraded
authorScottDowne <sdowne@learn.senecac.on.ca>
Thu, 6 Jan 2011 16:55:00 +0000 (11:55 -0500)
committerScottDowne <sdowne@learn.senecac.on.ca>
Thu, 6 Jan 2011 16:55:00 +0000 (11:55 -0500)
popcorn.js

index 435cfb845d5240a1ba3e268fbbcc5130e63936d6..f9ebcc98ac0c03173fb947dbd71a44d6c8df4be0 100644 (file)
   //  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);