Merge branch 'master' of git://git.ikiwiki.info into underlay-da
[ikiwiki.git] / underlays / javascript / ikiwiki.js
blob1252f244f8429faab7d5e7dccdd175bdd37a33f7
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 function run_hooks_onload() {
14 // avoid firing twice
15 if (arguments.callee.done)
16 return;
17 arguments.callee.done = true;
19 run_hooks("onload");
22 function run_hooks(name) {
23 if (typeof(hooks) != "undefined") {
24 for (var i = 0; i < hooks.length; i++) {
25 if (hooks[i].name == name) {
26 hooks[i].call();
32 function hook(name, call) {
33 if (typeof(hooks) == "undefined")
34 hooks = new Array;
35 hooks.push({name: name, call: call});
38 function getElementsByClass(cls, node, tag) {
39 if (document.getElementsByClass)
40 return document.getElementsByClass(cls, node, tag);
41 if (! node) node = document;
42 if (! tag) tag = '*';
43 var ret = new Array();
44 var pattern = new RegExp("(^|\\s)"+cls+"(\\s|$)");
45 var els = node.getElementsByTagName(tag);
46 for (i = 0; i < els.length; i++) {
47 if ( pattern.test(els[i].className) ) {
48 ret.push(els[i]);
51 return ret;