--- /dev/null
+(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
--- /dev/null
+<!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>
--- /dev/null
+(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
// 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);
-
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
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();
});