summaryrefslogtreecommitdiff
path: root/underlays/javascript/ikiwiki/toggle.js
blob: d190b737ae1fc8288ae846328caa62ab0688fbdb (plain)
  1. // Uses CSS to hide toggleables, to avoid any flashing on page load. The
  2. // CSS is only emitted after it tests that it's going to be able
  3. // to show the toggleables.
  4. if (document.getElementById && document.getElementsByTagName && document.createTextNode) {
  5. document.write('<style type="text/css">div.toggleable { display: none; }</style>');
  6. hook("onload", inittoggle);
  7. }
  8. function inittoggle() {
  9. var as = getElementsByClass('toggle');
  10. for (var i = 0; i < as.length; i++) {
  11. var id = as[i].href.match(/#(\w.+)/)[1];
  12. if (document.getElementById(id).className == "toggleable")
  13. document.getElementById(id).style.display="none";
  14. as[i].onclick = function() {
  15. toggle(this);
  16. return false;
  17. }
  18. }
  19. }
  20. function toggle(s) {
  21. var id = s.href.match(/#(\w.+)/)[1];
  22. style = document.getElementById(id).style;
  23. if (style.display == "none")
  24. style.display = "block";
  25. else
  26. style.display = "none";
  27. }