[#439] loading scripts only when a track exists that needs the script

This commit is contained in:
ScottDowne 2011-04-11 13:32:11 -04:00
Родитель a79f2af651
Коммит b069e23deb
6 изменённых файлов: 51 добавлений и 35 удалений

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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

Просмотреть файл

@ -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 ) ) {

Просмотреть файл

@ -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,

Просмотреть файл

@ -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' );

Просмотреть файл

@ -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