]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - underlays/javascript/ikiwiki/toggle.js
answer question, with reference.
[git.ikiwiki.info.git] / underlays / javascript / ikiwiki / toggle.js
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 }
13 function inittoggle() {
14         var as = getElementsByClass('toggle');
15         for (var i = 0; i < as.length; i++) {
16                 var id = as[i].href.match(/#(\w.+)/)[1];
17                 if (document.getElementById(id).className == "toggleable")
18                         document.getElementById(id).style.display="none";
19                 as[i].onclick = function() {
20                         toggle(this);
21                         return false;
22                 }
23         }
24 }
26 function toggle(s) {
27         var id = s.href.match(/#(\w.+)/)[1];
28         style = document.getElementById(id).style;
29         if (style.display == "none")
30                 style.display = "block";
31         else
32                 style.display = "none";
33 }