CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418346
1
/* toggless.js Frank Lübeck */
2
3
/* this file contains two functions:
4
mergeSideTOCHooks: this changes div.ContSect elements to the class
5
ContSectClosed and includes a hook to toggle between
6
ContSectClosed and ContSectOpen.
7
openclosetoc: this function does the toggling, the rest is done by
8
CSS
9
*/
10
11
12
13
closedTOCMarker = "▶ ";
14
openTOCMarker = "▼ ";
15
noTOCMarker = " ";
16
/* merge hooks into side toc for opening/closing subsections
17
with openclosetoc */
18
function mergeSideTOCHooks() {
19
var hlist = document.getElementsByTagName("div");
20
for (var i = 0; i < hlist.length; i++) {
21
if (hlist[i].className == "ContSect") {
22
var chlds = hlist[i].childNodes;
23
var el = document.createElement("span");
24
var oncl = document.createAttribute("class");
25
oncl.nodeValue = "toctoggle";
26
el.setAttributeNode(oncl);
27
var cont;
28
if (chlds.length > 2) {
29
var oncl = document.createAttribute("onclick");
30
oncl.nodeValue = "openclosetoc(event)";
31
el.setAttributeNode(oncl);
32
cont = document.createTextNode(closedTOCMarker);
33
} else {
34
cont = document.createTextNode(noTOCMarker);
35
}
36
el.appendChild(cont);
37
hlist[i].firstChild.insertBefore(el, hlist[i].firstChild.firstChild);
38
hlist[i].className = "ContSectClosed";
39
}
40
}
41
}
42
43
function openclosetoc (event) {
44
/* first two steps to make it work in most browsers */
45
var evt=window.event || event;
46
if (!evt.target)
47
evt.target=evt.srcElement;
48
49
var markClosed = document.createTextNode(closedTOCMarker);
50
var markOpen = document.createTextNode(openTOCMarker);
51
52
var par = evt.target.parentNode.parentNode;
53
if (par.className == "ContSectOpen") {
54
par.className = "ContSectClosed";
55
evt.target.replaceChild(markClosed, evt.target.firstChild);
56
}
57
else if (par.className == "ContSectClosed") {
58
par.className = "ContSectOpen";
59
evt.target.replaceChild(markOpen, evt.target.firstChild);
60
}
61
}
62
63
/* adjust jscontent which is called onload */
64
jscontentfuncs.push(mergeSideTOCHooks);
65
66
67