From: ScottDowne Date: Mon, 11 Apr 2011 17:32:11 +0000 (-0400) Subject: [#439] loading scripts only when a track exists that needs the script X-Git-Tag: v0.5~30^2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=b069e23deb0a79ece264c1dc57ccb38962da5d75;p=popcorn-js.git [#439] loading scripts only when a track exists that needs the script --- diff --git a/plugins/googlefeed/popcorn.googlefeed.js b/plugins/googlefeed/popcorn.googlefeed.js index bacd4f2..acc919f 100644 --- a/plugins/googlefeed/popcorn.googlefeed.js +++ b/plugins/googlefeed/popcorn.googlefeed.js @@ -2,8 +2,9 @@ (function (Popcorn) { var i = 1, - scriptLoaded = false, - callBack = function( data ) { + scriptLoading = false, + scriptLoaded = false, + callBack = function( data ) { if ( typeof google !== 'undefined' && google.load ) { @@ -17,17 +18,6 @@ } }; - Popcorn.getScript( "http://www.google.com/jsapi", callBack ); - Popcorn.getScript( "http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js" ); - - //Doing this because I cannot find something similar to getScript() for css files - var head = document.getElementsByTagName("head")[0]; - var css = document.createElement('link'); - css.type = "text/css"; - css.rel = "stylesheet"; - css.href = "http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.css"; - head.insertBefore( css, head.firstChild ); - /** * googlefeed popcorn plug-in * Adds a feed from the specified blog url at the target div @@ -81,6 +71,22 @@ } }; + if ( !scriptLoading ) { + + scriptLoading = true; + + Popcorn.getScript( "http://www.google.com/jsapi", callBack ); + Popcorn.getScript( "http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js" ); + + //Doing this because I cannot find something similar to getScript() for css files + var head = document.getElementsByTagName("head")[0]; + var css = document.createElement('link'); + css.type = "text/css"; + css.rel = "stylesheet"; + css.href = "http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.css"; + head.insertBefore( css, head.firstChild ); + } + initialize(); return { diff --git a/plugins/googlemap/popcorn.googlemap.js b/plugins/googlemap/popcorn.googlemap.js index 92dbc38..46d4d98 100644 --- a/plugins/googlemap/popcorn.googlemap.js +++ b/plugins/googlemap/popcorn.googlemap.js @@ -1,6 +1,7 @@ // PLUGIN: Google Maps var googleCallback; (function (Popcorn) { + var newdiv, i = 1, _mapFired = false, @@ -32,11 +33,6 @@ var googleCallback; }, 1); } }; - // if this is the firest time running the plugins - // call the function that gets the sctipt - if ( !_mapFired ) { - loadMaps(); - } /** * googlemap popcorn plug-in @@ -71,6 +67,12 @@ var googleCallback; var newdiv, map, location; + + // if this is the firest time running the plugins + // call the function that gets the sctipt + if ( !_mapFired ) { + loadMaps(); + } // create a new div this way anything in the target div is left intact // this is later passed on to the maps api diff --git a/plugins/googlenews/popcorn.googlenews.js b/plugins/googlenews/popcorn.googlenews.js index 9e104bf..d381795 100644 --- a/plugins/googlenews/popcorn.googlenews.js +++ b/plugins/googlenews/popcorn.googlenews.js @@ -3,6 +3,7 @@ (function (Popcorn) { var scriptLoaded = false, + scriptLoading = false, callBack = function( data ) { if ( typeof google !== 'undefined' && google.load ) { @@ -17,8 +18,6 @@ } }; - Popcorn.getScript( "http://www.google.com/jsapi", callBack ); - /** * Google News popcorn plug-in * Displays Google News information on a topic in a targeted div. @@ -59,6 +58,12 @@ } }, _setup : function( options ) { + + if ( !scriptLoading ) { + + scriptLoading = true; + Popcorn.getScript( "http://www.google.com/jsapi", callBack ); + } options.container = document.createElement( 'div' ); if ( document.getElementById( options.target ) ) { diff --git a/plugins/mustache/popcorn.mustache.js b/plugins/mustache/popcorn.mustache.js index f393445..3ae5cf5 100644 --- a/plugins/mustache/popcorn.mustache.js +++ b/plugins/mustache/popcorn.mustache.js @@ -2,8 +2,6 @@ (function (Popcorn) { - Popcorn.getScript('https://github.com/janl/mustache.js/raw/master/mustache.js'); - /** * Mustache Popcorn Plug-in * @@ -87,6 +85,9 @@ */ Popcorn.plugin( 'mustache' , function( options ) { + + Popcorn.getScript('https://github.com/janl/mustache.js/raw/master/mustache.js'); + var getData, data, getTemplate, template; var shouldReload = !!options.dynamic, diff --git a/plugins/openmap/popcorn.openmap.js b/plugins/openmap/popcorn.openmap.js index afbc3a1..988354e 100644 --- a/plugins/openmap/popcorn.openmap.js +++ b/plugins/openmap/popcorn.openmap.js @@ -41,15 +41,6 @@ var openmapCallback; _mapFired = false, _mapLoaded = false; - // insert openlayers api script once - if ( !_mapFired ) { - _mapFired = true; - Popcorn.getScript('http://openlayers.org/api/OpenLayers.js', - function() { - _mapLoaded = true; - } ); - } - Popcorn.plugin( "openmap" , function( options ){ var newdiv, map, @@ -60,6 +51,15 @@ var openmapCallback; selectControl, popup; + // insert openlayers api script once + if ( !_mapFired ) { + _mapFired = true; + Popcorn.getScript('http://openlayers.org/api/OpenLayers.js', + function() { + _mapLoaded = true; + } ); + } + // create a new div within the target div // this is later passed on to the maps api newdiv = document.createElement( 'div' ); diff --git a/plugins/twitter/popcorn.twitter.js b/plugins/twitter/popcorn.twitter.js index cb0e2c8..5106b3b 100644 --- a/plugins/twitter/popcorn.twitter.js +++ b/plugins/twitter/popcorn.twitter.js @@ -1,6 +1,7 @@ // PLUGIN: TWITTER (function (Popcorn) { + var scriptLoading = false; /** * Twitter popcorn plug-in @@ -30,10 +31,6 @@ * */ - if ( !window.TWTR ) { - Popcorn.getScript("http://widgets.twimg.com/j/2/widget.js"); - } - Popcorn.plugin( "twitter" , { manifest: { @@ -55,6 +52,11 @@ _setup: function( options ) { + if ( !window.TWTR && !scriptLoading ) { + scriptLoading = true; + Popcorn.getScript("http://widgets.twimg.com/j/2/widget.js"); + } + // 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