-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathel.js
32 lines (29 loc) · 961 Bytes
/
el.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.Elm = factory());
}(this, function () { 'use strict';
return function (name, attrs) {
attrs = attrs || {};
var el = document.createElement(name);
for (var attr in attrs) {
if (attrs.hasOwnProperty(attr)) {
el.setAttribute(attr, attrs[attr])
}
}
var appendChildren = function () {
for (var i = 0, iLen = arguments.length ; i < iLen; i++) {
var child = arguments[i];
if (Array.isArray(child)) {
appendChildren.apply(this, child);
} else if (child instanceof Node) {
el.appendChild(child);
} else { // Try to build a text node
el.appendChild(document.createTextNode(child));
}
}
return el
};
return appendChildren
};
}));