2026-08-27 02:35:47 -07:00
|
|
|
<?php
|
2026-08-27 03:22:29 -07:00
|
|
|
|
|
|
|
|
use Cake\Core\Configure;
|
|
|
|
|
|
2026-08-27 02:35:47 -07:00
|
|
|
/**
|
|
|
|
|
* @var \App\View\AppView $this
|
|
|
|
|
*/
|
2026-08-27 03:22:29 -07:00
|
|
|
$strategy = Configure::read('CheeseCake.darkMode.strategy', 'dataset');
|
2026-08-27 02:35:47 -07:00
|
|
|
|
|
|
|
|
?>
|
|
|
|
|
<script>
|
|
|
|
|
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
|
2026-08-27 03:22:29 -07:00
|
|
|
<?php if ($strategy === 'class') : ?>
|
|
|
|
|
|
2026-08-27 02:35:47 -07:00
|
|
|
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"
|
|
|
|
|
);
|
2026-08-27 03:22:29 -07:00
|
|
|
<?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; ?>
|
|
|
|
|
|
2026-08-27 02:35:47 -07:00
|
|
|
// 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");
|
2026-08-27 03:22:29 -07:00
|
|
|
</script>
|