summaryrefslogtreecommitdiff
path: root/itjs/boot.js
diff options
context:
space:
mode:
authorChristian Schneider2007-10-11 00:39:30 +0000
committerChristian Schneider2007-10-11 00:39:30 +0000
commit35fe33f7364329dacf415c950bff01b6de9ef88e (patch)
treeb0e6b018b50038ca20266723c53750268f508df5 /itjs/boot.js
parent1f95711ff3e9697cd85a54545ab42e5fd3611317 (diff)
downloaditools-35fe33f7364329dacf415c950bff01b6de9ef88e.tar.gz
itools-35fe33f7364329dacf415c950bff01b6de9ef88e.tar.bz2
itools-35fe33f7364329dacf415c950bff01b6de9ef88e.zip
Populated release branch
Diffstat (limited to 'itjs/boot.js')
-rw-r--r--itjs/boot.js162
1 files changed, 162 insertions, 0 deletions
diff --git a/itjs/boot.js b/itjs/boot.js
new file mode 100644
index 0000000..aaa0321
--- /dev/null
+++ b/itjs/boot.js
@@ -0,0 +1,162 @@
+// $Id$
+
+var it_boot_status = "boot";
+var it_panictimer = window.setTimeout("it_panic(it_boot_status)", 31337), it_domtimer;
+var it_catcherrstart = new Date().getTime();
+
+function it_catcherr(msg, url, line)
+{
+ var stacktrace = "";
+
+ for (var c = it_catcherr.caller; c != null; c = c.caller)
+ {
+ var funcname = c.toString().match(/function (\w*)/)[1];
+ stacktrace += (funcname ? funcname : "anon") + "/";
+
+ if (c.caller == c) // Break simple recursion
+ {
+ stacktrace += "*";
+ break;
+ }
+ }
+
+ if (typeof it_boot.sequence != 'undefined')
+ stacktrace += "it_boot=" + it_boot.sequence + ";";
+ if (typeof window.it_loader != 'undefined' && it_loader.sequence)
+ stacktrace += "it_loader=" + it_loader.sequence + ";";
+
+ it_boot_report(msg, url, line, stacktrace);
+
+ return !window.env || !!window.env.is_live_server; // No env or live server -> suppress error
+}
+
+window.onerror = it_catcherr;
+
+function it_boot_addparam(url, param)
+{
+ return url + (url.match(/\?/) ? "&" : "?") + param;
+}
+
+function it_panic(reason, msg)
+{
+ if (!document.location.href.match(/[?&]static=/)) // Avoid loop
+ window.setTimeout("document.location.href = it_boot_addparam(document.location.href, 'static=" + reason + "')", 500);
+
+ return it_boot_report('panic ' + reason, '-', -1, (msg ? msg : ''));
+}
+
+function it_boot_report(msg, file, line, more)
+{
+ window.clearTimeout(window.it_domtimer);
+ window.clearTimeout(window.it_panictimer);
+
+ new Image().src = "/itjs/error.gif/" + escape(msg) + "|" + escape(file) + "|" + line + "|" + (new Date().getTime() - it_catcherrstart) + "|" + escape(more);
+}
+
+function it_boot_checkcss(style, key, value)
+{
+ return navigator.userAgent.match(/konqueror/i) || (style && style.getPropertyValue && (style.getPropertyValue(key) == value));
+}
+
+function it_boot_init()
+{
+ window.it_domtimer = null;
+ var konqueror = navigator.userAgent.match(/konqueror/i);
+ var doc = document;
+ var dom = doc && (dom = doc.getElementById('it_boot_dom')); // HTML has been rendered
+ var view = dom && doc.defaultView; // We can check if stylesheet is active
+ var style = view && view.getComputedStyle && view.getComputedStyle(dom, '');
+ var css = window.it_boot_checkcss(style, "visibility", "hidden"); // CSS active (inline style on tag)
+ var stylesheet = window.it_boot_checkcss(style, "display", "none"); // External stylesheet loaded
+
+ if (!(doc || !(it_boot_status = "doc")) || !(dom || !(it_boot_status = "dom")) || (style && !(stylesheet || !(it_boot_status = "stylesheet"))))
+ {
+ window.it_domtimer = window.setTimeout("it_boot_init()" , 42);
+
+ if (style && !css)
+ it_panic("css");
+
+ return;
+ }
+
+ it_boot.sequence += "i";
+ window.clearTimeout(window.it_panictimer);
+ window.it_boot_start();
+ it_boot.sequence = "";
+}
+
+function it_boot(file, isretry)
+{
+ it_boot.file = file;
+ it_boot.sequence = isretry ? "r" : "b";
+
+ try
+ {
+ var loader = new XMLHttpRequest();
+ }
+ catch (e)
+ {
+ var classnames = [ 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP' ];
+
+ for (var i in classnames)
+ try { loader = new ActiveXObject(classnames[i]); break; } catch (e) {}
+ }
+
+ if (loader)
+ {
+ it_boot.sequence += "l";
+ loader.open("GET", it_boot_addparam(file, "boot=1" + (isretry ? "&retry=1" : "")));
+ loader.onreadystatechange = function()
+ {
+ var error = "";
+
+ if (loader.readyState == 4)
+ {
+ if (loader.status < 400) // Opera gives back 304 if from cache
+ {
+ // check length cookie
+ var ln = String(loader.responseText).substr(-16).match(/\*sln:\s*([0-9]+)\*/);
+ if (ln && ln[1]-0 == loader.responseText.length)
+ {
+ it_boot.sequence += "e";
+ var code = "try {" + loader.responseText + "} catch (e) { it_catcherr(e.message, it_boot.file, -1); }"; // Wrapped in try/catch as Konqueror does not support window.onerror
+ if (window.execScript)
+ window.execScript(code, "javascript"); // IE work-around to get script executed in global scope
+ else
+ window.setTimeout(code, 0); // Standard compliant version
+ }
+ else
+ error = (ln ? "length mismatch: "+ln[1]+" != "+loader.responseText.length : "no length cookie");
+ }
+ else
+ error = loader.statusText;
+
+ if (error)
+ {
+ if (isretry)
+ it_panic('load', error);
+ else
+ it_boot(file, true);
+ }
+ }
+ }
+ loader.send(null);
+ }
+ else
+ {
+ var doc = document;
+ var dom = doc && (dom = doc.getElementById('it_boot_dom')); // HTML has been rendered
+ it_boot.sequence += "n";
+
+ if (window.opera || (document.all && navigator.platform.indexOf("Mac") >= 0))
+ document.write('<sc'+'ript type="text/javascript" src="'+it_boot_addparam(file, 'boot=1')+'"><\/sc'+'ript>');
+ else if (dom)
+ {
+ var tag = doc.createElement("script");
+ tag.src = it_boot_addparam(file, 'boot=1&retry=1');
+ dom.appendChild(tag);
+ }
+ else
+ window.it_domtimer = window.setTimeout("it_boot('" + file + "')" , 42);
+ }
+}