dark mode theme strategy/dataset strategy
CI / testsuite (pgsql, 8.4, ) (push) Successful in 2m52s
CI / testsuite (mysql, 8.2, ) (push) Successful in 4m5s
CI / testsuite (mysql, 8.4, ) (push) Successful in 2m47s
CI / testsuite (pgsql, 8.2, ) (push) Successful in 4m25s
CI / testsuite (sqlite, 8.2, ) (push) Successful in 4m46s
CI / testsuite (sqlite, 8.2, prefer-lowest) (push) Successful in 3m57s
Release / build (push) Successful in 13s
CI / Coding Standard & Static Analysis (push) Successful in 3m28s
CI / testsuite (sqlite, 8.4, ) (push) Successful in 7m57s

This commit is contained in:
bs
2026-08-27 03:22:29 -07:00
parent 30325f4071
commit 9a8e85b647
2 changed files with 27 additions and 13 deletions
+14 -2
View File
@@ -1,11 +1,17 @@
<?php
use Cake\Core\Configure;
/**
* @var \App\View\AppView $this
*/
$strategy = Configure::read('CheeseCake.darkMode.strategy', 'dataset');
?>
<script>
// On page load or when changing themes, best to add inline in `head` to avoid FOUC
<?php if ($strategy === 'class') : ?>
document.documentElement.classList.toggle(
"dark",
localStorage.theme === "dark" ||
@@ -15,6 +21,13 @@
"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
// localStorage.theme = "light";
@@ -22,5 +35,4 @@
// localStorage.theme = "dark";
// // Whenever the user explicitly chooses to respect the OS preference
// localStorage.removeItem("theme");
</script>
</script>