From: ScottDowne Date: Mon, 21 Mar 2011 15:59:40 +0000 (-0400) Subject: [#408] google scripts need to wait for google.load for googlefeed plugin X-Git-Tag: v0.4.1~2^2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=0d2dfdaf8ed8b74112212aa7c118ab71108d3a5b;p=popcorn-js.git [#408] google scripts need to wait for google.load for googlefeed plugin --- diff --git a/plugins/googlefeed/popcorn.googlefeed.js b/plugins/googlefeed/popcorn.googlefeed.js index 29d7b59..44168eb 100644 --- a/plugins/googlefeed/popcorn.googlefeed.js +++ b/plugins/googlefeed/popcorn.googlefeed.js @@ -1,6 +1,33 @@ // PLUGIN: Google Feed (function (Popcorn) { + var i = 1, + scriptLoaded = false, + callBack = function( data ) { + + if ( typeof google !== 'undefined' && google.load ) { + + google.load( "feeds", "1", { callback: function () { _feedLoaded = true; } } ); + } else { + + setTimeout( function() { + + callBack( data ); + }, 1); + } + } + + 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 @@ -25,27 +52,6 @@ * */ - var _feedFired = false, - _feedLoaded = false, - i = 1; - - // insert google api and dynamic feed control script once, as well as the dynamic feed css file - if ( !_feedFired ) { - _feedFired = true; - Popcorn.getScript( "https://www.google.com/jsapi", function () { - google.load( "feeds", "1", { callback: function () { _feedLoaded = true; } } ); - }); - 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 ); - } - - 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