--- /dev/null
+// 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 );
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Popcorn 0.3 JSON parser Plug-in Tes</title>
+ <link rel="stylesheet" href="../../test/qunit/qunit.css" type="text/css" media="screen">
+ <script src="../../test/qunit/qunit.js"></script>
+ <!--
+ do not move - this must be called immediately prior to
+ popcorn-api-draft.js
+ -->
+ <script src="../../test/jquery.js"></script>
+
+ <script src="../../popcorn.js"></script>
+ <script src="../../plugins/webpage/popcorn.webpage.js"></script>
+ <script src="../../plugins/footnote/popcorn.footnote.js"></script>
+ <script src="../../plugins/googlemap/popcorn.googlemap.js"></script>
+ <script src="http://localhost/popcorn-js/parsers/parserJSON/popcorn.parserJSON.js"></script>
+ <script src="http://localhost/popcorn-js/parsers/parserJSON/popcorn.parserJSON.unit.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Popcorn 0.3 JSON parser Plug-in Test</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
+ width= '250px'
+ poster="../../test/poster.png">
+
+ <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"'>
+
+ <p>Your user agent does not support the HTML5 Video element.</p>
+
+ </video>
+ <style>
+ .displays {
+ width: 300px;
+ height: 300px;
+ }
+ </style>
+ <div class="displays" id="iframe-container"></div>
+ <div class="displays" id="map-container"></div>
+ <div class="displays" id="footnote-container"></div>
+</body>
+</html>
--- /dev/null
+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);
+
+});
}
dataType = dataType.toUpperCase();
-
+
parserFn = "parse" + dataType;
// If the video has data sources and the correct parser is registered, continue to load