]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#439] loading scripts only when a track exists that needs the script
authorScottDowne <sdowne@learn.senecac.on.ca>
Mon, 11 Apr 2011 17:32:11 +0000 (13:32 -0400)
committerScottDowne <sdowne@learn.senecac.on.ca>
Mon, 11 Apr 2011 17:32:11 +0000 (13:32 -0400)
plugins/googlefeed/popcorn.googlefeed.js
plugins/googlemap/popcorn.googlemap.js
plugins/googlenews/popcorn.googlenews.js
plugins/mustache/popcorn.mustache.js
plugins/openmap/popcorn.openmap.js
plugins/twitter/popcorn.twitter.js

index bacd4f270b72b32350b27abdd308110c16a1d9dc..acc919f93a4930f14cd8ad05f9fc955695583419 100644 (file)
@@ -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 ) {
 
         }
       };
 
-  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
       }
     };
     
+    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 {
index 92dbc385e9bf457dde1c6053a5d257cb669cb395..46d4d98929308d2390e9741a1a541cbee8a208aa 100644 (file)
@@ -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
index 9e104bf6fe19093ccc1ba5c855a9b87cf75c56f2..d381795a5bddfb16fbebccc35d117aa6f4e17787 100644 (file)
@@ -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.
         }
       },
       _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 ) ) {
index f3934458685ad651b4bc6b9dafb8ae37e1632376..3ae5cf52807752c15827542c27f0e2241fec6c61 100644 (file)
@@ -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,
index afbc3a1f9a7b86252a5fb6bbf29fbef38bcf0730..988354ea4b9fc9acba017b823b634d54c67a1263 100644 (file)
@@ -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' );
index cb0e2c8a78e0977af2b704839d97443586c0d190..5106b3b0ccf110a99dd2508db2b3cd453955e112 100644 (file)
@@ -1,6 +1,7 @@
 // PLUGIN: TWITTER
 
 (function (Popcorn) {
+  var scriptLoading = false;
 
   /**
    * Twitter popcorn plug-in 
    *
    */
 
-  if ( !window.TWTR ) {
-    Popcorn.getScript("http://widgets.twimg.com/j/2/widget.js");
-  }
-
   Popcorn.plugin( "twitter" , {
 
       manifest: {
 
       _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