forked from extern/egroupware
Added onLoadFinish event to egw_json_response on the js side, which gets triggered when all javascript code which should be included has been loaded and evaluated on the client
This commit is contained in:
parent
2b016955d9
commit
7ad65804d5
@ -200,6 +200,9 @@ function egw_json_request(_menuaction, _parameters, _context)
|
|||||||
this.sender = null;
|
this.sender = null;
|
||||||
this.callback = null;
|
this.callback = null;
|
||||||
this.alertHandler = this.alertFunc;
|
this.alertHandler = this.alertFunc;
|
||||||
|
this.onLoadFinish = null;
|
||||||
|
this.loadedJSFiles = {};
|
||||||
|
this.handleResponseDone = false;
|
||||||
if (window.egw_alertHandler)
|
if (window.egw_alertHandler)
|
||||||
{
|
{
|
||||||
this.alertHandler = window.egw_alertHandler;
|
this.alertHandler = window.egw_alertHandler;
|
||||||
@ -272,6 +275,7 @@ egw_json_request.prototype.jsonError = function(_msg, _e)
|
|||||||
/* Internal function which handles the response from the server */
|
/* Internal function which handles the response from the server */
|
||||||
egw_json_request.prototype.handleResponse = function(data, textStatus, XMLHttpRequest)
|
egw_json_request.prototype.handleResponse = function(data, textStatus, XMLHttpRequest)
|
||||||
{
|
{
|
||||||
|
this.handleResponseDone = false;
|
||||||
if (data && data.response)
|
if (data && data.response)
|
||||||
{
|
{
|
||||||
var hasResponse = false;
|
var hasResponse = false;
|
||||||
@ -406,7 +410,39 @@ egw_json_request.prototype.handleResponse = function(data, textStatus, XMLHttpRe
|
|||||||
var scriptnode = document.createElement('script');
|
var scriptnode = document.createElement('script');
|
||||||
scriptnode.type = "text/javascript";
|
scriptnode.type = "text/javascript";
|
||||||
scriptnode.src = res.data;
|
scriptnode.src = res.data;
|
||||||
|
scriptnode._originalSrc = res.data;
|
||||||
headID.appendChild(scriptnode);
|
headID.appendChild(scriptnode);
|
||||||
|
|
||||||
|
//Increment the includedJSFiles count
|
||||||
|
this.loadedJSFiles[res.data] = false;
|
||||||
|
|
||||||
|
if (typeof console != 'undefined')
|
||||||
|
console.log("Requested JS file '%s' from server", [res.data]);
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
//FF, Opera, Chrome
|
||||||
|
scriptnode.onload = function(e) {
|
||||||
|
var file = e.target._originalSrc;
|
||||||
|
if (typeof console != 'undefined')
|
||||||
|
console.log("Retrieved JS file '%s' from server", [file]);
|
||||||
|
|
||||||
|
self.loadedJSFiles[file] = true;
|
||||||
|
self.checkLoadFinish();
|
||||||
|
};
|
||||||
|
|
||||||
|
//IE
|
||||||
|
scriptnode.onreadystatechange = function() {
|
||||||
|
var node = window.event.srcElement;
|
||||||
|
if (node.readyState == 'complete') {
|
||||||
|
var file = node._originalSrc;
|
||||||
|
if (typeof console != 'undefined')
|
||||||
|
console.log("Retrieved JS file '%s' from server", [file]);
|
||||||
|
|
||||||
|
self.loadedJSFiles[file] = true;
|
||||||
|
self.checkLoadFinish();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
hasResponse = true;
|
hasResponse = true;
|
||||||
} else
|
} else
|
||||||
@ -434,6 +470,23 @@ egw_json_request.prototype.handleResponse = function(data, textStatus, XMLHttpRe
|
|||||||
{
|
{
|
||||||
this.callback.call(this.sender, data.response[i].data);
|
this.callback.call(this.sender, data.response[i].data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.handleResponseDone = true;
|
||||||
|
|
||||||
|
this.checkLoadFinish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
egw_json_request.prototype.checkLoadFinish = function()
|
||||||
|
{
|
||||||
|
var complete = true;
|
||||||
|
for (var key in this.loadedJSFiles)
|
||||||
|
complete = complete && this.loadedJSFiles[key];
|
||||||
|
|
||||||
|
if (complete && this.onLoadFinish && this.handleResponseDone)
|
||||||
|
{
|
||||||
|
console.log("Call onLoadFinish");
|
||||||
|
this.onLoadFinish.call(this.sender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
6364
phpgwapi/js/jquery/jquery.js
vendored
6364
phpgwapi/js/jquery/jquery.js
vendored
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user