Switch theme after loading for error pages
This commit is contained in:
parent
2b5d37295f
commit
375f72ec4d
1 changed files with 5 additions and 3 deletions
|
|
@ -6,12 +6,14 @@ export default class extends Controller {
|
||||||
COOKIE_NAME = "modeTheme";
|
COOKIE_NAME = "modeTheme";
|
||||||
|
|
||||||
connect() {
|
connect() {
|
||||||
|
console.log("set theme")
|
||||||
const cookieValue = Cookie.get(this.COOKIE_NAME);
|
const cookieValue = Cookie.get(this.COOKIE_NAME);
|
||||||
|
let darkMode = window.matchMedia("(prefers-color-scheme:dark)").matches ? "dark" : "light";
|
||||||
if (cookieValue) {
|
if (cookieValue) {
|
||||||
return true;
|
darkMode = cookieValue
|
||||||
|
} else {
|
||||||
|
Cookie.set(this.COOKIE_NAME, darkMode);
|
||||||
}
|
}
|
||||||
const darkMode = window.matchMedia("(prefers-color-scheme:dark)").matches ? "dark" : "light";
|
|
||||||
Cookie.set(this.COOKIE_NAME, darkMode);
|
|
||||||
window.document.getElementsByTagName("html")[0].setAttribute("data-bs-theme", darkMode)
|
window.document.getElementsByTagName("html")[0].setAttribute("data-bs-theme", darkMode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue