From: Scott Worley Date: Tue, 1 Mar 2022 23:47:39 +0000 (-0800) Subject: Factor insertInPriorityOrder() out of setPriority() X-Git-Url: http://git.scottworley.com/vopamoi/commitdiff_plain/1804fd5af88aa31a9fc2847492480609dc592c77 Factor insertInPriorityOrder() out of setPriority() --- diff --git a/vopamoi.ts b/vopamoi.ts index 6ba608a..bdc8b0d 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -120,6 +120,17 @@ const Model = { } }, + insertInPriorityOrder: function (task: Element, dest: Element) { + const priority = this.getPriority(task); + for (const t of dest.children) { + if (t !== task && this.getPriority(t) < priority) { + dest.insertBefore(task, t); + return; + } + } + dest.appendChild(task); + }, + removeTag: function (createTimestamp: string, tagName: string) { const task = this.getTask(createTimestamp); if (!task) return null; @@ -133,13 +144,7 @@ const Model = { const target = this.getTask(createTimestamp); if (!target) return null; target.setAttribute("data-priority", `${priority}`); - for (const task of document.getElementsByClassName("task")) { - if (task !== target && this.getPriority(task) < priority) { - task.parentElement!.insertBefore(target, task); - return target; - } - } - document.getElementById("tasks")!.appendChild(target); + this.insertInPriorityOrder(target, target.parentElement!); return target; },