]> sipb.mit.edu Git - ikiwiki.git/blob - underlays/javascript/ikiwiki.js
relativedate: New javascript-alicious plugin that makes all dates display relative...
[ikiwiki.git] / underlays / javascript / ikiwiki.js
1 // ikiwiki's javascript utility function library
2
3 var hooks = new Array;
4 window.onload = run_hooks_onload;
5
6 function run_hooks_onload() {
7         run_hooks("onload");
8 }
9
10 function run_hooks(name) {
11         for (var i = 0; i < hooks.length; i++) {
12                 if (hooks[i].name == name) {
13                         hooks[i].call();
14                 }
15         }
16 }
17
18 function hook(name, call) {
19         var h={name: name, call: call};
20         hooks.push(h);
21 }
22
23 function getElementsByClass(cls, node, tag) {
24         if (document.getElementsByClass)
25                 return document.getElementsByClass(cls, node, tag);
26         if (! node) node = document;
27         if (! tag) tag = '*';
28         var ret = new Array();
29         var pattern = new RegExp("(^|\\s)"+cls+"(\\s|$)");
30         var els = node.getElementsByTagName(tag);
31         for (i = 0; i < els.length; i++) {
32                 if ( pattern.test(els[i].className) ) {
33                         ret.push(els[i]);
34                 }
35         }
36         return ret;
37 }