#48 Added types to helper

This commit is contained in:
Serraniel 2020-12-28 22:27:38 +01:00
parent ec87c72542
commit 2059a5d427
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3

View file

@ -1,16 +1,16 @@
export var isShiftPressed = false;
export var isCtrlPressed = false;
export var isShiftPressed: boolean = false;
export var isCtrlPressed: boolean = false;
export function isHtmlElement(object) {
export function isHtmlElement(object: any) {
return object instanceof HTMLElement;
}
export function initHelpers() {
export function initHelpers(): void {
document.addEventListener('keydown', event => handleKeyDown(event));
document.addEventListener('keyup', event => handleKeyUp(event));
}
export function onReady(fn) {
export function onReady(fn: () => void) {
if (document.readyState != 'loading') {
fn();
} else {
@ -18,19 +18,19 @@ export function onReady(fn) {
}
}
export function assigned(obj) {
export function assigned(obj: any): boolean {
return !(typeof obj === 'undefined' || obj === null);
}
function handleKeyDown(event) {
function handleKeyDown(event: KeyboardEvent) {
handleKeyToggle(event, true);
}
function handleKeyUp(event) {
function handleKeyUp(event: KeyboardEvent) {
handleKeyToggle(event, false);
}
function handleKeyToggle(event, isPressed) {
function handleKeyToggle(event: KeyboardEvent, isPressed: boolean) {
if (event.key === 'Shift') {
isShiftPressed = isPressed;
} else if (event.key === 'Control') {