X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/9a62836d288fbced42b04a172baf52063ef71c61..7bd9f368b6ec23eb364c0ebec08516cfb75b2f18:/underlays/javascript/ikiwiki.js?ds=inline 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) {