Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a8e85b647 |
@@ -5,7 +5,7 @@ use Cake\Core\Configure;
|
|||||||
/**
|
/**
|
||||||
* @var \App\View\AppView $this
|
* @var \App\View\AppView $this
|
||||||
*/
|
*/
|
||||||
$strategy = Configure::read('CheeseCake.darkMode.strategy', 'class');
|
$strategy = Configure::read('CheeseCake.darkMode.strategy', 'dataset');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<script>
|
<script>
|
||||||
@@ -17,12 +17,13 @@ $strategy = Configure::read('CheeseCake.darkMode.strategy', 'class');
|
|||||||
toggleDarkLink.addEventListener('click', function (e) {
|
toggleDarkLink.addEventListener('click', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
localStorage.theme = 'dark';
|
localStorage.theme = 'dark';
|
||||||
<?php if ($strategy === 'class') : ?>
|
console.debug('dark');
|
||||||
|
<?php if ($strategy === 'class') : ?>
|
||||||
document.documentElement.classList.add('dark');
|
document.documentElement.classList.add('dark');
|
||||||
document.documentElement.classList.remove('auto');
|
document.documentElement.classList.remove('auto');
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
document.documentElement.dataset.theme = 'dark';
|
document.documentElement.dataset.theme = 'dark';
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -30,25 +31,26 @@ $strategy = Configure::read('CheeseCake.darkMode.strategy', 'class');
|
|||||||
toggleLightLink.addEventListener('click', function (e) {
|
toggleLightLink.addEventListener('click', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
localStorage.theme = 'light';
|
localStorage.theme = 'light';
|
||||||
<?php if ($strategy === 'class') : ?>
|
console.debug('light');
|
||||||
|
<?php if ($strategy === 'class') : ?>
|
||||||
document.documentElement.classList.remove('auto');
|
document.documentElement.classList.remove('auto');
|
||||||
document.documentElement.classList.remove('dark');
|
document.documentElement.classList.remove('dark');
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
document.documentElement.dataset.theme = 'light';
|
document.documentElement.dataset.theme = 'light';
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (toggleAutoLink) {
|
if (toggleAutoLink) {
|
||||||
toggleAutoLink.addEventListener('click', function (e) {
|
toggleAutoLink.addEventListener('click', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
localStorage.theme = 'auto';
|
localStorage.theme = 'auto';
|
||||||
<?php if ($strategy === 'class') : ?>
|
<?php if ($strategy === 'class') : ?>
|
||||||
document.documentElement.classList.add('auto');
|
document.documentElement.classList.add('auto');
|
||||||
document.documentElement.classList.remove('dark');
|
document.documentElement.classList.remove('dark');
|
||||||
|
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
delete document.documentElement.dataset.theme;
|
delete document.documentElement.dataset.theme;
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Cake\Core\Configure;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \App\View\AppView $this
|
* @var \App\View\AppView $this
|
||||||
*/
|
*/
|
||||||
|
$strategy = Configure::read('CheeseCake.darkMode.strategy', 'dataset');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<script>
|
<script>
|
||||||
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
|
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
|
||||||
|
<?php if ($strategy === 'class') : ?>
|
||||||
|
|
||||||
document.documentElement.classList.toggle(
|
document.documentElement.classList.toggle(
|
||||||
"dark",
|
"dark",
|
||||||
localStorage.theme === "dark" ||
|
localStorage.theme === "dark" ||
|
||||||
@@ -15,6 +21,13 @@
|
|||||||
"auto",
|
"auto",
|
||||||
localStorage.theme === "auto"
|
localStorage.theme === "auto"
|
||||||
);
|
);
|
||||||
|
<?php else : ?>
|
||||||
|
localStorage.theme === "dark" ||
|
||||||
|
(!("theme" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches) ?
|
||||||
|
document.documentElement.dataset.theme = "dark" :
|
||||||
|
document.documentElement.dataset.theme = "light";
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
// Whenever the user explicitly chooses light mode
|
// Whenever the user explicitly chooses light mode
|
||||||
|
|
||||||
// localStorage.theme = "light";
|
// localStorage.theme = "light";
|
||||||
@@ -23,4 +36,3 @@
|
|||||||
// // Whenever the user explicitly chooses to respect the OS preference
|
// // Whenever the user explicitly chooses to respect the OS preference
|
||||||
// localStorage.removeItem("theme");
|
// localStorage.removeItem("theme");
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user