philomena/assets/js/settings.ts

31 lines
900 B
TypeScript
Raw Normal View History

2019-10-05 02:09:52 +02:00
/**
* Settings.
*/
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;
const localCheckboxes = $$<HTMLInputElement>('[data-tab="local"] input[type="checkbox"]');
const themeSelect = assertNotNull($<HTMLSelectElement>('#user_theme'));
const styleSheet = assertNotNull($<HTMLLinkElement>('head link[rel="stylesheet"]'));
2019-10-05 02:09:52 +02:00
// Local settings
localCheckboxes.forEach(checkbox => {
checkbox.addEventListener('change', () => {
store.set(checkbox.id.replace('user_', ''), checkbox.checked);
2019-10-05 02:09:52 +02:00
});
});
// Theme preview
2024-06-12 22:56:58 +02:00
if (themeSelect) {
themeSelect.addEventListener('change', () => {
styleSheet.href = assertNotUndefined(themeSelect.options[themeSelect.selectedIndex].dataset.themePath);
});
}
2019-10-05 02:09:52 +02:00
}