]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - underlays/javascript/ikiwiki.js
response
[git.ikiwiki.info.git] / underlays / javascript / ikiwiki.js
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);
9 }
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");
22 }
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();
29                         }
30                 }
31         }
32 }
34 function hook(name, call) {
35         if (typeof(hooks) == "undefined")
36                 hooks = new Array;
37         hooks.push({name: name, call: call});
38 }
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]);
51                 }
52         }
53         return ret;
54 }