X-Git-Url: http://git.scottworley.com/vopamoi/blobdiff_plain/e88c099c05a14bc0851cbab622938cdd4e8c6cc9..caa93fd1819b0d57029de637029daf0bc867d17e:/vopamoi.ts?ds=inline diff --git a/vopamoi.ts b/vopamoi.ts index 654a7a8..f127da9 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -14,18 +14,19 @@ function splitN(str: string, delimiter: string, limit: number = MAX_SAFE_INTEGER } const Model = { - createTask: function (description: string) { + createTask: function (timestamp: string, description: string) { const task = document.createElement("div"); task.appendChild(document.createTextNode(description)); task.setAttribute("tabindex", "0"); + task.setAttribute("data-created", timestamp); return task; }, - addTask: function (description: string) { - document.body.appendChild(this.createTask(description)).focus(); + addTask: function (timestamp: string, description: string) { + document.body.appendChild(this.createTask(timestamp, description)).focus(); }, - moveCursor: function (offset: number) { + moveCursor: function (offset: number): boolean { var active = document.activeElement; if (offset === 1 && active) { active = active.nextElementSibling; @@ -33,7 +34,11 @@ const Model = { if (offset === -1 && active) { active = active.previousElementSibling; } - if (active && active instanceof HTMLElement) active.focus(); + if (active && active instanceof HTMLElement) { + active.focus(); + return true; + } + return false; }, }; @@ -43,7 +48,7 @@ const Log = (function () { apply: function (entry: string) { const [timestamp, command, data] = splitN(entry, " ", 2); if (command == "Create") { - Model.addTask(data); + Model.addTask(timestamp, data); } }, @@ -75,23 +80,27 @@ const UI = { }, }; -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(); +const BrowserUI = { + addTask: function (form: any) { + if (form.taskName.value) { + UI.addTask(form.taskName.value); + form.taskName.value = ""; } - } + return false; + }, +}; + +function focusTaskNameInput(event: any) { + document.getElementById("taskName")!.focus(); + event.preventDefault(); } -function browserCreateTask(form: any) { - if (form.taskName.value) { - UI.addTask(form.taskName.value); +function handleKey(event: any) { + if (event.target.tagName !== "INPUT") { + if (event.key == "j") return Model.moveCursor(1); + if (event.key == "k") return Model.moveCursor(-1); + if (event.key == "c") return focusTaskNameInput(event); } - form.taskName.value = ""; - return false; } function browserInit() {