-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathheader_custom.html
More file actions
33 lines (31 loc) · 1.09 KB
/
header_custom.html
File metadata and controls
33 lines (31 loc) · 1.09 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
<button class="btn js-toggle-dark-mode" aria-label="Switch to light mode">
☼
</button>
<script>
const toggleDarkMode = document.querySelector(".js-toggle-dark-mode");
jtd.addEvent(toggleDarkMode, "click", function () {
if (jtd.getTheme() === "light") {
jtd.setTheme("dark");
toggleDarkMode.textContent = "☼";
toggleDarkMode.ariaLabel = "Switch to light mode";
localStorage.setItem("theme", "dark");
} else {
jtd.setTheme("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 () {
if (localStorage.getItem("theme") === "dark") {
jtd.setTheme("dark");
toggleDarkMode.textContent = "☼";
} else {
jtd.setTheme("light");
toggleDarkMode.textContent = "☾";
}
});
</script>