summaryrefslogtreecommitdiff
path: root/underlays/javascript/ikiwiki/toggle.js
diff options
context:
space:
mode:
authorJoey Hess <joey@kitenet.net>2010-04-24 00:54:59 -0400
committerJoey Hess <joey@kitenet.net>2010-04-24 00:54:59 -0400
commite90d67d3c9a93862657563e17e24054087f205d1 (patch)
treed1bfb530411c4ae2b9bb95737608ee3090a20c0a /underlays/javascript/ikiwiki/toggle.js
parentb28323e76a98d56fa4af813338a134dea0106626 (diff)
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/toggle.js')
-rw-r--r--underlays/javascript/ikiwiki/toggle.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/underlays/javascript/ikiwiki/toggle.js b/underlays/javascript/ikiwiki/toggle.js
new file mode 100644
index 000000000..d190b737a
--- /dev/null
+++ b/underlays/javascript/ikiwiki/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";
+}