-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.js
32 lines (29 loc) · 802 Bytes
/
create.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
var create = (function() {
var builderProto = {
append: function(childBuilder) {
this.element.appendChild(childBuilder.element);
return this;
},
addEventListener: function(event, fn) {
this.element.addEventListener(event, fn, true);
return this;
},
build: function() {
return this.element;
}
};
return function(tagName, attributes) {
var builder = Object.create( builderProto );
if (tagName === 'fragment') {
builder.element = document.createDocumentFragment();
} else {
builder.element = document.createElement( tagName );
for( key in attributes ) {
if( attributes.hasOwnProperty( key ) ) {
builder.element[ key ] = attributes[ key ];
}
}
}
return builder;
};
}());