Hi !
Modified Ext.ux.OnDemandLoadByAjax to permit multiple callbacks, one on each script or
no callback, and no check of script extension (php, js, anything).
Code:
/** begin of code **/
Ext.ux.OnDemandLoadByAjax = function() {
loadComponent = function(component) {
var sURL = null;
var sCALLBACK = null;
if (typeof component === "string") {
sURL = component;
} else if (typeof component === "object") {
sURL = component[0];
sCALLBACK = component[1];
}
handleSuccess = function(response, options) {
var head = document.getElementsByTagName("head")[0];
var js = document.createElement('script');
js.setAttribute("type", "text/javascript");
js.text = response.responseText;
if (!document.all) {
js.innerHTML = response.responseText;
}
head.appendChild(js);
if (typeof sCALLBACK == "function") {
if (document.all) {
sCALLBACK();
} else {
sCALLBACK.defer(50);
}
}
}
handleFailure = function(response, options) {
alert('Dynamic load script: [' + sURL + '] failed!');
}
Ext.Ajax.request({
url: sURL ,method: 'GET' ,success: handleSuccess ,failure: handleFailure ,disableCaching : false
});
}
return {
load: function(components) {
Ext.each(components, function(component) {
loadComponent(component);
});
}
}
}();
/** end of code **/
/** example of use, one callback only **/
var oScripts = [
'dependence1.js', 'dependence2.js', [ 'script.php', function(options) {
alert('this is a callback after script.php');
}
]
];
Ext.ux.OnDemandLoadByAjax.load(oScripts);
/** example of use, multiples callbacks **/
var oScripts = [
[ 'script1.php', function(options) {
alert('this is a callback after script1.php');
}
] ,[ 'script2.php', function(options) {
alert('this is a callback after script2.php');
}
]
];
Ext.ux.OnDemandLoadByAjax.load(oScripts);
Thanks