3 var joey = this.joey = function joey(elementDef, parentNode) {
4 return createNode( elementDef, parentNode, parentNode ? parentNode.ownerDocument : this.document );
7 var shortcuts = joey.shortcuts = {
8 "text" : "textContent",
12 var plugins = joey.plugins = [
13 function( obj, context ) {
14 if( typeof obj === 'string' ) {
15 return context.createTextNode( obj );
18 function( obj, context ) {
20 var el = context.createElement( obj.tag );
21 for( var attr in obj ) {
22 addAttr( el, attr, obj[ attr ], context );
29 function addAttr( el, attr, value, context ) {
30 attr = shortcuts[attr] || attr;
31 if( attr === 'children' ) {
32 for( var i = 0; i < value.length; i++) {
33 createNode( value[i], el, context );
35 } else if( attr === 'style' || attr === 'dataset' ) {
36 for( var prop in value ) {
37 el[ attr ][ prop ] = value[ prop ];
39 } else if( attr.indexOf("on") === 0 ) {
40 el.addEventListener( attr.substr(2), value, false );
41 } else if( value !== undefined ) {
46 function createNode( obj, parent, context ) {
49 plugins.some( function( plug ) {
50 return ( el = plug( obj, context ) );
52 parent && parent.appendChild( el );