Improve announcement rendering and theme assets
This commit is contained in:
@@ -2,25 +2,26 @@
|
||||
|
||||
(function () {
|
||||
var storageKey = 'lte-theme';
|
||||
var theme = 'dark';
|
||||
|
||||
function getPreferredTheme() {
|
||||
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
return 'dark';
|
||||
}
|
||||
|
||||
return 'light';
|
||||
}
|
||||
var root = document.documentElement;
|
||||
var authoredTheme = root.getAttribute('data-bs-theme');
|
||||
var theme = authoredTheme === 'light' || authoredTheme === 'dark' ? authoredTheme : 'dark';
|
||||
var storedTheme = null;
|
||||
|
||||
try {
|
||||
var storedTheme = window.localStorage.getItem(storageKey);
|
||||
if (storedTheme === 'dark' || storedTheme === 'light' || storedTheme === 'auto') {
|
||||
theme = storedTheme === 'auto' ? getPreferredTheme() : storedTheme;
|
||||
}
|
||||
storedTheme = window.localStorage.getItem(storageKey);
|
||||
} catch (error) {
|
||||
theme = 'dark';
|
||||
storedTheme = null;
|
||||
}
|
||||
|
||||
document.documentElement.dataset.bsTheme = theme;
|
||||
document.documentElement.style.colorScheme = theme;
|
||||
if (storedTheme === 'light' || storedTheme === 'dark') {
|
||||
theme = storedTheme;
|
||||
} else if (storedTheme === 'auto' || (authoredTheme !== 'light' && authoredTheme !== 'dark')) {
|
||||
theme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||
}
|
||||
|
||||
root.setAttribute('data-bs-theme', theme);
|
||||
root.style.colorScheme = theme;
|
||||
if (theme !== authoredTheme) {
|
||||
root.setAttribute('data-lte-theme-resolved', '');
|
||||
}
|
||||
}());
|
||||
Reference in New Issue
Block a user