Skip to content

Commit 751b9a5

Browse files
committed
refactor: 删除 getPreferredTheme 方法
1 parent dbbd390 commit 751b9a5

File tree

4 files changed

+7
-17
lines changed

4 files changed

+7
-17
lines changed

src/BootstrapBlazor.Server/Components/Components/Pre.razor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { copy, getDescribedElement, addLink, removeLink, addScript, getHeight, getPreferredTheme, registerBootstrapBlazorModule } from "../../_content/BootstrapBlazor/modules/utility.js"
1+
import { copy, getDescribedElement, addLink, removeLink, addScript, getHeight, getTheme, registerBootstrapBlazorModule } from "../../_content/BootstrapBlazor/modules/utility.js"
22
import EventHandler from "../../_content/BootstrapBlazor/modules/event-handler.js"
33

44
export async function init(id, title, assetRoot) {
@@ -9,7 +9,7 @@ export async function init(id, title, assetRoot) {
99

1010
await addScript(`${assetRoot}lib/highlight/highlight.min.js`)
1111
await addScript(`${assetRoot}lib/highlight/cshtml-razor.min.js`)
12-
await switchTheme(getPreferredTheme(), assetRoot);
12+
await switchTheme(getTheme(), assetRoot);
1313

1414
const preElement = el.querySelector('pre')
1515
const code = el.querySelector('pre > code')
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { getPreferredTheme, setTheme } from "../../_content/BootstrapBlazor/modules/utility.js"
1+
import { getTheme, setTheme } from "../../_content/BootstrapBlazor/modules/utility.js"
22

33
export function initTheme() {
4-
const currentTheme = getPreferredTheme();
4+
const currentTheme = getTheme();
55
setTheme(currentTheme, false);
66
}

src/BootstrapBlazor/Components/ThemeProvider/ThemeProvider.razor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getPreferredTheme, setTheme, switchTheme, calcCenterPosition } from "../../modules/utility.js"
1+
import { getTheme, setTheme, switchTheme, calcCenterPosition } from "../../modules/utility.js"
22
import EventHandler from "../../modules/event-handler.js"
33
import Data from "../../modules/data.js"
44

@@ -17,7 +17,7 @@ export function init(id, invoke, themeValue, callback) {
1717

1818
let currentTheme = themeValue;
1919
if (currentTheme === 'useLocalStorage') {
20-
currentTheme = getPreferredTheme();
20+
currentTheme = getTheme();
2121
}
2222
setTheme(currentTheme, true);
2323
theme.currentTheme = currentTheme;

src/BootstrapBlazor/wwwroot/modules/utility.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -716,18 +716,8 @@ export function getHtml(options) {
716716
return html;
717717
}
718718

719-
720-
export function getPreferredTheme() {
721-
const storedTheme = getTheme()
722-
if (storedTheme) {
723-
return storedTheme
724-
}
725-
726-
return getAutoThemeValue();
727-
}
728-
729719
export function getTheme() {
730-
return localStorage.getItem('theme') || document.documentElement.getAttribute('data-bs-theme') || 'light';
720+
return localStorage.getItem('theme') || document.documentElement.getAttribute('data-bs-theme') || getAutoThemeValue();
731721
}
732722

733723
export function saveTheme(theme) {

0 commit comments

Comments
 (0)