]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#556] Fixed requested changes, made sure scripts were not being requested twice
authorDavid Seifried <david.c.seifried@gmail.com>
Mon, 6 Jun 2011 16:51:25 +0000 (12:51 -0400)
committerDavid Seifried <david.c.seifried@gmail.com>
Mon, 6 Jun 2011 16:51:25 +0000 (12:51 -0400)
plugins/googlefeed/popcorn.googlefeed.js

index 409f1cf86d2b74df1c18f4adb28d7d8195f76474..4eb4b9f0776aa79cc82eb60288fbf9bf1c13498e 100644 (file)
@@ -2,29 +2,54 @@
 (function (Popcorn) {
 
   var i = 1,
-      scriptLoading = false,
-      scriptLoaded  = false,
-      callBack      = function( data ) {
+      scriptLoaded  = false;
 
-        if ( typeof google !== 'undefined' && google.load ) {
+  var dynamicFeedLoad = function() {
+    var dontLoad = false;
 
-          google.load( "feeds", "1", {
-            callback: function () {
-            
-              Popcorn.getScript( "http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js", function() {
+    if ( typeof GFdynamicFeedControl === "undefined" ) {
 
-                scriptLoaded = true;
-              }); 
-            }
-          });
-        } else {
+      Popcorn.getScript( "http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js", function() {
+        scriptLoaded = true;
+      }); 
 
-          setTimeout( function() {
+    } else {
+      scriptLoaded = true;
+    }
+
+    //  Checking if the css file is already included
+    for ( var k = 0; k < document.getElementsByTagName( "link" ).length; k++ ){
+      if ( document.getElementsByTagName( "link" )[ k ].href == "http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.css" ) {
+        dontLoad = true;
+      }
+    }
+
+    if ( !dontLoad ) {
+      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 );
+      }
+  }
+
+  if ( typeof google === "undefined" ) {
+
+    Popcorn.getScript( "http://www.google.com/jsapi", function() {
 
-            callBack( data );
-          }, 1);
+      google.load( "feeds", "1", {
+
+        callback: function () {
+
+          dynamicFeedLoad();              
         }
-      };
+      });
+    });
+
+  } else {
+    dynamicFeedLoad();
+  }
 
   /**
    * googlefeed popcorn plug-in
     newdiv.style.height = "100%";
     i++;
 
-    document.getElementById( options.target ) && document.getElementById( options.target ).appendChild( newdiv );
+    document.getElementById( options.target ).appendChild( newdiv );
 
     var initialize = function() {
       //ensure that the script has been loaded
       if ( !scriptLoaded ) {
-        setTimeout(function () {
-          initialize();
-        }, 5);
+        setTimeout( function () {
+          initialize(); 
+        }, 5 );
       } else {
         // Create the feed control using the user entered url and title
         options.feed = new GFdynamicFeedControl( options.url, newdiv, {
         });
       }
     };
-    
-    if ( !scriptLoading ) {
-
-      scriptLoading = true;
-    
-      Popcorn.getScript( "http://www.google.com/jsapi", callBack );
-
-      //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();
     
        * of the video reaches the end time provided by the
        * options variable
        */
-      end: function(event, options){
+      end: function( event, options ){
         newdiv.setAttribute( "style", "display:none" );
       },
       _teardown: function( options ) {
   },
   {
     about: {
-      name: "Popcorn Google Feed Plugin",
+      name:    "Popcorn Google Feed Plugin",
       version: "0.1",
-      author: "David Seifried",
+      author:  "David Seifried",
       website: "dseifried.wordpress.com"
     },
     options: {
       target         : "feed-container",
       url            : { elem:"input", type:"text", label:"url" },
       title          : { elem:"input", type:"text", label:"title" },
-      orientation    : {elem:"select", options:["Vertical","Horizontal"], label:"orientation"}
+      orientation    : {elem:"select", options:["Vertical","Horizontal"], label:"orientation" }
     }
   });