X-Git-Url: http://git.scottworley.com/vopamoi/blobdiff_plain/28568279f452686693f5e92182ce83651afbc174..262705dd315ec4bf7088cc3ec9013dc32f3e3bd3:/vopamoi.ts diff --git a/vopamoi.ts b/vopamoi.ts index 5967c7d..505781d 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -1,23 +1,52 @@ -var tasks: string[] = []; +const Model = { + createTask: function (description: string) { + const task = document.createElement("div"); + task.appendChild(document.createTextNode(description)); + task.setAttribute("tabindex", "0"); + return task; + }, -function createViewTask(task: string) { - const viewTask = document.createElement("div"); - viewTask.appendChild(document.createTextNode(task)); - viewTask.setAttribute("tabindex", "0"); - return viewTask; -} + addTask: function (description: string) { + document.body.appendChild(this.createTask(description)).focus(); + }, -function updateView() { - tasks.forEach((t) => document.getElementById(t) || document.body.appendChild(createViewTask(t))); -} + 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(); + }, +}; + +const Log = { + addTask: function (description: string) { + Model.addTask(description); + }, +}; -function addTask(task: string) { - tasks.push(task); - updateView(); +function handleKey(event: any) { + if (event.target.tagName !== "INPUT") { + if (event.key == "j") Model.moveCursor(1); + if (event.key == "k") Model.moveCursor(-1); + if (event.key == "c") { + document.getElementById("taskName")!.focus(); + event.preventDefault(); + } + } } function browserCreateTask(form: any) { - addTask(form.taskName.value); + if (form.taskName.value) { + Log.addTask(form.taskName.value); + } form.taskName.value = ""; return false; } + +function browserInit() { + document.body.addEventListener("keydown", handleKey, { capture: false }); +}