]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - underlays/javascript/ikiwiki.js
Revert spam
[git.ikiwiki.info.git] / underlays / javascript / ikiwiki.js
index 29de7ec6f6f6237f1fc4ef5237b16d18d2a96ea4..aebc5cf7ed66395ec8277a1e748d29184226f960 100644 (file)
@@ -1,23 +1,40 @@
 // 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;
 
+var onload_done = 0;
+
 function run_hooks_onload() {
+       // avoid firing twice
+       if (onload_done)
+               return;
+       onload_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) {