]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#t461] adding debug and error logging to plugins
authorScottDowne <sdowne@learn.senecac.on.ca>
Tue, 19 Jul 2011 19:01:41 +0000 (15:01 -0400)
committerScottDowne <sdowne@learn.senecac.on.ca>
Tue, 19 Jul 2011 19:01:41 +0000 (15:01 -0400)
41 files changed:
plugins/attribution/popcorn.attribution.js
plugins/code/popcorn.code.html
plugins/code/popcorn.code.js
plugins/code/popcorn.code.unit.js
plugins/facebook/popcorn.facebook.js
plugins/flickr/popcorn.flickr.js
plugins/flickr/popcorn.flickr.unit.js
plugins/footnote/popcorn.footnote.js
plugins/gml/popcorn.gml.js
plugins/googlefeed/popcorn.googlefeed.html
plugins/googlefeed/popcorn.googlefeed.js
plugins/googlefeed/popcorn.googlefeed.unit.js
plugins/googlemap/popcorn.googlemap.js
plugins/googlemap/popcorn.googlemap.unit.js
plugins/googlenews/popcorn.googlenews.js
plugins/googlenews/popcorn.googlenews.unit.js
plugins/image/popcorn.image.js
plugins/lastfm/popcorn.lastfm.html
plugins/lastfm/popcorn.lastfm.js
plugins/lastfm/popcorn.lastfm.unit.js
plugins/linkedin/popcorn.linkedin.js
plugins/linkedin/popcorn.linkedin.unit.js
plugins/lowerthird/popcorn.lowerthird.html
plugins/lowerthird/popcorn.lowerthird.js
plugins/lowerthird/popcorn.lowerthird.unit.js
plugins/mustache/popcorn.mustache.js
plugins/mustache/popcorn.mustache.unit.js
plugins/openmap/popcorn.openmap.js
plugins/processing/popcorn.processing.html
plugins/processing/popcorn.processing.js
plugins/processing/popcorn.processing.unit.js
plugins/tagthisperson/popcorn.tagthisperson.js
plugins/timeline/popcorn.timeline.html
plugins/timeline/popcorn.timeline.js
plugins/twitter/popcorn.twitter.js
plugins/webpage/popcorn.webpage.js
plugins/wikipedia/popcorn.wikipedia.html
plugins/wikipedia/popcorn.wikipedia.js
plugins/wikipedia/popcorn.wikipedia.unit.js
plugins/wordriver/popcorn.wordriver.js
plugins/wordriver/popcorn.wordriver.unit.js

index 703ea964ff4e8a5ecdf944031b12596e4f03462d..fb3edd1a89362b599cb72fde1b07c206b9dc12f9 100755 (executable)
         
         options._container.innerHTML  = attrib;
 
