]>
Commit | Line | Data |
---|---|---|
9e79bdbb SW |
1 | function createTask(description: string) { |
2 | const task = document.createElement("div"); | |
3 | task.appendChild(document.createTextNode(description)); | |
4 | task.setAttribute("tabindex", "0"); | |
5 | return task; | |
7dcd9167 | 6 | } |
974848d3 | 7 | |
9e79bdbb SW |
8 | function addTask(description: string) { |
9 | document.body.appendChild(createTask(description)); | |
974848d3 SW |
10 | } |
11 | ||
f1afad9b SW |
12 | function moveCursor(offset: number) { |
13 | var active = document.activeElement; | |
14 | if (offset === 1 && active) { | |
15 | active = active.nextElementSibling; | |
16 | } | |
17 | if (offset === -1 && active) { | |
18 | active = active.previousElementSibling; | |
19 | } | |
20 | if (active && active instanceof HTMLElement) active.focus(); | |
21 | } | |
22 | ||
23 | function handleKey(event: any) { | |
24 | if (event.target.tagName !== "INPUT") { | |
25 | if (event.key == "j") moveCursor(1); | |
26 | if (event.key == "k") moveCursor(-1); | |
27 | } | |
28 | } | |
29 | ||
974848d3 SW |
30 | function browserCreateTask(form: any) { |
31 | addTask(form.taskName.value); | |
32 | form.taskName.value = ""; | |
33 | return false; | |
34 | } | |
f1afad9b SW |
35 | |
36 | function browserInit() { | |
37 | document.body.addEventListener("keydown", handleKey, { capture: false }); | |
38 | } |