]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - underlays/javascript/ikiwiki.js
Merge commit 'upstream/master'
[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 function run_hooks_onload() {
14         // avoid firing twice
15         if (arguments.callee.done)
16                 return;
17         arguments.callee.done = true;
19         run_hooks("onload");
20 }
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();
27                         }
28                 }
29         }
30 }
32 function hook(name, call) {
33         if (typeof(hooks) == "undefined")
34                 hooks = new Array;
35         hooks.push({name: name, call: call});
36 }
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]);
49                 }
50         }
51         return ret;
52 }