File: toggless.js

package info (click to toggle)
gap-gapdoc 1.6.2-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 4,452 kB
  • sloc: xml: 3,491; makefile: 243; sh: 3
file content (65 lines) | stat: -rw-r--r-- 2,181 bytes parent folder | download | duplicates (35)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* toggless.js                                      Frank Lübeck   */

/* this file contains two functions:
   mergeSideTOCHooks:  this changes div.ContSect elements to the class
                       ContSectClosed and includes a hook to toggle between
                       ContSectClosed and ContSectOpen. 
   openclosetoc:       this function does the toggling, the rest is done by
                       CSS
*/



closedTOCMarker = "▶ ";
openTOCMarker = "▼ ";
noTOCMarker = "  ";
/* merge hooks into side toc for opening/closing subsections
   with openclosetoc   */
function mergeSideTOCHooks() {
  var hlist = document.getElementsByTagName("div");
  for (var i = 0; i < hlist.length; i++) {
     if (hlist[i].className == "ContSect") {
       var chlds = hlist[i].childNodes;
       var el = document.createElement("span");
       var oncl = document.createAttribute("class");
       oncl.nodeValue = "toctoggle";
       el.setAttributeNode(oncl);
       var cont;
       if (chlds.length > 2) {
         var oncl = document.createAttribute("onclick");
         oncl.nodeValue = "openclosetoc(event)";
         el.setAttributeNode(oncl);
         cont = document.createTextNode(closedTOCMarker);
       } else {
         cont = document.createTextNode(noTOCMarker);
       }
       el.appendChild(cont);
       hlist[i].firstChild.insertBefore(el, hlist[i].firstChild.firstChild);
       hlist[i].className = "ContSectClosed";
     }
  }
}

function openclosetoc (event) {
  /* first two steps to make it work in most browsers */
  var evt=window.event || event;
  if (!evt.target) 
    evt.target=evt.srcElement;

  var markClosed = document.createTextNode(closedTOCMarker);
  var markOpen = document.createTextNode(openTOCMarker);

  var par = evt.target.parentNode.parentNode;
  if (par.className == "ContSectOpen") {
    par.className = "ContSectClosed";
    evt.target.replaceChild(markClosed, evt.target.firstChild);
  }
  else if (par.className == "ContSectClosed") {
    par.className = "ContSectOpen";
    evt.target.replaceChild(markOpen, evt.target.firstChild);
  }
}

/* adjust jscontent which is called onload */
jscontentfuncs.push(mergeSideTOCHooks);