X-Git-Url: http://git.scottworley.com/vopamoi/blobdiff_plain/974848d36d6c4f1b171bd990f3d5659cb0e8134d..f69ff5261a6e77cfba0daf8eb4c164d0c57c2602:/vopamoi.ts diff --git a/vopamoi.ts b/vopamoi.ts index cb2d50e..2567e85 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -1,11 +1,40 @@ -var tasks = []; +const Model = { + createTask: function (description: string) { + const task = document.createElement("div"); + task.appendChild(document.createTextNode(description)); + task.setAttribute("tabindex", "0"); + return task; + }, -function addTask(task: string) { - tasks.push(task); + addTask: function (description: string) { + document.body.appendChild(this.createTask(description)).focus(); + }, + + moveCursor: function (offset: number) { + var active = document.activeElement; + if (offset === 1 && active) { + active = active.nextElementSibling; + } + if (offset === -1 && active) { + active = active.previousElementSibling; + } + if (active && active instanceof HTMLElement) active.focus(); + }, +}; + +function handleKey(event: any) { + if (event.target.tagName !== "INPUT") { + if (event.key == "j") Model.moveCursor(1); + if (event.key == "k") Model.moveCursor(-1); + } } function browserCreateTask(form: any) { - addTask(form.taskName.value); + Model.addTask(form.taskName.value); form.taskName.value = ""; return false; } + +function browserInit() { + document.body.addEventListener("keydown", handleKey, { capture: false }); +}