Skip to content

Commit ce58ea8

Browse files
1 parent 2a2596e commit ce58ea8

File tree

174 files changed

+33888
-863
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+33888
-863
lines changed

main/404.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6484,8 +6484,6 @@ <h1>404 - Not found</h1>
64846484

64856485
<script src="https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js"></script>
64866486

6487-
<script src="/assets/javascripts/toggle-sidebar.js" async></script>
6488-
64896487

64906488
</body>
64916489
</html>

main/algebra/all-submasks.html

Lines changed: 203 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,209 @@
7272

7373

7474

75-
</head>
75+
<script>(function() {
76+
const customDynamicStyle = document.createElement("style");
77+
// We must put it outside of the head and body, since they are replaced by the instant navigation feature in the Material theme
78+
document.documentElement.appendChild(customDynamicStyle);
79+
80+
const TOGGLE_BUTTON_REFERENCE_ELEMENT_NOT_FOUND_WARNING = "[mkdocs-toggle-sidebar-plugin] Reference element for inserting 'toggle_button' not found. This version of the plugin may not be compatible with this version of the theme. Try updating both to the latest version. If that fails, you can open an GitHub issue.";
81+
82+
const loadBool = (name, default_value) => {
83+
const value = localStorage.getItem(`TOGGLE_SIDEBAR_${name}`);
84+
if (value == null) {
85+
return default_value;
86+
} else {
87+
return value == "1";
88+
}
89+
}
90+
91+
const loadNavigationState = () => loadBool("NAVIGATION", true);
92+
const loadTocState = () => loadBool("TOC", true);
93+
94+
const saveBool = (name, value) => {
95+
localStorage.setItem(`TOGGLE_SIDEBAR_${name}`, value ? "1" : "0");
96+
}
97+
98+
const toggleVisibility = (toggleNavigation, toggleTOC) => {
99+
let newNavigation = loadNavigationState();
100+
let newTOC = loadTocState();
101+
102+
if (toggleNavigation) {
103+
newNavigation = !newNavigation;
104+
saveBool("NAVIGATION", newNavigation);
105+
}
106+
if (toggleTOC) {
107+
newTOC = !newTOC;
108+
saveBool("TOC", newTOC);
109+
}
110+
111+
_setVisibility(newNavigation, newTOC);
112+
}
113+
114+
const _setVisibility = (newNavigation, newTOC) => {
115+
console.debug(`Setting new visibility: navigation=${newNavigation}, TOC=${newTOC}`);
116+
// combine this into one operation, so that it is more efficient (for toggling both) and easier to code with dynamic CSS generation
117+
customDynamicStyle.innerHTML = setCombinedVisibility(newNavigation, newTOC);
118+
}
119+
120+
// START OF INCLUDE
121+
// This gets replaced with the definitions of:
122+
// - setCombinedVisibility(showNavigation: bool, showTOC: bool) -> string (dynamic CSS)
123+
// - registerKeyboardEventHandler() -> void
124+
const setCombinedVisibility = (showNavigation, showTOC) => {
125+
// Hide the button when on mobile (and menu us shown as hamburger menu anyways).
126+
// The exact max-width is taken from the styling of the 'body > header > nav > a' element
127+
128+
let style = `
129+
.mkdocs-toggle-sidebar-button {
130+
cursor: pointer;
131+
margin-right: 5px;
132+
margin-left: 1rem;
133+
}
134+
135+
@media screen and (max-width: 76.1875em) {
136+
.mkdocs-toggle-sidebar-button {
137+
display: none;
138+
}
139+
}
140+
`;
141+
// The TOC has a different break point than the navigation.
142+
// It can be seen on the nav.md-nav--secondary:nth-child(1) element (60em)
143+
// If the screen is smaller, it is shown in the navigation section if you click the nested hamburger menu
144+
if (!showTOC) {
145+
style += `
146+
@media screen and (min-width: 60em) {
147+
div.md-sidebar.md-sidebar--secondary {
148+
display: none;
149+
}
150+
}
151+
`;
152+
}
153+
154+
// We always have to show the navigation in mobile view, otherwise the hamburger menu is broken
155+
if (!showNavigation) {
156+
style += `
157+
@media screen and (min-width: 76.1875em) {
158+
div.md-sidebar.md-sidebar--primary {
159+
display: none;
160+
}
161+
}
162+
`;
163+
}
164+
165+
return style;
166+
}
167+
168+
const addToggleButton = (toggleNavigation, toggleTOC) => {
169+
const toggleBtn = createDefaultToggleButton(toggleNavigation, toggleTOC);
170+
toggleBtn.classList.add("md-icon");
171+
172+
const titleElement = document.querySelector(".md-header__title");
173+
if (titleElement) {
174+
titleElement.parentNode.insertBefore(toggleBtn, titleElement.nextSibling);
175+
} else {
176+
console.warn(TOGGLE_BUTTON_REFERENCE_ELEMENT_NOT_FOUND_WARNING);
177+
}
178+
}
179+
180+
const registerKeyboardEventHandler = () => {
181+
// Custom key handlers: SEE https://squidfunk.github.io/mkdocs-material/setup/setting-up-navigation/?h=key+bind#docsjavascriptsshortcutsjs
182+
keyboard$.subscribe(key => {
183+
if (key.mode === "global") {
184+
if (coreEventListenerLogic(key.type)) {
185+
// event handled, stop propagation
186+
key.claim();
187+
}
188+
}
189+
});
190+
}
191+
192+
// END OF INCLUDE
193+
194+
// argument: string, returns true if the key was handled and the event should be marked as already handled
195+
const coreEventListenerLogic = (keyChar) => {
196+
if (keyChar === "t") {
197+
toggleVisibility(false, true);
198+
return true;
199+
} else if (keyChar === "m") {
200+
toggleVisibility(true, false);
201+
return true;
202+
} else if (keyChar === "b") {
203+
toggleVisibility(true, true);
204+
return true;
205+
} else {
206+
return false;
207+
}
208+
}
209+
210+
const onPageLoadedAction = () => {
211+
console.log("The mkdocs-toggle-sidebar-plugin is installed. It adds the following key bindings:\n T -> toggle table of contents sidebar\n M -> toggle navigation menu sidebar\n B -> toggle both sidebars (TOC and navigation)");
212+
213+
const toggle_button = "all";
214+
if (toggle_button == "none") {
215+
// do nothing
216+
} else if (toggle_button == "navigation") {
217+
addToggleButton(true, false);
218+
} else if (toggle_button == "toc") {
219+
addToggleButton(false, true);
220+
} else if (toggle_button == "all") {
221+
addToggleButton(true, true);
222+
} else {
223+
console.error(`[mkdocs-toggle-sidebar-plugin] Unknown value for toggle_button: '${toggleButtonType}'`);
224+
}
225+
226+
registerKeyboardEventHandler();
227+
}
228+
229+
const createDefaultToggleButton = (toggleNavigation, toggleTOC) => {
230+
const toggleBtn = document.createElement("div");
231+
toggleBtn.className = "mkdocs-toggle-sidebar-button";
232+
toggleBtn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"></path></svg>`;
233+
if (toggleNavigation && toggleTOC) {
234+
toggleBtn.title = "Toggle Navigation and Table of Contents";
235+
} else if (toggleNavigation) {
236+
toggleBtn.title = "Toggle Navigation";
237+
} else if (toggleTOC) {
238+
toggleBtn.title = "Toggle Table of Contents";
239+
}
240+
toggleBtn.addEventListener("click", () => toggleVisibility(toggleNavigation, toggleTOC));
241+
return toggleBtn;
242+
};
243+
244+
// Export functions that the user can call to modify the state
245+
window.MkdocsToggleSidebarPlugin = {
246+
setNavigationVisibility: (show) => {
247+
saveBool("NAVIGATION", show);
248+
_setVisibility(show, loadTocState());
249+
},
250+
setTocVisibility: (show) => {
251+
saveBool("TOC", show);
252+
_setVisibility(loadNavigationState(), show);
253+
},
254+
setAllVisibility: (showNavigation, showTOC) => {
255+
saveBool("NAVIGATION", showNavigation);
256+
saveBool("TOC", showTOC);
257+
_setVisibility(showNavigation, showTOC);
258+
},
259+
toggleNavigationVisibility: () => toggleVisibility(true, false),
260+
toggleTocVisibility: () => toggleVisibility(false, true),
261+
toggleAllVisibility: () => toggleVisibility(true, true)
262+
};
263+
264+
// Run this immediately instead of waiting for page.onload to prevent page flicker
265+
customDynamicStyle.innerHTML = setCombinedVisibility(loadNavigationState(), loadTocState());
266+
// console.log("Debug: hide sidebar completed");
267+
268+
// SEE https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event#checking_whether_loading_is_already_complete
269+
if (document.readyState === "loading") {
270+
// console.debug("Registering DOMContentLoaded event listener");
271+
document.addEventListener("DOMContentLoaded", onPageLoadedAction);
272+
} else {
273+
// console.debug("DOMContentLoaded has already fired");
274+
onPageLoadedAction();
275+
}
276+
}());
277+
</script></head>
76278

77279

78280

@@ -6789,8 +6991,6 @@ <h2 id="practice-problems">Practice Problems<a class="headerlink" href="#practic
67896991

67906992
<script src="https://unpkg.com/mathjax@3/es5/tex-mml-chtml.js"></script>
67916993

6792-
<script src="../assets/javascripts/toggle-sidebar.js" async></script>
6793-
67946994

67956995
</body>
67966996
</html>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy