www.spaceplanner.app

Web client to the spaceplanner API
git clone git://jacobedwards.org/www.spaceplanner.app
Log | Files | Refs

commit 9b5d4e4d006fb6f80d132f7c06f40db11fcb57ca
parent ce6e37d92bafde9abbc3f1f97141152e55a8df86
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Thu,  8 Aug 2024 18:14:43 -0700

Make create_input a function of ui, and utilize it in button() too

Diffstat:
Mfiles/floorplans/main.js | 4++--
Mfiles/lib/etc.js | 20--------------------
Mfiles/lib/ui.js | 29++++++++++++++++++++++-------
3 files changed, 24 insertions(+), 29 deletions(-)

diff --git a/files/floorplans/main.js b/files/floorplans/main.js @@ -139,11 +139,11 @@ function editable_floorplan_func(element, data) { let c = floorplan_info_class(editables[i]) let e = parent.querySelector("." + c) // .getElementsByClassName() if (e) { - input = etc.create_input(editables[i], { value: e.textContent }) + input = ui.input(editables[i], { value: e.textContent }) input.setAttribute("class", c) e.replaceWith(input) } else { - input = etc.create_input(editables[i]) + input = ui.input(editables[i]) input.setAttribute("class", c) if (prev) { prev.after(input) diff --git a/files/lib/etc.js b/files/lib/etc.js @@ -91,23 +91,3 @@ export function require_id(id) { } return e } - -export function create_input(name, options) { - if (!name) { - throw new Error("No name provided") - } - if (!options) { - options = {} - } - - let input = document.createElement("input") - input.name = name - input.placeholder = name - if (options["type"]) { - input.type = options["type"] - } - if (options["value"]) { - input.value = options["value"] - } - return input -} diff --git a/files/lib/ui.js b/files/lib/ui.js @@ -1,13 +1,28 @@ -export function button(name, memo, icon, func) { - let button = document.createElement("input") - button.alt = name - button.type = "image" - button.src = "/icons/" + icon + "-outline.svg" +export function input(name, memo, attributes) { + if (!name) { + throw new Error("No name provided") + } + + let input = document.createElement("input") + input.name = name + input.placeholder = name + for (let i in attributes) { + input.setAttribute(i, attributes[i]) + } + return input +} + +export function button(name, memo, icon, func, options) { + let button = input(name, memo, { + alt: name, + title: memo, + type: "image", + class: "icon", + src: "/icons/" + icon + "-outline.svg" + }) if (func) { button.addEventListener("click", func, false) } - button.setAttribute("title", memo) - button.setAttribute("class", "icon") return button }