summaryrefslogtreecommitdiff
path: root/ikiwiki/toggle.js
blob: 597a37458afc61995685c8e95f3cd18adf4cbd25 (plain)
  1. // © 2006-2010 Joey Hess
  2. // Redistribution and use in source and compiled forms, with or without
  3. // modification, are permitted under any circumstances. No warranty.
  4. //
  5. // Uses CSS to hide toggleables, to avoid any flashing on page load. The
  6. // CSS is only emitted after it tests that it's going to be able
  7. // to show the toggleables.
  8. if (document.getElementById && document.getElementsByTagName && document.createTextNode) {
  9. document.write('<style type="text/css">div.toggleable { display: none; }</style>');
  10. hook("onload", inittoggle);
  11. }
  12. function inittoggle() {
  13. var as = getElementsByClass('toggle');
  14. for (var i = 0; i < as.length; i++) {
  15. var id = as[i].href.match(/#(\w.+)/)[1];
  16. if (document.getElementById(id).className == "toggleable")
  17. document.getElementById(id).style.display="none";
  18. as[i].onclick = function() {
  19. toggle(this);
  20. return false;
  21. }
  22. }
  23. }
  24. function toggle(s) {
  25. var id = s.href.match(/#(\w.+)/)[1];
  26. style = document.getElementById(id).style;
  27. if (style.display == "none")
  28. style.display = "block";
  29. else
  30. style.display = "none";
  31. }