Recursive append strategy

This commit is contained in:
斟酌 鵬兄 2016-02-22 07:55:17 +08:00
parent 7af43e256c
commit c274018645
1 changed files with 25 additions and 21 deletions

View File

@ -8,6 +8,27 @@
/* @type {Dandelion.IDOMElement}*/ /* @type {Dandelion.IDOMElement}*/
var IDOMElement; var IDOMElement;
var appendR = function( container, elements )
{
if( elements instanceof Array )
{
var l = elements.length;
for( var i = 0; i < l; i ++ )
{
elements[i] && appendR( container, elements[i] );
}
}
else if( typeof elements == "string" )
{
container.appendChild( _createTextNode( elements ) );
}
// append child, do not do any error handling!
else if( elements )
{
container.appendChild( elements );
}
};
var wrap = function ( wwith, id, wclass, elements, iKeys ) var wrap = function ( wwith, id, wclass, elements, iKeys )
{ {
var tmp = document.createElement( wwith || "div" ); var tmp = document.createElement( wwith || "div" );
@ -41,26 +62,9 @@
if( elements ) if( elements )
{ {
// is array? appendR( tmp, elements );
if(elements instanceof Array)
{
var l = elements.length;
for( var i = 0; i < l; i ++ )
{
elements[i] && tmp.appendChild( elements[i] );
}
}
// else if string
else if( typeof elements == "string" )
{
tmp.appendChild(_createTextNode(elements));
}
// else append child, do not do any error handling!
else if( elements )
{
tmp.appendChild( elements );
}
} }
return tmp; return tmp;
}; };
@ -75,12 +79,12 @@
// wrap name element after // wrap name element after
var wrapne = function ( name, elements, iKeys ) { var wrapne = function ( name, elements, iKeys ) {
return wrap(name, false, false, elements, iKeys); return wrap( name, false, false, elements, iKeys );
}; };
// wrap name attirbutes after // wrap name attirbutes after
var wrapna = function ( name, iKeys ) { var wrapna = function ( name, iKeys ) {
return wrap(name, false, false, false, iKeys); return wrap( name, false, false, false, iKeys );
}; };
var _createTextNode = function (s) var _createTextNode = function (s)