Skip to content
This repository has been archived by the owner on Jun 29, 2018. It is now read-only.

Commit

Permalink
[#297] parser plugin datatype playing nice with xhr and data-timeline…
Browse files Browse the repository at this point in the history
…-sources, plus parser callback for testing
  • Loading branch information
ScottDowne committed Feb 18, 2011
1 parent 160025b commit 8026a9f
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 42 deletions.
4 changes: 2 additions & 2 deletions parsers/parserJSON/popcorn.parserJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
data: []
},
manifestData = {},
dataObj = data.json.data;
dataObj = data;


/*
Expand All @@ -31,7 +31,7 @@
*/


Popcorn.forEach( dataObj, function ( obj, key ) {
Popcorn.forEach( dataObj.data, function ( obj, key ) {
retObj.data.push( obj );
});

Expand Down
2 changes: 1 addition & 1 deletion parsers/parserSBV/popcorn.parseSBV.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
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 = {
Expand Down
2 changes: 1 addition & 1 deletion parsers/parserSRT/popcorn.parserSRT.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
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 = {
Expand Down
2 changes: 1 addition & 1 deletion parsers/parserSSA/popcorn.parseSSA.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/

// Register for SSA extensions
Popcorn.parser( "parseSSA", "SSA", function( data ) {
Popcorn.parser( "parseSSA", function( data ) {

// declare needed variables
var retObj = {
Expand Down
2 changes: 1 addition & 1 deletion parsers/parserTTML/popcorn.parseTTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</body>
</tt>
*/
Popcorn.parser( "parseTTML", "TTML", function( data ) {
Popcorn.parser( "parseTTML", function( data ) {

// declare needed variables
var returnData = {
Expand Down
2 changes: 1 addition & 1 deletion parsers/parserTTXT/popcorn.parseTTXT.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* 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 = {
Expand Down
2 changes: 1 addition & 1 deletion parsers/parserVTT/popcorn.parserVTT.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
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 = {
Expand Down
2 changes: 1 addition & 1 deletion parsers/parserXML/popcorn.parseXML.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
};

// 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++ ) {

Expand Down
45 changes: 25 additions & 20 deletions popcorn.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,14 @@
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;
}

Expand All @@ -809,7 +815,7 @@
parseFn,
parser = {};

parseFn = function ( filename ) {
parseFn = function ( filename, callback ) {

if ( !filename ) {
return this;
Expand All @@ -819,6 +825,7 @@

Popcorn.xhr({
url: filename,
dataType: type,
success: function( data ) {

var tracksObject = definition( data ),
Expand Down Expand Up @@ -849,6 +856,9 @@
}
}
}
if ( callback ) {
callback();
}
}
});

Expand All @@ -862,7 +872,7 @@
Popcorn.extend( Popcorn.p, parser );

// keys the function name by filetype extension
Popcorn.parsers[ type ] = name;
//Popcorn.parsers[ name ] = true;

return parser;
};
Expand Down Expand Up @@ -1016,7 +1026,7 @@

var video = videos[ key ],
hasDataSources = false,
dataSources, dataTemp, dataType, parserFn, popcornVideo;
dataSources, data, popcornVideo;

// Ensure that the DOM has an id
if ( !video.id ) {
Expand All @@ -1032,37 +1042,32 @@

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 ) {
Expand Down
33 changes: 20 additions & 13 deletions test/popcorn.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ test("Parsing Functions", function () {
plus();

Popcorn.parser( "parseJSON" , "json", function( data ){
return data.json;
return data;
});

ok(typeof popperly.parseJSON === "function", "Popcorn.parser created a parseJSON function");
Expand All @@ -1379,29 +1379,35 @@ test("Parsing Functions", 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 () {
Expand All @@ -1414,12 +1420,13 @@ test("Parsing Integrity", 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);
});

});

Expand All @@ -1445,7 +1452,7 @@ test("Parsing Handler - References unavailable plugin", function () {

stop();

Popcorn.parser( "parseJson" , "json", function( data ){
Popcorn.parser( "parseJson", function( data ){

return data.json;
});
Expand Down

0 comments on commit 8026a9f

Please sign in to comment.