Permalink
Browse files

MINOR Performance improvement and removal of duplicate code in jQuery…

….ondemand
  • Loading branch information...
1 parent b3164eb commit 22de5c65979355752f2dbd9ca5b7f70265474742 @chillu chillu committed Jun 6, 2012
Showing with 8 additions and 22 deletions.
  1. +8 −22 javascript/jquery-ondemand/jquery.ondemand.js
@@ -23,42 +23,28 @@
// loaded files list - to protect against loading existed file again (by PGA)
_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
*/
isItemLoaded : function(scriptUrl) {
- var self = this;
-
- if(this._ondemand_loaded_list == null) {
+ var self = this, src;
+ if(this._ondemand_loaded_list === null) {
this._ondemand_loaded_list = {};
$('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() {
- 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){
- if(media == null) media = 'all';
+ if(media === null) media = 'all';
// Don't double up on loading scripts
if($.isItemLoaded(styleUrl)) return;

0 comments on commit 22de5c6

Please sign in to comment.