diff options
author | Joey Hess <joey@kodama.kitenet.net> | 2008-10-17 20:28:18 -0400 |
---|---|---|
committer | Joey Hess <joey@kodama.kitenet.net> | 2008-10-17 20:28:18 -0400 |
commit | 79b376f9912891a8748fcbb4580969e4dbf7fc75 (patch) | |
tree | 40c99e6f94ddb7e0c9ecea6a1a109e015061dd68 /underlays/javascript/toggle.js | |
parent | 16d51e67a7e7257739e1cb3f9a3713d448065e5d (diff) |
Add an underlay for javascript, and add ikiwiki.js containing some utility code.
* Add an underlay for javascript, and add ikiwiki.js containing some utility
code.
* toggle: Stop embedding the full toggle code on each page using it, and
move it to toggle.js in the javascript underlay.
Diffstat (limited to 'underlays/javascript/toggle.js')
-rw-r--r-- | underlays/javascript/toggle.js | 29 |
1 files changed, 29 insertions, 0 deletions
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"; +} |