MCPcopy Create free account
hub / github.com/dtmilano/AndroidViewClient / initialiseSidebar

Function initialiseSidebar

docs/_static/sidebar.js:24–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22 */
23
24const initialiseSidebar = () => {
25
26
27
28
29 // global elements used by the functions.
30 const bodyWrapper = document.getElementsByClassName("bodywrapper")[0]
31 const sidebar = document.getElementsByClassName("sphinxsidebar")[0]
32 const sidebarWrapper = document.getElementsByClassName('sphinxsidebarwrapper')[0]
33 const sidebarButton = document.getElementById("sidebarbutton")
34 const sidebarArrow = sidebarButton.querySelector('span')
35
36 // for some reason, the document has no sidebar; do not run into errors
37 if (typeof sidebar === "undefined") return;
38
39 const flipArrow = element => element.innerText = (element.innerText === "»") ? "«" : "»"
40
41 const collapse_sidebar = () => {
42 bodyWrapper.style.marginLeft = ".8em";
43 sidebar.style.width = ".8em"
44 sidebarWrapper.style.display = "none"
45 flipArrow(sidebarArrow)
46 sidebarButton.title = _('Expand sidebar')
47 window.localStorage.setItem("sidebar", "collapsed")
48 }
49
50 const expand_sidebar = () => {
51 bodyWrapper.style.marginLeft = ""
52 sidebar.style.removeProperty("width")
53 sidebarWrapper.style.display = ""
54 flipArrow(sidebarArrow)
55 sidebarButton.title = _('Collapse sidebar')
56 window.localStorage.setItem("sidebar", "expanded")
57 }
58
59 sidebarButton.addEventListener("click", () => {
60 (sidebarWrapper.style.display === "none") ? expand_sidebar() : collapse_sidebar()
61 })
62
63 if (!window.localStorage.getItem("sidebar")) return
64 const value = window.localStorage.getItem("sidebar")
65 if (value === "collapsed") collapse_sidebar();
66 else if (value === "expanded") expand_sidebar();
67}
68
69if (document.readyState !== "loading") initialiseSidebar()
70else document.addEventListener("DOMContentLoaded", initialiseSidebar)

Callers 1

sidebar.jsFile · 0.85

Calls 2

expand_sidebarFunction · 0.85
collapse_sidebarFunction · 0.85

Tested by

no test coverage detected