From 3ed758b58ab932315dfe6d8e8e06d3b5cf366258 Mon Sep 17 00:00:00 2001 From: RubyLouvre Date: Tue, 18 Nov 2014 14:45:55 +0800 Subject: [PATCH 01/18] fix getEachProxy BUG --- avalon.js | 7 +++-- avalon.min.js | 24 ++++++++--------- avalon.modern.js | 3 +++ avalon.modern.min.js | 60 ++++++++++++++++++++--------------------- examples/avalon.shim.js | 39 ++++++++++++++++++--------- 5 files changed, 76 insertions(+), 57 deletions(-) diff --git a/avalon.js b/avalon.js index 53928681a..95e6f1188 100644 --- a/avalon.js +++ b/avalon.js @@ -1708,7 +1708,7 @@ if (tag === "tr") { for (els = wrapper.children, i = 0; el = els[i++]; ) { // IE6-8,如果动态生成tr元素,必须会在后面添加早已废弃caption的标签,其nodeName,innerHTML都为"" - if (el.nodeName == "") { + if (el.nodeName === "") { el.parentNode.removeChild(el) i-- } @@ -3674,7 +3674,7 @@ } } data.bound("change", updateVModel) - checkScan(element,function() { + checkScan(element, function() { //先等到select里的option元素被扫描后,才根据model设置selected属性 registerSubscriber(data) data.changed.call(element, evaluator(), data) @@ -4084,6 +4084,9 @@ proxy[k] = source[k] } eachProxyPool.splice(i, 1) + proxy.$watch(param, function(val) { + data.$repeat.set(proxy.$index, val) + }) return proxy } } diff --git a/avalon.min.js b/avalon.min.js index 4126c3bc4..8747518d1 100644 --- a/avalon.min.js +++ b/avalon.min.js @@ -23,18 +23,18 @@ try{c=Function.apply(y,l.concat(n)),d.evaluator=Ea(g,c)}catch(H){v("debug: parse function wc(b){var c={},d;for(d in b)c[d]=b[d];d=c.target=b.srcElement;0===b.type.indexOf("key")?c.which=null!=b.charCode?b.charCode:b.keyCode:/mouse|click/.test(b.type)&&(d=d.ownerDocument||p,d="BackCompat"===d.compatMode?d.body:d.documentElement,c.pageX=b.clientX+(d.scrollLeft>>0)-(d.clientLeft>>0),c.pageY=b.clientY+(d.scrollTop>>0)-(d.clientTop>>0),c.wheelDeltaY=c.wheelDelta,c.wheelDeltaX=0);c.timeStamp=new Date-0;c.originalEvent=b;c.preventDefault=function(){b.returnValue=!1};c.stopPropagation= function(){b.cancelBubble=!0};return c}function Xb(b){var c=[];c.$id=ha();c.$model=b;c.$events={};c.$events[G]=[];c._=N({length:b.length});c._.$watch("length",function(b,d){c.$fire("length",b,d)});for(var d in R)c[d]=R[d];avalon.mix(c,Ab);return c}function Bb(b,c,d,e){var f=avalon.parseHTML(b.template),g=avalon.slice(f.childNodes);c.appendChild(f);d.$outer=b.$outer;b=b.vmodels;d=[d].concat(b);d.cb=b.cb;e.push({nodes:g,vmodels:d})}function Ha(b,c){var d=b.endRepeat,e=[],f=b.element.nextSibling;if(f!== d){do if(f!==d)e.push(f);else break;while(f=f.nextSibling)}return e[b.group*c]||d}function Cb(b,c,d){c*=d||1;d=[b];for(var e=1,f=I;eu.maxRepeatSize&&da.pop()}b.length=0}function T(){p.body&&(D?(s["ready!"].state=2,D.checkDeps()):Fb.forEach(function(b){b(avalon)}),T=y)}function Gb(){try{B.doScroll("left"),T()}catch(b){setTimeout(Gb)}}var A=new Date-0,G="$"+A,r=Function("return this")(),Ac=r.require,Bc=r.define,ja=!1,z=/[^, ]+/g,Hb=/\[native code\]/,wa=/^(?:object|array)$/,Ib=/^\[object SVG\w*Element\]$/,Vb=/^\[object (?:Window|DOMWindow|global)\]$/, -Ia=Object.prototype,O=Ia.hasOwnProperty,ia=Ia.toString,L=Array.prototype,$=L.slice,Y={},w=r.dispatchEvent,B=p.documentElement,J=p.getElementsByTagName("head")[0],I=p.createDocumentFragment(),ea=p.createElement("div"),Jb={};"Boolean Number String Function Array Date RegExp Object Error".replace(z,function(b){Jb["[object "+b+"]"]=b.toLowerCase()});avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]=this.element=b};avalon.fn=avalon.prototype=avalon.init.prototype;avalon.type= -function(b){return null==b?String(b):"object"===typeof b||"function"===typeof b?Jb[ia.call(b)]||"object":typeof b};var V="object"===typeof alert?function(b){try{return/^\s*\bfunction\b/.test(b+"")}catch(c){return!1}}:function(b){return"[object Function]"==ia.call(b)};avalon.isFunction=V;avalon.isWindow=function(b){return!b?!1:b==b.document&&b.document!=b};Ya(r)&&(avalon.isWindow=Ya);for(var Cc in avalon({}))break;var Dc="0"!==Cc;avalon.isPlainObject=function(b,c){if(!b||"object"!==avalon.type(b)|| -b.nodeType||avalon.isWindow(b))return!1;try{if(b.constructor&&!O.call(b,"constructor")&&!O.call(b.constructor.prototype,"isPrototypeOf"))return!1}catch(d){return!1}if(Dc)for(c in b)return O.call(b,c);for(c in b);return void 0===c||O.call(b,c)};Hb.test(Object.getPrototypeOf)&&(avalon.isPlainObject=function(b){return!!b&&"object"===typeof b&&Object.getPrototypeOf(b)===Ia});avalon.mix=avalon.fn.mix=function(){var b,c,d,e,f,g=arguments[0]||{},h=1,k=arguments.length,l=!1;"boolean"===typeof g&&(l=g,g=arguments[1]|| -{},h++);"object"!==typeof g&&"function"!==avalon.type(g)&&(g={});h===k&&(g=this,h--);for(;hu.maxRepeatSize&&da.pop()}b.length=0}function T(){p.body&&(D?(s["ready!"].state=2,D.checkDeps()):Fb.forEach(function(b){b(avalon)}),T=y)}function Gb(){try{B.doScroll("left"),T()}catch(b){setTimeout(Gb)}}var A=new Date-0,G="$"+A,r=Function("return this")(),Ac=r.require,Bc=r.define,ja=!1,z=/[^, ]+/g,Hb=/\[native code\]/,wa=/^(?:object|array)$/,Ib=/^\[object SVG\w*Element\]$/, +Vb=/^\[object (?:Window|DOMWindow|global)\]$/,Ia=Object.prototype,O=Ia.hasOwnProperty,ia=Ia.toString,L=Array.prototype,$=L.slice,Y={},w=r.dispatchEvent,B=p.documentElement,J=p.getElementsByTagName("head")[0],I=p.createDocumentFragment(),ea=p.createElement("div"),Jb={};"Boolean Number String Function Array Date RegExp Object Error".replace(z,function(b){Jb["[object "+b+"]"]=b.toLowerCase()});avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]=this.element=b};avalon.fn=avalon.prototype= +avalon.init.prototype;avalon.type=function(b){return null==b?String(b):"object"===typeof b||"function"===typeof b?Jb[ia.call(b)]||"object":typeof b};var V="object"===typeof alert?function(b){try{return/^\s*\bfunction\b/.test(b+"")}catch(c){return!1}}:function(b){return"[object Function]"==ia.call(b)};avalon.isFunction=V;avalon.isWindow=function(b){return!b?!1:b==b.document&&b.document!=b};Ya(r)&&(avalon.isWindow=Ya);for(var Cc in avalon({}))break;var Dc="0"!==Cc;avalon.isPlainObject=function(b,c){if(!b|| +"object"!==avalon.type(b)||b.nodeType||avalon.isWindow(b))return!1;try{if(b.constructor&&!O.call(b,"constructor")&&!O.call(b.constructor.prototype,"isPrototypeOf"))return!1}catch(d){return!1}if(Dc)for(c in b)return O.call(b,c);for(c in b);return void 0===c||O.call(b,c)};Hb.test(Object.getPrototypeOf)&&(avalon.isPlainObject=function(b){return!!b&&"object"===typeof b&&Object.getPrototypeOf(b)===Ia});avalon.mix=avalon.fn.mix=function(){var b,c,d,e,f,g=arguments[0]||{},h=1,k=arguments.length,l=!1;"boolean"=== +typeof g&&(l=g,g=arguments[1]||{},h++);"object"!==typeof g&&"function"!==avalon.type(g)&&(g={});h===k&&(g=this,h--);for(;h 0 Then","\t\t["+b+'] = [__proxy__]([__data__],"'+b+'")',"\tEnd If","\tOn Error Goto 0","\tEnd Property");f.push("End Class");b=f.join("\r\n"); b=r.findOrDefineVBClass(e,b);b===e&&r.parseVB(["Function "+e+"Factory(a, b)","\tDim o","\tSet o = (New "+e+")(a, b)","\tSet "+e+"Factory = o","End Function"].join("\r\n"));return r[b+"Factory"](c,Ec)}}if(!"\u53f8\u5f92\u6b63\u7f8e".trim){var Fc=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;String.prototype.trim=function(){return this.replace(Fc,"")}}var Gc=!{toString:null}.propertyIsEnumerable("toString"),Hc=function(){}.propertyIsEnumerable("prototype"),Kb="toString toLocaleString valueOf hasOwnProperty isPrototypeOf propertyIsEnumerable constructor".split(" "), diff --git a/avalon.modern.js b/avalon.modern.js index fa26893fe..2d289b21e 100644 --- a/avalon.modern.js +++ b/avalon.modern.js @@ -3287,6 +3287,9 @@ proxy[k] = source[k] } eachProxyPool.splice(i, 1) + proxy.$watch(param, function(val) { + data.$repeat.set(proxy.$index, val) + }) return proxy } } diff --git a/avalon.modern.min.js b/avalon.modern.min.js index fd9b458fd..e694928a3 100644 --- a/avalon.modern.min.js +++ b/avalon.modern.min.js @@ -20,36 +20,36 @@ b="\nreturn "+b+";",e=b.lastIndexOf("\nreturn"),q=b.slice(0,e),b=b.slice(e),b=q+ b+")"},qa(d))}function X(b,c){var d="_"+b;if(!X[d]){var e=p.createElement(b);D.appendChild(e);c=getComputedStyle(e,null).display;D.removeChild(e);X[d]=c}return X[d]}function ya(b){return null==b?"":b}function Ob(b,c,d){c.param.replace(/\w+/g,function(e){(e=avalon.duplexHooks[e])&&"function"===typeof e[d]&&(b=e[d](b,c))});return b}function fb(b){var c=arguments.length?b:this.value;if(!this.disabled&&this.oldValue!==c){var c=this.getAttribute("data-duplex-event")||"input",c=c.match(w).shift(),d=p.createEvent("Events"); d.initEvent(c,!0,!0);this.dispatchEvent(d)}}function Pb(){for(var b=Y.length-1;0<=b;b--)!1===(0,Y[b])()&&Y.splice(b,1);Y.length||clearInterval(gb)}function Qb(b){Rb.call(this,b);fb.call(this,b)}function wb(b){var c=[];c.$id=ba();c.$model=b;c.$events={};c.$events[F]=[];c._=K({length:b.length});c._.$watch("length",function(b,d){c.$fire("length",b,d)});for(var d in P)c[d]=P[d];avalon.mix(c,hb);return c}function ib(b,c,d,e){var f=avalon.parseHTML(b.template),g=avalon.slice(f.childNodes);c.appendChild(f); d.$outer=b.$outer;b=b.vmodels;d=[d].concat(b);d.cb=b.cb;e.push({nodes:g,vmodels:d})}function za(b,c){var d=b.endRepeat,e=[],f=b.element.nextSibling;if(f!==d){do if(f!==d)e.push(f);else break;while(f=f.nextSibling)}return e[b.group*c]||d}function jb(b,c,d){c*=d||1;d=[b];for(var e=1,f=H;es.maxRepeatSize&&Z.pop()}b.length=0}function $(){z?(r["ready!"].state=2,z.checkDeps()):lb.forEach(function(b){b(avalon)});$=v}var A=Date.now(),F="$"+A,x=Function("return this")(),Wb=x.require,Xb=x.define,ca=!1,w=/[^, ]+/g,La=/^(?:object|array)$/, -mb=/^\[object SVG\w*Element\]$/,Yb=/^\[object (Window|DOMWindow|global)\]$/,Aa=Object.prototype,Ma=Aa.hasOwnProperty,Ba=Aa.toString,N=Array.prototype,ia=N.slice,V={},G=p.head,D=p.documentElement,H=p.createDocumentFragment(),la=p.createElement("div"),nb={};"Boolean Number String Function Array Date RegExp Object Error".replace(w,function(b){nb["[object "+b+"]"]=b.toLowerCase()});x.avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]=this.element=b};avalon.fn=avalon.prototype= -avalon.init.prototype;avalon.isFunction=R;avalon.type=function(b){return null==b?String(b):"object"===typeof b||"function"===typeof b?nb[Ba.call(b)]||"object":typeof b};avalon.isWindow=function(b){return Yb.test(Ba.call(b))};avalon.isPlainObject=function(b){return!!b&&"object"===typeof b&&Object.getPrototypeOf(b)===Aa};avalon.mix=avalon.fn.mix=function(){var b,c,d,e,f,g=arguments[0]||{},h=1,k=arguments.length,l=!1;"boolean"===typeof g&&(l=g,g=arguments[1]||{},h++);"object"!==typeof g&&"function"!== -avalon.type(g)&&(g={});h===k&&(g=this,h--);for(;h';if(!mb.test(ob.firstChild)){var Ca=function(b,c){if(b&&b.childNodes)for(var d=b.childNodes,e=0,f;f=d[e++];)if(f.tagName){var g=p.createElementNS("http://www.w3.org/2000/svg", -f.tagName.toLowerCase());N.forEach.call(f.attributes,function(b){g.setAttribute(b.name,b.value)});Ca(f,g);c.appendChild(g)}};Object.defineProperties(SVGElement.prototype,{outerHTML:{enumerable:!0,configurable:!0,get:function(){return(new XMLSerializer).serializeToString(this)},set:function(b){var c=this.tagName.toLowerCase(),d=this.parentNode;b=avalon.parseHTML(b);"svg"===c?d.insertBefore(b,this):(c=p.createDocumentFragment(),Ca(b,c),d.insertBefore(c,this));d.removeChild(this)}},innerHTML:{enumerable:!0, -configurable:!0,get:function(){var b=RegExp("$","i");return this.outerHTML.replace(RegExp("<"+this.nodeName+'\\b(?:(["\'])[^"]*?(\\1)|[^>])*>',"i"),"").replace(b,"")},set:function(b){avalon.clearHTML&&(avalon.clearHTML(this),b=avalon.parseHTML(b),Ca(b,this))}}})}}var ka=avalon.vmodels={};avalon.define=function(b,c){var d=b.$id||b;d||t("warning: \u5fc5\u987b\u6307\u5b9a$id");ka[d]&&t("warning: "+d+" \u5df2\u7ecf\u5b58\u5728\u4e8eavalon.vmodels\u4e2d");if("object"===typeof b)var e= -K(b);else e={$watch:v},c(e),e=K(e),ca=!0,c(e),ca=!1;e.$id=d;return ka[d]=e};var Ka="$id,$watch,$unwatch,$fire,$events,$model,$skipArray".match(w),ea=Object.is||function(b,c){return 0===b&&0===c?1/b===1/c:b!==b?c!==c:b===c},T={},fa=0,pa={},L,M,W,pb,bb,qb=/[-.*+?^${}()|[\]\/\\]/g,z=v,O={loader:function(b){x.define=b?z.define:Xb;x.require=b?z:Wb},interpolate:function(b){L=b[0];M=b[1];L===M?avalon.error("openTag!==closeTag",SyntaxError):"\x3c!--,--\x3e"===b+""?s.commentInterpolate=!0:(b=L+"test"+M,la.innerHTML= -b,la.innerHTML!==b&&0<=la.innerHTML.indexOf("<")&&avalon.error("\u6b64\u5b9a\u754c\u7b26\u4e0d\u5408\u6cd5",SyntaxError),la.innerHTML="");b=(L+"").replace(qb,"\\$&");var c=(M+"").replace(qb,"\\$&");W=RegExp(b+"(.*?)"+c);pb=RegExp(b+"(.*?)"+c,"g");bb=RegExp(b+".*?"+c+"|\\sms-")}};s.debug=!0;s.plugins=O;s.plugins.interpolate(["{{","}}"]);s.paths={};s.shim={};s.maxRepeatSize=100;avalon.config=s;"add,remove".replace(w,function(b){avalon.fn[b+"Class"]=function(c){var d=this[0];c&&("string"===typeof c&& -d&&1===d.nodeType)&&c.replace(/\S+/g,function(c){d.classList[b](c)});return this}});avalon.fn.mix({hasClass:function(b){var c=this[0]||{};return 1===c.nodeType&&c.classList.contains(b)},toggleClass:function(b,c){for(var d,e=0,f=b.split(/\s+/),g="boolean"===typeof c;d=f[e++];)this[(g?c:!this.hasClass(d))?"addClass":"removeClass"](d);return this},attr:function(b,c){return 2===arguments.length?(this[0].setAttribute(b,c),this):this[0].getAttribute(b)},data:function(b,c){b="data-"+Na(b||"");switch(arguments.length){case 2:return this.attr(b, -c),this;case 1:var d=this.attr(b);return ha(d);case 0:var e={};N.forEach.call(this[0].attributes,function(c){c&&(b=c.name,b.indexOf("data-")||(b=ga(b.slice(5)),e[b]=ha(c.value)))});return e}},removeData:function(b){b="data-"+Na(b);this[0].removeAttribute(b);return this},css:function(b,c){if(avalon.isPlainObject(b))for(var d in b)avalon.css(this,d,b[d]);else var e=avalon.css(this,b,c);return void 0!==e?e:this},position:function(){var b,c,d=this[0],e={top:0,left:0};if(d)return"fixed"===this.css("position")? -c=d.getBoundingClientRect():(b=this.offsetParent(),c=this.offset(),"HTML"!==b[0].tagName&&(e=b.offset()),e.top+=avalon.css(b[0],"borderTopWidth",!0),e.left+=avalon.css(b[0],"borderLeftWidth",!0)),{top:c.top-e.top-avalon.css(d,"marginTop",!0),left:c.left-e.left-avalon.css(d,"marginLeft",!0)}},offsetParent:function(){for(var b=this[0].offsetParent||D;b&&"HTML"!==b.tagName&&"static"===avalon.css(b,"position");)b=b.offsetParent;return avalon(b||D)},bind:function(b,c,d){if(this[0])return avalon.bind(this[0], -b,c,d)},unbind:function(b,c,d){this[0]&&avalon.unbind(this[0],b,c,d);return this},val:function(b){var c=this[0];if(c&&1===c.nodeType){var d=0===arguments.length,e=d?":get":":set",f=Zb,g;g=c.tagName.toLowerCase();g="input"===g&&/checkbox|radio/.test(c.type)?"checked":g;if(e=f[g+e])var h=e(c,b);else{if(d)return(c.value||"").replace(/\r/g,"");c.value=b}}return d?h:this}});D.dataset&&(avalon.fn.data=function(b,c){var d=this[0].dataset;switch(arguments.length){case 2:return d[b]=c,this;case 1:return c= -d[b],ha(c);case 0:var e={};for(b in d)e[b]=ha(d[b]);return e}});var zb=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/;avalon.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(b,c){avalon.fn[b]=function(d){var e=this[0]||{},f=e.window&&e.document?e:9===e.nodeType?e.defaultView:!1,g="scrollTop"===b;if(arguments.length)f?f.scrollTo(!g?d:avalon(f).scrollLeft(),g?d:avalon(f).scrollTop()):e[b]=d;else return f?f[c]:e[b]}});var y=avalon.cssHooks={},rb=["","-webkit-","-moz-","-ms-"],Da={"float":"cssFloat"}; -avalon.cssNumber=J("columnCount,order,fillOpacity,fontWeight,lineHeight,opacity,orphans,widows,zIndex,zoom");avalon.cssName=function(b,c,d){if(Da[b])return Da[b];c=c||D.style;for(var e=0,f=rb.length;el&&(e=e-avalon.css(c,"border"+d[0]+"Width",!0)-avalon.css(c,"border"+d[1]+"Width",!0));-4===l&&(e=e-avalon.css(c,"padding"+d[0],!0)-avalon.css(c,"padding"+d[1],!0));return e};y[c+"&get"]=function(b){var d=[];Oa(b,d);for(var e=y[c+":get"](b),f=0,m;m=d[f++];){b=m.node;for(var n in m)"string"===typeof m[n]&&(b.style[n]=m[n])}return e};avalon.fn[c]=function(g){var h=this[0]; -if(0===arguments.length){if(h.setTimeout)return h["inner"+b]||h.document.documentElement[d];if(9===h.nodeType){var k=h.documentElement;return Math.max(h.body[e],k[e],h.body[f],k[f],k[d])}return y[c+"&get"](h)}return this.css(c,g)};avalon.fn["inner"+b]=function(){return y[c+":get"](this[0],void 0,-2)};avalon.fn["outer"+b]=function(b){return y[c+":get"](this[0],void 0,!0===b?2:0)}});avalon.fn.offset=function(){var b=this[0],c={left:0,top:0};if(!b||!b.tagName||!b.ownerDocument)return c;var d=b.ownerDocument, -e=d.documentElement,d=d.defaultView;if(!e.contains(b))return c;void 0!==b.getBoundingClientRect&&(c=b.getBoundingClientRect());return{top:c.top+d.pageYOffset-e.clientTop,left:c.left+d.pageXOffset-e.clientLeft}};var Zb={"select:get":function(b,c){for(var d,e=b.options,f=b.selectedIndex,g="select-one"===b.type||0>f,h=g?null:[],k=g?f+1:e.length,l=0>f?k:g?f:0;l]*)\/>/ig,bc=J(["","text/javascript","text/ecmascript","application/ecmascript","application/javascript"]),cc=p.createElement("script");avalon.parseHTML=function(b){"string"!==typeof b&&(b+="");b=b.replace(ac,"<$1>").trim(); -var c=($b.exec(b)||["",""])[1].toLowerCase(),c=B[c]||B._default,d=H.cloneNode(!1);c.innerHTML=b;b=c.getElementsByTagName("script");if(b.length)for(var e=0,f;f=b[e++];)if(bc[f.type]){var g=cc.cloneNode(!1);N.forEach.call(f.attributes,function(b){g.setAttribute(b.name,b.value)});g.text=f.text;f.parentNode.replaceChild(g,f)}for(;b=c.firstChild;)d.appendChild(b);return d};avalon.innerHTML=function(b,c){var d=this.parseHTML(c);this.clearHTML(b).appendChild(d)};avalon.clearHTML=function(b){for(b.textContent= -"";b.firstChild;)b.removeChild(b.firstChild);return b};var P={$watch:function(b,c){if("function"===typeof c){var d=this.$events[b];d?d.push(c):this.$events[b]=[c]}else this.$events=this.$watch.backup;return this},$unwatch:function(b,c){var d=arguments.length;if(0===d)this.$watch.backup=this.$events,this.$events={};else if(1===d)this.$events[b]=[];else for(var d=this.$events[b]||[],e=d.length;0>~--e;)if(d[e]===c)return d.splice(e,1);return this},$fire:function(b){var c;/^(\w+)!(\S+)$/.test(b)&&(c= -RegExp.$1,b=RegExp.$2);var d=this.$events,e=ia.call(arguments,1),f=[b].concat(e);if("all"===c)for(var g in avalon.vmodels)e=avalon.vmodels[g],e!==this&&e.$fire.apply(e,f);else if("up"===c||"down"===c){if(d=d.expr&&p.querySelector(d.expr)){for(g in avalon.vmodels)if(e=avalon.vmodels[g],e!==this&&e.$events.expr){var h=p.querySelector(e.$events.expr);if(h&&("down"===c?d.contains(h):h.contains(d)))h._avalon=e}g=p.getElementsByTagName("*");var k=[];Array.prototype.forEach.call(g,function(b){b._avalon&& -(k.push(b._avalon),b._avalon="",b.removeAttribute("_avalon"))});"up"===c&&k.reverse();for(g=0;(c=k[g++])&&!1!==c.$fire.apply(c,f););}}else{f=d[b]||[];c=d.$all||[];for(g=0;d=f[g++];)R(d)&&d.apply(this,e);for(g=0;d=c[g++];)R(d)&&d.apply(this,arguments)}}},Bb=/^(duplex|on)$/,Q=[],ra=0,Cb=200,Sa=Date.now(),Ta,Ea={};avalon.scanCallback=function(b,c){c=c||"$all";(Ea[c]||(Ea[c]=[])).push(b)};avalon.scan=function(b,c,d){b=b||D;var e=Ea[d||"$all"]||[];c=c?[].concat(c):[];var f=0,g=!1,h,k=!1;c.cb=function(b){f+= -b;k=!0;setTimeout(function(){if(0>=f&&!g)for(g=!0;h=e.shift();)h()})};Ua(b,c);if(!k)for(;h=e.shift();)h()};var Gb=J("AREA,BASE,BASEFONT,BR,COL,COMMAND,EMBED,HR,IMG,INPUT,LINK,META,PARAM,SOURCE,TRACK,WBR,NOSCRIPT,NOSCRIPT,SCRIPT,STYLE,TEXTAREA"),Db=/ms-(\w+)-?(.*)/,ab={"if":10,repeat:90,data:100,widget:110,each:1400,"with":1500,duplex:2E3,on:3E3},Eb=J("animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scan,scroll,submit"), +c,d){b=K({$key:b,$outer:d,$val:c},{$val:1,$key:1});b.$id=("$proxy$with"+Math.random()).replace(/0\./,"");return b}function Tb(b,c,d,e){var f=d.param||"el",g;b={$remove:function(){return d.$repeat.removeAt(g.$index)},$itemName:f,$index:b,$outer:d.$outer,$first:0===b,$last:b===e};b[f]=c;e=0;for(var h=Z.length;es.maxRepeatSize&&Z.pop()}b.length=0}function $(){z?(r["ready!"].state=2,z.checkDeps()):lb.forEach(function(b){b(avalon)});$=v}var A=Date.now(),F="$"+A,x=Function("return this")(),Wb=x.require,Xb=x.define, +ca=!1,w=/[^, ]+/g,La=/^(?:object|array)$/,mb=/^\[object SVG\w*Element\]$/,Yb=/^\[object (Window|DOMWindow|global)\]$/,Aa=Object.prototype,Ma=Aa.hasOwnProperty,Ba=Aa.toString,N=Array.prototype,ia=N.slice,V={},G=p.head,D=p.documentElement,H=p.createDocumentFragment(),la=p.createElement("div"),nb={};"Boolean Number String Function Array Date RegExp Object Error".replace(w,function(b){nb["[object "+b+"]"]=b.toLowerCase()});x.avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]= +this.element=b};avalon.fn=avalon.prototype=avalon.init.prototype;avalon.isFunction=R;avalon.type=function(b){return null==b?String(b):"object"===typeof b||"function"===typeof b?nb[Ba.call(b)]||"object":typeof b};avalon.isWindow=function(b){return Yb.test(Ba.call(b))};avalon.isPlainObject=function(b){return!!b&&"object"===typeof b&&Object.getPrototypeOf(b)===Aa};avalon.mix=avalon.fn.mix=function(){var b,c,d,e,f,g=arguments[0]||{},h=1,k=arguments.length,l=!1;"boolean"===typeof g&&(l=g,g=arguments[1]|| +{},h++);"object"!==typeof g&&"function"!==avalon.type(g)&&(g={});h===k&&(g=this,h--);for(;h';if(!mb.test(ob.firstChild)){var Ca=function(b,c){if(b&&b.childNodes)for(var d=b.childNodes, +e=0,f;f=d[e++];)if(f.tagName){var g=p.createElementNS("http://www.w3.org/2000/svg",f.tagName.toLowerCase());N.forEach.call(f.attributes,function(b){g.setAttribute(b.name,b.value)});Ca(f,g);c.appendChild(g)}};Object.defineProperties(SVGElement.prototype,{outerHTML:{enumerable:!0,configurable:!0,get:function(){return(new XMLSerializer).serializeToString(this)},set:function(b){var c=this.tagName.toLowerCase(),d=this.parentNode;b=avalon.parseHTML(b);"svg"===c?d.insertBefore(b,this):(c=p.createDocumentFragment(), +Ca(b,c),d.insertBefore(c,this));d.removeChild(this)}},innerHTML:{enumerable:!0,configurable:!0,get:function(){var b=RegExp("$","i");return this.outerHTML.replace(RegExp("<"+this.nodeName+'\\b(?:(["\'])[^"]*?(\\1)|[^>])*>',"i"),"").replace(b,"")},set:function(b){avalon.clearHTML&&(avalon.clearHTML(this),b=avalon.parseHTML(b),Ca(b,this))}}})}}var ka=avalon.vmodels={};avalon.define=function(b,c){var d=b.$id||b;d||t("warning: \u5fc5\u987b\u6307\u5b9a$id");ka[d]&&t("warning: "+d+" \u5df2\u7ecf\u5b58\u5728\u4e8eavalon.vmodels\u4e2d"); +if("object"===typeof b)var e=K(b);else e={$watch:v},c(e),e=K(e),ca=!0,c(e),ca=!1;e.$id=d;return ka[d]=e};var Ka="$id,$watch,$unwatch,$fire,$events,$model,$skipArray".match(w),ea=Object.is||function(b,c){return 0===b&&0===c?1/b===1/c:b!==b?c!==c:b===c},T={},fa=0,pa={},L,M,W,pb,bb,qb=/[-.*+?^${}()|[\]\/\\]/g,z=v,O={loader:function(b){x.define=b?z.define:Xb;x.require=b?z:Wb},interpolate:function(b){L=b[0];M=b[1];L===M?avalon.error("openTag!==closeTag",SyntaxError):"\x3c!--,--\x3e"===b+""?s.commentInterpolate= +!0:(b=L+"test"+M,la.innerHTML=b,la.innerHTML!==b&&0<=la.innerHTML.indexOf("<")&&avalon.error("\u6b64\u5b9a\u754c\u7b26\u4e0d\u5408\u6cd5",SyntaxError),la.innerHTML="");b=(L+"").replace(qb,"\\$&");var c=(M+"").replace(qb,"\\$&");W=RegExp(b+"(.*?)"+c);pb=RegExp(b+"(.*?)"+c,"g");bb=RegExp(b+".*?"+c+"|\\sms-")}};s.debug=!0;s.plugins=O;s.plugins.interpolate(["{{","}}"]);s.paths={};s.shim={};s.maxRepeatSize=100;avalon.config=s;"add,remove".replace(w,function(b){avalon.fn[b+"Class"]=function(c){var d= +this[0];c&&("string"===typeof c&&d&&1===d.nodeType)&&c.replace(/\S+/g,function(c){d.classList[b](c)});return this}});avalon.fn.mix({hasClass:function(b){var c=this[0]||{};return 1===c.nodeType&&c.classList.contains(b)},toggleClass:function(b,c){for(var d,e=0,f=b.split(/\s+/),g="boolean"===typeof c;d=f[e++];)this[(g?c:!this.hasClass(d))?"addClass":"removeClass"](d);return this},attr:function(b,c){return 2===arguments.length?(this[0].setAttribute(b,c),this):this[0].getAttribute(b)},data:function(b, +c){b="data-"+Na(b||"");switch(arguments.length){case 2:return this.attr(b,c),this;case 1:var d=this.attr(b);return ha(d);case 0:var e={};N.forEach.call(this[0].attributes,function(c){c&&(b=c.name,b.indexOf("data-")||(b=ga(b.slice(5)),e[b]=ha(c.value)))});return e}},removeData:function(b){b="data-"+Na(b);this[0].removeAttribute(b);return this},css:function(b,c){if(avalon.isPlainObject(b))for(var d in b)avalon.css(this,d,b[d]);else var e=avalon.css(this,b,c);return void 0!==e?e:this},position:function(){var b, +c,d=this[0],e={top:0,left:0};if(d)return"fixed"===this.css("position")?c=d.getBoundingClientRect():(b=this.offsetParent(),c=this.offset(),"HTML"!==b[0].tagName&&(e=b.offset()),e.top+=avalon.css(b[0],"borderTopWidth",!0),e.left+=avalon.css(b[0],"borderLeftWidth",!0)),{top:c.top-e.top-avalon.css(d,"marginTop",!0),left:c.left-e.left-avalon.css(d,"marginLeft",!0)}},offsetParent:function(){for(var b=this[0].offsetParent||D;b&&"HTML"!==b.tagName&&"static"===avalon.css(b,"position");)b=b.offsetParent;return avalon(b|| +D)},bind:function(b,c,d){if(this[0])return avalon.bind(this[0],b,c,d)},unbind:function(b,c,d){this[0]&&avalon.unbind(this[0],b,c,d);return this},val:function(b){var c=this[0];if(c&&1===c.nodeType){var d=0===arguments.length,e=d?":get":":set",f=Zb,g;g=c.tagName.toLowerCase();g="input"===g&&/checkbox|radio/.test(c.type)?"checked":g;if(e=f[g+e])var h=e(c,b);else{if(d)return(c.value||"").replace(/\r/g,"");c.value=b}}return d?h:this}});D.dataset&&(avalon.fn.data=function(b,c){var d=this[0].dataset;switch(arguments.length){case 2:return d[b]= +c,this;case 1:return c=d[b],ha(c);case 0:var e={};for(b in d)e[b]=ha(d[b]);return e}});var zb=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/;avalon.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(b,c){avalon.fn[b]=function(d){var e=this[0]||{},f=e.window&&e.document?e:9===e.nodeType?e.defaultView:!1,g="scrollTop"===b;if(arguments.length)f?f.scrollTo(!g?d:avalon(f).scrollLeft(),g?d:avalon(f).scrollTop()):e[b]=d;else return f?f[c]:e[b]}});var y=avalon.cssHooks={},rb=["","-webkit-","-moz-","-ms-"], +Da={"float":"cssFloat"};avalon.cssNumber=J("columnCount,order,fillOpacity,fontWeight,lineHeight,opacity,orphans,widows,zIndex,zoom");avalon.cssName=function(b,c,d){if(Da[b])return Da[b];c=c||D.style;for(var e=0,f=rb.length;el&&(e=e-avalon.css(c,"border"+d[0]+"Width",!0)-avalon.css(c,"border"+d[1]+"Width",!0));-4===l&&(e=e-avalon.css(c,"padding"+d[0],!0)-avalon.css(c,"padding"+d[1],!0));return e};y[c+"&get"]=function(b){var d=[];Oa(b,d);for(var e=y[c+":get"](b),f=0,m;m=d[f++];){b=m.node;for(var n in m)"string"===typeof m[n]&&(b.style[n]=m[n])}return e};avalon.fn[c]=function(g){var h= +this[0];if(0===arguments.length){if(h.setTimeout)return h["inner"+b]||h.document.documentElement[d];if(9===h.nodeType){var k=h.documentElement;return Math.max(h.body[e],k[e],h.body[f],k[f],k[d])}return y[c+"&get"](h)}return this.css(c,g)};avalon.fn["inner"+b]=function(){return y[c+":get"](this[0],void 0,-2)};avalon.fn["outer"+b]=function(b){return y[c+":get"](this[0],void 0,!0===b?2:0)}});avalon.fn.offset=function(){var b=this[0],c={left:0,top:0};if(!b||!b.tagName||!b.ownerDocument)return c;var d= +b.ownerDocument,e=d.documentElement,d=d.defaultView;if(!e.contains(b))return c;void 0!==b.getBoundingClientRect&&(c=b.getBoundingClientRect());return{top:c.top+d.pageYOffset-e.clientTop,left:c.left+d.pageXOffset-e.clientLeft}};var Zb={"select:get":function(b,c){for(var d,e=b.options,f=b.selectedIndex,g="select-one"===b.type||0>f,h=g?null:[],k=g?f+1:e.length,l=0>f?k:g?f:0;l]*)\/>/ig,bc=J(["","text/javascript","text/ecmascript","application/ecmascript","application/javascript"]),cc=p.createElement("script");avalon.parseHTML=function(b){"string"!==typeof b&&(b+= +"");b=b.replace(ac,"<$1>").trim();var c=($b.exec(b)||["",""])[1].toLowerCase(),c=B[c]||B._default,d=H.cloneNode(!1);c.innerHTML=b;b=c.getElementsByTagName("script");if(b.length)for(var e=0,f;f=b[e++];)if(bc[f.type]){var g=cc.cloneNode(!1);N.forEach.call(f.attributes,function(b){g.setAttribute(b.name,b.value)});g.text=f.text;f.parentNode.replaceChild(g,f)}for(;b=c.firstChild;)d.appendChild(b);return d};avalon.innerHTML=function(b,c){var d=this.parseHTML(c);this.clearHTML(b).appendChild(d)};avalon.clearHTML= +function(b){for(b.textContent="";b.firstChild;)b.removeChild(b.firstChild);return b};var P={$watch:function(b,c){if("function"===typeof c){var d=this.$events[b];d?d.push(c):this.$events[b]=[c]}else this.$events=this.$watch.backup;return this},$unwatch:function(b,c){var d=arguments.length;if(0===d)this.$watch.backup=this.$events,this.$events={};else if(1===d)this.$events[b]=[];else for(var d=this.$events[b]||[],e=d.length;0>~--e;)if(d[e]===c)return d.splice(e,1);return this},$fire:function(b){var c; +/^(\w+)!(\S+)$/.test(b)&&(c=RegExp.$1,b=RegExp.$2);var d=this.$events,e=ia.call(arguments,1),f=[b].concat(e);if("all"===c)for(var g in avalon.vmodels)e=avalon.vmodels[g],e!==this&&e.$fire.apply(e,f);else if("up"===c||"down"===c){if(d=d.expr&&p.querySelector(d.expr)){for(g in avalon.vmodels)if(e=avalon.vmodels[g],e!==this&&e.$events.expr){var h=p.querySelector(e.$events.expr);if(h&&("down"===c?d.contains(h):h.contains(d)))h._avalon=e}g=p.getElementsByTagName("*");var k=[];Array.prototype.forEach.call(g, +function(b){b._avalon&&(k.push(b._avalon),b._avalon="",b.removeAttribute("_avalon"))});"up"===c&&k.reverse();for(g=0;(c=k[g++])&&!1!==c.$fire.apply(c,f););}}else{f=d[b]||[];c=d.$all||[];for(g=0;d=f[g++];)R(d)&&d.apply(this,e);for(g=0;d=c[g++];)R(d)&&d.apply(this,arguments)}}},Bb=/^(duplex|on)$/,Q=[],ra=0,Cb=200,Sa=Date.now(),Ta,Ea={};avalon.scanCallback=function(b,c){c=c||"$all";(Ea[c]||(Ea[c]=[])).push(b)};avalon.scan=function(b,c,d){b=b||D;var e=Ea[d||"$all"]||[];c=c?[].concat(c):[];var f=0,g=!1, +h,k=!1;c.cb=function(b){f+=b;k=!0;setTimeout(function(){if(0>=f&&!g)for(g=!0;h=e.shift();)h()})};Ua(b,c);if(!k)for(;h=e.shift();)h()};var Gb=J("AREA,BASE,BASEFONT,BR,COL,COMMAND,EMBED,HR,IMG,INPUT,LINK,META,PARAM,SOURCE,TRACK,WBR,NOSCRIPT,NOSCRIPT,SCRIPT,STYLE,TEXTAREA"),Db=/ms-(\w+)-?(.*)/,ab={"if":10,repeat:90,data:100,widget:110,each:1400,"with":1500,duplex:2E3,on:3E3},Eb=J("animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scan,scroll,submit"), Fb=J("value,title,alt,checked,selected,disabled,readonly,enabled"),Ib=/\|\s*(\w+)\s*(\([^)]*\))?/g,Hb=/\|\|/g,Jb=/U2hvcnRDaXJjdWl0/g,dc=/\/\*[\w\W]*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|"(?:[^"\\]|\\[\w\W])*"|'(?:[^'\\]|\\[\w\W])*'|[\s\t\n]*\.[\s\t\n]*[$\w\.]+/g,ec=/[^\w$]+/g,fc=RegExp(""+("\\b"+"break,case,catch,continue,debugger,default,delete,do,else,false,finally,for,function,if,in,instanceof,new,null,return,switch,this,throw,true,try,typeof,var,void,while,with,abstract,boolean,byte,char,class,const,double,enum,export,extends,final,float,goto,implements,import,int,interface,long,native,package,private,protected,public,short,static,super,synchronized,throws,transient,volatile,arguments,let,yield,undefined".replace(/,/g, "\\b|\\b")+"\\b"),"g"),gc=/\b\d[^,]*/g,hc=/^,+|,+$/g,Fa=db(512),Mb=function(b){var c=","+b.trim();if(Fa[c])return Fa[c];b=b.replace(dc,"").replace(ec,",").replace(fc,"").replace(gc,"").replace(hc,"").split(/^$|,+/);return Fa(c,cb(b))},wa=db(128),Nb=/\w\[.*\]|\w\.\w/,Lb=/(\$proxy\$[a-z]+)\d+$/;avalon.parseExprProxy=I;G.insertAdjacentHTML("afterBegin",'');var sa=G.firstChild,aa=function(b,c,d){if(b=b.getAttribute(c)){c= 0;for(var e;e=d[c++];)if(e.hasOwnProperty(b)&&"function"===typeof e[b])return e[b]}},Ga=avalon.templateCache={},Ha={};"autofocus,autoplay,async,checked,controls,declare,disabled,defer,defaultChecked,defaultSelectedcontentEditable,isMap,loop,multiple,noHref,noResize,noShade,open,readOnly,selected".replace(w,function(b){Ha[b.toLowerCase()]=b});var xa=avalon.bindingExecutors={attr:function(b,c,d){var e=d.type,f=d.param;if("css"===e)avalon(c).css(f,b);else if("attr"===e){if(Ha[f]&&(e=Ha[f],"boolean"=== diff --git a/examples/avalon.shim.js b/examples/avalon.shim.js index 0e443fd06..9260b9d6e 100644 --- a/examples/avalon.shim.js +++ b/examples/avalon.shim.js @@ -1694,9 +1694,10 @@ for (i = wrap[0]; i--; wrapper = wrapper.lastChild) { } if (!W3C) { //fix IE - for (els = avalon.slice(wrapper["getElementsByTagName"]("br")), i = 0; el = els[i++]; ) { + for (els = wrapper["getElementsByTagName"]("br"), i = 0; el = els[i++]; ) { if (el.className && el.className === "msNoScope") { el.parentNode.removeChild(el) + i-- } } for (els = wrapper.all, i = 0; el = els[i++]; ) { //fix VML @@ -1705,10 +1706,11 @@ } } if (tag === "tr") { - for (els = avalon.slice(wrapper.children), i = 0; el = els[i++]; ) { + for (els = wrapper.children, i = 0; el = els[i++]; ) { // IE6-8,如果动态生成tr元素,必须会在后面添加早已废弃caption的标签,其nodeName,innerHTML都为"" - if (el.nodeName == "") { + if (el.nodeName === "") { el.parentNode.removeChild(el) + i-- } } } @@ -2024,7 +2026,17 @@ //http://www.w3.org/TR/html5/syntax.html#void-elements var stopScan = oneObject("area,base,basefont,br,col,command,embed,hr,img,input,link,meta,param,source,track,wbr,noscript,script,style,textarea".toUpperCase()) - + function checkScan(elem, callback, innerHTML) { + var id = setTimeout(function() { + var currHTML = elem.innerHTML + clearTimeout(id) + if (currHTML === innerHTML) { + callback() + } else { + checkScan(elem, callback, currHTML) + } + }) + } function scanTag(elem, vmodels, node) { //扫描顺序 ms-skip(0) --> ms-important(1) --> ms-controller(2) --> ms-if(10) --> ms-repeat(100) @@ -2658,11 +2670,10 @@ text = loaded.apply(target, [text].concat(vmodels)) } if (rendered) { - avalon.scanCallback(function() { + checkScan(target, function() { rendered.call(target) - }) + }, NaN) } - avalon.scan(target) while (true) { var node = data.startInclude.nextSibling if (node && node !== data.endInclude) { @@ -2889,13 +2900,13 @@ } var callback = data.renderedCallback || noop, args = arguments - avalon.scanCallback(function() { + + checkScan(parent, function() { callback.apply(parent, args) if (parent.oldValue && parent.tagName === "SELECT" && method === "index") { //fix #503 avalon(parent).val(parent.oldValue.split(",")) } - }) - avalon.scan(parent) + }, NaN) } }, "html": function(val, elem, data) { @@ -3663,12 +3674,11 @@ } } data.bound("change", updateVModel) - avalon.scanCallback(function() { + checkScan(element, function() { //先等到select里的option元素被扫描后,才根据model设置selected属性 registerSubscriber(data) data.changed.call(element, evaluator(), data) - }) - avalon.scan(element) + }, NaN) } duplexBinding.TEXTAREA = duplexBinding.INPUT //============================= event binding ======================= @@ -4074,6 +4084,9 @@ proxy[k] = source[k] } eachProxyPool.splice(i, 1) + proxy.$watch(param, function(val) { + data.$repeat.set(proxy.$index, val) + }) return proxy } } From f15fccc23ccfa6c036147b20735d6413a9ba5c4f Mon Sep 17 00:00:00 2001 From: RubyLouvre Date: Tue, 18 Nov 2014 16:02:07 +0800 Subject: [PATCH 02/18] remove --- newhtml1.html | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 newhtml1.html diff --git a/newhtml1.html b/newhtml1.html deleted file mode 100644 index e394a0563..000000000 --- a/newhtml1.html +++ /dev/null @@ -1,31 +0,0 @@ - - - - TODO supply a title - - - - - - -
TODO write content
- - From caef27a01337b621547c4012c5ffbb3dff11a88b Mon Sep 17 00:00:00 2001 From: RubyLouvre Date: Tue, 18 Nov 2014 17:35:01 +0800 Subject: [PATCH 03/18] update --- avalon.js | 1 + avalon.modern.js | 1 + 2 files changed, 2 insertions(+) diff --git a/avalon.js b/avalon.js index 95e6f1188..3f5ae4c8c 100644 --- a/avalon.js +++ b/avalon.js @@ -3335,6 +3335,7 @@ data.value = [widget, id, optName].join(",") data[widget + "Id"] = id data.evaluator = noop + elem.msData["ms-widget-id"] = id var options = data[widget + "Options"] = avalon.mix({}, constructor.defaults, vmOptions || {}, widgetData) elem.removeAttribute("ms-widget") var vmodel = constructor(elem, data, vmodels) || {} //防止组件不返回VM diff --git a/avalon.modern.js b/avalon.modern.js index 2d289b21e..306e13e73 100644 --- a/avalon.modern.js +++ b/avalon.modern.js @@ -2637,6 +2637,7 @@ var widgetData = avalon.getWidgetData(elem, widget) data.value = [widget, id, optName].join(",") data[widget + "Id"] = id + elem.msData["ms-widget-id"] = id data.evaluator = noop var options = data[widget + "Options"] = avalon.mix({}, constructor.defaults, vmOptions || {}, widgetData) elem.removeAttribute("ms-widget") From e5ccdac2520e20a8392f2529b079dc770eff372a Mon Sep 17 00:00:00 2001 From: RubyLouvre Date: Tue, 18 Nov 2014 20:40:30 +0800 Subject: [PATCH 04/18] update validation --- avalon.js | 93 +++++++++++++------------ avalon.min.js | 38 +++++------ avalon.modern.js | 84 +++++++++++------------ avalon.modern.min.js | 158 +++++++++++++++++++++---------------------- 4 files changed, 186 insertions(+), 187 deletions(-) diff --git a/avalon.js b/avalon.js index 3f5ae4c8c..5480c8ba5 100644 --- a/avalon.js +++ b/avalon.js @@ -3109,60 +3109,59 @@ }, "duplex": function(data, vmodels) { var elem = data.element, - tagName = elem.tagName, hasCast parseExprProxy(data.value, vmodels, data, 0, 1) - if (typeof duplexBinding[tagName] === "function") { - data.changed = getBindingCallback(elem, "data-duplex-changed", vmodels) || noop - if (data.evaluator && data.args) { - var params = [] - var casting = oneObject("string,number,boolean,checked") - if (elem.type === "radio" && data.param === "") { - data.param = "checked" + + data.changed = getBindingCallback(elem, "data-duplex-changed", vmodels) || noop + if (data.evaluator && data.args) { + var params = [] + var casting = oneObject("string,number,boolean,checked") + if (elem.type === "radio" && data.param === "") { + data.param = "checked" + } + data.param.replace(/\w+/g, function(name) { + if (/^(checkbox|radio)$/.test(elem.type) && /^(radio|checked)$/.test(name)) { + if (name === "radio") + log("ms-duplex-radio已经更名为ms-duplex-checked") + name = "checked" + data.isChecked = true } - data.param.replace(/\w+/g, function(name) { - if (/^(checkbox|radio)$/.test(elem.type) && /^(radio|checked)$/.test(name)) { - if (name === "radio") - log("ms-duplex-radio已经更名为ms-duplex-checked") - name = "checked" - data.isChecked = true - } - if (name === "bool") { - name = "boolean" - log("ms-duplex-bool已经更名为ms-duplex-boolean") - } else if (name === "text") { - name = "string" - log("ms-duplex-text已经更名为ms-duplex-string") - } - if (casting[name]) { - hasCast = true - } - avalon.Array.ensure(params, name) - }) - if (!hasCast) { - params.push("string") + if (name === "bool") { + name = "boolean" + log("ms-duplex-bool已经更名为ms-duplex-boolean") + } else if (name === "text") { + name = "string" + log("ms-duplex-text已经更名为ms-duplex-string") } - data.param = params.join("-") - data.bound = function(type, callback) { - if (elem.addEventListener) { - elem.addEventListener(type, callback, false) - } else { - elem.attachEvent("on" + type, callback) - } - var old = data.rollback - data.rollback = function() { - avalon.unbind(elem, type, callback) - old && old() - } + if (casting[name]) { + hasCast = true } - for (var i in avalon.vmodels) { - var v = avalon.vmodels[i] - v.$fire("avalon-ms-duplex-init", data) + avalon.Array.ensure(params, name) + }) + if (!hasCast) { + params.push("string") + } + data.param = params.join("-") + data.bound = function(type, callback) { + if (elem.addEventListener) { + elem.addEventListener(type, callback, false) + } else { + elem.attachEvent("on" + type, callback) + } + var old = data.rollback + data.rollback = function() { + avalon.unbind(elem, type, callback) + old && old() } - var cpipe = data.pipe || (data.pipe = pipe) - cpipe(null, data, "init") - duplexBinding[elem.tagName](elem, data.evaluator.apply(null, data.args), data) } + for (var i in avalon.vmodels) { + var v = avalon.vmodels[i] + v.$fire("avalon-ms-duplex-init", data) + } + var cpipe = data.pipe || (data.pipe = pipe) + cpipe(null, data, "init") + var tagName = elem.tagName + duplexBinding[tagName] && duplexBinding[tagName](elem, data.evaluator.apply(null, data.args), data) } }, "repeat": function(data, vmodels) { diff --git a/avalon.min.js b/avalon.min.js index 8747518d1..b80b9f767 100644 --- a/avalon.min.js +++ b/avalon.min.js @@ -61,7 +61,7 @@ return{top:c.top+h-b,left:c.left+e-g}};var Qc=/^"],param:[1,""],col:[2,"","
"],legend:[1,"
"],option:[1,"\u4e0d\u80fd\u5bf9\u5e94\u4e00\u4e2a\u6570\u7ec4");d=Array.isArray(d)?d.map(String):d+"";d+""!==b.oldValue&&(e.val(d), -b.oldValue=d+"")};d.bound("change",function(){if(!1!==e.data("duplex-observe")){var f=e.val(),f=Array.isArray(f)?f.map(function(b){return d.pipe(b,d,"get")}):d.pipe(f,d,"get");f+""!==b.oldValue&&c(f);d.changed.call(b,f,d)}});qa(b,function(){ya(d);d.changed.call(b,c(),d)},NaN)};X.TEXTAREA=X.INPUT;var ga=avalon.eventHooks;"onmouseenter"in B||avalon.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(b,c){ga[b]={type:c,deel:function(c,e){return function(f){var g=f.relatedTarget;if(!g||g!==c&& -!(c.compareDocumentPosition(g)&16))return delete f.type,f.type=b,e.call(c,f)}}}});avalon.each({AnimationEvent:"animationend",WebKitAnimationEvent:"webkitAnimationEnd"},function(b,c){r[b]&&!ga.animationend&&(ga.animationend={type:c})});"oninput"in p.createElement("input")||(ga.input={type:"propertychange",deel:function(b,c){return function(d){if("value"===d.propertyName)return d.type="input",c.call(b,d)}}});if(void 0===p.onmousewheel){var Ub=void 0!==p.onwheel?"wheel":"DOMMouseScroll",id="wheel"=== -Ub?"deltaY":"detail";ga.mousewheel={type:Ub,deel:function(b,c){return function(d){d.wheelDeltaY=d.wheelDelta=0]*>([\S\s]*?)<\/script\s*>/gim,kd=/\s+(on[^=\s]+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,ld=/<\w+\b(?:(["'])[^"]*?(\1)|[^>])*>/ig,md={a:/\b(href)\=("javascript[^"]*"|'javascript[^']*')/ig,img:/\b(src)\=("javascript[^"]*"|'javascript[^']*')/ig,form:/\b(action)\=("javascript[^"]*"|'javascript[^']*')/ig}, +typeof l[d]){var m=l[d],m=m.$model||m;break}m&&(k=m[f+"Id"],"string"===typeof k&&(g=k));k=avalon.getWidgetData(e,f);b.value=[f,g,d].join();b[f+"Id"]=g;b.evaluator=y;e.msData["ms-widget-id"]=g;var n=b[f+"Options"]=avalon.mix({},h.defaults,m||{},k);e.removeAttribute("ms-widget");var q=h(e,b,c)||{};if(q.$id){if(avalon.vmodels[g]=q,mb(e,q),q.hasOwnProperty("$init")&&q.$init(function(){var b=[q].concat(c);b.cb=c.cb;avalon.scan(e,b);"function"===typeof n.onInit&&n.onInit.call(e,q,n,c)}),q.hasOwnProperty("$remove")){var p= +function(){if(!e.msRetain&&!B.contains(e))return q.$remove(),e.msData={},delete ra[q.$id],!1};r.chrome?e.addEventListener("DOMNodeRemovedFromDocument",function(){setTimeout(p)}):avalon.tick(p)}}else avalon.scan(e,c)}else c.length&&(e.vmodels=c)}};"hover,active".replace(z,function(b){C[b]=C["class"]});"with,each".replace(z,function(b){C[b]=C.repeat});C["if"]=C.data=C.text=C.html;"title,alt,src,value,css,include,href".replace(z,function(b){C[b]=C.attr});var X=C.duplex;avalon.duplexHooks={checked:{get:function(b, +c){return!c.element.oldValue}},string:{get:function(b){return b},set:Ga},"boolean":{get:function(b){return"true"===b},set:Ga},number:{get:function(b){return isFinite(b)?parseFloat(b)||0:b},set:Ga}};X.INPUT=function(b,c,d){function e(b){d.changed.call(this,b,d)}function f(){n=!0}function g(){n=!1}function h(){if(!n){var f=b.oldValue=b.value,f=d.pipe(f,d,"get");!1!==m.data("duplex-observe")&&(c(f),e.call(b,f),m.data("duplex-focus")&&avalon.nextTick(function(){b.focus()}))}}var k=b.type,l=d.bound,m= +avalon(b),n=!1;d.handler=function(){var e=d.pipe(c(),d,"set");e!==b.value&&(b.value=e)};if(d.isChecked||"radio"===b.type){var q=!r.XMLHttpRequest,h=function(){if(!1!==m.data("duplex-observe")){var f=d.pipe(b.value,d,"get");c(f);e.call(b,f)}};d.handler=function(){var e=c(),f=d.isChecked?!!e:e+""===b.value;b.oldValue=f;q?setTimeout(function(){b.defaultChecked=f;b.checked=f},100):b.checked=f};l(q?"mouseup":"click",h)}else if("checkbox"===k)h=function(){if(!1!==m.data("duplex-observe")){var f=b.checked? +"ensure":"remove",g=c();Array.isArray(g)||(v("ms-duplex\u5e94\u7528\u4e8echeckbox\u4e0a\u8981\u5bf9\u5e94\u4e00\u4e2a\u6570\u7ec4"),g=[g]);avalon.Array[f](g,d.pipe(b.value,d,"get"));e.call(b,g)}},d.handler=function(){var e=[].concat(c());b.checked=0<=e.indexOf(d.pipe(b.value,d,"get"))},l(w?"change":"click",h);else{k=b.getAttribute("data-duplex-event")||b.getAttribute("data-event")||"input";b.attributes["data-event"]&&v("data-event\u6307\u4ee4\u5df2\u7ecf\u5e9f\u5f03\uff0c\u8bf7\u6539\u7528data-duplex-event"); +var t=function(b){setTimeout(function(){h(b)})};k.replace(z,function(b){switch(b){case "input":w?(l("input",h),l("compositionstart",f),l("compositionend",g),9===p.documentMode&&(l("paste",t),l("cut",t))):l("propertychange",function(b){"value"===b.propertyName&&h()});break;default:l(b,h)}})}b.oldValue=b.value;Tb(function(){if(avalon.contains(B,b))yb.call(b);else if(!b.msRetain)return!1});ya(d);e.call(b,b.value)};var zb,ca=[],Tb=y;avalon.tick=function(b){1===ca.push(b)&&(zb=setInterval(tc,60))};try{var Va= +HTMLInputElement.prototype;Object.getOwnPropertyNames(Va);var vc=Object.getOwnPropertyDescriptor(Va,"value").set;Object.defineProperty(Va,"value",{set:uc})}catch(qd){Tb=avalon.tick}X.SELECT=function(b,c,d){var e=avalon(b);d.handler=function(){var d=c(),d=d&&d.$model||d;Array.isArray(d)?b.multiple||v("ms-duplex\u5728\u4e0d\u80fd\u5bf9\u5e94\u4e00\u4e2a\u6570\u7ec4");d= +Array.isArray(d)?d.map(String):d+"";d+""!==b.oldValue&&(e.val(d),b.oldValue=d+"")};d.bound("change",function(){if(!1!==e.data("duplex-observe")){var f=e.val(),f=Array.isArray(f)?f.map(function(b){return d.pipe(b,d,"get")}):d.pipe(f,d,"get");f+""!==b.oldValue&&c(f);d.changed.call(b,f,d)}});qa(b,function(){ya(d);d.changed.call(b,c(),d)},NaN)};X.TEXTAREA=X.INPUT;var ga=avalon.eventHooks;"onmouseenter"in B||avalon.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(b,c){ga[b]={type:c,deel:function(c, +e){return function(f){var g=f.relatedTarget;if(!g||g!==c&&!(c.compareDocumentPosition(g)&16))return delete f.type,f.type=b,e.call(c,f)}}}});avalon.each({AnimationEvent:"animationend",WebKitAnimationEvent:"webkitAnimationEnd"},function(b,c){r[b]&&!ga.animationend&&(ga.animationend={type:c})});"oninput"in p.createElement("input")||(ga.input={type:"propertychange",deel:function(b,c){return function(d){if("value"===d.propertyName)return d.type="input",c.call(b,d)}}});if(void 0===p.onmousewheel){var Ub= +void 0!==p.onwheel?"wheel":"DOMMouseScroll",id="wheel"===Ub?"deltaY":"detail";ga.mousewheel={type:Ub,deel:function(b,c){return function(d){d.wheelDeltaY=d.wheelDelta=0]*>([\S\s]*?)<\/script\s*>/gim,kd=/\s+(on[^=\s]+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,ld=/<\w+\b(?:(["'])[^"]*?(\1)|[^>])*>/ig,md={a:/\b(href)\=("javascript[^"]*"|'javascript[^']*')/ig,img:/\b(src)\=("javascript[^"]*"|'javascript[^']*')/ig,form:/\b(action)\=("javascript[^"]*"|'javascript[^']*')/ig}, nd=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,od=/([^\#-~| |!])/g,Xa=avalon.filters={uppercase:function(b){return b.toUpperCase()},lowercase:function(b){return b.toLowerCase()},truncate:function(b,c,d){c=c||30;d=void 0===d?"...":d;return b.length>c?b.slice(0,c-d.length)+d:String(b)},camelize:oa,sanitize:function(b){return b.replace(jd,"").replace(ld,function(b,d){var e=b.toLowerCase().match(/<(\w+)\s/);e&&(e=md[e[1]])&&(b=b.replace(e,function(b,c,d){b=d.charAt(0);return c+"="+b+"javascript:void(0)"+b}));return b.replace(kd, " ").replace(/\s+/g," ")})},escape:function(b){return String(b).replace(/&/g,"&").replace(nd,function(b){var d=b.charCodeAt(0);b=b.charCodeAt(1);return"&#"+(1024*(d-55296)+(b-56320)+65536)+";"}).replace(od,function(b){return"&#"+b.charCodeAt(0)+";"}).replace(//g,">")},currency:function(b,c){return(c||"\uffe5")+avalon.filters.number(b)},number:function(b,c,d,e){b=(b+"").replace(/[^0-9+\-Ee.]/g,"");b=!isFinite(+b)?0:+b;c=!isFinite(+c)?0:Math.abs(c);e=e||",";d=d||".";var f= "",f=function(b,c){var d=Math.pow(10,c);return""+Math.round(b*d)/d},f=(c?f(b,c):""+Math.round(b)).split(".");3b&&(e="-",b=-b);for(b=""+b;b.length-e)g+=e;0===g&&-12===e&&(g=12);return b(g, diff --git a/avalon.modern.js b/avalon.modern.js index 306e13e73..102a66ecd 100644 --- a/avalon.modern.js +++ b/avalon.modern.js @@ -2419,54 +2419,54 @@ }, "duplex": function(data, vmodels) { var elem = data.element, - tagName = elem.tagName, hasCast + hasCast parseExprProxy(data.value, vmodels, data, 0, 1) - if (typeof duplexBinding[tagName] === "function") { - data.changed = getBindingCallback(elem, "data-duplex-changed", vmodels) || noop - if (data.evaluator && data.args) { - var params = [] - var casting = oneObject("string,number,boolean,checked") - if (elem.type === "radio" && data.param === "") { - data.param = "checked" + + data.changed = getBindingCallback(elem, "data-duplex-changed", vmodels) || noop + if (data.evaluator && data.args) { + var params = [] + var casting = oneObject("string,number,boolean,checked") + if (elem.type === "radio" && data.param === "") { + data.param = "checked" + } + data.param.replace(/\w+/g, function(name) { + if (/^(checkbox|radio)$/.test(elem.type) && /^(radio|checked)$/.test(name)) { + log("ms-duplex-radio已经更名为ms-duplex-checked") + name = "checked" + data.isChecked = true } - data.param.replace(/\w+/g, function(name) { - if (/^(checkbox|radio)$/.test(elem.type) && /^(radio|checked)$/.test(name)) { - log("ms-duplex-radio已经更名为ms-duplex-checked") - name = "checked" - data.isChecked = true - } - if (name === "bool") { - name = "boolean" - log("ms-duplex-bool已经更名为ms-duplex-boolean") - } else if (name === "text") { - name = "string" - log("ms-duplex-text已经更名为ms-duplex-string") - } - if (casting[name]) { - hasCast = true - } - avalon.Array.ensure(params, name) - }) - if (!hasCast) { - params.push("string") + if (name === "bool") { + name = "boolean" + log("ms-duplex-bool已经更名为ms-duplex-boolean") + } else if (name === "text") { + name = "string" + log("ms-duplex-text已经更名为ms-duplex-string") } - data.param = params.join("-") - data.bound = function(type, callback) { - elem.addEventListener(type, callback) - var old = data.rollback - data.rollback = function() { - elem.removeEventListener(type, callback) - old && old() - } + if (casting[name]) { + hasCast = true } - for (var i in avalon.vmodels) { - var v = avalon.vmodels[i] - v.$fire("avalon-ms-duplex-init", data) + avalon.Array.ensure(params, name) + }) + if (!hasCast) { + params.push("string") + } + data.param = params.join("-") + data.bound = function(type, callback) { + elem.addEventListener(type, callback) + var old = data.rollback + data.rollback = function() { + elem.removeEventListener(type, callback) + old && old() } - var cpipe = data.pipe || (data.pipe = pipe) - cpipe(null, data, "init") - duplexBinding[elem.tagName](elem, data.evaluator.apply(null, data.args), data) } + for (var i in avalon.vmodels) { + var v = avalon.vmodels[i] + v.$fire("avalon-ms-duplex-init", data) + } + var cpipe = data.pipe || (data.pipe = pipe) + cpipe(null, data, "init") + var tagName = elem.tagName + duplexBinding[tagName] && duplexBinding[tagName](elem, data.evaluator.apply(null, data.args), data) } }, "repeat": function(data, vmodels) { diff --git a/avalon.modern.min.js b/avalon.modern.min.js index e694928a3..0b322c02e 100644 --- a/avalon.modern.min.js +++ b/avalon.modern.min.js @@ -1,106 +1,106 @@ -(function(p){function v(){}function t(){avalon.config.debug&&console.log.apply(console,arguments)}function J(b,c){"string"===typeof b&&(b=b.match(w)||[]);for(var d={},e=void 0!==c?c:1,f=0,g=b.length;f=Object.keys(e).length){var S=e.set,E=e.get;l=function(b){var e=f.$events,g=d[c]; -if(arguments.length){if(ca)return;if(R(S)){var h=e[c];e[c]=[];S.call(f,b);e[c]=h}}else avalon.openComputedCollect&&da(e[c]);b=d[c]=E.call(f);if(!ea(g,b)){if(fa&&(h=T[f.$id])&&h[c])h[c].$val=b;oa(e[c]);f.$events&&P.$fire.call(f,c,b,g)}return b};k.push(function(){V[A]={evaluator:l,element:G,type:"computed::"+c,handler:v,args:[]};l();da(g[c]);delete V[A]})}else La.test(C)?(l=function(b){var e=l.child,h=d[c];if(arguments.length)!ca&&!ea(h,b)&&(e=l.child=xb(f,c,b,C),b=d[c]=e.$model,(e=pa[e.$id])&&e(), -f.$events&&P.$fire.call(f,c,b,h));else return da(g[c]),e},(l.child=K(e,0,d[c])).$events[F]=g[c]):l=function(b){var e=d[c];if(arguments.length){if(!ea(e,b)){d[c]=b;if(fa){var h=T[f.$id];h&&h[c]&&(h[c].$val=b)}oa(g[c]);f.$events&&P.$fire.call(f,c,b,e)}}else return da(g[c]),e};h[c]=l}})(e,b[e]);Ka.forEach(function(c){delete b[c];delete d[c]});Object.defineProperties(f,yb(h));for(var l in b)h[l]||(f[l]=b[l]);f.$id=ba();f.$model=d;f.$events=g;for(e in P)f[e]=P[e];Object.defineProperty(f,"hasOwnProperty", -{value:function(b){return b in f.$model},writable:!1,enumerable:!1,configurable:!0});k.forEach(function(b){b()});return f}function yb(b){var c={},d;for(d in b)c[d]={get:b[d],set:b[d],enumerable:!0,configurable:!0};return c}function xb(b,c,d,e){var f=b[c];if("array"===e){if(!Array.isArray(d)||f===d)return f;f.clear();f.pushArray(d.concat());return f}var g=b.$events[c];T[f.$id]&&(fa--,delete T[f.$id]);var h=K(d);h.$events[F]=g;pa[h.$id]=function(b){for(;b=g.shift();)(function(b){b.type&&avalon.nextTick(function(){b.rollback&& +(function(q){function v(){}function t(){avalon.config.debug&&console.log.apply(console,arguments)}function I(b,c){"string"===typeof b&&(b=b.match(w)||[]);for(var d={},e=void 0!==c?c:1,f=0,g=b.length;f=Object.keys(e).length){var S=e.set,D=e.get;p=function(b){var e=f.$events,g=d[c]; +if(arguments.length){if(ca)return;if(R(S)){var h=e[c];e[c]=[];S.call(f,b);e[c]=h}}else avalon.openComputedCollect&&da(e[c]);b=d[c]=D.call(f);if(!ea(g,b)){if(fa&&(h=T[f.$id])&&h[c])h[c].$val=b;oa(e[c]);f.$events&&P.$fire.call(f,c,b,g)}return b};k.push(function(){V[A]={evaluator:p,element:F,type:"computed::"+c,handler:v,args:[]};p();da(g[c]);delete V[A]})}else La.test(l)?(p=function(b){var e=p.child,h=d[c];if(arguments.length)!ca&&!ea(h,b)&&(e=p.child=xb(f,c,b,l),b=d[c]=e.$model,(e=pa[e.$id])&&e(), +f.$events&&P.$fire.call(f,c,b,h));else return da(g[c]),e},(p.child=J(e,0,d[c])).$events[E]=g[c]):p=function(b){var e=d[c];if(arguments.length){if(!ea(e,b)){d[c]=b;if(fa){var h=T[f.$id];h&&h[c]&&(h[c].$val=b)}oa(g[c]);f.$events&&P.$fire.call(f,c,b,e)}}else return da(g[c]),e};h[c]=p}})(e,b[e]);Ka.forEach(function(c){delete b[c];delete d[c]});Object.defineProperties(f,yb(h));for(var l in b)h[l]||(f[l]=b[l]);f.$id=ba();f.$model=d;f.$events=g;for(e in P)f[e]=P[e];Object.defineProperty(f,"hasOwnProperty", +{value:function(b){return b in f.$model},writable:!1,enumerable:!1,configurable:!0});k.forEach(function(b){b()});return f}function yb(b){var c={},d;for(d in b)c[d]={get:b[d],set:b[d],enumerable:!0,configurable:!0};return c}function xb(b,c,d,e){var f=b[c];if("array"===e){if(!Array.isArray(d)||f===d)return f;f.clear();f.pushArray(d.concat());return f}var g=b.$events[c];T[f.$id]&&(fa--,delete T[f.$id]);var h=J(d);h.$events[E]=g;pa[h.$id]=function(b){for(;b=g.shift();)(function(b){b.type&&avalon.nextTick(function(){b.rollback&& b.rollback();u[b.type](b,b.vmodels)})})(b);delete pa[h.$id]};return h}function s(b){for(var c in b)if(Ma.call(b,c)){var d=b[c];if("function"===typeof s.plugins[c])s.plugins[c](d);else"object"===typeof s[c]?avalon.mix(s[c],d):s[c]=d}return this}function Na(b){return b.replace(/([a-z\d])([A-Z]+)/g,"$1-$2").toLowerCase()}function ga(b){return 0>b.indexOf("-")&&0>b.indexOf("_")?b:b.replace(/[-_][^-_]/g,function(b){return b.charAt(1).toUpperCase()})}function ha(b){try{b="true"===b?!0:"false"===b?!1:"null"=== b?null:+b+""===b?+b:zb.test(b)?JSON.parse(b):b}catch(c){}return b}function Oa(b,c){if(0>=b.offsetWidth){var d=getComputedStyle(b,null);if(Ab.test(d.display)){var e={node:b},f;for(f in Pa)e[f]=d[f],b.style[f]=Pa[f];c.push(e)}(d=b.parentNode)&&1===d.nodeType&&Oa(d,c)}}function qa(b){V[A]=b;avalon.openComputedCollect=!0;var c=b.evaluator;if(c)try{var d=Bb.test(b.type)?b:c.apply(0,b.args);b.handler(d,b.element,b)}catch(e){t("warning:exception throwed in [registerSubscriber] "+e),delete b.evaluator,c= -b.element,3===c.nodeType&&(d=c.parentNode,s.commentInterpolate?d.replaceChild(p.createComment(b.value),c):c.data=L+b.value+M)}avalon.openComputedCollect=!1;delete V[A]}function da(b){var c=V[A];b&&(c&&avalon.Array.ensure(b,c)&&c.element)&&Qa(c,b)}function Qa(b,c){b.$uuid=b.$uuid||ba();c.$uuid=c.$uuid||ba();var d={data:b,list:c,toString:function(){return b.$uuid+" "+c.$uuid}};Q[d]||(Q[d]=1,Q.push(d))}function Ra(){for(var b=ra,c=ra+Cb;bb&&delete c[d.shift()];return c[e]=f}var d=[];return c}function eb(b,c,d){var e=d.type,f=d.filters?d.filters.join(""):"",g=c.map(function(b){return b.$id.replace(Lb, -"$1")})+b+e+f,h=Mb(b).concat(),k=[],l=[],m=[],n="";c=cb(c);for(var q=0,n=c.length;qs.maxRepeatSize&&Z.pop()}b.length=0}function $(){z?(r["ready!"].state=2,z.checkDeps()):lb.forEach(function(b){b(avalon)});$=v}var A=Date.now(),F="$"+A,x=Function("return this")(),Wb=x.require,Xb=x.define, -ca=!1,w=/[^, ]+/g,La=/^(?:object|array)$/,mb=/^\[object SVG\w*Element\]$/,Yb=/^\[object (Window|DOMWindow|global)\]$/,Aa=Object.prototype,Ma=Aa.hasOwnProperty,Ba=Aa.toString,N=Array.prototype,ia=N.slice,V={},G=p.head,D=p.documentElement,H=p.createDocumentFragment(),la=p.createElement("div"),nb={};"Boolean Number String Function Array Date RegExp Object Error".replace(w,function(b){nb["[object "+b+"]"]=b.toLowerCase()});x.avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]= +b="\nreturn "+b+";",e=b.lastIndexOf("\nreturn"),p=b.slice(0,e),b=b.slice(e),b=p+"\n"+b):b="\nreturn "+b+";"}try{c=Function.apply(v,l.concat("'use strict';\n"+n+b)),d.evaluator=wa(g,c)}catch(D){t("debug: parse error,"+D.message)}finally{h=e=l=null}}}function H(b,c,d,e,f){c.cb(-1);Array.isArray(e)&&(b=e.map(function(b){return b.expr?"("+b.value+")":JSON.stringify(b.value)}).join(" + "));eb(b,c,d);d.evaluator&&!f&&(d.handler=xa[d.handlerName||d.type],d.evaluator.toString=function(){return d.type+" binding to eval("+ +b+")"},qa(d))}function X(b,c){var d="_"+b;if(!X[d]){var e=q.createElement(b);C.appendChild(e);c=getComputedStyle(e,null).display;C.removeChild(e);X[d]=c}return X[d]}function ya(b){return null==b?"":b}function Ob(b,c,d){c.param.replace(/\w+/g,function(e){(e=avalon.duplexHooks[e])&&"function"===typeof e[d]&&(b=e[d](b,c))});return b}function fb(b){var c=arguments.length?b:this.value;if(!this.disabled&&this.oldValue!==c){var c=this.getAttribute("data-duplex-event")||"input",c=c.match(w).shift(),d=q.createEvent("Events"); +d.initEvent(c,!0,!0);this.dispatchEvent(d)}}function Pb(){for(var b=Y.length-1;0<=b;b--)!1===(0,Y[b])()&&Y.splice(b,1);Y.length||clearInterval(gb)}function Qb(b){Rb.call(this,b);fb.call(this,b)}function wb(b){var c=[];c.$id=ba();c.$model=b;c.$events={};c.$events[E]=[];c._=J({length:b.length});c._.$watch("length",function(b,d){c.$fire("length",b,d)});for(var d in P)c[d]=P[d];avalon.mix(c,hb);return c}function ib(b,c,d,e){var f=avalon.parseHTML(b.template),g=avalon.slice(f.childNodes);c.appendChild(f); +d.$outer=b.$outer;b=b.vmodels;d=[d].concat(b);d.cb=b.cb;e.push({nodes:g,vmodels:d})}function za(b,c){var d=b.endRepeat,e=[],f=b.element.nextSibling;if(f!==d){do if(f!==d)e.push(f);else break;while(f=f.nextSibling)}return e[b.group*c]||d}function jb(b,c,d){c*=d||1;d=[b];for(var e=1,f=G;es.maxRepeatSize&&Z.pop()}b.length=0}function $(){z?(r["ready!"].state=2,z.checkDeps()):lb.forEach(function(b){b(avalon)});$=v}var A=Date.now(),E="$"+A,x=Function("return this")(),Wb=x.require,Xb=x.define, +ca=!1,w=/[^, ]+/g,La=/^(?:object|array)$/,mb=/^\[object SVG\w*Element\]$/,Yb=/^\[object (Window|DOMWindow|global)\]$/,Aa=Object.prototype,Ma=Aa.hasOwnProperty,Ba=Aa.toString,N=Array.prototype,ia=N.slice,V={},F=q.head,C=q.documentElement,G=q.createDocumentFragment(),la=q.createElement("div"),nb={};"Boolean Number String Function Array Date RegExp Object Error".replace(w,function(b){nb["[object "+b+"]"]=b.toLowerCase()});x.avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]= this.element=b};avalon.fn=avalon.prototype=avalon.init.prototype;avalon.isFunction=R;avalon.type=function(b){return null==b?String(b):"object"===typeof b||"function"===typeof b?nb[Ba.call(b)]||"object":typeof b};avalon.isWindow=function(b){return Yb.test(Ba.call(b))};avalon.isPlainObject=function(b){return!!b&&"object"===typeof b&&Object.getPrototypeOf(b)===Aa};avalon.mix=avalon.fn.mix=function(){var b,c,d,e,f,g=arguments[0]||{},h=1,k=arguments.length,l=!1;"boolean"===typeof g&&(l=g,g=arguments[1]|| -{},h++);"object"!==typeof g&&"function"!==avalon.type(g)&&(g={});h===k&&(g=this,h--);for(;h';if(!mb.test(ob.firstChild)){var Ca=function(b,c){if(b&&b.childNodes)for(var d=b.childNodes, -e=0,f;f=d[e++];)if(f.tagName){var g=p.createElementNS("http://www.w3.org/2000/svg",f.tagName.toLowerCase());N.forEach.call(f.attributes,function(b){g.setAttribute(b.name,b.value)});Ca(f,g);c.appendChild(g)}};Object.defineProperties(SVGElement.prototype,{outerHTML:{enumerable:!0,configurable:!0,get:function(){return(new XMLSerializer).serializeToString(this)},set:function(b){var c=this.tagName.toLowerCase(),d=this.parentNode;b=avalon.parseHTML(b);"svg"===c?d.insertBefore(b,this):(c=p.createDocumentFragment(), +avalon.nextTick=x.setImmediate?setImmediate.bind(x):function(b){setTimeout(b,0)};C.contains||(Node.prototype.contains=function(b){return!!(this.compareDocumentPosition(b)&16)});avalon.contains=function(b,c){try{for(;c=c.parentNode;)if(c===b)return!0;return!1}catch(d){return!1}};if(x.SVGElement){var ob=q.createElementNS("http://www.w3.org/2000/svg","svg");ob.innerHTML='';if(!mb.test(ob.firstChild)){var Ca=function(b,c){if(b&&b.childNodes)for(var d=b.childNodes, +e=0,f;f=d[e++];)if(f.tagName){var g=q.createElementNS("http://www.w3.org/2000/svg",f.tagName.toLowerCase());N.forEach.call(f.attributes,function(b){g.setAttribute(b.name,b.value)});Ca(f,g);c.appendChild(g)}};Object.defineProperties(SVGElement.prototype,{outerHTML:{enumerable:!0,configurable:!0,get:function(){return(new XMLSerializer).serializeToString(this)},set:function(b){var c=this.tagName.toLowerCase(),d=this.parentNode;b=avalon.parseHTML(b);"svg"===c?d.insertBefore(b,this):(c=q.createDocumentFragment(), Ca(b,c),d.insertBefore(c,this));d.removeChild(this)}},innerHTML:{enumerable:!0,configurable:!0,get:function(){var b=RegExp("$","i");return this.outerHTML.replace(RegExp("<"+this.nodeName+'\\b(?:(["\'])[^"]*?(\\1)|[^>])*>',"i"),"").replace(b,"")},set:function(b){avalon.clearHTML&&(avalon.clearHTML(this),b=avalon.parseHTML(b),Ca(b,this))}}})}}var ka=avalon.vmodels={};avalon.define=function(b,c){var d=b.$id||b;d||t("warning: \u5fc5\u987b\u6307\u5b9a$id");ka[d]&&t("warning: "+d+" \u5df2\u7ecf\u5b58\u5728\u4e8eavalon.vmodels\u4e2d"); -if("object"===typeof b)var e=K(b);else e={$watch:v},c(e),e=K(e),ca=!0,c(e),ca=!1;e.$id=d;return ka[d]=e};var Ka="$id,$watch,$unwatch,$fire,$events,$model,$skipArray".match(w),ea=Object.is||function(b,c){return 0===b&&0===c?1/b===1/c:b!==b?c!==c:b===c},T={},fa=0,pa={},L,M,W,pb,bb,qb=/[-.*+?^${}()|[\]\/\\]/g,z=v,O={loader:function(b){x.define=b?z.define:Xb;x.require=b?z:Wb},interpolate:function(b){L=b[0];M=b[1];L===M?avalon.error("openTag!==closeTag",SyntaxError):"\x3c!--,--\x3e"===b+""?s.commentInterpolate= +if("object"===typeof b)var e=J(b);else e={$watch:v},c(e),e=J(e),ca=!0,c(e),ca=!1;e.$id=d;return ka[d]=e};var Ka="$id,$watch,$unwatch,$fire,$events,$model,$skipArray".match(w),ea=Object.is||function(b,c){return 0===b&&0===c?1/b===1/c:b!==b?c!==c:b===c},T={},fa=0,pa={},L,M,W,pb,bb,qb=/[-.*+?^${}()|[\]\/\\]/g,z=v,O={loader:function(b){x.define=b?z.define:Xb;x.require=b?z:Wb},interpolate:function(b){L=b[0];M=b[1];L===M?avalon.error("openTag!==closeTag",SyntaxError):"\x3c!--,--\x3e"===b+""?s.commentInterpolate= !0:(b=L+"test"+M,la.innerHTML=b,la.innerHTML!==b&&0<=la.innerHTML.indexOf("<")&&avalon.error("\u6b64\u5b9a\u754c\u7b26\u4e0d\u5408\u6cd5",SyntaxError),la.innerHTML="");b=(L+"").replace(qb,"\\$&");var c=(M+"").replace(qb,"\\$&");W=RegExp(b+"(.*?)"+c);pb=RegExp(b+"(.*?)"+c,"g");bb=RegExp(b+".*?"+c+"|\\sms-")}};s.debug=!0;s.plugins=O;s.plugins.interpolate(["{{","}}"]);s.paths={};s.shim={};s.maxRepeatSize=100;avalon.config=s;"add,remove".replace(w,function(b){avalon.fn[b+"Class"]=function(c){var d= this[0];c&&("string"===typeof c&&d&&1===d.nodeType)&&c.replace(/\S+/g,function(c){d.classList[b](c)});return this}});avalon.fn.mix({hasClass:function(b){var c=this[0]||{};return 1===c.nodeType&&c.classList.contains(b)},toggleClass:function(b,c){for(var d,e=0,f=b.split(/\s+/),g="boolean"===typeof c;d=f[e++];)this[(g?c:!this.hasClass(d))?"addClass":"removeClass"](d);return this},attr:function(b,c){return 2===arguments.length?(this[0].setAttribute(b,c),this):this[0].getAttribute(b)},data:function(b, c){b="data-"+Na(b||"");switch(arguments.length){case 2:return this.attr(b,c),this;case 1:var d=this.attr(b);return ha(d);case 0:var e={};N.forEach.call(this[0].attributes,function(c){c&&(b=c.name,b.indexOf("data-")||(b=ga(b.slice(5)),e[b]=ha(c.value)))});return e}},removeData:function(b){b="data-"+Na(b);this[0].removeAttribute(b);return this},css:function(b,c){if(avalon.isPlainObject(b))for(var d in b)avalon.css(this,d,b[d]);else var e=avalon.css(this,b,c);return void 0!==e?e:this},position:function(){var b, -c,d=this[0],e={top:0,left:0};if(d)return"fixed"===this.css("position")?c=d.getBoundingClientRect():(b=this.offsetParent(),c=this.offset(),"HTML"!==b[0].tagName&&(e=b.offset()),e.top+=avalon.css(b[0],"borderTopWidth",!0),e.left+=avalon.css(b[0],"borderLeftWidth",!0)),{top:c.top-e.top-avalon.css(d,"marginTop",!0),left:c.left-e.left-avalon.css(d,"marginLeft",!0)}},offsetParent:function(){for(var b=this[0].offsetParent||D;b&&"HTML"!==b.tagName&&"static"===avalon.css(b,"position");)b=b.offsetParent;return avalon(b|| -D)},bind:function(b,c,d){if(this[0])return avalon.bind(this[0],b,c,d)},unbind:function(b,c,d){this[0]&&avalon.unbind(this[0],b,c,d);return this},val:function(b){var c=this[0];if(c&&1===c.nodeType){var d=0===arguments.length,e=d?":get":":set",f=Zb,g;g=c.tagName.toLowerCase();g="input"===g&&/checkbox|radio/.test(c.type)?"checked":g;if(e=f[g+e])var h=e(c,b);else{if(d)return(c.value||"").replace(/\r/g,"");c.value=b}}return d?h:this}});D.dataset&&(avalon.fn.data=function(b,c){var d=this[0].dataset;switch(arguments.length){case 2:return d[b]= +c,d=this[0],e={top:0,left:0};if(d)return"fixed"===this.css("position")?c=d.getBoundingClientRect():(b=this.offsetParent(),c=this.offset(),"HTML"!==b[0].tagName&&(e=b.offset()),e.top+=avalon.css(b[0],"borderTopWidth",!0),e.left+=avalon.css(b[0],"borderLeftWidth",!0)),{top:c.top-e.top-avalon.css(d,"marginTop",!0),left:c.left-e.left-avalon.css(d,"marginLeft",!0)}},offsetParent:function(){for(var b=this[0].offsetParent||C;b&&"HTML"!==b.tagName&&"static"===avalon.css(b,"position");)b=b.offsetParent;return avalon(b|| +C)},bind:function(b,c,d){if(this[0])return avalon.bind(this[0],b,c,d)},unbind:function(b,c,d){this[0]&&avalon.unbind(this[0],b,c,d);return this},val:function(b){var c=this[0];if(c&&1===c.nodeType){var d=0===arguments.length,e=d?":get":":set",f=Zb,g;g=c.tagName.toLowerCase();g="input"===g&&/checkbox|radio/.test(c.type)?"checked":g;if(e=f[g+e])var h=e(c,b);else{if(d)return(c.value||"").replace(/\r/g,"");c.value=b}}return d?h:this}});C.dataset&&(avalon.fn.data=function(b,c){var d=this[0].dataset;switch(arguments.length){case 2:return d[b]= c,this;case 1:return c=d[b],ha(c);case 0:var e={};for(b in d)e[b]=ha(d[b]);return e}});var zb=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/;avalon.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(b,c){avalon.fn[b]=function(d){var e=this[0]||{},f=e.window&&e.document?e:9===e.nodeType?e.defaultView:!1,g="scrollTop"===b;if(arguments.length)f?f.scrollTo(!g?d:avalon(f).scrollLeft(),g?d:avalon(f).scrollTop()):e[b]=d;else return f?f[c]:e[b]}});var y=avalon.cssHooks={},rb=["","-webkit-","-moz-","-ms-"], -Da={"float":"cssFloat"};avalon.cssNumber=J("columnCount,order,fillOpacity,fontWeight,lineHeight,opacity,orphans,widows,zIndex,zoom");avalon.cssName=function(b,c,d){if(Da[b])return Da[b];c=c||D.style;for(var e=0,f=rb.length;el&&(e=e-avalon.css(c,"border"+d[0]+"Width",!0)-avalon.css(c,"border"+d[1]+"Width",!0));-4===l&&(e=e-avalon.css(c,"padding"+d[0],!0)-avalon.css(c,"padding"+d[1],!0));return e};y[c+"&get"]=function(b){var d=[];Oa(b,d);for(var e=y[c+":get"](b),f=0,m;m=d[f++];){b=m.node;for(var n in m)"string"===typeof m[n]&&(b.style[n]=m[n])}return e};avalon.fn[c]=function(g){var h= this[0];if(0===arguments.length){if(h.setTimeout)return h["inner"+b]||h.document.documentElement[d];if(9===h.nodeType){var k=h.documentElement;return Math.max(h.body[e],k[e],h.body[f],k[f],k[d])}return y[c+"&get"](h)}return this.css(c,g)};avalon.fn["inner"+b]=function(){return y[c+":get"](this[0],void 0,-2)};avalon.fn["outer"+b]=function(b){return y[c+":get"](this[0],void 0,!0===b?2:0)}});avalon.fn.offset=function(){var b=this[0],c={left:0,top:0};if(!b||!b.tagName||!b.ownerDocument)return c;var d= b.ownerDocument,e=d.documentElement,d=d.defaultView;if(!e.contains(b))return c;void 0!==b.getBoundingClientRect&&(c=b.getBoundingClientRect());return{top:c.top+d.pageYOffset-e.clientTop,left:c.left+d.pageXOffset-e.clientLeft}};var Zb={"select:get":function(b,c){for(var d,e=b.options,f=b.selectedIndex,g="select-one"===b.type||0>f,h=g?null:[],k=g?f+1:e.length,l=0>f?k:g?f:0;l]*)\/>/ig,bc=J(["","text/javascript","text/ecmascript","application/ecmascript","application/javascript"]),cc=p.createElement("script");avalon.parseHTML=function(b){"string"!==typeof b&&(b+= -"");b=b.replace(ac,"<$1>").trim();var c=($b.exec(b)||["",""])[1].toLowerCase(),c=B[c]||B._default,d=H.cloneNode(!1);c.innerHTML=b;b=c.getElementsByTagName("script");if(b.length)for(var e=0,f;f=b[e++];)if(bc[f.type]){var g=cc.cloneNode(!1);N.forEach.call(f.attributes,function(b){g.setAttribute(b.name,b.value)});g.text=f.text;f.parentNode.replaceChild(g,f)}for(;b=c.firstChild;)d.appendChild(b);return d};avalon.innerHTML=function(b,c){var d=this.parseHTML(c);this.clearHTML(b).appendChild(d)};avalon.clearHTML= +[].concat(c);for(var e=0,f;f=b.options[e++];)if(f.selected=0<=c.indexOf(f.value))d=!0;d||(b.selectedIndex=-1)}},B=new function(){avalon.mix(this,{option:q.createElement("select"),thead:q.createElement("table"),td:q.createElement("tr"),area:q.createElement("map"),tr:q.createElement("tbody"),col:q.createElement("colgroup"),legend:q.createElement("fieldset"),_default:q.createElement("div"),g:q.createElementNS("http://www.w3.org/2000/svg","svg")});this.optgroup=this.option;this.tbody=this.tfoot=this.colgroup= +this.caption=this.thead;this.th=this.td};B.optgroup=B.option;B.tbody=B.tfoot=B.colgroup=B.caption=B.thead;B.th=B.td;"circle,defs,ellipse,image,line,path,polygon,polyline,rect,symbol,text,use".replace(w,function(b){B[b]=B.g});var $b=/<([\w:]+)/,ac=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,bc=I(["","text/javascript","text/ecmascript","application/ecmascript","application/javascript"]),cc=q.createElement("script");avalon.parseHTML=function(b){"string"!==typeof b&&(b+= +"");b=b.replace(ac,"<$1>").trim();var c=($b.exec(b)||["",""])[1].toLowerCase(),c=B[c]||B._default,d=G.cloneNode(!1);c.innerHTML=b;b=c.getElementsByTagName("script");if(b.length)for(var e=0,f;f=b[e++];)if(bc[f.type]){var g=cc.cloneNode(!1);N.forEach.call(f.attributes,function(b){g.setAttribute(b.name,b.value)});g.text=f.text;f.parentNode.replaceChild(g,f)}for(;b=c.firstChild;)d.appendChild(b);return d};avalon.innerHTML=function(b,c){var d=this.parseHTML(c);this.clearHTML(b).appendChild(d)};avalon.clearHTML= function(b){for(b.textContent="";b.firstChild;)b.removeChild(b.firstChild);return b};var P={$watch:function(b,c){if("function"===typeof c){var d=this.$events[b];d?d.push(c):this.$events[b]=[c]}else this.$events=this.$watch.backup;return this},$unwatch:function(b,c){var d=arguments.length;if(0===d)this.$watch.backup=this.$events,this.$events={};else if(1===d)this.$events[b]=[];else for(var d=this.$events[b]||[],e=d.length;0>~--e;)if(d[e]===c)return d.splice(e,1);return this},$fire:function(b){var c; -/^(\w+)!(\S+)$/.test(b)&&(c=RegExp.$1,b=RegExp.$2);var d=this.$events,e=ia.call(arguments,1),f=[b].concat(e);if("all"===c)for(var g in avalon.vmodels)e=avalon.vmodels[g],e!==this&&e.$fire.apply(e,f);else if("up"===c||"down"===c){if(d=d.expr&&p.querySelector(d.expr)){for(g in avalon.vmodels)if(e=avalon.vmodels[g],e!==this&&e.$events.expr){var h=p.querySelector(e.$events.expr);if(h&&("down"===c?d.contains(h):h.contains(d)))h._avalon=e}g=p.getElementsByTagName("*");var k=[];Array.prototype.forEach.call(g, -function(b){b._avalon&&(k.push(b._avalon),b._avalon="",b.removeAttribute("_avalon"))});"up"===c&&k.reverse();for(g=0;(c=k[g++])&&!1!==c.$fire.apply(c,f););}}else{f=d[b]||[];c=d.$all||[];for(g=0;d=f[g++];)R(d)&&d.apply(this,e);for(g=0;d=c[g++];)R(d)&&d.apply(this,arguments)}}},Bb=/^(duplex|on)$/,Q=[],ra=0,Cb=200,Sa=Date.now(),Ta,Ea={};avalon.scanCallback=function(b,c){c=c||"$all";(Ea[c]||(Ea[c]=[])).push(b)};avalon.scan=function(b,c,d){b=b||D;var e=Ea[d||"$all"]||[];c=c?[].concat(c):[];var f=0,g=!1, -h,k=!1;c.cb=function(b){f+=b;k=!0;setTimeout(function(){if(0>=f&&!g)for(g=!0;h=e.shift();)h()})};Ua(b,c);if(!k)for(;h=e.shift();)h()};var Gb=J("AREA,BASE,BASEFONT,BR,COL,COMMAND,EMBED,HR,IMG,INPUT,LINK,META,PARAM,SOURCE,TRACK,WBR,NOSCRIPT,NOSCRIPT,SCRIPT,STYLE,TEXTAREA"),Db=/ms-(\w+)-?(.*)/,ab={"if":10,repeat:90,data:100,widget:110,each:1400,"with":1500,duplex:2E3,on:3E3},Eb=J("animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scan,scroll,submit"), -Fb=J("value,title,alt,checked,selected,disabled,readonly,enabled"),Ib=/\|\s*(\w+)\s*(\([^)]*\))?/g,Hb=/\|\|/g,Jb=/U2hvcnRDaXJjdWl0/g,dc=/\/\*[\w\W]*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|"(?:[^"\\]|\\[\w\W])*"|'(?:[^'\\]|\\[\w\W])*'|[\s\t\n]*\.[\s\t\n]*[$\w\.]+/g,ec=/[^\w$]+/g,fc=RegExp(""+("\\b"+"break,case,catch,continue,debugger,default,delete,do,else,false,finally,for,function,if,in,instanceof,new,null,return,switch,this,throw,true,try,typeof,var,void,while,with,abstract,boolean,byte,char,class,const,double,enum,export,extends,final,float,goto,implements,import,int,interface,long,native,package,private,protected,public,short,static,super,synchronized,throws,transient,volatile,arguments,let,yield,undefined".replace(/,/g, -"\\b|\\b")+"\\b"),"g"),gc=/\b\d[^,]*/g,hc=/^,+|,+$/g,Fa=db(512),Mb=function(b){var c=","+b.trim();if(Fa[c])return Fa[c];b=b.replace(dc,"").replace(ec,",").replace(fc,"").replace(gc,"").replace(hc,"").split(/^$|,+/);return Fa(c,cb(b))},wa=db(128),Nb=/\w\[.*\]|\w\.\w/,Lb=/(\$proxy\$[a-z]+)\d+$/;avalon.parseExprProxy=I;G.insertAdjacentHTML("afterBegin",'');var sa=G.firstChild,aa=function(b,c,d){if(b=b.getAttribute(c)){c= +/^(\w+)!(\S+)$/.test(b)&&(c=RegExp.$1,b=RegExp.$2);var d=this.$events,e=ia.call(arguments,1),f=[b].concat(e);if("all"===c)for(var g in avalon.vmodels)e=avalon.vmodels[g],e!==this&&e.$fire.apply(e,f);else if("up"===c||"down"===c){if(d=d.expr&&q.querySelector(d.expr)){for(g in avalon.vmodels)if(e=avalon.vmodels[g],e!==this&&e.$events.expr){var h=q.querySelector(e.$events.expr);if(h&&("down"===c?d.contains(h):h.contains(d)))h._avalon=e}g=q.getElementsByTagName("*");var k=[];Array.prototype.forEach.call(g, +function(b){b._avalon&&(k.push(b._avalon),b._avalon="",b.removeAttribute("_avalon"))});"up"===c&&k.reverse();for(g=0;(c=k[g++])&&!1!==c.$fire.apply(c,f););}}else{f=d[b]||[];c=d.$all||[];for(g=0;d=f[g++];)R(d)&&d.apply(this,e);for(g=0;d=c[g++];)R(d)&&d.apply(this,arguments)}}},Bb=/^(duplex|on)$/,Q=[],ra=0,Cb=200,Sa=Date.now(),Ta,Ea={};avalon.scanCallback=function(b,c){c=c||"$all";(Ea[c]||(Ea[c]=[])).push(b)};avalon.scan=function(b,c,d){b=b||C;var e=Ea[d||"$all"]||[];c=c?[].concat(c):[];var f=0,g=!1, +h,k=!1;c.cb=function(b){f+=b;k=!0;setTimeout(function(){if(0>=f&&!g)for(g=!0;h=e.shift();)h()})};Ua(b,c);if(!k)for(;h=e.shift();)h()};var Gb=I("AREA,BASE,BASEFONT,BR,COL,COMMAND,EMBED,HR,IMG,INPUT,LINK,META,PARAM,SOURCE,TRACK,WBR,NOSCRIPT,NOSCRIPT,SCRIPT,STYLE,TEXTAREA"),Db=/ms-(\w+)-?(.*)/,ab={"if":10,repeat:90,data:100,widget:110,each:1400,"with":1500,duplex:2E3,on:3E3},Eb=I("animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scan,scroll,submit"), +Fb=I("value,title,alt,checked,selected,disabled,readonly,enabled"),Ib=/\|\s*(\w+)\s*(\([^)]*\))?/g,Hb=/\|\|/g,Jb=/U2hvcnRDaXJjdWl0/g,dc=/\/\*[\w\W]*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|"(?:[^"\\]|\\[\w\W])*"|'(?:[^'\\]|\\[\w\W])*'|[\s\t\n]*\.[\s\t\n]*[$\w\.]+/g,ec=/[^\w$]+/g,fc=RegExp(""+("\\b"+"break,case,catch,continue,debugger,default,delete,do,else,false,finally,for,function,if,in,instanceof,new,null,return,switch,this,throw,true,try,typeof,var,void,while,with,abstract,boolean,byte,char,class,const,double,enum,export,extends,final,float,goto,implements,import,int,interface,long,native,package,private,protected,public,short,static,super,synchronized,throws,transient,volatile,arguments,let,yield,undefined".replace(/,/g, +"\\b|\\b")+"\\b"),"g"),gc=/\b\d[^,]*/g,hc=/^,+|,+$/g,Fa=db(512),Mb=function(b){var c=","+b.trim();if(Fa[c])return Fa[c];b=b.replace(dc,"").replace(ec,",").replace(fc,"").replace(gc,"").replace(hc,"").split(/^$|,+/);return Fa(c,cb(b))},wa=db(128),Nb=/\w\[.*\]|\w\.\w/,Lb=/(\$proxy\$[a-z]+)\d+$/;avalon.parseExprProxy=H;F.insertAdjacentHTML("afterBegin",'');var sa=F.firstChild,aa=function(b,c,d){if(b=b.getAttribute(c)){c= 0;for(var e;e=d[c++];)if(e.hasOwnProperty(b)&&"function"===typeof e[b])return e[b]}},Ga=avalon.templateCache={},Ha={};"autofocus,autoplay,async,checked,controls,declare,disabled,defer,defaultChecked,defaultSelectedcontentEditable,isMap,loop,multiple,noHref,noResize,noShade,open,readOnly,selected".replace(w,function(b){Ha[b.toLowerCase()]=b});var xa=avalon.bindingExecutors={attr:function(b,c,d){var e=d.type,f=d.param;if("css"===e)avalon(c).css(f,b);else if("attr"===e){if(Ha[f]&&(e=Ha[f],"boolean"=== typeof c[e]))return c[e]=!!b;if(!1===b||null===b||void 0===b)return c.removeAttribute(f);(mb.test(c)?0:f in c.cloneNode(!1))?c[f]=b:c.setAttribute(f,b)}else if("include"===e&&b){var g=d.vmodels,h=d.includeRendered,k=d.includeLoaded,l=d.includeReplaced?c.parentNode:c,m=function(b){k&&(b=k.apply(l,[b].concat(g)));for(h&&ja(l,function(){h.call(l)},NaN);;){var c=d.startInclude.nextSibling;if(c&&c!==d.endInclude)l.removeChild(c);else break}b=avalon.parseHTML(b);c=avalon.slice(b.childNodes);l.insertBefore(b, -d.endInclude);ta(c,g);g.cb(-1)};if("src"===d.param)if(Ga[b])avalon.nextTick(function(){m(Ga[b])});else{var n=new x.XMLHttpRequest;n.onload=function(){var c=n.status;if(200<=c&&300>c||304===c)m(Ga[b]=n.responseText)};n.open("GET",b,!0);n.withCredentials=!0;n.setRequestHeader("X-Requested-With","XMLHttpRequest");n.send(null)}else{var q=b&&1==b.nodeType?b:p.getElementById(b);avalon.nextTick(function(){m(q.value||q.innerText||q.innerHTML)})}}else c[e]=b,x.chrome&&"EMBED"===c.tagName&&(f=c.parentNode, +d.endInclude);ta(c,g);g.cb(-1)};if("src"===d.param)if(Ga[b])avalon.nextTick(function(){m(Ga[b])});else{var n=new x.XMLHttpRequest;n.onload=function(){var c=n.status;if(200<=c&&300>c||304===c)m(Ga[b]=n.responseText)};n.open("GET",b,!0);n.withCredentials=!0;n.setRequestHeader("X-Requested-With","XMLHttpRequest");n.send(null)}else{var p=b&&1==b.nodeType?b:q.getElementById(b);avalon.nextTick(function(){m(p.value||p.innerText||p.innerHTML)})}}else c[e]=b,x.chrome&&"EMBED"===c.tagName&&(f=c.parentNode, e=document.createComment("ms-src"),f.replaceChild(e,c),f.replaceChild(c,e))},"class":function(b,c,d){var e=avalon(c),f=d.type;if("class"===f&&d.oldStyle)e.toggleClass(d.oldStyle,!!b);else switch(d.toggleClass=d._evaluator?!!d._evaluator.apply(c,d._args):!0,d.newClass=d.immobileClass||b,d.oldClass&&d.newClass!==d.oldClass&&e.removeClass(d.oldClass),d.oldClass=d.newClass,f){case "class":e.toggleClass(d.newClass,d.toggleClass);break;case "hover":case "active":if(!d.hasBindEvent){b="mouseenter";var g= -"mouseleave";"active"===f&&(c.tabIndex=c.tabIndex||-1,b="mousedown",g="mouseup",e.bind("mouseleave",function(){d.toggleClass&&e.removeClass(d.newClass)}));e.bind(b,function(){d.toggleClass&&e.addClass(d.newClass)});e.bind(g,function(){d.toggleClass&&e.removeClass(d.newClass)});d.hasBindEvent=!0}}},data:function(b,c,d){d="data-"+d.param;b&&"object"===typeof b?c[d]=b:c.setAttribute(d,String(b))},repeat:function(b,c,d){if(b){var e=this.element.parentNode,f=this.proxies,g=H.cloneNode(!1);if("del"===b|| -"move"===b)var h=za(this,c);var k=this.group;switch(b){case "add":for(var l=d,m=this.$repeat.length-1,k=[],h=0,n=l.length;h\u4e0a\u8981\u6c42\u5bf9\u5e94\u4e00\u4e2a\u6570\u7ec4"):b.multiple&&t("ms-duplex\u5728\u4e0d\u80fd\u5bf9\u5e94\u4e00\u4e2a\u6570\u7ec4");d=Array.isArray(d)?d.map(String): +d+"";d+""!==b.oldValue&&(e.val(d),b.oldValue=d+"")};d.bound("change",function(){if(!1!==e.data("duplex-observe")){var f=e.val(),f=Array.isArray(f)?f.map(function(b){return d.pipe(b,d,"get")}):d.pipe(f,d,"get");f+""!==b.oldValue&&c(f);d.changed.call(b,f,d)}});ja(b,function(){qa(d);d.changed.call(b,c(),d)},NaN)};U.TEXTAREA=U.INPUT;var ma=avalon.eventHooks;"onmouseenter"in C||avalon.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(b,c){ma[b]={type:c,deel:function(c,e){return function(f){var g= +f.relatedTarget;if(!g||g!==c&&!(c.compareDocumentPosition(g)&16))return delete f.type,f.type=b,e.call(c,f)}}}});avalon.each({AnimationEvent:"animationend",WebKitAnimationEvent:"webkitAnimationEnd"},function(b,c){x[b]&&!ma.animationend&&(ma.animationend={type:c})});void 0===q.onmousewheel&&(ma.mousewheel={type:"wheel",deel:function(b,c){return function(d){d.wheelDeltaY=d.wheelDelta=0b?Math.max(d+b,0):Math.min(b,d);var d=Ia.apply(this.$model,arguments),e=[],f;this._stopFireLength=!0;d.length&&(e=this._del(b,d.length),f=!0);2]*>([\S\s]*?)<\/script\s*>/gim,jc=/\s+(on[^=\s]+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,kc=/<\w+\b(?:(["'])[^"]*?(\1)|[^>])*>/ig,lc={a:/\b(href)\=("javascript[^"]*"|'javascript[^']*')/ig,img:/\b(src)\=("javascript[^"]*"|'javascript[^']*')/ig,form:/\b(action)\=("javascript[^"]*"|'javascript[^']*')/ig},mc=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,nc=/([^\#-~| |!])/g,Ja=avalon.filters={uppercase:function(b){return b.toUpperCase()},lowercase:function(b){return b.toLowerCase()},truncate:function(b, +c,d){c=c||30;d=void 0===d?"...":d;return b.length>c?b.slice(0,c-d.length)+d:String(b)},sanitize:x.toStaticHTML?toStaticHTML.bind(x):function(b){return b.replace(ic,"").replace(kc,function(b,d){var e=b.toLowerCase().match(/<(\w+)\s/);e&&(e=lc[e[1]])&&(b=b.replace(e,function(b,c,d){b=d.charAt(0);return c+"="+b+"javascript:void(0)"+b}));return b.replace(jc," ").replace(/\s+/g," ")})},camelize:ga,escape:function(b){return String(b).replace(/&/g,"&").replace(mc,function(b){var d=b.charCodeAt(0);b= +b.charCodeAt(1);return"&#"+(1024*(d-55296)+(b-56320)+65536)+";"}).replace(nc,function(b){return"&#"+b.charCodeAt(0)+";"}).replace(//g,">")},currency:function(b,c){return(c||"\uffe5")+avalon.filters.number(b)},number:function(b,c,d,e){b=(b+"").replace(/[^0-9+\-Ee.]/g,"");b=!isFinite(+b)?0:+b;c=!isFinite(+c)?0:Math.abs(c);e=e||",";d=d||".";var f="",f=function(b,c){var d=Math.pow(10,c);return""+Math.round(b*d)/d},f=(c?f(b,c):""+Math.round(b)).split(".");3b&&(e="-",b=-b);for(b=""+b;b.length-e)g+=e;0===g&&-12===e&&(g=12);return b(g,d,f)}}function d(b,c){return function(d,e){var f=d["get"+b](),g=(c?"SHORT"+b:b).toUpperCase();return e[g][f]}}function e(b){var c; +if(c=b.match(k)){b=new Date(0);var d=0,e=0,f=c[8]?b.setUTCFullYear:b.setFullYear,g=c[8]?b.setUTCHours:b.setHours;c[9]&&(d=parseInt(c[9]+c[10],10),e=parseInt(c[9]+c[11],10));f.call(b,parseInt(c[1],10),parseInt(c[2],10)-1,parseInt(c[3],10));d=parseInt(c[4]||0,10)-d;e=parseInt(c[5]||0,10)-e;f=parseInt(c[6]||0,10);c=Math.round(1E3*parseFloat("0."+(c[7]||0)));g.call(b,d,e,f,c)}return b}var f={yyyy:c("FullYear",4),yy:c("FullYear",2,0,!0),y:c("FullYear",1),MMMM:d("Month"),MMM:d("Month",!0),MM:c("Month", +2,1),M:c("Month",1,1),dd:c("Date",2),d:c("Date",1),HH:c("Hours",2),H:c("Hours",1),hh:c("Hours",2,-12),h:c("Hours",1,-12),mm:c("Minutes",2),m:c("Minutes",1),ss:c("Seconds",2),s:c("Seconds",1),sss:c("Milliseconds",3),EEEE:d("Day"),EEE:d("Day",!0),a:function(b,c){return 12>b.getHours()?c.AMPMS[0]:c.AMPMS[1]},Z:function(c){c=-1*c.getTimezoneOffset();return c=(0<=c?"+":"")+(b(Math[0 Date: Wed, 19 Nov 2014 14:30:26 +0800 Subject: [PATCH 05/18] =?UTF-8?q?fix=20=E7=9F=AD=E8=B7=AF=E4=B8=8E=20?= =?UTF-8?q?=E7=9F=AD=E8=B7=AF=E6=88=96=E5=BC=95=E5=8F=91=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E6=94=B6=E9=9B=86=E5=A4=B1=E8=B4=A5=E7=9A=84BUG=20https://gith?= =?UTF-8?q?ub.com/RubyLouvre/avalon/issues/583?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- avalon.js | 26 ++++++++++++++++++++++---- avalon.modern.js | 18 +++++++++++++++++- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/avalon.js b/avalon.js index 5480c8ba5..17c6beefe 100644 --- a/avalon.js +++ b/avalon.js @@ -2404,6 +2404,7 @@ for (var i = vars.length, prop; prop = vars[--i]; ) { if (scope.hasOwnProperty(prop)) { ret.push(prop + prefix + prop) + data.vars.push(prop) if (data.type === "duplex") { vars.get = name + "." + prop } @@ -2411,7 +2412,6 @@ } } return ret - } function uniqSet(array) { @@ -2449,7 +2449,7 @@ var dataType = data.type var filters = data.filters ? data.filters.join("") : "" var exprId = scopes.map(function(el) { - return el.$id.replace(rproxy, "$1") + return String(el.$id).replace(rproxy, "$1") }) + code + dataType + filters var vars = getVariables(code).concat(), assigns = [], @@ -2458,6 +2458,7 @@ prefix = "" //args 是一个对象数组, names 是将要生成的求值函数的参数 scopes = uniqSet(scopes) + data.vars = [] for (var i = 0, sn = scopes.length; i < sn; i++) { if (vars.length) { var name = "vm" + expose + "_" + i @@ -2469,6 +2470,20 @@ if (!assigns.length && dataType === "duplex") { return } + //https://github.com/RubyLouvre/avalon/issues/583 + data.vars.forEach(function(v) { + var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig") + code = code.replace(reg, function(_) { + var c = _.charAt(v.length) + if (c === "." || c === "[") { + var name = "var" + String(Math.random()).replace(/^0\./, "") + assigns.push(name + " = " + _) + return name + } else { + return _ + } + }) + }) //---------------args---------------- if (filters) { args.push(avalon.filters) @@ -2571,9 +2586,12 @@ parseExpr(code, scopes, data) if (data.evaluator && !noregister) { data.handler = bindingExecutors[data.handlerName || data.type] - data.evaluator.toString = function() { - return data.type + " binding to eval(" + code + ")" + if (data.type === "if") { + console.log(data.evaluator + "") } +// data.evaluator.toString = function() { +// return data.type + " binding to eval(" + code + ")" +// } //方便调试 //这里非常重要,我们通过判定视图刷新函数的element是否在DOM树决定 //将它移出订阅者列表 diff --git a/avalon.modern.js b/avalon.modern.js index 102a66ecd..35bb26970 100644 --- a/avalon.modern.js +++ b/avalon.modern.js @@ -1798,6 +1798,7 @@ for (var i = vars.length, prop; prop = vars[--i]; ) { if (scope.hasOwnProperty(prop)) { ret.push(prop + prefix + prop) + data.vars.push(prop) if (data.type === "duplex") { vars.get = name + "." + prop } @@ -1848,6 +1849,7 @@ names = [], args = [], prefix = "" + data.vars = [] //args 是一个对象数组, names 是将要生成的求值函数的参数 scopes = uniqSet(scopes) for (var i = 0, sn = scopes.length; i < sn; i++) { @@ -1861,6 +1863,20 @@ if (!assigns.length && dataType === "duplex") { return } + //https://github.com/RubyLouvre/avalon/issues/583 + data.vars.forEach(function(v) { + var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig") + code = code.replace(reg, function(_) { + var c = _.charAt(v.length) + if (c === "." || c === "[") { + var name = "var" + String(Math.random()).replace(/^0\./, "") + assigns.push(name + " = " + _) + return name + } else { + return _ + } + }) + }) //---------------args---------------- if (filters) { args.push(avalon.filters) @@ -1931,7 +1947,7 @@ } catch (e) { log("debug: parse error," + e.message) } finally { - vars = textBuffer = names = null //释放内存 + vars = textBuffer = names = null //释放内存 } } From c6e751ae7015ffa9f00c5091ae7217e82efbd19c Mon Sep 17 00:00:00 2001 From: RubyLouvre Date: Wed, 19 Nov 2014 15:03:17 +0800 Subject: [PATCH 06/18] =?UTF-8?q?data.type=20=3D=3D=20'duplex'=E4=B8=8D?= =?UTF-8?q?=E5=81=9A=E6=9B=BF=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- avalon.js | 34 +++---- avalon.min.js | 42 ++++---- avalon.modern.js | 38 ++++---- avalon.modern.min.js | 210 ++++++++++++++++++++-------------------- examples/avalon.shim.js | 135 +++++++++++++++----------- 5 files changed, 238 insertions(+), 221 deletions(-) diff --git a/avalon.js b/avalon.js index 17c6beefe..5bf54df7b 100644 --- a/avalon.js +++ b/avalon.js @@ -2470,20 +2470,22 @@ if (!assigns.length && dataType === "duplex") { return } - //https://github.com/RubyLouvre/avalon/issues/583 - data.vars.forEach(function(v) { - var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig") - code = code.replace(reg, function(_) { - var c = _.charAt(v.length) - if (c === "." || c === "[") { - var name = "var" + String(Math.random()).replace(/^0\./, "") - assigns.push(name + " = " + _) - return name - } else { - return _ - } + if (dataType !== "duplex") { + //https://github.com/RubyLouvre/avalon/issues/583 + data.vars.forEach(function(v) { + var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig") + code = code.replace(reg, function(_) { + var c = _.charAt(v.length) + if (c === "." || c === "[") { + var name = "var" + String(Math.random()).replace(/^0\./, "") + assigns.push(name + " = " + _) + return name + } else { + return _ + } + }) }) - }) + } //---------------args---------------- if (filters) { args.push(avalon.filters) @@ -2586,12 +2588,6 @@ parseExpr(code, scopes, data) if (data.evaluator && !noregister) { data.handler = bindingExecutors[data.handlerName || data.type] - if (data.type === "if") { - console.log(data.evaluator + "") - } -// data.evaluator.toString = function() { -// return data.type + " binding to eval(" + code + ")" -// } //方便调试 //这里非常重要,我们通过判定视图刷新函数的element是否在DOM树决定 //将它移出订阅者列表 diff --git a/avalon.min.js b/avalon.min.js index b80b9f767..53f345eda 100644 --- a/avalon.min.js +++ b/avalon.min.js @@ -14,27 +14,27 @@ qb(b,d):u.commentInterpolate&&(8===c&&!aa.test(b.nodeValue))&&qb(b,d)}function q b);d.length&&Ca(d,c)}}function ec(b,c){return b.priority-c.priority}function nb(b,c){for(var d=sb?sb(b):avalon.slice(b.attributes),e=[],f={},g,h=0,k;k=d[h++];)if(k.specified&&(g=k.name.match(tb))){var l=g[1],m=g[2]||"",n=k.value;k=k.name;f[k]=n;fc[l]?(m=l,l="on"):gc[l]&&(v("ms-"+l+"\u5df2\u7ecf\u88ab\u5e9f\u5f03,\u8bf7\u4f7f\u7528ms-attr-*\u4ee3\u66ff"),"enabled"===l&&(l="disabled",n="!("+n+")"),m=l,l="attr",b.removeAttribute(k),k="ms-attr-"+m,b.setAttribute(k,n),g=[k],f[k]=n);"function"===typeof C[l]&& (n={type:l,param:m,element:b,name:g[0],value:n,priority:l in ub?ub[l]:10*l.charCodeAt(0)+(Number(m)||0)},"if"===l&&-1"))&&ob(b,c)}}function Ca(b,c){b.length&&c.cb(b.length);for(var d=0,e;e=b[d++];)e.vmodels=c,C[e.type](e,c),e.evaluator&&(e.element&&1===e.element.nodeType)&&e.element.removeAttribute(e.name);b.length=0}function rb(b,c){0b&&delete c[d.shift()];return c[e]=f}var d=[];return c}function xb(b,c,d){var e=d.type,f=d.filters?d.filters.join(""):"",g=c.map(function(b){return b.$id.replace(oc,"$1")})+b+e+f,h=pc(b).concat(),k=[],l=[],m=[],n="";c=wb(c);for(var q=0,n=c.length;q>0)-(d.clientLeft>>0),c.pageY=b.clientY+(d.scrollTop>>0)-(d.clientTop>>0),c.wheelDeltaY=c.wheelDelta,c.wheelDeltaX=0);c.timeStamp=new Date-0;c.originalEvent=b;c.preventDefault=function(){b.returnValue=!1};c.stopPropagation= -function(){b.cancelBubble=!0};return c}function Xb(b){var c=[];c.$id=ha();c.$model=b;c.$events={};c.$events[G]=[];c._=N({length:b.length});c._.$watch("length",function(b,d){c.$fire("length",b,d)});for(var d in R)c[d]=R[d];avalon.mix(c,Ab);return c}function Bb(b,c,d,e){var f=avalon.parseHTML(b.template),g=avalon.slice(f.childNodes);c.appendChild(f);d.$outer=b.$outer;b=b.vmodels;d=[d].concat(b);d.cb=b.cb;e.push({nodes:g,vmodels:d})}function Ha(b,c){var d=b.endRepeat,e=[],f=b.element.nextSibling;if(f!== -d){do if(f!==d)e.push(f);else break;while(f=f.nextSibling)}return e[b.group*c]||d}function Cb(b,c,d){c*=d||1;d=[b];for(var e=1,f=I;eu.maxRepeatSize&&da.pop()}b.length=0}function T(){p.body&&(D?(s["ready!"].state=2,D.checkDeps()):Fb.forEach(function(b){b(avalon)}),T=y)}function Gb(){try{B.doScroll("left"),T()}catch(b){setTimeout(Gb)}}var A=new Date-0,G="$"+A,r=Function("return this")(),Ac=r.require,Bc=r.define,ja=!1,z=/[^, ]+/g,Hb=/\[native code\]/,wa=/^(?:object|array)$/,Ib=/^\[object SVG\w*Element\]$/, -Vb=/^\[object (?:Window|DOMWindow|global)\]$/,Ia=Object.prototype,O=Ia.hasOwnProperty,ia=Ia.toString,L=Array.prototype,$=L.slice,Y={},w=r.dispatchEvent,B=p.documentElement,J=p.getElementsByTagName("head")[0],I=p.createDocumentFragment(),ea=p.createElement("div"),Jb={};"Boolean Number String Function Array Date RegExp Object Error".replace(z,function(b){Jb["[object "+b+"]"]=b.toLowerCase()});avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]=this.element=b};avalon.fn=avalon.prototype= -avalon.init.prototype;avalon.type=function(b){return null==b?String(b):"object"===typeof b||"function"===typeof b?Jb[ia.call(b)]||"object":typeof b};var V="object"===typeof alert?function(b){try{return/^\s*\bfunction\b/.test(b+"")}catch(c){return!1}}:function(b){return"[object Function]"==ia.call(b)};avalon.isFunction=V;avalon.isWindow=function(b){return!b?!1:b==b.document&&b.document!=b};Ya(r)&&(avalon.isWindow=Ya);for(var Cc in avalon({}))break;var Dc="0"!==Cc;avalon.isPlainObject=function(b,c){if(!b|| -"object"!==avalon.type(b)||b.nodeType||avalon.isWindow(b))return!1;try{if(b.constructor&&!O.call(b,"constructor")&&!O.call(b.constructor.prototype,"isPrototypeOf"))return!1}catch(d){return!1}if(Dc)for(c in b)return O.call(b,c);for(c in b);return void 0===c||O.call(b,c)};Hb.test(Object.getPrototypeOf)&&(avalon.isPlainObject=function(b){return!!b&&"object"===typeof b&&Object.getPrototypeOf(b)===Ia});avalon.mix=avalon.fn.mix=function(){var b,c,d,e,f,g=arguments[0]||{},h=1,k=arguments.length,l=!1;"boolean"=== -typeof g&&(l=g,g=arguments[1]||{},h++);"object"!==typeof g&&"function"!==avalon.type(g)&&(g={});h===k&&(g=this,h--);for(;hb&&delete c[d.shift()];return c[e]=f}var d=[];return c}function xb(b,c,d){var e=d.type,f=d.filters?d.filters.join(""):"",g=c.map(function(b){return String(b.$id).replace(oc,"$1")})+b+e+f,h=pc(b).concat(),k=[],l=[],m=[],n="";c=wb(c);d.vars=[];for(var q=0,n=c.length;q>0)-(d.clientLeft>>0),c.pageY=b.clientY+(d.scrollTop>>0)-(d.clientTop>> +0),c.wheelDeltaY=c.wheelDelta,c.wheelDeltaX=0);c.timeStamp=new Date-0;c.originalEvent=b;c.preventDefault=function(){b.returnValue=!1};c.stopPropagation=function(){b.cancelBubble=!0};return c}function Xb(b){var c=[];c.$id=ha();c.$model=b;c.$events={};c.$events[G]=[];c._=N({length:b.length});c._.$watch("length",function(b,d){c.$fire("length",b,d)});for(var d in R)c[d]=R[d];avalon.mix(c,Ab);return c}function Bb(b,c,d,e){var f=avalon.parseHTML(b.template),g=avalon.slice(f.childNodes);c.appendChild(f); +d.$outer=b.$outer;b=b.vmodels;d=[d].concat(b);d.cb=b.cb;e.push({nodes:g,vmodels:d})}function Ha(b,c){var d=b.endRepeat,e=[],f=b.element.nextSibling;if(f!==d){do if(f!==d)e.push(f);else break;while(f=f.nextSibling)}return e[b.group*c]||d}function Cb(b,c,d){c*=d||1;d=[b];for(var e=1,f=I;eu.maxRepeatSize&&da.pop()}b.length=0}function T(){p.body&&(D?(s["ready!"].state=2,D.checkDeps()):Fb.forEach(function(b){b(avalon)}),T=y)}function Gb(){try{B.doScroll("left"),T()}catch(b){setTimeout(Gb)}}var A=new Date- +0,G="$"+A,r=Function("return this")(),Ac=r.require,Bc=r.define,ja=!1,z=/[^, ]+/g,Hb=/\[native code\]/,wa=/^(?:object|array)$/,Ib=/^\[object SVG\w*Element\]$/,Vb=/^\[object (?:Window|DOMWindow|global)\]$/,Ia=Object.prototype,O=Ia.hasOwnProperty,ia=Ia.toString,L=Array.prototype,$=L.slice,Y={},w=r.dispatchEvent,B=p.documentElement,J=p.getElementsByTagName("head")[0],I=p.createDocumentFragment(),ea=p.createElement("div"),Jb={};"Boolean Number String Function Array Date RegExp Object Error".replace(z, +function(b){Jb["[object "+b+"]"]=b.toLowerCase()});avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]=this.element=b};avalon.fn=avalon.prototype=avalon.init.prototype;avalon.type=function(b){return null==b?String(b):"object"===typeof b||"function"===typeof b?Jb[ia.call(b)]||"object":typeof b};var V="object"===typeof alert?function(b){try{return/^\s*\bfunction\b/.test(b+"")}catch(c){return!1}}:function(b){return"[object Function]"==ia.call(b)};avalon.isFunction=V;avalon.isWindow= +function(b){return!b?!1:b==b.document&&b.document!=b};Ya(r)&&(avalon.isWindow=Ya);for(var Cc in avalon({}))break;var Dc="0"!==Cc;avalon.isPlainObject=function(b,c){if(!b||"object"!==avalon.type(b)||b.nodeType||avalon.isWindow(b))return!1;try{if(b.constructor&&!O.call(b,"constructor")&&!O.call(b.constructor.prototype,"isPrototypeOf"))return!1}catch(d){return!1}if(Dc)for(c in b)return O.call(b,c);for(c in b);return void 0===c||O.call(b,c)};Hb.test(Object.getPrototypeOf)&&(avalon.isPlainObject=function(b){return!!b&& +"object"===typeof b&&Object.getPrototypeOf(b)===Ia});avalon.mix=avalon.fn.mix=function(){var b,c,d,e,f,g=arguments[0]||{},h=1,k=arguments.length,l=!1;"boolean"===typeof g&&(l=g,g=arguments[1]||{},h++);"object"!==typeof g&&"function"!==avalon.type(g)&&(g={});h===k&&(g=this,h--);for(;h 0 Then","\t\t["+b+'] = [__proxy__]([__data__],"'+b+'")',"\tEnd If","\tOn Error Goto 0","\tEnd Property");f.push("End Class");b=f.join("\r\n"); b=r.findOrDefineVBClass(e,b);b===e&&r.parseVB(["Function "+e+"Factory(a, b)","\tDim o","\tSet o = (New "+e+")(a, b)","\tSet "+e+"Factory = o","End Function"].join("\r\n"));return r[b+"Factory"](c,Ec)}}if(!"\u53f8\u5f92\u6b63\u7f8e".trim){var Fc=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;String.prototype.trim=function(){return this.replace(Fc,"")}}var Gc=!{toString:null}.propertyIsEnumerable("toString"),Hc=function(){}.propertyIsEnumerable("prototype"),Kb="toString toLocaleString valueOf hasOwnProperty isPrototypeOf propertyIsEnumerable constructor".split(" "), diff --git a/avalon.modern.js b/avalon.modern.js index 35bb26970..8d79fb520 100644 --- a/avalon.modern.js +++ b/avalon.modern.js @@ -1840,6 +1840,7 @@ function parseExpr(code, scopes, data) { var dataType = data.type + var isDuplex = dataType === "duplex" var filters = data.filters ? data.filters.join("") : "" var exprId = scopes.map(function(el) { return el.$id.replace(rproxy, "$1") @@ -1860,23 +1861,25 @@ assigns.push.apply(assigns, addAssign(vars, scopes[i], name, data)) } } - if (!assigns.length && dataType === "duplex") { + if (!assigns.length && isDuplex) { return } - //https://github.com/RubyLouvre/avalon/issues/583 - data.vars.forEach(function(v) { - var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig") - code = code.replace(reg, function(_) { - var c = _.charAt(v.length) - if (c === "." || c === "[") { - var name = "var" + String(Math.random()).replace(/^0\./, "") - assigns.push(name + " = " + _) - return name - } else { - return _ - } + if (!isDuplex) { + //https://github.com/RubyLouvre/avalon/issues/583 + data.vars.forEach(function(v) { + var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig") + code = code.replace(reg, function(_) { + var c = _.charAt(v.length) + if (c === "." || c === "[") { + var name = "var" + String(Math.random()).replace(/^0\./, "") + assigns.push(name + " = " + _) + return name + } else { + return _ + } + }) }) - }) + } //---------------args---------------- if (filters) { args.push(avalon.filters) @@ -1912,7 +1915,7 @@ code = textBuffer.join("") code += "\nreturn ret" + expose names.push("filters" + expose) - } else if (dataType === "duplex") { //双工绑定 + } else if (isDuplex) { //双工绑定 var _body = "'use strict';\nreturn function(vvv){\n\t" + prefix + ";\n\tif(!arguments.length){\n\t\treturn " + @@ -1947,7 +1950,7 @@ } catch (e) { log("debug: parse error," + e.message) } finally { - vars = textBuffer = names = null //释放内存 + vars = textBuffer = names = null //释放内存 } } @@ -1962,9 +1965,6 @@ parseExpr(code, scopes, data) if (data.evaluator && !noregister) { data.handler = bindingExecutors[data.handlerName || data.type] - data.evaluator.toString = function() { - return data.type + " binding to eval(" + code + ")" - } //方便调试 //这里非常重要,我们通过判定视图刷新函数的element是否在DOM树决定 //将它移出订阅者列表 diff --git a/avalon.modern.min.js b/avalon.modern.min.js index 0b322c02e..9faf998ce 100644 --- a/avalon.modern.min.js +++ b/avalon.modern.min.js @@ -1,106 +1,106 @@ -(function(q){function v(){}function t(){avalon.config.debug&&console.log.apply(console,arguments)}function I(b,c){"string"===typeof b&&(b=b.match(w)||[]);for(var d={},e=void 0!==c?c:1,f=0,g=b.length;f=Object.keys(e).length){var S=e.set,D=e.get;p=function(b){var e=f.$events,g=d[c]; -if(arguments.length){if(ca)return;if(R(S)){var h=e[c];e[c]=[];S.call(f,b);e[c]=h}}else avalon.openComputedCollect&&da(e[c]);b=d[c]=D.call(f);if(!ea(g,b)){if(fa&&(h=T[f.$id])&&h[c])h[c].$val=b;oa(e[c]);f.$events&&P.$fire.call(f,c,b,g)}return b};k.push(function(){V[A]={evaluator:p,element:F,type:"computed::"+c,handler:v,args:[]};p();da(g[c]);delete V[A]})}else La.test(l)?(p=function(b){var e=p.child,h=d[c];if(arguments.length)!ca&&!ea(h,b)&&(e=p.child=xb(f,c,b,l),b=d[c]=e.$model,(e=pa[e.$id])&&e(), -f.$events&&P.$fire.call(f,c,b,h));else return da(g[c]),e},(p.child=J(e,0,d[c])).$events[E]=g[c]):p=function(b){var e=d[c];if(arguments.length){if(!ea(e,b)){d[c]=b;if(fa){var h=T[f.$id];h&&h[c]&&(h[c].$val=b)}oa(g[c]);f.$events&&P.$fire.call(f,c,b,e)}}else return da(g[c]),e};h[c]=p}})(e,b[e]);Ka.forEach(function(c){delete b[c];delete d[c]});Object.defineProperties(f,yb(h));for(var l in b)h[l]||(f[l]=b[l]);f.$id=ba();f.$model=d;f.$events=g;for(e in P)f[e]=P[e];Object.defineProperty(f,"hasOwnProperty", -{value:function(b){return b in f.$model},writable:!1,enumerable:!1,configurable:!0});k.forEach(function(b){b()});return f}function yb(b){var c={},d;for(d in b)c[d]={get:b[d],set:b[d],enumerable:!0,configurable:!0};return c}function xb(b,c,d,e){var f=b[c];if("array"===e){if(!Array.isArray(d)||f===d)return f;f.clear();f.pushArray(d.concat());return f}var g=b.$events[c];T[f.$id]&&(fa--,delete T[f.$id]);var h=J(d);h.$events[E]=g;pa[h.$id]=function(b){for(;b=g.shift();)(function(b){b.type&&avalon.nextTick(function(){b.rollback&& -b.rollback();u[b.type](b,b.vmodels)})})(b);delete pa[h.$id]};return h}function s(b){for(var c in b)if(Ma.call(b,c)){var d=b[c];if("function"===typeof s.plugins[c])s.plugins[c](d);else"object"===typeof s[c]?avalon.mix(s[c],d):s[c]=d}return this}function Na(b){return b.replace(/([a-z\d])([A-Z]+)/g,"$1-$2").toLowerCase()}function ga(b){return 0>b.indexOf("-")&&0>b.indexOf("_")?b:b.replace(/[-_][^-_]/g,function(b){return b.charAt(1).toUpperCase()})}function ha(b){try{b="true"===b?!0:"false"===b?!1:"null"=== -b?null:+b+""===b?+b:zb.test(b)?JSON.parse(b):b}catch(c){}return b}function Oa(b,c){if(0>=b.offsetWidth){var d=getComputedStyle(b,null);if(Ab.test(d.display)){var e={node:b},f;for(f in Pa)e[f]=d[f],b.style[f]=Pa[f];c.push(e)}(d=b.parentNode)&&1===d.nodeType&&Oa(d,c)}}function qa(b){V[A]=b;avalon.openComputedCollect=!0;var c=b.evaluator;if(c)try{var d=Bb.test(b.type)?b:c.apply(0,b.args);b.handler(d,b.element,b)}catch(e){t("warning:exception throwed in [registerSubscriber] "+e),delete b.evaluator,c= -b.element,3===c.nodeType&&(d=c.parentNode,s.commentInterpolate?d.replaceChild(q.createComment(b.value),c):c.data=L+b.value+M)}avalon.openComputedCollect=!1;delete V[A]}function da(b){var c=V[A];b&&(c&&avalon.Array.ensure(b,c)&&c.element)&&Qa(c,b)}function Qa(b,c){b.$uuid=b.$uuid||ba();c.$uuid=c.$uuid||ba();var d={data:b,list:c,toString:function(){return b.$uuid+" "+c.$uuid}};Q[d]||(Q[d]=1,Q.push(d))}function Ra(){for(var b=ra,c=ra+Cb;b=Object.keys(e).length){var P=e.set,E=e.get;n=function(b){var e=f.$events,g=d[c]; +if(arguments.length){if(da)return;if(S(P)){var h=e[c];e[c]=[];P.call(f,b);e[c]=h}}else avalon.openComputedCollect&&ea(e[c]);b=d[c]=E.call(f);if(!fa(g,b)){if(ga&&(h=T[f.$id])&&h[c])h[c].$val=b;oa(e[c]);f.$events&&Q.$fire.call(f,c,b,g)}return b};k.push(function(){W[B]={evaluator:n,element:G,type:"computed::"+c,handler:v,args:[]};n();ea(g[c]);delete W[B]})}else La.test(l)?(n=function(b){var e=n.child,h=d[c];if(arguments.length)!da&&!fa(h,b)&&(e=n.child=xb(f,c,b,l),b=d[c]=e.$model,(e=pa[e.$id])&&e(), +f.$events&&Q.$fire.call(f,c,b,h));else return ea(g[c]),e},(n.child=K(e,0,d[c])).$events[F]=g[c]):n=function(b){var e=d[c];if(arguments.length){if(!fa(e,b)){d[c]=b;if(ga){var h=T[f.$id];h&&h[c]&&(h[c].$val=b)}oa(g[c]);f.$events&&Q.$fire.call(f,c,b,e)}}else return ea(g[c]),e};h[c]=n}})(e,b[e]);Ka.forEach(function(c){delete b[c];delete d[c]});Object.defineProperties(f,yb(h));for(var l in b)h[l]||(f[l]=b[l]);f.$id=ca();f.$model=d;f.$events=g;for(e in Q)f[e]=Q[e];Object.defineProperty(f,"hasOwnProperty", +{value:function(b){return b in f.$model},writable:!1,enumerable:!1,configurable:!0});k.forEach(function(b){b()});return f}function yb(b){var c={},d;for(d in b)c[d]={get:b[d],set:b[d],enumerable:!0,configurable:!0};return c}function xb(b,c,d,e){var f=b[c];if("array"===e){if(!Array.isArray(d)||f===d)return f;f.clear();f.pushArray(d.concat());return f}var g=b.$events[c];T[f.$id]&&(ga--,delete T[f.$id]);var h=K(d);h.$events[F]=g;pa[h.$id]=function(b){for(;b=g.shift();)(function(b){b.type&&avalon.nextTick(function(){b.rollback&& +b.rollback();y[b.type](b,b.vmodels)})})(b);delete pa[h.$id]};return h}function s(b){for(var c in b)if(Ma.call(b,c)){var d=b[c];if("function"===typeof s.plugins[c])s.plugins[c](d);else"object"===typeof s[c]?avalon.mix(s[c],d):s[c]=d}return this}function Na(b){return b.replace(/([a-z\d])([A-Z]+)/g,"$1-$2").toLowerCase()}function ha(b){return 0>b.indexOf("-")&&0>b.indexOf("_")?b:b.replace(/[-_][^-_]/g,function(b){return b.charAt(1).toUpperCase()})}function ia(b){try{b="true"===b?!0:"false"===b?!1:"null"=== +b?null:+b+""===b?+b:zb.test(b)?JSON.parse(b):b}catch(c){}return b}function Oa(b,c){if(0>=b.offsetWidth){var d=getComputedStyle(b,null);if(Ab.test(d.display)){var e={node:b},f;for(f in Pa)e[f]=d[f],b.style[f]=Pa[f];c.push(e)}(d=b.parentNode)&&1===d.nodeType&&Oa(d,c)}}function qa(b){W[B]=b;avalon.openComputedCollect=!0;var c=b.evaluator;if(c)try{var d=Bb.test(b.type)?b:c.apply(0,b.args);b.handler(d,b.element,b)}catch(e){u("warning:exception throwed in [registerSubscriber] "+e),delete b.evaluator,c= +b.element,3===c.nodeType&&(d=c.parentNode,s.commentInterpolate?d.replaceChild(p.createComment(b.value),c):c.data=L+b.value+M)}avalon.openComputedCollect=!1;delete W[B]}function ea(b){var c=W[B];b&&(c&&avalon.Array.ensure(b,c)&&c.element)&&Qa(c,b)}function Qa(b,c){b.$uuid=b.$uuid||ca();c.$uuid=c.$uuid||ca();var d={data:b,list:c,toString:function(){return b.$uuid+" "+c.$uuid}};R[d]||(R[d]=1,R.push(d))}function Ra(){for(var b=ra,c=ra+Cb;bb&&delete c[d.shift()];return c[e]=f}var d=[];return c}function eb(b,c,d){var e=d.type,f=d.filters?d.filters.join(""):"",g=c.map(function(b){return b.$id.replace(Lb, -"$1")})+b+e+f,h=Mb(b).concat(),k=[],l=[],m=[],n="";c=cb(c);for(var p=0,n=c.length;ps.maxRepeatSize&&Z.pop()}b.length=0}function $(){z?(r["ready!"].state=2,z.checkDeps()):lb.forEach(function(b){b(avalon)});$=v}var A=Date.now(),E="$"+A,x=Function("return this")(),Wb=x.require,Xb=x.define, -ca=!1,w=/[^, ]+/g,La=/^(?:object|array)$/,mb=/^\[object SVG\w*Element\]$/,Yb=/^\[object (Window|DOMWindow|global)\]$/,Aa=Object.prototype,Ma=Aa.hasOwnProperty,Ba=Aa.toString,N=Array.prototype,ia=N.slice,V={},F=q.head,C=q.documentElement,G=q.createDocumentFragment(),la=q.createElement("div"),nb={};"Boolean Number String Function Array Date RegExp Object Error".replace(w,function(b){nb["[object "+b+"]"]=b.toLowerCase()});x.avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]= -this.element=b};avalon.fn=avalon.prototype=avalon.init.prototype;avalon.isFunction=R;avalon.type=function(b){return null==b?String(b):"object"===typeof b||"function"===typeof b?nb[Ba.call(b)]||"object":typeof b};avalon.isWindow=function(b){return Yb.test(Ba.call(b))};avalon.isPlainObject=function(b){return!!b&&"object"===typeof b&&Object.getPrototypeOf(b)===Aa};avalon.mix=avalon.fn.mix=function(){var b,c,d,e,f,g=arguments[0]||{},h=1,k=arguments.length,l=!1;"boolean"===typeof g&&(l=g,g=arguments[1]|| -{},h++);"object"!==typeof g&&"function"!==avalon.type(g)&&(g={});h===k&&(g=this,h--);for(;h';if(!mb.test(ob.firstChild)){var Ca=function(b,c){if(b&&b.childNodes)for(var d=b.childNodes, -e=0,f;f=d[e++];)if(f.tagName){var g=q.createElementNS("http://www.w3.org/2000/svg",f.tagName.toLowerCase());N.forEach.call(f.attributes,function(b){g.setAttribute(b.name,b.value)});Ca(f,g);c.appendChild(g)}};Object.defineProperties(SVGElement.prototype,{outerHTML:{enumerable:!0,configurable:!0,get:function(){return(new XMLSerializer).serializeToString(this)},set:function(b){var c=this.tagName.toLowerCase(),d=this.parentNode;b=avalon.parseHTML(b);"svg"===c?d.insertBefore(b,this):(c=q.createDocumentFragment(), -Ca(b,c),d.insertBefore(c,this));d.removeChild(this)}},innerHTML:{enumerable:!0,configurable:!0,get:function(){var b=RegExp("$","i");return this.outerHTML.replace(RegExp("<"+this.nodeName+'\\b(?:(["\'])[^"]*?(\\1)|[^>])*>',"i"),"").replace(b,"")},set:function(b){avalon.clearHTML&&(avalon.clearHTML(this),b=avalon.parseHTML(b),Ca(b,this))}}})}}var ka=avalon.vmodels={};avalon.define=function(b,c){var d=b.$id||b;d||t("warning: \u5fc5\u987b\u6307\u5b9a$id");ka[d]&&t("warning: "+d+" \u5df2\u7ecf\u5b58\u5728\u4e8eavalon.vmodels\u4e2d"); -if("object"===typeof b)var e=J(b);else e={$watch:v},c(e),e=J(e),ca=!0,c(e),ca=!1;e.$id=d;return ka[d]=e};var Ka="$id,$watch,$unwatch,$fire,$events,$model,$skipArray".match(w),ea=Object.is||function(b,c){return 0===b&&0===c?1/b===1/c:b!==b?c!==c:b===c},T={},fa=0,pa={},L,M,W,pb,bb,qb=/[-.*+?^${}()|[\]\/\\]/g,z=v,O={loader:function(b){x.define=b?z.define:Xb;x.require=b?z:Wb},interpolate:function(b){L=b[0];M=b[1];L===M?avalon.error("openTag!==closeTag",SyntaxError):"\x3c!--,--\x3e"===b+""?s.commentInterpolate= -!0:(b=L+"test"+M,la.innerHTML=b,la.innerHTML!==b&&0<=la.innerHTML.indexOf("<")&&avalon.error("\u6b64\u5b9a\u754c\u7b26\u4e0d\u5408\u6cd5",SyntaxError),la.innerHTML="");b=(L+"").replace(qb,"\\$&");var c=(M+"").replace(qb,"\\$&");W=RegExp(b+"(.*?)"+c);pb=RegExp(b+"(.*?)"+c,"g");bb=RegExp(b+".*?"+c+"|\\sms-")}};s.debug=!0;s.plugins=O;s.plugins.interpolate(["{{","}}"]);s.paths={};s.shim={};s.maxRepeatSize=100;avalon.config=s;"add,remove".replace(w,function(b){avalon.fn[b+"Class"]=function(c){var d= -this[0];c&&("string"===typeof c&&d&&1===d.nodeType)&&c.replace(/\S+/g,function(c){d.classList[b](c)});return this}});avalon.fn.mix({hasClass:function(b){var c=this[0]||{};return 1===c.nodeType&&c.classList.contains(b)},toggleClass:function(b,c){for(var d,e=0,f=b.split(/\s+/),g="boolean"===typeof c;d=f[e++];)this[(g?c:!this.hasClass(d))?"addClass":"removeClass"](d);return this},attr:function(b,c){return 2===arguments.length?(this[0].setAttribute(b,c),this):this[0].getAttribute(b)},data:function(b, -c){b="data-"+Na(b||"");switch(arguments.length){case 2:return this.attr(b,c),this;case 1:var d=this.attr(b);return ha(d);case 0:var e={};N.forEach.call(this[0].attributes,function(c){c&&(b=c.name,b.indexOf("data-")||(b=ga(b.slice(5)),e[b]=ha(c.value)))});return e}},removeData:function(b){b="data-"+Na(b);this[0].removeAttribute(b);return this},css:function(b,c){if(avalon.isPlainObject(b))for(var d in b)avalon.css(this,d,b[d]);else var e=avalon.css(this,b,c);return void 0!==e?e:this},position:function(){var b, -c,d=this[0],e={top:0,left:0};if(d)return"fixed"===this.css("position")?c=d.getBoundingClientRect():(b=this.offsetParent(),c=this.offset(),"HTML"!==b[0].tagName&&(e=b.offset()),e.top+=avalon.css(b[0],"borderTopWidth",!0),e.left+=avalon.css(b[0],"borderLeftWidth",!0)),{top:c.top-e.top-avalon.css(d,"marginTop",!0),left:c.left-e.left-avalon.css(d,"marginLeft",!0)}},offsetParent:function(){for(var b=this[0].offsetParent||C;b&&"HTML"!==b.tagName&&"static"===avalon.css(b,"position");)b=b.offsetParent;return avalon(b|| -C)},bind:function(b,c,d){if(this[0])return avalon.bind(this[0],b,c,d)},unbind:function(b,c,d){this[0]&&avalon.unbind(this[0],b,c,d);return this},val:function(b){var c=this[0];if(c&&1===c.nodeType){var d=0===arguments.length,e=d?":get":":set",f=Zb,g;g=c.tagName.toLowerCase();g="input"===g&&/checkbox|radio/.test(c.type)?"checked":g;if(e=f[g+e])var h=e(c,b);else{if(d)return(c.value||"").replace(/\r/g,"");c.value=b}}return d?h:this}});C.dataset&&(avalon.fn.data=function(b,c){var d=this[0].dataset;switch(arguments.length){case 2:return d[b]= -c,this;case 1:return c=d[b],ha(c);case 0:var e={};for(b in d)e[b]=ha(d[b]);return e}});var zb=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/;avalon.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(b,c){avalon.fn[b]=function(d){var e=this[0]||{},f=e.window&&e.document?e:9===e.nodeType?e.defaultView:!1,g="scrollTop"===b;if(arguments.length)f?f.scrollTo(!g?d:avalon(f).scrollLeft(),g?d:avalon(f).scrollTop()):e[b]=d;else return f?f[c]:e[b]}});var y=avalon.cssHooks={},rb=["","-webkit-","-moz-","-ms-"], -Da={"float":"cssFloat"};avalon.cssNumber=I("columnCount,order,fillOpacity,fontWeight,lineHeight,opacity,orphans,widows,zIndex,zoom");avalon.cssName=function(b,c,d){if(Da[b])return Da[b];c=c||C.style;for(var e=0,f=rb.length;el&&(e=e-avalon.css(c,"border"+d[0]+"Width",!0)-avalon.css(c,"border"+d[1]+"Width",!0));-4===l&&(e=e-avalon.css(c,"padding"+d[0],!0)-avalon.css(c,"padding"+d[1],!0));return e};y[c+"&get"]=function(b){var d=[];Oa(b,d);for(var e=y[c+":get"](b),f=0,m;m=d[f++];){b=m.node;for(var n in m)"string"===typeof m[n]&&(b.style[n]=m[n])}return e};avalon.fn[c]=function(g){var h= -this[0];if(0===arguments.length){if(h.setTimeout)return h["inner"+b]||h.document.documentElement[d];if(9===h.nodeType){var k=h.documentElement;return Math.max(h.body[e],k[e],h.body[f],k[f],k[d])}return y[c+"&get"](h)}return this.css(c,g)};avalon.fn["inner"+b]=function(){return y[c+":get"](this[0],void 0,-2)};avalon.fn["outer"+b]=function(b){return y[c+":get"](this[0],void 0,!0===b?2:0)}});avalon.fn.offset=function(){var b=this[0],c={left:0,top:0};if(!b||!b.tagName||!b.ownerDocument)return c;var d= -b.ownerDocument,e=d.documentElement,d=d.defaultView;if(!e.contains(b))return c;void 0!==b.getBoundingClientRect&&(c=b.getBoundingClientRect());return{top:c.top+d.pageYOffset-e.clientTop,left:c.left+d.pageXOffset-e.clientLeft}};var Zb={"select:get":function(b,c){for(var d,e=b.options,f=b.selectedIndex,g="select-one"===b.type||0>f,h=g?null:[],k=g?f+1:e.length,l=0>f?k:g?f:0;l]*)\/>/ig,bc=I(["","text/javascript","text/ecmascript","application/ecmascript","application/javascript"]),cc=q.createElement("script");avalon.parseHTML=function(b){"string"!==typeof b&&(b+= -"");b=b.replace(ac,"<$1>").trim();var c=($b.exec(b)||["",""])[1].toLowerCase(),c=B[c]||B._default,d=G.cloneNode(!1);c.innerHTML=b;b=c.getElementsByTagName("script");if(b.length)for(var e=0,f;f=b[e++];)if(bc[f.type]){var g=cc.cloneNode(!1);N.forEach.call(f.attributes,function(b){g.setAttribute(b.name,b.value)});g.text=f.text;f.parentNode.replaceChild(g,f)}for(;b=c.firstChild;)d.appendChild(b);return d};avalon.innerHTML=function(b,c){var d=this.parseHTML(c);this.clearHTML(b).appendChild(d)};avalon.clearHTML= -function(b){for(b.textContent="";b.firstChild;)b.removeChild(b.firstChild);return b};var P={$watch:function(b,c){if("function"===typeof c){var d=this.$events[b];d?d.push(c):this.$events[b]=[c]}else this.$events=this.$watch.backup;return this},$unwatch:function(b,c){var d=arguments.length;if(0===d)this.$watch.backup=this.$events,this.$events={};else if(1===d)this.$events[b]=[];else for(var d=this.$events[b]||[],e=d.length;0>~--e;)if(d[e]===c)return d.splice(e,1);return this},$fire:function(b){var c; -/^(\w+)!(\S+)$/.test(b)&&(c=RegExp.$1,b=RegExp.$2);var d=this.$events,e=ia.call(arguments,1),f=[b].concat(e);if("all"===c)for(var g in avalon.vmodels)e=avalon.vmodels[g],e!==this&&e.$fire.apply(e,f);else if("up"===c||"down"===c){if(d=d.expr&&q.querySelector(d.expr)){for(g in avalon.vmodels)if(e=avalon.vmodels[g],e!==this&&e.$events.expr){var h=q.querySelector(e.$events.expr);if(h&&("down"===c?d.contains(h):h.contains(d)))h._avalon=e}g=q.getElementsByTagName("*");var k=[];Array.prototype.forEach.call(g, -function(b){b._avalon&&(k.push(b._avalon),b._avalon="",b.removeAttribute("_avalon"))});"up"===c&&k.reverse();for(g=0;(c=k[g++])&&!1!==c.$fire.apply(c,f););}}else{f=d[b]||[];c=d.$all||[];for(g=0;d=f[g++];)R(d)&&d.apply(this,e);for(g=0;d=c[g++];)R(d)&&d.apply(this,arguments)}}},Bb=/^(duplex|on)$/,Q=[],ra=0,Cb=200,Sa=Date.now(),Ta,Ea={};avalon.scanCallback=function(b,c){c=c||"$all";(Ea[c]||(Ea[c]=[])).push(b)};avalon.scan=function(b,c,d){b=b||C;var e=Ea[d||"$all"]||[];c=c?[].concat(c):[];var f=0,g=!1, -h,k=!1;c.cb=function(b){f+=b;k=!0;setTimeout(function(){if(0>=f&&!g)for(g=!0;h=e.shift();)h()})};Ua(b,c);if(!k)for(;h=e.shift();)h()};var Gb=I("AREA,BASE,BASEFONT,BR,COL,COMMAND,EMBED,HR,IMG,INPUT,LINK,META,PARAM,SOURCE,TRACK,WBR,NOSCRIPT,NOSCRIPT,SCRIPT,STYLE,TEXTAREA"),Db=/ms-(\w+)-?(.*)/,ab={"if":10,repeat:90,data:100,widget:110,each:1400,"with":1500,duplex:2E3,on:3E3},Eb=I("animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scan,scroll,submit"), -Fb=I("value,title,alt,checked,selected,disabled,readonly,enabled"),Ib=/\|\s*(\w+)\s*(\([^)]*\))?/g,Hb=/\|\|/g,Jb=/U2hvcnRDaXJjdWl0/g,dc=/\/\*[\w\W]*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|"(?:[^"\\]|\\[\w\W])*"|'(?:[^'\\]|\\[\w\W])*'|[\s\t\n]*\.[\s\t\n]*[$\w\.]+/g,ec=/[^\w$]+/g,fc=RegExp(""+("\\b"+"break,case,catch,continue,debugger,default,delete,do,else,false,finally,for,function,if,in,instanceof,new,null,return,switch,this,throw,true,try,typeof,var,void,while,with,abstract,boolean,byte,char,class,const,double,enum,export,extends,final,float,goto,implements,import,int,interface,long,native,package,private,protected,public,short,static,super,synchronized,throws,transient,volatile,arguments,let,yield,undefined".replace(/,/g, -"\\b|\\b")+"\\b"),"g"),gc=/\b\d[^,]*/g,hc=/^,+|,+$/g,Fa=db(512),Mb=function(b){var c=","+b.trim();if(Fa[c])return Fa[c];b=b.replace(dc,"").replace(ec,",").replace(fc,"").replace(gc,"").replace(hc,"").split(/^$|,+/);return Fa(c,cb(b))},wa=db(128),Nb=/\w\[.*\]|\w\.\w/,Lb=/(\$proxy\$[a-z]+)\d+$/;avalon.parseExprProxy=H;F.insertAdjacentHTML("afterBegin",'');var sa=F.firstChild,aa=function(b,c,d){if(b=b.getAttribute(c)){c= -0;for(var e;e=d[c++];)if(e.hasOwnProperty(b)&&"function"===typeof e[b])return e[b]}},Ga=avalon.templateCache={},Ha={};"autofocus,autoplay,async,checked,controls,declare,disabled,defer,defaultChecked,defaultSelectedcontentEditable,isMap,loop,multiple,noHref,noResize,noShade,open,readOnly,selected".replace(w,function(b){Ha[b.toLowerCase()]=b});var xa=avalon.bindingExecutors={attr:function(b,c,d){var e=d.type,f=d.param;if("css"===e)avalon(c).css(f,b);else if("attr"===e){if(Ha[f]&&(e=Ha[f],"boolean"=== -typeof c[e]))return c[e]=!!b;if(!1===b||null===b||void 0===b)return c.removeAttribute(f);(mb.test(c)?0:f in c.cloneNode(!1))?c[f]=b:c.setAttribute(f,b)}else if("include"===e&&b){var g=d.vmodels,h=d.includeRendered,k=d.includeLoaded,l=d.includeReplaced?c.parentNode:c,m=function(b){k&&(b=k.apply(l,[b].concat(g)));for(h&&ja(l,function(){h.call(l)},NaN);;){var c=d.startInclude.nextSibling;if(c&&c!==d.endInclude)l.removeChild(c);else break}b=avalon.parseHTML(b);c=avalon.slice(b.childNodes);l.insertBefore(b, -d.endInclude);ta(c,g);g.cb(-1)};if("src"===d.param)if(Ga[b])avalon.nextTick(function(){m(Ga[b])});else{var n=new x.XMLHttpRequest;n.onload=function(){var c=n.status;if(200<=c&&300>c||304===c)m(Ga[b]=n.responseText)};n.open("GET",b,!0);n.withCredentials=!0;n.setRequestHeader("X-Requested-With","XMLHttpRequest");n.send(null)}else{var p=b&&1==b.nodeType?b:q.getElementById(b);avalon.nextTick(function(){m(p.value||p.innerText||p.innerHTML)})}}else c[e]=b,x.chrome&&"EMBED"===c.tagName&&(f=c.parentNode, -e=document.createComment("ms-src"),f.replaceChild(e,c),f.replaceChild(c,e))},"class":function(b,c,d){var e=avalon(c),f=d.type;if("class"===f&&d.oldStyle)e.toggleClass(d.oldStyle,!!b);else switch(d.toggleClass=d._evaluator?!!d._evaluator.apply(c,d._args):!0,d.newClass=d.immobileClass||b,d.oldClass&&d.newClass!==d.oldClass&&e.removeClass(d.oldClass),d.oldClass=d.newClass,f){case "class":e.toggleClass(d.newClass,d.toggleClass);break;case "hover":case "active":if(!d.hasBindEvent){b="mouseenter";var g= -"mouseleave";"active"===f&&(c.tabIndex=c.tabIndex||-1,b="mousedown",g="mouseup",e.bind("mouseleave",function(){d.toggleClass&&e.removeClass(d.newClass)}));e.bind(b,function(){d.toggleClass&&e.addClass(d.newClass)});e.bind(g,function(){d.toggleClass&&e.removeClass(d.newClass)});d.hasBindEvent=!0}}},data:function(b,c,d){d="data-"+d.param;b&&"object"===typeof b?c[d]=b:c.setAttribute(d,String(b))},repeat:function(b,c,d){if(b){var e=this.element.parentNode,f=this.proxies,g=G.cloneNode(!1);if("del"===b|| -"move"===b)var h=za(this,c);var k=this.group;switch(b){case "add":for(var l=d,m=this.$repeat.length-1,k=[],h=0,n=l.length;h\u4e0a\u8981\u6c42\u5bf9\u5e94\u4e00\u4e2a\u6570\u7ec4"):b.multiple&&t("ms-duplex\u5728\u4e0d\u80fd\u5bf9\u5e94\u4e00\u4e2a\u6570\u7ec4");d=Array.isArray(d)?d.map(String):d+"";d+""!==b.oldValue&&(e.val(d),b.oldValue=d+"")};d.bound("change",function(){if(!1!==e.data("duplex-observe")){var f=e.val(),f=Array.isArray(f)?f.map(function(b){return d.pipe(b, +d,"get")}):d.pipe(f,d,"get");f+""!==b.oldValue&&c(f);d.changed.call(b,f,d)}});ka(b,function(){qa(d);d.changed.call(b,c(),d)},NaN)};U.TEXTAREA=U.INPUT;var na=avalon.eventHooks;"onmouseenter"in D||avalon.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(b,c){na[b]={type:c,deel:function(c,e){return function(f){var g=f.relatedTarget;if(!g||g!==c&&!(c.compareDocumentPosition(g)&16))return delete f.type,f.type=b,e.call(c,f)}}}});avalon.each({AnimationEvent:"animationend",WebKitAnimationEvent:"webkitAnimationEnd"}, +function(b,c){x[b]&&!na.animationend&&(na.animationend={type:c})});void 0===p.onmousewheel&&(na.mousewheel={type:"wheel",deel:function(b,c){return function(d){d.wheelDeltaY=d.wheelDelta=0b?Math.max(d+b,0):Math.min(b,d);var d=Ia.apply(this.$model,arguments),e=[],f;this._stopFireLength=!0;d.length&&(e=this._del(b,d.length),f=!0);2]*>([\S\s]*?)<\/script\s*>/gim,jc=/\s+(on[^=\s]+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,kc=/<\w+\b(?:(["'])[^"]*?(\1)|[^>])*>/ig,lc={a:/\b(href)\=("javascript[^"]*"|'javascript[^']*')/ig,img:/\b(src)\=("javascript[^"]*"|'javascript[^']*')/ig, +form:/\b(action)\=("javascript[^"]*"|'javascript[^']*')/ig},mc=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,nc=/([^\#-~| |!])/g,Ja=avalon.filters={uppercase:function(b){return b.toUpperCase()},lowercase:function(b){return b.toLowerCase()},truncate:function(b,c,d){c=c||30;d=void 0===d?"...":d;return b.length>c?b.slice(0,c-d.length)+d:String(b)},sanitize:x.toStaticHTML?toStaticHTML.bind(x):function(b){return b.replace(ic,"").replace(kc,function(b,d){var e=b.toLowerCase().match(/<(\w+)\s/);e&&(e=lc[e[1]])&&(b= +b.replace(e,function(b,c,d){b=d.charAt(0);return c+"="+b+"javascript:void(0)"+b}));return b.replace(jc," ").replace(/\s+/g," ")})},camelize:ha,escape:function(b){return String(b).replace(/&/g,"&").replace(mc,function(b){var d=b.charCodeAt(0);b=b.charCodeAt(1);return"&#"+(1024*(d-55296)+(b-56320)+65536)+";"}).replace(nc,function(b){return"&#"+b.charCodeAt(0)+";"}).replace(//g,">")},currency:function(b,c){return(c||"\uffe5")+avalon.filters.number(b)},number:function(b,c, +d,e){b=(b+"").replace(/[^0-9+\-Ee.]/g,"");b=!isFinite(+b)?0:+b;c=!isFinite(+c)?0:Math.abs(c);e=e||",";d=d||".";var f="",f=function(b,c){var d=Math.pow(10,c);return""+Math.round(b*d)/d},f=(c?f(b,c):""+Math.round(b)).split(".");3b&&(e="-",b=-b);for(b=""+b;b.length-e)g+=e;0===g&&-12===e&&(g=12);return b(g,d,f)}}function d(b,c){return function(d,e){var f=d["get"+b](),g=(c?"SHORT"+b:b).toUpperCase();return e[g][f]}}function e(b){var c;if(c=b.match(k)){b=new Date(0);var d=0,e=0,f=c[8]?b.setUTCFullYear:b.setFullYear,g=c[8]?b.setUTCHours:b.setHours;c[9]&&(d=parseInt(c[9]+c[10],10),e=parseInt(c[9]+c[11],10));f.call(b,parseInt(c[1],10),parseInt(c[2],10)-1,parseInt(c[3],10));d=parseInt(c[4]|| +0,10)-d;e=parseInt(c[5]||0,10)-e;f=parseInt(c[6]||0,10);c=Math.round(1E3*parseFloat("0."+(c[7]||0)));g.call(b,d,e,f,c)}return b}var f={yyyy:c("FullYear",4),yy:c("FullYear",2,0,!0),y:c("FullYear",1),MMMM:d("Month"),MMM:d("Month",!0),MM:c("Month",2,1),M:c("Month",1,1),dd:c("Date",2),d:c("Date",1),HH:c("Hours",2),H:c("Hours",1),hh:c("Hours",2,-12),h:c("Hours",1,-12),mm:c("Minutes",2),m:c("Minutes",1),ss:c("Seconds",2),s:c("Seconds",1),sss:c("Milliseconds",3),EEEE:d("Day"),EEE:d("Day",!0),a:function(b, +c){return 12>b.getHours()?c.AMPMS[0]:c.AMPMS[1]},Z:function(c){c=-1*c.getTimezoneOffset();return c=(0<=c?"+":"")+(b(Math[0chrome // chrome - // IE67chrome + // IE67chrome // IE67chrome // IE67chrome sanitize: function(str) { @@ -4187,10 +4207,10 @@ }, number: function(number, decimals, dec_point, thousands_sep) { //与PHP的number_format完全兼容 - //number 必需,要格式化的数字 - //decimals 可选,规定多少个小数位。 - //dec_point 可选,规定用作小数点的字符串(默认为 . )。 - //thousands_sep 可选,规定用作千位分隔符的字符串(默认为 , ),如果设置了该参数,那么所有其他参数都是必需的。 + //number 必需,要格式化的数字 + //decimals 可选,规定多少个小数位。 + //dec_point 可选,规定用作小数点的字符串(默认为 . )。 + //thousands_sep 可选,规定用作千位分隔符的字符串(默认为 , ),如果设置了该参数,那么所有其他参数都是必需的。 // http://kevin.vanzonneveld.net number = (number + "").replace(/[^0-9+\-Ee.]/g, "") var n = !isFinite(+number) ? 0 : +number, @@ -4440,6 +4460,7 @@ locate.SHORTMONTH = locate.MONTH filters.date.locate = locate } + /********************************************************************* * END * **********************************************************************/ From cb1549e94addd14464a7ab68e450d380650282ec Mon Sep 17 00:00:00 2001 From: RubyLouvre Date: Wed, 19 Nov 2014 15:20:37 +0800 Subject: [PATCH 07/18] =?UTF-8?q?fix=20addClass=E6=B2=A1=E6=9C=89=E8=BF=9B?= =?UTF-8?q?=E8=A1=8Ctrim=E6=93=8D=E4=BD=9C=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- avalon.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/avalon.js b/avalon.js index 5bf54df7b..d814a545e 100644 --- a/avalon.js +++ b/avalon.js @@ -1122,9 +1122,10 @@ } }, _remove: function(cls) { - this._set((" " + this + " ").replace(" " + cls + " ", " ").trim()) + this._set((" " + this + " ").replace(" " + cls + " ", " ")) }, __set: function(cls) { + cls = cls.trim() var node = this.node if (typeof node.className === "string") { node.className = cls From d1d01ee129308f468bb0445ef4bb6b41ae16e963 Mon Sep 17 00:00:00 2001 From: RubyLouvre Date: Wed, 19 Nov 2014 15:39:13 +0800 Subject: [PATCH 08/18] =?UTF-8?q?fix=20parseHTML=E5=A4=84=E7=90=86tr?= =?UTF-8?q?=E5=85=83=E7=B4=A0=E6=8F=92=E5=85=A5caption=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- avalon.js | 14 +++++++------- avalon.min.js | 23 ++++++++++++----------- examples/avalon.shim.js | 17 +++++++++-------- 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/avalon.js b/avalon.js index d814a545e..9f284835a 100644 --- a/avalon.js +++ b/avalon.js @@ -1706,13 +1706,13 @@ fixVML(el) } } - if (tag === "tr") { - for (els = wrapper.children, i = 0; el = els[i++]; ) { - // IE6-8,如果动态生成tr元素,必须会在后面添加早已废弃caption的标签,其nodeName,innerHTML都为"" - if (el.nodeName === "") { - el.parentNode.removeChild(el) - i-- - } + } + if (DOC.createStyleSheet && tag === "tr") { + for (els = wrapper.children, i = 0; el = els[i++]; ) { + // IE6-9,如果动态生成tr元素,必须会在后面添加早已废弃caption的标签,其nodeName,innerHTML都为"" + if (el.nodeName === "") { + el.parentNode.removeChild(el) + i-- } } } diff --git a/avalon.min.js b/avalon.min.js index 53f345eda..fe71ce235 100644 --- a/avalon.min.js +++ b/avalon.min.js @@ -44,7 +44,7 @@ arguments.length&&void 0===b)return this;var c=this,d=arguments;return function( b.childNodes)for(var d=b.childNodes,e=0,f;f=d[e++];)if(f.tagName){var g=p.createElementNS("http://www.w3.org/2000/svg",f.tagName.toLowerCase());L.forEach.call(f.attributes,function(b){g.setAttribute(b.name,b.value)});Ka(f,g);c.appendChild(g)}};Object.defineProperties(SVGElement.prototype,{outerHTML:{enumerable:!0,configurable:!0,get:$a,set:function(b){var c=this.tagName.toLowerCase(),d=this.parentNode;b=avalon.parseHTML(b);"svg"===c?d.insertBefore(b,this):(c=p.createDocumentFragment(),Ka(b,c),d.insertBefore(c, this));d.removeChild(this)}},innerHTML:{enumerable:!0,configurable:!0,get:function(){var b=RegExp("$","i");return this.outerHTML.replace(RegExp("<"+this.nodeName+'\\b(?:(["\'])[^"]*?(\\1)|[^>])*>',"i"),"").replace(b,"")},set:function(b){avalon.clearHTML&&(avalon.clearHTML(this),b=avalon.parseHTML(b),Ka(b,this))}}})}}!B.outerHTML&&r.HTMLElement&&HTMLElement.prototype.__defineGetter__("outerHTML",$a);var P,Q,aa,Mb,vb,Nb=/[-.*+?^${}()|[\]\/\\]/g,D=y,U={loader:function(b){r.define= b?D.define:Bc;r.require=b?D:Ac},interpolate:function(b){P=b[0];Q=b[1];if(P===Q)throw new SyntaxError("openTag!==closeTag");if("\x3c!--,--\x3e"===b+"")u.commentInterpolate=!0;else{b=P+"test"+Q;ea.innerHTML=b;if(ea.innerHTML!==b&&0<=ea.innerHTML.indexOf("<"))throw new SyntaxError("\u6b64\u5b9a\u754c\u7b26\u4e0d\u5408\u6cd5");ea.innerHTML=""}b=(P+"").replace(Nb,"\\$&");var c=(Q+"").replace(Nb,"\\$&");aa=RegExp(b+"(.*?)"+c);Mb=RegExp(b+"(.*?)"+c,"g");vb=RegExp(b+".*?"+c+"|\\sms-")}};u.debug=!0;u.plugins= -U;u.plugins.interpolate(["{{","}}"]);u.paths={};u.shim={};u.maxRepeatSize=100;avalon.config=u;var cb={_toString:function(){var b=this.node.className;return("string"===typeof b?b:b.baseVal).split(/\s+/).join(" ")},_contains:function(b){return-1<(" "+this+" ").indexOf(" "+b+" ")},_add:function(b){this.contains(b)||this._set(this+" "+b)},_remove:function(b){this._set((" "+this+" ").replace(" "+b+" "," ").trim())},__set:function(b){var c=this.node;"string"===typeof c.className?c.className=b:c.setAttribute("class", +U;u.plugins.interpolate(["{{","}}"]);u.paths={};u.shim={};u.maxRepeatSize=100;avalon.config=u;var cb={_toString:function(){var b=this.node.className;return("string"===typeof b?b:b.baseVal).split(/\s+/).join(" ")},_contains:function(b){return-1<(" "+this+" ").indexOf(" "+b+" ")},_add:function(b){this.contains(b)||this._set(this+" "+b)},_remove:function(b){this._set((" "+this+" ").replace(" "+b+" "," "))},__set:function(b){b=b.trim();var c=this.node;"string"===typeof c.className?c.className=b:c.setAttribute("class", b)}};"add,remove".replace(z,function(b){avalon.fn[b+"Class"]=function(c){var d=this[0];c&&("string"===typeof c&&d&&1===d.nodeType)&&c.replace(/\S+/g,function(c){bb(d)[b](c)});return this}});avalon.fn.mix({hasClass:function(b){var c=this[0]||{};return 1===c.nodeType&&bb(c).contains(b)},toggleClass:function(b,c){for(var d,e=0,f=b.split(/\s+/),g="boolean"===typeof c;d=f[e++];)this[(g?c:!this.hasClass(d))?"addClass":"removeClass"](d);return this},attr:function(b,c){return 2===arguments.length?(this[0].setAttribute(b, c),this):this[0].getAttribute(b)},data:function(b,c){b="data-"+ab(b||"");switch(arguments.length){case 2:return this.attr(b,c),this;case 1:var d=this.attr(b);return db(d);case 0:var e={};L.forEach.call(this[0].attributes,function(c){c&&(b=c.name,b.indexOf("data-")||(b=oa(b.slice(5)),e[b]=db(c.value)))});return e}},removeData:function(b){b="data-"+ab(b);this[0].removeAttribute(b);return this},css:function(b,c){if(avalon.isPlainObject(b))for(var d in b)avalon.css(this,d,b[d]);else var e=avalon.css(this, b,c);return void 0!==e?e:this},position:function(){var b,c,d=this[0],e={top:0,left:0};if(d)return"fixed"===this.css("position")?c=d.getBoundingClientRect():(b=this.offsetParent(),c=this.offset(),"HTML"!==b[0].tagName&&(e=b.offset()),e.top+=avalon.css(b[0],"borderTopWidth",!0),e.left+=avalon.css(b[0],"borderLeftWidth",!0)),{top:c.top-e.top-avalon.css(d,"marginTop",!0),left:c.left-e.left-avalon.css(d,"marginLeft",!0)}},offsetParent:function(){for(var b=this[0].offsetParent||B;b&&"HTML"!==b.tagName&& @@ -61,16 +61,17 @@ return{top:c.top+h-b,left:c.left+e-g}};var Qc=/^"],param:[1,""],col:[2,"","
"],legend:[1,"
"],option:[1,""], thead: [1, "", "
"], - tr: [2, ""], + //如果这里不写
,在IE6-9会在多出一个奇怪的caption标签 + tr: [2, "","
"], td: [3, ""], g: [1, '', ''], //IE6-8在用innerHTML生成节点时,不能直接创建no-scope元素与HTML5的新标签 @@ -1707,15 +1708,7 @@ } } } - if (DOC.createStyleSheet && tag === "tr") { - for (els = wrapper.children, i = 0; el = els[i++]; ) { - // IE6-9,如果动态生成tr元素,必须会在后面添加早已废弃caption的标签,其nodeName,innerHTML都为"" - if (el.nodeName === "") { - el.parentNode.removeChild(el) - i-- - } - } - } + while (firstChild = wrapper.firstChild) { // 将wrapper上的节点转移到文档碎片上! fragment.appendChild(firstChild) } diff --git a/avalon.min.js b/avalon.min.js index fe71ce235..81a540627 100644 --- a/avalon.min.js +++ b/avalon.min.js @@ -58,20 +58,19 @@ ac=/^(none|table(?!-c[ea]).+)/;"Width,Height".replace(z,function(b){var c=b.toLo x[c+"&get"]=function(b){var d=[];eb(b,d);for(var e=x[c+":get"](b),f=0,m;m=d[f++];){b=m.node;for(var n in m)"string"===typeof m[n]&&(b.style[n]=m[n])}return e};avalon.fn[c]=function(g){var h=this[0];if(0===arguments.length){if(h.setTimeout)return h["inner"+b]||h.document.documentElement[d];if(9===h.nodeType){var k=h.documentElement;return Math.max(h.body[e],k[e],h.body[f],k[f],k[d])}return x[c+"&get"](h)}return this.css(c,g)};avalon.fn["inner"+b]=function(){return x[c+":get"](this[0],void 0,-2)};avalon.fn["outer"+ b]=function(b){return x[c+":get"](this[0],void 0,!0===b?2:0)}});avalon.fn.offset=function(){var b=this[0],c={left:0,top:0};if(!b||!b.tagName||!b.ownerDocument)return c;var d=b.ownerDocument,e=d.body,f=d.documentElement,d=d.defaultView||d.parentWindow;if(!avalon.contains(f,b))return c;b.getBoundingClientRect&&(c=b.getBoundingClientRect());var b=f.clientTop||e.clientTop,g=f.clientLeft||e.clientLeft,h=Math.max(d.pageYOffset||0,f.scrollTop,e.scrollTop),e=Math.max(d.pageXOffset||0,f.scrollLeft,e.scrollLeft); return{top:c.top+h-b,left:c.left+e-g}};var Qc=/^]+))?)*\s+value[\s=]/i,La={"option:get":r.VBArray?function(b){return Qc.test(b.outerHTML)?b.value:b.text.trim()}:function(b){return b.value},"select:get":function(b,c){for(var d,e=b.options,f=b.selectedIndex,g=La["option:get"],h="select-one"===b.type||0>f,k=h?null:[],l=h?f+1:e.length,m=0>f?l:h?f:0;m"],param:[1,""],col:[2,"
","
"],legend:[1,"
"],option:[1,""],thead:[1,"","
"],tr:[2,"","
"],td:[3,""],g:[1,'', +""],_default:w?[0,""]:[1,"X
"]};E.optgroup=E.option;E.tbody=E.tfoot=E.colgroup=E.caption=E.thead;E.th=E.td;"circle,defs,ellipse,image,line,path,polygon,polyline,rect,symbol,text,use".replace(z,function(b){E[b]=E.g});var Rc=/<([\w:]+)/,Sc=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,Qb=w?/[^\d\D]/:/(<(?:script|link|style|meta|noscript))/ig,Tc=M(["","text/javascript","text/ecmascript","application/ecmascript","application/javascript"]),Uc=/<(?:tb|td|tf|th|tr|col|opt|leg|cap|area)/, +Vc=p.createElement("script");avalon.parseHTML=function(b){"string"!==typeof b&&(b+="");b=b.replace(Sc,"<$1>").trim();var c=(Rc.exec(b)||["",""])[1].toLowerCase(),d=E[c]||E._default,c=I.cloneNode(!1),e=ea,f;w||(b=b.replace(Qb,"
$1"));e.innerHTML=d[1]+b+(d[2]||"");b=e.getElementsByTagName("script");if(b.length)for(var g=0,h;h=b[g++];)Tc[h.type]&&(f=Vc.cloneNode(!1),L.forEach.call(h.attributes,function(b){b&&b.specified&&(f[b.name]=b.value,f.setAttribute(b.name,b.value))}),f.text= +h.text,h.parentNode.replaceChild(f,h));for(g=d[0];g--;e=e.lastChild);if(!w){b=e.getElementsByTagName("br");for(g=0;h=b[g++];)h.className&&"msNoScope"===h.className&&(h.parentNode.removeChild(h),g--);b=e.all;for(g=0;h=b[g++];)gb(h)&&bc(h)}for(;d=e.firstChild;)c.appendChild(d);return c};avalon.innerHTML=function(b,c){if(!w&&!Qb.test(c)&&!Uc.test(c))try{b.innerHTML=c;return}catch(d){}var e=this.parseHTML(c);this.clearHTML(b).appendChild(e)};avalon.clearHTML=function(b){for(b.textContent="";b.firstChild;)b.removeChild(b.firstChild); +return b};var R={$watch:function(b,c){if("function"===typeof c){var d=this.$events[b];d?d.push(c):this.$events[b]=[c]}else this.$events=this.$watch.backup;return this},$unwatch:function(b,c){var d=arguments.length;if(0===d)this.$watch.backup=this.$events,this.$events={};else if(1===d)this.$events[b]=[];else for(var d=this.$events[b]||[],e=d.length;0>~--e;)if(d[e]===c)return d.splice(e,1);return this},$fire:function(b){var c;/^(\w+)!(\S+)$/.test(b)&&(c=RegExp.$1,b=RegExp.$2);var d=this.$events,e=$.call(arguments, +1),f=[b].concat(e);if("all"===c)for(var g in avalon.vmodels)e=avalon.vmodels[g],e!==this&&e.$fire.apply(e,f);else if("up"===c||"down"===c){if(d=d.expr&&Rb(d.expr)){for(g in avalon.vmodels)if(e=avalon.vmodels[g],e!==this&&e.$events.expr){var h=Rb(e.$events.expr);if(h&&("down"===c?d.contains(h):h.contains(d)))h._avalon=e}g=p.getElementsByTagName("*");var k=[];Array.prototype.forEach.call(g,function(b){b._avalon&&(k.push(b._avalon),b._avalon="",b.removeAttribute("_avalon"))});"up"===c&&k.reverse();for(g= +0;(c=k[g++])&&!1!==c.$fire.apply(c,f););}}else{f=d[b]||[];c=d.$all||[];for(g=0;d=f[g++];)V(d)&&d.apply(this,e);for(g=0;d=c[g++];)V(d)&&d.apply(this,arguments)}}},Wc=/(\w+)\[(avalonctrl)="(\S+)"\]/,Rb=p.querySelector?function(b){return p.querySelector(b)}:function(b){b=b.match(Wc);for(var c=p.getElementsByTagName(b[1]),d=0,e;e=c[d++];)if(e.getAttribute(b[2])===b[3])return e},cc=/^(duplex|on)$/,S=[],za=0,dc=200,jb=new Date,kb,Oa={};avalon.scanCallback=function(b,c){c=c||"$all";(Oa[c]||(Oa[c]=[])).push(b)}; +avalon.scan=function(b,c,d){b=b||B;var e=Oa[d||"$all"]||[];c=c?[].concat(c):[];var f=0,g=!1,h,k=!1;c.cb=function(b){f+=b;k=!0;setTimeout(function(){if(0>=f&&!g)for(g=!0;h=e.shift();)h()})};lb(b,c);if(!k)for(;h=e.shift();)h()};var hc=M("AREA,BASE,BASEFONT,BR,COL,COMMAND,EMBED,HR,IMG,INPUT,LINK,META,PARAM,SOURCE,TRACK,WBR,NOSCRIPT,SCRIPT,STYLE,TEXTAREA"),tb=/ms-(\w+)-?(.*)/,ub={"if":10,repeat:90,data:100,widget:110,each:1400,"with":1500,duplex:2E3,on:3E3},fc=M("animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scan,scroll,submit"), +gc=M("value,title,alt,checked,selected,disabled,readonly,enabled");if(!"1"[0])var Pa=Da(512),Xc=/\s+(ms-[^=\s]+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,Yc=/^['"]/,Zc=/<\w+\b(?:(["'])[^"]*?(\1)|[^>])*>/i,$c=/&/g,sb=function(b){b=b.outerHTML;if(".avalonHide{ display: none!important }";var gd=/(?:[\s\S]+?)<\/noscript>/img,hd=/([\s\S]+?)<\/noscript>/im,Sa=function(){return new (r.XMLHttpRequest||ActiveXObject)("Microsoft.XMLHTTP")},fa=function(b,c,d){if(b=b.getAttribute(c)){c=0;for(var e;e=d[c++];)if(e.hasOwnProperty(b)&&"function"===typeof e[b])return e[b]}},Ta=avalon.templateCache={};avalon.contains=Za;var Ua={};"autofocus,autoplay,async,allowTransparency,checked,controls,declare,disabled,defer,defaultChecked,defaultSelectedcontentEditable,isMap,loop,multiple,noHref,noResize,noShade,open,readOnly,selected".replace(z, function(b){Ua[b.toLowerCase()]=b});var Fa=avalon.bindingExecutors={attr:function(b,c,d){var e=d.type,f=d.param;if("css"===e)avalon(c).css(f,b);else if("attr"===e){if(Ua[f]&&(e=Ua[f],"boolean"===typeof c[e]))return c[e]=!!b;!w&&Ra[f]&&(f=Ra[f]);if(!1===b||null===b||void 0===b)return c.removeAttribute(f);(Ib.test(c)?0:p.namespaces&&gb(c)||f in c.cloneNode(!1))?c[f]=b:c.setAttribute(f,b)}else if("include"===e&&b){var g=d.vmodels,h=d.includeRendered,k=d.includeLoaded,l=d.includeReplaced?c.parentNode: c;g.cb(1);var m=function(b){k&&(b=k.apply(l,[b].concat(g)));for(h&&qa(l,function(){h.call(l)},NaN);;){var c=d.startInclude.nextSibling;if(c&&c!==d.endInclude)l.removeChild(c);else break}b=avalon.parseHTML(b);c=avalon.slice(b.childNodes);l.insertBefore(b,d.endInclude);Aa(c,g);g.cb(-1)};if("src"===d.param)if(Ta[b])avalon.nextTick(function(){m(Ta[b])});else{var n=Sa();n.onreadystatechange=function(){if(4===n.readyState){var c=n.status;if(200<=c&&300>c||304===c||1223===c)m(Ta[b]=n.responseText)}};n.open("GET", b,!0);"withCredentials"in n&&(n.withCredentials=!0);n.setRequestHeader("X-Requested-With","XMLHttpRequest");n.send(null)}else{var q=b&&1===b.nodeType?b:p.getElementById(b);if(q){if("NOSCRIPT"===q.tagName&&!q.innerHTML&&!q.fixIE78){n=Sa();n.open("GET",location,!1);n.send(null);c=p.getElementsByTagName("noscript");for(var f=(n.responseText||"").match(gd)||[],e=f.length,t=0;t"], option: [1, "
", "
"], - tr: [2, ""], + //如果这里不写
,在IE6-9会在多出一个奇怪的caption标签 + tr: [2, "", "
"], td: [3, ""], g: [1, '', ''], //IE6-8在用innerHTML生成节点时,不能直接创建no-scope元素与HTML5的新标签 @@ -1707,15 +1708,6 @@ } } } - if (DOC.createStyleSheet && tag === "tr") { - for (els = wrapper.children, i = 0; el = els[i++]; ) { - // IE6-9,如果动态生成tr元素,必须会在后面添加早已废弃caption的标签,其nodeName,innerHTML都为"" - if (el.nodeName === "") { - el.parentNode.removeChild(el) - i-- - } - } - } while (firstChild = wrapper.firstChild) { // 将wrapper上的节点转移到文档碎片上! fragment.appendChild(firstChild) } From 8d20c47f3492d255e6d220217d1a56e2e9ef5f15 Mon Sep 17 00:00:00 2001 From: RubyLouvre Date: Wed, 19 Nov 2014 18:27:30 +0800 Subject: [PATCH 10/18] fix shim --- examples/avalon.shim.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/avalon.shim.js b/examples/avalon.shim.js index 06be3ddf0..085675a2b 100644 --- a/examples/avalon.shim.js +++ b/examples/avalon.shim.js @@ -1639,7 +1639,7 @@ col: [2, "
", "
"], legend: [1, "
"], option: [1, ""], thead: [1, "", "
"], //如果这里不写,在IE6-9会在多出一个奇怪的caption标签 - tr: [2, "","
"], + tr: [2, "", "
"], td: [3, ""], g: [1, '', ''], //IE6-8在用innerHTML生成节点时,不能直接创建no-scope元素与HTML5的新标签 @@ -1874,6 +1874,7 @@ var c = ronduplex.test(data.type) ? data : fn.apply(0, data.args) data.handler(c, data.element, data) } catch (e) { + console.log(fn + "") log("warning:exception throwed in [registerSubscriber] " + e) delete data.evaluator var node = data.element @@ -3809,6 +3810,9 @@ for (var i in EventManager) { array[i] = EventManager[i] } + array.size = function() { //取得数组长度,这个函数可以同步视图,length不能 + return array._.length + } avalon.mix(array, CollectionPrototype) return array } @@ -3893,9 +3897,6 @@ contains: function(el) { //判定是否包含 return this.indexOf(el) !== -1 }, - size: function() { //取得数组长度,这个函数可以同步视图,length不能 - return this._.length - }, remove: function(el) { //移除第一个等于给定值的元素 return this.removeAt(this.indexOf(el)) }, diff --git a/avalon.modern.js b/avalon.modern.js index e8c6c2ee4..f86459373 100644 --- a/avalon.modern.js +++ b/avalon.modern.js @@ -3024,6 +3024,9 @@ for (var i in EventManager) { array[i] = EventManager[i] } + array.size = function() { //取得数组长度,这个函数可以同步视图,length不能 + return array._.length + } avalon.mix(array, CollectionPrototype) return array } @@ -3110,9 +3113,6 @@ contains: function(el) { //判定是否包含 return this.indexOf(el) !== -1 }, - size: function() { //取得数组长度,这个函数可以同步视图,length不能 - return this._.length - }, remove: function(el) { //移除第一个等于给定值的元素 return this.removeAt(this.indexOf(el)) }, From 40f746386610474b0688759d143bb212cf2c2b79 Mon Sep 17 00:00:00 2001 From: RubyLouvre Date: Thu, 20 Nov 2014 12:28:39 +0800 Subject: [PATCH 15/18] =?UTF-8?q?update=20array.size=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=A7=A3=E9=87=8A=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- avalon.js | 19 +++++++++--- avalon.min.js | 55 ++++++++++++++++---------------- avalon.modern.js | 20 +++++++++--- avalon.modern.min.js | 74 ++++++++++++++++++++++---------------------- 4 files changed, 96 insertions(+), 72 deletions(-) diff --git a/avalon.js b/avalon.js index 779592744..ce444d720 100644 --- a/avalon.js +++ b/avalon.js @@ -2471,8 +2471,19 @@ var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig") code = code.replace(reg, function(_) { var c = _.charAt(v.length) - if (c === "." || c === "[") { + var method = /^\s*\(/.test(RegExp.rightContext) + if (c === "." || c === "[" || method) {//比如v为aa,我们只匹配aa.bb,aa[cc],不匹配aaa.xxx var name = "var" + String(Math.random()).replace(/^0\./, "") + if (method) {//array.size() + var array = _.split(".") + if (array.length > 2) { + var last = array.pop() + assigns.push(name + " = " + array.join(".")) + return name + "." + last + } else { + return _ + } + } assigns.push(name + " = " + _) return name } else { @@ -3810,9 +3821,6 @@ for (var i in EventManager) { array[i] = EventManager[i] } - array.size = function() { //取得数组长度,这个函数可以同步视图,length不能 - return array._.length - } avalon.mix(array, CollectionPrototype) return array } @@ -3852,6 +3860,9 @@ this._fire("index", n > 2 ? n - 2 : 0) return n }, + size: function() { //取得数组长度,这个函数可以同步视图,length不能 + return this._.length + }, pushArray: function(array) { return this.push.apply(this, array) }, diff --git a/avalon.min.js b/avalon.min.js index 81a540627..3c286466f 100644 --- a/avalon.min.js +++ b/avalon.min.js @@ -6,35 +6,36 @@ d;f.$events=g;for(e in R)c=R[e],w||(c=c.bind(f)),f[e]=c;f.hasOwnProperty=functio return h}function Z(b,c,d){b="for(var "+b+"i=0,n = this.length; i < n; i++){"+c.replace("_","((i in this) && fn.call(scope,this[i],i,this))")+"}"+d;return Function("fn,scope",b)}function Za(b,c){try{for(;c=c.parentNode;)if(c===b)return!0;return!1}catch(d){return!1}}function $a(){return(new XMLSerializer).serializeToString(this)}function u(b){for(var c in b)if(O.call(b,c)){var d=b[c];if("function"===typeof u.plugins[c])u.plugins[c](d);else"object"===typeof u[c]?avalon.mix(u[c],d):u[c]=d}return this} function ab(b){return b.replace(/([a-z\d])([A-Z]+)/g,"$1-$2").toLowerCase()}function oa(b){return 0>b.indexOf("-")&&0>b.indexOf("_")?b:b.replace(/[-_][^-_]/g,function(b){return b.charAt(1).toUpperCase()})}function bb(b){if(!("classList"in b)){b.classList={node:b};for(var c in cb)b.classList[c.slice(1)]=cb[c]}return b.classList}function db(b){try{b="true"===b?!0:"false"===b?!1:"null"===b?null:+b+""===b?+b:$b.test(b)?avalon.parseJSON(b):b}catch(c){}return b}function eb(b,c){if(0>=b.offsetWidth){if(ac.test(x["@:get"](b, "display"))){var d={node:b},e;for(e in fb)d[e]=b.style[e],b.style[e]=fb[e];c.push(d)}(d=b.parentNode)&&1===d.nodeType&&eb(d,c)}}function gb(b){var c=b.nodeName;return c.toLowerCase()===c&&b.scopeName&&""===b.outerText}function bc(b){"url(#default#VML)"!==b.currentStyle.behavior&&(b.style.behavior="url(#default#VML)",b.style.display="inline-block",b.style.zoom=1)}function ya(b){Y[A]=b;avalon.openComputedCollect=!0;var c=b.evaluator;if(c)try{var d=cc.test(b.type)?b:c.apply(0,b.args);b.handler(d,b.element, -b)}catch(e){v("warning:exception throwed in [registerSubscriber] "+e),delete b.evaluator,c=b.element,3===c.nodeType&&(d=c.parentNode,u.commentInterpolate?d.replaceChild(p.createComment(b.value),c):c.data=P+b.value+Q)}avalon.openComputedCollect=!1;delete Y[A]}function ka(b){var c=Y[A];b&&(c&&avalon.Array.ensure(b,c)&&c.element)&&hb(c,b)}function hb(b,c){b.$uuid=b.$uuid||ha();c.$uuid=c.$uuid||ha();var d={data:b,list:c,toString:function(){return b.$uuid+" "+c.$uuid}};S[d]||(S[d]=1,S.push(d))}function ib(){for(var b= -za,c=za+dc;b"))&&ob(b,c)}}function Ca(b,c){b.length&&c.cb(b.length);for(var d=0,e;e=b[d++];)e.vmodels=c,C[e.type](e,c),e.evaluator&&(e.element&&1===e.element.nodeType)&&e.element.removeAttribute(e.name);b.length=0}function rb(b,c){0b&&delete c[d.shift()];return c[e]=f}var d=[];return c}function xb(b,c,d){var e=d.type,f=d.filters?d.filters.join(""):"",g=c.map(function(b){return String(b.$id).replace(oc,"$1")})+b+e+f,h=pc(b).concat(),k=[],l=[],m=[],n="";c=wb(c);d.vars=[];for(var q=0,n=c.length;q>0)-(d.clientLeft>>0),c.pageY=b.clientY+(d.scrollTop>>0)-(d.clientTop>> -0),c.wheelDeltaY=c.wheelDelta,c.wheelDeltaX=0);c.timeStamp=new Date-0;c.originalEvent=b;c.preventDefault=function(){b.returnValue=!1};c.stopPropagation=function(){b.cancelBubble=!0};return c}function Xb(b){var c=[];c.$id=ha();c.$model=b;c.$events={};c.$events[G]=[];c._=N({length:b.length});c._.$watch("length",function(b,d){c.$fire("length",b,d)});for(var d in R)c[d]=R[d];avalon.mix(c,Ab);return c}function Bb(b,c,d,e){var f=avalon.parseHTML(b.template),g=avalon.slice(f.childNodes);c.appendChild(f); -d.$outer=b.$outer;b=b.vmodels;d=[d].concat(b);d.cb=b.cb;e.push({nodes:g,vmodels:d})}function Ha(b,c){var d=b.endRepeat,e=[],f=b.element.nextSibling;if(f!==d){do if(f!==d)e.push(f);else break;while(f=f.nextSibling)}return e[b.group*c]||d}function Cb(b,c,d){c*=d||1;d=[b];for(var e=1,f=I;eu.maxRepeatSize&&da.pop()}b.length=0}function T(){p.body&&(D?(s["ready!"].state=2,D.checkDeps()):Fb.forEach(function(b){b(avalon)}),T=y)}function Gb(){try{B.doScroll("left"),T()}catch(b){setTimeout(Gb)}}var A=new Date- -0,G="$"+A,r=Function("return this")(),Ac=r.require,Bc=r.define,ja=!1,z=/[^, ]+/g,Hb=/\[native code\]/,wa=/^(?:object|array)$/,Ib=/^\[object SVG\w*Element\]$/,Vb=/^\[object (?:Window|DOMWindow|global)\]$/,Ia=Object.prototype,O=Ia.hasOwnProperty,ia=Ia.toString,L=Array.prototype,$=L.slice,Y={},w=r.dispatchEvent,B=p.documentElement,J=p.getElementsByTagName("head")[0],I=p.createDocumentFragment(),ea=p.createElement("div"),Jb={};"Boolean Number String Function Array Date RegExp Object Error".replace(z, -function(b){Jb["[object "+b+"]"]=b.toLowerCase()});avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]=this.element=b};avalon.fn=avalon.prototype=avalon.init.prototype;avalon.type=function(b){return null==b?String(b):"object"===typeof b||"function"===typeof b?Jb[ia.call(b)]||"object":typeof b};var V="object"===typeof alert?function(b){try{return/^\s*\bfunction\b/.test(b+"")}catch(c){return!1}}:function(b){return"[object Function]"==ia.call(b)};avalon.isFunction=V;avalon.isWindow= -function(b){return!b?!1:b==b.document&&b.document!=b};Ya(r)&&(avalon.isWindow=Ya);for(var Cc in avalon({}))break;var Dc="0"!==Cc;avalon.isPlainObject=function(b,c){if(!b||"object"!==avalon.type(b)||b.nodeType||avalon.isWindow(b))return!1;try{if(b.constructor&&!O.call(b,"constructor")&&!O.call(b.constructor.prototype,"isPrototypeOf"))return!1}catch(d){return!1}if(Dc)for(c in b)return O.call(b,c);for(c in b);return void 0===c||O.call(b,c)};Hb.test(Object.getPrototypeOf)&&(avalon.isPlainObject=function(b){return!!b&& -"object"===typeof b&&Object.getPrototypeOf(b)===Ia});avalon.mix=avalon.fn.mix=function(){var b,c,d,e,f,g=arguments[0]||{},h=1,k=arguments.length,l=!1;"boolean"===typeof g&&(l=g,g=arguments[1]||{},h++);"object"!==typeof g&&"function"!==avalon.type(g)&&(g={});h===k&&(g=this,h--);for(;h>0)-(d.clientLeft>>0),c.pageY=b.clientY+(d.scrollTop>>0)-(d.clientTop>>0),c.wheelDeltaY=c.wheelDelta,c.wheelDeltaX=0);c.timeStamp=new Date-0;c.originalEvent=b;c.preventDefault=function(){b.returnValue=!1};c.stopPropagation=function(){b.cancelBubble=!0};return c}function Xb(b){var c=[];c.$id=ha();c.$model=b;c.$events={};c.$events[G]=[];c._=N({length:b.length});c._.$watch("length",function(b,d){c.$fire("length",b,d)});for(var d in R)c[d]=R[d]; +avalon.mix(c,Ab);return c}function Bb(b,c,d,e){var f=avalon.parseHTML(b.template),g=avalon.slice(f.childNodes);c.appendChild(f);d.$outer=b.$outer;b=b.vmodels;d=[d].concat(b);d.cb=b.cb;e.push({nodes:g,vmodels:d})}function Ha(b,c){var d=b.endRepeat,e=[],f=b.element.nextSibling;if(f!==d){do if(f!==d)e.push(f);else break;while(f=f.nextSibling)}return e[b.group*c]||d}function Cb(b,c,d){c*=d||1;d=[b];for(var e=1,f=I;eu.maxRepeatSize&&da.pop()}b.length=0}function T(){p.body&&(D?(s["ready!"].state=2,D.checkDeps()):Fb.forEach(function(b){b(avalon)}), +T=y)}function Gb(){try{B.doScroll("left"),T()}catch(b){setTimeout(Gb)}}var A=new Date-0,G="$"+A,r=Function("return this")(),Ac=r.require,Bc=r.define,ja=!1,z=/[^, ]+/g,Hb=/\[native code\]/,wa=/^(?:object|array)$/,Ib=/^\[object SVG\w*Element\]$/,Vb=/^\[object (?:Window|DOMWindow|global)\]$/,Ia=Object.prototype,O=Ia.hasOwnProperty,ia=Ia.toString,L=Array.prototype,$=L.slice,Y={},w=r.dispatchEvent,B=p.documentElement,J=p.getElementsByTagName("head")[0],I=p.createDocumentFragment(),ea=p.createElement("div"), +Jb={};"Boolean Number String Function Array Date RegExp Object Error".replace(z,function(b){Jb["[object "+b+"]"]=b.toLowerCase()});avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]=this.element=b};avalon.fn=avalon.prototype=avalon.init.prototype;avalon.type=function(b){return null==b?String(b):"object"===typeof b||"function"===typeof b?Jb[ia.call(b)]||"object":typeof b};var V="object"===typeof alert?function(b){try{return/^\s*\bfunction\b/.test(b+"")}catch(c){return!1}}: +function(b){return"[object Function]"==ia.call(b)};avalon.isFunction=V;avalon.isWindow=function(b){return!b?!1:b==b.document&&b.document!=b};Ya(r)&&(avalon.isWindow=Ya);for(var Cc in avalon({}))break;var Dc="0"!==Cc;avalon.isPlainObject=function(b,c){if(!b||"object"!==avalon.type(b)||b.nodeType||avalon.isWindow(b))return!1;try{if(b.constructor&&!O.call(b,"constructor")&&!O.call(b.constructor.prototype,"isPrototypeOf"))return!1}catch(d){return!1}if(Dc)for(c in b)return O.call(b,c);for(c in b);return void 0=== +c||O.call(b,c)};Hb.test(Object.getPrototypeOf)&&(avalon.isPlainObject=function(b){return!!b&&"object"===typeof b&&Object.getPrototypeOf(b)===Ia});avalon.mix=avalon.fn.mix=function(){var b,c,d,e,f,g=arguments[0]||{},h=1,k=arguments.length,l=!1;"boolean"===typeof g&&(l=g,g=arguments[1]||{},h++);"object"!==typeof g&&"function"!==avalon.type(g)&&(g={});h===k&&(g=this,h--);for(;h 0 Then","\t\t["+b+'] = [__proxy__]([__data__],"'+b+'")',"\tEnd If","\tOn Error Goto 0","\tEnd Property");f.push("End Class");b=f.join("\r\n"); b=r.findOrDefineVBClass(e,b);b===e&&r.parseVB(["Function "+e+"Factory(a, b)","\tDim o","\tSet o = (New "+e+")(a, b)","\tSet "+e+"Factory = o","End Function"].join("\r\n"));return r[b+"Factory"](c,Ec)}}if(!"\u53f8\u5f92\u6b63\u7f8e".trim){var Fc=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;String.prototype.trim=function(){return this.replace(Fc,"")}}var Gc=!{toString:null}.propertyIsEnumerable("toString"),Hc=function(){}.propertyIsEnumerable("prototype"),Kb="toString toLocaleString valueOf hasOwnProperty isPrototypeOf propertyIsEnumerable constructor".split(" "), @@ -101,9 +102,9 @@ HTMLInputElement.prototype;Object.getOwnPropertyNames(Va);var vc=Object.getOwnPr Array.isArray(d)?d.map(String):d+"";d+""!==b.oldValue&&(e.val(d),b.oldValue=d+"")};d.bound("change",function(){if(!1!==e.data("duplex-observe")){var f=e.val(),f=Array.isArray(f)?f.map(function(b){return d.pipe(b,d,"get")}):d.pipe(f,d,"get");f+""!==b.oldValue&&c(f);d.changed.call(b,f,d)}});qa(b,function(){ya(d);d.changed.call(b,c(),d)},NaN)};X.TEXTAREA=X.INPUT;var ga=avalon.eventHooks;"onmouseenter"in B||avalon.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(b,c){ga[b]={type:c,deel:function(c, e){return function(f){var g=f.relatedTarget;if(!g||g!==c&&!(c.compareDocumentPosition(g)&16))return delete f.type,f.type=b,e.call(c,f)}}}});avalon.each({AnimationEvent:"animationend",WebKitAnimationEvent:"webkitAnimationEnd"},function(b,c){r[b]&&!ga.animationend&&(ga.animationend={type:c})});"oninput"in p.createElement("input")||(ga.input={type:"propertychange",deel:function(b,c){return function(d){if("value"===d.propertyName)return d.type="input",c.call(b,d)}}});if(void 0===p.onmousewheel){var Ub= void 0!==p.onwheel?"wheel":"DOMMouseScroll",id="wheel"===Ub?"deltaY":"detail";ga.mousewheel={type:Ub,deel:function(b,c){return function(d){d.wheelDeltaY=d.wheelDelta=0]*>([\S\s]*?)<\/script\s*>/gim,kd=/\s+(on[^=\s]+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,ld=/<\w+\b(?:(["'])[^"]*?(\1)|[^>])*>/ig,md={a:/\b(href)\=("javascript[^"]*"|'javascript[^']*')/ig,img:/\b(src)\=("javascript[^"]*"|'javascript[^']*')/ig,form:/\b(action)\=("javascript[^"]*"|'javascript[^']*')/ig}, nd=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,od=/([^\#-~| |!])/g,Xa=avalon.filters={uppercase:function(b){return b.toUpperCase()},lowercase:function(b){return b.toLowerCase()},truncate:function(b,c,d){c=c||30;d=void 0===d?"...":d;return b.length>c?b.slice(0,c-d.length)+d:String(b)},camelize:oa,sanitize:function(b){return b.replace(jd,"").replace(ld,function(b,d){var e=b.toLowerCase().match(/<(\w+)\s/);e&&(e=md[e[1]])&&(b=b.replace(e,function(b,c,d){b=d.charAt(0);return c+"="+b+"javascript:void(0)"+b}));return b.replace(kd, diff --git a/avalon.modern.js b/avalon.modern.js index f86459373..aee5ce66b 100644 --- a/avalon.modern.js +++ b/avalon.modern.js @@ -1870,8 +1870,19 @@ var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig") code = code.replace(reg, function(_) { var c = _.charAt(v.length) - if (c === "." || c === "[") { + var method = /^\s*\(/.test(RegExp.rightContext) + if (c === "." || c === "[" || method) {//比如v为aa,我们只匹配aa.bb,aa[cc],不匹配aaa.xxx var name = "var" + String(Math.random()).replace(/^0\./, "") + if (method) {//array.size() + var array = _.split(".") + if (array.length > 2) { + var last = array.pop() + assigns.push(name + " = " + array.join(".")) + return name + "." + last + } else { + return _ + } + } assigns.push(name + " = " + _) return name } else { @@ -3024,9 +3035,7 @@ for (var i in EventManager) { array[i] = EventManager[i] } - array.size = function() { //取得数组长度,这个函数可以同步视图,length不能 - return array._.length - } + avalon.mix(array, CollectionPrototype) return array } @@ -3038,6 +3047,9 @@ _fire: function(method, a, b) { notifySubscribers(this.$events[subscribers], method, a, b) }, + size: function() { //取得数组长度,这个函数可以同步视图,length不能 + return this._.length + }, _add: function(arr, pos) { var oldLength = this.length pos = typeof pos === "number" ? pos : oldLength diff --git a/avalon.modern.min.js b/avalon.modern.min.js index 9faf998ce..0a851449a 100644 --- a/avalon.modern.min.js +++ b/avalon.modern.min.js @@ -14,39 +14,39 @@ e)};e.length&&(f.filters=e);e=[f]}else e=ua(b.data);if(e.length){for(var g=0;f=e l&&(b.msData=b.msData||f)))}f["ms-checked"]&&f["ms-duplex"]&&u("warning!\u4e00\u4e2a\u5143\u7d20\u4e0a\u4e0d\u80fd\u540c\u65f6\u5b9a\u4e49ms-checked\u4e0ems-duplex");e.sort(function(b,c){return b.priority-c.priority});d=e[0]||{};switch(d.type){case "if":case "repeat":case "widget":va([d],c);break;default:va(e,c),!Gb[b.tagName]&&bb.test(b.innerHTML+b.textContent)&&Xa(b,c)}}function va(b,c){b.length&&c.cb(b.length);for(var d=0,e;e=b[d++];)e.vmodels=c,y[e.type](e,c),e.evaluator&&(e.element&&1===e.element.nodeType)&& e.element.removeAttribute(e.name);b.length=0}function $a(b,c){0b&&delete c[d.shift()];return c[e]=f}var d=[];return c}function eb(b,c,d){var e=d.type,f="duplex"===e,g=d.filters?d.filters.join(""): -"",h=c.map(function(b){return b.$id.replace(Lb,"$1")})+b+e+g,k=Mb(b).concat(),l=[],m=[],q=[],n="";d.vars=[];c=cb(c);for(var t=0,n=c.length;ts.maxRepeatSize&&$.pop()}b.length=0}function aa(){A?(r["ready!"].state=2,A.checkDeps()):lb.forEach(function(b){b(avalon)});aa=v}var B=Date.now(),F="$"+B,x=Function("return this")(),Wb=x.require,Xb=x.define,da=!1,w=/[^, ]+/g,La=/^(?:object|array)$/,mb=/^\[object SVG\w*Element\]$/,Yb=/^\[object (Window|DOMWindow|global)\]$/,Aa=Object.prototype,Ma=Aa.hasOwnProperty,Ba=Aa.toString,N=Array.prototype,ja=N.slice,W={},G=p.head,D=p.documentElement,H=p.createDocumentFragment(),ma=p.createElement("div"), -nb={};"Boolean Number String Function Array Date RegExp Object Error".replace(w,function(b){nb["[object "+b+"]"]=b.toLowerCase()});x.avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]=this.element=b};avalon.fn=avalon.prototype=avalon.init.prototype;avalon.isFunction=S;avalon.type=function(b){return null==b?String(b):"object"===typeof b||"function"===typeof b?nb[Ba.call(b)]||"object":typeof b};avalon.isWindow=function(b){return Yb.test(Ba.call(b))};avalon.isPlainObject=function(b){return!!b&& -"object"===typeof b&&Object.getPrototypeOf(b)===Aa};avalon.mix=avalon.fn.mix=function(){var b,c,d,e,f,g=arguments[0]||{},h=1,k=arguments.length,l=!1;"boolean"===typeof g&&(l=g,g=arguments[1]||{},h++);"object"!==typeof g&&"function"!==avalon.type(g)&&(g={});h===k&&(g=this,h--);for(;h$","i");return this.outerHTML.replace(RegExp("<"+this.nodeName+'\\b(?:(["\'])[^"]*?(\\1)|[^>])*>',"i"),"").replace(b,"")},set:function(b){avalon.clearHTML&&(avalon.clearHTML(this),b=avalon.parseHTML(b),Ca(b, -this))}}})}}var la=avalon.vmodels={};avalon.define=function(b,c){var d=b.$id||b;d||u("warning: \u5fc5\u987b\u6307\u5b9a$id");la[d]&&u("warning: "+d+" \u5df2\u7ecf\u5b58\u5728\u4e8eavalon.vmodels\u4e2d");if("object"===typeof b)var e=K(b);else e={$watch:v},c(e),e=K(e),da=!0,c(e),da=!1;e.$id=d;return la[d]=e};var Ka="$id,$watch,$unwatch,$fire,$events,$model,$skipArray".match(w),fa=Object.is||function(b,c){return 0===b&&0===c?1/b===1/c:b!==b?c!==c:b===c},T={},ga=0,pa={},L,M,X,pb,bb,qb=/[-.*+?^${}()|[\]\/\\]/g, -A=v,O={loader:function(b){x.define=b?A.define:Xb;x.require=b?A:Wb},interpolate:function(b){L=b[0];M=b[1];L===M?avalon.error("openTag!==closeTag",SyntaxError):"\x3c!--,--\x3e"===b+""?s.commentInterpolate=!0:(b=L+"test"+M,ma.innerHTML=b,ma.innerHTML!==b&&0<=ma.innerHTML.indexOf("<")&&avalon.error("\u6b64\u5b9a\u754c\u7b26\u4e0d\u5408\u6cd5",SyntaxError),ma.innerHTML="");b=(L+"").replace(qb,"\\$&");var c=(M+"").replace(qb,"\\$&");X=RegExp(b+"(.*?)"+c);pb=RegExp(b+"(.*?)"+c,"g");bb=RegExp(b+".*?"+ -c+"|\\sms-")}};s.debug=!0;s.plugins=O;s.plugins.interpolate(["{{","}}"]);s.paths={};s.shim={};s.maxRepeatSize=100;avalon.config=s;"add,remove".replace(w,function(b){avalon.fn[b+"Class"]=function(c){var d=this[0];c&&("string"===typeof c&&d&&1===d.nodeType)&&c.replace(/\S+/g,function(c){d.classList[b](c)});return this}});avalon.fn.mix({hasClass:function(b){var c=this[0]||{};return 1===c.nodeType&&c.classList.contains(b)},toggleClass:function(b,c){for(var d,e=0,f=b.split(/\s+/),g="boolean"===typeof c;d= -f[e++];)this[(g?c:!this.hasClass(d))?"addClass":"removeClass"](d);return this},attr:function(b,c){return 2===arguments.length?(this[0].setAttribute(b,c),this):this[0].getAttribute(b)},data:function(b,c){b="data-"+Na(b||"");switch(arguments.length){case 2:return this.attr(b,c),this;case 1:var d=this.attr(b);return ia(d);case 0:var e={};N.forEach.call(this[0].attributes,function(c){c&&(b=c.name,b.indexOf("data-")||(b=ha(b.slice(5)),e[b]=ia(c.value)))});return e}},removeData:function(b){b="data-"+Na(b); -this[0].removeAttribute(b);return this},css:function(b,c){if(avalon.isPlainObject(b))for(var d in b)avalon.css(this,d,b[d]);else var e=avalon.css(this,b,c);return void 0!==e?e:this},position:function(){var b,c,d=this[0],e={top:0,left:0};if(d)return"fixed"===this.css("position")?c=d.getBoundingClientRect():(b=this.offsetParent(),c=this.offset(),"HTML"!==b[0].tagName&&(e=b.offset()),e.top+=avalon.css(b[0],"borderTopWidth",!0),e.left+=avalon.css(b[0],"borderLeftWidth",!0)),{top:c.top-e.top-avalon.css(d, -"marginTop",!0),left:c.left-e.left-avalon.css(d,"marginLeft",!0)}},offsetParent:function(){for(var b=this[0].offsetParent||D;b&&"HTML"!==b.tagName&&"static"===avalon.css(b,"position");)b=b.offsetParent;return avalon(b||D)},bind:function(b,c,d){if(this[0])return avalon.bind(this[0],b,c,d)},unbind:function(b,c,d){this[0]&&avalon.unbind(this[0],b,c,d);return this},val:function(b){var c=this[0];if(c&&1===c.nodeType){var d=0===arguments.length,e=d?":get":":set",f=Zb,g;g=c.tagName.toLowerCase();g="input"=== -g&&/checkbox|radio/.test(c.type)?"checked":g;if(e=f[g+e])var h=e(c,b);else{if(d)return(c.value||"").replace(/\r/g,"");c.value=b}}return d?h:this}});D.dataset&&(avalon.fn.data=function(b,c){var d=this[0].dataset;switch(arguments.length){case 2:return d[b]=c,this;case 1:return c=d[b],ia(c);case 0:var e={};for(b in d)e[b]=ia(d[b]);return e}});var zb=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/;avalon.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(b,c){avalon.fn[b]=function(d){var e=this[0]||{},f= -e.window&&e.document?e:9===e.nodeType?e.defaultView:!1,g="scrollTop"===b;if(arguments.length)f?f.scrollTo(!g?d:avalon(f).scrollLeft(),g?d:avalon(f).scrollTop()):e[b]=d;else return f?f[c]:e[b]}});var z=avalon.cssHooks={},rb=["","-webkit-","-moz-","-ms-"],Da={"float":"cssFloat"};avalon.cssNumber=J("columnCount,order,fillOpacity,fontWeight,lineHeight,opacity,orphans,widows,zIndex,zoom");avalon.cssName=function(b,c,d){if(Da[b])return Da[b];c=c||D.style;for(var e=0,f=rb.length;el&&(e=e-avalon.css(c,"border"+d[0]+"Width",!0)-avalon.css(c,"border"+d[1]+"Width",!0));-4===l&&(e= -e-avalon.css(c,"padding"+d[0],!0)-avalon.css(c,"padding"+d[1],!0));return e};z[c+"&get"]=function(b){var d=[];Oa(b,d);for(var e=z[c+":get"](b),f=0,m;m=d[f++];){b=m.node;for(var q in m)"string"===typeof m[q]&&(b.style[q]=m[q])}return e};avalon.fn[c]=function(g){var h=this[0];if(0===arguments.length){if(h.setTimeout)return h["inner"+b]||h.document.documentElement[d];if(9===h.nodeType){var k=h.documentElement;return Math.max(h.body[e],k[e],h.body[f],k[f],k[d])}return z[c+"&get"](h)}return this.css(c, -g)};avalon.fn["inner"+b]=function(){return z[c+":get"](this[0],void 0,-2)};avalon.fn["outer"+b]=function(b){return z[c+":get"](this[0],void 0,!0===b?2:0)}});avalon.fn.offset=function(){var b=this[0],c={left:0,top:0};if(!b||!b.tagName||!b.ownerDocument)return c;var d=b.ownerDocument,e=d.documentElement,d=d.defaultView;if(!e.contains(b))return c;void 0!==b.getBoundingClientRect&&(c=b.getBoundingClientRect());return{top:c.top+d.pageYOffset-e.clientTop,left:c.left+d.pageXOffset-e.clientLeft}};var Zb= -{"select:get":function(b,c){for(var d,e=b.options,f=b.selectedIndex,g="select-one"===b.type||0>f,h=g?null:[],k=g?f+1:e.length,l=0>f?k:g?f:0;l]*)\/>/ig,bc=J(["","text/javascript","text/ecmascript","application/ecmascript","application/javascript"]),cc=p.createElement("script");avalon.parseHTML=function(b){"string"!==typeof b&&(b+="");b=b.replace(ac,"<$1>").trim();var c=($b.exec(b)||["",""])[1].toLowerCase(),c=C[c]||C._default,d=H.cloneNode(!1);c.innerHTML=b;b=c.getElementsByTagName("script");if(b.length)for(var e=0,f;f=b[e++];)if(bc[f.type]){var g=cc.cloneNode(!1); -N.forEach.call(f.attributes,function(b){g.setAttribute(b.name,b.value)});g.text=f.text;f.parentNode.replaceChild(g,f)}for(;b=c.firstChild;)d.appendChild(b);return d};avalon.innerHTML=function(b,c){var d=this.parseHTML(c);this.clearHTML(b).appendChild(d)};avalon.clearHTML=function(b){for(b.textContent="";b.firstChild;)b.removeChild(b.firstChild);return b};var Q={$watch:function(b,c){if("function"===typeof c){var d=this.$events[b];d?d.push(c):this.$events[b]=[c]}else this.$events=this.$watch.backup; +"",h=c.map(function(b){return b.$id.replace(Lb,"$1")})+b+e+g,k=Mb(b).concat(),l=[],m=[],q=[],n="";d.vars=[];c=cb(c);for(var t=0,n=c.length;ts.maxRepeatSize&&$.pop()}b.length=0}function aa(){A?(r["ready!"].state=2,A.checkDeps()):lb.forEach(function(b){b(avalon)});aa=v}var B=Date.now(),F="$"+B,x=Function("return this")(),Wb=x.require,Xb=x.define,da=!1,w=/[^, ]+/g,La=/^(?:object|array)$/,mb=/^\[object SVG\w*Element\]$/,Yb=/^\[object (Window|DOMWindow|global)\]$/,Aa=Object.prototype,Ma=Aa.hasOwnProperty, +Ba=Aa.toString,N=Array.prototype,ja=N.slice,W={},G=p.head,D=p.documentElement,H=p.createDocumentFragment(),ma=p.createElement("div"),nb={};"Boolean Number String Function Array Date RegExp Object Error".replace(w,function(b){nb["[object "+b+"]"]=b.toLowerCase()});x.avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]=this.element=b};avalon.fn=avalon.prototype=avalon.init.prototype;avalon.isFunction=S;avalon.type=function(b){return null==b?String(b):"object"===typeof b||"function"=== +typeof b?nb[Ba.call(b)]||"object":typeof b};avalon.isWindow=function(b){return Yb.test(Ba.call(b))};avalon.isPlainObject=function(b){return!!b&&"object"===typeof b&&Object.getPrototypeOf(b)===Aa};avalon.mix=avalon.fn.mix=function(){var b,c,d,e,f,g=arguments[0]||{},h=1,k=arguments.length,l=!1;"boolean"===typeof g&&(l=g,g=arguments[1]||{},h++);"object"!==typeof g&&"function"!==avalon.type(g)&&(g={});h===k&&(g=this,h--);for(;h';if(!mb.test(ob.firstChild)){var Ca=function(b,c){if(b&&b.childNodes)for(var d=b.childNodes,e=0,f;f=d[e++];)if(f.tagName){var g=p.createElementNS("http://www.w3.org/2000/svg",f.tagName.toLowerCase());N.forEach.call(f.attributes,function(b){g.setAttribute(b.name,b.value)});Ca(f, +g);c.appendChild(g)}};Object.defineProperties(SVGElement.prototype,{outerHTML:{enumerable:!0,configurable:!0,get:function(){return(new XMLSerializer).serializeToString(this)},set:function(b){var c=this.tagName.toLowerCase(),d=this.parentNode;b=avalon.parseHTML(b);"svg"===c?d.insertBefore(b,this):(c=p.createDocumentFragment(),Ca(b,c),d.insertBefore(c,this));d.removeChild(this)}},innerHTML:{enumerable:!0,configurable:!0,get:function(){var b=RegExp("$","i");return this.outerHTML.replace(RegExp("<"+ +this.nodeName+'\\b(?:(["\'])[^"]*?(\\1)|[^>])*>',"i"),"").replace(b,"")},set:function(b){avalon.clearHTML&&(avalon.clearHTML(this),b=avalon.parseHTML(b),Ca(b,this))}}})}}var la=avalon.vmodels={};avalon.define=function(b,c){var d=b.$id||b;d||u("warning: \u5fc5\u987b\u6307\u5b9a$id");la[d]&&u("warning: "+d+" \u5df2\u7ecf\u5b58\u5728\u4e8eavalon.vmodels\u4e2d");if("object"===typeof b)var e=K(b);else e={$watch:v},c(e),e=K(e),da=!0,c(e),da=!1;e.$id=d;return la[d]=e};var Ka="$id,$watch,$unwatch,$fire,$events,$model,$skipArray".match(w), +fa=Object.is||function(b,c){return 0===b&&0===c?1/b===1/c:b!==b?c!==c:b===c},T={},ga=0,pa={},L,M,X,pb,bb,qb=/[-.*+?^${}()|[\]\/\\]/g,A=v,O={loader:function(b){x.define=b?A.define:Xb;x.require=b?A:Wb},interpolate:function(b){L=b[0];M=b[1];L===M?avalon.error("openTag!==closeTag",SyntaxError):"\x3c!--,--\x3e"===b+""?s.commentInterpolate=!0:(b=L+"test"+M,ma.innerHTML=b,ma.innerHTML!==b&&0<=ma.innerHTML.indexOf("<")&&avalon.error("\u6b64\u5b9a\u754c\u7b26\u4e0d\u5408\u6cd5",SyntaxError),ma.innerHTML= +"");b=(L+"").replace(qb,"\\$&");var c=(M+"").replace(qb,"\\$&");X=RegExp(b+"(.*?)"+c);pb=RegExp(b+"(.*?)"+c,"g");bb=RegExp(b+".*?"+c+"|\\sms-")}};s.debug=!0;s.plugins=O;s.plugins.interpolate(["{{","}}"]);s.paths={};s.shim={};s.maxRepeatSize=100;avalon.config=s;"add,remove".replace(w,function(b){avalon.fn[b+"Class"]=function(c){var d=this[0];c&&("string"===typeof c&&d&&1===d.nodeType)&&c.replace(/\S+/g,function(c){d.classList[b](c)});return this}});avalon.fn.mix({hasClass:function(b){var c=this[0]|| +{};return 1===c.nodeType&&c.classList.contains(b)},toggleClass:function(b,c){for(var d,e=0,f=b.split(/\s+/),g="boolean"===typeof c;d=f[e++];)this[(g?c:!this.hasClass(d))?"addClass":"removeClass"](d);return this},attr:function(b,c){return 2===arguments.length?(this[0].setAttribute(b,c),this):this[0].getAttribute(b)},data:function(b,c){b="data-"+Na(b||"");switch(arguments.length){case 2:return this.attr(b,c),this;case 1:var d=this.attr(b);return ia(d);case 0:var e={};N.forEach.call(this[0].attributes, +function(c){c&&(b=c.name,b.indexOf("data-")||(b=ha(b.slice(5)),e[b]=ia(c.value)))});return e}},removeData:function(b){b="data-"+Na(b);this[0].removeAttribute(b);return this},css:function(b,c){if(avalon.isPlainObject(b))for(var d in b)avalon.css(this,d,b[d]);else var e=avalon.css(this,b,c);return void 0!==e?e:this},position:function(){var b,c,d=this[0],e={top:0,left:0};if(d)return"fixed"===this.css("position")?c=d.getBoundingClientRect():(b=this.offsetParent(),c=this.offset(),"HTML"!==b[0].tagName&& +(e=b.offset()),e.top+=avalon.css(b[0],"borderTopWidth",!0),e.left+=avalon.css(b[0],"borderLeftWidth",!0)),{top:c.top-e.top-avalon.css(d,"marginTop",!0),left:c.left-e.left-avalon.css(d,"marginLeft",!0)}},offsetParent:function(){for(var b=this[0].offsetParent||D;b&&"HTML"!==b.tagName&&"static"===avalon.css(b,"position");)b=b.offsetParent;return avalon(b||D)},bind:function(b,c,d){if(this[0])return avalon.bind(this[0],b,c,d)},unbind:function(b,c,d){this[0]&&avalon.unbind(this[0],b,c,d);return this},val:function(b){var c= +this[0];if(c&&1===c.nodeType){var d=0===arguments.length,e=d?":get":":set",f=Zb,g;g=c.tagName.toLowerCase();g="input"===g&&/checkbox|radio/.test(c.type)?"checked":g;if(e=f[g+e])var h=e(c,b);else{if(d)return(c.value||"").replace(/\r/g,"");c.value=b}}return d?h:this}});D.dataset&&(avalon.fn.data=function(b,c){var d=this[0].dataset;switch(arguments.length){case 2:return d[b]=c,this;case 1:return c=d[b],ia(c);case 0:var e={};for(b in d)e[b]=ia(d[b]);return e}});var zb=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/;avalon.each({scrollLeft:"pageXOffset", +scrollTop:"pageYOffset"},function(b,c){avalon.fn[b]=function(d){var e=this[0]||{},f=e.window&&e.document?e:9===e.nodeType?e.defaultView:!1,g="scrollTop"===b;if(arguments.length)f?f.scrollTo(!g?d:avalon(f).scrollLeft(),g?d:avalon(f).scrollTop()):e[b]=d;else return f?f[c]:e[b]}});var z=avalon.cssHooks={},rb=["","-webkit-","-moz-","-ms-"],Da={"float":"cssFloat"};avalon.cssNumber=J("columnCount,order,fillOpacity,fontWeight,lineHeight,opacity,orphans,widows,zIndex,zoom");avalon.cssName=function(b,c,d){if(Da[b])return Da[b]; +c=c||D.style;for(var e=0,f=rb.length;el&&(e=e-avalon.css(c,"border"+d[0]+"Width", +!0)-avalon.css(c,"border"+d[1]+"Width",!0));-4===l&&(e=e-avalon.css(c,"padding"+d[0],!0)-avalon.css(c,"padding"+d[1],!0));return e};z[c+"&get"]=function(b){var d=[];Oa(b,d);for(var e=z[c+":get"](b),f=0,m;m=d[f++];){b=m.node;for(var q in m)"string"===typeof m[q]&&(b.style[q]=m[q])}return e};avalon.fn[c]=function(g){var h=this[0];if(0===arguments.length){if(h.setTimeout)return h["inner"+b]||h.document.documentElement[d];if(9===h.nodeType){var k=h.documentElement;return Math.max(h.body[e],k[e],h.body[f], +k[f],k[d])}return z[c+"&get"](h)}return this.css(c,g)};avalon.fn["inner"+b]=function(){return z[c+":get"](this[0],void 0,-2)};avalon.fn["outer"+b]=function(b){return z[c+":get"](this[0],void 0,!0===b?2:0)}});avalon.fn.offset=function(){var b=this[0],c={left:0,top:0};if(!b||!b.tagName||!b.ownerDocument)return c;var d=b.ownerDocument,e=d.documentElement,d=d.defaultView;if(!e.contains(b))return c;void 0!==b.getBoundingClientRect&&(c=b.getBoundingClientRect());return{top:c.top+d.pageYOffset-e.clientTop, +left:c.left+d.pageXOffset-e.clientLeft}};var Zb={"select:get":function(b,c){for(var d,e=b.options,f=b.selectedIndex,g="select-one"===b.type||0>f,h=g?null:[],k=g?f+1:e.length,l=0>f?k:g?f:0;l]*)\/>/ig,bc=J(["","text/javascript","text/ecmascript","application/ecmascript","application/javascript"]),cc=p.createElement("script");avalon.parseHTML=function(b){"string"!==typeof b&&(b+="");b=b.replace(ac,"<$1>").trim();var c=($b.exec(b)||["",""])[1].toLowerCase(),c=C[c]||C._default,d=H.cloneNode(!1);c.innerHTML=b;b=c.getElementsByTagName("script");if(b.length)for(var e=0,f;f=b[e++];)if(bc[f.type]){var g= +cc.cloneNode(!1);N.forEach.call(f.attributes,function(b){g.setAttribute(b.name,b.value)});g.text=f.text;f.parentNode.replaceChild(g,f)}for(;b=c.firstChild;)d.appendChild(b);return d};avalon.innerHTML=function(b,c){var d=this.parseHTML(c);this.clearHTML(b).appendChild(d)};avalon.clearHTML=function(b){for(b.textContent="";b.firstChild;)b.removeChild(b.firstChild);return b};var Q={$watch:function(b,c){if("function"===typeof c){var d=this.$events[b];d?d.push(c):this.$events[b]=[c]}else this.$events=this.$watch.backup; return this},$unwatch:function(b,c){var d=arguments.length;if(0===d)this.$watch.backup=this.$events,this.$events={};else if(1===d)this.$events[b]=[];else for(var d=this.$events[b]||[],e=d.length;0>~--e;)if(d[e]===c)return d.splice(e,1);return this},$fire:function(b){var c;/^(\w+)!(\S+)$/.test(b)&&(c=RegExp.$1,b=RegExp.$2);var d=this.$events,e=ja.call(arguments,1),f=[b].concat(e);if("all"===c)for(var g in avalon.vmodels)e=avalon.vmodels[g],e!==this&&e.$fire.apply(e,f);else if("up"===c||"down"===c){if(d= d.expr&&p.querySelector(d.expr)){for(g in avalon.vmodels)if(e=avalon.vmodels[g],e!==this&&e.$events.expr){var h=p.querySelector(e.$events.expr);if(h&&("down"===c?d.contains(h):h.contains(d)))h._avalon=e}g=p.getElementsByTagName("*");var k=[];Array.prototype.forEach.call(g,function(b){b._avalon&&(k.push(b._avalon),b._avalon="",b.removeAttribute("_avalon"))});"up"===c&&k.reverse();for(g=0;(c=k[g++])&&!1!==c.$fire.apply(c,f););}}else{f=d[b]||[];c=d.$all||[];for(g=0;d=f[g++];)S(d)&&d.apply(this,e);for(g= 0;d=c[g++];)S(d)&&d.apply(this,arguments)}}},Bb=/^(duplex|on)$/,R=[],ra=0,Cb=200,Sa=Date.now(),Ta,Ea={};avalon.scanCallback=function(b,c){c=c||"$all";(Ea[c]||(Ea[c]=[])).push(b)};avalon.scan=function(b,c,d){b=b||D;var e=Ea[d||"$all"]||[];c=c?[].concat(c):[];var f=0,g=!1,h,k=!1;c.cb=function(b){f+=b;k=!0;setTimeout(function(){if(0>=f&&!g)for(g=!0;h=e.shift();)h()})};Ua(b,c);if(!k)for(;h=e.shift();)h()};var Gb=J("AREA,BASE,BASEFONT,BR,COL,COMMAND,EMBED,HR,IMG,INPUT,LINK,META,PARAM,SOURCE,TRACK,WBR,NOSCRIPT,NOSCRIPT,SCRIPT,STYLE,TEXTAREA"), @@ -80,10 +80,10 @@ b.checked?"ensure":"remove",g=c();Array.isArray(g)||(u("ms-duplex\u5e94\u7528\u4 k.replace(w,function(b){switch(b){case "input":l("input",h);l("compositionstart",f);l("compositionend",g);break;default:l(b,h)}}));b.oldValue=b.value;tb(function(){if(avalon.contains(D,b))fb.call(b);else if(!b.msRetain)return!1});qa(d);e.call(b,b.value)};var gb,Z=[],tb=v;avalon.tick=function(b){1===Z.push(b)&&(gb=setInterval(Pb,60))};try{var ub=HTMLInputElement.prototype,Rb=Object.getOwnPropertyDescriptor(ub,"value").set;Object.defineProperty(ub,"value",{set:Qb,configurable:!0})}catch(oc){tb=avalon.tick}U.SELECT= function(b,c,d){var e=avalon(b);d.handler=function(){var d=c(),d=d&&d.$model||d;Array.isArray(d)?b.multiple||u("ms-duplex\u5728\u4e0d\u80fd\u5bf9\u5e94\u4e00\u4e2a\u6570\u7ec4");d=Array.isArray(d)?d.map(String):d+"";d+""!==b.oldValue&&(e.val(d),b.oldValue=d+"")};d.bound("change",function(){if(!1!==e.data("duplex-observe")){var f=e.val(),f=Array.isArray(f)?f.map(function(b){return d.pipe(b, d,"get")}):d.pipe(f,d,"get");f+""!==b.oldValue&&c(f);d.changed.call(b,f,d)}});ka(b,function(){qa(d);d.changed.call(b,c(),d)},NaN)};U.TEXTAREA=U.INPUT;var na=avalon.eventHooks;"onmouseenter"in D||avalon.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(b,c){na[b]={type:c,deel:function(c,e){return function(f){var g=f.relatedTarget;if(!g||g!==c&&!(c.compareDocumentPosition(g)&16))return delete f.type,f.type=b,e.call(c,f)}}}});avalon.each({AnimationEvent:"animationend",WebKitAnimationEvent:"webkitAnimationEnd"}, -function(b,c){x[b]&&!na.animationend&&(na.animationend={type:c})});void 0===p.onmousewheel&&(na.mousewheel={type:"wheel",deel:function(b,c){return function(d){d.wheelDeltaY=d.wheelDelta=0b?Math.max(d+b,0):Math.min(b,d);var d=Ia.apply(this.$model,arguments),e=[],f;this._stopFireLength=!0;d.length&&(e=this._del(b,d.length),f=!0);2b?Math.max(d+b,0):Math.min(b,d);var d=Ia.apply(this.$model,arguments),e=[],f;this._stopFireLength=!0;d.length&&(e=this._del(b,d.length), +f=!0);2]*>([\S\s]*?)<\/script\s*>/gim,jc=/\s+(on[^=\s]+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,kc=/<\w+\b(?:(["'])[^"]*?(\1)|[^>])*>/ig,lc={a:/\b(href)\=("javascript[^"]*"|'javascript[^']*')/ig,img:/\b(src)\=("javascript[^"]*"|'javascript[^']*')/ig, form:/\b(action)\=("javascript[^"]*"|'javascript[^']*')/ig},mc=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,nc=/([^\#-~| |!])/g,Ja=avalon.filters={uppercase:function(b){return b.toUpperCase()},lowercase:function(b){return b.toLowerCase()},truncate:function(b,c,d){c=c||30;d=void 0===d?"...":d;return b.length>c?b.slice(0,c-d.length)+d:String(b)},sanitize:x.toStaticHTML?toStaticHTML.bind(x):function(b){return b.replace(ic,"").replace(kc,function(b,d){var e=b.toLowerCase().match(/<(\w+)\s/);e&&(e=lc[e[1]])&&(b= From 26b77233a747dade571eee1d7106305f47f7d769 Mon Sep 17 00:00:00 2001 From: RubyLouvre Date: Thu, 20 Nov 2014 14:02:14 +0800 Subject: [PATCH 16/18] =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E5=B0=B1=E4=B8=8D=E8=A6=81=E8=BD=AC=E6=8D=A2=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- avalon.js | 3 +-- avalon.min.js | 52 ++++++++++++++++++++--------------------- avalon.modern.js | 2 +- avalon.modern.min.js | 34 +++++++++++++-------------- examples/avalon.shim.js | 23 +++++++++++------- 5 files changed, 59 insertions(+), 55 deletions(-) diff --git a/avalon.js b/avalon.js index ce444d720..10b98be90 100644 --- a/avalon.js +++ b/avalon.js @@ -1874,7 +1874,6 @@ var c = ronduplex.test(data.type) ? data : fn.apply(0, data.args) data.handler(c, data.element, data) } catch (e) { - console.log(fn + "") log("warning:exception throwed in [registerSubscriber] " + e) delete data.evaluator var node = data.element @@ -2465,7 +2464,7 @@ if (!assigns.length && dataType === "duplex") { return } - if (dataType !== "duplex") { + if (dataType !== "duplex" && (code.indexOf("||") > -1 || code.indexOf("&&") > -1)) { //https://github.com/RubyLouvre/avalon/issues/583 data.vars.forEach(function(v) { var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig") diff --git a/avalon.min.js b/avalon.min.js index 3c286466f..5b14ea8e0 100644 --- a/avalon.min.js +++ b/avalon.min.js @@ -6,36 +6,36 @@ d;f.$events=g;for(e in R)c=R[e],w||(c=c.bind(f)),f[e]=c;f.hasOwnProperty=functio return h}function Z(b,c,d){b="for(var "+b+"i=0,n = this.length; i < n; i++){"+c.replace("_","((i in this) && fn.call(scope,this[i],i,this))")+"}"+d;return Function("fn,scope",b)}function Za(b,c){try{for(;c=c.parentNode;)if(c===b)return!0;return!1}catch(d){return!1}}function $a(){return(new XMLSerializer).serializeToString(this)}function u(b){for(var c in b)if(O.call(b,c)){var d=b[c];if("function"===typeof u.plugins[c])u.plugins[c](d);else"object"===typeof u[c]?avalon.mix(u[c],d):u[c]=d}return this} function ab(b){return b.replace(/([a-z\d])([A-Z]+)/g,"$1-$2").toLowerCase()}function oa(b){return 0>b.indexOf("-")&&0>b.indexOf("_")?b:b.replace(/[-_][^-_]/g,function(b){return b.charAt(1).toUpperCase()})}function bb(b){if(!("classList"in b)){b.classList={node:b};for(var c in cb)b.classList[c.slice(1)]=cb[c]}return b.classList}function db(b){try{b="true"===b?!0:"false"===b?!1:"null"===b?null:+b+""===b?+b:$b.test(b)?avalon.parseJSON(b):b}catch(c){}return b}function eb(b,c){if(0>=b.offsetWidth){if(ac.test(x["@:get"](b, "display"))){var d={node:b},e;for(e in fb)d[e]=b.style[e],b.style[e]=fb[e];c.push(d)}(d=b.parentNode)&&1===d.nodeType&&eb(d,c)}}function gb(b){var c=b.nodeName;return c.toLowerCase()===c&&b.scopeName&&""===b.outerText}function bc(b){"url(#default#VML)"!==b.currentStyle.behavior&&(b.style.behavior="url(#default#VML)",b.style.display="inline-block",b.style.zoom=1)}function ya(b){Y[A]=b;avalon.openComputedCollect=!0;var c=b.evaluator;if(c)try{var d=cc.test(b.type)?b:c.apply(0,b.args);b.handler(d,b.element, -b)}catch(e){console.log(c+""),v("warning:exception throwed in [registerSubscriber] "+e),delete b.evaluator,c=b.element,3===c.nodeType&&(d=c.parentNode,u.commentInterpolate?d.replaceChild(p.createComment(b.value),c):c.data=P+b.value+Q)}avalon.openComputedCollect=!1;delete Y[A]}function ka(b){var c=Y[A];b&&(c&&avalon.Array.ensure(b,c)&&c.element)&&hb(c,b)}function hb(b,c){b.$uuid=b.$uuid||ha();c.$uuid=c.$uuid||ha();var d={data:b,list:c,toString:function(){return b.$uuid+" "+c.$uuid}};S[d]||(S[d]=1, -S.push(d))}function ib(){for(var b=za,c=za+dc;b"))&&ob(b,c)}}function Ca(b,c){b.length&&c.cb(b.length);for(var d=0,e;e=b[d++];)e.vmodels=c,C[e.type](e,c),e.evaluator&&(e.element&&1===e.element.nodeType)&&e.element.removeAttribute(e.name);b.length=0}function rb(b,c){0b&&delete c[d.shift()];return c[e]=f}var d=[];return c}function xb(b,c,d){var e=d.type,f=d.filters?d.filters.join(""):"",g=c.map(function(b){return String(b.$id).replace(oc,"$1")})+b+e+f,h=pc(b).concat(),k=[],l=[],m=[],n="";c=wb(c);d.vars=[];for(var q=0,n=c.length;q>0)-(d.clientLeft>>0),c.pageY=b.clientY+(d.scrollTop>>0)-(d.clientTop>>0),c.wheelDeltaY=c.wheelDelta,c.wheelDeltaX=0);c.timeStamp=new Date-0;c.originalEvent=b;c.preventDefault=function(){b.returnValue=!1};c.stopPropagation=function(){b.cancelBubble=!0};return c}function Xb(b){var c=[];c.$id=ha();c.$model=b;c.$events={};c.$events[G]=[];c._=N({length:b.length});c._.$watch("length",function(b,d){c.$fire("length",b,d)});for(var d in R)c[d]=R[d]; -avalon.mix(c,Ab);return c}function Bb(b,c,d,e){var f=avalon.parseHTML(b.template),g=avalon.slice(f.childNodes);c.appendChild(f);d.$outer=b.$outer;b=b.vmodels;d=[d].concat(b);d.cb=b.cb;e.push({nodes:g,vmodels:d})}function Ha(b,c){var d=b.endRepeat,e=[],f=b.element.nextSibling;if(f!==d){do if(f!==d)e.push(f);else break;while(f=f.nextSibling)}return e[b.group*c]||d}function Cb(b,c,d){c*=d||1;d=[b];for(var e=1,f=I;eu.maxRepeatSize&&da.pop()}b.length=0}function T(){p.body&&(D?(s["ready!"].state=2,D.checkDeps()):Fb.forEach(function(b){b(avalon)}), -T=y)}function Gb(){try{B.doScroll("left"),T()}catch(b){setTimeout(Gb)}}var A=new Date-0,G="$"+A,r=Function("return this")(),Ac=r.require,Bc=r.define,ja=!1,z=/[^, ]+/g,Hb=/\[native code\]/,wa=/^(?:object|array)$/,Ib=/^\[object SVG\w*Element\]$/,Vb=/^\[object (?:Window|DOMWindow|global)\]$/,Ia=Object.prototype,O=Ia.hasOwnProperty,ia=Ia.toString,L=Array.prototype,$=L.slice,Y={},w=r.dispatchEvent,B=p.documentElement,J=p.getElementsByTagName("head")[0],I=p.createDocumentFragment(),ea=p.createElement("div"), -Jb={};"Boolean Number String Function Array Date RegExp Object Error".replace(z,function(b){Jb["[object "+b+"]"]=b.toLowerCase()});avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]=this.element=b};avalon.fn=avalon.prototype=avalon.init.prototype;avalon.type=function(b){return null==b?String(b):"object"===typeof b||"function"===typeof b?Jb[ia.call(b)]||"object":typeof b};var V="object"===typeof alert?function(b){try{return/^\s*\bfunction\b/.test(b+"")}catch(c){return!1}}: -function(b){return"[object Function]"==ia.call(b)};avalon.isFunction=V;avalon.isWindow=function(b){return!b?!1:b==b.document&&b.document!=b};Ya(r)&&(avalon.isWindow=Ya);for(var Cc in avalon({}))break;var Dc="0"!==Cc;avalon.isPlainObject=function(b,c){if(!b||"object"!==avalon.type(b)||b.nodeType||avalon.isWindow(b))return!1;try{if(b.constructor&&!O.call(b,"constructor")&&!O.call(b.constructor.prototype,"isPrototypeOf"))return!1}catch(d){return!1}if(Dc)for(c in b)return O.call(b,c);for(c in b);return void 0=== -c||O.call(b,c)};Hb.test(Object.getPrototypeOf)&&(avalon.isPlainObject=function(b){return!!b&&"object"===typeof b&&Object.getPrototypeOf(b)===Ia});avalon.mix=avalon.fn.mix=function(){var b,c,d,e,f,g=arguments[0]||{},h=1,k=arguments.length,l=!1;"boolean"===typeof g&&(l=g,g=arguments[1]||{},h++);"object"!==typeof g&&"function"!==avalon.type(g)&&(g={});h===k&&(g=this,h--);for(;hb&&delete c[d.shift()];return c[e]=f}var d=[];return c}function xb(b,c,d){var e=d.type,f=d.filters?d.filters.join(""):"",g=c.map(function(b){return String(b.$id).replace(oc,"$1")})+b+e+f,h=pc(b).concat(),k=[],l=[],m=[],n="";c=wb(c);d.vars=[];for(var q=0,n=c.length;q>0)-(d.clientLeft>>0),c.pageY=b.clientY+(d.scrollTop>>0)-(d.clientTop>>0),c.wheelDeltaY=c.wheelDelta,c.wheelDeltaX=0);c.timeStamp=new Date-0;c.originalEvent=b;c.preventDefault=function(){b.returnValue=!1};c.stopPropagation=function(){b.cancelBubble=!0};return c}function Xb(b){var c=[];c.$id=ha();c.$model=b;c.$events={};c.$events[G]=[];c._=N({length:b.length});c._.$watch("length", +function(b,d){c.$fire("length",b,d)});for(var d in R)c[d]=R[d];avalon.mix(c,Ab);return c}function Bb(b,c,d,e){var f=avalon.parseHTML(b.template),g=avalon.slice(f.childNodes);c.appendChild(f);d.$outer=b.$outer;b=b.vmodels;d=[d].concat(b);d.cb=b.cb;e.push({nodes:g,vmodels:d})}function Ha(b,c){var d=b.endRepeat,e=[],f=b.element.nextSibling;if(f!==d){do if(f!==d)e.push(f);else break;while(f=f.nextSibling)}return e[b.group*c]||d}function Cb(b,c,d){c*=d||1;d=[b];for(var e=1,f=I;eu.maxRepeatSize&& +da.pop()}b.length=0}function T(){p.body&&(D?(s["ready!"].state=2,D.checkDeps()):Fb.forEach(function(b){b(avalon)}),T=y)}function Gb(){try{B.doScroll("left"),T()}catch(b){setTimeout(Gb)}}var A=new Date-0,G="$"+A,r=Function("return this")(),Ac=r.require,Bc=r.define,ja=!1,z=/[^, ]+/g,Hb=/\[native code\]/,wa=/^(?:object|array)$/,Ib=/^\[object SVG\w*Element\]$/,Vb=/^\[object (?:Window|DOMWindow|global)\]$/,Ia=Object.prototype,O=Ia.hasOwnProperty,ia=Ia.toString,L=Array.prototype,$=L.slice,Y={},w=r.dispatchEvent, +B=p.documentElement,J=p.getElementsByTagName("head")[0],I=p.createDocumentFragment(),ea=p.createElement("div"),Jb={};"Boolean Number String Function Array Date RegExp Object Error".replace(z,function(b){Jb["[object "+b+"]"]=b.toLowerCase()});avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]=this.element=b};avalon.fn=avalon.prototype=avalon.init.prototype;avalon.type=function(b){return null==b?String(b):"object"===typeof b||"function"===typeof b?Jb[ia.call(b)]||"object": +typeof b};var V="object"===typeof alert?function(b){try{return/^\s*\bfunction\b/.test(b+"")}catch(c){return!1}}:function(b){return"[object Function]"==ia.call(b)};avalon.isFunction=V;avalon.isWindow=function(b){return!b?!1:b==b.document&&b.document!=b};Ya(r)&&(avalon.isWindow=Ya);for(var Cc in avalon({}))break;var Dc="0"!==Cc;avalon.isPlainObject=function(b,c){if(!b||"object"!==avalon.type(b)||b.nodeType||avalon.isWindow(b))return!1;try{if(b.constructor&&!O.call(b,"constructor")&&!O.call(b.constructor.prototype, +"isPrototypeOf"))return!1}catch(d){return!1}if(Dc)for(c in b)return O.call(b,c);for(c in b);return void 0===c||O.call(b,c)};Hb.test(Object.getPrototypeOf)&&(avalon.isPlainObject=function(b){return!!b&&"object"===typeof b&&Object.getPrototypeOf(b)===Ia});avalon.mix=avalon.fn.mix=function(){var b,c,d,e,f,g=arguments[0]||{},h=1,k=arguments.length,l=!1;"boolean"===typeof g&&(l=g,g=arguments[1]||{},h++);"object"!==typeof g&&"function"!==avalon.type(g)&&(g={});h===k&&(g=this,h--);for(;h 0 Then","\t\t["+b+'] = [__proxy__]([__data__],"'+b+'")',"\tEnd If","\tOn Error Goto 0","\tEnd Property");f.push("End Class");b=f.join("\r\n"); b=r.findOrDefineVBClass(e,b);b===e&&r.parseVB(["Function "+e+"Factory(a, b)","\tDim o","\tSet o = (New "+e+")(a, b)","\tSet "+e+"Factory = o","End Function"].join("\r\n"));return r[b+"Factory"](c,Ec)}}if(!"\u53f8\u5f92\u6b63\u7f8e".trim){var Fc=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;String.prototype.trim=function(){return this.replace(Fc,"")}}var Gc=!{toString:null}.propertyIsEnumerable("toString"),Hc=function(){}.propertyIsEnumerable("prototype"),Kb="toString toLocaleString valueOf hasOwnProperty isPrototypeOf propertyIsEnumerable constructor".split(" "), diff --git a/avalon.modern.js b/avalon.modern.js index aee5ce66b..29a82bb14 100644 --- a/avalon.modern.js +++ b/avalon.modern.js @@ -1864,7 +1864,7 @@ if (!assigns.length && isDuplex) { return } - if (!isDuplex) { + if (!isDuplex && (code.indexOf("||") > -1 || code.indexOf("&&") > -1)) { //https://github.com/RubyLouvre/avalon/issues/583 data.vars.forEach(function(v) { var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig") diff --git a/avalon.modern.min.js b/avalon.modern.min.js index 0a851449a..dcc26e999 100644 --- a/avalon.modern.min.js +++ b/avalon.modern.min.js @@ -14,23 +14,23 @@ e)};e.length&&(f.filters=e);e=[f]}else e=ua(b.data);if(e.length){for(var g=0;f=e l&&(b.msData=b.msData||f)))}f["ms-checked"]&&f["ms-duplex"]&&u("warning!\u4e00\u4e2a\u5143\u7d20\u4e0a\u4e0d\u80fd\u540c\u65f6\u5b9a\u4e49ms-checked\u4e0ems-duplex");e.sort(function(b,c){return b.priority-c.priority});d=e[0]||{};switch(d.type){case "if":case "repeat":case "widget":va([d],c);break;default:va(e,c),!Gb[b.tagName]&&bb.test(b.innerHTML+b.textContent)&&Xa(b,c)}}function va(b,c){b.length&&c.cb(b.length);for(var d=0,e;e=b[d++];)e.vmodels=c,y[e.type](e,c),e.evaluator&&(e.element&&1===e.element.nodeType)&& e.element.removeAttribute(e.name);b.length=0}function $a(b,c){0b&&delete c[d.shift()];return c[e]=f}var d=[];return c}function eb(b,c,d){var e=d.type,f="duplex"===e,g=d.filters?d.filters.join(""): -"",h=c.map(function(b){return b.$id.replace(Lb,"$1")})+b+e+g,k=Mb(b).concat(),l=[],m=[],q=[],n="";d.vars=[];c=cb(c);for(var t=0,n=c.length;ts.maxRepeatSize&&$.pop()}b.length=0}function aa(){A?(r["ready!"].state=2,A.checkDeps()):lb.forEach(function(b){b(avalon)});aa=v}var B=Date.now(),F="$"+B,x=Function("return this")(),Wb=x.require,Xb=x.define,da=!1,w=/[^, ]+/g,La=/^(?:object|array)$/,mb=/^\[object SVG\w*Element\]$/,Yb=/^\[object (Window|DOMWindow|global)\]$/,Aa=Object.prototype,Ma=Aa.hasOwnProperty, -Ba=Aa.toString,N=Array.prototype,ja=N.slice,W={},G=p.head,D=p.documentElement,H=p.createDocumentFragment(),ma=p.createElement("div"),nb={};"Boolean Number String Function Array Date RegExp Object Error".replace(w,function(b){nb["[object "+b+"]"]=b.toLowerCase()});x.avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]=this.element=b};avalon.fn=avalon.prototype=avalon.init.prototype;avalon.isFunction=S;avalon.type=function(b){return null==b?String(b):"object"===typeof b||"function"=== -typeof b?nb[Ba.call(b)]||"object":typeof b};avalon.isWindow=function(b){return Yb.test(Ba.call(b))};avalon.isPlainObject=function(b){return!!b&&"object"===typeof b&&Object.getPrototypeOf(b)===Aa};avalon.mix=avalon.fn.mix=function(){var b,c,d,e,f,g=arguments[0]||{},h=1,k=arguments.length,l=!1;"boolean"===typeof g&&(l=g,g=arguments[1]||{},h++);"object"!==typeof g&&"function"!==avalon.type(g)&&(g={});h===k&&(g=this,h--);for(;h';if(!mb.test(ob.firstChild)){var Ca=function(b,c){if(b&&b.childNodes)for(var d=b.childNodes,e=0,f;f=d[e++];)if(f.tagName){var g=p.createElementNS("http://www.w3.org/2000/svg",f.tagName.toLowerCase());N.forEach.call(f.attributes,function(b){g.setAttribute(b.name,b.value)});Ca(f, -g);c.appendChild(g)}};Object.defineProperties(SVGElement.prototype,{outerHTML:{enumerable:!0,configurable:!0,get:function(){return(new XMLSerializer).serializeToString(this)},set:function(b){var c=this.tagName.toLowerCase(),d=this.parentNode;b=avalon.parseHTML(b);"svg"===c?d.insertBefore(b,this):(c=p.createDocumentFragment(),Ca(b,c),d.insertBefore(c,this));d.removeChild(this)}},innerHTML:{enumerable:!0,configurable:!0,get:function(){var b=RegExp("$","i");return this.outerHTML.replace(RegExp("<"+ +"",h=c.map(function(b){return b.$id.replace(Lb,"$1")})+b+e+g,k=Mb(b).concat(),l=[],m=[],q=[],n="";d.vars=[];c=cb(c);for(var t=0,n=c.length;ts.maxRepeatSize&&$.pop()}b.length=0}function aa(){A?(r["ready!"].state=2,A.checkDeps()):lb.forEach(function(b){b(avalon)});aa=v}var B=Date.now(),F="$"+B,x=Function("return this")(),Wb=x.require,Xb=x.define,da=!1,w=/[^, ]+/g,La=/^(?:object|array)$/,mb=/^\[object SVG\w*Element\]$/,Yb=/^\[object (Window|DOMWindow|global)\]$/, +Aa=Object.prototype,Ma=Aa.hasOwnProperty,Ba=Aa.toString,N=Array.prototype,ja=N.slice,W={},G=p.head,D=p.documentElement,H=p.createDocumentFragment(),ma=p.createElement("div"),nb={};"Boolean Number String Function Array Date RegExp Object Error".replace(w,function(b){nb["[object "+b+"]"]=b.toLowerCase()});x.avalon=function(b){return new avalon.init(b)};avalon.init=function(b){this[0]=this.element=b};avalon.fn=avalon.prototype=avalon.init.prototype;avalon.isFunction=S;avalon.type=function(b){return null== +b?String(b):"object"===typeof b||"function"===typeof b?nb[Ba.call(b)]||"object":typeof b};avalon.isWindow=function(b){return Yb.test(Ba.call(b))};avalon.isPlainObject=function(b){return!!b&&"object"===typeof b&&Object.getPrototypeOf(b)===Aa};avalon.mix=avalon.fn.mix=function(){var b,c,d,e,f,g=arguments[0]||{},h=1,k=arguments.length,l=!1;"boolean"===typeof g&&(l=g,g=arguments[1]||{},h++);"object"!==typeof g&&"function"!==avalon.type(g)&&(g={});h===k&&(g=this,h--);for(;h';if(!mb.test(ob.firstChild)){var Ca=function(b,c){if(b&&b.childNodes)for(var d=b.childNodes,e=0,f;f=d[e++];)if(f.tagName){var g=p.createElementNS("http://www.w3.org/2000/svg",f.tagName.toLowerCase());N.forEach.call(f.attributes,function(b){g.setAttribute(b.name, +b.value)});Ca(f,g);c.appendChild(g)}};Object.defineProperties(SVGElement.prototype,{outerHTML:{enumerable:!0,configurable:!0,get:function(){return(new XMLSerializer).serializeToString(this)},set:function(b){var c=this.tagName.toLowerCase(),d=this.parentNode;b=avalon.parseHTML(b);"svg"===c?d.insertBefore(b,this):(c=p.createDocumentFragment(),Ca(b,c),d.insertBefore(c,this));d.removeChild(this)}},innerHTML:{enumerable:!0,configurable:!0,get:function(){var b=RegExp("$","i");return this.outerHTML.replace(RegExp("<"+ this.nodeName+'\\b(?:(["\'])[^"]*?(\\1)|[^>])*>',"i"),"").replace(b,"")},set:function(b){avalon.clearHTML&&(avalon.clearHTML(this),b=avalon.parseHTML(b),Ca(b,this))}}})}}var la=avalon.vmodels={};avalon.define=function(b,c){var d=b.$id||b;d||u("warning: \u5fc5\u987b\u6307\u5b9a$id");la[d]&&u("warning: "+d+" \u5df2\u7ecf\u5b58\u5728\u4e8eavalon.vmodels\u4e2d");if("object"===typeof b)var e=K(b);else e={$watch:v},c(e),e=K(e),da=!0,c(e),da=!1;e.$id=d;return la[d]=e};var Ka="$id,$watch,$unwatch,$fire,$events,$model,$skipArray".match(w), fa=Object.is||function(b,c){return 0===b&&0===c?1/b===1/c:b!==b?c!==c:b===c},T={},ga=0,pa={},L,M,X,pb,bb,qb=/[-.*+?^${}()|[\]\/\\]/g,A=v,O={loader:function(b){x.define=b?A.define:Xb;x.require=b?A:Wb},interpolate:function(b){L=b[0];M=b[1];L===M?avalon.error("openTag!==closeTag",SyntaxError):"\x3c!--,--\x3e"===b+""?s.commentInterpolate=!0:(b=L+"test"+M,ma.innerHTML=b,ma.innerHTML!==b&&0<=ma.innerHTML.indexOf("<")&&avalon.error("\u6b64\u5b9a\u754c\u7b26\u4e0d\u5408\u6cd5",SyntaxError),ma.innerHTML= "");b=(L+"").replace(qb,"\\$&");var c=(M+"").replace(qb,"\\$&");X=RegExp(b+"(.*?)"+c);pb=RegExp(b+"(.*?)"+c,"g");bb=RegExp(b+".*?"+c+"|\\sms-")}};s.debug=!0;s.plugins=O;s.plugins.interpolate(["{{","}}"]);s.paths={};s.shim={};s.maxRepeatSize=100;avalon.config=s;"add,remove".replace(w,function(b){avalon.fn[b+"Class"]=function(c){var d=this[0];c&&("string"===typeof c&&d&&1===d.nodeType)&&c.replace(/\S+/g,function(c){d.classList[b](c)});return this}});avalon.fn.mix({hasClass:function(b){var c=this[0]|| diff --git a/examples/avalon.shim.js b/examples/avalon.shim.js index 085675a2b..72f225ce4 100644 --- a/examples/avalon.shim.js +++ b/examples/avalon.shim.js @@ -1639,7 +1639,7 @@ col: [2, "
", "
"], legend: [1, "
"], option: [1, "