]> khamidou — GitHub mirrors - popcorn-js.git/commitdiff
[#556] Made a few performance changes, as well as some small styling changes
authorDavid Seifried <david.c.seifried@gmail.com>
Tue, 21 Jun 2011 19:10:17 +0000 (15:10 -0400)
committerDavid Seifried <david.c.seifried@gmail.com>
Tue, 21 Jun 2011 19:10:17 +0000 (15:10 -0400)
plugins/googlefeed/popcorn.googlefeed.js

index 619a9dbb56ce124ea3990aa761a6239492d9a003..7b4417b82d120ba4273341230544e7a673405109 100755 (executable)
@@ -1,11 +1,16 @@
 // PLUGIN: Google Feed
-(function (Popcorn) {
+(function ( Popcorn ) {
 
   var i = 1,
-      scriptLoaded  = false;
+      scriptLoaded  = false,
 
-  var dynamicFeedLoad = function() {
-    var dontLoad = false;
+  dynamicFeedLoad = function() {
+    var dontLoad = false,
+        k = 0,
+        links = document.getElementsByTagName( "link" ),
+        len = links.length,
+        head = document.getElementsByTagName( "head" )[ 0 ],
+        css = document.createElement( "link" );
 
     if ( typeof GFdynamicFeedControl === "undefined" ) {
 
     }
 
     //  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" ) {
+    for ( ; k < len; k++ ){
+      if ( links[ 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";
   Popcorn.plugin( "googlefeed" , function( options ) {
     // 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" );
-    newdiv.style.display = "none";
-    newdiv.id = "_feed"+i;
-    newdiv.style.width = "100%";
-    newdiv.style.height = "100%";
-    i++;
-
-    document.getElementById( options.target ).appendChild( newdiv );
-
-    var initialize = function() {
+    var newdiv = document.createElement( "div" ),
+    initialize = function() {
       //ensure that the script has been loaded
       if ( !scriptLoaded ) {
         setTimeout( function () {
       } else {
         // Create the feed control using the user entered url and title
         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"
+          vertical: options.orientation.toLowerCase() === "vertical" ? true : false,
+          horizontal: options.orientation.toLowerCase() === "horizontal" ? true : false,
+          title: options.title = options.title || "Blog"
         });
       }
     };
 
+    newdiv.style.display = "none";
+    newdiv.id = "_feed" + i;
+    newdiv.style.width = "100%";
+    newdiv.style.height = "100%";
+    i++;
+
+    document.getElementById( options.target ).appendChild( newdiv );
+
     initialize();
     
     return {
       start: function( event, options ){
         newdiv.setAttribute( "style", "display:inline" );
         // Default to vertical orientation if empty or incorrect input
-        if( !options.orientation || ( options.orientation.toLowerCase() != "vertical" &&
-          options.orientation.toLowerCase() != "horizontal" ) ) {
+        if( !options.orientation || ( options.orientation.toLowerCase() !== "vertical" &&
+          options.orientation.toLowerCase() !== "horizontal" ) ) {
           options.orientation = "vertical";
         }
       },
       website: "dseifried.wordpress.com"
     },
     options: {
-      start          : { elem:"input", type:"text", label:"In" },
-      end            : { elem:"input", type:"text", label:"Out" },
-      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" }
+      start: {
+        elem:"input", 
+        type:"text", 
+        label:"In" 
+      },
+      end: { 
+        elem:"input", 
+        type:"text", 
+        label:"Out" 
+      },
+      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" 
+      }
     }
   });