-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhecomes.js
29 lines (29 loc) · 996 Bytes
/
hecomes.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
function Register(elementName, elementTag, elementPrototype, elementTemplate) {
var protoDef = {};
for(func in elementPrototype) {
if(elementPrototype.hasOwnProperty(func)) {
protoDef[func] = {
enumerable: true,
value: elementPrototype[func]
};
}
}
var protoObj = Object.create(HTMLElement.prototype, protoDef);
window[elementName] = document.registerElement(elementTag, {
prototype: protoObj
});
Object.defineProperty(protoObj, 'template', {
get: function() {
var fragment = document.createDocumentFragment();
var div = fragment.appendChild(document.createElement('div'));
div.innerHTML = elementTemplate;
while(child = div.firstChild) {
fragment.insertBefore(child,div);
}
fragment.removeChild(div);
return {
content: fragment
};
}
});
}