sidebar.js - sphere - GPU-based 3D discrete element method algorithm with optional fluid coupling
HTML git clone git://src.adamsgaard.dk/sphere
DIR Log
DIR Files
DIR Refs
DIR LICENSE
---
sidebar.js (2395B)
---
1 /*
2 * This script makes the Sphinx sidebar collapsible.
3 *
4 * .sphinxsidebar contains .sphinxsidebarwrapper. This script adds
5 * in .sphixsidebar, after .sphinxsidebarwrapper, the #sidebarbutton
6 * used to collapse and expand the sidebar.
7 *
8 * When the sidebar is collapsed the .sphinxsidebarwrapper is hidden
9 * and the width of the sidebar and the margin-left of the document
10 * are decreased. When the sidebar is expanded the opposite happens.
11 * This script saves a per-browser/per-session cookie used to
12 * remember the position of the sidebar among the pages.
13 * Once the browser is closed the cookie is deleted and the position
14 * reset to the default (expanded).
15 *
16 */
17
18 const initialiseSidebar = () => {
19
20
21
22
23 // global elements used by the functions.
24 const bodyWrapper = document.getElementsByClassName("bodywrapper")[0]
25 const sidebar = document.getElementsByClassName("sphinxsidebar")[0]
26 const sidebarWrapper = document.getElementsByClassName('sphinxsidebarwrapper')[0]
27 const sidebarButton = document.getElementById("sidebarbutton")
28 const sidebarArrow = sidebarButton.querySelector('span')
29
30 // for some reason, the document has no sidebar; do not run into errors
31 if (typeof sidebar === "undefined") return;
32
33 const flipArrow = element => element.innerText = (element.innerText === "»") ? "«" : "»"
34
35 const collapse_sidebar = () => {
36 bodyWrapper.style.marginLeft = ".8em";
37 sidebar.style.width = ".8em"
38 sidebarWrapper.style.display = "none"
39 flipArrow(sidebarArrow)
40 sidebarButton.title = _('Expand sidebar')
41 window.localStorage.setItem("sidebar", "collapsed")
42 }
43
44 const expand_sidebar = () => {
45 bodyWrapper.style.marginLeft = ""
46 sidebar.style.removeProperty("width")
47 sidebarWrapper.style.display = ""
48 flipArrow(sidebarArrow)
49 sidebarButton.title = _('Collapse sidebar')
50 window.localStorage.setItem("sidebar", "expanded")
51 }
52
53 sidebarButton.addEventListener("click", () => {
54 (sidebarWrapper.style.display === "none") ? expand_sidebar() : collapse_sidebar()
55 })
56
57 if (!window.localStorage.getItem("sidebar")) return
58 const value = window.localStorage.getItem("sidebar")
59 if (value === "collapsed") collapse_sidebar();
60 else if (value === "expanded") expand_sidebar();
61 }
62
63 if (document.readyState !== "loading") initialiseSidebar()
64