1 function createTask(description: string) {
2 const task = document.createElement("div");
3 task.appendChild(document.createTextNode(description));
4 task.setAttribute("tabindex", "0");
8 function addTask(description: string) {
9 document.body.appendChild(createTask(description));
12 function moveCursor(offset: number) {
13 var active = document.activeElement;
14 if (offset === 1 && active) {
15 active = active.nextElementSibling;
17 if (offset === -1 && active) {
18 active = active.previousElementSibling;
20 if (active && active instanceof HTMLElement) active.focus();
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);
30 function browserCreateTask(form: any) {
31 addTask(form.taskName.value);
32 form.taskName.value = "";
36 function browserInit() {
37 document.body.addEventListener("keydown", handleKey, { capture: false });