Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99e01b3de3 |
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \App\View\AppView $this
|
||||
*/
|
||||
|
||||
?>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function (e) {
|
||||
const toggleDarkLink = document.getElementById('toggle-dark-mode');
|
||||
const toggleLightLink = document.getElementById('toggle-light-mode');
|
||||
const toggleAutoLink = document.getElementById('toggle-auto-mode');
|
||||
if (toggleDarkLink) {
|
||||
toggleDarkLink.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
localStorage.theme = 'dark';
|
||||
document.documentElement.classList.add('dark');
|
||||
document.documentElement.classList.remove('auto');
|
||||
});
|
||||
}
|
||||
if (toggleLightLink) {
|
||||
toggleLightLink.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
localStorage.theme = 'light';
|
||||
document.documentElement.classList.remove('auto');
|
||||
document.documentElement.classList.remove('dark');
|
||||
});
|
||||
}
|
||||
if (toggleAutoLink) {
|
||||
toggleAutoLink.addEventListener('click', function (e) {
|
||||
e.preventDefault();
|
||||
localStorage.theme = 'auto';
|
||||
document.documentElement.classList.add('auto');
|
||||
document.documentElement.classList.remove('dark');
|
||||
});
|
||||
}
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \App\View\AppView $this
|
||||
*/
|
||||
|
||||
?>
|
||||
<script>
|
||||
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
|
||||
document.documentElement.classList.toggle(
|
||||
"dark",
|
||||
localStorage.theme === "dark" ||
|
||||
(!("theme" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches),
|
||||
);
|
||||
document.documentElement.classList.toggle(
|
||||
"auto",
|
||||
localStorage.theme === "auto"
|
||||
);
|
||||
// Whenever the user explicitly chooses light mode
|
||||
|
||||
// localStorage.theme = "light";
|
||||
// // Whenever the user explicitly chooses dark mode
|
||||
// localStorage.theme = "dark";
|
||||
// // Whenever the user explicitly chooses to respect the OS preference
|
||||
// localStorage.removeItem("theme");
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user