//универсальный тег
//empty
CLASS["teg"]=class
{
get Data(){return this.data;}
set Data(val){this.data=val;}
create_arr(p)
{
bo52.data={};
bo52.temp=this;
if(Array.isArray(p)==true){
Object.keys(p).forEach(function(key){
bo52.data[key]=bo52.temp.create_teg(p[key]);
}, p);
} else
bo52.data=this.create_teg(p);
return bo52.data;
}
constructor(p){
this.p=p;
this.Data=this.create_arr(p);
}
create_teg(p)
{
if (typeof(p)=='string') p={teg:p};
if (p.body==undefined) p.body=$('body');
if (p.teg==undefined) p.teg='div';
if (p.html==undefined) p.html='';
if (typeof(p.body)=='number') p.body=bo52.tegs[p.body].ex;
p.ex=$('<'+p.teg+'>').appendTo(p.body);
p.ex.data('ex',this);
p.ex.data('EX',p.EX);
this.create_attr(p);
this.create_css(p);
this.create_event(p);
this.create_class(p);
this.create_html(p);
this.create_data(p);
this.create_prop(p);
return p.ex;
}
create_attr(p){
if (p.attr==undefined) return;
if (p.teg=='a')
{
if (p.attr.href==undefined) p.attr.href='#';
}
Object.keys(p.attr).forEach(function(key) {
let val=this[key];
if (key=='src') val='http://unity/wp-content/uploads/2021/05/'+val+'.png';
p.ex.attr(key.replace('_','-'),val);
}, p.attr);
}
create_css(p){
if (p.css==undefined) return;
Object.keys(p.css).forEach(function(key){
p.ex.css(key.replace('_','-'),p.css[key]);
}, p.css);
}
create_prop(p){
if (p.prop==undefined) return;
Object.keys(p.prop).forEach(function(key){
p.ex.prop(key.replace('_','-'),p.prop[key]);
}, p.prop);
}
create_event(p){
if (p.event==undefined) return;
Object.keys(p.event).forEach(function(key) {
let v=p.event[key];
if (typeof(v)=='number')
v=bo52.e[v];
p.ex.bind(key,v);
}, p.event);
}
create_data(p){
if (p.data==undefined) return;
Object.keys(p.data).forEach(function(key) {
p.ex.data(key,p.data[key]);
}, p.data);
}
create_class(p){
if (p.classes==undefined) return;
for (var i = 0; i < p.classes.length; i++) {
let v=p.classes[i];
if (typeof(v)=='number')
v=bo52.classes[v].v;
p.ex.addClass(v);
}
}
create_html(p){
if (Array.isArray(p.html)==true)
{
Object.keys(p.html).forEach(function(key) {
p.html[key].EX=p.EX;
p.html[key]=new CLASS"teg";
$(p.html[key].p.ex).appendTo(p.ex);
}, p.html);
return;
}
switch(typeof(p.html))
{
case 'string':
p.ex.html(p.html);
break;
case 'function':
let f=p.html;
Object.keys(f).forEach(function(key) {
if (typeof(p.html[key])=='string'){
p.html[key].ex=p.html[key];
} else {
p.html[key].EX=p.EX;
p.html[key]=new CLASS"teg";
}
$(p.html[key].ex).appendTo(p.ex);
}, f);
break;
default:
p.html.EX=p.EX;
p.html=new CLASS"teg";
$(p.html.p.ex).appendTo(p.ex);
break;
}
}
}