]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
moved data-timeline automagical parsing into a new dir: modules, fixed core unit...
authorChristopher De Cairos <chris.decairos@gmail.com>
Fri, 16 Sep 2011 20:28:26 +0000 (16:28 -0400)
committerChristopher De Cairos <chris.decairos@gmail.com>
Fri, 16 Sep 2011 20:28:26 +0000 (16:28 -0400)
modules/timeline-sources/popcorn.timeline-sources.js [new file with mode: 0644]
modules/timeline-sources/popcorn.timeline-sources.unit.html [new file with mode: 0644]
modules/timeline-sources/popcorn.timeline-sources.unit.js [new file with mode: 0644]
popcorn.js
test/popcorn.unit.js

diff --git a/modules/timeline-sources/popcorn.timeline-sources.js b/modules/timeline-sources/popcorn.timeline-sources.js
new file mode 100644 (file)
index 0000000..3970350
--- /dev/null
@@ -0,0 +1,64 @@
+(function( Popcorn ) {
+  document.addEventListener( "DOMContentLoaded", function() {
+
+    //  Supports non-specific elements
+    var dataAttr = "data-timeline-sources",
+        medias = document.querySelectorAll( "[" + dataAttr + "]" );
+
+    Popcorn.forEach( medias, function( idx, key ) {
+
+      var media = medias[ key ],
+          hasDataSources = false,
+          dataSources, data, popcornMedia;
+
+      //  Ensure that the DOM has an id
+      if ( !media.id ) {
+
+        media.id = Popcorn.guid( "__popcorn" );
+      }
+
+      //  Ensure we're looking at a dom node
+      if ( media.nodeType && media.nodeType === 1 ) {
+
+        popcornMedia = Popcorn( "#" + media.id );
+
+        dataSources = ( media.getAttribute( dataAttr ) || "" ).split( "," );
+
+        if ( dataSources[ 0 ] ) {
+
+          Popcorn.forEach( dataSources, function( source ) {
+
+            // split the parser and data as parser!file
+            data = source.split( "!" );
+
+            // if no parser is defined for the file, assume "parse" + file extension
+            if ( data.length === 1 ) {
+
+              // parse a relative URL for the filename, split to get extension
+                                                       data = source.match( /(.*)[\/\\]([^\/\\]+\.\w+)$/ )[ 2 ].split( "." );
+
+              data[ 0 ] = "parse" + data[ 1 ].toUpperCase();
+              data[ 1 ] = source;
+            }
+
+            //  If the media has data sources and the correct parser is registered, continue to load
+            if ( dataSources[ 0 ] && popcornMedia[ data[ 0 ] ] ) {
+
+              //  Set up the media and load in the datasources
+              popcornMedia[ data[ 0 ] ]( data[ 1 ] );
+
+            }
+          });
+
+        }
+
+        //  Only play the media if it was specified to do so
+        if ( !!popcornMedia.autoplay ) {
+          popcornMedia.play();
+        }
+
+      }
+    });
+  }, false );
+
+})( Popcorn );
\ No newline at end of file
diff --git a/modules/timeline-sources/popcorn.timeline-sources.unit.html b/modules/timeline-sources/popcorn.timeline-sources.unit.html
new file mode 100644 (file)
index 0000000..122aee3
--- /dev/null
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>Popcorn Module: Timeline-Sources</title>
+  <link rel="stylesheet" href="../../test/qunit/qunit.css" type="text/css" media="screen">
+  <script src="../../test/qunit/qunit.js"></script>
+
+  <script src="../../popcorn.js"></script>
+  <script src="popcorn.timeline-sources.js"></script>
+  <script src="popcorn.timeline-sources.unit.js"></script>
+  <script src="../../parsers/parserJSON/popcorn.parserJSON.js"></script>
+</head>
+<body>
+  <h1 id="qunit-header">Popcorn Module: timeline-sources</h1>
+  <h2 id="qunit-banner"></h2>
+  <div id="qunit-testrunner-toolbar"></div>
+  <h2 id="qunit-userAgent"></h2>
+  <ol id="qunit-tests"></ol>
+  <div id="qunit-fixture">  </div>
+
+  <video id='video'
+    controls preload='none'
+    width= '250px'
+    poster="../../test/poster.png"
+    data-timeline-sources="../../parsers/parserJSON/data/video.json">
+
+    <source id='mp4'
+      src="../../test/trailer.mp4"
+      type='video/mp4; codecs="avc1, mp4a"'>
+
+    <source id='ogv'
+      src="../../test/trailer.ogv"
+      type='video/ogg; codecs="theora, vorbis"'>
+
+    <source id='webm'
+      src="../../test/trailer.webm"
+      type='video/webm; codecs="vp8, vorbis"'>
+
+    <p>Your user agent does not support the HTML5 Video element.</p>
+
+  </video> 
+</body>
+</html>
diff --git a/modules/timeline-sources/popcorn.timeline-sources.unit.js b/modules/timeline-sources/popcorn.timeline-sources.unit.js
new file mode 100644 (file)
index 0000000..e48f174
--- /dev/null
@@ -0,0 +1,79 @@
+(function( Popcorn ) {
+
+  var setupCalled = 0,
+      startCalled = 0,
+      endCalled = 0;
+
+  Popcorn.plugin( "footnote", function( options ) {
+    return {
+      _setup: function() {
+          setupCalled++;
+        },
+      start: function() {
+        startCalled++;
+      },
+      end: function() {
+        endCalled++;
+      }
+    };
+  });
+
+  Popcorn.plugin( "googlemap", function( options ) {
+    return {
+      _setup: function() {
+        setupCalled++;
+      },
+      start: function() {
+        startCalled++;
+      },
+      end: function() {
+        endCalled++;
+      }
+    };
+  });
+
+  Popcorn.plugin( "webpage", function( options ) {
+    return {
+      _setup: function() {
+        setupCalled++;
+      },
+      start: function() {
+        startCalled++;
+      },
+      end: function() {
+        endCalled++;
+      }
+    };
+  });
+
+  test( "Timeline-sources Module", function() {
+    expect( 3 );
+
+    var count = 0,
+        p = Popcorn.getInstanceById( "video" );
+
+    function plus() {
+      if ( ++count === 3 ) {
+        start();
+      }
+    }
+
+    stop();
+
+    p.exec( 3, function() {
+      equals( startCalled, 5, "start was called 5 times from the parsed data" );
+      plus();
+      p.currentTime( 9 );
+    });
+
+    p.exec( 10.5, function() {
+      equals( endCalled, 5, "end was called 5 times from the parsed data" );
+      plus()
+    });
+
+    equals( setupCalled, 5, "setup was called 5 times from the parsed data" );
+    plus();
+
+  });
+
+})( Popcorn );
\ No newline at end of file
index e2c7320a73229cfaa39255e2c7fe59c740cf6e82..43765805a4ca3857e6e1b4b5480f01dc5bbae023 100644 (file)
   //  Exposes Popcorn to global context
   global.Popcorn = Popcorn;
 
