diff options
Diffstat (limited to 'pydis_site/static/js/base/navbar.js')
-rw-r--r-- | pydis_site/static/js/base/navbar.js | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/pydis_site/static/js/base/navbar.js b/pydis_site/static/js/base/navbar.js index 23ddfd7c..b49c86b1 100644 --- a/pydis_site/static/js/base/navbar.js +++ b/pydis_site/static/js/base/navbar.js @@ -44,6 +44,30 @@ function setStyleSheets() { } } +function toggleThemeSwitch() { + let switchToggle = $(".switch")[0]; + let knob = $(".knob")[0]; + + if (knob.classList.contains("dark")) { + knob.classList.remove("dark"); + knob.classList.add("light"); + + // After 500ms, switch the icons + setTimeout(function() { + switchToggle.classList.remove("dark"); + switchToggle.classList.add("light"); + }, 100); + } else { + knob.classList.remove("light"); + knob.classList.add("dark"); + + // After 500ms, switch the icons + setTimeout(function() { + switchToggle.classList.remove("light"); + switchToggle.classList.add("dark"); + }, 100); + } +} // Executed when the page has finished loading. document.addEventListener("DOMContentLoaded", () => { @@ -51,6 +75,9 @@ document.addEventListener("DOMContentLoaded", () => { setStyleSheets(); displayThemedElements(); + if (getCurrentTheme() === "default") + toggleThemeSwitch(); + $('#theme-switch').on("click", () => { // Update cookie @@ -62,29 +89,6 @@ document.addEventListener("DOMContentLoaded", () => { setStyleSheets(); displayThemedElements(); - - // Animations - let switchToggle = $(".switch")[0]; - let knob = $(".knob")[0]; - - if (knob.classList.contains("dark")) { - knob.classList.remove("dark"); - knob.classList.add("light"); - - // After 500ms, switch the icons - setTimeout(function() { - switchToggle.classList.remove("dark"); - switchToggle.classList.add("light"); - }, 100); - } else { - knob.classList.remove("light"); - knob.classList.add("dark"); - - // After 500ms, switch the icons - setTimeout(function() { - switchToggle.classList.remove("light"); - switchToggle.classList.add("dark"); - }, 100); - } + toggleThemeSwitch(); }); });
\ No newline at end of file |