mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR Performance improvement and removal of duplicate code in jQuery.ondemand
This commit is contained in:
parent
b3164eb2a9
commit
22de5c6597
@ -24,41 +24,27 @@
|
|||||||
// 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,
|
||||||
|
|
||||||
// Added by SRM: Initialise the loaded_list with the scripts included on first load
|
|
||||||
initialiseItemLoadedList : function() {
|
|
||||||
if(this.loaded_list == null) {
|
|
||||||
$this = this;
|
|
||||||
$this.loaded_list = {};
|
|
||||||
$('script').each(function() {
|
|
||||||
if($(this).attr('src')) $this.loaded_list[ $(this).attr('src') ] = 1;
|
|
||||||
});
|
|
||||||
$('link[rel="stylesheet"]').each(function() {
|
|
||||||
if($(this).attr('href')) $this.loaded_list[ $(this).attr('href') ] = 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
|
||||||
*/
|
*/
|
||||||
isItemLoaded : function(scriptUrl) {
|
isItemLoaded : function(scriptUrl) {
|
||||||
var self = this;
|
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() {
|
||||||
if($(this).attr('src')) self._ondemand_loaded_list[ $(this).attr('src') ] = 1;
|
src = $(this).attr('src');
|
||||||
|
if(src) self._ondemand_loaded_list[src] = 1;
|
||||||
});
|
});
|
||||||
$('link[rel="stylesheet"]').each(function() {
|
$('link[rel="stylesheet"]').each(function() {
|
||||||
if($(this).attr('href')) self._ondemand_loaded_list[ $(this).attr('href') ] = 1;
|
src = $(this).attr('href');
|
||||||
|
if(src) self._ondemand_loaded_list[src] = 1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return (this._ondemand_loaded_list[decodePath(scriptUrl)] !== undefined);
|
||||||
return (this._ondemand_loaded_list[decodePath(scriptUrl)] != undefined);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
requireCss : function(styleUrl, media){
|
requireCss : function(styleUrl, media){
|
||||||
if(media == null) media = 'all';
|
if(media === null) media = 'all';
|
||||||
|
|
||||||
// Don't double up on loading scripts
|
// Don't double up on loading scripts
|
||||||
if($.isItemLoaded(styleUrl)) return;
|
if($.isItemLoaded(styleUrl)) return;
|
||||||
|
Loading…
Reference in New Issue
Block a user