From d2d98a1a3ce7a0def73e75be6e305e03b1af864e Mon Sep 17 00:00:00 2001 From: GDWR Date: Tue, 8 Feb 2022 23:44:26 +0000 Subject: Determine current theme and set switch --- pydis_site/static/js/base/navbar.js | 52 ++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'pydis_site/static/js') 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 -- cgit v1.2.3