aboutsummaryrefslogtreecommitdiff
path: root/html/haddock-util.js
diff options
context:
space:
mode:
Diffstat (limited to 'html/haddock-util.js')
-rw-r--r--html/haddock-util.js64
1 files changed, 48 insertions, 16 deletions
diff --git a/html/haddock-util.js b/html/haddock-util.js
index c5bc6a8d..e9e4f64d 100644
--- a/html/haddock-util.js
+++ b/html/haddock-util.js
@@ -1,26 +1,58 @@
// Haddock JavaScript utilities
-function makeClassToggle(cOn, cOff)
+var rspace = /\s\s+/g,
+ rtrim = /^\s+|\s+$/g;
+
+function spaced(s) { return (" " + s + " ").replace(rspace, " "); }
+function trim(s) { return s.replace(rtrim, ""); }
+
+function hasClass(elem, value) {
+ var className = spaced(elem.className || "");
+ return className.indexOf( " " + value + " " ) >= 0;
+}
+
+function addClass(elem, value) {
+ var className = spaced(elem.className || "");
+ if ( className.indexOf( " " + value + " " ) < 0 ) {
+ elem.className = trim(className + " " + value);
+ }
+}
+
+function removeClass(elem, value) {
+ var className = spaced(elem.className || "");
+ className = className.replace(" " + value + " ", " ");
+ elem.className = trim(className);
+}
+
+function toggleClass(elem, valueOn, valueOff, bool) {
+ if (bool == null) { bool = ! hasClass(elem, valueOn); }
+ if (bool) {
+ removeClass(elem, valueOff);
+ addClass(elem, valueOn);
+ }
+ else {
+ removeClass(elem, valueOn);
+ addClass(elem, valueOff);
+ }
+ return bool;
+}
+
+
+function makeClassToggle(valueOn, valueOff)
{
- var rOn = new RegExp('\\b'+cOn+'\\b');
- var rOff = new RegExp('\\b'+cOff+'\\b');
-
- return function(e, a) {
- var c = e.className;
- if (a == null) { a = rOff.test(c); }
- if (a) { c = c.replace(rOff, cOn); }
- else { c = c.replace(rOn, cOff); }
- e.className = c;
+ return function(elem, bool) {
+ return toggleClass(elem, valueOn, valueOff, bool);
}
}
-toggleClassShow = makeClassToggle("show", "hide");
-toggleClassCollapser = makeClassToggle("collapser", "expander");
+toggleShow = makeClassToggle("show", "hide");
+toggleCollapser = makeClassToggle("collapser", "expander");
-function toggleSection(toggler,id)
+function toggleSection(id)
{
- toggleClassShow(document.getElementById(id))
- toggleClassCollapser(toggler);
+ var b = toggleShow(document.getElementById("section." + id))
+ toggleCollapser(document.getElementById("control." + id), b)
+ return b;
}
@@ -244,7 +276,7 @@ function resetStyle() {
function styleMenu(show) {
var m = document.getElementById('style-menu');
- toggleClassShow(m, show);
+ if (m) toggleClassShow(m, show);
}