feat[css,js]: implemented auto select

I implemented dark-light auto select in the js button.
I also corrected the baseof layout to put the selector in the right place.
This commit is contained in:
Judah Sotomayor 2023-11-13 21:01:38 -05:00
parent edba941110
commit 317f064ac2
Signed by: judahsotomayor
SSH Key Fingerprint: SHA256:9Dq4ppxhfAjbX+7HLXEt+ROMiIojI6kqQgUyFUJb9lI
3 changed files with 17 additions and 7 deletions

View File

@ -15,7 +15,6 @@
<!-- The part of the page that begins to differ between templates -->
{{ end }}
<script src="/js/dark.js"></script>
{{ block "footer" . }}
<!-- More shared code, perhaps a footer but that can be overridden if need be in -->
@ -23,5 +22,6 @@
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
{{ end }}
<script src="/js/dark.js"></script>
</body>
</html>

View File

@ -103,7 +103,6 @@ weight: bold;
#mode-selector {
position: relative;
display: flex;
padding: 0.125em 0.25em;
border: 3px solid transparent;
}
#mode-selector button {

View File

@ -286,19 +286,30 @@ function updateModeSelectorState() {
/* Set specified color mode (auto, light, dark).
*/
function setDark() {
document.body.classList.add('dark');
document.getElementById("mode-selector").classList.add('dark');
}
function unsetDark() {
document.body.classList.remove('dark');
document.getElementById("mode-selector").classList.remove('dark');
}
function setMode(modeOption) {
GWLog("setMode");
// Inject the appropriate styles.
let modeStyles = document.querySelector("#mode-styles");
if (modeOption == 'auto') {
modeStyles.innerHTML = `@media (prefers-color-scheme:dark) {${GW.modeStyles}}`;
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
setDark();
} else {
unsetDark();
}
} else if (modeOption == 'dark') {
document.body.classList.add('dark');
document.getElementById("mode-selector").classList.add('dark');
setDark();
} else {
document.body.classList.remove('dark');
document.getElementById("mode-selector").classList.remove('dark');
unsetDark();
}
// Update selector state.