allow ikiwiki.js to be loaded twice w/o clobbering previous hooks
authorJoey Hess <joey@kodama.kitenet.net>
Sat, 18 Oct 2008 16:47:08 +0000 (12:47 -0400)
committerJoey Hess <joey@kodama.kitenet.net>
Sat, 18 Oct 2008 16:47:08 +0000 (12:47 -0400)
Clearly it's suboptimal for it to be loaded twice, but this is a quick fix
at least.

underlays/javascript/ikiwiki.js

index 29de7ec6f6f6237f1fc4ef5237b16d18d2a96ea4..14ddd0745a60abffb28aaec298488a8036d81025 100644 (file)
@@ -1,6 +1,6 @@
 // ikiwiki's javascript utility function library
 
 // ikiwiki's javascript utility function library
 
-var hooks = new Array;
+var hooks;
 window.onload = run_hooks_onload;
 
 function run_hooks_onload() {
 window.onload = run_hooks_onload;
 
 function run_hooks_onload() {
@@ -8,16 +8,19 @@ function run_hooks_onload() {
 }
 
 function run_hooks(name) {
 }
 
 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) {
                }
        }
 }
 
 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) {
 }
 
 function getElementsByClass(cls, node, tag) {