summaryrefslogtreecommitdiff
path: root/underlays/javascript/ikiwiki.js
diff options
context:
space:
mode:
authorintrigeri <intrigeri@boum.org>2008-10-20 14:34:36 +0200
committerintrigeri <intrigeri@boum.org>2008-10-20 14:34:36 +0200
commitb6a4da775945856b07fdc8f1330a86f67e329ac9 (patch)
tree7ee389c28208e236cc4da4c3c51dbe9eae9234f0 /underlays/javascript/ikiwiki.js
parent67473ec58fbd1eebd914f2d023ee6c7a34ad47ba (diff)
parentfadb26bc1507f7fc2caaa873ad32c12f75c378aa (diff)
Merge branch 'prv/po' into pub/po
Diffstat (limited to 'underlays/javascript/ikiwiki.js')
-rw-r--r--underlays/javascript/ikiwiki.js27
1 files changed, 21 insertions, 6 deletions
diff --git a/underlays/javascript/ikiwiki.js b/underlays/javascript/ikiwiki.js
index 29de7ec6f..1252f244f 100644
--- a/underlays/javascript/ikiwiki.js
+++ b/underlays/javascript/ikiwiki.js
@@ -1,23 +1,38 @@
// ikiwiki's javascript utility function library
-var hooks = new Array;
+var hooks;
+
+// Run onload as soon as the DOM is ready, if possible.
+// gecko, opera 9
+if (document.addEventListener) {
+ document.addEventListener("DOMContentLoaded", run_hooks_onload, false);
+}
+// other browsers
window.onload = run_hooks_onload;
function run_hooks_onload() {
+ // avoid firing twice
+ if (arguments.callee.done)
+ return;
+ arguments.callee.done = true;
+
run_hooks("onload");
}
function run_hooks(name) {
- for (var i = 0; i < hooks.length; i++) {
- if (hooks[i].name == name) {
- hooks[i].call();
+ if (typeof(hooks) != "undefined") {
+ for (var i = 0; i < hooks.length; i++) {
+ if (hooks[i].name == name) {
+ hooks[i].call();
+ }
}
}
}
function hook(name, call) {
- var h={name: name, call: call};
- hooks.push(h);
+ if (typeof(hooks) == "undefined")
+ hooks = new Array;
+ hooks.push({name: name, call: call});
}
function getElementsByClass(cls, node, tag) {