summaryrefslogtreecommitdiff
path: root/underlays/javascript/ikiwiki.js
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-10-17 20:28:18 -0400
committerJoey Hess <joey@kodama.kitenet.net>2008-10-17 20:28:18 -0400
commit79b376f9912891a8748fcbb4580969e4dbf7fc75 (patch)
tree40c99e6f94ddb7e0c9ecea6a1a109e015061dd68 /underlays/javascript/ikiwiki.js
parent16d51e67a7e7257739e1cb3f9a3713d448065e5d (diff)
Add an underlay for javascript, and add ikiwiki.js containing some utility code.
* Add an underlay for javascript, and add ikiwiki.js containing some utility code. * toggle: Stop embedding the full toggle code on each page using it, and move it to toggle.js in the javascript underlay.
Diffstat (limited to 'underlays/javascript/ikiwiki.js')
-rw-r--r--underlays/javascript/ikiwiki.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/underlays/javascript/ikiwiki.js b/underlays/javascript/ikiwiki.js
new file mode 100644
index 000000000..29de7ec6f
--- /dev/null
+++ b/underlays/javascript/ikiwiki.js
@@ -0,0 +1,37 @@
+// ikiwiki's javascript utility function library
+
+var hooks = new Array;
+window.onload = run_hooks_onload;
+
+function run_hooks_onload() {
+ run_hooks("onload");
+}
+
+function run_hooks(name) {
+ 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);
+}
+
+function getElementsByClass(cls, node, tag) {
+ if (document.getElementsByClass)
+ return document.getElementsByClass(cls, node, tag);
+ if (! node) node = document;
+ if (! tag) tag = '*';
+ var ret = new Array();
+ var pattern = new RegExp("(^|\\s)"+cls+"(\\s|$)");
+ var els = node.getElementsByTagName(tag);
+ for (i = 0; i < els.length; i++) {
+ if ( pattern.test(els[i].className) ) {
+ ret.push(els[i]);
+ }
+ }
+ return ret;
+}