diff options
author | Joey Hess <joey@kodama.kitenet.net> | 2008-10-18 12:47:08 -0400 |
---|---|---|
committer | Joey Hess <joey@kodama.kitenet.net> | 2008-10-18 12:47:08 -0400 |
commit | 18806fa6b0f2afab703d558a499da8918214a1c7 (patch) | |
tree | fcd36fe6c2a7702b2b445ecd7966c5e25b140c0b /underlays/javascript | |
parent | cb9a695443abb64b2bcce1316ccea5842adab9e7 (diff) |
allow ikiwiki.js to be loaded twice w/o clobbering previous hooks
Clearly it's suboptimal for it to be loaded twice, but this is a quick fix
at least.
Diffstat (limited to 'underlays/javascript')
-rw-r--r-- | underlays/javascript/ikiwiki.js | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/underlays/javascript/ikiwiki.js b/underlays/javascript/ikiwiki.js index 29de7ec6f..14ddd0745 100644 --- a/underlays/javascript/ikiwiki.js +++ b/underlays/javascript/ikiwiki.js @@ -1,6 +1,6 @@ // ikiwiki's javascript utility function library -var hooks = new Array; +var hooks; window.onload = run_hooks_onload; function run_hooks_onload() { @@ -8,16 +8,19 @@ function 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) { |