diff options
author | Joey Hess <joey@kitenet.net> | 2010-04-24 00:54:59 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-04-24 00:54:59 -0400 |
commit | e90d67d3c9a93862657563e17e24054087f205d1 (patch) | |
tree | d1bfb530411c4ae2b9bb95737608ee3090a20c0a /underlays/javascript/ikiwiki/ikiwiki.js | |
parent | b28323e76a98d56fa4af813338a134dea0106626 (diff) | |
download | ikiwiki-e90d67d3c9a93862657563e17e24054087f205d1.tar ikiwiki-e90d67d3c9a93862657563e17e24054087f205d1.tar.gz |
Moved javascript files under the ikiwiki/ directory, to avoid cluttering the top of the web root. This is another things that requires a wiki rebuild on upgrade to this version.
Diffstat (limited to 'underlays/javascript/ikiwiki/ikiwiki.js')
-rw-r--r-- | underlays/javascript/ikiwiki/ikiwiki.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/underlays/javascript/ikiwiki/ikiwiki.js b/underlays/javascript/ikiwiki/ikiwiki.js new file mode 100644 index 000000000..aebc5cf7e --- /dev/null +++ b/underlays/javascript/ikiwiki/ikiwiki.js @@ -0,0 +1,54 @@ +// ikiwiki's javascript utility function library + +var hooks; + +// Run onload as soon as the DOM is ready, if possible. +// gecko, opera 9 +if (document.addEventListener) { + document.addEventListener("DOMContentLoaded", run_hooks_onload, false); +} +// other browsers +window.onload = run_hooks_onload; + +var onload_done = 0; + +function run_hooks_onload() { + // avoid firing twice + if (onload_done) + return; + onload_done = true; + + run_hooks("onload"); +} + +function run_hooks(name) { + if (typeof(hooks) != "undefined") { + for (var i = 0; i < hooks.length; i++) { + if (hooks[i].name == name) { + hooks[i].call(); + } + } + } +} + +function hook(name, call) { + if (typeof(hooks) == "undefined") + hooks = new Array; + hooks.push({name: name, call: call}); +} + +function getElementsByClass(cls, node, tag) { + if (document.getElementsByClass) + return document.getElementsByClass(cls, node, tag); + if (! node) node = document; + if (! tag) tag = '*'; + var ret = new Array(); + var pattern = new RegExp("(^|\\s)"+cls+"(\\s|$)"); + var els = node.getElementsByTagName(tag); + for (i = 0; i < els.length; i++) { + if ( pattern.test(els[i].className) ) { + ret.push(els[i]); + } + } + return ret; +} |