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