mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2025-04-29 03:53:30 +08:00
feat(darkmode): dispatch onColorSchemeChange event
This commit is contained in:
parent
9ef0fd8928
commit
8e87827726
@ -38,7 +38,14 @@ class StackDarkMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private isDark() {
|
private isDark() {
|
||||||
return (this.currentScheme == 'dark' || this.currentScheme == 'auto' && this.preferDarkMode);
|
return (this.currentScheme == 'dark' || this.currentScheme == 'auto' && this.systemPreferScheme == 'dark');
|
||||||
|
}
|
||||||
|
|
||||||
|
private dispatchEvent(colorScheme: colorScheme) {
|
||||||
|
const event = new CustomEvent('onColorSchemeChange', {
|
||||||
|
detail: colorScheme
|
||||||
|
});
|
||||||
|
window.dispatchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private setBodyClass() {
|
private setBodyClass() {
|
||||||
@ -51,6 +58,8 @@ class StackDarkMode {
|
|||||||
else {
|
else {
|
||||||
document.body.dataset.scheme = 'light';
|
document.body.dataset.scheme = 'light';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.dispatchEvent(document.body.dataset.scheme as colorScheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getSavedScheme(): colorScheme {
|
private getSavedScheme(): colorScheme {
|
||||||
|
Loading…
Reference in New Issue
Block a user