aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site
diff options
context:
space:
mode:
authorGravatar GDWR <[email protected]>2022-02-08 23:44:26 +0000
committerGravatar GDWR <[email protected]>2022-02-08 23:44:26 +0000
commitd2d98a1a3ce7a0def73e75be6e305e03b1af864e (patch)
treed19335ec38f7090db695219613755de1029d5b14 /pydis_site
parentremove unused colour values (diff)
Determine current theme and set switch
Diffstat (limited to 'pydis_site')
-rw-r--r--pydis_site/static/js/base/navbar.js52
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