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 } }