diff options
author | sanine <sanine.not@pm.me> | 2022-06-02 00:53:26 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2022-06-02 00:53:26 -0500 |
commit | e69dfc1b29f2fed1d1fd26dbeb9b248b1377c64c (patch) | |
tree | 44c6c389646d6e65f43930a97ac65acbaf0f7e52 /src/Util/DomUtil.js | |
parent | f82f540a0cf07e8fd95e36dea10a49aa839832d0 (diff) |
add basic layer ui
Diffstat (limited to 'src/Util/DomUtil.js')
-rw-r--r-- | src/Util/DomUtil.js | 36 |
1 files changed, 36 insertions, 0 deletions
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; |