cyp/app/js/lib/html.js

30 lines
702 B
JavaScript
Raw Normal View History

2019-03-22 22:35:04 +08:00
export function node(name, attrs, content, parent) {
let n = document.createElement(name);
Object.assign(n, attrs);
if (attrs && attrs.title) { n.setAttribute("aria-label", attrs.title); }
content && text(content, n);
parent && parent.appendChild(n);
return n;
}
export function button(attrs, content, parent) {
return node("button", attrs, content, parent);
}
export function clear(node) {
while (node.firstChild) { node.firstChild.parentNode.removeChild(node.firstChild); }
return node;
}
export function text(txt, parent) {
let n = document.createTextNode(txt);
parent && parent.appendChild(n);
return n;
}
export function fragment() {
return document.createDocumentFragment();
}