Fixed TS errors my laptop was complaining about.

This commit is contained in:
flash 2019-05-13 16:46:28 +02:00
parent d9836b2267
commit 94a5aefe5d
2 changed files with 21 additions and 14 deletions

View file

@ -1,17 +1,17 @@
function forumPollsInit(): void { function forumPollsInit(): void {
const polls: NodeListOf<HTMLFormElement> = document.getElementsByClassName('js-forum-poll'); const polls: HTMLCollectionOf<Element> = document.getElementsByClassName('js-forum-poll');
if (polls.length < 1) { if (polls.length < 1) {
return; return;
} }
for (let i = 0; i < polls.length; i++) { for (let i = 0; i < polls.length; i++) {
forumPollInit(polls[i]); forumPollInit(polls[i] as HTMLFormElement);
} }
} }
function forumPollInit(poll: HTMLFormElement): void { function forumPollInit(poll: HTMLFormElement): void {
const options: HTMLNodeListOf<HTMLInputElement> = poll.getElementsByClassName('input__checkbox__input'), const options: HTMLCollectionOf<HTMLInputElement> = poll.getElementsByClassName('input__checkbox__input') as HTMLCollectionOf<HTMLInputElement>,
votesRemaining: HTMLDivElement = poll.querySelector('.js-forum-poll-remaining'), votesRemaining: HTMLDivElement = poll.querySelector('.js-forum-poll-remaining'),
votesRemainingCount: HTMLSpanElement = poll.querySelector('.js-forum-poll-remaining-count'), votesRemainingCount: HTMLSpanElement = poll.querySelector('.js-forum-poll-remaining-count'),
votesRemainingPlural: HTMLSpanElement = poll.querySelector('.js-forum-poll-remaining-plural'), votesRemainingPlural: HTMLSpanElement = poll.querySelector('.js-forum-poll-remaining-plural'),
@ -30,9 +30,11 @@ function forumPollInit(poll: HTMLFormElement): void {
} }
options[i].addEventListener('change', ev => { options[i].addEventListener('change', ev => {
if (ev.target.checked) { const elem: HTMLInputElement = ev.target as HTMLInputElement;
if (elem.checked) {
if (votes < 1) { if (votes < 1) {
ev.target.checked = false; elem.checked = false;
ev.preventDefault(); ev.preventDefault();
return; return;
} }
@ -42,13 +44,13 @@ function forumPollInit(poll: HTMLFormElement): void {
votes++; votes++;
} }
votesRemainingCount.textContent = votes; votesRemainingCount.textContent = votes.toString();
votesRemainingPlural.hidden = votes == 1; votesRemainingPlural.hidden = votes == 1;
}); });
} }
votesRemaining.hidden = false; votesRemaining.hidden = false;
votesRemainingCount.textContent = votes; votesRemainingCount.textContent = votes.toString();
votesRemainingPlural.hidden = votes == 1; votesRemainingPlural.hidden = votes == 1;
} }
} }

View file

@ -18,7 +18,7 @@ function forumPostingInit(): void
markupButtons = document.querySelectorAll('.forum__post__action--tag'); markupButtons = document.querySelectorAll('.forum__post__action--tag');
for(let i = 0; i < markupButtons.length; i++) { for(let i = 0; i < markupButtons.length; i++) {
let currentBtn = markupButtons[i]; let currentBtn = markupButtons[i] as HTMLDivElement;
currentBtn.addEventListener('click', (ev) => currentBtn.addEventListener('click', (ev) =>
forumPostingInputMarkup(currentBtn.dataset.tagOpen, currentBtn.dataset.tagClose)); forumPostingInputMarkup(currentBtn.dataset.tagOpen, currentBtn.dataset.tagClose));
} }
@ -153,8 +153,8 @@ function forumPostingPreview(
} }
function forumPostingSwitchButtons(parser: Parser): void { function forumPostingSwitchButtons(parser: Parser): void {
const bbcodeButtons = document.querySelector('.forum__post__actions--bbcode'), const bbcodeButtons = document.querySelector('.forum__post__actions--bbcode') as HTMLElement,
markdownButtons = document.querySelector('.forum__post__actions--markdown'); markdownButtons = document.querySelector('.forum__post__actions--markdown') as HTMLElement;
switch(parser) { switch(parser) {
default: default:
@ -172,12 +172,17 @@ function forumPostingSwitchButtons(parser: Parser): void {
} }
} }
function forumPostingInputMarkup(tagOpen: string, tagClose: string): void { declare interface document {
const editor = document.querySelector('.js-forum-posting-text'); selection: any;
}
if(document.selection) { function forumPostingInputMarkup(tagOpen: string, tagClose: string): void {
const editor: HTMLTextAreaElement = document.querySelector('.js-forum-posting-text'),
doc = document as any;
if(doc.selection) {
editor.focus(); editor.focus();
let selected = document.selection.createRange(); let selected = doc.selection.createRange();
selected.text = tagOpen + selected.text + tagClose; selected.text = tagOpen + selected.text + tagClose;
editor.focus(); editor.focus();
} else if(editor.selectionStart || editor.selectionStart === 0) { } else if(editor.selectionStart || editor.selectionStart === 0) {