MCPcopy Create free account
hub / github.com/arfct/itty-bitty / el

Function el

docs/bitty.js:577–608  ·  view source on GitHub ↗
(selector, ...args)

Source from the content-addressed store, hash-verified

575// }
576
577const el = (selector, ...args) => {
578 var attrs = (args[0] && typeof args[0] === 'object' && !Array.isArray(args[0]) && !(args[0] instanceof HTMLElement)) ? args.shift() : {};
579
580 let classes = selector.split(".");
581 if (classes.length > 0) selector = classes.shift();
582 if (classes.length) attrs.className = classes.join(" ")
583
584 let id = selector.split("#");
585 if (id.length > 0) selector = id.shift();
586 if (id.length) attrs.id = id[0];
587
588 var node = document.createElement(selector.length > 0 ? selector : "div");
589 for (let prop in attrs) {
590 if (attrs.hasOwnProperty(prop) && attrs[prop] != undefined) {
591 if (prop.indexOf("data-") == 0) {
592 let dataProp = prop.substring(5).replace(/-([a-z])/g, function(g) { return g[1].toUpperCase(); });
593 node.dataset[dataProp] = attrs[prop];
594 } else {
595 node[prop] = attrs[prop];
596 }
597 }
598 }
599
600 const append = (child) => {
601 if (Array.isArray(child)) return child.forEach(append);
602 if (typeof child == "string") child = document.createTextNode(child);
603 if (child) node.appendChild(child);
604 };
605 args.forEach(append);
606
607 return node;
608};
609
610export {
611 DataURL,

Callers 5

showErrorFunction · 0.70
renderContentFunction · 0.70
renderMethod · 0.70
makeQRMethod · 0.70
showMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected