From: rwldrn Date: Mon, 17 Jan 2011 22:08:50 +0000 (-0500) Subject: [#245] Popcorn data object parser plugin; Parses and loads a Butter generated and... X-Git-Tag: v0.3~28 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=0a648233602fe1bb3abad2bacd7577923911d7ed;p=popcorn-js.git [#245] Popcorn data object parser plugin; Parses and loads a Butter generated and serialized data object --- diff --git a/parsers/parserJSON/popcorn.parserJSON.js b/parsers/parserJSON/popcorn.parserJSON.js new file mode 100644 index 0000000..9d398e2 --- /dev/null +++ b/parsers/parserJSON/popcorn.parserJSON.js @@ -0,0 +1,41 @@ +// PARSER: 0.3 JSON + +(function (Popcorn) { + Popcorn.parser( "parseJSON", "JSON", function( data ) { + + // declare needed variables + var retObj = { + title: "", + remote: "", + data: [] + }, + manifestData = {}, + dataObj = data.json.data; + + + /* + TODO: add support for filling in source children of the video element + + + remote: [ + { + src: "whatever.mp4", + type: 'video/mp4; codecs="avc1, mp4a"' + }, + { + src: "whatever.ogv", + type: 'video/ogg; codecs="theora, vorbis"' + } + ] + + */ + + + Popcorn.forEach( dataObj, function ( obj, key ) { + retObj.data.push( obj ); + }); + + return retObj; + }); + +})( Popcorn ); diff --git a/parsers/parserJSON/popcorn.parserJSON.unit.html b/parsers/parserJSON/popcorn.parserJSON.unit.html new file mode 100644 index 0000000..84512e8 --- /dev/null +++ b/parsers/parserJSON/popcorn.parserJSON.unit.html @@ -0,0 +1,54 @@ + + + + Popcorn 0.3 JSON parser Plug-in Tes + + + + + + + + + + + + + +

Popcorn 0.3 JSON parser Plug-in Test

+

+
+

+
    +
    + + + +
    +
    +
    + + diff --git a/parsers/parserJSON/popcorn.parserJSON.unit.js b/parsers/parserJSON/popcorn.parserJSON.unit.js new file mode 100644 index 0000000..1a6e2fb --- /dev/null +++ b/parsers/parserJSON/popcorn.parserJSON.unit.js @@ -0,0 +1,100 @@ +test("Popcorn 0.3 JSON Parser Plugin", function () { + + var expects = 9, + count = 0, + timeOut = 0, + numLoadingEvents = 5, + trackData, + trackEvents, + interval, + poppercorn = Popcorn( "#video" ); + + function plus() { + if ( ++count === expects ) { + start(); + // clean up added events after tests + clearInterval( interval ); + } + } + + poppercorn.parseJSON("data/data.json"); + + expect(expects); + + stop( 10000 ); + + + + + setTimeout(function () { + + trackData = poppercorn.data; + trackEvents = trackData.trackEvents; + + + equals( trackEvents.byStart.length, numLoadingEvents + 2 , "trackEvents.byStart.length === (5 loaded, 2 padding) " ); + plus(); + + + Popcorn.xhr({ + url: 'data/data.json', + success: function( data ) { + + var idx = 0; + + Popcorn.forEach( data.json.data, function (dataObj) { + Popcorn.forEach( dataObj, function ( obj, key ) { + + + equals( trackData.history[idx].indexOf(key), 0, "history item '" + trackData.history[idx] + "' matches data key '"+ key+ "' at correct index" ); + plus(); + + idx++; + }); + }); + + + } + }); + + + + + poppercorn.listen("timeupdate", function ( event ) { + + if ( Math.round( this.currentTime()) === 3 ) { + + equals( $("#iframe-container").children().length, 2, '$("#iframe-container").children().length' ) + plus(); + equals( $("#map-container").children().length, 1, '$("#map-container").children().length' ); + plus(); + equals( $("#footnote-container").children().length, 2, '$("#footnote-container").children().length' ); + plus(); + + this.pause(); + + } + + + }); + + + poppercorn.currentTime(0).play() + + + }, 500); + + + + + + + + + + // interval used to wait for data to be parsed + //interval = setInterval( function() { + //poppercorn.currentTime(5).play().currentTime(6); + //}, 2000); + +}); diff --git a/popcorn.js b/popcorn.js index 7a45ce7..4775632 100644 --- a/popcorn.js +++ b/popcorn.js @@ -948,7 +948,7 @@ } dataType = dataType.toUpperCase(); - + parserFn = "parse" + dataType; // If the video has data sources and the correct parser is registered, continue to load