Add element function
This commit is contained in:
49
public/src/js/element.js
Normal file
49
public/src/js/element.js
Normal file
@@ -0,0 +1,49 @@
|
||||
function element(){
|
||||
var parent
|
||||
var lasttag
|
||||
var createdtag
|
||||
var toreturn={}
|
||||
for(var i=0;i<arguments.length;i++){
|
||||
var current=arguments[i]
|
||||
if(current){
|
||||
if(current.nodeType){
|
||||
parent=lasttag=current
|
||||
}else if(Array.isArray(current)){
|
||||
lasttag=parent
|
||||
for(var j=0;j<current.length;j++){
|
||||
if(current[j]){
|
||||
if(j==0&&typeof current[j]=="string"){
|
||||
var tagname=current[0].split("#")
|
||||
lasttag=createdtag=document.createElement(tagname[0])
|
||||
if(tagname[1]){
|
||||
toreturn[tagname[1]]=createdtag
|
||||
}
|
||||
}else if(current[j].constructor==Object){
|
||||
if(lasttag){
|
||||
for(var value in current[j]){
|
||||
if(value!="style"&&value in lasttag){
|
||||
lasttag[value]=current[j][value]
|
||||
}else{
|
||||
lasttag.setAttribute(value,current[j][value])
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
var returned=element(lasttag,current[j])
|
||||
for(var k in returned){
|
||||
toreturn[k]=returned[k]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(current){
|
||||
createdtag=document.createTextNode(current)
|
||||
}
|
||||
if(parent&&createdtag){
|
||||
parent.appendChild(createdtag)
|
||||
}
|
||||
createdtag=0
|
||||
}
|
||||
}
|
||||
return toreturn
|
||||
}
|
||||
Reference in New Issue
Block a user