From a6c1c8c8cf2c21245c42733dcf72fadc3c7e0460 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Fri, 23 Sep 2016 17:15:18 +0200 Subject: [PATCH] Ajout observer sur les attributs --- js/lib/form-builder-min-min.js | 1 + js/lib/form-builder-min.js | 9 +++++---- js/lib/form-builder.js | 27 +++++++++++++++++++-------- 3 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 js/lib/form-builder-min-min.js diff --git a/js/lib/form-builder-min-min.js b/js/lib/form-builder-min-min.js new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/js/lib/form-builder-min-min.js @@ -0,0 +1 @@ + diff --git a/js/lib/form-builder-min.js b/js/lib/form-builder-min.js index 17ff805..9ca553e 100644 --- a/js/lib/form-builder-min.js +++ b/js/lib/form-builder-min.js @@ -20,10 +20,11 @@ FormBuilder.createElements=function(a,b,d){var e=FormBuilder.debugStart("FormBui 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",2);FormBuilder.debugStop(e);return a.dom=f}; +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",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]), 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, -[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){for(var b in a)console.log(a[b]),console.log(a[b].target),console.log(a[b].type)}; +[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])}; diff --git a/js/lib/form-builder.js b/js/lib/form-builder.js index 8d7d42f..bc0e059 100644 --- a/js/lib/form-builder.js +++ b/js/lib/form-builder.js @@ -1284,7 +1284,7 @@ FormBuilder.createElements = function(definition, ref_table, ref_assoc){ } // {4} Si de type texte // - if( input ){ + else if( input ){ // On met à jour la valeur built[b].node[n].addEventListener('input', function(e){ @@ -1315,10 +1315,23 @@ FormBuilder.createElements = function(definition, ref_table, ref_assoc){ }, false); + // {5} Sinon gestion des attributs // + }else{ + + if( !definition.hasOwnProperty('observers') ) + definition.observers = []; + + // On met un observer sur les attributs + on lui passe la definition actuelle + var obs = new MutationObserver( + (function(def){ + return function(ev){ return FormBuilder.DOMUpdates(def, ev) }; + })(definition) + ); + obs.observe(built[b].node[n], FormBuilder.observe.attributes); + + definition.observers.push(obs); + } - - // TODO: Gestion de la transmission de 'value' / 'selected' lors de la construction - } } @@ -1504,7 +1517,7 @@ FormBuilder.fetchNodeType = function(definition){ }; -FormBuilder.DOMUpdates = function(events){ +FormBuilder.DOMUpdates = function(definition, events){ var e; @@ -1512,9 +1525,7 @@ FormBuilder.DOMUpdates = function(events){ =========================================================*/ for( e in events){ - console.log( events[e] ); - console.log( events[e].target ); - console.log( events[e].type ); + console.log( definition, events[e] );