]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#297] parser plugin datatype playing nice with xhr and data-timeline-sources, plus...
authorScottDowne <sdowne@learn.senecac.on.ca>
Fri, 18 Feb 2011 21:01:11 +0000 (16:01 -0500)
committerScottDowne <sdowne@learn.senecac.on.ca>
Fri, 18 Feb 2011 21:01:11 +0000 (16:01 -0500)
parsers/parserJSON/popcorn.parserJSON.js
parsers/parserSBV/popcorn.parseSBV.js
parsers/parserSRT/popcorn.parserSRT.js
parsers/parserSSA/popcorn.parseSSA.js
parsers/parserTTML/popcorn.parseTTML.js
parsers/parserTTXT/popcorn.parseTTXT.js
parsers/parserVTT/popcorn.parserVTT.js
parsers/parserXML/popcorn.parseXML.js
popcorn.js
test/popcorn.unit.js

index 9d398e2e4c74c198e1f463fec1986be1b7ad550b..4297f37b6fc791794b5038fe5625f8a05273e562 100644 (file)
@@ -10,7 +10,7 @@
           data: []
         },
         manifestData = {}, 
-        dataObj = data.json.data;
+        dataObj = data;
     
     
     /*
@@ -31,7 +31,7 @@
     */
     
         
-    Popcorn.forEach( dataObj, function ( obj, key ) {
+    Popcorn.forEach( dataObj.data, function ( obj, key ) {
       retObj.data.push( obj );
     });
 
index 364fba8ed7e87643f4724c5cb1d5a21dabb0fca6..145bda0b8db77abfbd917158e2dd72d90f729949 100644 (file)
@@ -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 = {
index 2ab5f8356ec1c0d7912ec9d0cf17a0604d078eb5..0ff28265090b7deae6208f3e56253492d69780e7 100644 (file)
@@ -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 = {
index 1597358174fc8098d37381d086910fd239a4dddf..51574c1928c80543b1d3a3ccbc2a72256a5eed12 100644 (file)
@@ -28,7 +28,7 @@
    */
   
   // Register for SSA extensions
-  Popcorn.parser( "parseSSA", "SSA", function( data ) {
+  Popcorn.parser( "parseSSA", function( data ) {
   
     // declare needed variables
     var retObj = {
index 42e88fe48e6c783d476e3a77be47fc7d7bee5f48..e4ec9f8a3c2adc2c0b35cd04f9df80c22850012b 100644 (file)
@@ -26,7 +26,7 @@
       </body>
     </tt>
    */
-  Popcorn.parser( "parseTTML", "TTML", function( data ) {
+  Popcorn.parser( "parseTTML", function( data ) {
 
     // declare needed variables
     var returnData = {
index d3c7341138c573dd51444606b5ea674ac713437a..592f9b7435a1f51f3e9d1fa6505dafd143608cf5 100644 (file)
@@ -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 = {
index 6aee0249cfb2402aabca90a45e6b517f3ead2d3d..1bcdbc73c2bd1e939be45a2ee6b83cbc0d9ead0d 100644 (file)
@@ -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 = {
index 8363bb10277ac4b87d9baaf99946279c4ff02fa5..d33895aeced6318a4f9ada042cff90738eed6d0e 100644 (file)
@@ -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++ ) {
 
index 9f63c0c3967a259a0bec1bc8adda073887f1460a..d80b53ae23fa5f16a31e32d042af4f4cffe7029b 100644 (file)
       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 ) {
index c1660c1514f50fc088742482096ddbaff8143ddb..0ca2c0caba21fffb6aac6dbfafec7387693a5d53 100644 (file)
@@ -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");
@@ -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 () {
@@ -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);
+  });
 
 });
 
@@ -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;
   });