-  document.addEventListener( "DOMContentLoaded", function() {
-
-    //  Supports non-specific elements
-    var dataAttr = "data-timeline-sources",
-        medias = document.querySelectorAll( "[" + dataAttr + "]" );
-
-    Popcorn.forEach( medias, function( idx, key ) {
-
-      var media = medias[ key ],
-          hasDataSources = false,
-          dataSources, data, popcornMedia;
-
-      //  Ensure that the DOM has an id
-      if ( !media.id ) {
-
-        media.id = Popcorn.guid( "__popcorn" );
-      }
-
-      //  Ensure we're looking at a dom node
-      if ( media.nodeType && media.nodeType === 1 ) {
-
-        popcornMedia = Popcorn( "#" + media.id );
-
-        dataSources = ( media.getAttribute( dataAttr ) || "" ).split( "," );
-
-        if ( dataSources[ 0 ] ) {
-
-          Popcorn.forEach( dataSources, function( source ) {
-
-            // split the parser and data as parser!file
-            data = source.split( "!" );
-
-            // if no parser is defined for the file, assume "parse" + file extension
-            if ( data.length === 1 ) {
-
-              data = source.split( "." );
-              data[ 0 ] = "parse" + data[ data.length - 1 ].toUpperCase();
-              data[ 1 ] = source;
-            }
-
-            //  If the media has data sources and the correct parser is registered, continue to load
-            if ( dataSources[ 0 ] && popcornMedia[ data[ 0 ] ] ) {
-
-              //  Set up the media and load in the datasources
-              popcornMedia[ data[ 0 ] ]( data[ 1 ] );
-
-            }
-          });
-
-        }
-
-        //  Only play the media if it was specified to do so
-        if ( !!popcornMedia.autoplay ) {
-          popcornMedia.play();
-        }
-
-      }
-    });
-  }, false );
-
 })(window, window.document);
-
index 6dfff8f4996c8d8ecd5150f130ac1e8564ec6b5d..37f0340d5732fe47063c5ca526774f095950a6a3 100644 (file)
@@ -268,7 +268,7 @@ test("Instances", function() {
   ok( instance instanceof Popcorn, "Instance instanceof Popcorn" );
   plus();
 
-  equal( Popcorn.instances.length, 2, "There are the correct number of Popcorn instances" );
+  equal( Popcorn.instances.length, 1, "There are the correct number of Popcorn instances" );
   plus();
 
   //  Create another instance
@@ -278,7 +278,7 @@ test("Instances", function() {
   var remove = Popcorn.instances[1];
 
   //  Remove and check the length of the currently cached instances
-  equal( Popcorn.removeInstanceById( remove.id ).length, 2, "Removing an instance by id: 1 instance remains" );
+  equal( Popcorn.removeInstanceById( remove.id ).length, 1, "Removing an instance by id: 1 instance remains" );
   plus();
 });