diff options
author | Cache Saravento <cache@sarava.org> | 2015-08-07 14:07:50 -0300 |
---|---|---|
committer | Cache Saravento <cache@sarava.org> | 2015-08-07 14:07:50 -0300 |
commit | eeb7c436cc670a5910bc868bc2afaa06933334dd (patch) | |
tree | 2661af3c1a22ffc2c2b7b7f5a3b7b7b0f28c7eab /ikiwiki/ikiwiki.js | |
parent | f9d22a65481e2bdfc26a9f2c66ce2bf6ff8f6bd8 (diff) | |
download | cache-eeb7c436cc670a5910bc868bc2afaa06933334dd.tar.gz cache-eeb7c436cc670a5910bc868bc2afaa06933334dd.tar.bz2 |
Static generated site
Diffstat (limited to 'ikiwiki/ikiwiki.js')
-rw-r--r-- | ikiwiki/ikiwiki.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/ikiwiki/ikiwiki.js b/ikiwiki/ikiwiki.js new file mode 100644 index 0000000..aebc5cf --- /dev/null +++ b/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; +} |