77 lines
2.3 KiB
JavaScript
77 lines
2.3 KiB
JavaScript
(function () {
|
|
var storageKey = 'lte-theme';
|
|
var theme = 'auto';
|
|
var ckeditorThemeStyleId = 'ckeditor-dark-theme-overrides';
|
|
|
|
function getPreferredTheme() {
|
|
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
return 'dark';
|
|
}
|
|
|
|
return 'light';
|
|
}
|
|
|
|
function getOrCreateCkeditorThemeStyleElement() {
|
|
var styleElement = document.getElementById(ckeditorThemeStyleId);
|
|
|
|
if (styleElement) {
|
|
return styleElement;
|
|
}
|
|
|
|
styleElement = document.createElement('style');
|
|
styleElement.id = ckeditorThemeStyleId;
|
|
document.head.appendChild(styleElement);
|
|
|
|
return styleElement;
|
|
}
|
|
|
|
function syncCkeditorTheme(currentTheme) {
|
|
var styleElement = getOrCreateCkeditorThemeStyleElement();
|
|
|
|
if (currentTheme !== 'dark') {
|
|
styleElement.textContent = '';
|
|
return;
|
|
}
|
|
|
|
styleElement.textContent = [
|
|
'.ck.ck-dropdown__panel,',
|
|
'.ck.ck-list__panel,',
|
|
'.ck.ck-list,',
|
|
'.ck.ck-balloon-panel {',
|
|
' background: var(--bs-body-bg) !important;',
|
|
' background-color: var(--bs-body-bg) !important;',
|
|
' border-color: var(--bs-border-color) !important;',
|
|
' color: var(--bs-body-color) !important;',
|
|
'}',
|
|
'.ck.ck-list .ck-list-item-button {',
|
|
' background: transparent !important;',
|
|
' background-color: transparent !important;',
|
|
' color: var(--bs-body-color) !important;',
|
|
'}',
|
|
'.ck.ck-list .ck-list-item-button:hover {',
|
|
' background: var(--bs-secondary-bg) !important;',
|
|
' background-color: var(--bs-secondary-bg) !important;',
|
|
'}',
|
|
'.ck.ck-color-grid,',
|
|
'.ck.ck-color-grid__tile {',
|
|
' color: var(--bs-body-color) !important;',
|
|
'}',
|
|
'.ck.ck-color-grid__tile {',
|
|
' border-color: var(--bs-border-color) !important;',
|
|
'}'
|
|
].join('\n');
|
|
}
|
|
|
|
try {
|
|
var storedTheme = window.localStorage.getItem(storageKey);
|
|
if (storedTheme === 'dark' || storedTheme === 'light' || storedTheme === 'auto') {
|
|
theme = storedTheme;
|
|
}
|
|
} catch (error) {
|
|
theme = 'auto';
|
|
}
|
|
|
|
document.documentElement.dataset.bsTheme = theme;
|
|
document.documentElement.style.colorScheme = theme;
|
|
syncCkeditorTheme(theme === 'auto' ? getPreferredTheme() : theme);
|
|
}()); |