From: ScottDowne Date: Tue, 19 Jul 2011 19:01:41 +0000 (-0400) Subject: [#t461] adding debug and error logging to plugins X-Git-Tag: v0.8^2~7^2~3^2~7 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=4aaf54e0d2cd846918ff266640157b64b8a0a5d1;p=popcorn-js.git [#t461] adding debug and error logging to plugins --- diff --git a/plugins/attribution/popcorn.attribution.js b/plugins/attribution/popcorn.attribution.js index 703ea96..fb3edd1 100755 --- a/plugins/attribution/popcorn.attribution.js +++ b/plugins/attribution/popcorn.attribution.js @@ -120,6 +120,9 @@ options._container.innerHTML = attrib; + if ( !target && Popcorn.plugin.debug ) { + throw new Error( "target container doesn't exist" ); + } target && target.appendChild( options._container ); }, /** diff --git a/plugins/code/popcorn.code.html b/plugins/code/popcorn.code.html index 25e00d9..973b5d2 100755 --- a/plugins/code/popcorn.code.html +++ b/plugins/code/popcorn.code.html @@ -16,13 +16,7 @@ var p = Popcorn('#video') - .code({ - start: 1, - end: 3, - onStart: function( options ) { - $('#test1').innerHTML = 'Yes'; - } - }) + .code({}) .code({ start: 5, diff --git a/plugins/code/popcorn.code.js b/plugins/code/popcorn.code.js index a871a35..4a7c9c1 100755 --- a/plugins/code/popcorn.code.js +++ b/plugins/code/popcorn.code.js @@ -102,15 +102,27 @@ } )(); 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 { diff --git a/plugins/code/popcorn.code.unit.js b/plugins/code/popcorn.code.unit.js index 5daf659..8aac079 100755 --- a/plugins/code/popcorn.code.unit.js +++ b/plugins/code/popcorn.code.unit.js @@ -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(); }); diff --git a/plugins/facebook/popcorn.facebook.js b/plugins/facebook/popcorn.facebook.js index cfcd83c..0366ed0 100755 --- a/plugins/facebook/popcorn.facebook.js +++ b/plugins/facebook/popcorn.facebook.js @@ -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" ); @@ -188,9 +191,10 @@ 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 diff --git a/plugins/flickr/popcorn.flickr.js b/plugins/flickr/popcorn.flickr.js index 2c14bc3..dfd6031 100755 --- a/plugins/flickr/popcorn.flickr.js +++ b/plugins/flickr/popcorn.flickr.js @@ -45,6 +45,7 @@ Popcorn.plugin( "flickr" , function( options ) { var containerDiv, + target = document.getElementById( options.target ), _userid, _uri, _link, @@ -65,11 +66,10 @@ 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() { diff --git a/plugins/flickr/popcorn.flickr.unit.js b/plugins/flickr/popcorn.flickr.unit.js index 4151b34..e9688fc 100755 --- a/plugins/flickr/popcorn.flickr.unit.js +++ b/plugins/flickr/popcorn.flickr.unit.js @@ -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(); }); diff --git a/plugins/footnote/popcorn.footnote.js b/plugins/footnote/popcorn.footnote.js index 2570da1..436f7dc 100755 --- a/plugins/footnote/popcorn.footnote.js +++ b/plugins/footnote/popcorn.footnote.js @@ -41,11 +41,17 @@ } }, _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 diff --git a/plugins/gml/popcorn.gml.js b/plugins/gml/popcorn.gml.js index f0b54b4..17cf12f 100755 --- a/plugins/gml/popcorn.gml.js +++ b/plugins/gml/popcorn.gml.js @@ -147,7 +147,8 @@ _setup : function( options ) { - var self = this; + var self = this, + target = document.getElementById( options.target ); options.endDrawing = options.endDrawing || options.end; @@ -157,7 +158,10 @@ 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 ) { diff --git a/plugins/googlefeed/popcorn.googlefeed.html b/plugins/googlefeed/popcorn.googlefeed.html index 242d7e1..72bc9a1 100755 --- a/plugins/googlefeed/popcorn.googlefeed.html +++ b/plugins/googlefeed/popcorn.googlefeed.html @@ -56,4 +56,4 @@

Horizontal Feed:

- \ No newline at end of file + diff --git a/plugins/googlefeed/popcorn.googlefeed.js b/plugins/googlefeed/popcorn.googlefeed.js index df44a77..1a6d1cd 100755 --- a/plugins/googlefeed/popcorn.googlefeed.js +++ b/plugins/googlefeed/popcorn.googlefeed.js @@ -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 ) { @@ -111,7 +112,10 @@ 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(); diff --git a/plugins/googlefeed/popcorn.googlefeed.unit.js b/plugins/googlefeed/popcorn.googlefeed.unit.js index 027625b..06aff4a 100755 --- a/plugins/googlefeed/popcorn.googlefeed.unit.js +++ b/plugins/googlefeed/popcorn.googlefeed.unit.js @@ -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(); }); diff --git a/plugins/googlemap/popcorn.googlemap.js b/plugins/googlemap/popcorn.googlemap.js index f2b2bec..5c044c9 100755 --- a/plugins/googlemap/popcorn.googlemap.js +++ b/plugins/googlemap/popcorn.googlemap.js @@ -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 diff --git a/plugins/googlemap/popcorn.googlemap.unit.js b/plugins/googlemap/popcorn.googlemap.unit.js index 3355924..d326905 100755 --- a/plugins/googlemap/popcorn.googlemap.unit.js +++ b/plugins/googlemap/popcorn.googlemap.unit.js @@ -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(); }); diff --git a/plugins/googlenews/popcorn.googlenews.js b/plugins/googlenews/popcorn.googlenews.js index fb808cf..166be7d 100755 --- a/plugins/googlenews/popcorn.googlenews.js +++ b/plugins/googlenews/popcorn.googlenews.js @@ -59,26 +59,30 @@ }, _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" } diff --git a/plugins/googlenews/popcorn.googlenews.unit.js b/plugins/googlenews/popcorn.googlenews.unit.js index a41c634..353b46a 100755 --- a/plugins/googlenews/popcorn.googlenews.unit.js +++ b/plugins/googlenews/popcorn.googlenews.unit.js @@ -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(); }); diff --git a/plugins/image/popcorn.image.js b/plugins/image/popcorn.image.js index dc5f90d..6da4bec 100755 --- a/plugins/image/popcorn.image.js +++ b/plugins/image/popcorn.image.js @@ -66,16 +66,19 @@ } }, _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() { diff --git a/plugins/lastfm/popcorn.lastfm.html b/plugins/lastfm/popcorn.lastfm.html index 2d7e5ee..35ae0a0 100755 --- a/plugins/lastfm/popcorn.lastfm.html +++ b/plugins/lastfm/popcorn.lastfm.html @@ -20,7 +20,6 @@ .lastfm({ start: 5, // seconds end: 15, // seconds - artist: 'yacht', target: 'lastfmdiv', apikey: '30ac38340e8be75f9268727cb4526b3d' } ) diff --git a/plugins/lastfm/popcorn.lastfm.js b/plugins/lastfm/popcorn.lastfm.js index 9de8702..2876d03 100755 --- a/plugins/lastfm/popcorn.lastfm.js +++ b/plugins/lastfm/popcorn.lastfm.js @@ -76,10 +76,14 @@ 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]) { diff --git a/plugins/lastfm/popcorn.lastfm.unit.js b/plugins/lastfm/popcorn.lastfm.unit.js index f02c13a..a5c0c0a 100755 --- a/plugins/lastfm/popcorn.lastfm.unit.js +++ b/plugins/lastfm/popcorn.lastfm.unit.js @@ -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(); }); diff --git a/plugins/linkedin/popcorn.linkedin.js b/plugins/linkedin/popcorn.linkedin.js index 991fe64..75363af 100755 --- a/plugins/linkedin/popcorn.linkedin.js +++ b/plugins/linkedin/popcorn.linkedin.js @@ -70,14 +70,16 @@ 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 apikey"; - 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 ) { @@ -144,12 +146,13 @@ } 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 @@ -158,7 +161,7 @@ * options variable */ start: function( event, options ) { - options._container.parentNode.style.display = "block"; + options._container.style.display = "block"; }, /** * @member linkedin @@ -167,7 +170,7 @@ * 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 ); diff --git a/plugins/linkedin/popcorn.linkedin.unit.js b/plugins/linkedin/popcorn.linkedin.unit.js index a4d8413..2625bff 100755 --- a/plugins/linkedin/popcorn.linkedin.unit.js +++ b/plugins/linkedin/popcorn.linkedin.unit.js @@ -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 { diff --git a/plugins/lowerthird/popcorn.lowerthird.html b/plugins/lowerthird/popcorn.lowerthird.html index 5ca491a..7fb234f 100755 --- a/plugins/lowerthird/popcorn.lowerthird.html +++ b/plugins/lowerthird/popcorn.lowerthird.html @@ -8,6 +8,7 @@