forked from UCL-ARC/python-tooling
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader_custom.html
More file actions
43 lines (39 loc) · 1.34 KB
/
header_custom.html
File metadata and controls
43 lines (39 loc) · 1.34 KB
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
<div class="js-toggle-dark-mode-wrapper">
<button
class="btn js-toggle-dark-mode"
aria-label="Switch to light mode"
type="button"
>
☼
</button>
</div>
<script>
const toggleDarkMode = document.querySelector(".js-toggle-dark-mode");
const setHtmlThemeAttr = (theme) => {
document.documentElement.setAttribute("data-theme", theme);
};
jtd.addEvent(toggleDarkMode, "click", function () {
if (jtd.getTheme() === "light") {
jtd.setTheme("dark");
setHtmlThemeAttr("dark");
toggleDarkMode.textContent = "☼";
toggleDarkMode.ariaLabel = "Switch to light mode";
localStorage.setItem("theme", "dark");
} else {
jtd.setTheme("light");
setHtmlThemeAttr("light");
toggleDarkMode.textContent = "☾";
toggleDarkMode.ariaLabel = "Switch to dark mode";
localStorage.setItem("theme", "light");
}
});
/* TODO: we can probably delete this (hacky workaround) if/when just-the-docs/#1223 is fixed.
* Meanwhile, we check each time if there is a theme written to local storage and obey it.
*/
window.addEventListener("DOMContentLoaded", function () {
const theme = localStorage.getItem("theme") === "dark" ? "dark" : "light";
jtd.setTheme(theme);
setHtmlThemeAttr(theme);
toggleDarkMode.textContent = theme === "dark" ? "☼" : "☾";
});
</script>