-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhtml.js
27 lines (26 loc) · 942 Bytes
/
html.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
define(["jquery.js", "util.js"], function (jquery, util) {
function make_element_factory(tagName) {
return function () {
var attributes = {}, children = [];
switch (arguments.length) {
case 0:
break;
case 1:
if (arguments[0].constructor === Object) {
attributes = arguments[0];
} else {
children = arguments[0];
}
break;
case 2:
attributes = arguments[0];
children = arguments[1];
break;
}
return $(document.createElement(tagName)).attr(attributes).append(children)[0];
};
}
var element_factories = {};
"div span".words().forEach(function (tagName) { element_factories[tagName] = make_element_factory(tagName); });
return element_factories;
});