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;
15 function 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) {
34 function hook(name, call) {
35 if (typeof(hooks) == "undefined")
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;
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) ) {