Convert miscellaneous scripts to TypeScript

This commit is contained in:
Luna D 2024-06-08 11:53:44 -04:00 committed by Liam
parent 85ab98c085
commit 0bdbc2899e
6 changed files with 12 additions and 15 deletions

View file

@ -4,11 +4,11 @@
* Warn users that their PM will be reviewed.
*/
import { $ } from './utils/dom';
import { $, hideEl, showEl } from './utils/dom';
function warnAboutPMs() {
const textarea = $('.js-toolbar-input');
const warning = $('.js-hidden-warning');
export function warnAboutPMs() {
const textarea = $<HTMLTextAreaElement>('.js-toolbar-input');
const warning = $<HTMLDivElement>('.js-hidden-warning');
const imageEmbedRegex = /!+\[/g;
if (!warning || !textarea) return;
@ -17,12 +17,10 @@ function warnAboutPMs() {
const value = textarea.value;
if (value.match(imageEmbedRegex)) {
warning.classList.remove('hidden');
showEl(warning);
}
else if (!warning.classList.contains('hidden')) {
warning.classList.add('hidden');
hideEl(warning);
}
});
}
export { warnAboutPMs };

View file

@ -1,6 +1,6 @@
import { inputDuplicatorCreator } from './input-duplicator';
function pollOptionCreator() {
export function pollOptionCreator() {
inputDuplicatorCreator({
addButtonSelector: '.js-poll-add-option',
fieldSelector: '.js-poll-option',
@ -8,5 +8,3 @@ function pollOptionCreator() {
removeButtonSelector: '.js-option-remove',
});
}
export { pollOptionCreator };

View file

@ -2,6 +2,7 @@
* Settings.
*/
import { assertNotNull, assertNotUndefined } from './utils/assert';
import { $, $$ } from './utils/dom';
import store from './utils/store';
@ -9,9 +10,9 @@ export function setupSettings() {
if (!$('#js-setting-table')) return;
const localCheckboxes = $$('[data-tab="local"] input[type="checkbox"]');
const themeSelect = $('#user_theme');
const styleSheet = $('head link[rel="stylesheet"]');
const localCheckboxes = $$<HTMLInputElement>('[data-tab="local"] input[type="checkbox"]');
const themeSelect = assertNotNull($<HTMLSelectElement>('#user_theme'));
const styleSheet = assertNotNull($<HTMLLinkElement>('head link[rel="stylesheet"]'));
// Local settings
localCheckboxes.forEach(checkbox => {
@ -22,7 +23,7 @@ export function setupSettings() {
// Theme preview
themeSelect && themeSelect.addEventListener('change', () => {
styleSheet.href = themeSelect.options[themeSelect.selectedIndex].dataset.themePath;
styleSheet.href = assertNotUndefined(themeSelect.options[themeSelect.selectedIndex].dataset.themePath);
});
}