diff --git a/_includes/Nav.html b/_includes/Nav.html index 22cb9be82..4ded8eaf8 100644 --- a/_includes/Nav.html +++ b/_includes/Nav.html @@ -30,55 +30,56 @@ {%- endcomment -%} \ No newline at end of file + + \ No newline at end of file diff --git a/assets/js/modeswitcher.js b/assets/js/modeswitcher.js index c6ed7523f..7829231cf 100644 --- a/assets/js/modeswitcher.js +++ b/assets/js/modeswitcher.js @@ -19,11 +19,24 @@ function changeIconImgSrc(src) { document.getElementById("theme-toggle-img--mobile").src = src; } -if (systemInitiatedDark.matches) { - changeIconImgSrc(iconMoon); -} else { - changeIconImgSrc(iconSun); -} +document.addEventListener("DOMContentLoaded", () => { + if (systemInitiatedDark.matches) { + changeIconImgSrc(iconMoon); + } else { + changeIconImgSrc(iconSun); + } + if (theme === "dark") { + document.documentElement.setAttribute('data-theme', 'dark'); + sessionStorage.setItem('theme', 'dark'); + changeIconImgSrc(iconMoon); + } else if (theme === "light") { + document.documentElement.setAttribute('data-theme', 'light'); + sessionStorage.setItem('theme', 'light'); + changeIconImgSrc(iconSun); + } +}) + + function prefersColorTest(systemInitiatedDark) { if (systemInitiatedDark.matches) { @@ -58,14 +71,4 @@ function modeSwitcher() { sessionStorage.setItem('theme', 'dark'); changeIconImgSrc(iconMoon); } -} - -if (theme === "dark") { - document.documentElement.setAttribute('data-theme', 'dark'); - sessionStorage.setItem('theme', 'dark'); - changeIconImgSrc(iconMoon); -} else if (theme === "light") { - document.documentElement.setAttribute('data-theme', 'light'); - sessionStorage.setItem('theme', 'light'); - changeIconImgSrc(iconSun); } \ No newline at end of file