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:
parent
edba941110
commit
317f064ac2
@ -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>
|
||||||
|
@ -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 {
|
||||||
|
@ -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) {
|
||||||
|
setDark();
|
||||||
|
} else {
|
||||||
|
unsetDark();
|
||||||
|
}
|
||||||
|
|
||||||
} else if (modeOption == 'dark') {
|
} else if (modeOption == 'dark') {
|
||||||
document.body.classList.add('dark');
|
setDark();
|
||||||
document.getElementById("mode-selector").classList.add('dark');
|
|
||||||
} else {
|
} else {
|
||||||
document.body.classList.remove('dark');
|
unsetDark();
|
||||||
document.getElementById("mode-selector").classList.remove('dark');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update selector state.
|
// Update selector state.
|
||||||
|
Loading…
Reference in New Issue
Block a user