data: []
},
manifestData = {},
- dataObj = data.json.data;
+ dataObj = data;
/*
*/
- Popcorn.forEach( dataObj, function ( obj, key ) {
+ Popcorn.forEach( dataObj.data, function ( obj, key ) {
retObj.data.push( obj );
});
0:00:02.400,0:00:07.200
Senator, we're making our final approach into Coruscant.
*/
- Popcorn.parser( "parseSBV", "SBV", function( data ) {
+ Popcorn.parser( "parseSBV", function( data ) {
// declare needed variables
var retObj = {
SSA tags with {\i1} would open and close italicize {\i0}, but are stripped
Multiple {\pos(142,120)\b1}SSA tags are stripped
*/
- Popcorn.parser( "parseSRT", "SRT", function( data ) {
+ Popcorn.parser( "parseSRT", function( data ) {
// declare needed variables
var retObj = {
*/
// Register for SSA extensions
- Popcorn.parser( "parseSSA", "SSA", function( data ) {
+ Popcorn.parser( "parseSSA", function( data ) {
// declare needed variables
var retObj = {
</body>
</tt>
*/
- Popcorn.parser( "parseTTML", "TTML", function( data ) {
+ Popcorn.parser( "parseTTML", function( data ) {
// declare needed variables
var returnData = {
* Example:
<TextSample sampleTime="00:00:00.000" text=""></TextSample>
*/
- Popcorn.parser( "parseTTXT", "TTXT", function( data ) {
+ Popcorn.parser( "parseTTXT", function( data ) {
// declare needed variables
var returnData = {
00:00:15.542 --> 00:00:18.542 A:start D:vertical L:98%
It's a <i>trap!</i>
*/
- Popcorn.parser( "parseVTT", "VTT", function( data ) {
+ Popcorn.parser( "parseVTT", function( data ) {
// declare needed variables
var retObj = {
};
// this is where things actually start
- var x = data.xml.documentElement.childNodes;
+ var x = data.documentElement.childNodes;
for ( var i = 0, xl = x.length; i < xl; i++ ) {
Popcorn.error("'" + name + "' is a protected function name");
return;
}
+
+ // fixes parameters for overloaded function call
+ if ( typeof type === "function" && !definition ) {
+ definition = type;
+ type = "";
+ }
- if ( typeof definition !== "function" ) {
+ if ( typeof definition !== "function" || typeof type !== "string" ) {
return;
}
parseFn,
parser = {};
- parseFn = function ( filename ) {
+ parseFn = function ( filename, callback ) {
if ( !filename ) {
return this;
Popcorn.xhr({
url: filename,
+ dataType: type,
success: function( data ) {
var tracksObject = definition( data ),
}
}
}
+ if ( callback ) {
+ callback();
+ }
}
});
Popcorn.extend( Popcorn.p, parser );
// keys the function name by filetype extension
- Popcorn.parsers[ type ] = name;
+ //Popcorn.parsers[ name ] = true;
return parser;
};
var video = videos[ key ],
hasDataSources = false,
- dataSources, dataTemp, dataType, parserFn, popcornVideo;
+ dataSources, data, popcornVideo;
// Ensure that the DOM has an id
if ( !video.id ) {
dataSources = ( video.getAttribute( "data-timeline-sources" ) || "" ).split(",");
- if ( dataSources.length ) {
+ if ( dataSources[ 0 ] ) {
Popcorn.forEach( dataSources, function ( source ) {
- dataTemp = source.split( ":" );
-
- dataType = dataTemp[0];
-
- if ( dataTemp.length === 1 ) {
+ // split the parser and data as parser:file
+ data = source.split( ":" );
- dataTemp = source.split( "." );
+ // if no parser is defined for the file, assume "parse" + file extension
+ if ( data.length === 1 ) {
- dataType = dataTemp[ dataTemp.length - 1 ];
+ data = source.split( "." );
+ data[ 0 ] = "parse" + data[ data.length - 1 ].toUpperCase();
+ data[ 1 ] = source;
}
- dataType = dataType.toUpperCase();
-
- parserFn = "parse" + dataType;
-
// If the video has data sources and the correct parser is registered, continue to load
- if ( dataSources && Popcorn.parsers[ dataType ] ) {
+ if ( dataSources[ 0 ] && popcornVideo[ data[ 0 ] ] ) {
// Set up the video and load in the datasources
- popcornVideo[ parserFn ]( source );
-
+ popcornVideo[ data[ 0 ] ]( data[ 1 ] );
}
});
- }
+ }
// Only play the video if it was specified to do so
if ( !!popcornVideo.autoplay ) {
plus();
Popcorn.parser( "parseJSON" , "json", function( data ){
- return data.json;
+ return data;
});
ok(typeof popperly.parseJSON === "function", "Popcorn.parser created a parseJSON function");
test("Parsing Integrity", function () {
- var expects = 2,
+ var expects = 6,
count = 0,
timeOut = 0,
- interval,
poppercore = Popcorn( "#video" );
function plus() {
if ( ++count === expects ) {
start();
// clean up added events after tests
- clearInterval( interval );
Popcorn.removePlugin( "parserTest" );
}
}
-
+
expect(expects);
-
+
stop( 10000 );
- Popcorn.parser( "parseJSON2" , "json", function( data ){
+ Popcorn.parser( "parseJSON2", function( data ){
+ ok( typeof data.json === "object", "data.json exists");
+ plus();
return data.json;
});
+ Popcorn.parser( "parseJSON3" , "json", function( data ){
+ ok( typeof data === "object", "data exists");
+ plus();
+ return data;
+ });
+
Popcorn.plugin("parserTest", {
start: function () {
}
});
- poppercore.parseJSON2("data/parserData.json");
+ poppercore.parseJSON2("data/parserData.json", function() {
+
+ poppercore.parseJSON3("data/parserData.json", function() {
+ poppercore.currentTime(5).play();
+ });
- // interval used to wait for data to be parsed
- interval = setInterval( function() {
- poppercore.currentTime(5).play();
- }, 2000);
+ });
});
stop();
- Popcorn.parser( "parseJson" , "json", function( data ){
+ Popcorn.parser( "parseJson", function( data ){
return data.json;
});