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

View file

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