Skip to content

Instantly share code, notes, and snippets.

@shergin
Created July 22, 2010 06:52
Show Gist options
  • Save shergin/485668 to your computer and use it in GitHub Desktop.
Save shergin/485668 to your computer and use it in GitHub Desktop.
function create(x) {
// {node, name, child, attribute, property, event, link (node, ), service, append}
if (x instanceof Widget)
x = x.main();
if (x.nodeType)
return x;
var node = null;
if (x.node) {
node = x.node;
y5.Dom.clearNode(node);
}
else
node = document.createElement(x.tag ? x.tag : 'div');
if (x.name)
node.className = x.name;
// text
var a = x.text || x.content;
if (a) {
a = document.createTextNode(a);
node.appendChild(a);
}
a = x.html;
if (a) {
node.innerHTML = a;
}
a = x.child;
if (a) {
if (!(a instanceof Array))
a = [a];
for(var i = 0; i < a.length; i++)
if (a[i])
node.appendChild(Utils.create(a[i]));
}
a = x.attribute;
if (a)
for (var i in a)
if (a[i] == null)
node.removeAttribute(i);
else
node.setAttribute(i, a[i]);
a = x.style;
if (a)
for (var i in a)
node.style[i] = a[i] || '';
a = x.property;
if (a)
for (var i in a)
node[i] = a[i];
// event
a = x.event;
if (a) {
if (!(a instanceof Array))
a = [a];
for (var i = a.length; i --;)
y5.on(a[i].name || a[i].type, a[i].listener, node, a[i].context);
}
// reference
if (a = x.reference) {
if (!(a instanceof Array))
a = [a];
for (var i = a.length; i --;)
for (var name in a[i])
a[i][name][name] = node;
}
// link
if (x.link)
x.link.hash[x.link.name] = node;
// service
if (x.service) {
if (x.service instanceof Function)
x.service(node);
else
Widget.service(node);
}
// append
if (x.append)
x.append.appendChild(node);
return node;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment