2019-10-05 02:09:52 +02:00
|
|
|
/**
|
|
|
|
* Settings.
|
|
|
|
*/
|
|
|
|
|
2024-06-08 17:53:44 +02:00
|
|
|
import { assertNotNull, assertNotUndefined } from './utils/assert';
|
2019-10-05 02:09:52 +02:00
|
|
|
import { $, $$ } from './utils/dom';
|
|
|
|
import store from './utils/store';
|
|
|
|
|
|
|
|
export function setupSettings() {
|
|
|
|
|
|
|
|
if (!$('#js-setting-table')) return;
|
|
|
|
|
2024-06-08 17:53:44 +02:00
|
|
|
const localCheckboxes = $$<HTMLInputElement>('[data-tab="local"] input[type="checkbox"]');
|
2024-07-03 21:32:27 +02:00
|
|
|
const themeSelect = assertNotNull($<HTMLSelectElement>('#user_theme_name'));
|
|
|
|
const themeColorSelect = assertNotNull($<HTMLSelectElement>('#user_theme_color'));
|
|
|
|
const styleSheet = assertNotNull($<HTMLLinkElement>('#js-theme-stylesheet'));
|
2019-10-05 02:09:52 +02:00
|
|
|
|
|
|
|
// Local settings
|
|
|
|
localCheckboxes.forEach(checkbox => {
|
|
|
|
checkbox.addEventListener('change', () => {
|
2020-01-01 17:05:44 +01:00
|
|
|
store.set(checkbox.id.replace('user_', ''), checkbox.checked);
|
2019-10-05 02:09:52 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Theme preview
|
2024-07-03 21:32:27 +02:00
|
|
|
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);
|
2019-10-05 02:09:52 +02:00
|
|
|
}
|