mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
/**
|
|
* Settings.
|
|
*/
|
|
|
|
import { assertNotNull, assertNotUndefined } from './utils/assert';
|
|
import { $, $$ } from './utils/dom';
|
|
import store from './utils/store';
|
|
|
|
export function setupSettings() {
|
|
|
|
if (!$('#js-setting-table')) return;
|
|
|
|
const localCheckboxes = $$<HTMLInputElement>('[data-tab="local"] input[type="checkbox"]');
|
|
const themeSelect = assertNotNull($<HTMLSelectElement>('#user_theme_name'));
|
|
const themeColorSelect = assertNotNull($<HTMLSelectElement>('#user_theme_color'));
|
|
const styleSheet = assertNotNull($<HTMLLinkElement>('#js-theme-stylesheet'));
|
|
|
|
// Local settings
|
|
localCheckboxes.forEach(checkbox => {
|
|
checkbox.addEventListener('change', () => {
|
|
store.set(checkbox.id.replace('user_', ''), checkbox.checked);
|
|
});
|
|
});
|
|
|
|
// Theme preview
|
|
const themePreviewCallback = () => {
|
|
const themeName = assertNotUndefined(themeSelect.options[themeSelect.selectedIndex].value);
|
|
const themeColor = assertNotUndefined(themeColorSelect.options[themeColorSelect.selectedIndex].value);
|
|
|
|
styleSheet.href = `/css/${themeName}-${themeColor}.css`;
|
|
};
|
|
|
|
themeSelect.addEventListener('change', themePreviewCallback);
|
|
themeColorSelect.addEventListener('change', themePreviewCallback);
|
|
}
|