aboutsummaryrefslogtreecommitdiff
path: root/underlays
diff options
context:
space:
mode:
Diffstat (limited to 'underlays')
-rw-r--r--underlays/javascript/ikiwiki.js37
-rw-r--r--underlays/javascript/toggle.js29
2 files changed, 66 insertions, 0 deletions
diff --git a/underlays/javascript/ikiwiki.js b/underlays/javascript/ikiwiki.js
new file mode 100644
index 000000000..29de7ec6f
--- /dev/null
+++ b/underlays/javascript/ikiwiki.js
@@ -0,0 +1,37 @@
+// ikiwiki's javascript utility function library
+
+var hooks = new Array;
+window.onload = run_hooks_onload;
+
+function run_hooks_onload() {
+ run_hooks("onload");
+}
+
+function run_hooks(name) {
+ for (var i = 0; i < hooks.length; i++) {
+ if (hooks[i].name == name) {
+ hooks[i].call();
+ }
+ }
+}
+
+function hook(name, call) {
+ var h={name: name, call: call};
+ hooks.push(h);
+}
+
+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;
+}
diff --git a/underlays/javascript/toggle.js b/underlays/javascript/toggle.js
new file mode 100644
index 000000000..d190b737a
--- /dev/null
+++ b/underlays/javascript/toggle.js
@@ -0,0 +1,29 @@
+// Uses CSS to hide toggleables, to avoid any flashing on page load. The
+// CSS is only emitted after it tests that it's going to be able
+// to show the toggleables.
+if (document.getElementById && document.getElementsByTagName && document.createTextNode) {
+ document.write('<style type="text/css">div.toggleable { display: none; }</style>');
+ hook("onload", inittoggle);
+}
+
+function inittoggle() {
+ var as = getElementsByClass('toggle');
+ for (var i = 0; i < as.length; i++) {
+ var id = as[i].href.match(/#(\w.+)/)[1];
+ if (document.getElementById(id).className == "toggleable")
+ document.getElementById(id).style.display="none";
+ as[i].onclick = function() {
+ toggle(this);
+ return false;
+ }
+ }
+}
+
+function toggle(s) {
+ var id = s.href.match(/#(\w.+)/)[1];
+ style = document.getElementById(id).style;
+ if (style.display == "none")
+ style.display = "block";
+ else
+ style.display = "none";
+}