bugfix
[knw_133/js/MVSync/.git] / MVSync.min.js
1 (function(){function v(){Object.observe(n,function(e){e.forEach(function(e){"add"==e.type&&C(e.name)})})}function D(e){function f(f){function q(a){a.forEach(function(a){r(a.name)})}function w(a){try{return(new Function("v","return v."+a+";"))(f)}catch(g){return null}}function r(a){if(a in k)for(var g in k[a])(function(){var b=k[a][g],h=null;b.a&&(h=w(b.a));var d=null;switch(b.type){case "getter":var c=y[a+b.a]=l[b.which]=y[a+b.a]||l[b.which]||{};p[b.which]&&(c.k=p[b.which]);var e=function(a){for(c.i=
2 a;c.b.length;){var d=c.b.pop();(new Function("s","n","v","s[n]"+b.a+"=v;")).call(f,f,d,a)}};c.b=c.b||[];c.b.length||(d=h(),d instanceof Function?d(e):e(d));c.b.push(b.which);break;case "setter":d=z[a+b.a]=p[b.which]=z[a+b.a]||p[b.which]||{};(l[b.which]||l[b.which]||{}).k=d;d.d=h;break;case "value":d=h;a in l&&l[a].i==d||(h=null,a in l&&(h=l[a].k.d,delete l[a].i),!h&&a in p&&(h=p[a].d),h&&(h=h(d))&&h());"attribute"==b.e?t(b.element,b.which,d):"content"==b.e&&A(b.element,d);break;case "map":b.update()}})()}
3 function t(a,g,b){g in a?a[g]=b:a.setAttribute(g,b)}function A(a,g){for(;a.childNodes.length;){var b=a.childNodes[a.childNodes.length-1];b.l&&b.l.f();a.removeChild(b)}"_content"in a&&delete a.c;g instanceof Node?(b=g.cloneNode(!0),x(b),a.appendChild(b)):a.appendChild(document.createTextNode(g||""))}function x(a){var g=a.getAttribute("data-bind");if(g)for(var g=g.split("\u00a6"),b=0;b<g.length;b++){var h=g[b].split(":"),d=h[1],c=d.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(.*)/)[1],h=h[0],e=w(d);t(a,h,e);
4 k[c]=k[c]||[];k[c].push({which:h,e:"attribute",type:"value",a:d,element:a})}if(b=a.getAttribute("data-content"))d=b.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(.*)/),c=d[1],d=b,e=w(d),A(a,e),k[c]=k[c]||[],k[c].push({e:"content",type:"value",a:d,element:a});if(g=a.getAttribute("data-getter"))for(g=g.split("\u00a6"),b=0;b<g.length;b++)h=g[b].split(":"),d=h[1],c=d.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(.*)/)[1],h=h[0],k[c]=k[c]||[],k[c].push({which:h,type:"getter",a:d,element:a});if(g=a.getAttribute("data-setter"))for(g=
5 g.split("\u00a6"),b=0;b<g.length;b++)h=g[b].split(":"),d=h[1],c=d.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(.*)/)[1],h=h[0],k[c]=k[c]||[],k[c].push({which:h,type:"setter",a:d,element:a});(new MutationObserver(function(b){b.forEach(function(b){b=b.attributeName;var c=a.getAttribute(b),d;for(d in k){var g=k[d],e;for(e in g){var h=g[e];"value"==h.type&&h.which==b&&(new Function("s","v","if(s."+h.a+".toString()!=v)s."+h.a+"=Object(s."+h.a+").constructor(v);")).call(f,f,c)}}})})).observe(a,{attributes:!0});"value"in
6 a&&a.addEventListener("change",function(){a.setAttribute("value",a.value)});if(b=a.getAttribute("data-map")){var m=b.split(":"),d=m[0].match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(.*)/),c=d[1],d=d[2],l=function(){if(m[1]in u){var b=f[c];b&&(b=Object((new Function("v","return v"+d+";"))(b)));b||(b=[]);"length"in b||(b=[b]);a.c=a.c||{o:[],n:[]};Object.observe(b,function(){B(a.c,b,a,u[m[1]])});B(a.c,b,a,u[m[1]])}else(n[m[1]]=n[m[1]]||[]).push(l)};(k[m[0]]=k[m[0]]||[]).push({type:"map",update:l});l()}if(!b)for(b=
7 0;b<a.children.length;b++)x(a.children[b])}function B(a,g,b,e){for(var d=[],c=0;c<g.length;c++)g[c]instanceof Object&&-1==d.indexOf(g[c])&&d.push(g[c]);g=a.o;a=a.n;for(c=g.length;c--;)-1==d.indexOf(g[c])&&(a[c].element.parentNode&&a[c].element.parentNode.removeChild(a[c].element),g.splice(c,1),a.splice(c,1));for(c=0;c<d.length;c++){var f=g.indexOf(d[c]);if(-1!=f)a[f].index=c;else{f={element:e.h(d[c]),index:c};if(a.length){var k=a[a.length-1].element;k.parentNode==b?b.insertBefore(f.element,k.nextSibling):
8 b.appendChild(f.element)}else b.appendChild(f.element);g.push(d[c]);a.push(f)}}for(c=0;c<a.length;c++)d=a[c],d.index!=c&&(b=d.element,e=a[d.index].element,f=d.index,a[c]=[a[f],a[f]=a[c]][0],d=d.index,g[c]=[g[d],g[d]=g[c]][0],d=b.parentNode,f=e.parentNode,d&&f&&(k=b.nextSibling,f.insertBefore(b,e.nextSibling),d.insertBefore(e,k)))}Object.defineProperty(f,"this",{configurable:!0,writable:!0,enumerable:!1,value:f});var k={},y={},l={},z={},p={};this.g=[];this.root=e instanceof HTMLHtmlElement?e:e.cloneNode(!0);
9 this.root.l=this;this.root.classList.add(E);this.f=function(){Object.r(this.j.m,this.j.d);for(var a=0;a<this.g.length;a++)this.g[a].f()};x(this.root);this.j={m:Object.observe(f,q),d:q};for(var v in f)r(v)}e.removeAttribute("data-template");var E=e.p;e.q=this;this.h=function(e){return(new f(e)).root}}function r(e){var f=e.getAttribute("data-template");!f&&e instanceof HTMLHtmlElement&&(f="root");!e.parentNode||e instanceof HTMLHtmlElement||e.parentNode.removeChild(e);e.p=f;e=u[f]=new D(e);if(f in n){for(;n[f].length;)n[f].pop()();
10 delete n[f]}return e}function t(e){"querySelectorAll"in e&&(e=e.querySelectorAll("[data-template]"));for(var f=0;f<e.length;f++)r(e[f])}function C(e){var f=new XMLHttpRequest;f.open("GET",q+"templates/"+e+".html",!0);f.onload=function(){var e=null;if(!e){var e=document.createDocumentFragment(),f=document.createElement("div");f.innerHTML=this.responseText;e.appendChild(f)}t(e)};f.send()}window.model=window.model||{};var u={},n={},q="/";addEventListener("load",function(){window.templateRoot?q=window.templateRoot+
11 "/":document.querySelector("[data-template-root]")&&(q=document.querySelector("[data-template-root]").getAttribute("data-template-root")+"/");v();t(document);r(document.documentElement).h(model)})})();