Passed
Push — develop ( 1f9243...cb7e29 )
by Daniel
54s queued 11s
created

helpers.js ➔ assigned   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
1
export var isShiftPressed = false;
2
export var isCtrlPressed = false;
3
4
export function isHtmlElement(object) {
5
    return object instanceof HTMLElement;
0 ignored issues
show
Bug introduced by
The variable HTMLElement seems to be never declared. If this is a global, consider adding a /** global: HTMLElement */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
6
}
7
8
export function initHelpers() {
9
    document.addEventListener('keydown', event => handleKeyDown(event));
10
    document.addEventListener('keyup', event => handleKeyUp(event));
11
}
12
13
export function onReady(fn) {
14
    if (document.readyState != 'loading') {
15
        fn();
16
    } else {
17
        document.addEventListener('DOMContentLoaded', fn);
18
    }
19
}
20
21
export function assigned(obj) {
22
    return !(typeof obj === 'undefined' || obj === null);
23
}
24
25
function handleKeyDown(event) {
26
    handleKeyToggle(event, true);
27
}
28
29
function handleKeyUp(event) {
30
    handleKeyToggle(event, false);
31
}
32
33
function handleKeyToggle(event, isPressed) {
34
    if (event.key === 'Shift') {
35
        isShiftPressed = isPressed;
36
    } else if (event.key === 'Control') {
37
        isCtrlPressed = isPressed;
38
    }
39
}