_ master origin/HEAD origin/master
authorDaniel Abrecht <daniel.abrecht@hotmail.com>
Sun, 24 May 2015 18:32:28 +0000 (20:32 +0200)
committerDaniel Abrecht <daniel.abrecht@hotmail.com>
Sun, 24 May 2015 18:32:28 +0000 (20:32 +0200)
MVSync.js
MVSync.min.js

index a1357d7..3497b30 100644 (file)
--- a/MVSync.js
+++ b/MVSync.js
@@ -127,6 +127,8 @@ function Template(template){
               }
               if(b.what=="attribute"){
                 setAttr(b.element,b.which,value);
+              }else if(b.what=="style"){
+                setStyle(b.element,b.which,value);
               }else if(b.what=="content"){
                 setContent(b.element,value);
               }
@@ -164,7 +166,11 @@ function Template(template){
       if(name in element)
         element[name] = value;
       else
-        element.setAttribute(name,value);
+        element.setAttribute(name,value===undefined?"":value);
+    }
+
+    function setStyle(element,name,value){
+      element.style[name] = value===undefined?"":value;
     }
 
     function setContent(element,value){
@@ -186,13 +192,17 @@ function Template(template){
           var b = bind[i].split(":");
           var expr = b[1];
           var name = expr.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(.*)/)[1];
-          var attr = b[0];
+          var style = b[0].substr(0,1) == "@";
+          var attr = style?b[0].substr(1):b[0];
           var value = evaluateExpression(expr);
-          setAttr(e,attr,value);
+          if(style)
+            setStyle(e,attr,value);
+          else
+            setAttr(e,attr,value);
           mapping[name] = mapping[name] || [];
           mapping[name].push({
             which: attr,
-            what: "attribute",
+            what: style?"style":"attribute",
             type: "value",
             expr: expr,
             element: e
index 15838c2..217823f 100644 (file)
@@ -1,12 +1,12 @@
-(function(){function x(){Object.observe(p,function(c){c.forEach(function(c){"add"==c.type&&D(c.name)})})}function E(c){function g(g){function q(a){a.forEach(function(a){t(a.name)})}function y(a){try{return(new Function("v","return v."+a+";"))(g)}catch(c){return null}}function t(a){if(a in k)for(var c in k[a])(function(){var b=k[a][c],f=null;b.a&&(f=y(b.a));var e=null;switch(b.type){case "getter":var d=A[a+b.a]=l[b.which]=A[a+b.a]||l[b.which]||{};m[b.which]&&(d.k=m[b.which]);var h=function(a){for(d.i=
-a;d.b.length;){var e=d.b.pop();(new Function("s","n","v","s[n]"+b.a+"=v;")).call(g,g,e,a)}};d.b=d.b||[];d.b.length||(e=f(),e instanceof Function?e(h):h(e));d.b.push(b.which);break;case "setter":e=B[a+b.a]=m[b.which]=B[a+b.a]||m[b.which]||{};(l[b.which]||l[b.which]||{}).k=e;e.d=f;break;case "value":e=f;a in l&&l[a].i==e||(f=null,a in l&&(f=l[a].k.d,delete l[a].i),!f&&a in m&&(f=m[a].d),f&&(f=f(e))&&f());"attribute"==b.e?u(b.element,b.which,e):"content"==b.e&&v(b.element,e);break;case "map":b.update()}})()}
-function u(a,c,b){c in a?a[c]=b:a.setAttribute(c,b)}function v(a,c){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;c instanceof Node?(b=c.cloneNode(!0),z(b),a.appendChild(b)):a.appendChild(document.createTextNode(c||""))}function z(a){function c(d){var b=a[d]||a.getAttribute(d),e;for(e in k){var f=k[e],h;for(h in f){var r=f[h];"value"==r.type&&r.which==d&&(new Function("s","v","if(s."+r.a+".toString()!=v)s."+r.a+"=Object(s."+
-r.a+").constructor(v);")).call(g,g,b)}}}var b=a.getAttribute("data-bind");if(b)for(var b=b.split("\u00a6"),f=0;f<b.length;f++){var e=b[f].split(":"),d=e[1],h=d.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(.*)/)[1],e=e[0],l=y(d);u(a,e,l);k[h]=k[h]||[];k[h].push({which:e,e:"attribute",type:"value",a:d,element:a})}if(f=a.getAttribute("data-content"))d=f.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(.*)/),h=d[1],d=f,l=y(d),v(a,l),k[h]=k[h]||[],k[h].push({e:"content",type:"value",a:d,element:a});if(b=a.getAttribute("data-getter"))for(b=
-b.split("\u00a6"),f=0;f<b.length;f++)e=b[f].split(":"),d=e[1],h=d.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(.*)/)[1],e=e[0],k[h]=k[h]||[],k[h].push({which:e,type:"getter",a:d,element:a});if(b=a.getAttribute("data-setter"))for(b=b.split("\u00a6"),f=0;f<b.length;f++)e=b[f].split(":"),d=e[1],h=d.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(.*)/)[1],e=e[0],k[h]=k[h]||[],k[h].push({which:e,type:"setter",a:d,element:a});"MutationObserver"in window?(new MutationObserver(function(a){a.forEach(function(a){c(a.attributeName)})})).observe(a,
-{attributes:!0}):"value"in a&&(a.addEventListener("change",c.bind(null,"value"),!1),a.addEventListener("input",c.bind(null,"value"),!1));"value"in a&&a.addEventListener("change",function(){a.setAttribute("value",a.value)});if(f=a.getAttribute("data-map")){var n=f.split(":"),d=n[0].match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(.*)/),h=d[1],d=d[2],m=function(){if(n[1]in w){var b=g[h];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(){C(a.c,
-b,a,w[n[1]])});C(a.c,b,a,w[n[1]])}else(p[n[1]]=p[n[1]]||[]).push(m)};(k[n[0]]=k[n[0]]||[]).push({type:"map",update:m});m()}if(!f)for(f=0;f<a.children.length;f++)z(a.children[f])}function C(a,c,b,f){for(var e=[],d=0;d<c.length;d++)c[d]instanceof Object&&-1==e.indexOf(c[d])&&e.push(c[d]);c=a.o;a=a.n;for(d=c.length;d--;)-1==e.indexOf(c[d])&&(a[d].element.parentNode&&a[d].element.parentNode.removeChild(a[d].element),c.splice(d,1),a.splice(d,1));for(d=0;d<e.length;d++){var h=c.indexOf(e[d]);if(-1!=h)a[h].index=
-d;else{h={element:f.h(e[d]),index:d};if(a.length){var g=a[a.length-1].element;g.parentNode==b?b.insertBefore(h.element,g.nextSibling):b.appendChild(h.element)}else b.appendChild(h.element);c.push(e[d]);a.push(h)}}for(d=0;d<a.length;d++)e=a[d],e.index!=d&&(b=e.element,f=a[e.index].element,h=e.index,a[d]=[a[h],a[h]=a[d]][0],e=e.index,c[d]=[c[e],c[e]=c[d]][0],e=b.parentNode,h=f.parentNode,e&&h&&(g=b.nextSibling,h.insertBefore(b,f.nextSibling),e.insertBefore(f,g)))}Object.defineProperty(g,"this",{configurable:!0,
-writable:!0,enumerable:!1,value:g});var k={},A={},l={},B={},m={};this.g=[];this.root=c instanceof HTMLHtmlElement?c:c.cloneNode(!0);this.root.l=this;this.root.classList.add(F);this.f=function(){Object.r(this.j.m,this.j.d);for(var a=0;a<this.g.length;a++)this.g[a].f()};z(this.root);this.j={m:Object.observe(g,q),d:q};for(var x in g)t(x)}c.removeAttribute("data-template");var F=c.p;c.q=this;this.h=function(c){return(new g(c)).root}}function t(c){var g=c.getAttribute("data-template");!g&&c instanceof
-HTMLHtmlElement&&(g="root");!c.parentNode||c instanceof HTMLHtmlElement||c.parentNode.removeChild(c);c.p=g;c=w[g]=new E(c);if(g in p){for(;p[g].length;)p[g].pop()();delete p[g]}return c}function u(c){"querySelectorAll"in c&&(c=c.querySelectorAll("[data-template]"));for(var g=0;g<c.length;g++)t(c[g])}function D(c){var g=new XMLHttpRequest;g.open("GET",q+"templates/"+c+".html",!0);g.onload=function(){var c=null;if(!c){var c=document.createDocumentFragment(),g=document.createElement("div");g.innerHTML=
-this.responseText;c.appendChild(g)}u(c)};g.send()}window.model=window.model||{};var w={},p={},q="/",v=!1;window.initMVSync=function(c){!v&&("complete"==document.readyState||"loaded"==document.readyState||"interactive"==document.readyState||c)&&"observe"in Object&&(v=!0,window.templateRoot?q=window.templateRoot+"/":document.querySelector("[data-template-root]")&&(q=document.querySelector("[data-template-root]").getAttribute("data-template-root")+"/"),x(),u(document),t(document.documentElement).h(model))}})();
-addEventListener("load",initMVSync.bind(null,!0));addEventListener("DOMContentLoaded",initMVSync.bind(null,!0));initMVSync(!1);
+(function(){function y(){Object.observe(p,function(c){c.forEach(function(c){"add"==c.type&&E(c.name)})})}function F(c){function g(g){function q(a){a.forEach(function(a){u(a.name)})}function z(a){try{return(new Function("v","return v."+a+";"))(g)}catch(c){return null}}function u(a){if(a in k)for(var c in k[a])(function(){var b=k[a][c],f=null;b.a&&(f=z(b.a));var e=null;switch(b.type){case "getter":var d=B[a+b.a]=l[b.which]=B[a+b.a]||l[b.which]||{};m[b.which]&&(d.o=m[b.which]);var h=function(a){for(d.l=
+a;d.b.length;){var e=d.b.pop();(new Function("s","n","v","s[n]"+b.a+"=v;")).call(g,g,e,a)}};d.b=d.b||[];d.b.length||(e=f(),e instanceof Function?e(h):h(e));d.b.push(b.which);break;case "setter":e=C[a+b.a]=m[b.which]=C[a+b.a]||m[b.which]||{};(l[b.which]||l[b.which]||{}).o=e;e.f=f;break;case "value":e=f;a in l&&l[a].l==e||(f=null,a in l&&(f=l[a].o.f,delete l[a].l),!f&&a in m&&(f=m[a].f),f&&(f=f(e))&&f());"attribute"==b.g?v(b.element,b.which,e):"style"==b.g?b.element.style[b.which]=void 0===e?"":e:"content"==
+b.g&&w(b.element,e);break;case "map":b.update()}})()}function v(a,c,b){c in a?a[c]=b:a.setAttribute(c,void 0===b?"":b)}function w(a,c){for(;a.childNodes.length;){var b=a.childNodes[a.childNodes.length-1];b.s&&b.s.h();a.removeChild(b)}"_content"in a&&delete a.c;c instanceof Node?(b=c.cloneNode(!0),A(b),a.appendChild(b)):a.appendChild(document.createTextNode(c||""))}function A(a){function c(b){var d=a[b]||a.getAttribute(b),e;for(e in k){var f=k[e],h;for(h in f){var r=f[h];"value"==r.type&&r.which==
+b&&(new Function("s","v","if(s."+r.a+".toString()!=v)s."+r.a+"=Object(s."+r.a+").constructor(v);")).call(g,g,d)}}}var b=a.getAttribute("data-bind");if(b)for(var b=b.split("\u00a6"),f=0;f<b.length;f++){var e=b[f].split(":"),d=e[1],h=d.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(.*)/)[1],l="@"==e[0].substr(0,1),e=l?e[0].substr(1):e[0],m=z(d);l?a.style[e]=void 0===m?"":m:v(a,e,m);k[h]=k[h]||[];k[h].push({which:e,g:l?"style":"attribute",type:"value",a:d,element:a})}if(f=a.getAttribute("data-content"))d=f.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(.*)/),
+h=d[1],d=f,m=z(d),w(a,m),k[h]=k[h]||[],k[h].push({g:"content",type:"value",a:d,element:a});if(b=a.getAttribute("data-getter"))for(b=b.split("\u00a6"),f=0;f<b.length;f++)e=b[f].split(":"),d=e[1],h=d.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(.*)/)[1],e=e[0],k[h]=k[h]||[],k[h].push({which:e,type:"getter",a:d,element:a});if(b=a.getAttribute("data-setter"))for(b=b.split("\u00a6"),f=0;f<b.length;f++)e=b[f].split(":"),d=e[1],h=d.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(.*)/)[1],e=e[0],k[h]=k[h]||[],k[h].push({which:e,
+type:"setter",a:d,element:a});"MutationObserver"in window?(new MutationObserver(function(a){a.forEach(function(a){c(a.attributeName)})})).observe(a,{attributes:!0}):"value"in a&&(a.addEventListener("change",c.bind(null,"value"),!1),a.addEventListener("input",c.bind(null,"value"),!1));"value"in a&&a.addEventListener("change",function(){a.setAttribute("value",a.value)});if(f=a.getAttribute("data-map")){var n=f.split(":"),d=n[0].match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)(.*)/),h=d[1],d=d[2],t=function(){if(n[1]in
+x){var b=g[h];b&&(b=Object((new Function("v","return v"+d+";"))(b)));b||(b=[]);"length"in b||(b=[b]);a.c=a.c||{w:[],v:[]};Object.observe(b,function(){D(a.c,b,a,x[n[1]])});D(a.c,b,a,x[n[1]])}else(p[n[1]]=p[n[1]]||[]).push(t)};(k[n[0]]=k[n[0]]||[]).push({type:"map",update:t});t()}if(!f)for(f=0;f<a.children.length;f++)A(a.children[f])}function D(a,c,b,f){for(var e=[],d=0;d<c.length;d++)c[d]instanceof Object&&-1==e.indexOf(c[d])&&e.push(c[d]);c=a.w;a=a.v;for(d=c.length;d--;)-1==e.indexOf(c[d])&&(a[d].element.parentNode&&
+a[d].element.parentNode.removeChild(a[d].element),c.splice(d,1),a.splice(d,1));for(d=0;d<e.length;d++){var h=c.indexOf(e[d]);if(-1!=h)a[h].index=d;else{h={element:f.j(e[d]),index:d};if(a.length){var g=a[a.length-1].element;g.parentNode==b?b.insertBefore(h.element,g.nextSibling):b.appendChild(h.element)}else b.appendChild(h.element);c.push(e[d]);a.push(h)}}for(d=0;d<a.length;d++)e=a[d],e.index!=d&&(b=e.element,f=a[e.index].element,h=e.index,a[d]=[a[h],a[h]=a[d]][0],e=e.index,c[d]=[c[e],c[e]=c[d]][0],
+e=b.parentNode,h=f.parentNode,e&&h&&(g=b.nextSibling,h.insertBefore(b,f.nextSibling),e.insertBefore(f,g)))}Object.defineProperty(g,"this",{configurable:!0,writable:!0,enumerable:!1,value:g});var k={},B={},l={},C={},m={};this.i=[];this.root=c instanceof HTMLHtmlElement?c:c.cloneNode(!0);this.root.s=this;this.root.classList.add(t);this.h=function(){Object.C(this.m.u,this.m.f);for(var a=0;a<this.i.length;a++)this.i[a].h()};A(this.root);this.m={u:Object.observe(g,q),f:q};for(var y in g)u(y)}c.removeAttribute("data-template");
+var t=c.A;c.B=this;this.j=function(c){return(new g(c)).root}}function u(c){var g=c.getAttribute("data-template");!g&&c instanceof HTMLHtmlElement&&(g="root");!c.parentNode||c instanceof HTMLHtmlElement||c.parentNode.removeChild(c);c.A=g;c=x[g]=new F(c);if(g in p){for(;p[g].length;)p[g].pop()();delete p[g]}return c}function v(c){"querySelectorAll"in c&&(c=c.querySelectorAll("[data-template]"));for(var g=0;g<c.length;g++)u(c[g])}function E(c){var g=new XMLHttpRequest;g.open("GET",q+"templates/"+c+".html",
+!0);g.onload=function(){var c=null;if(!c){var c=document.createDocumentFragment(),g=document.createElement("div");g.innerHTML=this.responseText;c.appendChild(g)}v(c)};g.send()}window.model=window.model||{};var x={},p={},q="/",w=!1;window.initMVSync=function(c){!w&&("complete"==document.readyState||"loaded"==document.readyState||"interactive"==document.readyState||c)&&"observe"in Object&&(w=!0,window.templateRoot?q=window.templateRoot+"/":document.querySelector("[data-template-root]")&&(q=document.querySelector("[data-template-root]").getAttribute("data-template-root")+
+"/"),y(),v(document),u(document.documentElement).j(model))}})();addEventListener("load",initMVSync.bind(null,!0));addEventListener("DOMContentLoaded",initMVSync.bind(null,!0));initMVSync(!1);
\ No newline at end of file