]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#245] Popcorn data object parser plugin; Parses and loads a Butter generated and...
authorrwldrn <waldron.rick@gmail.com>
Mon, 17 Jan 2011 22:08:50 +0000 (17:08 -0500)
committerAnna Sobiepanek <annaopensource@gmail.com>
Wed, 19 Jan 2011 21:27:26 +0000 (16:27 -0500)
parsers/parserJSON/popcorn.parserJSON.js [new file with mode: 0644]
parsers/parserJSON/popcorn.parserJSON.unit.html [new file with mode: 0644]
parsers/parserJSON/popcorn.parserJSON.unit.js [new file with mode: 0644]
popcorn.js

diff --git a/parsers/parserJSON/popcorn.parserJSON.js b/parsers/parserJSON/popcorn.parserJSON.js
new file mode 100644 (file)
index 0000000..9d398e2
--- /dev/null
@@ -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 (file)
index 0000000..84512e8
--- /dev/null
@@ -0,0 +1,54 @@
+<!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>
diff --git a/parsers/parserJSON/popcorn.parserJSON.unit.js b/parsers/parserJSON/popcorn.parserJSON.unit.js
new file mode 100644 (file)
index 0000000..1a6e2fb
--- /dev/null
@@ -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);
+  
+});
index 7a45ce776ba0770fb15db58a6ed79e390dfb5663..477563288d819cdf8000c58128fdecc96912ff77 100644 (file)
             }
             
             dataType = dataType.toUpperCase();
-            
+     
             parserFn = "parse" + dataType;
 
             //  If the video has data sources and the correct parser is registered, continue to load