Add types to reviewer.ts

This commit is contained in:
Henrik Giesel 2020-12-30 15:06:22 +01:00
parent aaa30a5d49
commit c6c52e06b4

View file

@ -27,7 +27,12 @@ function _queueAction(action: () => Promise<void>): void {
_updatingQueue = _updatingQueue.then(action);
}
async function _updateQA(html, fadeTime, onupdate, onshown): Promise<void> {
async function _updateQA(
html: string,
fadeTime: number,
onupdate: () => void,
onshown: () => void
): Promise<void> {
onUpdateHook = [onupdate];
onShownHook = [onshown];
@ -62,44 +67,48 @@ async function _updateQA(html, fadeTime, onupdate, onshown): Promise<void> {
await _runHook(onShownHook);
}
function _showQuestion(q, bodyclass) {
_queueAction(() => _updateQA(
q,
qFade,
function () {
// return to top of window
window.scrollTo(0, 0);
function _showQuestion(q: string, bodyclass: string): void {
_queueAction(() =>
_updateQA(
q,
qFade,
function () {
// return to top of window
window.scrollTo(0, 0);
document.body.className = bodyclass;
},
function () {
// focus typing area if visible
typeans = document.getElementById("typeans");
if (typeans) {
typeans.focus();
document.body.className = bodyclass;
},
function () {
// focus typing area if visible
typeans = document.getElementById("typeans");
if (typeans) {
typeans.focus();
}
}
}
));
)
);
}
function _showAnswer(a, bodyclass) {
_queueAction(() => _updateQA(
a,
aFade,
function () {
if (bodyclass) {
// when previewing
document.body.className = bodyclass;
}
function _showAnswer(a: string, bodyclass: string): void {
_queueAction(() =>
_updateQA(
a,
aFade,
function () {
if (bodyclass) {
// when previewing
document.body.className = bodyclass;
}
// scroll to answer?
var e = $("#answer");
if (e[0]) {
e[0].scrollIntoView();
}
},
function () {}
));
// scroll to answer?
var e = $("#answer");
if (e[0]) {
e[0].scrollIntoView();
}
},
function () {}
)
);
}
const _flagColours = {
@ -109,7 +118,7 @@ const _flagColours = {
4: "#77aaff",
};
function _drawFlag(flag) {
function _drawFlag(flag: 0 | 1 | 2 | 3): void {
var elem = $("#_flag");
if (flag === 0) {
elem.hide();
@ -119,7 +128,7 @@ function _drawFlag(flag) {
elem.css("color", _flagColours[flag]);
}
function _drawMark(mark) {
function _drawMark(mark: boolean): void {
var elem = $("#_mark");
if (!mark) {
elem.hide();
@ -128,13 +137,13 @@ function _drawMark(mark) {
}
}
function _typeAnsPress() {
function _typeAnsPress(): void {
if ((window.event as KeyboardEvent).keyCode === 13) {
pycmd("ans");
}
}
function _emulateMobile(enabled: boolean) {
function _emulateMobile(enabled: boolean): void {
const list = document.documentElement.classList;
if (enabled) {
list.add("mobile");