summaryrefslogtreecommitdiff
path: root/src/Util/DomUtil.js
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2022-06-02 00:53:26 -0500
committersanine <sanine.not@pm.me>2022-06-02 00:53:26 -0500
commite69dfc1b29f2fed1d1fd26dbeb9b248b1377c64c (patch)
tree44c6c389646d6e65f43930a97ac65acbaf0f7e52 /src/Util/DomUtil.js
parentf82f540a0cf07e8fd95e36dea10a49aa839832d0 (diff)
add basic layer ui
Diffstat (limited to 'src/Util/DomUtil.js')
-rw-r--r--src/Util/DomUtil.js36
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;