From ad7a07064a81d6085eb4f981ea2ca9dc26b8e6d0 Mon Sep 17 00:00:00 2001 From: ScottDowne Date: Mon, 16 May 2011 19:19:37 -0400 Subject: [PATCH] [#t484] teardown checks for target, linting, explicit googlefeed delete --- plugins/attribution/popcorn.attribution.js | 7 +++---- plugins/flickr/popcorn.flickr.js | 2 +- plugins/footnote/popcorn.footnote.js | 7 +++---- plugins/googlefeed/popcorn.googlefeed.js | 10 +++++----- plugins/googlefeed/popcorn.googlefeed.unit.js | 2 +- plugins/googlemap/popcorn.googlemap.js | 2 +- plugins/googlenews/popcorn.googlenews.js | 2 +- plugins/image/popcorn.image.js | 12 +++++++----- plugins/lastfm/popcorn.lastfm.js | 8 +++----- plugins/mustache/popcorn.mustache.js | 2 +- plugins/openmap/popcorn.openmap.js | 8 ++++---- plugins/tagthisperson/popcorn.tagthisperson.js | 9 +++------ plugins/twitter/popcorn.twitter.js | 9 +++++---- plugins/webpage/popcorn.webpage.js | 7 +++---- 14 files changed, 41 insertions(+), 46 deletions(-) diff --git a/plugins/attribution/popcorn.attribution.js b/plugins/attribution/popcorn.attribution.js index 7331228..fe0c478 100644 --- a/plugins/attribution/popcorn.attribution.js +++ b/plugins/attribution/popcorn.attribution.js @@ -104,9 +104,8 @@ attrib += ", license "; } options._container.innerHTML = attrib; - if ( document.getElementById( options.target ) ) { - document.getElementById( options.target ).appendChild( options._container ); - } + + document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( options._container ); }, /** * @member attribution @@ -127,7 +126,7 @@ options._container.style.display = "none"; }, _teardown: function( options ) { - document.getElementById( options.target ).removeChild( options._container ); + document.getElementById( options.target ) && document.getElementById( options.target ).removeChild( options._container ); } }; })()); diff --git a/plugins/flickr/popcorn.flickr.js b/plugins/flickr/popcorn.flickr.js index 37977bd..1009fea 100644 --- a/plugins/flickr/popcorn.flickr.js +++ b/plugins/flickr/popcorn.flickr.js @@ -141,7 +141,7 @@ containerDiv.style.display = "none"; }, _teardown: function( options ) { - document.getElementById( options.target ).removeChild( containerDiv ); + document.getElementById( options.target ) && document.getElementById( options.target ).removeChild( containerDiv ); } }; }, diff --git a/plugins/footnote/popcorn.footnote.js b/plugins/footnote/popcorn.footnote.js index 981d94a..2570da1 100644 --- a/plugins/footnote/popcorn.footnote.js +++ b/plugins/footnote/popcorn.footnote.js @@ -44,9 +44,8 @@ options._container = document.createElement( 'div' ); options._container.style.display = "none"; options._container.innerHTML = options.text; - if ( document.getElementById( options.target ) ) { - document.getElementById( options.target ).appendChild( options._container ); - } + + document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( options._container ); }, /** * @member footnote @@ -67,7 +66,7 @@ options._container.style.display = "none"; }, _teardown: function( options ) { - document.getElementById( options.target ).removeChild( options._container ); + document.getElementById( options.target ) && document.getElementById( options.target ).removeChild( options._container ); } }); diff --git a/plugins/googlefeed/popcorn.googlefeed.js b/plugins/googlefeed/popcorn.googlefeed.js index 4d24794..1e9c0f3 100644 --- a/plugins/googlefeed/popcorn.googlefeed.js +++ b/plugins/googlefeed/popcorn.googlefeed.js @@ -51,9 +51,8 @@ newdiv.style.width = "100%"; newdiv.style.height = "100%"; i++; - if ( document.getElementById( options.target ) ) { - document.getElementById( options.target ).appendChild( newdiv ); - } + + document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( newdiv ); var initialize = function() { //ensure that the script has been loaded @@ -63,7 +62,7 @@ }, 5); } else { // Create the feed control using the user entered url and title - var tmp = new GFdynamicFeedControl( options.url, newdiv, { + options.feed = new GFdynamicFeedControl( options.url, newdiv, { vertical: options.orientation.toLowerCase() == "vertical" ? true : false, horizontal: options.orientation.toLowerCase() == "horizontal" ? true : false, title: options.title = options.title || "Blog" @@ -114,7 +113,8 @@ newdiv.setAttribute( "style", "display:none" ); }, _teardown: function( options ) { - document.getElementById( options.target ).removeChild( newdiv ); + document.getElementById( options.target ) && document.getElementById( options.target ).removeChild( newdiv ); + delete options.feed; } }; }, diff --git a/plugins/googlefeed/popcorn.googlefeed.unit.js b/plugins/googlefeed/popcorn.googlefeed.unit.js index b2778c2..5fbcfcc 100644 --- a/plugins/googlefeed/popcorn.googlefeed.unit.js +++ b/plugins/googlefeed/popcorn.googlefeed.unit.js @@ -64,7 +64,7 @@ test("Popcorn Google Feed Plugin", function () { plus(); popped.pause().removeTrackEvent( setupId ); - ok( !document.getElementById('feed1').children[0], "removed footnote was properly destroyed" ); + ok( !document.getElementById('feed1').children[0], "removed feed was properly destroyed" ); plus(); }); diff --git a/plugins/googlemap/popcorn.googlemap.js b/plugins/googlemap/popcorn.googlemap.js index 0819870..954eea1 100644 --- a/plugins/googlemap/popcorn.googlemap.js +++ b/plugins/googlemap/popcorn.googlemap.js @@ -189,7 +189,7 @@ var googleCallback; }, _teardown: function( options ) { // the map must be manually removed - document.getElementById( options.target ).removeChild( newdiv ); + document.getElementById( options.target ) && document.getElementById( options.target ).removeChild( newdiv ); newdiv = map = location = null; } }; diff --git a/plugins/googlenews/popcorn.googlenews.js b/plugins/googlenews/popcorn.googlenews.js index e12e0bf..e9b8876 100644 --- a/plugins/googlenews/popcorn.googlenews.js +++ b/plugins/googlenews/popcorn.googlenews.js @@ -111,7 +111,7 @@ _teardown: function( options ) { // google news does not like this, throws an error "a is null" // doesn't hurt popcorn, and only happens once - document.getElementById( options.target ).removeChild( options.container ); + document.getElementById( options.target ) && document.getElementById( options.target ).removeChild( options.container ); options.newsShow = null; } }); diff --git a/plugins/image/popcorn.image.js b/plugins/image/popcorn.image.js index 2b77387..3a8b292 100644 --- a/plugins/image/popcorn.image.js +++ b/plugins/image/popcorn.image.js @@ -55,15 +55,17 @@ var img = document.createElement( 'img' ); img.addEventListener( "load", function() { - img.style.borderStyle = "none"; // borders look really bad, if someone wants it they can put it on their div target + + // borders look really bad, if someone wants it they can put it on their div target + img.style.borderStyle = "none"; if ( options.href ) { options.link.href = options.href; } options.link.target = "_blank"; - if ( document.getElementById( options.target ) ) { - document.getElementById( options.target ).appendChild( options.link ); // add the widget's div to the target div - } + + // add the widget's div to the target div + document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( options.link ); var fontHeight = ( img.height / 12 ) + "px"; @@ -109,7 +111,7 @@ options.link.style.display = "none"; }, _teardown: function( options ) { - document.getElementById( options.target ).removeChild( options.link ); + document.getElementById( options.target ) && document.getElementById( options.target ).removeChild( options.link ); } }); diff --git a/plugins/lastfm/popcorn.lastfm.js b/plugins/lastfm/popcorn.lastfm.js index b17b603..9de8702 100644 --- a/plugins/lastfm/popcorn.lastfm.js +++ b/plugins/lastfm/popcorn.lastfm.js @@ -78,10 +78,8 @@ options._container.innerHTML = ""; options.artist = options.artist.toLowerCase(); - - if ( document.getElementById( options.target ) ) { - document.getElementById( options.target ).appendChild( options._container ); - } + + document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( options._container ); if(!_artists[options.artist]) { @@ -117,7 +115,7 @@ _teardown: function( options ) { // cleaning possible reference to _artist array; --_artists[ options.artist ].count || delete _artists[ options.artist ]; - document.getElementById( options.target ).removeChild( options._container ); + document.getElementById( options.target ) && document.getElementById( options.target ).removeChild( options._container ); } }; })()); diff --git a/plugins/mustache/popcorn.mustache.js b/plugins/mustache/popcorn.mustache.js index 86f318f..97a8c76 100644 --- a/plugins/mustache/popcorn.mustache.js +++ b/plugins/mustache/popcorn.mustache.js @@ -141,7 +141,7 @@ document.getElementById( options.target ).innerHTML = ''; }, _teardown: function( options ) { - getData, data, getTemplate, template = null; + getData = data = getTemplate = template = null; } }; }, diff --git a/plugins/openmap/popcorn.openmap.js b/plugins/openmap/popcorn.openmap.js index ad7262e..38a4f36 100644 --- a/plugins/openmap/popcorn.openmap.js +++ b/plugins/openmap/popcorn.openmap.js @@ -67,9 +67,9 @@ var openmapCallback; newdiv.style.width = "100%"; newdiv.style.height = "100%"; i++; - if ( document.getElementById( options.target ) ) { - document.getElementById( options.target ).appendChild( newdiv ); - } + + document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( newdiv ); + // callback function fires when the script is run var isGeoReady = function() { if ( !_mapLoaded ) { @@ -253,7 +253,7 @@ var openmapCallback; }, _teardown: function( options ) { - document.getElementById( options.target ).removeChild( newdiv ); + document.getElementById( options.target ) && document.getElementById( options.target ).removeChild( newdiv ); newdiv = map = centerlonlat = projection = displayProjection = pointLayer = selectControl = popup = null; } }; diff --git a/plugins/tagthisperson/popcorn.tagthisperson.js b/plugins/tagthisperson/popcorn.tagthisperson.js index 029e500..c67a24c 100644 --- a/plugins/tagthisperson/popcorn.tagthisperson.js +++ b/plugins/tagthisperson/popcorn.tagthisperson.js @@ -90,9 +90,7 @@ options._p.contains[ options.person ] = ( options.image ) ? " " : "" ; options._p.contains[ options.person ] += ( options.href ) ? " " + options.person + "" : options.person ; - if ( document.getElementById( options.target ) ) { - document.getElementById( options.target ).innerHTML = options._p.toString(); - } + document.getElementById( options.target ).innerHTML = options._p.toString(); }, /** * @member tagthisperson @@ -102,9 +100,8 @@ */ end: function( event, options ){ delete options._p.contains[ options.person ]; - if ( document.getElementById( options.target ) ) { - document.getElementById( options.target ).innerHTML = options._p.toString(); - } + + document.getElementById( options.target ).innerHTML = options._p.toString(); } }; })()); diff --git a/plugins/twitter/popcorn.twitter.js b/plugins/twitter/popcorn.twitter.js index 8cdfe5e..b8aa8d9 100644 --- a/plugins/twitter/popcorn.twitter.js +++ b/plugins/twitter/popcorn.twitter.js @@ -61,9 +61,10 @@ 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 ( document.getElementById( options.target ) ) { - document.getElementById( options.target ).appendChild( options.container ); // add the widget's div to the target div - } + + // add the widget's div to the target div + document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( options.container ); + // setup info for the widget var src = options.src || "", width = options.width || 250, @@ -149,7 +150,7 @@ }, _teardown: function( options ) { - document.getElementById( options.target ).removeChild( options.container ); + document.getElementById( options.target ) && document.getElementById( options.target ).removeChild( options.container ); } }); diff --git a/plugins/webpage/popcorn.webpage.js b/plugins/webpage/popcorn.webpage.js index ecfabda..632e1a1 100644 --- a/plugins/webpage/popcorn.webpage.js +++ b/plugins/webpage/popcorn.webpage.js @@ -50,10 +50,9 @@ options._iframe.id = options.id; options._iframe.src = options.src; options._iframe.style.display = 'none'; + // add the hidden iframe to the DOM - if ( document.getElementById( options.target ) ) { - document.getElementById( options.target ).appendChild(options._iframe); - } + document.getElementById( options.target ) && document.getElementById( options.target ).appendChild(options._iframe); }, /** @@ -79,7 +78,7 @@ }, _teardown: function( options ) { - document.getElementById( options.target ).removeChild( options._iframe ); + document.getElementById( options.target ) && document.getElementById( options.target ).removeChild( options._iframe ); } }); })( Popcorn ); -- 2.43.0