+        if ( !target && Popcorn.plugin.debug ) {
+          throw new Error( "target container doesn't exist" );
+        }
         target && target.appendChild( options._container );
       },
       /**
index 25e00d9bbd56c77235d52d450b07e963fa64b2e8..973b5d2563a001a713ea36c87c892336ddc74b8c 100755 (executable)
 
      var p = Popcorn('#video')
 
-     .code({
-        start: 1,
-        end: 3,
-        onStart: function( options ) {
-          $('#test1').innerHTML = 'Yes';
-        }
-      })
+     .code({})
 
       .code({
         start: 5,
index a871a3505c0a6d99d150cc61a275cdc45d0b09dd..4a7c9c1bcae88d2448f4a2ff381631700b7bc014 100755 (executable)
     } )();
 
     if ( !options.onStart || typeof options.onStart !== 'function' ) {
-      throw 'Popcorn Code Plugin Error: onStart must be a function.';
+
+      if ( Popcorn.plugin.debug ) {
+        throw new Error( 'Popcorn Code Plugin Error: onStart must be a function.' );
+      }
+      options.onStart = Popcorn.nop;
     }
 
     if ( options.onEnd && typeof options.onEnd !== 'function' ) {
-      throw 'Popcorn Code Plugin Error: onEnd  must be a function.';
+
+      if ( Popcorn.plugin.debug ) {
+        throw new Error( 'Popcorn Code Plugin Error: onEnd  must be a function.' );
+      }
+      options.onEnd = undefined;
     }
 
     if ( options.onFrame && typeof options.onFrame !== 'function' ) {
-      throw 'Popcorn Code Plugin Error: onFrame  must be a function.';
+
+      if ( Popcorn.plugin.debug ) {
+        throw new Error( 'Popcorn Code Plugin Error: onFrame  must be a function.' );
+      }
+      options.onFrame = undefined;
     }
 
     return {
index 5daf6598090e708b609163af59e75faf3889851d..8aac07963580c0e661e9409564ebf390140b7d9c 100755 (executable)
@@ -1,7 +1,7 @@
 test('Popcorn Code Plugin', function () {
 
   var popped = Popcorn('#video'),
-      expects = 8,
+      expects = 9,
       count = 0,
       frames = 0,
       codeDiv = document.getElementById('code-div');
@@ -69,6 +69,18 @@ test('Popcorn Code Plugin', function () {
     }
   });
 
+  // empty track events should be safe
+  popped.code({});
+
+  // debug should log errors on empty track events
+  Popcorn.plugin.debug = true;
+  try {
+    popped.code({});
+  } catch( e ) {
+    ok(true, 'empty event was caught by debug');
+    plus();
+  }
+
   popped.volume(0);
   popped.play();
 });
index cfcd83c413360cefa1ffc2fc3684983dbf457617..0366ed0da86c6126d37c269e455b21fca55a1947 100755 (executable)
@@ -95,6 +95,9 @@
     },
     
     _setup: function( options ) {
+
+      var target = document.getElementById( options.target );
+
       // facebook script requires a div named fb-root
       if ( !document.getElementById( "fb-root" ) ) {
         var fbRoot = document.createElement( "div" );
 
       setOptions[ options.type ]();
 
-      if ( document.getElementById( options.target ) ) {
-        document.getElementById( options.target ).appendChild( options._container );
+      if ( !target && Popcorn.plugin.debug ) {
+        throw new Error( "flickr target container doesn't exist" );
       }
+      target && target.appendChild( options._container );
     },
     /**
     * @member facebook
index 2c14bc387a246bd45e93d8c5d9ffb6d95a73978b..dfd60314fb04468da6ae7f1fdf939431a31c85c3 100755 (executable)
@@ -45,6 +45,7 @@
 
   Popcorn.plugin( "flickr" , function( options ) {
     var containerDiv,
+        target = document.getElementById( options.target ),
         _userid,
         _uri,
         _link,
     idx++;
     
     // ensure the target container the user chose exists
-    if ( document.getElementById( options.target ) ) {
-      document.getElementById( options.target ).appendChild( containerDiv );
-    } else { 
-      throw ( "flickr target container doesn't exist" );
+    if ( !target && Popcorn.plugin.debug ) {
+      throw new Error( "flickr target container doesn't exist" );
     }
+    target && target.appendChild( containerDiv );
     
     // get the userid from Flickr API by using the username and apikey
     var isUserIDReady = function() {
index 4151b341296f0c7635b373a3028e6990d2c2d348..e9688fc0b5a3716bfd2ecf51ad75c3453c6c06b2 100755 (executable)
@@ -1,7 +1,7 @@
 test("Popcorn Flickr Plugin", function () {
   
   var popped = Popcorn( "#video" ),
-      expects = 10, 
+      expects = 11, 
       count = 0,
       setupId,
       flickrdiv = document.getElementById( "flickrdiv" );
@@ -81,7 +81,19 @@ test("Popcorn Flickr Plugin", function () {
     ok( !flickrdiv.children[2], "Removed flickr was properly destroyed"  );
     plus();
   });
-  
+
+  // empty track events should be safe
+  popped.flickr({});
+
+  // debug should log errors on empty track events
+  Popcorn.plugin.debug = true;
+  try {
+    popped.flickr({});
+  } catch( e ) {
+    ok(true, 'empty event was caught by debug');
+    plus();
+  }
+
   popped.volume(0).play();
   
 });
index 2570da1e3c89893756a77028e9af5594b89eb60d..436f7dcc8be9496fab4c3c8804bdc000bf3da531 100755 (executable)
       }
     },
     _setup: function(options) {
+
+      var target = document.getElementById( options.target );
+
       options._container = document.createElement( 'div' );
       options._container.style.display = "none";
       options._container.innerHTML  = options.text;
 
-      document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( options._container );
+      if ( !target && Popcorn.plugin.debug ) {
+        throw new Error( "target container doesn't exist" );
+      }
+      target && target.appendChild( options._container );
     },
     /**
      * @member footnote 
index f0b54b4005817e1e22ede80df38f0ab50ff77eab..17cf12f4ea0d79ed763d585af3093eb30f6e0aa8 100755 (executable)
 
     _setup : function( options ) {
 
-      var self = this;
+      var self = this,
+          target = document.getElementById( options.target );
       
       options.endDrawing = options.endDrawing || options.end;
 
       options.container.style.display = "none";
       options.container.setAttribute( "id", "canvas" + options.gmltag );
 
-      document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( options.container );
+      if ( !target && Popcorn.plugin.debug ) {
+        throw new Error( "target container doesn't exist" );
+      }
+      target && target.appendChild( options.container );
 
       if ( !window.Processing ) {
 
index 242d7e120ae4556c82e7266741bb45489fc9b440..72bc9a195eab0f6fe0b64ab2207ddc7d8a775dc0 100755 (executable)
@@ -56,4 +56,4 @@
     <div id="feed1" style="position:relative;float:left;width:600px;height:200px"><p>Horizontal Feed:</p></div>
   </div>
 </body>
-</html>
\ No newline at end of file
+</html>
index df44a77bc7b16fda1180d393016e7bfb3fef4a60..1a6d1cd4f21c04524485173826a41137c9b61de0 100755 (executable)
@@ -83,6 +83,7 @@
     // create a new div and append it to the parent div so nothing
     // that already exists in the parent div gets overwritten
     var newdiv = document.createElement( "div" ),
+        target = document.getElementById( options.target ),
     initialize = function() {
       //ensure that the script has been loaded
       if ( !scriptLoaded ) {
     newdiv.style.height = "100%";
     i++;
 
-    document.getElementById( options.target ).appendChild( newdiv );
+    if ( !target && Popcorn.plugin.debug ) {
+      throw new Error( "target container doesn't exist" );
+    }
+    target && target.appendChild( newdiv );
 
     initialize();
     
index 027625b4c05fc031a4d35d285a369d1f2e299637..06aff4af535769a68902e379533c8b15a7669c28 100755 (executable)
@@ -1,7 +1,7 @@
 test("Popcorn Google Feed Plugin", function () {
   
   var popped = Popcorn( "#video" ),
-      expects = 12,
+      expects = 13,
       setupId, 
       count = 0;
   
@@ -68,7 +68,19 @@ test("Popcorn Google Feed Plugin", function () {
     ok( !document.getElementById('feed1').children[0], "removed feed was properly destroyed"  );
     plus();
   });
-  
+
+  // empty track events should be safe
+  popped.googlefeed({});
+
+  // debug should log errors on empty track events
+  Popcorn.plugin.debug = true;
+  try {
+    popped.googlefeed({});
+  } catch( e ) {
+    ok(true, 'empty event was caught by debug');
+    plus();
+  }  
+
   popped.play();
   
 });
index f2b2bec0738b632d80c85e9fbb170fd960130a69..5c044c97f3f1f3ae8bcfd687aae397a207366b8f 100755 (executable)
@@ -76,7 +76,8 @@ var googleCallback;
    *
    */
   Popcorn.plugin("googlemap", function (options) {
-    var newdiv, map, location;
+    var newdiv, map, location,
+        target = document.getElementById( options.target );
 
     // if this is the firest time running the plugins
     // call the function that gets the sctipt
@@ -93,11 +94,10 @@ var googleCallback;
     i++;
 
     // ensure the target container the user chose exists
-    if (document.getElementById(options.target)) {
-      document.getElementById(options.target).appendChild(newdiv);
-    } else {
-      throw ("map target container doesn't exist");
+    if ( !target && Popcorn.plugin.debug ) {
+      throw new Error( "target container doesn't exist" );
     }
+    target && target.appendChild( newdiv );
 
     // ensure that google maps and its functions are loaded
     // before setting up the map parameters
index 335592428875d0257b6d92f5a2295ced867e149c..d3269057d6fc93933a029212b3b46f1f9fef52f6 100755 (executable)
@@ -1,7 +1,7 @@
 test("Popcorn Google Map Plugin", function () {
   
   var popped = Popcorn( "#video" ),
-      expects = 14, 
+      expects = 15, 
       count = 0,
       setupId;
   
@@ -95,6 +95,18 @@ test("Popcorn Google Map Plugin", function () {
     plus();
   });
 
+  // empty track events should be safe
+  popped.googlemap({});
+
+  // debug should log errors on empty track events
+  Popcorn.plugin.debug = true;
+  try {
+    popped.googlemap({});
+  } catch( e ) {
+    ok(true, 'empty event was caught by debug');
+    plus();
+  }
+
   popped.play();
   
 });
index fb808cfe5b5b40e80781bccdbb9cb4ce10347c4f..166be7d92761ba0b08045ac678895ddfae5120c0 100755 (executable)
       },
       _setup : function( options ) {
       
+        var target = document.getElementById( options.target );
+        options.container = document.createElement( 'div' );
+
+        if ( !target && Popcorn.plugin.debug ) {
+          throw new Error( "target container doesn't exist" );
+        }
+
+        var container = document.createElement( "div" );
+        target && target.appendChild( options.container );
+        options.container.appendChild( container );
+
         if ( !scriptLoading ) {
 
           scriptLoading = true;
           Popcorn.getScript( "http://www.google.com/jsapi", callBack );
         }
 
-        options.container = document.createElement( 'div' );
-        var container = document.createElement( 'div' );
-        if ( document.getElementById( options.target ) ) {
-          document.getElementById( options.target ).appendChild( options.container );
-          options.container.appendChild( container );
-        }
-
         var readyCheck = setInterval(function() {
           if ( !scriptLoaded ) {
             return;
           }
           clearInterval( readyCheck );
 
-          options.newsShow = new google.elements.NewsShow( container, {
+          options.newsShow = target && new google.elements.NewsShow( container, {
             format : "300x250",
             queryList : [
               { q: options.topic || "Top Stories" }
index a41c634c29184e75c3b29a22d64dd74098e06501..353b46a6bc4df404ba3c513e319e001b49831b26 100755 (executable)
@@ -1,7 +1,7 @@
 test( "Popcorn google news Plugin", function () {
   
   var popped = Popcorn( "#video" ),
-      expects = 8, 
+      expects = 9, 
       count = 0,
       setupId,
       googlenewsdiv = document.getElementById( "googlenewsdiv" );
@@ -21,6 +21,18 @@ test( "Popcorn google news Plugin", function () {
   
   equals ( googlenewsdiv.innerHTML, "", "initially, there is nothing inside the googlenewsdiv" );
   plus();
+
+  // empty track events should be safe
+  popped.googlenews({});
+
+  // debug should log errors on empty track events
+  Popcorn.plugin.debug = true;
+  try {
+    popped.googlenews({});
+  } catch( e ) {
+    ok(true, 'empty event was caught by debug');
+    plus();
+  }
   
   popped.googlenews({
     start: 0, // seconds
@@ -60,7 +72,7 @@ test( "Popcorn google news Plugin", function () {
     ok( !googlenewsdiv.children[1], "removed google news was properly destroyed" );
     plus();
   });
-  
+
   popped.play();
 
 });
index dc5f90dc26948396754e435c45994cb499d0307b..6da4bec2453a4b992bd68e78a09233be04d918fd 100755 (executable)
         }
       },
       _setup: function( options ) {
-        var img = document.createElement( "img" );
+        var img = document.createElement( "img" ),
+            target = document.getElementById( options.target );
 
         options.link = document.createElement( "a" );
         options.link.style.position = "relative";
         options.link.style.textDecoration = "none";
 
-        if ( document.getElementById( options.target ) ) {
-          // add the widget's div to the target div
-          document.getElementById( options.target ).appendChild( options.link );
+
+        if ( !target && Popcorn.plugin.debug ) {
+          throw new Error( "target container doesn't exist" );
         }
+        // add the widget's div to the target div
+        target && target.appendChild( options.link );
 
         img.addEventListener( "load", function() {
 
index 2d7e5ee242b746aa170abd79470c255d18eb7b6e..35ae0a0847cd4ed94d8c97ac5e2050c6b5bbd5e2 100755 (executable)
@@ -20,7 +20,6 @@
       .lastfm({
         start: 5, // seconds
         end: 15, // seconds
-        artist: 'yacht',
         target: 'lastfmdiv',
         apikey: '30ac38340e8be75f9268727cb4526b3d'
       } )
index 9de8702d3d69b3128efdca5117d8e23fb47263cf..2876d036f61d4a635ed0e1c554a77cd6a5bbd350 100755 (executable)
         options._container = document.createElement( 'div' );
         options._container.style.display = "none";
         options._container.innerHTML = "";
-        
-        options.artist = options.artist.toLowerCase();
+        options.artist = options.artist && options.artist.toLowerCase() || "";
+
+        var target = document.getElementById( options.target );
 
-        document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( options._container );
+        if ( !target && Popcorn.plugin.debug ) {
+          throw new Error( "target container doesn't exist" );
+        }
+        target && target.appendChild( options._container );
         
         if(!_artists[options.artist]) {
 
index f02c13ae441ecee27652c93d8652710c511d0023..a5c0c0a39aed9027b83a596a27811fcc88f8a326 100755 (executable)
@@ -6,7 +6,7 @@ test("Popcorn LastFM Plugin", function () {
     plugin. Please do not use it for other purposes.
   */
   var popped = Popcorn("#video"),
-      expects = 9, 
+      expects = 10, 
       count = 0,
       setupId,
       lastfmdiv = document.getElementById('lastfmdiv');
@@ -44,7 +44,6 @@ test("Popcorn LastFM Plugin", function () {
   .lastfm({
     start: 4, // seconds
     end: 7, // seconds
-    artist: '',
     target: 'lastfmdiv',
     apikey: '30ac38340e8be75f9268727cb4526b3d'
   });
@@ -75,6 +74,18 @@ test("Popcorn LastFM Plugin", function () {
     ok( !lastfmdiv.children[2], "removed artist was properly destroyed" );
     plus();
   });
+
+  // empty track events should be safe
+  popped.lastfm({});
+
+  // debug should log errors on empty track events
+  Popcorn.plugin.debug = true;
+  try {
+    popped.lastfm({});
+  } catch( e ) {
+    ok(true, 'empty event was caught by debug');
+    plus();
+  }
   
   popped.volume(0).play();
 });
index 991fe64e74b251cf01ace5d28c01eb5479a4627e..75363af5348e17d70de346527d46f8bd91d948c2 100755 (executable)
         script.innerHTML = "api_key: " + apikey;
       }
       
-      options.type = options.type.toLowerCase();
+      options.type = options.type && options.type.toLowerCase() || "";
       
       // Replace the LinkedIn plugin's error message to something more helpful
       var errorMsg = function() {
-
         options._container = document.createElement( "p" );
         options._container.innerHTML = "Plugin requires a valid <a href='https://www.linkedin.com/secure/developer'>apikey</a>";
-        document.getElementById( options.target ).appendChild( options._container );
+        if ( !target && Popcorn.plugin.debug ) {
+          throw ( "target container doesn't exist" );
+        }
+        target && target.appendChild( options._container );
       };
       
       var setOptions = (function ( options ) {
       } else {
         setOptions[ options.type ] && setOptions[ options.type ]();
       }
-      
-      if ( document.getElementById( options.target ) ) {
-        document.getElementById( options.target ).appendChild( options._container );
+
+      if ( !target && Popcorn.plugin.debug ) {
+        throw new Error( "target container doesn't exist" );
       }
+      target && target.appendChild( options._container );
 
-      target.style.display = "none";
+      options._container.style.display = "none";
     },
     /**
      * @member linkedin
      * options variable
      */
     start: function( event, options ) {
-      options._container.parentNode.style.display = "block";
+      options._container.style.display = "block";
     },
     /**
      * @member linkedin
      * options variable
      */    
     end: function( event, options ) {
-      options._container.parentNode.style.display = "none";
+      options._container.style.display = "none";
     },
     _teardown: function( options ) {
       var tar = document.getElementById( options.target );
index a4d84130e71d8ec48252eeb683c283414de63d0f..2625bff36a221e6271bd5ae2f79b3b966840cf10 100755 (executable)
@@ -4,7 +4,7 @@ test("Popcorn LinkedIn Plugin", function () {
     
     // run tests on localhost
     var popped = Popcorn("#video"),
-        expects = 22,
+        expects = 23,
         count = 0,
         setupId,
         sharediv = document.getElementById( "sharediv" ),
@@ -43,15 +43,15 @@ test("Popcorn LinkedIn Plugin", function () {
   
     popped.exec( 2, function() {
   
-      ok( /block/.test( sharediv.style.display ), "sharediv contents are displayed" );
+      ok( /block/.test( sharediv.children[ 0 ].style.display ), "sharediv contents are displayed" );
       plus();
-      ok( /script/.test( sharediv.innerHTML ), "share plugin exists" );
+      ok( /script/.test( sharediv.children[ 0 ].innerHTML ), "share plugin exists" );
       plus();
     });
     
     popped.exec( 4, function() {
   
-      ok( /none/.test( sharediv.style.display ), "sharediv contents are hidden again" );
+      ok( /none/.test( sharediv.children[ 0 ].style.display ), "sharediv contents are hidden again" );
       plus();
     });
     
@@ -72,15 +72,15 @@ test("Popcorn LinkedIn Plugin", function () {
     
     popped.exec( 2, function() {
   
-      ok( /block/.test( recommenddiv.style.display ), "recommenddiv contents are displayed" );
+      ok( /block/.test( recommenddiv.children[ 0 ].style.display ), "recommenddiv contents are displayed" );
       plus();
-      ok( /script/.test( recommenddiv.innerHTML ), "recommend plugin exists" );
+      ok( /script/.test( recommenddiv.children[ 0 ].innerHTML ), "recommend plugin exists" );
       plus();
     });
     
     popped.exec( 4, function() {
   
-      ok( /none/.test( recommenddiv.style.display ), "recommenddiv contents are hidden again" );
+      ok( /none/.test( recommenddiv.children[ 0 ].style.display ), "recommenddiv contents are hidden again" );
       plus();
     });
     
@@ -100,15 +100,15 @@ test("Popcorn LinkedIn Plugin", function () {
 
     popped.exec( 2, function() {
   
-      ok( /block/.test( memberprofilediv.style.display ), "memberprofilediv contents are displayed" );
+      ok( /block/.test( memberprofilediv.children[ 0 ].style.display ), "memberprofilediv contents are displayed" );
       plus();
-      ok( /script/.test( memberprofilediv.innerHTML ), "member profile plugin exists" );
+      ok( /script/.test( memberprofilediv.children[ 0 ].innerHTML ), "member profile plugin exists" );
       plus();
     });
     
     popped.exec( 4, function() {
   
-      ok( /none/.test( memberprofilediv.style.display ), "memberprofilediv contents are hidden again" );
+      ok( /none/.test( memberprofilediv.children[ 0 ].style.display ), "memberprofilediv contents are hidden again" );
       plus();
     });
     
@@ -127,15 +127,15 @@ test("Popcorn LinkedIn Plugin", function () {
 
     popped.exec( 2, function() {
   
-      ok( /block/.test( companyinsiderdiv.style.display ), "companyinsiderdiv contents are displayed" );
+      ok( /block/.test( companyinsiderdiv.children[ 0 ].style.display ), "companyinsiderdiv contents are displayed" );
       plus();
-      ok( /script/.test( companyinsiderdiv.innerHTML ), "company insider plugin exists" );
+      ok( /script/.test( companyinsiderdiv.children[ 0 ].innerHTML ), "company insider plugin exists" );
       plus();
     });
     
     popped.exec( 4, function() {
   
-      ok( /none/.test( companyinsiderdiv.style.display ), "companyinsiderdiv contents are hidden again" );
+      ok( /none/.test( companyinsiderdiv.children[ 0 ].style.display ), "companyinsiderdiv contents are hidden again" );
       plus();
     });
 
@@ -157,15 +157,15 @@ test("Popcorn LinkedIn Plugin", function () {
 
     popped.exec( 2, function() {
   
-      ok( /block/.test( companyprofilediv.style.display ), "companyprofilediv contents are displayed" );
+      ok( /block/.test( companyprofilediv.children[ 0 ].style.display ), "companyprofilediv contents are displayed" );
       plus();
-      ok( /script/.test( companyprofilediv.innerHTML ), "company profile plugin exists" );
+      ok( /script/.test( companyprofilediv.children[ 0 ].innerHTML ), "company profile plugin exists" );
       plus();
     });
     
     popped.exec( 4, function() {
   
-      ok( /none/.test( companyprofilediv.style.display ), "companyprofilediv contents are hidden again" );
+      ok( /none/.test( companyprofilediv.children[ 0 ].style.display ), "companyprofilediv contents are hidden again" );
       plus();
       
       // Make sure _teardown functionality works
@@ -173,7 +173,19 @@ test("Popcorn LinkedIn Plugin", function () {
       ok( !companyprofilediv.children[1], "companyprofilediv plugin was properly destroyed"  );
       plus();
     });
-    
+
+    // empty track events should be safe
+    popped.linkedin({});
+
+    // debug should log errors on empty track events
+    Popcorn.plugin.debug = true;
+    try {
+      popped.linkedin({});
+    } catch( e ) {
+      ok(true, 'empty event was caught by debug');
+      plus();
+    }
+
     popped.volume( 0 ).play();
   } else {
     
index 5ca491a28d03c78144c0662928bfd2a3469dfd21..7fb234f615cfbb1a793f402eb741b3c772a643b2 100755 (executable)
@@ -8,6 +8,7 @@
   <script src="popcorn.lowerthird.js"></script>
   <script>
     document.addEventListener('DOMContentLoaded', function () {
+
       var p = Popcorn('#video')
       .play()
       .lowerthird({
index e15418eb0284857c8a3ff55a34a64370ced18341..0e6277c1669e807f93a05c1bb7d71e98ed93745d 100755 (executable)
@@ -51,6 +51,8 @@
 
       _setup: function( options ) {
 
+        var target = document.getElementById( options.target );
+
         // Creates a div for all Lower Thirds to use
         if ( !this.container ) {
           this.container = document.createElement('div');
         }
 
         // if a target is specified, use that
-        if ( options.target && options.target !== 'lowerthird-container' ) {
-          options.container = document.getElementById( options.target );
+        if ( options.target && options.target !== "lowerthird-container") {
+          options.container = document.createElement( "div" );
+          if ( !target && Popcorn.plugin.debug ) {
+            throw new Error( "target container doesn't exist" );
+          }
+          target && target.appendChild( options.container );
         } else { // use shared default container
           options.container = this.container;
         }
 
-
-
       },
       /**
        * @member lowerthird
index ac37f3817611dbad5f39cfe156ea599eb1ba3955..fc81db04bc0490a1ad6ade2433080bc793b9b3ca 100755 (executable)
@@ -1,7 +1,7 @@
 test( "Popcorn lower third Plugin", function () {
   
   var popped = Popcorn( "#video" ),
-      expects = 7, 
+      expects = 8, 
       count = 0,
       lowerthirddiv = document.getElementById( "lowerthirddiv" );
 
@@ -24,7 +24,20 @@ test( "Popcorn lower third Plugin", function () {
   ok( !popped.container, "initially, there is no default div" );
   plus();
   
-  
+  // empty track events should be safe
+  popped.lowerthird({});
+
+  // debug should log errors on error track events
+  Popcorn.plugin.debug = true;
+  try {
+    popped.lowerthird({
+      target: "does not exist"
+    });
+  } catch( e ) {
+    ok(true, 'invalid target event was caught by debug');
+    plus();
+  }
+
   popped.lowerthird({
       start: 0, // seconds
       end: 2, // seconds
@@ -48,14 +61,14 @@ test( "Popcorn lower third Plugin", function () {
   });
   
   popped.exec( 3, function() {
-    equals ( lowerthirddiv.innerHTML, "Dr Jekyll<br>Person", "second lowerthird is visible" );
+    equals ( lowerthirddiv.innerHTML, "<div>Dr Jekyll<br>Person</div>", "second lowerthird is visible" );
     plus();
   });
   
   popped.exec( 5, function() {
     equals ( popped.container.innerHTML, "", "first lowerthird is empty" );
     plus();
-    equals ( lowerthirddiv.innerHTML, "", "second lowerthird is empty" );
+    equals ( lowerthirddiv.innerHTML, "<div></div>", "second lowerthird is empty" );
     plus();
   });
   
index 9c24694327e94f2f3380b2e37287d60e16384a8b..92813e89abf3fff8eb2aaf01bfab6b01b394ed2b 100755 (executable)
 
   Popcorn.plugin( 'mustache' , function( options ) {
 
-    var getData, data, getTemplate, template, loaded = false;
+    var getData, data, getTemplate, template;
 
-    Popcorn.getScript('https://github.com/janl/mustache.js/raw/master/mustache.js', function() {
-      loaded = true; 
-    });
+    Popcorn.getScript('https://github.com/janl/mustache.js/raw/master/mustache.js');
 
     var shouldReload = !!options.dynamic,
         typeOfTemplate = typeof options.template,
-        typeOfData = typeof options.data;
+        typeOfData = typeof options.data,
+        target = document.getElementById( options.target );
+
+    if ( !target && Popcorn.plugin.debug ) {
+      throw new Error( "target container doesn't exist" );
+    }
+    options.container = target || document.createElement( "div" );
 
     if ( typeOfTemplate === 'function' ) {
       if ( !shouldReload ) {
     } else if ( typeOfTemplate === 'string' ) {
       template = options.template;
     } else {
-      Popcorn.error( 'Mustache Plugin Error: options.template must be a String or a Function.' );
+      Popcorn.plugin.debug && Popcorn.error( 'Mustache Plugin Error: options.template must be a String or a Function.' );
+      template = "";
     }
 
     if ( typeOfData === 'function' ) {
     } else if ( typeOfData === 'object' ) {
       data = options.data;
     } else {
-      Popcorn.error( 'Mustache Plugin Error: options.data must be a String, Object, or Function.' );
+      Popcorn.plugin.debug && Popcorn.error( 'Mustache Plugin Error: options.data must be a String, Object, or Function.' );
+      data = "";
     }
 
     return {
       start: function( event, options ) {
 
         var interval = function() {
-          
-          if( !loaded ) {
+
+          if( !window.Mustache ) {
             setTimeout( function() {
               interval();
             }, 10 );
             var html = Mustache.to_html( template,
                                          data
                                        ).replace( /^\s*/mg, '' );
-            document.getElementById( options.target ).innerHTML = html;
+            options.container.innerHTML = html;
           }
         };
 
       },
 
       end: function( event, options ) {
-        document.getElementById( options.target ).innerHTML = '';
+        options.container.innerHTML = '';
       },
       _teardown: function( options ) {
         getData = data = getTemplate = template = null;
index 62568f2fc7cb66dda1f2cc10c99ed59851ea2055..c330b60c7a727d9a553376c29c4654958f31da55 100755 (executable)
@@ -1,7 +1,7 @@
 test('Popcorn Mustache Plugin', function () {
 
   var popped = Popcorn('#video'),
-      expects = 5,
+      expects = 6,
       count = 0,
       mustacheDiv = document.getElementById('mustache-div');
 
@@ -85,6 +85,18 @@ test('Popcorn Mustache Plugin', function () {
 
   }, false);
 
+  // empty track events should be safe
+  popped.mustache({});
+
+  // debug should log errors on empty track events
+  Popcorn.plugin.debug = true;
+  try {
+    popped.mustache({});
+  } catch( e ) {
+    ok(true, 'empty event was caught by debug');
+    plus();
+  }
+
   popped.volume(0);
   popped.play();
 });
index 7c51277e610b657b22ddf8cf9ff14420e5a77de9..ccc3d08c18241445cd1da3d3136f02ad6f008006 100755 (executable)
@@ -57,7 +57,8 @@
         displayProjection,
         pointLayer,
         selectControl,
-        popup;
+        popup,
+        target = document.getElementById( options.target );
 
     // create a new div within the target div
     // this is later passed on to the maps api
     newdiv.style.height  = "100%";
     i++;
 
-    document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( newdiv );
+
+    if ( !target && Popcorn.plugin.debug ) {
+      throw new Error( "target container doesn't exist" );
+    }
+    target && target.appendChild( newdiv );
 
     // callback function fires when the script is run
     var isGeoReady = function() {
index 94bb360def78cd33a20bb0b0a3cf59c1a817ac11..9ca0f503152834d9c4e6e60b845a09503ce4497c 100644 (file)
@@ -7,16 +7,11 @@
   
   <script>
     document.addEventListener( "DOMContentLoaded", function () {
+Popcorn.plugin.debug = true;
       var p = Popcorn( "#video" )
       .volume( 0 )
       .play()
-      .processing({
-        start: 2,
-        end: 10,
-        target: "processing-div",
-        sketch: "test.pjs",
-        noPause: true
-      })
+      .processing({})
       .processing({
         start: 10,
         end: 15,
index 560e4ff1ea8af97c4e315255a062d71e86e9aa1b..82c4a6eb495eff11e38153c1fdbabc36eedb6ced 100644 (file)
@@ -59,8 +59,8 @@
 
       options.parentTarget = document.getElementById( options.target );
       
-      if ( !options.parentTarget ) {
-        throw ( "target container doesn't exist" );
+      if ( !options.parentTarget && Popcorn.plugin.debug ) {
+        throw new Error( "target container doesn't exist" );
       }
       
       initProcessing = function() {
       canvas.style.display = "none";   
       options.canvas = canvas;
       
-      options.parentTarget.appendChild( options.canvas );
-      
-      Popcorn.xhr({
-        url: options.sketch,
-        dataType: "text",
-        success: function( responseCode ) {
-          options.codeReady = true;
-          options.processingCode = responseCode;
-          initProcessing();
+      options.parentTarget && options.parentTarget.appendChild( options.canvas );
+
+      if ( options.sketch ) {
+
+        Popcorn.xhr({
+          url: options.sketch,
+          dataType: "text",
+          success: function( responseCode ) {
+            options.codeReady = true;
+            options.processingCode = responseCode;
+            initProcessing();
+          }
+        });
+      } else {
+
+        if ( Popcorn.plugin.debug ) {
+          throw new Error( "options.sketch is undefined" );
         }
-      });
+      }
     };
 
     return {
index a4a40c79a671eac333c3f2fc6323a571c8a90110..e44c5c7480dc19508f26c83cad1318d1d857ffde 100644 (file)
@@ -1,6 +1,6 @@
 test( "Processing plugin tests", function() {
   var popped = Popcorn( "#video" ),
-      expects = 31,
+      expects = 32,
       count = 0,
       processingDiv = document.getElementById( "processing-div-1" ),
       processingDiv2 = document.getElementById( "processing-div-2" ),
@@ -131,6 +131,18 @@ test( "Processing plugin tests", function() {
     equals( ctx.style.display, "none", ctx.id + " is hidden initially" );
     plus();
   });
+
+  // empty track events should be safe
+  popped.processing({});
+
+  // debug should log errors on empty track events
+  Popcorn.plugin.debug = true;
+  try {
+    popped.processing({});
+  } catch( e ) {
+    ok(true, 'empty event was caught by debug');
+    plus();
+  }
   
   popped.play();
 });
index 519ac294884d7b27f7073dcbc19d8817d2cc6144..8bd07f09116606083d3a1d98deccb23d55d99bd8 100755 (executable)
         }
       },
       _setup: function( options ) {
-        var exists = false;
+        var exists = false,
+            target = document.getElementById( options.target );
+
+        if ( !target && Popcorn.plugin.debug ) {
+          throw new Error( "target container doesn't exist" );
+        }
+
         // loop through the existing objects to ensure no duplicates
         // the idea here is to have one object per unique options.target
         for ( var i = 0; i < peopleArray.length; i++ ) {
index e6dc422fe4793d5f6909c0d7d2ab7e0f73a3527a..880e2c2b8ebad294d44cb871314de6051b9bdd55 100644 (file)
       .volume(0)
       .play()
       .timeline({
-        start: 1, // seconds
-        target: "timeline",
-        title: "This is a title",
-        text: "this is some interesting text that goes inside",
-        innerHTML: "Click here for <a href='http://www.google.ca'>Google</a>" ,
-        direction: "down"
       } )
       .timeline({
         start: 3, // seconds
index ddc1fc4f97222a1e79caff295856df2bee768d91..641396b228a7a459f5a23baaa71e8c2fa0ece626 100644 (file)
     var target = document.getElementById( options.target ),
         newdiv = document.createElement( "div" );
 
-    target.style.width = "400px";
-    target.style.height = "200px";
-    target.style.overflow = "auto";
-
     newdiv.style.display = "none";
     newdiv.id = "timelineDiv" + i;
 
@@ -55,6 +51,9 @@
 
     if ( target ) {
 
+      target.style.width = "400px";
+      target.style.height = "200px";
+      target.style.overflow = "auto";
       target.appendChild( newdiv );
 
       // if this isnt the first div added to the target div
@@ -63,6 +62,8 @@
         target.insertBefore( newdiv, document.getElementById( "timelineDiv" + ( i - 1 ) ) );
       }
 
+    } else if ( Popcorn.plugin.debug ) {
+      throw new Error( "target container doesn't exist" );
     }
     
     i++;
index 103cec5e8f22bd1310e5db151cd9f99b5bd8a848..490899cb900be709495621d9c23b647d7b50093b 100755 (executable)
           Popcorn.getScript("http://widgets.twimg.com/j/2/widget.js");
         }
 
+        var target = document.getElementById( options.target );
+
         // setup widget div that is unique per track
         options.container = document.createElement( 'div' ); // create the div to store the widget
         options.container.setAttribute('id', Popcorn.guid()); // use this id to connect it to the widget
         options.container.style.display = "none"; // display none by default
 
+        if ( !target && Popcorn.plugin.debug ) {
+          throw new Error( "target container doesn't exist" );
+        }
          // add the widget's div to the target div
-        document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( options.container );
+        target && target.appendChild( options.container );
 
         // setup info for the widget
         var src     = options.src || "",
index 632e1a1a1401d0c5c4a02fd6ba73913a7e719454..1ac06a641b068530e7cff454d182b942fdd6bf91 100755 (executable)
       }
     },
     _setup : function( options ) {
-      // make an iframe 
+
+      var target = document.getElementById( options.target );
+
+      // make an iframe
       options._iframe  = document.createElement( 'iframe' );
       options._iframe.setAttribute('width', "100%");
       options._iframe.setAttribute('height', "100%");
       options._iframe.src = options.src;
       options._iframe.style.display = 'none';
 
+      if ( !target && Popcorn.plugin.debug ) {
+        throw new Error( "target container doesn't exist" );
+      }
+
       // add the hidden iframe to the DOM
-      document.getElementById( options.target ) && document.getElementById( options.target ).appendChild(options._iframe);
+      target && target.appendChild(options._iframe);
       
     },
     /**
index 067fab370575d5fb2f8fee29c1c1e761cfa311e5..3e24d669f4c87f4a1159435755086246d4d2d930 100755 (executable)
@@ -7,16 +7,11 @@
   <script src="popcorn.wikipedia.js"></script>
   <script>
     document.addEventListener('DOMContentLoaded', function () {
+Popcorn.plugin.debug = true;
       var p = Popcorn('#video')
       .volume(0)
       .play() 
-      .wikipedia({
-        start: 0, // seconds
-        end: 10, // seconds
-        src: 'http://en.wikipedia.org/wiki/Cape_Town',
-        title: "this is an article",
-        target: 'wikidiv'
-      } )
+      .wikipedia({} )
       .wikipedia({
         start: 7, // seconds
         end: 20, // seconds
index dfa775b8f0455248770034e72e1303baa7983ff8..1ff257e84dd899da8d846c9436c86463470efb08 100755 (executable)
@@ -121,8 +121,8 @@ var wikiCallback;
       if ( options.src ) {
         Popcorn.getScript( "http://" + options.lang + ".wikipedia.org/w/api.php?action=parse&props=text&page=" + 
           options.src.slice( options.src.lastIndexOf("/")+1)  + "&format=json&callback=wikiCallback" + _guid);
-      } else {
-        throw ( "Wikipedia plugin needs a 'src'" );
+      } else if ( Popcorn.plugin.debug ) {
+        throw new Error( "Wikipedia plugin needs a 'src'" );
       }
 
     },
index d30de47bbb5103c6335a185e7b6a7346972156c8..88863bcbe5278f1b88a5df5649ea1c0dc79f9f73 100755 (executable)
@@ -1,7 +1,7 @@
 test("Popcorn wikipedia Plugin", function () {
   
   var popped        = Popcorn( "#video" ),
-      expects       = 11, 
+      expects       = 12, 
       count         = 0,
       theArticle    = document.getElementById( "wikidiv" );
        
@@ -67,4 +67,16 @@ test("Popcorn wikipedia Plugin", function () {
     equals ( theArticle.innerHTML, "", "wikidiv is now empty" );
     plus();
   });
+
+  // empty track events should be safe
+  popped.wikipedia({});
+
+  // debug should log errors on empty track events
+  Popcorn.plugin.debug = true;
+  try {
+    popped.wikipedia({});
+  } catch( e ) {
+    ok(true, 'empty event was caught by debug');
+    plus();
+  }
 });
index 1e03b598356d4cfb51d474331f4056fe8fc010e5..cd74c42d490079cac8c2da535c27cf13d21817a6 100755 (executable)
 
       _setup: function( options ) {
 
+        if ( !document.getElementById( options.target ) && Popcorn.plugin.debug ) {
+          throw new Error( "target container doesn't exist" );
+        } 
+
         options._duration = options.end - options.start;
         options._container = container[ options.target ] || setupContainer( options.target );
 
         spanLocation = spanLocation % ( options._container.offsetWidth - options.word.offsetWidth );
         options.word.style.left = spanLocation + "px";
         spanLocation += options.word.offsetWidth + 10;
-
         options.word.style[ supports.transform ] = "translateY(" +
-          ( document.getElementById( options.target ).offsetHeight - options.word.offsetHeight ) + "px)";
+          ( options._container.offsetHeight - options.word.offsetHeight ) + "px)";
 
         options.word.style.opacity = 1;
 
index 1cc8e90f96d65274bf2d1f4750b1e4550b633a05..0d7a020eee12891ce384af7a3b0ba6e086f14352 100755 (executable)
@@ -1,7 +1,7 @@
 test( "Popcorn wordriver Plugin", function () {
   
   var popped = Popcorn( "#video" ),
-      expects = 16, 
+      expects = 17, 
       count = 0,
       firstTrack,
       secondTrack,
@@ -93,6 +93,18 @@ test( "Popcorn wordriver Plugin", function () {
     equals( wordriverdiv.childElementCount, 0, "wordriverdiv now has no inner element, even though one still exists, but was never called" );
     plus();
   });
+
+  // empty track events should be safe
+  popped.wordriver({});
+
+  // debug should log errors on empty track events
+  Popcorn.plugin.debug = true;
+  try {
+    popped.wordriver({});
+  } catch( e ) {
+    ok(true, 'empty event was caught by debug');
+    plus();
+  }
   
   popped.play();