mirror of
https://github.com/trwnh/hugo-theme-paradox.git
synced 2024-11-24 02:11:21 +00:00
finish fixing color switcher
This commit is contained in:
parent
cf9dc13bda
commit
ddadf97337
|
@ -133,14 +133,11 @@
|
|||
</style>
|
||||
<script>
|
||||
var body = document.body;
|
||||
var switcher = document.getElementsByClassName('js-toggle');
|
||||
var input = document.getElementsByClassName('js-toggle-screenreader-only');
|
||||
var switchers = document.getElementsByClassName('js-toggle');
|
||||
|
||||
console.log(switcher);
|
||||
|
||||
for (s of switcher) {
|
||||
s.removeAttribute("style");
|
||||
};
|
||||
for (switcher of switchers) {
|
||||
switcher.removeAttribute("style");
|
||||
var input = switcher.querySelector('.js-toggle-screenreader-only')
|
||||
|
||||
input.addEventListener('focus', (event) => {
|
||||
switcher.classList.add('js-toggle--focus');
|
||||
|
@ -152,7 +149,9 @@ input.addEventListener('focusout', (event) => {
|
|||
|
||||
//Click on dark mode icon. Add dark mode classes and wrappers. Store user preference through sessions
|
||||
switcher.addEventListener("click", function () {
|
||||
for (switcher of switchers) {
|
||||
this.classList.toggle('js-toggle--checked');
|
||||
}
|
||||
//this.classList.add('js-toggle--focus');
|
||||
//If dark mode is selected
|
||||
if (this.classList.contains('js-toggle--checked')) {
|
||||
|
@ -168,6 +167,7 @@ if (this.classList.contains('js-toggle--checked')) {
|
|||
}, 100);
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
localStorage.setItem('colorMode', 'dark');
|
||||
|
@ -175,14 +175,13 @@ if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').match
|
|||
|
||||
//Check Storage. Keep user preference on page reload
|
||||
if (localStorage.getItem('colorMode') == 'dark') {
|
||||
//body.classList.add('dark-mode');
|
||||
for (switcher of switchers) {
|
||||
switcher.classList.add('js-toggle--checked');
|
||||
}
|
||||
body.classList.add('dark-mode');
|
||||
}
|
||||
};
|
||||
if (localStorage.getItem('colorMode') == 'light') {
|
||||
//body.classList.add('dark-mode');
|
||||
|
||||
body.classList.add('light-mode');
|
||||
}
|
||||
};
|
||||
|
||||
</script>
|
Loading…
Reference in a new issue