From 13c97b9931434fe043c29c296792121cdf91e807 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Tue, 25 Jan 2022 14:20:22 -0800 Subject: [PATCH] Call some things "Model", to distinguish them from "Log" --- vopamoi.ts | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/vopamoi.ts b/vopamoi.ts index a0b2cfb..1961dd9 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -1,34 +1,36 @@ -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)); + }, -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); } } function browserCreateTask(form: any) { - addTask(form.taskName.value); + Model.addTask(form.taskName.value); form.taskName.value = ""; return false; } -- 2.44.1