Init
This commit is contained in:
22
resources/js/theme.js
Normal file
22
resources/js/theme.js
Normal file
@@ -0,0 +1,22 @@
|
||||
function darkModeListener() {
|
||||
document.querySelector("html").classList.toggle("dark");
|
||||
if (localStorage.theme == 'light') {
|
||||
localStorage.theme = 'dark';
|
||||
} else {
|
||||
localStorage.theme = 'light';
|
||||
}
|
||||
}
|
||||
|
||||
document.querySelector("input[type='checkbox']#toogleTheme").addEventListener("click", darkModeListener);
|
||||
|
||||
if(localStorage.theme) {
|
||||
if (localStorage.theme == 'light') {
|
||||
if (document.querySelector("html").classList.contains('dark')) {
|
||||
document.querySelector("html").classList.toggle("dark");
|
||||
}
|
||||
document.getElementById("toogleTheme").checked = true;
|
||||
}
|
||||
} else {
|
||||
// Default Dark Theme
|
||||
localStorage.theme = 'dark';
|
||||
}
|
Reference in New Issue
Block a user