1 // © 2006-2010 Joey Hess
2 // Redistribution and use in source and compiled forms, with or without
3 // modification, are permitted under any circumstances. No warranty.
5 // ikiwiki's javascript utility function library
9 // Run onload as soon as the DOM is ready, if possible.
11 if (document.addEventListener) {
12 document.addEventListener("DOMContentLoaded", run_hooks_onload, false);
15 window.onload = run_hooks_onload;
19 function run_hooks_onload() {
28 function run_hooks(name) {
29 if (typeof(hooks) != "undefined") {
30 for (var i = 0; i < hooks.length; i++) {
31 if (hooks[i].name == name) {
38 function hook(name, call) {
39 if (typeof(hooks) == "undefined")
41 hooks.push({name: name, call: call});
44 function getElementsByClass(cls, node, tag) {
45 if (document.getElementsByClass)
46 return document.getElementsByClass(cls, node, tag);
47 if (! node) node = document;
49 var ret = new Array();
50 var pattern = new RegExp("(^|\\s)"+cls+"(\\s|$)");
51 var els = node.getElementsByTagName(tag);
52 for (i = 0; i < els.length; i++) {
53 if ( pattern.test(els[i].className) ) {