Pull include/util.js from noVNC.
Pull version 51562999c7 load_scripts fixes.
This commit is contained in:
parent
c00c0eed1a
commit
1d795c0643
|
|
@ -217,32 +217,52 @@ Util.conf_defaults = function(cfg, api, defaults, arr) {
|
||||||
Util.get_include_uri = function() {
|
Util.get_include_uri = function() {
|
||||||
return (typeof INCLUDE_URI !== "undefined") ? INCLUDE_URI : "include/";
|
return (typeof INCLUDE_URI !== "undefined") ? INCLUDE_URI : "include/";
|
||||||
}
|
}
|
||||||
|
Util._loading_scripts = [];
|
||||||
Util._pending_scripts = [];
|
Util._pending_scripts = [];
|
||||||
Util.load_scripts = function(files) {
|
Util.load_scripts = function(files) {
|
||||||
var head = document.getElementsByTagName('head')[0],
|
var head = document.getElementsByTagName('head')[0], script,
|
||||||
ps = Util._pending_scripts;
|
ls = Util._loading_scripts, ps = Util._pending_scripts;
|
||||||
for (var f=0; f<files.length; f++) {
|
for (var f=0; f<files.length; f++) {
|
||||||
var script = document.createElement('script');
|
script = document.createElement('script');
|
||||||
script.type = 'text/javascript';
|
script.type = 'text/javascript';
|
||||||
script.src = Util.get_include_uri() + files[f];
|
script.src = Util.get_include_uri() + files[f];
|
||||||
//console.log("loading script: " + Util.get_include_uri() + files[f]);
|
//console.log("loading script: " + script.src);
|
||||||
head.appendChild(script);
|
|
||||||
ps.push(script);
|
|
||||||
script.onload = script.onreadystatechange = function (e) {
|
script.onload = script.onreadystatechange = function (e) {
|
||||||
if (!this.readyState ||
|
while (ls.length > 0 && (ls[0].readyState === 'loaded' ||
|
||||||
this.readyState == 'complete' ||
|
ls[0].readyState === 'complete')) {
|
||||||
this.readyState == 'loaded') {
|
// For IE, append the script to trigger execution
|
||||||
this.onload = this.onreadystatechange = null;
|
var s = ls.shift();
|
||||||
if (ps.indexOf(this) >= 0) {
|
//console.log("loaded script: " + s.src);
|
||||||
//console.log("loaded script: " + this.src);
|
head.appendChild(s);
|
||||||
ps.splice(ps.indexOf(this), 1);
|
|
||||||
}
|
}
|
||||||
|
if (!this.readyState ||
|
||||||
|
(Util.Engine.presto && this.readyState === 'loaded') ||
|
||||||
|
this.readyState === 'complete') {
|
||||||
|
if (ps.indexOf(this) >= 0) {
|
||||||
|
this.onload = this.onreadystatechange = null;
|
||||||
|
//console.log("completed script: " + this.src);
|
||||||
|
ps.splice(ps.indexOf(this), 1);
|
||||||
|
|
||||||
// Call window.onscriptsload after last script loads
|
// Call window.onscriptsload after last script loads
|
||||||
if (ps.length === 0 && window.onscriptsload) {
|
if (ps.length === 0 && window.onscriptsload) {
|
||||||
window.onscriptsload();
|
window.onscriptsload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
// In-order script execution tricks
|
||||||
|
if (Util.Engine.trident) {
|
||||||
|
// For IE wait until readyState is 'loaded' before
|
||||||
|
// appending it which will trigger execution
|
||||||
|
// http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
|
||||||
|
ls.push(script);
|
||||||
|
} else {
|
||||||
|
// For webkit and firefox set async=false and append now
|
||||||
|
// https://developer.mozilla.org/en-US/docs/HTML/Element/script
|
||||||
|
script.async = false;
|
||||||
|
head.appendChild(script);
|
||||||
|
}
|
||||||
|
ps.push(script);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue