X-Git-Url: http://git.scottworley.com/vopamoi/blobdiff_plain/f1afad9b15dd2e672dc83bf6469532683f9c33ed..75a42da4667eceebea699c52d85fa4b7c3e6a0bc:/vopamoi.ts?ds=inline diff --git a/vopamoi.ts b/vopamoi.ts index a0b2cfb..8db2865 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -1,34 +1,40 @@ -function createTask(description: string) { - const task = document.createElement("div"); - task.appendChild(document.createTextNode(description)); - task.setAttribute("tabindex", "0"); - return task; -} +const Model = { + createTask: function (description: string) { + const task = document.createElement("div"); + task.appendChild(document.createTextNode(description)); + task.setAttribute("tabindex", "0"); + return task; + }, -function addTask(description: string) { - document.body.appendChild(createTask(description)); -} + addTask: function (description: string) { + document.body.appendChild(this.createTask(description)).focus(); + }, -function moveCursor(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(); -} + 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") moveCursor(1); - if (event.key == "k") moveCursor(-1); + 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); + Model.addTask(form.taskName.value); form.taskName.value = ""; return false; }