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

View File

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

View File

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