aboutsummaryrefslogtreecommitdiff
path: root/underlays/javascript/ikiwiki.js
blob: 14ddd0745a60abffb28aaec298488a8036d81025 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// ikiwiki's javascript utility function library

var hooks;
window.onload = run_hooks_onload;

function run_hooks_onload() {
	run_hooks("onload");
}

function run_hooks(name) {
	if (typeof(hooks) != "undefined") {
		for (var i = 0; i < hooks.length; i++) {
			if (hooks[i].name == name) {
				hooks[i].call();
			}
		}
	}
}

function hook(name, call) {
	if (typeof(hooks) == "undefined")
		hooks = new Array;
	hooks.push({name: name, call: call});
}

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;
}