diff options
author | Marcin Aman <marcin.aman@gmail.com> | 2021-08-25 14:54:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-25 14:54:34 +0200 |
commit | 742f96bdf5c0b842e68dfaf43f4ab3446e87e3df (patch) | |
tree | 8c8553f21f8175f298ace4005973d482b1f0be13 /plugins/base/src/main/resources/dokka/scripts | |
parent | 06650909dbce632bd92d3a10c2887b69555edbfc (diff) | |
download | dokka-742f96bdf5c0b842e68dfaf43f4ab3446e87e3df.tar.gz dokka-742f96bdf5c0b842e68dfaf43f4ab3446e87e3df.tar.bz2 dokka-742f96bdf5c0b842e68dfaf43f4ab3446e87e3df.zip |
Dark mode (#2081)
Diffstat (limited to 'plugins/base/src/main/resources/dokka/scripts')
-rw-r--r-- | plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js b/plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js index 05ec7377..ae838d6f 100644 --- a/plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js +++ b/plugins/base/src/main/resources/dokka/scripts/platform-content-handler.js @@ -20,8 +20,21 @@ window.addEventListener('load', () => { handleAnchor() initHidingLeftNavigation() topNavbarOffset = document.getElementById('navigation-wrapper') + darkModeSwitch() }) +const darkModeSwitch = () => { + const localStorageKey = "dokka-dark-mode" + const storage = localStorage.getItem(localStorageKey) + const savedDarkMode = storage ? JSON.parse(storage) : false + const element = document.getElementById("theme-toggle-button") + + element.addEventListener('click', () => { + document.getElementsByTagName("html")[0].classList.toggle("theme-dark") + localStorage.setItem(localStorageKey, JSON.stringify(!savedDarkMode)) + }) +} + const initHidingLeftNavigation = () => { document.getElementById("leftToggler").onclick = function(event) { //Events need to be prevented from bubbling since they will trigger next handler |