function makenode() { var node = new nodeiteration(); var objs; var multi; var ret; var cfg; if (makenode.arguments[0]) { if (makenode.arguments[0].length > 0) { objs = makenode.arguments[0]; multi = true; } else { objs = new Array(makenode.arguments[0]); if (makenode.arguments.length > 1) { multi = true; } else { multi = false; } } } node.setDebug(ddw); ret = node.iterat(objs); if (ret) { if (!multi) { if (ret.length > 1) { var tmp = document.createElement('div'); for (var i=0; i < ret.length; i++) { tmp.appendChild(ret[i]) } return tmp; } else { return ret[0]; } } return ret[0]; } else { return null; } } function nodeiteration() { var config; var objs; var specials; this.doit = doit; this.iterat = function() { this.objs = arguments[0]; this.config = {}; this.style_px = ",top,left,width,height,minWidth,minHeight,"; this.style = ",position,display,visibility,textAlign,"; this.attribute = ",method,action,target,type,name,id,value,checked,className,overflow,src,title,label,alt,"; this.specials = ","; this.on = ",onclick,onblur,onkeyup,onchange,onfocus,"; this.offsetX = 0; this.offsetY = 0; return this.doit(this.objs); } this.setDebug = function() { this.myddw = arguments[0]; } this.getconfig = function() { return this.config; } function doit() { var objs = arguments[0]; var multi = true; var nodes = new Array(); var opt = {}; var config_mode = false; if (doit.arguments[0]) { if (doit.arguments[0] && doit.arguments[0].length > 0) { objs = doit.arguments[0]; } else { objs = new Array(doit.arguments[0]); } for (var m = 0; m < objs.length; m++) { if (arguments.length > 2) { config_mode = true; if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [131] doit() -- detect config_mode");} } var obj = objs[m]; for (var part in obj) { if (part == "text") { if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [138] doit() -- createTextNode "+obj[part]);} var t = obj[part]; t = t.replace(/"/g,'"'); if (t.indexOf("\n") > 0) { if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [143] doit() -- contains LF");} var texts = t.split("\n"); for (var i=0; i0) { nodes.push ( document.createElement("br")); } nodes.push ( document.createTextNode(texts[i])); } } else if (t.indexOf(" ") > 0) { if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [156] doit() -- contains LF");} var texts = t.split(" "); nodes.push(document.createTextNode(texts.join("\n"))); } else { if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [162] doit() -- regular text");} nodes.push ( document.createTextNode(obj[part])); } } else if (part == "option") { if (obj[part].length) { for (var o = 0; o < obj[part].length; o++) { var opti = document.createElement("option"); opti.text = obj[part][o]; nodes.push(opti); } } else { for (var o in obj[part]) { var opti = document.createElement("option"); opti.value = o; opti.text = obj[part][o]; nodes.push(opti); } } } else if (part == "script") { if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [190] doit() -- script "+obj[part]);} eval(obj[part]); } else if (typeof(obj[part]) == 'object') { var node; if (part == "config") { config_mode = true; if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [199] doit() -- detect part config -- set config_mode");} } if (config_mode) { node = new Object(); node['_name_'] = part; var childs = this.doit(obj[part],1,1); for (var i=0; i < childs.length; i++) { var nn = childs[i]["_name_"]; delete (childs[i]["_name_"]); this.config[nn] = childs[i]; this.specials += nn + ","; if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [212] doit() -- add to specials: "+nn);} } } else { try{ node = document.createElement(part); } catch(e) { alert("cannot create "+part+"\n"+view(e)); } if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [223] doit() -- createElement("+part+")");} var childs = this.doit(obj[part],1); if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [225] doit() -- append "+childs.length+" children to ("+node.tagName+")");} for (var i=0; i < childs.length; i++) { if (childs[i].tagName) { if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [230] doit() -- append "+ childs[i].tagName);} } node.appendChild(childs[i]); } } for (var t in opt) { var search = ","+t+","; if (config_mode) { if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [241] doit() -- set "+t+" to Object "+node["_name_"]);} node[t] = opt[t]; } else { if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [246] doit() -- attach "+t+" ("+opt[t]+") to "+node.tagName);} if (this.style_px.indexOf(search) >= 0) { node.style[t] = opt[t] + "px"; } else if (this.style.indexOf(search) >= 0) { node.style[t] = opt[t]; } else if (this.attribute.indexOf(search) >= 0) { try{ node[t] = opt[t]; } catch(e){} } else if (this.on.indexOf(search) >= 0) { if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [264] doit() -- install "+t+" = new Function("+opt[t]+")");} if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [265] doit() -- type "+typeof(opt[t]));} var func = opt[t]; node[t] = new Function( func ); } else if (this.specials.indexOf(search) >= 0) { if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [271] doit() -- special "+t+" = "+this.config[t]+" in "+this.specials);} for (var e in this.config[t]) { v = opt[t]; ex = "k = "+opt[t]+ "" + this.config[t][e] + ";"; if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [277] doit() -- special cal: \""+ex+"\"");} eval(ex); node.style[e] = k + "px"; t = e; } } else { alert("makenode.js [293]\nfound "+t); } if (this.config.offset) { if (t == "top" && this.config.offset.y) { if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [299] doit() -- offset for "+t+" !");} var v1 = parseInt(node.style[t]); var v2 = parseInt(this.config.offset.y); var v = v1 + v2; node.style[t] = v + "px"; if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [304] doit() -- offset "+v+" ("+v1+" + "+v2+")");} } else if (t == "left" && this.config.offset.x) { if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [308] doit() -- offset for "+t+" !");} var v1 = parseInt(node.style[t]); var v2 = parseInt(this.config.offset.x); var v = v1 + v2; node.style[t] = v + "px"; if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [313] doit() -- offset "+v+" ("+v1+" + "+v2+")");} } } } } delete opt; opt = {}; if (part == "config") { var n = node["_name_"]; this.config[n] = node; } else { nodes.push(node); } } else { if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [335] doit() -- save "+part+"="+obj[part]);} opt[part] = obj[part]; } } for (var t in opt) { if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [342] doit() -- option leave "+t);} this.config[t] = opt[t]; this.specials += t + ","; } if (config_mode) { if (ddw) {if (this.myddw) this.myddw.echo("makenode.js [349] doit() -- clear config_mode");} config_mode = false; } } return nodes; } } }