Skip to content

Commit cbc7c4b

Browse files
authored
doc(Theme): update event handler the float theme button (#4789)
1 parent 902e266 commit cbc7c4b

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { getTheme, switchTheme } from "../../../BootstrapBlazor/modules/utility.js"
2-
import { switchTheme as syncTheme } from "./Pre.razor.js"
3-
import Data from "../../../BootstrapBlazor/modules/data.js"
1+
import { switchTheme as syncTheme } from "./Pre.razor.js"
42
import EventHandler from "../../../BootstrapBlazor/modules/event-handler.js"
53

64
export function init(id) {
@@ -17,23 +15,6 @@ export function init(id) {
1715
}
1816
prevScrollTop = currentScrollTop
1917
});
20-
21-
const themeElement = document.querySelector('.icon-theme');
22-
if (themeElement) {
23-
EventHandler.on(themeElement, 'click', async e => {
24-
let theme = getTheme();
25-
if (theme === 'dark') {
26-
theme = 'light';
27-
}
28-
else {
29-
theme = 'dark';
30-
}
31-
switchTheme(theme, window.innerWidth, window.innerHeight);
32-
await updateTheme(theme);
33-
});
34-
}
35-
36-
Data.set(id, themeElement);
3718
}
3819

3920
export async function updateTheme(theme) {
@@ -42,11 +23,4 @@ export async function updateTheme(theme) {
4223

4324
export function dispose(id) {
4425
EventHandler.off(document, 'scroll');
45-
46-
const themeElement = Data.get(id);
47-
Data.remove(id);
48-
49-
if (themeElement) {
50-
EventHandler.off(themeElement, 'click');
51-
}
5226
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
@inherits ComponentBase
1+
@inherits WebSiteModuleComponentBase
2+
@attribute [JSModuleAutoLoader("Components/ThemeMode.razor.js")]
23

3-
<div class="btn btn-circle btn-fade btn-theme-mode icon-theme d-flex">
4+
<div id="@Id" class="btn btn-circle btn-fade btn-theme-mode icon-theme d-flex">
45
<i class="@GetLightIconClassString"></i>
56
<i class="@GetDarkIconClassString"></i>
67
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { getTheme, switchTheme } from "../../../BootstrapBlazor/modules/utility.js"
2+
import EventHandler from "../../../BootstrapBlazor/modules/event-handler.js"
3+
4+
export function init(id) {
5+
const el = document.getElementById(id);
6+
if (el) {
7+
EventHandler.on(el, 'click', e => {
8+
let theme = getTheme();
9+
if (theme === 'dark') {
10+
theme = 'light';
11+
}
12+
else {
13+
theme = 'dark';
14+
}
15+
switchTheme(theme, window.innerWidth, window.innerHeight);
16+
});
17+
}
18+
}
19+
20+
export function dispose(id) {
21+
const el = document.getElementById(id);
22+
23+
if (el) {
24+
EventHandler.off(el, 'click');
25+
}
26+
}

0 commit comments

Comments
 (0)