summaryrefslogtreecommitdiff
path: root/src/Util
diff options
context:
space:
mode:
Diffstat (limited to 'src/Util')
-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;