Revert "BUG Fix duplicate files being included in case of flush"

This commit is contained in:
Damian Mooyman 2015-11-02 17:11:22 +13:00
parent b857bdf209
commit 074718fcfa

View File

@ -15,74 +15,34 @@
*/ */
(function($){ (function($){
/**
* Decode URL from header string
*
* @param {String} str
* @returns {String}
*/
var decodePath = function(str) { var decodePath = function(str) {
return str.replace(/%2C/g,',').replace(/\&/g, '&').replace(/^\s+|\s+$/g, ''); return str.replace(/%2C/g,',').replace(/\&/g, '&').replace(/^\s+|\s+$/g, '');
}; };
/**
* Remove querystring from the url. Necessary to prevent a file being included twice in the same page if
* requested at different times (e.g. during flush)
*
* @param {String} str
* @returns {String}
*/
var removeQuerystring = function(str) {
return str.split("?")[0];
};
$.extend({ $.extend({
// loaded files list - to protect against loading existed file again (by PGA) // loaded files list - to protect against loading existed file again (by PGA)
_ondemand_loaded_list : null, _ondemand_loaded_list : null,
/**
* Add a new url to the loaded item
*
* @param {String} url
*/
registerLoadedItem : function(url) {
this._ondemand_loaded_list[removeQuerystring(url)] = 1;
},
/** /**
* Returns true if the given CSS or JS script has already been loaded * Returns true if the given CSS or JS script has already been loaded
*
* @param {String} scriptUrl Decoded CSS or JS file url
* @returns {Boolean}
*/ */
isItemLoaded : function(scriptUrl) { isItemLoaded : function(scriptUrl) {
var self = this, src, result; var self = this, src;
if(this._ondemand_loaded_list === null) { if(this._ondemand_loaded_list === null) {
this._ondemand_loaded_list = {}; this._ondemand_loaded_list = {};
$('script').each(function() { $('script').each(function() {
src = $(this).attr('src'); src = $(this).attr('src');
if(src) { if(src) self._ondemand_loaded_list[src] = 1;
self.registerLoadedItem(src);
}
}); });
$('link[rel="stylesheet"]').each(function() { $('link[rel="stylesheet"]').each(function() {
src = $(this).attr('href'); src = $(this).attr('href');
if(src) { if(src) self._ondemand_loaded_list[src] = 1;
self.registerLoadedItem(src);
}
}); });
} }
result = this._ondemand_loaded_list[removeQuerystring(scriptUrl)]; return (this._ondemand_loaded_list[decodePath(scriptUrl)] !== undefined);
return typeof result !== 'undefined';
}, },
/**
* Requires a CSS File
*
* @param {String} styleUrl Decoded CSS file url
* @param {String} media
*/
requireCss : function(styleUrl, media){ requireCss : function(styleUrl, media){
if(!media) media = 'all'; if(!media) media = 'all';
@ -93,7 +53,6 @@
var ss = document.createStyleSheet(styleUrl); var ss = document.createStyleSheet(styleUrl);
ss.media = media; ss.media = media;
} else { } else {
var styleTag = document.createElement('link'); var styleTag = document.createElement('link');
$(styleTag).attr({ $(styleTag).attr({
@ -104,7 +63,8 @@
}).appendTo($('head').get(0)); }).appendTo($('head').get(0));
} }
this.registerLoadedItem(styleUrl); this._ondemand_loaded_list[styleUrl] = 1;
}, },
/** /**
@ -150,7 +110,7 @@
dataType: 'script', dataType: 'script',
url: newJsInclude, url: newJsInclude,
success: function() { success: function() {
self.registerLoadedItem(newJsInclude); self._ondemand_loaded_list[newJsInclude] = 1;
getScriptQueue(); getScriptQueue();
}, },
cache: false, cache: false,