1 // ikiwiki's javascript utility function library
5 // Run onload as soon as the DOM is ready, if possible.
7 if (document.addEventListener) {
8 document.addEventListener("DOMContentLoaded", run_hooks_onload, false);
11 window.onload = run_hooks_onload;
13 function run_hooks_onload() {
15 if (arguments.callee.done)
17 arguments.callee.done = true;
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) {
32 function hook(name, call) {
33 if (typeof(hooks) == "undefined")
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;
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) ) {