remove link to index
[ikiwiki.git] / underlays / javascript / ikiwiki / ikiwiki.js
blobaebc5cf7ed66395ec8277a1e748d29184226f960
1 // ikiwiki's javascript utility function library
3 var hooks;
5 // Run onload as soon as the DOM is ready, if possible.
6 // gecko, opera 9
7 if (document.addEventListener) {
8 document.addEventListener("DOMContentLoaded", run_hooks_onload, false);
10 // other browsers
11 window.onload = run_hooks_onload;
13 var onload_done = 0;
15 function run_hooks_onload() {
16 // avoid firing twice
17 if (onload_done)
18 return;
19 onload_done = true;
21 run_hooks("onload");
24 function run_hooks(name) {
25 if (typeof(hooks) != "undefined") {
26 for (var i = 0; i < hooks.length; i++) {
27 if (hooks[i].name == name) {
28 hooks[i].call();
34 function hook(name, call) {
35 if (typeof(hooks) == "undefined")
36 hooks = new Array;
37 hooks.push({name: name, call: call});
40 function getElementsByClass(cls, node, tag) {
41 if (document.getElementsByClass)
42 return document.getElementsByClass(cls, node, tag);
43 if (! node) node = document;
44 if (! tag) tag = '*';
45 var ret = new Array();
46 var pattern = new RegExp("(^|\\s)"+cls+"(\\s|$)");
47 var els = node.getElementsByTagName(tag);
48 for (i = 0; i < els.length; i++) {
49 if ( pattern.test(els[i].className) ) {
50 ret.push(els[i]);
53 return ret;