mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Indentation in customized jquery.ondemand.js
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@92517 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
1b138d6916
commit
5d6233a59e
@ -26,28 +26,27 @@
|
||||
|
||||
// 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;
|
||||
});
|
||||
}
|
||||
},
|
||||
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) {
|
||||
/**
|
||||
* Returns true if the given CSS or JS script has already been loaded
|
||||
*/
|
||||
isItemLoaded : function(scriptUrl) {
|
||||
this.initialiseItemLoadedList();
|
||||
return this.loaded_list[scriptUrl] != undefined;
|
||||
},
|
||||
return this.loaded_list[scriptUrl] != undefined;
|
||||
},
|
||||
|
||||
requireJs : function(scriptUrl, callback, opts, obj, scope)
|
||||
{
|
||||
requireJs : function(scriptUrl, callback, opts, obj, scope) {
|
||||
|
||||
if(opts != undefined || opts == null){
|
||||
$.extend($.requireConfig, opts);
|
||||
@ -125,10 +124,10 @@
|
||||
},
|
||||
|
||||
requireCss : function(styleUrl, media){
|
||||
if(media == null) media = 'all';
|
||||
if(media == null) media = 'all';
|
||||
|
||||
// Don't double up on loading scripts
|
||||
if(this.isItemLoaded(styleUrl)) return;
|
||||
// Don't double up on loading scripts
|
||||
if(this.isItemLoaded(styleUrl)) return;
|
||||
|
||||
if(document.createStyleSheet){
|
||||
var ss = document.createStyleSheet($.requireConfig.routeCss + styleUrl);
|
||||
@ -156,27 +155,27 @@
|
||||
*/
|
||||
_originalAjax = $.ajax;
|
||||
$.ajax = function(s) {
|
||||
var _complete = s.complete;
|
||||
var _success = s.success;
|
||||
var _dataType = s.dataType;
|
||||
var _complete = s.complete;
|
||||
var _success = s.success;
|
||||
var _dataType = s.dataType;
|
||||
|
||||
// This replaces the usual ajax success & complete handlers. They are called after any on demand JS is loaded.
|
||||
var _ondemandComplete = function(xml) {
|
||||
var status = jQuery.httpSuccess(xml) ? 'success' : 'error';
|
||||
if(status == 'success') {
|
||||
data = jQuery.httpData(xml, _dataType);
|
||||
if(_success) _success(data, status, xml);
|
||||
}
|
||||
if(_complete) _complete(xml, status);
|
||||
}
|
||||
// This replaces the usual ajax success & complete handlers. They are called after any on demand JS is loaded.
|
||||
var _ondemandComplete = function(xml) {
|
||||
var status = jQuery.httpSuccess(xml) ? 'success' : 'error';
|
||||
if(status == 'success') {
|
||||
data = jQuery.httpData(xml, _dataType);
|
||||
if(_success) _success(data, status, xml);
|
||||
}
|
||||
if(_complete) _complete(xml, status);
|
||||
}
|
||||
|
||||
// We remove the success handler and take care of calling it outselves within _ondemandComplete
|
||||
s.success = null;
|
||||
s.complete = function(xml, status) {
|
||||
processOnDemandHeaders(xml, _ondemandComplete);
|
||||
}
|
||||
// We remove the success handler and take care of calling it outselves within _ondemandComplete
|
||||
s.success = null;
|
||||
s.complete = function(xml, status) {
|
||||
processOnDemandHeaders(xml, _ondemandComplete);
|
||||
}
|
||||
|
||||
return _originalAjax(s);
|
||||
return _originalAjax(s);
|
||||
}
|
||||
|
||||
})(jQuery);
|
||||
@ -194,43 +193,43 @@ function prototypeOnDemandHandler(xml, callback) {
|
||||
* Process the X-Include-CSS and X-Include-JS headers provided by the Requirements class
|
||||
*/
|
||||
function processOnDemandHeaders(xml, _ondemandComplete) {
|
||||
var i;
|
||||
// CSS
|
||||
if(xml.getResponseHeader('X-Include-CSS')) {
|
||||
var cssIncludes = xml.getResponseHeader('X-Include-CSS').split(',');
|
||||
for(i=0;i<cssIncludes.length;i++) {
|
||||
// Syntax 1: "URL:##:media"
|
||||
if(cssIncludes[i].match(/^(.*):##:(.*)$/)) {
|
||||
jQuery.requireCss(RegExp.$1, RegExp.$2);
|
||||
var i;
|
||||
// CSS
|
||||
if(xml.getResponseHeader('X-Include-CSS')) {
|
||||
var cssIncludes = xml.getResponseHeader('X-Include-CSS').split(',');
|
||||
for(i=0;i<cssIncludes.length;i++) {
|
||||
// Syntax 1: "URL:##:media"
|
||||
if(cssIncludes[i].match(/^(.*):##:(.*)$/)) {
|
||||
jQuery.requireCss(RegExp.$1, RegExp.$2);
|
||||
|
||||
// Syntax 2: "URL"
|
||||
} else {
|
||||
jQuery.requireCss(cssIncludes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Syntax 2: "URL"
|
||||
} else {
|
||||
jQuery.requireCss(cssIncludes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// JavaScript
|
||||
var newIncludes = [];
|
||||
if(xml.getResponseHeader('X-Include-JS')) {
|
||||
var jsIncludes = xml.getResponseHeader('X-Include-JS').split(',');
|
||||
for(i=0;i<jsIncludes.length;i++) {
|
||||
if(!jQuery.isItemLoaded(jsIncludes[i])) {
|
||||
newIncludes.push(jsIncludes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// JavaScript
|
||||
var newIncludes = [];
|
||||
if(xml.getResponseHeader('X-Include-JS')) {
|
||||
var jsIncludes = xml.getResponseHeader('X-Include-JS').split(',');
|
||||
for(i=0;i<jsIncludes.length;i++) {
|
||||
if(!jQuery.isItemLoaded(jsIncludes[i])) {
|
||||
newIncludes.push(jsIncludes[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We make an array of the includes that are actually new, and attach the callback to the last one
|
||||
// They are placed in a queue and will be included in order. This means that the callback will
|
||||
// be able to execute script in the new includes (such as a livequery update)
|
||||
if(newIncludes.length > 0) {
|
||||
for(i=0;i<jsIncludes.length;i++) {
|
||||
jQuery.requireJs(jsIncludes[i], (i == jsIncludes.length-1) ? function() { _ondemandComplete(xml); } : null);
|
||||
}
|
||||
// We make an array of the includes that are actually new, and attach the callback to the last one
|
||||
// They are placed in a queue and will be included in order. This means that the callback will
|
||||
// be able to execute script in the new includes (such as a livequery update)
|
||||
if(newIncludes.length > 0) {
|
||||
for(i=0;i<jsIncludes.length;i++) {
|
||||
jQuery.requireJs(jsIncludes[i], (i == jsIncludes.length-1) ? function() { _ondemandComplete(xml); } : null);
|
||||
}
|
||||
|
||||
// If there aren't any new includes, then we can just call the callbacks ourselves
|
||||
} else {
|
||||
_ondemandComplete(xml, status);
|
||||
}
|
||||
// If there aren't any new includes, then we can just call the callbacks ourselves
|
||||
} else {
|
||||
_ondemandComplete(xml, status);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user