-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js.mjs
executable file
·123 lines (107 loc) · 2.68 KB
/
index.js.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import bar from '_/bar';
import column from '_/column';
import dialog from '_/dialog';
import field from '_/field';
import file from '_/file';
import link from '_/link';
import menu from '_/menu';
import page from '_/page';
import row from '_/row';
import stack from '_/stack';
import tab from '_/tab';
import task from '_/task';
import {
B,
D,
R,
W,
getElement,
getFormElement,
getParent,
hasClass
} from '@taufik-nurrohman/document';
import {
fireEvent,
offEventDefault,
onEvent
} from '@taufik-nurrohman/event';
import {
hook
} from '@taufik-nurrohman/hook';
import {
isFunction
} from '@taufik-nurrohman/is';
import K from '@taufik-nurrohman/key';
import {
toValue
} from '@taufik-nurrohman/to';
let map = new K(W);
onEvent('blur', W, e => map.pull());
onEvent('keydown', W, e => {
map.push(e.key);
let command = map.test();
if (command) {
let value = map.fire(command);
if (false === value) {
offEventDefault(e);
} else if (null === value) {
console.error('Unknown command:', command);
}
}
});
onEvent('keyup', W, e => map.pull(e.key));
const _ = {
commands: map.commands,
keys: map.keys
};
const {fire, hooks, off, on} = hook(_);
W.K = K;
W._ = _;
onEvent('beforeload', D, () => fire('let'));
onEvent('load', D, () => fire('get'));
onEvent('DOMContentLoaded', D, () => fire('set'));
onEvent('keydown', W, function(e) {
if (e.defaultPrevented) {
return;
}
let t = this,
target = e.target,
key = e.key,
keyIsAlt = e.altKey,
keyIsCtrl = e.ctrlKey,
keyIsShift = e.shiftKey,
firstBarFocusable = getElement('.lot\\:bar a:any-link'),
mainSearchForm = getFormElement('get'),
mainSearchFormInput = mainSearchForm && mainSearchForm.q,
parent, stop;
if (mainSearchFormInput && 'F3' === key && !keyIsAlt && !keyIsCtrl && !keyIsShift) {
mainSearchFormInput.focus();
stop = true;
} else if (firstBarFocusable && 'F10' === key && !keyIsAlt && !keyIsCtrl && !keyIsShift) {
firstBarFocusable.focus();
if (parent = getParent(firstBarFocusable)) {
if (hasClass(parent, 'has:menu')) {
firstBarFocusable.click();
}
}
stop = true;
} else if (B !== target && R !== target && W !== target) {
if ('Escape' === key && (parent = getParent(getParent(target), '[tabindex]:not(.not\\:active)'))) {
parent.focus();
stop = true;
}
}
stop && offEventDefault(e);
});
bar(1);
column(1);
dialog(1);
field(1);
file(1);
link(1);
menu(1);
page(1);
row(1);
stack(1);
tab(1);
task(1);