-
Notifications
You must be signed in to change notification settings - Fork 7
/
iugo-bind_to_dom.min.js
2 lines (2 loc) · 2.97 KB
/
iugo-bind_to_dom.min.js
1
2
/* Author Chris Scott, MIT license */
$iugo.store.BD={a:[],b:{},f:0};$iugo.initializers.push(function(a){for(var l=/(>[^<]*)\$\{([^:.}<]+:)?([^}<]*)\}([^<]*<)/g;a.innerHTML.match(l);)a.innerHTML=a.innerHTML.replace(l,function(h,a,p,d,f){h=a+"<span ";p&&(h+='class="bindto-'+p.substr(0,p.length-1)+'" ');return h+('data-bind_key="'+d+'"></span>'+f)});a.innerHTML=a.innerHTML.replace(/<[^>]+ [^ =]+="[^"]*\$\{[^}<"]+\}[^"]*"[^>]*>/g,function(a){var e=$iugo.store.BD.f++;$iugo.store.BD.a[e]={d:[],c:{},e:{}};a=a.replace(/([^ =]+)="([^"]*\$\{[^}"]+\}[^"]*)"/g,function(a,d,f){"data-iugo_alias-"==d.substr(0,16)&&(d=d.substr(16));$iugo.store.BD.a[e].d.push(d);$iugo.store.BD.a[e].c[d]=f;f.replace(/\$\{([^"}:]+):[^}"]+\}/g,function(a,d){$iugo.store.BD.b[d]||($iugo.store.BD.b[d]=[]);-1==$iugo.store.BD.b[d].indexOf(e)&&$iugo.store.BD.b[d].push(e)});return d+'=""'});return a=a.replace(/ ?>$/,' data-iugo_id="'+e+'">')})});$iugo.defaultViewcontrollers.push(function(a,l,h){function e(n){for(var c=document.querySelector('[data-iugo_id="'+n+'"]'),g=$iugo.store.BD.a[n].d,b=0;b<g.length;b++){var a=$iugo.store.BD.a[n].c[g[b]].replace(s,function(b){return $iugo.store.BD.a[n].e[b]?$iugo.store.BD.a[n].e[b]:""});c.setAttribute(g[b],a)}}function p(n,c,a){if(c.hasAttribute("data-iugo_id")){var b=c.getAttribute("data-iugo_id");c=$iugo.store.BD.a[b].d;for(var d=0;d<c.length;d++)$iugo.store.BD.a[b].c[c[d]].replace(s,function(c,d,f){if(!d&&!a||d&&d.substr(0,d.length-1)==a){d=f.split(".");f=n;for(var e=0;e<d.length;e++)""!=d[e]&&(f=f[d[e]]);$iugo.store.BD.a[b].e[c]=f}});e(b)}}function d(d){var c=d.getAttribute("data-iugo_id"),a=$iugo.store.BD.f++,c=$iugo.store.BD.a[c];$iugo.store.BD.a[a]={d:c.d,c:c.c,e:{}};d.setAttribute("data-iugo_id",a)}function f(a,c,g){p(a,c);if(a instanceof Array){g=c.children.length;for(var b=g-1;0<=b;b--)c.children[b].classList.contains("iugo_cloned")&&c.removeChild(c.children[b]);g=c.children.length;for(b=0;b<g;b++){var e;if(c.children[b].hasAttribute("data-bind_each")){e=c.children[b];0==a.length?(e.setAttribute("data-iugo_display",e.style.display),e.style.display="none"):e.style.display=e.getAttribute("data-iugo_display");for(var h=0;h<a.length;h++){var m;if(1<=h){m=e.cloneNode(!0);m.classList.add("iugo_cloned");m.hasAttribute("data-iugo_id")&&d(m);for(var k=m.querySelectorAll("[data-iugo_id]"),l=0;l<k.length;l++)d(k[l]);c.appendChild(m)}else m=e;f(a[h],m)}}}}else if(a instanceof Object)if(b=c.getAttribute("data-bind_key"),null!=b&&""!=b)g=null==g?"":g+".",b=b.slice(g.length).split(".")[0],f(a[b],c,g+b);else for(b=0;b<c.children.length;b++)c.children[b].className.match("bindto-")||f(a,c.children[b],g);else if(0<c.children.length)for(b=0;b<c.children.length;b++)f(a,c.children[b],g);else"INPUT"==c.tagName?c.value=a:c.innerHTML=a}var s=/\$\{([^:}]+:)?([^}]+)\}/g;if($iugo.store.BD.b[a])for(var t=$iugo.store.BD.b[a],k=0;k<t.length;k++)for(var q=h.querySelectorAll('[data-iugo_id="'+t[k]+'"]'),r=0;r<q.length;r++)p(l,q[r],a);q=h.getElementsByClassName("bindto-"+a);for(k=0;k<q.length;k++)f(l,q[k])});