Gestion du suivi dynamique des attributs et de leur modification (DOM->objet) uniquement si la variable est soit 1) une référence unique, ou 2) un tableau contenant 1 référence uniquement
This commit is contained in:
parent
a6c1c8c8cf
commit
b412e5b6fb
|
@ -1,6 +1,6 @@
|
||||||
var ref=function(a,b){for(var d=null;null==d||a.hasOwnProperty(d);)d="$"+(268435456+Math.floor(4026531839*Math.random())).toString(16)+"$";a[d]=b;return d},FormBuilder=function(a){this.form_object=a;this.observer=new MutationObserver(FormBuilder.DOMUpdates)};FormBuilder.prototype={form_object:this.form_object,defs_object:{},parent_element:null,built_form:null,root_element:null,ref_table:{$00000000$:null},ref_assoc:{NULL:"$00000000$"},observer:this.observer,scope:{}};
|
var ref=function(a,b){for(var d=null;null==d||a.hasOwnProperty(d);)d="$"+(268435456+Math.floor(4026531839*Math.random())).toString(16)+"$";a[d]=b;return d},FormBuilder=function(a){this.form_object=a;this.observer=new MutationObserver(FormBuilder.DOMUpdates)};FormBuilder.prototype={form_object:this.form_object,defs_object:{},parent_element:null,built_form:null,root_element:null,ref_table:{$00000000$:null},ref_assoc:{NULL:"$00000000$"},observer:this.observer,scope:{}};
|
||||||
FormBuilder.regex={reg_in_key:/^\/\^(.+)\$\/$/,reg_out_val:/\{(\$[1-9])\}/,pri_out_val:/\{([a-z_]+)\}/g,pri_in_key:/^\$([a-z_]+)$/,arr_out_set:/^\{([a-z_]+)\[\]\}$/,arr_out_val:/\{([a-z_]+)([\.:])([a-z_]+)\}/g,arr_in_key:/^\$([a-z_]+)$/,fun_out_val:/^\{([a-z_]+)\(\)\}$/,ref_pri:/^\$[a-f0-9]{8}\$$/};FormBuilder.spread_attr="children next_nodes prev_nodes attributes node_link listeners repeat browse funcs".split(" ");FormBuilder.spec_attr=["_value","_selected"];
|
FormBuilder.regex={reg_in_key:/^\/\^(.+)\$\/$/,reg_out_val:/\{(\$[1-9])\}/,pri_out_val:/\{([a-z_]+)\}/g,pri_in_key:/^\$([a-z_]+)$/,arr_out_set:/^\{([a-z_]+)\[\]\}$/,arr_out_val:/\{([a-z_]+)([\.:])([a-z_]+)\}/g,arr_in_key:/^\$([a-z_]+)$/,fun_out_val:/^\{([a-z_]+)\(\)\}$/,ref_pri:/^\$[a-f0-9]{8}\$$/};FormBuilder.spread_attr="children next_nodes prev_nodes attributes node_link listeners repeat browse funcs".split(" ");FormBuilder.spec_attr=["_value","_selected"];
|
||||||
FormBuilder.observe={attributes:{attributes:!0,attributeOldValue:!0,childList:!1,characterData:!1,subtree:!1,characterDataOldValue:!1},characterData:{attributes:!1,attributeOldValue:!1,childList:!1,characterData:!0,subtree:!1,characterDataOldValue:!0}};FormBuilder.debug_time=!1;FormBuilder.debug_time_details=!1;
|
FormBuilder.observe={attributes:{attributes:!0,attributeOldValue:!1,childList:!1,characterData:!1,subtree:!1,characterDataOldValue:!1},characterData:{attributes:!1,attributeOldValue:!1,childList:!1,characterData:!0,subtree:!1,characterDataOldValue:!0}};FormBuilder.debug_time=!1;FormBuilder.debug_time_details=!1;
|
||||||
FormBuilder.debugStart=function(a,b){if(1!=b||!FormBuilder.debug_time)if(2!=b||!FormBuilder.debug_time_details)return{type:0};var d="["+parseInt(64424509439*Math.random()).toString(16)+"]";console.time(d);console.group(a);return{type:b,time_r:d,group:a}};FormBuilder.debug=function(a,b){if(1!=b||!FormBuilder.debug_time)if(2!=b||!FormBuilder.debug_time_details)return{type:0};console.debug(a)};
|
FormBuilder.debugStart=function(a,b){if(1!=b||!FormBuilder.debug_time)if(2!=b||!FormBuilder.debug_time_details)return{type:0};var d="["+parseInt(64424509439*Math.random()).toString(16)+"]";console.time(d);console.group(a);return{type:b,time_r:d,group:a}};FormBuilder.debug=function(a,b){if(1!=b||!FormBuilder.debug_time)if(2!=b||!FormBuilder.debug_time_details)return{type:0};console.debug(a)};
|
||||||
FormBuilder.debugStop=function(a){if(1!=a.type||!FormBuilder.debug_time)if(2!=a.type||!FormBuilder.debug_time_details)return null;console.timeEnd(a.time_r);console.groupEnd(a.group)};FormBuilder.prototype.add_definition=function(a){var b=FormBuilder.debugStart("FormBuilder.add_definition",1),d;for(d in a)this.defs_object[d]=a[d];FormBuilder.debugStop(b)};
|
FormBuilder.debugStop=function(a){if(1!=a.type||!FormBuilder.debug_time)if(2!=a.type||!FormBuilder.debug_time_details)return null;console.timeEnd(a.time_r);console.groupEnd(a.group)};FormBuilder.prototype.add_definition=function(a){var b=FormBuilder.debugStart("FormBuilder.add_definition",1),d;for(d in a)this.defs_object[d]=a[d];FormBuilder.debugStop(b)};
|
||||||
FormBuilder.prototype.build=function(a){var b=FormBuilder.debugStart("FormBuilder.build",1);a=null==a?{}:a;for(var d in a)a[d]=ref(this.ref_table,a[d]),this.ref_assoc[d]=a[d],this.scope["$"+d]=this.ref_assoc[d],this.__defineGetter__("$"+d,function(a,b){return function(){return a.ref_table[a.scope["$"+b]]}}(this,d)),this.__defineSetter__("$"+d,function(a,b){return function(d){a.ref_table[a.scope["$"+b]]=d;a.attach()}}(this,d));this.built_form=JSON.parse(JSON.stringify(this.form_object));this.built_form=
|
FormBuilder.prototype.build=function(a){var b=FormBuilder.debugStart("FormBuilder.build",1);a=null==a?{}:a;for(var d in a)a[d]=ref(this.ref_table,a[d]),this.ref_assoc[d]=a[d],this.scope["$"+d]=this.ref_assoc[d],this.__defineGetter__("$"+d,function(a,b){return function(){return a.ref_table[a.scope["$"+b]]}}(this,d)),this.__defineSetter__("$"+d,function(a,b){return function(d){a.ref_table[a.scope["$"+b]]=d;a.attach()}}(this,d));this.built_form=JSON.parse(JSON.stringify(this.form_object));this.built_form=
|
||||||
|
@ -15,16 +15,16 @@ f));FormBuilder.debugStop(g);return a};FormBuilder.replaceStatementsFunction=fun
|
||||||
FormBuilder.replaceStatementsRegex=function(a,b){var d=FormBuilder.regex.reg_out_val,e=null,f=[],g,c,h,k;for(h=0;h<a.length;h++){m=null;f=[];g=-1;for(c=[];null!==(e=d.exec(a[h]))&&!(g>=d.lastIndex);)g=d.lastIndex,f.push(e);for(e=g=0;e<f.length;e++)k=f[e][1],(0<g||0<f[e].index)&&c.push(a[h].substr(g,f[e].index-g)),b.hasOwnProperty(k)||(b[k]=""),c.push(b[k]),g=f[e].index+f[e][0].length;g<a[h].length&&c.push(a[h].substr(g,a[h].length));a=a.slice(0,h).concat(c).concat(a.slice(h+1))}return a};
|
FormBuilder.replaceStatementsRegex=function(a,b){var d=FormBuilder.regex.reg_out_val,e=null,f=[],g,c,h,k;for(h=0;h<a.length;h++){m=null;f=[];g=-1;for(c=[];null!==(e=d.exec(a[h]))&&!(g>=d.lastIndex);)g=d.lastIndex,f.push(e);for(e=g=0;e<f.length;e++)k=f[e][1],(0<g||0<f[e].index)&&c.push(a[h].substr(g,f[e].index-g)),b.hasOwnProperty(k)||(b[k]=""),c.push(b[k]),g=f[e].index+f[e][0].length;g<a[h].length&&c.push(a[h].substr(g,a[h].length));a=a.slice(0,h).concat(c).concat(a.slice(h+1))}return a};
|
||||||
FormBuilder.replaceStatementsPrimary=function(a,b){var d=FormBuilder.regex.pri_out_val,e=null,f=[],g,c,h,k;for(h=0;h<a.length;h++){m=null;f=[];g=0;for(c=[];null!==(e=d.exec(a[h]));)f.push(e);for(e=0;e<f.length;e++)k=f[e][1],(0<g||0<f[e].index)&&c.push(a[h].substr(g,f[e].index-g)),b.hasOwnProperty(k)||(b[k]=""),c.push(b[k]),g=f[e].index+f[e][0].length;g<a[h].length&&c.push(a[h].substr(g,a[h].length));a=a.slice(0,h).concat(c).concat(a.slice(h+1))}return a};
|
FormBuilder.replaceStatementsPrimary=function(a,b){var d=FormBuilder.regex.pri_out_val,e=null,f=[],g,c,h,k;for(h=0;h<a.length;h++){m=null;f=[];g=0;for(c=[];null!==(e=d.exec(a[h]));)f.push(e);for(e=0;e<f.length;e++)k=f[e][1],(0<g||0<f[e].index)&&c.push(a[h].substr(g,f[e].index-g)),b.hasOwnProperty(k)||(b[k]=""),c.push(b[k]),g=f[e].index+f[e][0].length;g<a[h].length&&c.push(a[h].substr(g,a[h].length));a=a.slice(0,h).concat(c).concat(a.slice(h+1))}return a};
|
||||||
FormBuilder.replaceStatementsArrayValue=function(a,b,d,e){b=FormBuilder.regex.arr_out_val;var f=null,g=[],c,h,k,l;for(k=0;k<a.length;k++){m=null;g=[];c=0;for(h=[];null!==(f=b.exec(a[k]));)g.push(f);for(f=0;f<g.length;f++)l=g[f][1]+g[f][2]+g[f][3],(0<c||0<g[f].index)&&h.push(a[k].substr(c,g[f].index-c)),e.hasOwnProperty(l)||(e[l]=ref(d)),h.push(e[l]),c=g[f].index+g[f][0].length;c<a[k].length&&h.push(a[k].substr(c,a[k].length));a=a.slice(0,k).concat(h).concat(a.slice(k+1))}return a};
|
FormBuilder.replaceStatementsArrayValue=function(a,b,d,e){b=FormBuilder.regex.arr_out_val;var f=null,g=[],c,h,k,l;for(k=0;k<a.length;k++){m=null;g=[];c=0;for(h=[];null!==(f=b.exec(a[k]));)g.push(f);for(f=0;f<g.length;f++)l=g[f][1]+g[f][2]+g[f][3],(0<c||0<g[f].index)&&h.push(a[k].substr(c,g[f].index-c)),e.hasOwnProperty(l)||(e[l]=ref(d)),h.push(e[l]),c=g[f].index+g[f][0].length;c<a[k].length&&h.push(a[k].substr(c,a[k].length));a=a.slice(0,k).concat(h).concat(a.slice(k+1))}return a};
|
||||||
FormBuilder.readRef=function(a,b){var d,e="";if("string"==typeof b&&FormBuilder.regex.ref_pri.test(b)){for(;"string"==typeof b&&FormBuilder.regex.ref_pri.test(b);)b=a[b],b instanceof Array&&1==b.length&&(b=b[0]);return b}for(d in b)e=FormBuilder.regex.ref_pri.test(b[d])&&a.hasOwnProperty(b[d])?a[b[d]]instanceof Array?e+FormBuilder.readRef(a,a[b[d]]):e+a[b[d]]:e+b[d].toString();return e};
|
FormBuilder.readRef=function(a,b){var d,e="";if("string"==typeof b&&FormBuilder.regex.ref_pri.test(b)){for(;"string"==typeof b&&FormBuilder.regex.ref_pri.test(b);)b=a[b],b instanceof Array&&1==b.length&&(b=b[0]);return b}for(d in b)e=FormBuilder.regex.ref_pri.test(b[d])&&a.hasOwnProperty(b[d])?a[b[d]]instanceof Array?e+FormBuilder.readRef(a,a[b[d]]):e+a[b[d]]:e+b[d].toString();return e};FormBuilder.fetchRef=function(a,b){for(var d=FormBuilder.regex.ref_pri,e=b;d.test(b);)e=b,b=a[b][0]||a[b];return e};
|
||||||
FormBuilder.createElements=function(a,b,d){var e=FormBuilder.debugStart("FormBuilder::createElements",2),f=[],g,c,h,k,l,n=["NULL"],p,q;if(a.hasOwnProperty("repeat")&&(l=FormBuilder.readRef(b,a.repeat.n),!isNaN(l)))for(n=[],d.hasOwnProperty(a.repeat.id+":i")||(d[a.repeat.id+":i"]=ref(0)),d.hasOwnProperty(a.repeat.id+":n")||(d[a.repeat.id+":n"]=ref(l)),g=0;g<l;g++)n[g]={},n[g][a.repeat.id+":i"]=g,n[g][a.repeat.id+":n"]=l;if(a.hasOwnProperty("browse")&&(l=FormBuilder.readRef(b,a.browse.array),l instanceof
|
FormBuilder.createElements=function(a,b,d){var e=FormBuilder.debugStart("FormBuilder::createElements",2),f=[],g,c,h,k,l,n=["NULL"],p,q;if(a.hasOwnProperty("repeat")&&(l=FormBuilder.readRef(b,a.repeat.n),!isNaN(l)))for(n=[],d.hasOwnProperty(a.repeat.id+":i")||(d[a.repeat.id+":i"]=ref(0)),d.hasOwnProperty(a.repeat.id+":n")||(d[a.repeat.id+":n"]=ref(l)),g=0;g<l;g++)n[g]={},n[g][a.repeat.id+":i"]=g,n[g][a.repeat.id+":n"]=l;if(a.hasOwnProperty("browse")&&(l=FormBuilder.readRef(b,a.browse.array),l instanceof
|
||||||
Array)){n=[];p=[];q={};h=new RegExp(a.browse.id+".(.+)");for(g in d)h.test(g)&&p.push(RegExp.$1);if(a.browse.hasOwnProperty("funcs"))for(g in a.browse.funcs)h.test(g)&&(q[RegExp.$1]=FormBuilder.readRef(b,a.browse.funcs[g]));d.hasOwnProperty(a.browse.id+":i")||(d[a.browse.id+":i"]=ref(0));d.hasOwnProperty(a.browse.id+":n")||(d[a.browse.id+":n"]=ref(l));for(g=0;g<l.length;g++){n[g]={};for(c in p)q.hasOwnProperty(p[c])?n[g][a.browse.id+"."+p[c]]=q[p[c]](l[g]):l[g].hasOwnProperty(p[c])&&(n[g][a.browse.id+
|
Array)){n=[];p=[];q={};h=new RegExp(a.browse.id+".(.+)");for(g in d)h.test(g)&&p.push(RegExp.$1);if(a.browse.hasOwnProperty("funcs"))for(g in a.browse.funcs)h.test(g)&&(q[RegExp.$1]=FormBuilder.readRef(b,a.browse.funcs[g]));d.hasOwnProperty(a.browse.id+":i")||(d[a.browse.id+":i"]=ref(0));d.hasOwnProperty(a.browse.id+":n")||(d[a.browse.id+":n"]=ref(l));for(g=0;g<l.length;g++){n[g]={};for(c in p)q.hasOwnProperty(p[c])?n[g][a.browse.id+"."+p[c]]=q[p[c]](l[g]):l[g].hasOwnProperty(p[c])&&(n[g][a.browse.id+
|
||||||
"."+p[c]]=l[g][p[c]]);n[g][a.browse.id+":i"]=g;n[g][a.browse.id+":n"]=l.length}}for(c=0;c<n.length;c++){f[c]={prev:[],node:[],next:[]};if(n[c]instanceof Object)for(g in n[c])b[d[g]]=n[c][g];if(a.hasOwnProperty("prev_nodes"))for(g in a.prev_nodes)f[c].prev=FormBuilder.createElements(a.prev_nodes[g],b,d);if(a.hasOwnProperty("next_nodes"))for(g in a.next_nodes)f[c].next=FormBuilder.createElements(a.next_nodes[g],b,d);if(a.hasOwnProperty("node_link"))for(g in l=FormBuilder.createElements(a.node_link,
|
"."+p[c]]=l[g][p[c]]);n[g][a.browse.id+":i"]=g;n[g][a.browse.id+":n"]=l.length}}for(c=0;c<n.length;c++){f[c]={prev:[],node:[],next:[]};if(n[c]instanceof Object)for(g in n[c])b[d[g]]=n[c][g];if(a.hasOwnProperty("prev_nodes"))for(g in a.prev_nodes)f[c].prev=FormBuilder.createElements(a.prev_nodes[g],b,d);if(a.hasOwnProperty("next_nodes"))for(g in a.next_nodes)f[c].next=FormBuilder.createElements(a.next_nodes[g],b,d);if(a.hasOwnProperty("node_link"))for(g in l=FormBuilder.createElements(a.node_link,
|
||||||
b,d),l)f[c].prev=f[c].prev.concat(l[g].prev),f[c].node=f[c].node.concat(l[g].node),f[c].next=l[g].next.concat(f[c].next);else a.hasOwnProperty("node_type")&&f[c].node.push(document.createElement(FormBuilder.readRef(b,a.node_type)))-1;if(a.hasOwnProperty("attributes"))for(g in a.attributes)for(k in f[c].node)f[c].node[k].setAttribute(g,FormBuilder.readRef(b,a.attributes[g]));if(a.hasOwnProperty("css"))for(k in f[c].node)FormBuilder.applyCSS(f[c].node[k],a.css);if(a.hasOwnProperty("text"))for(k in f[c].node)f[c].node[k].innerHTML=
|
b,d),l)f[c].prev=f[c].prev.concat(l[g].prev),f[c].node=f[c].node.concat(l[g].node),f[c].next=l[g].next.concat(f[c].next);else a.hasOwnProperty("node_type")&&f[c].node.push(document.createElement(FormBuilder.readRef(b,a.node_type)))-1;if(a.hasOwnProperty("attributes"))for(g in a.attributes)for(k in f[c].node)f[c].node[k].setAttribute(g,FormBuilder.readRef(b,a.attributes[g]));if(a.hasOwnProperty("css"))for(k in f[c].node)FormBuilder.applyCSS(f[c].node[k],a.css);if(a.hasOwnProperty("text"))for(k in f[c].node)f[c].node[k].innerHTML=
|
||||||
FormBuilder.readRef(b,a.text);if(a.hasOwnProperty("listeners"))for(g in a.listeners)for(k in f[c].node)f[c].node[k].addEventListener(g,FormBuilder.readRef(b,a.listeners[g]),!1);if(a.hasOwnProperty("children"))for(g in a.children)for(k in l=FormBuilder.createElements(a.children[g],b,d),f[c].node)FormBuilder.attachElements(f[c].node[k],l);for(k in f[c].node)if(l="input"==FormBuilder.fetchNodeType(a)&&a.hasOwnProperty("_value"),"select"==FormBuilder.fetchNodeType(a)&&a.hasOwnProperty("_selected")){for(g=
|
FormBuilder.readRef(b,a.text);if(a.hasOwnProperty("listeners"))for(g in a.listeners)for(k in f[c].node)f[c].node[k].addEventListener(g,FormBuilder.readRef(b,a.listeners[g]),!1);if(a.hasOwnProperty("children"))for(g in a.children)for(k in l=FormBuilder.createElements(a.children[g],b,d),f[c].node)FormBuilder.attachElements(f[c].node[k],l);for(k in f[c].node)if(l="input"==FormBuilder.fetchNodeType(a)&&a.hasOwnProperty("_value"),"select"==FormBuilder.fetchNodeType(a)&&a.hasOwnProperty("_selected")){for(g=
|
||||||
0;g<f[c].node[k].children.length;g++)f[c].node[k].children[g].value==FormBuilder.readRef(b,a._selected)?f[c].node[k].children[g].setAttribute("selected",!0):f[c].node[k].children[g].removeAttribute("selected");f[c].node[k].addEventListener("change",function(c){if(a._selected instanceof Array&&!(1<a._selected.length)&&FormBuilder.regex.ref_pri.test(a._selected[0])){var d=a._selected[0];for(c=d;FormBuilder.regex.ref_pri.test(d);)c=d,d=b[d],d instanceof Array&&(d=d[0]);b[c]=this.value}},!1)}else l?f[c].node[k].addEventListener("input",
|
0;g<f[c].node[k].children.length;g++)f[c].node[k].children[g].value==FormBuilder.readRef(b,a._selected)?f[c].node[k].children[g].setAttribute("selected",!0):f[c].node[k].children[g].removeAttribute("selected");f[c].node[k].addEventListener("change",function(c){a._selected instanceof Array&&!(1<a._selected.length)&&FormBuilder.regex.ref_pri.test(a._selected[0])&&(c=a._selected[0],c=FormBuilder.fetchRef(b,c),b[c]=this.value)},!1)}else l?f[c].node[k].addEventListener("input",function(c){a._value instanceof
|
||||||
function(d){if(a._value instanceof Array&&!(1<a._value.length)&&FormBuilder.regex.ref_pri.test(a._value[0])){var c=a._value[0];for(d=c;FormBuilder.regex.ref_pri.test(c);)d=c,c=b[c],c instanceof Array&&(c=c[0]);b[d]=this.value}},!1):(a.hasOwnProperty("observers")||(a.observers=[]),l=new MutationObserver(function(a){return function(b){return FormBuilder.DOMUpdates(a,b)}}(a)),l.observe(f[c].node[k],FormBuilder.observe.attributes),a.observers.push(l))}d=a.hasOwnProperty("node")?a.node:a.node_type;FormBuilder.debug("<"+
|
Array&&!(1<a._value.length)&&FormBuilder.regex.ref_pri.test(a._value[0])&&(c=a._value[0],c=FormBuilder.fetchRef(b,c),b[c]=this.value)},!1):(a.hasOwnProperty("observers")||(a.observers=[]),l=new MutationObserver(function(a,b){return function(c){return FormBuilder.DOMUpdates(a,c,b)}}(a,b)),l.observe(f[c].node[k],FormBuilder.observe.attributes),a.observers.push(l))}d=a.hasOwnProperty("node")?a.node:a.node_type;FormBuilder.debug("<"+d+">",2);FormBuilder.debugStop(e);return a.dom=f};
|
||||||
d+">",2);FormBuilder.debugStop(e);return a.dom=f};
|
|
||||||
FormBuilder.attachElements=function(a,b){var d=FormBuilder.debugStart("FormBuilder::attachElements",2),e,f;for(e in b){for(f in b[e].prev)b[e].prev[f]instanceof Element&&a.appendChild(b[e].prev[f]),b[e].prev[f]instanceof Object&&FormBuilder.attachElements(a,[b[e].prev[f]]);for(f in b[e].node)b[e].node[f]instanceof Element&&a.appendChild(b[e].node[f]),b[e].node[f]instanceof Object&&FormBuilder.attachElements(a,[b[e].node[f]]);for(f in b[e].next)b[e].next[f]instanceof Element&&a.appendChild(b[e].next[f]),
|
FormBuilder.attachElements=function(a,b){var d=FormBuilder.debugStart("FormBuilder::attachElements",2),e,f;for(e in b){for(f in b[e].prev)b[e].prev[f]instanceof Element&&a.appendChild(b[e].prev[f]),b[e].prev[f]instanceof Object&&FormBuilder.attachElements(a,[b[e].prev[f]]);for(f in b[e].node)b[e].node[f]instanceof Element&&a.appendChild(b[e].node[f]),b[e].node[f]instanceof Object&&FormBuilder.attachElements(a,[b[e].node[f]]);for(f in b[e].next)b[e].next[f]instanceof Element&&a.appendChild(b[e].next[f]),
|
||||||
b[e].next[f]instanceof Object&&FormBuilder.attachElements(a,[b[e].next[f]])}FormBuilder.debugStop(d)};
|
b[e].next[f]instanceof Object&&FormBuilder.attachElements(a,[b[e].next[f]])}FormBuilder.debugStop(d)};
|
||||||
FormBuilder.detachElements=function(a,b){var d,e;for(d in b){for(e in b[d].prev)b[d].prev[e]instanceof Element&&a.removeChild(b[d].prev[e]),b[d].prev[e]instanceof Object&&FormBuilder.detachElements(a,[b[d].prev[e]]);for(e in b[d].node)b[d].node[e]instanceof Element&&a.removeChild(b[d].node[e]),b[d].node[e]instanceof Object&&FormBuilder.detachElements(a,[b[d].node[e]]);for(e in b[d].next)b[d].next[e]instanceof Element&&a.removeChild(b[d].next[e]),b[d].next[e]instanceof Object&&FormBuilder.detachElements(a,
|
FormBuilder.detachElements=function(a,b){var d,e;for(d in b){for(e in b[d].prev)b[d].prev[e]instanceof Element&&a.removeChild(b[d].prev[e]),b[d].prev[e]instanceof Object&&FormBuilder.detachElements(a,[b[d].prev[e]]);for(e in b[d].node)b[d].node[e]instanceof Element&&a.removeChild(b[d].node[e]),b[d].node[e]instanceof Object&&FormBuilder.detachElements(a,[b[d].node[e]]);for(e in b[d].next)b[d].next[e]instanceof Element&&a.removeChild(b[d].next[e]),b[d].next[e]instanceof Object&&FormBuilder.detachElements(a,
|
||||||
[b[d].next[e]])}};FormBuilder.applyCSS=function(a,b){for(var d in b)a.style[d]=b[d]};FormBuilder.fetchNodeType=function(a){if(a.hasOwnProperty("node_type"))return a.node_type;if(a.hasOwnProperty("node_link"))return FormBuilder.fetchNodeType(a.node_link)};FormBuilder.DOMUpdates=function(a,b){for(var d in b)console.log(a,b[d])};
|
[b[d].next[e]])}};FormBuilder.applyCSS=function(a,b){for(var d in b)a.style[d]=b[d]};FormBuilder.fetchNodeType=function(a){if(a.hasOwnProperty("node_type"))return a.node_type;if(a.hasOwnProperty("node_link"))return FormBuilder.fetchNodeType(a.node_link)};
|
||||||
|
FormBuilder.DOMUpdates=function(a,b,d){var e,f,g,c=FormBuilder.regex.ref_pri;for(e in b)if(f=b[e].attributeName,a.hasOwnProperty("attributes")&&a.attributes.hasOwnProperty(f)&&(g=a.attributes[f]),g instanceof Array&&1==g.length&&c.test(g[0])||c.test(g))g=g[0]||g,g=FormBuilder.fetchRef(d,g),d[g]=b[e].target.getAttribute(f)};
|
||||||
|
|
|
@ -121,7 +121,7 @@ FormBuilder.spec_attr = [ // Liste des attributs à dupliquer jusque dans la def
|
||||||
FormBuilder.observe = {
|
FormBuilder.observe = {
|
||||||
attributes: {
|
attributes: {
|
||||||
attributes: true,
|
attributes: true,
|
||||||
attributeOldValue: true,
|
attributeOldValue: false,
|
||||||
childList: false,
|
childList: false,
|
||||||
characterData: false,
|
characterData: false,
|
||||||
subtree: false,
|
subtree: false,
|
||||||
|
@ -969,6 +969,36 @@ FormBuilder.readRef = function(ref_table, parts){
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* RETOURNE LA DERNIERE REFERENCE VERS LA VALEUR
|
||||||
|
*
|
||||||
|
* @ref_table<Object> Objet contenant les références
|
||||||
|
* @ref<String> Référence
|
||||||
|
*
|
||||||
|
* @return ref<String> Dernière référence
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
FormBuilder.fetchRef = function(ref_table, ref){
|
||||||
|
/* [0] Initialisation
|
||||||
|
=========================================================*/
|
||||||
|
var i,
|
||||||
|
r = FormBuilder.regex.ref_pri,
|
||||||
|
last = ref;
|
||||||
|
|
||||||
|
|
||||||
|
/* [1] On fetch la référence tant qu'on en a encore une
|
||||||
|
=========================================================*/
|
||||||
|
while( r.test(ref) ){
|
||||||
|
last = ref;
|
||||||
|
ref = ref_table[ref][0] || ref_table[ref];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* [2] On retourne le résultat
|
||||||
|
=========================================================*/
|
||||||
|
return last;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/* CONSTRUIT UN ELEMENT A PARTIR D'UNE DEFINITION
|
/* CONSTRUIT UN ELEMENT A PARTIR D'UNE DEFINITION
|
||||||
*
|
*
|
||||||
* @definition<Object> Objet de définition de l'élément
|
* @definition<Object> Objet de définition de l'élément
|
||||||
|
@ -1265,20 +1295,10 @@ FormBuilder.createElements = function(definition, ref_table, ref_assoc){
|
||||||
var selected_ref = definition._selected[0];
|
var selected_ref = definition._selected[0];
|
||||||
|
|
||||||
// On recupere la derniere reference
|
// On recupere la derniere reference
|
||||||
var last = selected_ref,
|
selected_ref = FormBuilder.fetchRef(ref_table, selected_ref);
|
||||||
curr = selected_ref;
|
|
||||||
|
|
||||||
// On var jusqu'a la valeur
|
|
||||||
while( FormBuilder.regex.ref_pri.test(curr) ){
|
|
||||||
last = curr;
|
|
||||||
curr = ref_table[ curr ];
|
|
||||||
|
|
||||||
if( curr instanceof Array )
|
|
||||||
curr = curr[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// On attribut la valeur modifiee
|
// On attribut la valeur modifiee
|
||||||
ref_table[ last ] = this.value;
|
ref_table[ selected_ref ] = this.value;
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1298,34 +1318,23 @@ FormBuilder.createElements = function(definition, ref_table, ref_assoc){
|
||||||
var value_ref = definition._value[0];
|
var value_ref = definition._value[0];
|
||||||
|
|
||||||
// On recupere la derniere reference
|
// On recupere la derniere reference
|
||||||
var last = value_ref,
|
value_ref = FormBuilder.fetchRef(ref_table, value_ref);
|
||||||
curr = value_ref;
|
|
||||||
|
|
||||||
// On var jusqu'a la valeur
|
|
||||||
while( FormBuilder.regex.ref_pri.test(curr) ){
|
|
||||||
last = curr;
|
|
||||||
curr = ref_table[ curr ];
|
|
||||||
|
|
||||||
if( curr instanceof Array )
|
|
||||||
curr = curr[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// On attribut la valeur modifiee
|
// On attribut la valeur modifiee
|
||||||
ref_table[ last ] = this.value;
|
ref_table[ value_ref ] = this.value;
|
||||||
|
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
// {5} Sinon gestion des attributs //
|
// {5} Sinon gestion des attributs //
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
if( !definition.hasOwnProperty('observers') )
|
definition.hasOwnProperty('observers') || (definition.observers = []);
|
||||||
definition.observers = [];
|
|
||||||
|
|
||||||
// On met un observer sur les attributs + on lui passe la definition actuelle
|
// On met un observer sur les attributs + on lui passe la definition actuelle
|
||||||
var obs = new MutationObserver(
|
var obs = new MutationObserver(
|
||||||
(function(def){
|
(function(def, rt){
|
||||||
return function(ev){ return FormBuilder.DOMUpdates(def, ev) };
|
return function(ev){ return FormBuilder.DOMUpdates(def, ev, rt) };
|
||||||
})(definition)
|
})(definition, ref_table)
|
||||||
);
|
);
|
||||||
obs.observe(built[b].node[n], FormBuilder.observe.attributes);
|
obs.observe(built[b].node[n], FormBuilder.observe.attributes);
|
||||||
|
|
||||||
|
@ -1517,15 +1526,38 @@ FormBuilder.fetchNodeType = function(definition){
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
FormBuilder.DOMUpdates = function(definition, events){
|
FormBuilder.DOMUpdates = function(definition, events, ref_table){
|
||||||
var e;
|
var e, attr, ref,
|
||||||
|
r = FormBuilder.regex.ref_pri;
|
||||||
|
|
||||||
|
|
||||||
/* [1] On parcourt chaque évènement
|
/* [1] On parcourt chaque évènement
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
for( e in events){
|
for( e in events){
|
||||||
|
|
||||||
console.log( definition, events[e] );
|
attr = events[e].attributeName;
|
||||||
|
|
||||||
|
// Si l'attribut existe
|
||||||
|
if( definition.hasOwnProperty('attributes') && definition.attributes.hasOwnProperty(attr) )
|
||||||
|
|
||||||
|
ref = definition.attributes[attr];
|
||||||
|
|
||||||
|
// s'il n'y a qu'une référence
|
||||||
|
if( ref instanceof Array && ref.length == 1 && r.test(ref[0]) || r.test(ref) ){
|
||||||
|
|
||||||
|
ref = ref[0] || ref;
|
||||||
|
|
||||||
|
// On récupère la dernière référence
|
||||||
|
ref = FormBuilder.fetchRef(ref_table, ref);
|
||||||
|
|
||||||
|
// On met à jour la valeur
|
||||||
|
ref_table[ ref ] = events[e].target.getAttribute(attr);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// console.log( definition, events[e] );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue