Skip to content

Commit 0a6dbcc

Browse files
authored
Merge pull request #1545 from gethinode/radius
fix: improve init of color mode icons
2 parents d7facc3 + c012eb5 commit 0a6dbcc

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

assets/js/critical/color.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@
4343
document.documentElement.setAttribute('data-bs-theme', theme)
4444
}
4545

46-
document.querySelectorAll('.navbar-mode-selector').forEach(chk => {
47-
chk.checked = (document.documentElement.getAttribute('data-bs-theme') === 'light')
48-
})
46+
updateSelectors()
4947
}
5048

5149
// alternates the currently active theme
@@ -54,6 +52,12 @@
5452
setTheme(target)
5553
}
5654

55+
function updateSelectors() {
56+
document.querySelectorAll('.navbar-mode-selector').forEach(chk => {
57+
chk.checked = (document.documentElement.getAttribute('data-bs-theme') === 'light')
58+
})
59+
}
60+
5761
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
5862
if (storedTheme !== 'light' || storedTheme !== 'dark') {
5963
setTheme(getPreferredTheme())
@@ -69,7 +73,12 @@
6973
})
7074
})
7175

72-
// initialize theme directly when script is invoked
76+
window.addEventListener('load', () => {
77+
// update the selectors when all elements are ready
78+
updateSelectors()
79+
})
80+
81+
// initialize theme as soon as possible to reduce screen flickering
7382
setTheme(getTheme())
7483
})()
7584

0 commit comments

Comments
 (0)