From e69dfc1b29f2fed1d1fd26dbeb9b248b1377c64c Mon Sep 17 00:00:00 2001 From: sanine Date: Thu, 2 Jun 2022 00:53:26 -0500 Subject: add basic layer ui --- src/Util/DomUtil.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/Util/DomUtil.js (limited to 'src/Util') diff --git a/src/Util/DomUtil.js b/src/Util/DomUtil.js new file mode 100644 index 0000000..5349365 --- /dev/null +++ b/src/Util/DomUtil.js @@ -0,0 +1,36 @@ +function h(tagName, text, attributes, children) { + /* allow for not adding text */ + if (children === undefined && typeof(text) === 'object') { + children = attributes; + attributes = text; + text = null; + } + + /* allow for not adding attributes */ + if (children === undefined && Array.isArray(attributes)) { + children = attributes; + attributes = {}; + } + + /* allow for not adding children */ + if (children === undefined) { + children = []; + } + + const element = document.createElement(tagName); + if (text) + element.appendChild(document.createTextNode(text)); + + for (let key in attributes) { + const value = attributes[key]; + element.setAttribute(key, value); + } + + for (let child of children) + element.appendChild(child); + + return element; +} + + +export default h; -- cgit v1.2.1