avalon-rails 1.4.1.1.20150404164109 → 1.4.6.0.20150915133100

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
- !function(e,t){"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("Avalon requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(e,t){function n(){e.console&&avalon.config.debug&&Function.apply.call(console.log,console,arguments)}function r(){}function i(e,t){"string"==typeof e&&(e=e.match(_t)||[]);for(var n={},r=void 0!==t?t:1,a=0,i=e.length;i>a;a++)n[e[a]]=r;return n}function o(){if(e.VBArray){var t=document.documentMode;return t?t:e.XMLHttpRequest?7:6}return 0}function l(e){return Lt.test(Pt.call(e))}function s(e,t){return e=Math.floor(e)||0,0>e?Math.max(t+e,0):Math.min(e,t)}function c(e){if(!e)return!1;var t=e.length;if(t===t>>>0){var n=Pt.call(e).slice(8,-1);if(/(?:regexp|string|function|window|global)$/i.test(n))return!1;if("Array"===n)return!0;try{return{}.propertyIsEnumerable.call(e,"length")===!1?/^\s?function/.test(e.item||e.callee):!0}catch(r){return!e.window}}return!1}function u(e,t,n){var r="for(var "+e+"i=0,n = this.length; i < n; i++){"+t.replace("_","((i in this) && fn.call(scope,this[i],i,this))")+"}"+n;return Function("fn,scope",r)}function f(e,t){try{for(;t=t.parentNode;)if(t===e)return!0;return!1}catch(n){return!1}}function p(){return(new XMLSerializer).serializeToString(this)}function d(e,t){if(e&&e.childNodes)for(var n,r=e.childNodes,a=0;n=r[a++];)if(n.tagName){var i=$t.createElementNS(an,n.tagName.toLowerCase());Dt.forEach.call(n.attributes,function(e){i.setAttribute(e.name,e.value)}),d(n,i),t.appendChild(i)}}function v(e){var t={};for(var n in e)t[n]=e[n];var r=t.target=e.srcElement;if(0===e.type.indexOf("key"))t.which=null!=e.charCode?e.charCode:e.keyCode;else if(ln.test(e.type)){var a=r.ownerDocument||$t,i="BackCompat"===a.compatMode?a.body:a.documentElement;t.pageX=e.clientX+(i.scrollLeft>>0)-(i.clientLeft>>0),t.pageY=e.clientY+(i.scrollTop>>0)-(i.clientTop>>0),t.wheelDeltaY=t.wheelDelta,t.wheelDeltaX=0}return t.timeStamp=new Date-0,t.originalEvent=e,t.preventDefault=function(){e.returnValue=!1},t.stopPropagation=function(){e.cancelBubble=!0},t}function h(e){for(var t in e)if(Ht.call(e,t)){var n=e[t];"function"==typeof h.plugins[t]?h.plugins[t](n):"object"==typeof h[t]?avalon.mix(h[t],n):h[t]=n}return this}function m(e){return(e+"").replace(mn,"\\$&")}function g(e,t,n){if(Xt(t)||t&&t.nodeType)return!1;if(-1!==n.indexOf(e))return!1;if(-1!==wn.indexOf(e))return!1;var r=n.$special;return e&&"$"===e.charAt(0)&&!r[e]?!1:!0}function y(e,t,n,r){switch(e.type){case 0:var a=e.get,i=e.set;if(Xt(i)){var o=r.$events,l=o[t];o[t]=[],i.call(r,n),o[t]=l}return a.call(r);case 1:return n;case 2:if(n!==r.$model[t]){var s=e.svmodel=$(r,t,n,e.valueType);n=s.$model;var c=Cn[s.$id];c&&c()}return n}}function b(e,t,n){if(Array.isArray(e)){var a=e.concat();e.length=0;var i=C(e);return i.pushArray(a),i}if(!e||e.nodeType>0||e.$id&&e.$events)return e;Array.isArray(e.$skipArray)||(e.$skipArray=[]),e.$skipArray.$special=t||{};var o={};n=n||{};var l={},s={},c=[];for(var u in e)!function(t,a){if(n[t]=a,g(t,a,e.$skipArray)){l[t]=[];var i=avalon.type(a),u=function(e){var t=u._name,n=this,r=n.$model,a=r[t],i=n.$events;return arguments.length?void(Ot||(1===u.type||(e=y(u,t,e,n),u.type))&&(Mn(a,e)||(r[t]=e,S(i[t]),x(n,t,e,a)))):0===u.type?(e=u.get.call(n),a!==e&&(r[t]=e,x(n,t,e,a)),e):(k(i[t]),u.svmodel||a)};"object"===i&&Xt(a.get)&&Object.keys(a).length<=2?(u.set=a.set,u.get=a.get,u.type=0,c.push(function(){var e={evaluator:function(){e.type=Math.random(),e.element=null,n[t]=u.get.call(o)},element:wt,type:Math.random(),handler:r,args:[]};Bt[xt]=e,u.call(o),delete Bt[xt]})):Nt.test(i)?(u.type=2,u.valueType=i,c.push(function(){var e=b(a,0,n[t]);u.svmodel=e,e.$events[At]=l[t]})):u.type=1,u._name=t,s[t]=u}}(u,e[u]);wn.forEach(function(t){delete e[t],delete n[t]}),o=An(o,On(s),e);for(var f in e)s[f]||(o[f]=e[f]);o.$id=qt(),o.$model=n,o.$events=l;for(u in xn){var p=xn[u];It||(p=p.bind(o)),o[u]=p}return En?Object.defineProperty(o,"hasOwnProperty",{value:function(e){return e in this.$model},writable:!1,enumerable:!1,configurable:!0}):o.hasOwnProperty=function(e){return e in o.$model},c.forEach(function(e){e()}),o}function x(e,t,n,r){e.$events&&xn.$fire.call(e,t,n,r)}function $(e,t,n,r){var a=e[t];if("array"===r)return Array.isArray(n)&&a!==n?(a._.$unwatch(),a.clear(),a._.$watch(),a.pushArray(n.concat()),a):a;var i=e.$events[t],o=a.$events.$withProxyPool;o&&(mt(o,"with"),a.$events.$withProxyPool=null);var l=b(n);return l.$events[At]=i,Cn[l.$id]=function(e){for(;e=i.shift();)!function(e){avalon.nextTick(function(){var t=e.type;t&&Jt[t]&&(e.rollback&&e.rollback(),Jt[t](e,e.vmodels))})}(e);delete Cn[l.$id]},l}function w(e,t,n,r){var a=t[n];return 4!==arguments.length?a.call(e):void a.call(e,r)}function C(e){var t=[];t.$id=qt(),t.$model=e,t.$events={},t.$events[At]=[],t._=b({length:e.length}),t._.$watch("length",function(e,n){t.$fire("length",e,n)});for(var n in xn)t[n]=xn[n];return avalon.mix(t,Nn),t}function T(e,t,n,r,a,i,o){for(var l=this.length,s=2;--s;){switch(e){case"add":var c=this.$model.slice(t,t+n).map(function(e){return Nt.test(avalon.type(e))?e.$id?e:b(e,0,e):e});_n.apply(this,[t,0].concat(c)),this._fire("add",t,n);break;case"del":var u=this._splice(t,n);this._fire("del",t,n)}a&&(e=a,t=i,n=o,s=2,a=0)}return this._fire("index",r),this.length!==l&&(this._.length=this.length),u}function E(e,t){for(var n={},r=0,a=t.length;a>r;r++){n[r]=e[r];var i=t[r];i in n?(e[r]=n[i],delete n[i]):e[r]=e[i]}}function A(e){Bt[xt]=e,avalon.openComputedCollect=!0;var t=e.evaluator;if(t)try{var n=Sn.test(e.type)?e:t.apply(0,e.args);e.handler(n,e.element,e)}catch(r){delete e.evaluator;var a=e.element;if(3===a.nodeType){var i=a.parentNode;h.commentInterpolate?i.replaceChild($t.createComment(e.value),a):a.data=fn+e.value+pn}}avalon.openComputedCollect=!1,delete Bt[xt]}function k(e){var t=Bt[xt];e&&t&&avalon.Array.ensure(e,t)&&t.element&&M(t,e)}function M(e,t){e.$uuid=e.$uuid||qt(),t.$uuid=t.$uuid||qt();var n={data:e,list:t,$$uuid:e.$uuid+t.$uuid};Ln[n.$$uuid]||(Ln[n.$$uuid]=1,Ln.push(n))}function O(e){e.element=null,e.rollback&&e.rollback();for(var t in e)e[t]=null}function _(e){try{if(!e.parentNode)return!0}catch(t){return!0}return e.msRetain?0:1===e.nodeType?"number"==typeof e.sourceIndex?0===e.sourceIndex:!Rt.contains(e):!avalon.contains(Rt,e)}function N(){for(var e,t=Ln.length,n=t,r=0,a=[],i={},o={};e=Ln[--t];){var l=e.data,s=l.type;i[s]?i[s]++:(i[s]=1,a.push(s))}var c=!1;if(a.forEach(function(e){Hn[e]!==i[e]&&(o[e]=1,c=!0)}),t=n,c)for(;e=Ln[--t];)l=e.data,void 0!==l.element&&o[l.type]&&_(l.element)&&(r++,Ln.splice(t,1),delete Ln[e.$$uuid],avalon.Array.remove(e.list,l),O(l),e.data=e.list=null);Hn=i,jn=new Date}function S(e){if(e&&e.length){new Date-jn>444&&"object"==typeof e[0]&&N();for(var t,n=Ft.call(arguments,1),a=e.length;t=e[--a];){var i=t.element;if(i&&i.parentNode)if(t.$repeat)t.handler.apply(t,n);else if("on"!==t.type){var o=t.evaluator||r;t.handler(o.apply(0,t.args||[]),i,t)}}}}function L(e){var t=e.nodeName;return t.toLowerCase()===t&&e.scopeName&&""===e.outerText}function j(e){"url(#default#VML)"!==e.currentStyle.behavior&&(e.style.behavior="url(#default#VML)",e.style.display="inline-block",e.style.zoom=1)}function H(e,t,n){var r=setTimeout(function(){var a=e.innerHTML;clearTimeout(r),a===n?t():H(e,t,a)})}function P(e,t){var n=e.getAttribute("avalonctrl")||t.$id;e.setAttribute("avalonctrl",n),t.$events.expr=e.tagName+'[avalonctrl="'+n+'"]'}function D(e,t){for(var n,r=0;n=e[r++];)n.vmodels=t,Jt[n.type](n,t),n.evaluator&&n.element&&1===n.element.nodeType&&n.element.removeAttribute(n.name);e.length=0}function F(e,t){return e.priority-t.priority}function B(e,t){for(var r,a,i=ar?ar(e):avalon.slice(e.attributes),o=[],l={},s=0;a=i[s++];)if(a.specified&&(r=a.name.match(Xn))){var c=r[1],u=r[2]||"",f=a.value,p=a.name;if(l[p]=f,Gn[c]?(u=c,c="on"):Jn[c]&&(n("warning!请改用ms-attr-"+c+"代替ms-"+c+"!"),"enabled"===c&&(n("warning!ms-enabled或ms-attr-enabled已经被废弃"),c="disabled",f="!("+f+")"),u=c,c="attr",e.removeAttribute(p),p="ms-attr-"+u,e.setAttribute(p,f),r=[p],l[p]=f),"function"==typeof Jt[c]){var d={type:c,param:u,element:e,name:r[0],value:f,priority:c in Yn?Yn[c]:10*c.charCodeAt(0)+(Number(u)||0)};if("html"===c||"text"===c){var v=W(f);avalon.mix(d,v),d.filters=d.filters.replace(ir,function(){return d.type="html",d.group=1,""})}"ms-if-loop"===p&&(d.priority+=100),t.length&&(o.push(d),"widget"===c&&(e.msData=e.msData||l))}}o.sort(F);var h=e.type;h&&l["ms-duplex"]&&(l["ms-attr-checked"]&&/radio|checkbox/.test(h)&&n("warning!"+h+"控件不能同时定义ms-attr-checked与ms-duplex"),l["ms-attr-value"]&&/text|password/.test(h)&&n("warning!"+h+"控件不能同时定义ms-attr-value与ms-duplex"));var m=!0;for(s=0;d=o[s];s++){if(c=d.type,Zn.test(c))return D(o.slice(0,s+1),t);m&&(m=!Qn.test(c))}D(o,t),m&&!Wn[e.tagName]&&hn.test(e.innerHTML.replace(lr,"<").replace(sr,">"))&&(zn&&zn(e),I(e,t))}function I(e,t){for(var n=e.firstChild;n;){var r=n.nextSibling;V(n,n.nodeType,t),n=r}}function R(e,t){for(var n,r=0;n=e[r++];)V(n,n.nodeType,t)}function V(e,t,n){1===t?U(e,n):3===t&&dn.test(e.data)?z(e,n):h.commentInterpolate&&8===t&&!dn.test(e.nodeValue)&&z(e,n)}function U(e,t,r){var a=e.getAttribute("ms-skip");if(!e.getAttributeNode)return n("warning "+e.tagName+" no getAttributeNode method");var i=e.getAttributeNode("ms-important"),o=e.getAttributeNode("ms-controller");if("string"!=typeof a){if(r=i||o){var l=avalon.vmodels[r.value];if(!l)return;t=r===i?[l]:[l].concat(t);var s=r.name;e.removeAttribute(s),avalon(e).removeClass(s),P(e,l)}B(e,t)}}function W(e){if(e.indexOf("|")>0){var t=e.replace(rstringLiteral,function(e){return Array(e.length+1).join("1")}),n=t.replace(or,"ᄢ㍄").indexOf("|");if(n>-1)return{filters:e.slice(n),value:e.slice(0,n),expr:!0}}return{value:e,filters:"",expr:!0}}function q(e){for(var t,n,r=[],a=0;;){if(n=e.indexOf(fn,a),-1===n)break;if(t=e.slice(a,n),t&&r.push({value:t,filters:"",expr:!1}),a=n+fn.length,n=e.indexOf(pn,a),-1===n)break;t=e.slice(a,n),t&&r.push(W(t)),a=n+pn.length}return t=e.slice(a),t&&r.push({value:t,expr:!1,filters:""}),r}function z(e,t){var n=[];if(8===e.nodeType)var r=W(e.nodeValue),a=[r];else a=q(e.data);if(a.length){for(var i=0;r=a[i++];){var o=$t.createTextNode(r.value);r.expr&&(r.type="text",r.element=o,r.filters=r.filters.replace(ir,function(){return r.type="html",r.group=1,""}),n.push(r)),Vt.appendChild(o)}e.parentNode.replaceChild(Vt,e),n.length&&D(n,t)}}function X(e){return e.replace(/([a-z\d])([A-Z]+)/g,"$1-$2").toLowerCase()}function Y(e){return e.indexOf("-")<0&&e.indexOf("_")<0?e:e.replace(/[-_][^-_]/g,function(e){return e.charAt(1).toUpperCase()})}function G(e){if(!("classList"in e)){e.classList={node:e};for(var t in cr)e.classList[t.slice(1)]=cr[t]}return e.classList}function J(e){try{if("object"==typeof e)return e;e="true"===e?!0:"false"===e?!1:"null"===e?null:+e+""===e?+e:ur.test(e)?avalon.parseJSON(e):e}catch(t){}return e}function Z(e){return e.window&&e.document?e:9===e.nodeType?e.defaultView||e.parentWindow:!1}function Q(e,t){if(e.offsetWidth<=0){if(Er.test(hr["@:get"](e,"display"))){var n={node:e};for(var r in Tr)n[r]=e.style[r],e.style[r]=Tr[r];t.push(n)}var a=e.parentNode;a&&1===a.nodeType&&Q(a,t)}}function K(e){var t=e.tagName.toLowerCase();return"input"===t&&/checkbox|radio/.test(e.type)?"checked":t}function et(e,t,n,r){for(var a,i=[],o=" = "+n+".",l=e.length;a=e[--l];)t.hasOwnProperty(a)&&(i.push(a+o+a),r.vars.push(a),"duplex"===r.type&&(e.get=n+"."+a),e.splice(l,1));return i}function tt(e){for(var t=[],n={},r=0;r<e.length;r++){var a=e[r],i=a&&"string"==typeof a.$id?a.$id:a;n[i]||(n[i]=t.push(a))}return t}function nt(e,t){return t=t.replace(Rr,"").replace(Vr,function(){return"],|"}).replace(Ur,function(e,t){return"["+Or(t)}).replace(Wr,function(){return'"],["'}).replace(qr,function(){return'",'})+"]","return avalon.filters.$filter("+e+", "+t+")"}function rt(e,t,a){var i=a.type,o=a.filters||"",l=t.map(function(e){return String(e.$id).replace(Ir,"$1")})+e+i+o,s=Dr(e).concat(),c=[],u=[],f=[],p="";t=tt(t),a.vars=[];for(var d=0,v=t.length;v>d;d++)if(s.length){var h="vm"+xt+"_"+d;u.push(h),f.push(t[d]),c.push.apply(c,et(s,t[d],h,a))}if(c.length||"duplex"!==i){"duplex"!==i&&(e.indexOf("||")>-1||e.indexOf("&&")>-1)&&a.vars.forEach(function(t){var n=new RegExp("\\b"+t+"(?:\\.\\w+|\\[\\w+\\])+","ig");e=e.replace(n,function(n){var r=n.charAt(t.length),a=zt?e.slice(arguments[1]+n.length):RegExp.rightContext,i=/^\s*\(/.test(a);if("."===r||"["===r||i){var o="var"+String(Math.random()).replace(/^0\./,"");if(i){var l=n.split(".");if(l.length>2){var s=l.pop();return c.push(o+" = "+l.join(".")),o+"."+s}return n}return c.push(o+" = "+n),o}return n})}),a.args=f;var m=Fr.get(l);if(m)return void(a.evaluator=m);if(p=c.join(", "),p&&(p="var "+p),/\S/.test(o)){if(!/text|html/.test(a.type))throw Error("ms-"+a.type+"不支持过滤器");e="\nvar ret"+xt+" = "+e+";\r\n",e+=nt("ret"+xt,o)}else{if("duplex"===i){var g="'use strict';\nreturn function(vvv){\n "+p+";\n if(!arguments.length){\n return "+e+"\n }\n "+(Br.test(e)?e:s.get)+"= vvv;\n} ";try{m=Function.apply(r,u.concat(g)),a.evaluator=Fr.put(l,m)}catch(y){n("debug: parse error,"+y.message)}return}if("on"===i){-1===e.indexOf("(")?e+=".call(this, $event)":e=e.replace("(",".call(this,"),u.push("$event"),e="\nreturn "+e+";";var b=e.lastIndexOf("\nreturn"),x=e.slice(0,b),$=e.slice(b);e=x+"\n"+$}else e="\nreturn "+e+";"}try{m=Function.apply(r,u.concat("'use strict';\n"+p+e)),a.evaluator=Fr.put(l,m)}catch(y){n("debug: parse error,"+y.message)}finally{s=c=u=null}}}function at(e,t,n,r,a){Array.isArray(r)&&(e=r.map(function(e){return e.expr?"("+e.value+")":Or(e.value)}).join(" + ")),rt(e,t,n),n.evaluator&&!a&&(n.handler=Zt[n.handlerName||n.type],A(n))}function it(e,t,n){var r=e.templateCache&&e.templateCache[t];if(r){for(var a,i=$t.createDocumentFragment();a=r.firstChild;)i.appendChild(a);return i}return avalon.parseHTML(n)}function ot(e){return null==e?"":e}function lt(e,t,n){return t.param.replace(/\w+/g,function(r){var a=avalon.duplexHooks[r];a&&"function"==typeof a[n]&&(e=a[n](e,t))}),e}function st(){for(var e=na.length-1;e>=0;e--){var t=na[e];t()===!1&&na.splice(e,1)}na.length||clearInterval(ta)}function ct(e,t,n,r){var a=e.template.cloneNode(!0),i=avalon.slice(a.childNodes);n.$stamp&&a.insertBefore(n.$stamp,a.firstChild),t.appendChild(a);var o=[n].concat(e.vmodels),l={nodes:i,vmodels:o};r.push(l)}function ut(e,t){var n=e.proxies[t];return n?n.$stamp:e.element}function ft(e,t,n){for(;;){var r=t.previousSibling;if(!r)break;if(r.parentNode.removeChild(r),n&&n.call(r),r===e)break}}function pt(e){var t={$host:[],$outer:{},$stamp:1,$index:0,$first:!1,$last:!1,$remove:avalon.noop};t[e]={get:function(){return this.$host[this.$index]},set:function(e){this.$host.set(this.$index,e)}};var n={$last:1,$first:1,$index:1},r=b(t,n),a=r.$events;return a[e]=a.$first=a.$last=a.$index,r.$id=qt("$proxy$each"),r}function dt(e,t){for(var n,r=t.param||"el",a=0,i=oa.length;i>a;a++){var o=oa[a];o&&o.hasOwnProperty(r)&&(n=o,oa.splice(a,1))}n||(n=pt(r));var l=t.$repeat,s=l.length-1;return n.$index=e,n.$first=0===e,n.$last=e===s,n.$host=l,n.$outer=t.$outer,n.$stamp=t.clone.cloneNode(!1),n.$remove=function(){return l.removeAt(n.$index)},n}function vt(){var e=b({$key:"",$outer:{},$host:{},$val:{get:function(){return this.$host[this.$key]},set:function(e){this.$host[this.$key]=e}}},{$val:1});return e.$id=qt("$proxy$with"),e}function ht(e,t){var n=la.pop();n||(n=vt());var r=t.$repeat;return n.$key=e,n.$host=r,n.$outer=t.$outer,r.$events?n.$events.$val=r.$events[e]:n.$events={},n}function mt(e,t){var n="each"===t?oa:la;avalon.each(e,function(e,t){if(t.$events){for(var r in t.$events)Array.isArray(t.$events[r])&&(t.$events[r].forEach(function(e){"object"==typeof e&&O(e)}),t.$events[r].length=0);t.$host=t.$outer={},n.unshift(t)>h.maxRepeatSize&&n.pop()}}),"each"===t&&(e.length=0)}function gt(e,t){var n="_"+e;if(!gt[n]){var r=$t.createElement(e);Rt.appendChild(r),t=It?getComputedStyle(r,null).display:r.currentStyle.display,Rt.removeChild(r),gt[n]=t}return gt[n]}function yt(e,t,n,r){e=(e+"").replace(/[^0-9+\-Ee.]/g,"");var a=isFinite(+e)?+e:0,i=isFinite(+t)?Math.abs(t):3,o=r||",",l=n||".",s="",c=function(e,t){var n=Math.pow(10,t);return""+(Math.round(e*n)/n).toFixed(t)};return s=(i?c(a,i):""+Math.round(a)).split("."),s[0].length>3&&(s[0]=s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g,o)),(s[1]||"").length<i&&(s[1]=s[1]||"",s[1]+=new Array(i-s[1].length+1).join("0")),s.join(l)}function bt(){try{Rt.doScroll("left"),ba()}catch(e){setTimeout(bt)}}var xt=new Date-0,$t=e.document,wt=$t.getElementsByTagName("head")[0],Ct=wt.insertBefore(document.createElement("avalon"),wt.firstChild);Ct.innerHTML="X<style id='avalonStyle'>.avalonHide{ display: none!important }</style>",Ct.setAttribute("ms-skip","1"),Ct.className="avalonHide";var Tt,Et=/\[native code\]/,At="$"+xt,kt=e.require,Mt=e.define,Ot=!1,_t=/[^, ]+/g,Nt=/^(?:object|array)$/,St=/^\[object SVG\w*Element\]$/,Lt=/^\[object (?:Window|DOMWindow|global)\]$/,jt=Object.prototype,Ht=jt.hasOwnProperty,Pt=jt.toString,Dt=Array.prototype,Ft=Dt.slice,Bt={},It=e.dispatchEvent,Rt=$t.documentElement,Vt=$t.createDocumentFragment(),Ut=$t.createElement("div"),Wt={};"Boolean Number String Function Array Date RegExp Object Error".replace(_t,function(e){Wt["[object "+e+"]"]=e.toLowerCase()});var qt=function(e){return e=e||"avalon",(e+Math.random()+Math.random()).replace(/0\./g,"")},zt=o();avalon=function(e){return new avalon.init(e)},avalon.nextTick=new function(){function t(){for(var e=i.length,t=0;e>t;t++)i[t]();i=i.slice(e)}var n=e.setImmediate,r=e.MutationObserver,a=It&&e.postMessage;if(n)return n.bind(e);var i=[];if(r){var o=document.createTextNode("avalon");return new r(t).observe(o,{characterData:!0}),function(e){i.push(e),o.data=Math.random()}}return a?(e.addEventListener("message",function(n){var r=n.source;r!==e&&null!==r||"process-tick"!==n.data||(n.stopPropagation(),t())}),function(t){i.push(t),e.postMessage("process-tick","*")}):function(e){setTimeout(e,0)}},avalon.init=function(e){this[0]=this.element=e},avalon.fn=avalon.prototype=avalon.init.prototype,avalon.type=function(e){return null==e?String(e):"object"==typeof e||"function"==typeof e?Wt[Pt.call(e)]||"object":typeof e};var Xt="object"==typeof alert?function(e){try{return/^\s*\bfunction\b/.test(e+"")}catch(t){return!1}}:function(e){return"[object Function]"===Pt.call(e)};avalon.isFunction=Xt,avalon.isWindow=function(e){return e?e==e.document&&e.document!=e:!1},l(e)&&(avalon.isWindow=l);var Yt;for(Yt in avalon({}))break;var Gt="0"!==Yt;avalon.isPlainObject=function(e,t){if(!e||"object"!==avalon.type(e)||e.nodeType||avalon.isWindow(e))return!1;try{if(e.constructor&&!Ht.call(e,"constructor")&&!Ht.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(n){return!1}if(Gt)for(t in e)return Ht.call(e,t);for(t in e);return void 0===t||Ht.call(e,t)},Et.test(Object.getPrototypeOf)&&(avalon.isPlainObject=function(e){return"[object Object]"===Pt.call(e)&&Object.getPrototypeOf(e)===jt}),avalon.mix=avalon.fn.mix=function(){var e,t,n,r,a,i,o=arguments[0]||{},l=1,s=arguments.length,c=!1;for("boolean"==typeof o&&(c=o,o=arguments[1]||{},l++),"object"==typeof o||Xt(o)||(o={}),l===s&&(o=this,l--);s>l;l++)if(null!=(e=arguments[l]))for(t in e){n=o[t];try{r=e[t]}catch(u){continue}o!==r&&(c&&r&&(avalon.isPlainObject(r)||(a=Array.isArray(r)))?(a?(a=!1,i=n&&Array.isArray(n)?n:[]):i=n&&avalon.isPlainObject(n)?n:{},o[t]=avalon.mix(c,i,r)):void 0!==r&&(o[t]=r))}return o},avalon.mix({rword:_t,subscribers:At,version:1.41,ui:{},log:n,slice:It?function(e,t,n){return Ft.call(e,t,n)}:function(e,t,n){var r=[],a=e.length;if(void 0===n&&(n=a),"number"==typeof n&&isFinite(n)){t=s(t,a),n=s(n,a);for(var i=t;n>i;++i)r[i-t]=e[i]}return r},noop:r,error:function(e,t){throw(t||Error)(e)},oneObject:i,range:function(e,t,n){n||(n=1),null==t&&(t=e||0,e=0);for(var r=-1,a=Math.max(0,Math.ceil((t-e)/n)),i=new Array(a);++r<a;)i[r]=e,e+=n;return i},eventHooks:{},bind:function(e,t,n,r){var a=avalon.eventHooks,i=a[t];"object"==typeof i&&(t=i.type,i.deel&&(n=i.deel(e,t,n,r)));var o=It?n:function(t){n.call(e,v(t))};return It?e.addEventListener(t,o,!!r):e.attachEvent("on"+t,o),o},unbind:function(e,t,n,a){var i=avalon.eventHooks,o=i[t],l=n||r;"object"==typeof o&&(t=o.type,o.deel&&(n=o.deel(e,t,n,!1))),It?e.removeEventListener(t,l,!!a):e.detachEvent("on"+t,l)},css:function(e,t,n){e instanceof avalon&&(e=e[0]);var r,a=/[_-]/.test(t)?Y(t):t;if(t=avalon.cssName(a)||a,void 0===n||"boolean"==typeof n){r=hr[a+":get"]||hr["@:get"],"background"===t&&(t="backgroundColor");var i=r(e,t);return n===!0?parseFloat(i)||0:i}if(""===n)e.style[t]="";else{if(null==n||n!==n)return;isFinite(n)&&!avalon.cssNumber[a]&&(n+="px"),r=hr[a+":set"]||hr["@:set"],r(e,t,n)}},each:function(e,t){if(e){var n=0;if(c(e))for(var r=e.length;r>n&&t(n,e[n])!==!1;n++);else for(n in e)if(e.hasOwnProperty(n)&&t(n,e[n])===!1)break}},getWidgetData:function(e,t){var n=avalon(e).data(),r={};for(var a in n)0===a.indexOf(t)&&(r[a.replace(t,"").replace(/\w/,function(e){return e.toLowerCase()})]=n[a]);return r},Array:{ensure:function(e,t){return-1===e.indexOf(t)?e.push(t):void 0},removeAt:function(e,t){return!!e.splice(t,1).length},remove:function(e,t){var n=e.indexOf(t);return~n?avalon.Array.removeAt(e,n):!1}}});var Jt=avalon.bindingHandlers={},Zt=avalon.bindingExecutors={},Qt=new function(){function e(e){this.size=0,this.limit=e,this.head=this.tail=void 0,this._keymap={}}var t=e.prototype;return t.put=function(e,t){var n={key:e,value:t};return this._keymap[e]=n,this.tail?(this.tail.newer=n,n.older=this.tail):this.head=n,this.tail=n,this.size===this.limit?this.shift():this.size++,t},t.shift=function(){var e=this.head;e&&(this.head=this.head.newer,this.head.older=e.newer=e.older=this._keymap[e.key]=void 0)},t.get=function(e){var t=this._keymap[e];if(void 0!==t)return t===this.tail?t.value:(t.newer&&(t===this.head&&(this.head=t.newer),t.newer.older=t.older),t.older&&(t.older.newer=t.newer),t.newer=void 0,t.older=this.tail,this.tail&&(this.tail.newer=t),this.tail=t,t.value)},e};if(!"司徒正美".trim){var Kt=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;String.prototype.trim=function(){return this.replace(Kt,"")}}var en=!{toString:null}.propertyIsEnumerable("toString"),tn=function(){}.propertyIsEnumerable("prototype"),nn=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],rn=nn.length;if(Object.keys||(Object.keys=function(e){var t=[],n=tn&&"function"==typeof e;if("string"==typeof e||e&&e.callee)for(var r=0;r<e.length;++r)t.push(String(r));else for(var a in e)n&&"prototype"===a||!Ht.call(e,a)||t.push(String(a));if(en)for(var i=e.constructor,o=i&&i.prototype===e,l=0;rn>l;l++){var s=nn[l];o&&"constructor"===s||!Ht.call(e,s)||t.push(s)}return t}),Array.isArray||(Array.isArray=function(e){return"[object Array]"===Pt.call(e)}),r.bind||(Function.prototype.bind=function(e){if(arguments.length<2&&void 0===e)return this;var t=this,n=arguments;return function(){var r,a=[];for(r=1;r<n.length;r++)a.push(n[r]);for(r=0;r<arguments.length;r++)a.push(arguments[r]);return t.apply(e,a)}}),Et.test([].map)||avalon.mix(Dt,{indexOf:function(e,t){var n=this.length,r=~~t;for(0>r&&(r+=n);n>r;r++)if(this[r]===e)return r;return-1},lastIndexOf:function(e,t){var n=this.length,r=null==t?n-1:t;for(0>r&&(r=Math.max(0,n+r));r>=0;r--)if(this[r]===e)return r;return-1},forEach:u("","_",""),filter:u("r=[],j=0,","if(_)r[j++]=this[i]","return r"),map:u("r=[],","r[i]=_","return r"),some:u("","if(_)return true","return false"),every:u("","if(!_)return false","return true")}),avalon.contains=f,$t.contains||($t.contains=function(e){return f($t,e)}),e.SVGElement){$t.createTextNode("x").contains||(Node.prototype.contains=function(e){return!!(16&this.compareDocumentPosition(e))});var an="http://www.w3.org/2000/svg",on=$t.createElementNS(an,"svg");on.innerHTML='<circle cx="50" cy="50" r="40" fill="red" />',St.test(on.firstChild)||Object.defineProperties(SVGElement.prototype,{outerHTML:{enumerable:!0,configurable:!0,get:p,set:function(e){var t=this.tagName.toLowerCase(),n=this.parentNode,r=avalon.parseHTML(e);if("svg"===t)n.insertBefore(r,this);else{var a=$t.createDocumentFragment();d(r,a),n.insertBefore(a,this)}n.removeChild(this)}},innerHTML:{enumerable:!0,configurable:!0,get:function(){var e=this.outerHTML,t=new RegExp("<"+this.nodeName+'\\b(?:(["\'])[^"]*?(\\1)|[^>])*>',"i"),n=new RegExp("</"+this.nodeName+">$","i");return e.replace(t,"").replace(n,"")},set:function(e){if(avalon.clearHTML){avalon.clearHTML(this);var t=avalon.parseHTML(e);d(t,this)}}}})}!Rt.outerHTML&&e.HTMLElement&&HTMLElement.prototype.__defineGetter__("outerHTML",p);var ln=/^(?:mouse|contextmenu|drag)|click/,sn=avalon.eventHooks;if("onmouseenter"in Rt||avalon.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){sn[e]={type:t,deel:function(t,n,r){return function(n){var a=n.relatedTarget;return a&&(a===t||16&t.compareDocumentPosition(a))?void 0:(delete n.type,n.type=e,r.call(t,n))}}}}),avalon.each({AnimationEvent:"animationend",WebKitAnimationEvent:"webkitAnimationEnd"},function(t,n){e[t]&&!sn.animationend&&(sn.animationend={type:n})}),"oninput"in $t.createElement("input")||(sn.input={type:"propertychange",deel:function(e,t,n){return function(t){return"value"===t.propertyName?(t.type="input",n.call(e,t)):void 0}}}),void 0===$t.onmousewheel){var cn=void 0!==$t.onwheel?"wheel":"DOMMouseScroll",un="wheel"===cn?"deltaY":"detail";sn.mousewheel={type:cn,deel:function(e,t,n){return function(t){t.wheelDeltaY=t.wheelDelta=t[un]>0?-120:120,t.wheelDeltaX=0,Object.defineProperty&&Object.defineProperty(t,"type",{value:"mousewheel"}),n.call(e,t)}}}}var fn,pn,dn,vn,hn,mn=/[-.*+?^${}()|[\]\/\\]/g,gn={loader:function(t){var n=Tt&&t;e.require=n?Tt:kt,e.define=n?Tt.define:Mt},interpolate:function(e){if(fn=e[0],pn=e[1],fn===pn)throw new SyntaxError("openTag!==closeTag");if(e+""=="<!--,-->")h.commentInterpolate=!0;else{var t=fn+"test"+pn;if(Ut.innerHTML=t,Ut.innerHTML!==t&&Ut.innerHTML.indexOf("&lt;")>-1)throw new SyntaxError("此定界符不合法");Ut.innerHTML=""}var n=m(fn),r=m(pn);dn=new RegExp(n+"(.*?)"+r),vn=new RegExp(n+"(.*?)"+r,"g"),hn=new RegExp(n+".*?"+r+"|\\sms-")}};h.debug=!0,h.plugins=gn,h.plugins.interpolate(["{{","}}"]),h.paths={},h.shim={},h.maxRepeatSize=100,avalon.config=h;var yn=/(\w+)\[(avalonctrl)="(\S+)"\]/,bn=$t.querySelectorAll?function(e){return $t.querySelectorAll(e)}:function(e){for(var t,n=e.match(yn),r=$t.getElementsByTagName(n[1]),a=[],i=0;t=r[i++];)t.getAttribute(n[2])===n[3]&&a.push(t);return a},xn={$watch:function(e,t){if("function"==typeof t){var n=this.$events[e];n?n.push(t):this.$events[e]=[t]}else this.$events=this.$watch.backup;return this},$unwatch:function(e,t){var n=arguments.length;if(0===n)this.$watch.backup=this.$events,this.$events={};else if(1===n)this.$events[e]=[];else for(var r=this.$events[e]||[],a=r.length;~--a<0;)if(r[a]===t)return r.splice(a,1);return this},$fire:function(e){var t,n,r,a;/^(\w+)!(\S+)$/.test(e)&&(t=RegExp.$1,e=RegExp.$2);var i=this.$events;if(i){var o=Ft.call(arguments,1),l=[e].concat(o);if("all"===t)for(n in avalon.vmodels)r=avalon.vmodels[n],r!==this&&r.$fire.apply(r,l);else if("up"===t||"down"===t){var s=i.expr?bn(i.expr):[];if(0===s.length)return;for(n in avalon.vmodels)if(r=avalon.vmodels[n],r!==this&&r.$events.expr){var c=bn(r.$events.expr);if(0===c.length)continue;Array.prototype.forEach.call(c,function(e){Array.prototype.forEach.call(s,function(n){var a="down"===t?n.contains(e):e.contains(n);a&&(e._avalon=r)})})}var u=$t.getElementsByTagName("*"),f=[];for(Array.prototype.forEach.call(u,function(e){e._avalon&&(f.push(e._avalon),e._avalon="",e.removeAttribute("_avalon"))}),"up"===t&&f.reverse(),n=0;(a=f[n++])&&a.$fire.apply(a,l)!==!1;);}else{var p=i[e]||[],d=i.$all||[];for(n=0;a=p[n++];)Xt(a)&&a.apply(this,o);for(n=0;a=d[n++];)Xt(a)&&a.apply(this,arguments)}}}},$n=avalon.vmodels={};avalon.define=function(e,t){var a=e.$id||e;if(a||n("warning: vm必须指定$id"),$n[a]&&n("warning: "+a+" 已经存在于avalon.vmodels中"),"object"==typeof e)var i=b(e);else{var o={$watch:r};t(o),i=b(o),Ot=!0,t(i),Ot=!1}return i.$id=a,$n[a]=i};var wn=String("$id,$watch,$unwatch,$fire,$events,$model,$skipArray").match(_t),Cn={},Tn=Object.defineProperty,En=!0;try{Tn({},"_",{value:"x"});var An=Object.defineProperties}catch(kn){En=!1}var Mn=Object.is||function(e,t){return 0===e&&0===t?1/e===1/t:e!==e?t!==t:e===t},On=It?function(e){var t={};for(var n in e)t[n]={get:e[n],set:e[n],enumerable:!0,configurable:!0};return t}:function(e){return e};En||("__defineGetter__"in avalon&&(Tn=function(e,t,n){return"value"in n&&(e[t]=n.value),"get"in n&&e.__defineGetter__(t,n.get),"set"in n&&e.__defineSetter__(t,n.set),e},An=function(e,t){for(var n in t)t.hasOwnProperty(n)&&Tn(e,n,t[n]);return e}),zt&&(e.execScript(["Function parseVB(code)"," ExecuteGlobal(code)","End Function","Dim VBClassBodies",'Set VBClassBodies=CreateObject("Scripting.Dictionary")',"Function findOrDefineVBClass(name,body)"," Dim found",' found=""'," For Each key in VBClassBodies"," If body=VBClassBodies.Item(key) Then"," found=key"," Exit For"," End If"," next",' If found="" Then',' parseVB("Class " + name + body)'," VBClassBodies.Add name, body"," found=name"," End If"," findOrDefineVBClass=found","End Function"].join("\n"),"VBScript"),An=function(t,n,r){var a="VBClass"+setTimeout("1"),i=[];i.push("\r\n Private [__data__], [__proxy__]"," Public Default Function [__const__](d, p)"," Set [__data__] = d: set [__proxy__] = p"," Set [__const__] = Me"," End Function");for(t in r)n.hasOwnProperty(t)||i.push(" Public ["+t+"]");wn.forEach(function(e){n.hasOwnProperty(e)||i.push(" Public ["+e+"]")}),i.push(" Public [hasOwnProperty]");for(t in n)i.push(" Public Property Let ["+t+"](val"+xt+")",' Call [__proxy__](Me,[__data__], "'+t+'", val'+xt+")"," End Property"," Public Property Set ["+t+"](val"+xt+")",' Call [__proxy__](Me,[__data__], "'+t+'", val'+xt+")"," End Property"," Public Property Get ["+t+"]"," On Error Resume Next"," Set["+t+'] = [__proxy__](Me,[__data__],"'+t+'")'," If Err.Number <> 0 Then"," ["+t+'] = [__proxy__](Me,[__data__],"'+t+'")'," End If"," On Error Goto 0"," End Property");i.push("End Class");var o=i.join("\r\n"),l=e.findOrDefineVBClass(a,o);l===a&&e.parseVB(["Function "+a+"Factory(a, b)"," Dim o"," Set o = (New "+a+")(a, b)"," Set "+a+"Factory = o","End Function"].join("\r\n"));var s=e[l+"Factory"](n,w);return s}));var _n=Dt.splice,Nn={_splice:_n,_fire:function(e,t,n){S(this.$events[At],e,t,n)},size:function(){return this._.length},pushArray:function(e){var t=e.length,n=this.length;return t&&(Dt.push.apply(this.$model,e),T.call(this,"add",n,t,Math.max(0,n-1))),t+n},push:function(){var e,t=[],n=arguments.length;for(e=0;n>e;e++)t[e]=arguments[e];return this.pushArray(t)},unshift:function(){var e=arguments.length,t=this.length;return e&&(Dt.unshift.apply(this.$model,arguments),T.call(this,"add",0,e,0)),e+t},shift:function(){if(this.length){var e=this.$model.shift();return T.call(this,"del",0,1,0),e}},pop:function(){var e=this.length;if(e){var t=this.$model.pop();return T.call(this,"del",e-1,1,Math.max(0,e-2)),t}},splice:function(e){var t,n=arguments.length,r=[],a=_n.apply(this.$model,arguments);return a.length&&(r.push("del",e,a.length,0),t=!0),n>2&&(t?r.splice(3,1,0,"add",e,n-2):r.push("add",e,n-2,0),t=!0),t?T.apply(this,r):[]},contains:function(e){return-1!==this.indexOf(e)},remove:function(e){return this.removeAt(this.indexOf(e))},removeAt:function(e){return e>=0?(this.$model.splice(e,1),T.call(this,"del",e,1,0)):[]},clear:function(){return this.$model.length=this.length=this._.length=0,this._fire("clear",0),this},removeAll:function(e){if(Array.isArray(e))e.forEach(function(e){this.remove(e)},this);else if("function"==typeof e)for(var t=this.length-1;t>=0;t--){var n=this[t];e(n,t)&&this.removeAt(t)}else this.clear()},ensure:function(e){return this.contains(e)||this.push(e),this},set:function(e,t){if(e>=0){var n=avalon.type(t);t&&t.$model&&(t=t.$model);var r=this[e];if("object"===n)for(var a in t)r.hasOwnProperty(a)&&(r[a]=t[a]);
2
- else"array"===n?r.clear().push.apply(r,t):r!==t&&(this[e]=t,this.$model[e]=t,this._fire("set",e,t))}return this}};"sort,reverse".replace(_t,function(e){Nn[e]=function(){var t,n=this.$model,r=n.concat(),a=Math.random(),i=[];Dt[e].apply(n,arguments);for(var o=0,l=r.length;l>o;o++){var s=n[o],c=r[o];if(Mn(s,c))i.push(o);else{var u=r.indexOf(s);i.push(u),r[u]=a,t=!0}}return t&&(E(this,i),this._fire("move",i),this._fire("index",0)),this}});var Sn=/^(duplex|on)$/,Ln=avalon.$$subscribers=[],jn=new Date,Hn={},Pn={area:[1,"<map>","</map>"],param:[1,"<object>","</object>"],col:[2,"<table><colgroup>","</colgroup></table>"],legend:[1,"<fieldset>","</fieldset>"],option:[1,"<select multiple='multiple'>","</select>"],thead:[1,"<table>","</table>"],tr:[2,"<table>","</table>"],td:[3,"<table><tr>","</tr></table>"],g:[1,'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">',"</svg>"],_default:It?[0,"",""]:[1,"X<div>","</div>"]};Pn.th=Pn.td,Pn.optgroup=Pn.option,Pn.tbody=Pn.tfoot=Pn.colgroup=Pn.caption=Pn.thead,String("circle,defs,ellipse,image,line,path,polygon,polyline,rect,symbol,text,use").replace(_t,function(e){Pn[e]=Pn.g});var Dn=/<([\w:]+)/,Fn=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,Bn=It?/[^\d\D]/:/(<(?:script|link|style|meta|noscript))/gi,In=i(["","text/javascript","text/ecmascript","application/ecmascript","application/javascript"]),Rn=/<(?:tb|td|tf|th|tr|col|opt|leg|cap|area)/,Vn=$t.createElement("script"),Un=/<|&#?\w+;/;avalon.parseHTML=function(e){var t=Vt.cloneNode(!1);if("string"!=typeof e)return t;if(!Un.test(e))return t.appendChild($t.createTextNode(e)),t;e=e.replace(Fn,"<$1></$2>").trim();var n,r,a=(Dn.exec(e)||["",""])[1].toLowerCase(),i=Pn[a]||Pn._default,o=Ut;It||(e=e.replace(Bn,"<br class=msNoScope>$1")),o.innerHTML=i[1]+e+i[2];var l=o.getElementsByTagName("script");if(l.length)for(var s,c=0;s=l[c++];)In[s.type]&&(r=Vn.cloneNode(!1),Dt.forEach.call(s.attributes,function(e){e&&e.specified&&(r[e.name]=e.value,r.setAttribute(e.name,e.value))}),r.text=s.text,s.parentNode.replaceChild(r,s));if(!It){var u="X<div>"===i[1]?o.lastChild.firstChild:o.lastChild;if(u&&"TABLE"===u.tagName&&"tbody"!==a)for(l=u.childNodes,c=0;s=l[c++];)if("TBODY"===s.tagName&&!s.innerHTML){u.removeChild(s);break}l=o.getElementsByTagName("br");for(var f=l.length;s=l[--f];)"msNoScope"===s.className&&s.parentNode.removeChild(s);for(l=o.all,c=0;s=l[c++];)L(s)&&j(s)}for(c=i[0];c--;o=o.lastChild);for(;n=o.firstChild;)t.appendChild(n);return t},avalon.innerHTML=function(e,t){if(!It&&!Bn.test(t)&&!Rn.test(t))try{return void(e.innerHTML=t)}catch(n){}var r=this.parseHTML(t);this.clearHTML(e).appendChild(r)},avalon.clearHTML=function(e){for(e.textContent="";e.firstChild;)e.removeChild(e.firstChild);return e},avalon.scan=function(e,t){e=e||Rt;var n=t?[].concat(t):[];U(e,n)};var Wn=i("area,base,basefont,br,col,command,embed,hr,img,input,link,meta,param,source,track,wbr,noscript,script,style,textarea".toUpperCase()),qn=function(e,t,n){var r=e.getAttribute(t);if(r)for(var a,i=0;a=n[i++];)if(a.hasOwnProperty(r)&&"function"==typeof a[r])return a[r]},zn=zt&&e.MutationObserver?function(e){for(var t,n=e.firstChild;n;){var r=n.nextSibling;3===n.nodeType?t?(t.nodeValue+=n.nodeValue,e.removeChild(n)):t=n:t=null,n=r}}:0,Xn=/ms-(\w+)-?(.*)/,Yn={"if":10,repeat:90,data:100,widget:110,each:1400,"with":1500,duplex:2e3,on:3e3},Gn=i("animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scan,scroll,submit"),Jn=i("value,title,alt,checked,selected,disabled,readonly,enabled"),Zn=/^if|widget|repeat$/,Qn=/^each|with|html|include$/;if(!"1"[0])var Kn=new Qt(512),er=/\s+(ms-[^=\s]+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,tr=/^['"]/,nr=/<\w+\b(?:(["'])[^"]*?(\1)|[^>])*>/i,rr=/&amp;/g,ar=function(e){var t=e.outerHTML;if("</"===t.slice(0,2)||!t.trim())return[];var n,r,a,i=t.match(nr)[0],o=[],l=Kn.get(i);if(l)return l;for(;r=er.exec(i);){a=r[2],a&&(a=(tr.test(a)?a.slice(1,-1):a).replace(rr,"&"));var s=r[1].toLowerCase();n=s.match(Xn);var c={name:s,specified:!0,value:a||""};o.push(c)}return Kn.put(i,o)};var ir=/\|\s*html\s*/,or=/\|\|/g,lr=/&lt;/g,sr=/&gt;/g;rstringLiteral=/(['"])(\\\1|.)+?\1/g;var cr={_toString:function(){var e=this.node,t=e.className,n="string"==typeof t?t:t.baseVal;return n.split(/\s+/).join(" ")},_contains:function(e){return(" "+this+" ").indexOf(" "+e+" ")>-1},_add:function(e){this.contains(e)||this._set(this+" "+e)},_remove:function(e){this._set((" "+this+" ").replace(" "+e+" "," "))},__set:function(e){e=e.trim();var t=this.node;St.test(t)?t.setAttribute("class",e):t.className=e}};"add,remove".replace(_t,function(e){avalon.fn[e+"Class"]=function(t){var n=this[0];return t&&"string"==typeof t&&n&&1===n.nodeType&&t.replace(/\S+/g,function(t){G(n)[e](t)}),this}}),avalon.fn.mix({hasClass:function(e){var t=this[0]||{};return 1===t.nodeType&&G(t).contains(e)},toggleClass:function(e,t){for(var n,r=0,a=e.split(/\s+/),i="boolean"==typeof t;n=a[r++];){var o=i?t:!this.hasClass(n);this[o?"addClass":"removeClass"](n)}return this},attr:function(e,t){return 2===arguments.length?(this[0].setAttribute(e,t),this):this[0].getAttribute(e)},data:function(e,t){switch(e="data-"+X(e||""),arguments.length){case 2:return this.attr(e,t),this;case 1:var n=this.attr(e);return J(n);case 0:var r={};return Dt.forEach.call(this[0].attributes,function(t){t&&(e=t.name,e.indexOf("data-")||(e=Y(e.slice(5)),r[e]=J(t.value)))}),r}},removeData:function(e){return e="data-"+X(e),this[0].removeAttribute(e),this},css:function(e,t){if(avalon.isPlainObject(e))for(var n in e)avalon.css(this,n,e[n]);else var r=avalon.css(this,e,t);return void 0!==r?r:this},position:function(){var e,t,n=this[0],r={top:0,left:0};if(n)return"fixed"===this.css("position")?t=n.getBoundingClientRect():(e=this.offsetParent(),t=this.offset(),"HTML"!==e[0].tagName&&(r=e.offset()),r.top+=avalon.css(e[0],"borderTopWidth",!0),r.left+=avalon.css(e[0],"borderLeftWidth",!0)),{top:t.top-r.top-avalon.css(n,"marginTop",!0),left:t.left-r.left-avalon.css(n,"marginLeft",!0)}},offsetParent:function(){for(var e=this[0].offsetParent;e&&"static"===avalon.css(e,"position");)e=e.offsetParent;return avalon(e||Rt)},bind:function(e,t,n){return this[0]?avalon.bind(this[0],e,t,n):void 0},unbind:function(e,t,n){return this[0]&&avalon.unbind(this[0],e,t,n),this},val:function(e){var t=this[0];if(t&&1===t.nodeType){var n=0===arguments.length,r=n?":get":":set",a=kr[K(t)+r];if(a)var i=a(t,e);else{if(n)return(t.value||"").replace(/\r/g,"");t.value=e}}return n?i:this}});var ur=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/,fr=/^[\],:{}\s]*$/,pr=/(?:^|:|,)(?:\s*\[)+/g,dr=/\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,vr=/"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g;avalon.parseJSON=e.JSON?JSON.parse:function(e){if("string"==typeof e){if(e=e.trim(),e&&fr.test(e.replace(dr,"@").replace(vr,"]").replace(pr,"")))return new Function("return "+e)();avalon.error("Invalid JSON: "+e)}return e},avalon.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(e,t){avalon.fn[e]=function(n){var r=this[0]||{},a=Z(r),i="scrollTop"===e;return arguments.length?void(a?a.scrollTo(i?avalon(a).scrollLeft():n,i?n:avalon(a).scrollTop()):r[e]=n):a?t in a?a[t]:Rt[e]:r[e]}});var hr=avalon.cssHooks={},mr=["","-webkit-","-o-","-moz-","-ms-"],gr={"float":It?"cssFloat":"styleFloat"};if(avalon.cssNumber=i("columnCount,order,fillOpacity,fontWeight,lineHeight,opacity,orphans,widows,zIndex,zoom"),avalon.cssName=function(e,t,n){if(gr[e])return gr[e];t=t||Rt.style;for(var r=0,a=mr.length;a>r;r++)if(n=Y(mr[r]+e),n in t)return gr[e]=n;return null},hr["@:set"]=function(e,t,n){try{e.style[t]=n}catch(r){}},e.getComputedStyle)hr["@:get"]=function(e,t){if(!e||!e.style)throw new Error("getComputedStyle要求传入一个节点 "+e);var n,r=getComputedStyle(e,null);return r&&(n="filter"===t?r.getPropertyValue(t):r[t],""===n&&(n=e.style[t])),n},hr["opacity:get"]=function(e){var t=hr["@:get"](e,"opacity");return""===t?"1":t};else{var yr=/^-?(?:\d*\.)?\d+(?!px)[^\d\s]+$/i,br=/^(top|right|bottom|left)$/,xr=/alpha\([^)]*\)/i,$r=!!e.XDomainRequest,wr="DXImageTransform.Microsoft.Alpha",Cr={thin:$r?"1px":"2px",medium:$r?"3px":"4px",thick:$r?"5px":"6px"};hr["@:get"]=function(e,t){var n=e.currentStyle,r=n[t];if(yr.test(r)&&!br.test(r)){var a=e.style,i=a.left,o=e.runtimeStyle.left;e.runtimeStyle.left=n.left,a.left="fontSize"===t?"1em":r||0,r=a.pixelLeft+"px",a.left=i,e.runtimeStyle.left=o}return"medium"===r&&(t=t.replace("Width","Style"),"none"===n[t]&&(r="0px")),""===r?"auto":Cr[r]||r},hr["opacity:set"]=function(e,t,n){var r=e.style,a=isFinite(n)&&1>=n?"alpha(opacity="+100*n+")":"",i=r.filter||"";r.zoom=1,r.filter=(xr.test(i)?i.replace(xr,a):i+" "+a).trim(),r.filter||r.removeAttribute("filter")},hr["opacity:get"]=function(e){var t=e.filters.alpha||e.filters[wr],n=t&&t.enabled?t.opacity:100;return n/100+""}}"top,left".replace(_t,function(e){hr[e+":get"]=function(t){var n=hr["@:get"](t,e);return/px$/.test(n)?n:avalon(t).position()[e]+"px"}});var Tr={position:"absolute",visibility:"hidden",display:"block"},Er=/^(none|table(?!-c[ea]).+)/;"Width,Height".replace(_t,function(e){var t=e.toLowerCase(),n="client"+e,r="scroll"+e,a="offset"+e;hr[t+":get"]=function(t,n,r){var i=-4;"number"==typeof r&&(i=r),n="Width"===e?["Left","Right"]:["Top","Bottom"];var o=t[a];return 2===i?o+avalon.css(t,"margin"+n[0],!0)+avalon.css(t,"margin"+n[1],!0):(0>i&&(o=o-avalon.css(t,"border"+n[0]+"Width",!0)-avalon.css(t,"border"+n[1]+"Width",!0)),-4===i&&(o=o-avalon.css(t,"padding"+n[0],!0)-avalon.css(t,"padding"+n[1],!0)),o)},hr[t+"&get"]=function(e){var n=[];Q(e,n);for(var r,a=hr[t+":get"](e),i=0;r=n[i++];){e=r.node;for(var o in r)"string"==typeof r[o]&&(e.style[o]=r[o])}return a},avalon.fn[t]=function(i){var o=this[0];if(0===arguments.length){if(o.setTimeout)return o["inner"+e]||o.document.documentElement[n];if(9===o.nodeType){var l=o.documentElement;return Math.max(o.body[r],l[r],o.body[a],l[a],l[n])}return hr[t+"&get"](o)}return this.css(t,i)},avalon.fn["inner"+e]=function(){return hr[t+":get"](this[0],void 0,-2)},avalon.fn["outer"+e]=function(e){return hr[t+":get"](this[0],void 0,e===!0?2:0)}}),avalon.fn.offset=function(){var e=this[0],t={left:0,top:0};if(!e||!e.tagName||!e.ownerDocument)return t;var n=e.ownerDocument,r=n.body,a=n.documentElement,i=n.defaultView||n.parentWindow;if(!avalon.contains(a,e))return t;e.getBoundingClientRect&&(t=e.getBoundingClientRect());var o=a.clientTop||r.clientTop,l=a.clientLeft||r.clientLeft,s=Math.max(i.pageYOffset||0,a.scrollTop,r.scrollTop),c=Math.max(i.pageXOffset||0,a.scrollLeft,r.scrollLeft);return{top:t.top+s-o,left:t.left+c-l}};var Ar=/^<option(?:\s+\w+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+))?)*\s+value[\s=]/i,kr={"option:get":zt?function(e){return Ar.test(e.outerHTML)?e.value:e.text.trim()}:function(e){return e.value},"select:get":function(e,t){for(var n,r=e.options,a=e.selectedIndex,i=kr["option:get"],o="select-one"===e.type||0>a,l=o?null:[],s=o?a+1:r.length,c=0>a?s:o?a:0;s>c;c++)if(n=r[c],(n.selected||c===a)&&!n.disabled){if(t=i(n),o)return t;l.push(t)}return l},"select:set":function(e,t,n){t=[].concat(t);for(var r,a=kr["option:get"],i=0;r=e.options[i++];)(r.selected=t.indexOf(a(r))>-1)&&(n=!0);n||(e.selectedIndex=-1)}},Mr={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},Or=e.JSON&&JSON.stringify||function(e){return'"'+e.replace(/[\\\"\x00-\x1f]/g,function(e){var t=Mr[e];return"string"==typeof t?t:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})+'"'},_r=["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"].join(","),Nr=/\/\*[\w\W]*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|"(?:[^"\\]|\\[\w\W])*"|'(?:[^'\\]|\\[\w\W])*'|[\s\t\n]*\.[\s\t\n]*[$\w\.]+/g,Sr=/[^\w$]+/g,Lr=new RegExp(["\\b"+_r.replace(/,/g,"\\b|\\b")+"\\b"].join("|"),"g"),jr=/\b\d[^,]*/g,Hr=/^,+|,+$/g,Pr=new Qt(512),Dr=function(e){var t=","+e.trim(),n=Pr.get(t);if(n)return n;var r=e.replace(Nr,"").replace(Sr,",").replace(Lr,"").replace(jr,"").replace(Hr,"").split(/^$|,+/);return Pr.put(t,tt(r))},Fr=new Qt(128),Br=/\w\[.*\]|\w\.\w/,Ir=/(\$proxy\$[a-z]+)\d+$/,Rr=/\)\s*$/,Vr=/\)\s*\|/g,Ur=/\|\s*([$\w]+)/g,Wr=/"\s*\["/g,qr=/"\s*\(/g;avalon.parseExprProxy=at;var zr=["autofocus,autoplay,async,allowTransparency,checked,controls","declare,disabled,defer,defaultChecked,defaultSelected","contentEditable,isMap,loop,multiple,noHref,noResize,noShade","open,readOnly,selected"].join(","),Xr={};zr.replace(_t,function(e){Xr[e.toLowerCase()]=e});var Yr={"accept-charset":"acceptCharset","char":"ch",charoff:"chOff","class":"className","for":"htmlFor","http-equiv":"httpEquiv"},Gr=["accessKey,bgColor,cellPadding,cellSpacing,codeBase,codeType,colSpan","dateTime,defaultValue,frameBorder,longDesc,maxLength,marginWidth,marginHeight","rowSpan,tabIndex,useMap,vSpace,valueType,vAlign"].join(",");Gr.replace(_t,function(e){Yr[e.toLowerCase()]=e});var Jr=/<noscript.*?>(?:[\s\S]+?)<\/noscript>/gim,Zr=/<noscript.*?>([\s\S]+?)<\/noscript>/im,Qr=function(){return new(e.XMLHttpRequest||ActiveXObject)("Microsoft.XMLHTTP")},Kr=avalon.templateCache={};Jt.attr=function(e,t){var n=e.value.trim(),r=!0;if(n.indexOf(fn)>-1&&n.indexOf(pn)>2&&(r=!1,dn.test(n)&&""===RegExp.rightContext&&""===RegExp.leftContext&&(r=!0,n=RegExp.$1)),"include"===e.type){var a=e.element;e.includeRendered=qn(a,"data-include-rendered",t),e.includeLoaded=qn(a,"data-include-loaded",t);var i=e.includeReplace=!!avalon(a).data("includeReplace");avalon(a).data("includeCache")&&(e.templateCache={}),e.startInclude=$t.createComment("ms-include"),e.endInclude=$t.createComment("ms-include-end"),i?(e.element=e.startInclude,a.parentNode.insertBefore(e.startInclude,a),a.parentNode.insertBefore(e.endInclude,a.nextSibling)):(a.insertBefore(e.startInclude,a.firstChild),a.appendChild(e.endInclude))}e.handlerName="attr",at(n,t,e,r?0:q(e.value))},Zt.attr=function(t,n,r){var a=r.type,i=r.param;if("css"===a)avalon(n).css(i,t);else if("attr"===a){if(Xr[i]){var o=Xr[i];if("boolean"==typeof n[o])return n[o]=!!t}var l=t===!1||null===t||void 0===t;if(!It&&Yr[i]&&(i=Yr[i]),l)return n.removeAttribute(i);var s=St.test(n)?!1:$t.namespaces&&L(n)?!0:i in n.cloneNode(!1);s?n[i]=t:n.setAttribute(i,t)}else if("include"===a&&t){var c=r.vmodels,u=r.includeRendered,f=r.includeLoaded,p=r.includeReplace,d=p?n.parentNode:n,v=function(e){f&&(e=f.apply(d,[e].concat(c))),u&&H(d,function(){u.call(d)},0/0);var n=r.includeLastID;if(r.templateCache&&n&&n!==t){var a=r.templateCache[n];a||(a=r.templateCache[n]=$t.createElement("div"),Ct.appendChild(a))}for(r.includeLastID=t;;){var i=r.startInclude.nextSibling;if(!i||i===r.endInclude)break;d.removeChild(i),a&&a.appendChild(i)}var o=it(r,t,e),l=avalon.slice(o.childNodes);d.insertBefore(o,r.endInclude),R(l,c)};if("src"===r.param)if(Kr[t])avalon.nextTick(function(){v(Kr[t])});else{var h=Qr();h.onreadystatechange=function(){if(4===h.readyState){var e=h.status;(e>=200&&300>e||304===e||1223===e)&&v(Kr[t]=h.responseText)}},h.open("GET",t,!0),"withCredentials"in h&&(h.withCredentials=!0),h.setRequestHeader("X-Requested-With","XMLHttpRequest"),h.send(null)}else{var m=t&&1===t.nodeType?t:$t.getElementById(t);if(m){if("NOSCRIPT"===m.tagName&&!m.innerHTML&&!m.fixIE78){h=Qr(),h.open("GET",location,!1),h.send(null);for(var g=$t.getElementsByTagName("noscript"),y=(h.responseText||"").match(Jr)||[],b=y.length,x=0;b>x;x++){var $=g[x];$&&($.style.display="none",$.fixIE78=(y[x].match(Zr)||["","&nbsp;"])[1])}}avalon.nextTick(function(){v(m.fixIE78||m.value||m.innerText||m.innerHTML)})}}}else if(Rt.hasAttribute||"string"!=typeof t||"src"!==a&&"href"!==a||(t=t.replace(/&amp;/g,"&")),n[a]=t,e.chrome&&"EMBED"===n.tagName){var w=n.parentNode,C=document.createComment("ms-src");w.replaceChild(C,n),w.replaceChild(n,C)}},"title,alt,src,value,css,include,href".replace(_t,function(e){Jt[e]=Jt.attr}),Jt["class"]=function(e,t){var r,a=e.param,i=e.value;if(e.handlerName="class",!a||isFinite(a)){e.param="";var o=i.replace(vn,function(e){return e.replace(/./g,"0")}),l=o.indexOf(":");if(-1===l)var s=i;else{if(s=i.slice(0,l),r=i.slice(l+1),rt(r,t,e),!e.evaluator)return n("debug: ms-class '"+(r||"").trim()+"' 不存在于VM中"),!1;e._evaluator=e.evaluator,e._args=e.args}var c=dn.test(s);c||(e.immobileClass=s),at("",t,e,c?q(s):0)}else e.immobileClass=e.oldStyle=e.param,at(i,t,e)},Zt["class"]=function(e,t,n){var r=avalon(t),a=n.type;if("class"===a&&n.oldStyle)r.toggleClass(n.oldStyle,!!e);else switch(n.toggleClass=n._evaluator?!!n._evaluator.apply(t,n._args):!0,n.newClass=n.immobileClass||e,n.oldClass&&n.newClass!==n.oldClass&&r.removeClass(n.oldClass),n.oldClass=n.newClass,a){case"class":r.toggleClass(n.newClass,n.toggleClass);break;case"hover":case"active":if(!n.hasBindEvent){var i="mouseenter",o="mouseleave";if("active"===a){t.tabIndex=t.tabIndex||-1,i="mousedown",o="mouseup";var l=r.bind("mouseleave",function(){n.toggleClass&&r.removeClass(n.newClass)})}var s=r.bind(i,function(){n.toggleClass&&r.addClass(n.newClass)}),c=r.bind(o,function(){n.toggleClass&&r.removeClass(n.newClass)});n.rollback=function(){r.unbind("mouseleave",l),r.unbind(i,s),r.unbind(o,c)},n.hasBindEvent=!0}}},"hover,active".replace(_t,function(e){Jt[e]=Jt["class"]}),Zt.data=function(e,t,n){var r="data-"+n.param;e&&"object"==typeof e?t[r]=e:t.setAttribute(r,String(e))};var ea=Jt.duplex=function(e,t){var a,o=e.element;if(at(e.value,t,e,0,1),e.changed=qn(o,"data-duplex-changed",t)||r,e.evaluator&&e.args){var l=[],s=i("string,number,boolean,checked");"radio"===o.type&&""===e.param&&(e.param="checked"),o.msData&&(o.msData["ms-duplex"]=e.value),e.param.replace(/\w+/g,function(t){/^(checkbox|radio)$/.test(o.type)&&/^(radio|checked)$/.test(t)&&("radio"===t&&n("ms-duplex-radio已经更名为ms-duplex-checked"),t="checked",e.isChecked=!0),"bool"===t?(t="boolean",n("ms-duplex-bool已经更名为ms-duplex-boolean")):"text"===t&&(t="string",n("ms-duplex-text已经更名为ms-duplex-string")),s[t]&&(a=!0),avalon.Array.ensure(l,t)}),a||l.push("string"),e.param=l.join("-"),e.bound=function(t,n){o.addEventListener?o.addEventListener(t,n,!1):o.attachEvent("on"+t,n);var r=e.rollback;e.rollback=function(){o.avalonSetter=null,avalon.unbind(o,t,n),r&&r()}};for(var c in avalon.vmodels){var u=avalon.vmodels[c];u.$fire("avalon-ms-duplex-init",e)}var f=e.pipe||(e.pipe=lt);f(null,e,"init");var p=o.tagName;ea[p]&&ea[p](o,e.evaluator.apply(null,e.args),e)}};avalon.duplexHooks={checked:{get:function(e,t){return!t.element.oldValue}},string:{get:function(e){return e},set:ot},"boolean":{get:function(e){return"true"===e},set:ot},number:{get:function(e,t){var n=parseFloat(e);if(-e===-n)return n;var r=/strong|medium|weak/.exec(t.element.getAttribute("data-duplex-number"))||["medium"];switch(r[0]){case"strong":return 0;case"medium":return""===e?"":0;case"weak":return e}},set:ot}};var ta,na=[];avalon.tick=function(e){1===na.push(e)&&(ta=setInterval(st,60))};var ra=r,aa=/text|password|hidden/;!new function(){function e(e){if(avalon.contains(Rt,this)){if(t[this.tagName].call(this,e),!aa.test(this.type))return;!this.msFocus&&this.avalonSetter&&this.avalonSetter()}}try{var t={},n=HTMLInputElement.prototype,r=HTMLTextAreaElement.prototype,a=HTMLInputElement.prototype;Object.getOwnPropertyNames(a),t.INPUT=Object.getOwnPropertyDescriptor(n,"value").set,Object.defineProperty(n,"value",{set:e}),t.TEXTAREA=Object.getOwnPropertyDescriptor(r,"value").set,Object.defineProperty(r,"value",{set:e})}catch(i){ra=avalon.tick}},zt&&avalon.bind($t,"selectionchange",function(){var e=$t.activeElement;e&&"function"==typeof e.avalonSetter&&e.avalonSetter()}),ea.INPUT=function(e,t,r){function a(e){r.changed.call(this,e,r)}function i(){f=!0}function o(){f=!1}function l(e){setTimeout(function(){p(e)})}var s=e.type,c=r.bound,u=avalon(e),f=!1,p=function(){if(!f){var n=e.oldValue=e.value,i=r.pipe(n,r,"get");u.data("duplex-observe")!==!1&&(t(i),a.call(e,i),u.data("duplex-focus")&&avalon.nextTick(function(){e.focus()}))}};if(r.handler=function(){var n=r.pipe(t(),r,"set")+"";n!==e.oldValue&&(e.value=n)},r.isChecked||"radio"===s){var d=6===zt;p=function(){if(u.data("duplex-observe")!==!1){var n=r.pipe(e.value,r,"get");t(n),a.call(e,n)}},r.handler=function(){var n=t(),a=r.isChecked?!!n:n+""===e.value;e.oldValue=a,d?setTimeout(function(){e.defaultChecked=a,e.checked=a},31):e.checked=a},c("click",p)}else if("checkbox"===s)p=function(){if(u.data("duplex-observe")!==!1){var i=e.checked?"ensure":"remove",o=t();Array.isArray(o)||(n("ms-duplex应用于checkbox上要对应一个数组"),o=[o]),avalon.Array[i](o,r.pipe(e.value,r,"get")),a.call(e,o)}},r.handler=function(){var n=[].concat(t());e.checked=n.indexOf(r.pipe(e.value,r,"get"))>-1},c(It?"change":"click",p);else{var v=e.getAttribute("data-duplex-event")||"input";e.attributes["data-event"]&&n("data-event指令已经废弃,请改用data-duplex-event"),v.replace(_t,function(e){switch(e){case"input":zt?(zt>8?c("input",p):c("propertychange",function(e){"value"===e.propertyName&&p()}),c("dragend",l)):(c("input",p),c("compositionstart",i),c("compositionend",o),c("DOMAutoComplete",p));break;default:c(e,p)}}),c("focus",function(){e.msFocus=!0}),c("blur",function(){e.msFocus=!1}),aa.test(s)&&ra(function(){if(Rt.contains(e))e.msFocus||e.oldValue===e.value||p();else if(!e.msRetain)return!1}),e.avalonSetter=p}e.oldValue=e.value,A(r),a.call(e,e.value)},ea.TEXTAREA=ea.INPUT,ea.SELECT=function(e,t,r){function a(){if(i.data("duplex-observe")!==!1){var n=i.val();n=Array.isArray(n)?n.map(function(e){return r.pipe(e,r,"get")}):r.pipe(n,r,"get"),n+""!==e.oldValue&&t(n),r.changed.call(e,n,r)}}var i=avalon(e);r.handler=function(){var r=t();r=r&&r.$model||r,Array.isArray(r)?e.multiple||n("ms-duplex在<select multiple=true>上要求对应一个数组"):e.multiple&&n("ms-duplex在<select multiple=false>不能对应一个数组"),r=Array.isArray(r)?r.map(String):r+"",r+""!==e.oldValue&&(i.val(r),e.oldValue=r+"")},r.bound("change",a),H(e,function(){A(r),r.changed.call(e,t(),r)},0/0)},Zt.html=function(e,t,n){e=null==e?"":e;var r="group"in n,a=r?t.parentNode:t;if(a){if(11===e.nodeType)var i=e;else if(1===e.nodeType||e.item){var o=1===e.nodeType?e.childNodes:e.item?e:[];for(i=Vt.cloneNode(!0);o[0];)i.appendChild(o[0])}else i=avalon.parseHTML(e);var l=$t.createComment("ms-html");if(r){a.insertBefore(l,t);for(var s=n.group,c=1;s>c;){var u=t.nextSibling;u&&(a.removeChild(u),c++)}a.removeChild(t),n.element=l}else avalon.clearHTML(a).appendChild(l);r&&(n.group=i.childNodes.length||1),o=avalon.slice(i.childNodes),o[0]&&(l.parentNode&&l.parentNode.replaceChild(i,l),r&&(n.element=o[0])),R(o,n.vmodels)}},Jt["if"]=Jt.data=Jt.text=Jt.html=function(e,t){at(e.value,t,e)},Zt["if"]=function(e,t,n){if(e)8===t.nodeType&&(t.parentNode.replaceChild(n.template,t),t=n.element=n.template),t.getAttribute(n.name)&&(t.removeAttribute(n.name),B(t,n.vmodels)),n.rollback=null;else if(1===t.nodeType){var r=n.element=$t.createComment("ms-if");t.parentNode.replaceChild(r,t),n.template=t,Ct.appendChild(t),n.rollback=function(){t.parentNode===Ct&&Ct.removeChild(t)}}};var ia=/\(([^)]*)\)/;Jt.on=function(e,t){var n=e.value;e.type="on";var r=e.param.replace(/-\d+$/,"");if("function"==typeof Jt.on[r+"Hook"]&&Jt.on[r+"Hook"](e),n.indexOf("(")>0&&n.indexOf(")")>-1){var a=(n.match(ia)||["",""])[1].trim();(""===a||"$event"===a)&&(n=n.replace(ia,""))}at(n,t,e)},Zt.on=function(e,t,n){e=function(e){var t=n.evaluator||r;return t.apply(this,n.args.concat(e))};var a=n.param.replace(/-\d+$/,"");if("scan"===a)e.call(t,{type:a});else if("function"==typeof n.specialBind)n.specialBind(t,e);else var i=avalon.bind(t,a,e);n.rollback=function(){"function"==typeof n.specialUnbind?n.specialUnbind():avalon.unbind(t,a,i)}},Jt.repeat=function(e,t){var n=e.type;at(e.value,t,e,0,1),e.proxies=[];var r=!1;try{var a=e.$repeat=e.evaluator.apply(0,e.args||[]),i=avalon.type(a);"object"!==i&&"array"!==i&&(r=!0,avalon.log("warning:"+e.value+"只能是对象或数组"))}catch(o){r=!0}var l=e.value.split(".")||[];if(l.length>1){l.pop();for(var s,c=l[0],u=0;s=t[u++];)if(s&&s.hasOwnProperty(c)){var f=s[c].$events||{};f[At]=f[At]||[],f[At].push(e);break}}var p=e.element;p.removeAttribute(e.name),e.sortedCallback=qn(p,"data-with-sorted",t),e.renderedCallback=qn(p,"data-"+n+"-rendered",t);var d=qt(n),v=e.element=$t.createComment(d+":end");if(e.clone=$t.createComment(d),Vt.appendChild(v),"each"===n||"with"===n?(e.template=p.innerHTML.trim(),avalon.clearHTML(p).appendChild(v)):(e.template=p.outerHTML.trim(),p.parentNode.replaceChild(v,p)),e.template=avalon.parseHTML(e.template),e.rollback=function(){var t=e.element;if(t){Zt.repeat.call(e,"clear");var n=t.parentNode,r=e.template,a=r.firstChild;n.replaceChild(r,t);var i=e.$stamp;i&&i.parentNode&&i.parentNode.removeChild(i),a=e.element="repeat"===e.type?a:n}},!r){e.handler=Zt.repeat,e.$outer={};var h="$key",m="$val";for(Array.isArray(a)&&(h="$first",m="$last"),u=0;s=t[u++];)if(s.hasOwnProperty(h)&&s.hasOwnProperty(m)){e.$outer=s;break}var g=a.$events,y=(g||{})[At];if(y&&avalon.Array.ensure(y,e)&&M(e,y),"object"===i){e.$with=!0;var b=g?g.$withProxyPool||(g.$withProxyPool={}):{};e.handler("append",a,b)}else a.length&&e.handler("add",0,a.length)}},Zt.repeat=function(e,t,n){if(e){var a=this,i=a.element,o=i.parentNode,l=a.proxies,s=Vt.cloneNode(!1);switch(e){case"add":for(var c,u=t+n,f=a.$repeat,p=f.length-1,d=[],v=ut(a,t),h=t;u>h;h++){var m=dt(h,a);l.splice(h,0,m),ct(a,s,m,d)}for(o.insertBefore(s,v),h=0;c=d[h++];)R(c.nodes,c.vmodels),c.nodes=c.vmodels=null;break;case"del":v=l[t].$stamp,i=ut(a,t+n),ft(v,i);var g=l.splice(t,n);mt(g,"each");break;case"clear":var y=a.$stamp||l[0];y&&(v=y.$stamp||y,ft(v,i)),mt(l,"each");break;case"move":v=l[0].$stamp;var b,x=v.nodeValue,$=[],w=[];for(ft(v,i,function(){w.unshift(this),this.nodeValue===x&&($.unshift(w),w=[])}),E(l,t),E($,t);w=$.shift();)for(;b=w.shift();)s.appendChild(b);o.insertBefore(s,i);break;case"index":for(p=l.length-1;n=l[t];t++)n.$index=t,n.$first=0===t,n.$last=t===p;return;case"set":return m=l[t],void(m&&S(m.$events.$index));case"append":var C=n,T=[];d=[];for(var A in t)t.hasOwnProperty(A)&&"hasOwnProperty"!==A&&T.push(A);if(a.sortedCallback){var k=a.sortedCallback.call(o,T);k&&Array.isArray(k)&&k.length&&(T=k)}for(h=0;A=T[h++];)"hasOwnProperty"!==A&&(C[A]||(C[A]=ht(A,a)),ct(a,s,C[A],d));var M=a.$stamp=a.clone;for(o.insertBefore(M,i),o.insertBefore(s,i),h=0;c=d[h++];)R(c.nodes,c.vmodels),c.nodes=c.vmodels=null}"clear"===e&&(e="del");var O=a.renderedCallback||r,_=arguments;H(o,function(){O.apply(o,_),o.oldValue&&"SELECT"===o.tagName&&avalon(o).val(o.oldValue.split(","))},0/0)}},"with,each".replace(_t,function(e){Jt[e]=Jt.repeat});var oa=[],la=[];Zt.text=function(e,t){if(e=null==e?"":e,3===t.nodeType)try{t.data=e}catch(n){}else"textContent"in t?t.textContent=e:t.innerText=e},avalon.parseDisplay=gt,Jt.visible=function(e,t){var n=avalon(e.element),r=n.css("display");if("none"===r){var a=n[0].style,i=/visibility/i.test(a.cssText),o=n.css("visibility");a.display="",a.visibility="hidden",r=n.css("display"),"none"===r&&(r=gt(n[0].nodeName)),a.visibility=i?o:""}e.display=r,at(e.value,t,e)},Zt.visible=function(e,t,n){t.style.display=e?n.display:"none"},Jt.widget=function(t,n){var a=t.value.match(_t),i=t.element,o=a[0],l=a[1];l&&"$"!==l||(l=qt(o));var s=a[2]||o,c=avalon.ui[o];if("function"==typeof c){n=i.vmodels||n;for(var u,f=0;u=n[f++];)if(u.hasOwnProperty(s)&&"object"==typeof u[s]){var p=u[s];p=p.$model||p;break}if(p){var d=p[o+"Id"];"string"==typeof d&&(l=d)}var v=avalon.getWidgetData(i,o);t.value=[o,l,s].join(","),t[o+"Id"]=l,t.evaluator=r,i.msData["ms-widget-id"]=l;var h=t[o+"Options"]=avalon.mix({},c.defaults,p||{},v);i.removeAttribute("ms-widget");var m=c(i,t,n)||{};m.$id?(avalon.vmodels[l]=m,P(i,m),m.hasOwnProperty("$init")&&m.$init(function(){avalon.scan(i,[m].concat(n)),"function"==typeof h.onInit&&h.onInit.call(i,m,h,n)}),t.rollback=function(){try{m.widgetElement=null,m.$remove()}catch(e){}i.msData={},delete avalon.vmodels[m.$id]},M(t,sa),e.chrome&&i.addEventListener("DOMNodeRemovedFromDocument",function(){setTimeout(N)})):avalon.scan(i,n)}else n.length&&(i.vmodels=n)};var sa=[],ca=/<script[^>]*>([\S\s]*?)<\/script\s*>/gim,ua=/\s+(on[^=\s]+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,fa=/<\w+\b(?:(["'])[^"]*?(\1)|[^>])*>/gi,pa={a:/\b(href)\=("javascript[^"]*"|'javascript[^']*')/gi,img:/\b(src)\=("javascript[^"]*"|'javascript[^']*')/gi,form:/\b(action)\=("javascript[^"]*"|'javascript[^']*')/gi},da=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,va=/([^\#-~| |!])/g,ha=avalon.filters={uppercase:function(e){return e.toUpperCase()},lowercase:function(e){return e.toLowerCase()},truncate:function(e,t,n){return t=t||30,n=void 0===n?"...":n,e.length>t?e.slice(0,t-n.length)+n:String(e)},$filter:function(e){for(var t=1,n=arguments.length;n>t;t++){var r=arguments[t],a=avalon.filters[r.shift()];if("function"==typeof a){var i=[e].concat(r);e=a.apply(null,i)}}return e},camelize:Y,sanitize:function(e){return e.replace(ca,"").replace(fa,function(e){var t=e.toLowerCase().match(/<(\w+)\s/);if(t){var n=pa[t[1]];n&&(e=e.replace(n,function(e,t,n){var r=n.charAt(0);return t+"="+r+"javascript:void(0)"+r}))}return e.replace(ua," ").replace(/\s+/g," ")})},escape:function(e){return String(e).replace(/&/g,"&amp;").replace(da,function(e){var t=e.charCodeAt(0),n=e.charCodeAt(1);return"&#"+(1024*(t-55296)+(n-56320)+65536)+";"}).replace(va,function(e){return"&#"+e.charCodeAt(0)+";"}).replace(/</g,"&lt;").replace(/>/g,"&gt;")},currency:function(e,t,n){return(t||"¥")+yt(e,isFinite(n)?n:2)},number:yt};!new function(){function e(e){return parseInt(e,10)||0}function t(e,t,n){var r="";for(0>e&&(r="-",e=-e),e=""+e;e.length<t;)e="0"+e;return n&&(e=e.substr(e.length-t)),r+e}function n(e,n,r,a){return function(i){var o=i["get"+e]();return(r>0||o>-r)&&(o+=r),0===o&&-12===r&&(o=12),t(o,n,a)}}function r(e,t){return function(n,r){var a=n["get"+e](),i=(t?"SHORT"+e:e).toUpperCase();return r[i][a]}}function a(e){var n=-1*e.getTimezoneOffset(),r=n>=0?"+":"";return r+=t(Math[n>0?"floor":"ceil"](n/60),2)+t(Math.abs(n%60),2)}function i(e,t){return e.getHours()<12?t.AMPMS[0]:t.AMPMS[1]}var o={yyyy:n("FullYear",4),yy:n("FullYear",2,0,!0),y:n("FullYear",1),MMMM:r("Month"),MMM:r("Month",!0),MM:n("Month",2,1),M:n("Month",1,1),dd:n("Date",2),d:n("Date",1),HH:n("Hours",2),H:n("Hours",1),hh:n("Hours",2,-12),h:n("Hours",1,-12),mm:n("Minutes",2),m:n("Minutes",1),ss:n("Seconds",2),s:n("Seconds",1),sss:n("Milliseconds",3),EEEE:r("Day"),EEE:r("Day",!0),a:i,Z:a},l=/((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z))(.*)/,s=/^\/Date\((\d+)\)\/$/;ha.date=function(t,n){var r,a,i=ha.date.locate,c="",u=[];if(n=n||"mediumDate",n=i[n]||n,"string"==typeof t)if(/^\d+$/.test(t))t=e(t);else if(s.test(t))t=+RegExp.$1;else{var f=t.trim(),p=[0,0,0,0,0,0,0],d=new Date(0);f=f.replace(/^(\d+)\D(\d+)\D(\d+)/,function(t,n,r,a){var i=4===a.length?[a,n,r]:[n,r,a];return p[0]=e(i[0]),p[1]=e(i[1])-1,p[2]=e(i[2]),""});var v=d.setFullYear,h=d.setHours;f=f.replace(/[T\s](\d+):(\d+):?(\d+)?\.?(\d)?/,function(t,n,r,a,i){return p[3]=e(n),p[4]=e(r),p[5]=e(a),i&&(p[6]=Math.round(1e3*parseFloat("0."+i))),""});var m=0,g=0;f=f.replace(/Z|([+-])(\d\d):?(\d\d)/,function(t,n,r,a){return v=d.setUTCFullYear,h=d.setUTCHours,n&&(m=e(n+r),g=e(n+a)),""}),p[3]-=m,p[4]-=g,v.apply(d,p.slice(0,3)),h.apply(d,p.slice(3)),t=d}if("number"==typeof t&&(t=new Date(t)),"date"===avalon.type(t)){for(;n;)a=l.exec(n),a?(u=u.concat(a.slice(1)),n=u.pop()):(u.push(n),n=null);return u.forEach(function(e){r=o[e],c+=r?r(t,i):e.replace(/(^'|'$)/g,"").replace(/''/g,"'")}),c}};var c={AMPMS:{0:"上午",1:"下午"},DAY:{0:"星期日",1:"星期一",2:"星期二",3:"星期三",4:"星期四",5:"星期五",6:"星期六"},MONTH:{0:"1月",1:"2月",2:"3月",3:"4月",4:"5月",5:"6月",6:"7月",7:"8月",8:"9月",9:"10月",10:"11月",11:"12月"},SHORTDAY:{0:"周日",1:"周一",2:"周二",3:"周三",4:"周四",5:"周五",6:"周六"},fullDate:"y年M月d日EEEE",longDate:"y年M月d日",medium:"yyyy-M-d H:mm:ss",mediumDate:"yyyy-M-d",mediumTime:"H:mm:ss","short":"yy-M-d ah:mm",shortDate:"yy-M-d",shortTime:"ah:mm"};
3
- c.SHORTMONTH=c.MONTH,ha.date.locate=c};var ma=avalon.modules={"domReady!":{exports:avalon,state:3},avalon:{exports:avalon,state:4}};ma.exports=ma.avalon,new function(){function t(e,t){var r="js";e=e.replace(/^(\w+)\!/,function(e,t){return r=t,""}),"ready"===r&&(n("debug: ready!已经被废弃,请使用domReady!"),r="domReady");var a="";e=e.replace(P,function(e){return a=e,""});var i="."+r,o=/js|css/.test(i)?i:"";e=e.replace(/\.[a-z0-9]+$/g,function(e){return e===i?(o=e,""):e});var l=avalon.mix({query:a,ext:o,res:r,name:e,toUrl:m},t);return l.toUrl(e),l}function i(e){var t=e.name,n=e.res,r=ma[t],a=t&&e.urlNoQuery;if(r&&r.state>=1)return t;if(r=ma[a],r&&r.state>=3)return Tt(r.deps||[],r.factory,a),a;if(t&&!r){r=ma[a]={id:a,state:1};var i=function(a){H[n]=a,a.load(t,e,function(e){arguments.length&&void 0!==e&&(r.exports=e),r.state=4,s()})};H[n]?i(H[n]):Tt([n],i)}return t?a:n+"!"}function o(e,t){for(var n,r=0;n=e[r++];)if(4!==ma[n].state&&(n===t||o(ma[n].deps,t)))return!0}function l(e,t,r){var a=u(e.src);return e.onload=e.onreadystatechange=e.onerror=null,t||r&&ma[a]&&!ma[a].state?(setTimeout(function(){wt.removeChild(e),e=null}),void n("debug: 加载 "+a+" 失败"+t+" "+!ma[a].state)):!0}function s(){e:for(var e,t=E.length;e=E[--t];){var n=ma[e],r=n.deps;if(r){for(var a,i=0;a=r[i];i++)if(4!==Object(ma[a]).state)continue e;4!==n.state&&(E.splice(t,1),v(n.id,n.deps,n.factory),s())}}}function c(e,t,r){function a(){if(!"1"[0]&&!o)return o=setTimeout(a,150);if(c||j.test(i.readyState)){clearTimeout(o);var u=A.pop();u&&u.require(t),r&&r(),l(i,!1,!c)&&(n("debug: 已成功加载 "+e),t&&E.push(t),s())}}var i=$t.createElement("script");i.className=At;var o,c="onload"in i,u=c?"onload":"onreadystatechange";i[u]=a,i.onerror=function(){l(i,!0)},wt.insertBefore(i,wt.firstChild),i.src=e,n("debug: 正准备加载 "+e)}function u(e){return(e||"").replace(P,"")}function f(e){return/^(?:[a-z]+:)?\/\//i.test(String(e))}function p(e,t){return"1"[0]?e[t]:e.getAttribute(t,4)}function d(){var t;try{a.b.c()}catch(n){t=n.stack,!t&&e.opera&&(t=(String(n).match(/of linked script \S+/g)||[]).join(" "))}if(t)return t=t.split(/[@ ]/g).pop(),t="("===t[0]?t.slice(1,-1):t.replace(/\s/,""),u(t.replace(/(:\d+)?:\d+$/i,""));for(var r,i=wt.getElementsByTagName("script"),o=i.length;r=i[--o];)if(r.className===At&&"interactive"===r.readyState){var l=p(r,"src");return r.className=u(l)}}function v(t,r,a){var i=Object(ma[t]);i.state=4;for(var o,l=0,s=[];o=r[l++];)if("exports"===o){var c=i.exports||(i.exports={});s.push(c)}else s.push(ma[o].exports);try{var u=a.apply(e,s)}catch(f){n("执行["+t+"]模块的factory抛错: "+f)}return void 0!==u&&(i.exports=u),D.test(t)&&delete ma[t],delete i.factory,u}function m(e){0===e.indexOf(this.res+"!")&&(e=e.slice(this.res.length+1));var t=e,n=0,r=this.baseUrl,a=this.parentUrl||r;$(e,h.paths,function(e,r){t=t.replace(r,e),n=1}),n||$(e,h.packages,function(e,n,r){t=t.replace(r.name,r.location)}),this.mapUrl&&$(this.mapUrl,h.map,function(e){$(t,e,function(e,n){t=t.replace(n,e),a=r})});var i=this.ext;i&&n&&t.slice(-i.length)===i&&(t=t.slice(0,-i.length)),f(t)||(a=this.built||/^\w/.test(t)?r:a,t=C(a,t));var o=t+i;return t=o+this.query,$(e,h.urlArgs,function(e){t+=(-1===t.indexOf("?")?"?":"&")+e}),this.url=t,this.urlNoQuery=o}function g(e,t,n){var r=x(e,t,n);return r.sort(w),r}function y(e){return new RegExp("^"+e+"(/|$)")}function b(t){return function(){var n;return t.init&&(n=t.init.apply(e,arguments)),n||t.exports&&T(t.exports)}}function x(e,t,n){var r=[];for(var a in e)if(Ht.call(e,a)){var i={name:a,val:e[a]};r.push(i),i.reg="*"===a&&t?/^/:y(a),n&&"*"!==a&&(i.reg=new RegExp("/"+a.replace(/^\//,"")+"(/|$)"))}return r}function $(e,t,n){t=t||[];for(var r,a=0;r=t[a++];)if(r.reg.test(e))return n(r.val,r.name,r),!1}function w(e,t){var n=e.name,r=t.name;return"*"===r?-1:"*"===n?1:r.length-n.length}function C(e,t){if("/"!==e.charAt(e.length-1)&&(e+="/"),"./"===t.slice(0,2))return e+t.slice(2);if(".."===t.slice(0,2)){for(e+=t;F.test(e);)e=e.replace(F,"");return e}return"/"===t.slice(0,1)?e+t.slice(1):e+t}function T(t){if(!t)return t;var n=e;return t.split(".").forEach(function(e){n=n[e]}),n}var E=[],A=[],k=/\.js$/i,M=[],O=!1;Tt=avalon.require=function(e,n,a,o){if(O){Array.isArray(e)||avalon.error("require方法的第一个参数应为数组 "+e);var l=[],c={},u=a||"callback"+setTimeout("1");o=o||{},o.baseUrl=h.baseUrl;var f=!!o.built;if(a&&(o.parentUrl=a.substr(0,a.lastIndexOf("/")),o.mapUrl=a.replace(k,"")),f){var p=t(o.defineName,o);u=p.urlNoQuery}else e.forEach(function(e){var n=t(e,o),r=i(n);r&&(c[r]||(l.push(r),c[r]="司徒正美"))});var d=ma[u];d&&4===d.state||(ma[u]={id:u,deps:f?e.concat():l,factory:n||r,state:3}),d||E.push(u),s()}else if(M.push(avalon.slice(arguments)),arguments.length<=2){O=!0;for(var v,m=M.splice(0,M.length);v=m.shift();)Tt.apply(null,v)}},Tt.define=function(e,t,n){"string"!=typeof e&&(n=t,t=e,e="anonymous"),Array.isArray(t)||(n=t,t=[]);var r={built:!O,defineName:e},a=[t,n,r];n.require=function(e){if(a.splice(2,0,e),ma[e]){ma[e].state=3;var t=!1;try{t=o(ma[e].deps,e)}catch(r){}t&&avalon.error(e+"模块与之前的模块存在循环依赖,请不要直接用script标签引入"+e+"模块")}delete n.require,Tt.apply(null,a)};var i=r.built?"unknown":d();if(i){var l=ma[i];l&&(l.state=2),n.require(i)}else A.push(n)},Tt.config=h,Tt.define.amd=ma;var _=h["orig.paths"]={},N=h["orig.map"]={},S=h.packages=[],L=h["orig.args"]={};avalon.mix(gn,{paths:function(e){avalon.mix(_,e),h.paths=g(_)},map:function(e){avalon.mix(N,e);var t=g(N,1,1);avalon.each(t,function(e,t){t.val=g(t.val)}),h.map=t},packages:function(e){e=e.concat(S);for(var t,n={},r=[],a=0;t=e[a++];){t="string"==typeof t?{name:t}:t;var i=t.name;if(!n[i]){var o=t.location?t.location:C(i,t.main||"main");o=o.replace(k,""),r.push(t),n[i]=t.location=o,t.reg=y(i)}}h.packages=r.sort()},urlArgs:function(e){"string"==typeof e&&(e={"*":e}),avalon.mix(L,e),h.urlArgs=g(L,1)},baseUrl:function(e){if(!f(e)){var t=wt.getElementsByTagName("base")[0];t&&wt.removeChild(t);var n=$t.createElement("a");n.href=e,e=p(n,"href"),t&&wt.insertBefore(t,wt.firstChild)}e.length>3&&(h.baseUrl=e)},shim:function(e){for(var t in e){var n=e[t];Array.isArray(n)&&(n=e[t]={deps:n}),n.exportsFn||!n.exports&&!n.init||(n.exportsFn=b(n))}h.shim=e}});var j=$t.documentMode>=8?/loaded/:/complete|loaded/,H=Tt.plugins={ready:{load:r},js:{load:function(e,t,n){var r=t.url,a=t.urlNoQuery,i=h.shim[e.replace(k,"")];i?Tt(i.deps||[],function(){var e=avalon.slice(arguments);c(r,a,function(){n(i.exportsFn?i.exportsFn.apply(0,e):void 0)})}):c(r,a)}},css:{load:function(e,t,r){var a=t.url,i=$t.createElement("link");i.rel="stylesheet",i.href=a,wt.insertBefore(i,wt.firstChild),n("debug: 已成功加载 "+a),r()}},text:{load:function(e,t,r){var a=t.url,i=Qr();i.onreadystatechange=function(){if(4===i.readyState){var e=i.status;e>399&&600>e?avalon.error(a+" 对应资源不存在或没有开启 CORS"):(n("debug: 已成功加载 "+a),r(i.responseText))}},i.open("GET",a,!0),"withCredentials"in i&&(i.withCredentials=!0),i.setRequestHeader("X-Requested-With","XMLHttpRequest"),i.send(),n("debug: 正准备加载 "+a)}}};Tt.checkDeps=s;var P=/(\?[^#]*)$/,D=/^callback\d+$/,F=/\/\w+\/\.\./,B=$t.scripts[$t.scripts.length-1],I=B.getAttribute("data-main");if(I){gn.baseUrl(I);var R=h.baseUrl;h.baseUrl=R.slice(0,R.lastIndexOf("/")+1),c(R.replace(k,"")+".js")}else{var V=u(p(B,"src"));h.baseUrl=V.slice(0,V.lastIndexOf("/")+1)}};var ga,ya=[],ba=function(e){for(ga=!0,Tt&&(ma["domReady!"].state=4,Tt.checkDeps());e=ya.shift();)e(avalon)};if("complete"===$t.readyState)setTimeout(ba);else if(It)$t.addEventListener("DOMContentLoaded",ba);else{$t.attachEvent("onreadystatechange",function(){"complete"===$t.readyState&&ba()});try{var xa=null===e.frameElement}catch(kn){}Rt.doScroll&&xa&&e.external&&bt()}avalon.bind(e,"load",ba),avalon.ready=function(e){ga?e(avalon):ya.push(e)},avalon.config({loader:!0}),avalon.ready(function(){avalon.scan($t.body)}),"function"==typeof define&&define.amd&&define("avalon",[],function(){return avalon});var $a=e.avalon;return avalon.noConflict=function(t){return t&&e.avalon===avalon&&(e.avalon=$a),avalon},void 0===t&&(e.avalon=avalon),avalon});
1
+ !function(e,t){"object"==typeof module&&"object"==typeof module.exports?module.exports=e.document?t(e,!0):function(e){if(!e.document)throw new Error("Avalon requires a window with a document");return t(e)}:t(e)}("undefined"!=typeof window?window:this,function(e,t){function n(){e.console&&avalon.config.debug&&Function.apply.call(console.log,console,arguments)}function r(){}function i(e,t){"string"==typeof e&&(e=e.match(Pt)||[]);for(var n={},r=void 0!==t?t:1,a=0,i=e.length;i>a;a++)n[e[a]]=r;return n}function o(){if(e.VBArray){var t=document.documentMode;return t?t:e.XMLHttpRequest?7:6}return 0/0}function l(e){return Rt.test(zt.call(e))}function s(e,t){return e=Math.floor(e)||0,0>e?Math.max(t+e,0):Math.min(e,t)}function c(e){if(!e)return!1;var t=e.length;if(t===t>>>0){var n=zt.call(e).slice(8,-1);if(/(?:regexp|string|function|window|global)$/i.test(n))return!1;if("Array"===n)return!0;try{return{}.propertyIsEnumerable.call(e,"length")===!1?/^\s?function/.test(e.item||e.callee):!0}catch(r){return!e.window}}return!1}function u(e,t,n){var r="for(var "+e+"i=0,n = this.length; i < n; i++){"+t.replace("_","((i in this) && fn.call(scope,this[i],i,this))")+"}"+n;return Function("fn,scope",r)}function f(e,t){try{for(;t=t.parentNode;)if(t===e)return!0;return!1}catch(n){return!1}}function p(){return(new XMLSerializer).serializeToString(this)}function d(e,t){if(e&&e.childNodes)for(var n,r=e.childNodes,a=0;n=r[a++];)if(n.tagName){var i=_t.createElementNS(fn,n.tagName.toLowerCase());Ut.forEach.call(n.attributes,function(e){i.setAttribute(e.name,e.value)}),d(n,i),t.appendChild(i)}}function v(e){var t={};for(var n in e)t[n]=e[n];var r=t.target=e.srcElement;if(0===e.type.indexOf("key"))t.which=null!=e.charCode?e.charCode:e.keyCode;else if(dn.test(e.type)){var a=r.ownerDocument||_t,i="BackCompat"===a.compatMode?a.body:a.documentElement;t.pageX=e.clientX+(i.scrollLeft>>0)-(i.clientLeft>>0),t.pageY=e.clientY+(i.scrollTop>>0)-(i.clientTop>>0),t.wheelDeltaY=t.wheelDelta,t.wheelDeltaX=0}return t.timeStamp=new Date-0,t.originalEvent=e,t.preventDefault=function(){e.returnValue=!1},t.stopPropagation=function(){e.cancelBubble=!0},t}function h(e){for(var t in e)if(Vt.call(e,t)){var n=e[t];"function"==typeof h.plugins[t]?h.plugins[t](n):"object"==typeof h[t]?avalon.mix(h[t],n):h[t]=n}return this}function m(e){return(e+"").replace($n,"\\$&")}function g(e,t,n){if(Array.isArray(e)){var r=e.concat();e.length=0;var a=_(e);return a.pushArray(r),a}if(!e||e.nodeType>0||e.$id&&e.$events)return e;var i=Array.isArray(e.$skipArray)?e.$skipArray:[];i.$special=t||{};var o={};n=n||{};var l={},s={},c=[];_n.forEach(function(t){delete e[t]});var u=Object.keys(e);u.forEach(function(t,r){var a=e[t];if(n[t]=a,T(t,a,i)){l[t]=[];var o=avalon.type(a);"object"===o&&Kt(a.get)&&Object.keys(a).length<=2?(r=x(t,a),c.push(r)):r=Ft.test(o)?w(t,a,o,l[t],n):b(t,a),s[t]=r}}),o=Mn(o,Ln(s),e);for(var f=0;f<u.length;f++){var p=u[f];s[p]||(o[p]=e[p])}y(o,"$id",Zt()),y(o,"$model",n),y(o,"$events",l),Nn?y(o,"hasOwnProperty",function(e){return e in o.$model}):o.hasOwnProperty=function(e){return e in o.$model&&"hasOwnProperty"!==e};for(f in En)y(o,f,En[f].bind(o));return o.$reinitialize=function(){c.forEach(function(e){delete e._value,delete e.oldArgs,e.digest=function(){e.call(o)},Fn.begin({callback:function(t,n){var r=n._name;if(n!==e){var a=t.$events[r];M(a,e.digest)}}});try{e.get.call(o)}finally{Fn.end()}})},o.$reinitialize(),o}function y(e,t,n){Nn?Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!1,configurable:!0}):e[t]=n}function b(e,t){function n(e){var t=n._value;return arguments.length>0?(Dt||jn(e,t)||(n.updateValue(this,e),n.notify(this,e,t)),this):(Fn.collectDependency(this,n),t)}return k(n,e),n._value=t,n}function x(e,t){function n(t){var r=n._value,a="_value"in n;if(arguments.length>0){if(Dt)return this;if("function"==typeof n.set&&n.oldArgs!==t){n.oldArgs=t;var i=this.$events,o=i[e];i[e]=[],n.set.call(this,t),i[e]=o,t=n.get.call(this),t!==r&&(n.updateValue(this,t),n.notify(this,t,r))}return this}return t=n.get.call(this),n.updateValue(this,t),a&&r!==t&&n.notify(this,t,r),t}return n.set=t.set,n.get=t.get,k(n,e),n}function w(e,t,n,r,a){function i(t){var r=i._value,a=i._vmodel;if(arguments.length>0){if(Dt)return this;if("array"===n){var o=a,l=t,s=o.length,c=l.length;o.$lock=!0,s>c?o.splice(c,s-c):c>s&&o.push.apply(o,l.slice(s));for(var u=Math.min(s,c),f=0;u>f;f++)o.set(f,l[f]);delete o.$lock,o._fire("set")}else if("object"===n){var p=this.$events[e]||[],d=avalon.mix(!0,{},t);for(f in a)a.hasOwnProperty(f)&&Vt.call(d,f)&&(a[f]=d[f]);a=i._vmodel=g(t),a.$events[jt]=p,p.length&&p.forEach(function(e){e.type&&(e.rollback&&e.rollback(),nn[e.type](e,e.vmodels))})}return i.updateValue(this,a.$model),i.notify(this,this._value,r),this}return Fn.collectDependency(this,i),a}k(i,e),a[e]=Array.isArray(t)?t:a[e]||{};var o=i._vmodel=g(t,0,a[e]);return o.$events[jt]=r,i}function $(e,t){e.$model[this._name]=this._value=t}function C(e,t,n){var r=this._name,a=e.$events[r];a&&(S(a),En.$fire.call(e,r,t,n))}function k(e,t){e._name=t,e.updateValue=$,e.notify=C}function T(e,t,n){if(Kt(t)||t&&t.nodeType)return!1;if(-1!==n.indexOf(e))return!1;var r=n.$special;return e&&"$"===e.charAt(0)&&!r[e]?!1:!0}function E(e){for(var t=Object.keys(e.$model?e.$model:e),n=0;n<_n.length;n++){var r=t.indexOf(_n[n]);-1!==r&&t.splice(r,1)}return t}function A(e,t,n,r){var a=t[n];return 4!==arguments.length?a.call(e):void a.call(e,r)}function _(e){var t=[];t.$id=Zt(),t.$model=e,t.$events={},t.$events[jt]=[],t._=g({length:e.length}),t._.$watch("length",function(e,n){t.$fire("length",e,n)});for(var n in En)t[n]=En[n];return avalon.mix(t,Pn),t}function O(e,t,n,r,a,i,o){for(var l=this.length,s=2;--s;){switch(e){case"add":var c=this.$model.slice(t,t+n).map(function(e){return Ft.test(avalon.type(e))?e.$id?e:g(e,0,e):e});Dn.apply(this,[t,0].concat(c)),this._fire("add",t,n);break;case"del":var u=this._splice(t,n);this._fire("del",t,n)}a&&(e=a,t=i,n=o,s=2,a=0)}return this._fire("index",r),this.length!==l&&(this._.length=this.length),u}function N(e,t){for(var n={},r=0,a=t.length;a>r;r++){n[r]=e[r];var i=t[r];i in n?(e[r]=n[i],delete n[i]):e[r]=e[i]}}function M(e,t){t.oneTime||e&&avalon.Array.ensure(e,t)&&t.element&&(L(t,e),new Date-Vn>444&&H())}function S(e){if(e&&e.length){new Date-Vn>444&&"object"==typeof e[0]&&H();for(var t,n=qt.call(arguments,1),r=e.length;t=e[--r];){var a=t.element;if(a&&a.parentNode)try{var i=t.evaluator;if(t.$repeat)t.handler.apply(t,n);else if("$repeat"in t||!i)nn[t.type](t,t.vmodels);else if("on"!==t.type){var o=i.apply(0,t.args||[]);t.handler(o,a,t)}}catch(l){console.log(l)}}}}function j(e,t){return e.uuid||t||(e.uuid=++Rn),e.uuid}function L(e,t){var n=e.element;e.uuid||(e.uuid=1!==n.nodeType?e.type+(e.pos||0)+"-"+j(n.parentNode):e.name+"-"+j(n));var r=e.lists||(e.lists=[]);avalon.Array.ensure(r,t),t.$uuid=t.$uuid||Zt(),In[e.uuid]||(In[e.uuid]=1,In.push(e))}function H(e){if(!avalon.optimize){for(var t=In.length,n=t,r=[],a={},i={};e=In[--t];){var o=e.type;i[o]?i[o]++:(i[o]=1,r.push(o))}var l=!1;if(r.forEach(function(e){zn[e]!==i[e]&&(a[e]=1,l=!0)}),t=n,l)for(;e=In[--t];)if(null!==e.element){if(a[e.type]&&P(e.element)){In.splice(t,1),delete In[e.uuid];for(var s,c=e.lists,u=0;s=c[u++];)avalon.Array.remove(c,s),avalon.Array.remove(s,e);D(e)}}else In.splice(t,1);zn=i,Vn=new Date}}function D(e){delete In[e.uuid],e.element=null,e.rollback&&e.rollback();for(var t in e)e[t]=null}function P(e){try{{e.parentNode.nodeType}}catch(t){return!0}return e.ifRemove&&!Xt.contains(e.ifRemove)&&Nt===e.parentNode?(e.parentNode&&e.parentNode.removeChild(e),!0):e.msRetain?0:1===e.nodeType?!Xt.contains(e):!avalon.contains(Xt,e)}function F(e){var t=e.nodeName;return t.toLowerCase()===t&&e.scopeName&&""===e.outerText}function B(e){"url(#default#VML)"!==e.currentStyle.behavior&&(e.style.behavior="url(#default#VML)",e.style.display="inline-block",e.style.zoom=1)}function R(e){return e.replace(/([a-z\d])([A-Z]+)/g,"$1-$2").toLowerCase()}function I(e){return!e||e.indexOf("-")<0&&e.indexOf("_")<0?e:e.replace(/[-_][^-_]/g,function(e){return e.charAt(1).toUpperCase()})}function V(e){if(!("classList"in e)){e.classList={node:e};for(var t in Qn)e.classList[t.slice(1)]=Qn[t]}return e.classList}function z(e){try{if("object"==typeof e)return e;e="true"===e?!0:"false"===e?!1:"null"===e?null:+e+""===e?+e:Kn.test(e)?avalon.parseJSON(e):e}catch(t){}return e}function U(e){return e.window&&e.document?e:9===e.nodeType?e.defaultView||e.parentWindow:!1}function q(e,t){if(e.offsetWidth<=0){if(vr.test(ar["@:get"](e,"display"))){var n={node:e};for(var r in dr)n[r]=e.style[r],e.style[r]=dr[r];t.push(n)}var a=e.parentNode;a&&1===a.nodeType&&q(a,t)}}function W(e){var t=e.tagName.toLowerCase();return"input"===t&&/checkbox|radio/.test(e.type)?"checked":t}function X(e,t,n,r){for(var a,i=[],o=" = "+n+".",l=e.length;a=e[--l];)t.hasOwnProperty(a)&&(i.push(a+o+a),r.vars.push(a),"duplex"===r.type&&(e.get=n+"."+a),e.splice(l,1));return i}function Y(e){for(var t=[],n={},r=0;r<e.length;r++){var a=e[r],i=a&&"string"==typeof a.$id?a.$id:a;n[i]||(n[i]=t.push(a))}return t}function G(e,t){return t=t.replace(Nr,"").replace(Mr,function(){return"],|"}).replace(Sr,function(e,t){return"["+yr(t)}).replace(jr,function(){return'"],["'}).replace(Lr,function(){return'",'})+"]","return this.filters.$filter("+e+", "+t+")"}function J(e,t,a){var i=a.type,o=a.filters||"",l=t.map(function(e){return String(e.$id).replace(Or,"$1")})+e+i+o,s=Er(e).concat(),c=[],u=[],f=[],p="";t=Y(t),a.vars=[];for(var d=0,v=t.length;v>d;d++)if(s.length){var h="vm"+At+"_"+d;u.push(h),f.push(t[d]),c.push.apply(c,X(s,t[d],h,a))}if(c.length||"duplex"!==i){"duplex"!==i&&(e.indexOf("||")>-1||e.indexOf("&&")>-1)&&a.vars.forEach(function(t){var n=new RegExp("\\b"+t+"(?:\\.\\w+|\\[\\w+\\])+","ig");e=e.replace(n,function(n,r){var a=n.charAt(t.length),i=e.slice(r+n.length),o=/^\s*\(/.test(i);if("."===a||"["===a||o){var l="var"+String(Math.random()).replace(/^0\./,"");if(o){var s=n.split(".");if(s.length>2){var u=s.pop();return c.push(l+" = "+s.join(".")),l+"."+u}return n}return c.push(l+" = "+n),l}return n})}),a.args=f,delete a.vars;var m=Ar.get(l);if(m)return void(a.evaluator=m);if(p=c.join(", "),p&&(p="var "+p),/\S/.test(o)){if(!/text|html/.test(a.type))throw Error("ms-"+a.type+"不支持过滤器");e="\nvar ret"+At+" = "+e+";\r\n",e+=G("ret"+At,o);try{m=Function.apply(r,u.concat("'use strict';\n"+p+e)),a.evaluator=Ar.put(l,function(){return m.apply(avalon,arguments)})}catch(g){n("debug: parse error,"+g.message)}return void(s=c=u=null)}if("duplex"===i){var y="'use strict';\nreturn function(vvv){\n "+p+";\n if(!arguments.length){\n return "+e+"\n }\n "+(_r.test(e)?e:s.get)+"= vvv;\n} ";try{m=Function.apply(r,u.concat(y)),a.evaluator=Ar.put(l,m)}catch(g){n("debug: parse error,"+g.message)}return void(s=c=u=null)}if("on"===i){-1===e.indexOf("(")?e+=".call(this, $event)":e=e.replace("(",".call(this,"),u.push("$event"),e="\nreturn "+e+";";var b=e.lastIndexOf("\nreturn"),x=e.slice(0,b),w=e.slice(b);e=x+"\n"+w}else e="\nreturn "+e+";";try{m=Function.apply(r,u.concat("'use strict';\n"+p+e)),a.evaluator=Ar.put(l,m)}catch(g){n("debug: parse error,"+g.message)}s=c=u=null}}function Z(e){var t=bn.test(e);if(t){var n=st(e);return 1===n.length?n[0].value:n.map(function(e){return e.expr?"("+e.value+")":yr(e.value)}).join(" + ")}return e}function Q(e,t,n,r){e=e||"",J(e,t,n),n.evaluator&&!r&&(n.handler=rn[n.handlerName||n.type],avalon.injectBinding(n))}function K(e,t,n){var r=setTimeout(function(){var a=e.innerHTML;clearTimeout(r),a===n?t():K(e,t,a)})}function et(e,t){var n=e.getAttribute("avalonctrl")||t.$id;e.setAttribute("avalonctrl",n),t.$events.expr=e.tagName+'[avalonctrl="'+n+'"]'}function tt(e,t){for(var n,r=0;n=e[r++];)n.vmodels=t,nn[n.type](n,t),n.evaluator&&n.element&&1===n.element.nodeType&&n.element.removeAttribute(n.name);e.length=0}function nt(e,t){return e.priority-t.priority}function rt(e,t,r){var a=!0;if(t.length){for(var i,o=Jr?Jr(e):e.attributes,l=[],s=[],c={},u={},f=0;i=o[f++];)if(i.specified&&(r=i.name.match(Br))){var p=r[1],d=r[2]||"",v=i.value,h=i.name;if(u[h])continue;if(u[h]=1,Ir[p]?(d=p,p="on"):Vr[p]&&("enabled"===p&&(n("warning!ms-enabled或ms-attr-enabled已经被废弃"),p="disabled",v="!("+v+")"),d=p,p="attr",h="ms-"+p+"-"+d,s.push([i.name,h,v])),c[h]=v,"function"==typeof nn[p]){var m=v.replace(Fr,""),g=v!==m,y={type:p,param:d,element:e,name:h,value:m,oneTime:g,uuid:h+"-"+j(e),priority:(Rr[p]||10*p.charCodeAt(0))+(Number(d.replace(/\D/g,""))||0)};if("html"===p||"text"===p){var b=lt(v);avalon.mix(y,b),y.filters=y.filters.replace(Zr,function(){return y.type="html",y.group=1,""})}else if("duplex"===p)var x=h;else"ms-if-loop"===h&&(y.priority+=100);l.push(y),"widget"===p&&(e.msData=e.msData||c)}}if(l.length){for(l.sort(nt),s.forEach(function(t){n("warning!请改用"+t[1]+"代替"+t[0]+"!"),e.removeAttribute(t[0]),e.setAttribute(t[1],t[2])}),x&&c["ms-attr-value"]&&!e.scopeName&&"text"===e.type&&n("warning!一个控件不能同时定义ms-attr-value与"+x),f=0;y=l[f];f++){if(p=y.type,zr.test(p))return tt(l.slice(0,f+1),t);a&&(a=!Ur.test(p))}tt(l,t)}}a&&!Hr[e.tagName]&&wn.test(e.innerHTML.replace(Kr,"<").replace(ea,">"))&&(Pr&&Pr(e),at(e,t))}function at(e,t){var n=avalon.slice(e.childNodes);it(n,t)}function it(e,t){for(var n,r=0;n=e[r++];)switch(n.nodeType){case 1:ot(n,t),n.msCallback&&(n.msCallback(),n.msCallback=void 0);break;case 3:bn.test(n.nodeValue)&&ct(n,t,r)}}function ot(e,t,r){var a=e.getAttribute("ms-skip");if(!e.getAttributeNode)return n("warning "+e.tagName+" no getAttributeNode method");var i=e.getAttributeNode("ms-important"),o=e.getAttributeNode("ms-controller");if("string"!=typeof a){if(r=i||o){var l=avalon.vmodels[r.value];if(!l)return;t=r===i?[l]:[l].concat(t);var s=r.name;e.removeAttribute(s),avalon(e).removeClass(s),et(e,l)}rt(e,t)}}function lt(e){if(e.indexOf("|")>0){var t=e.replace(ta,function(e){return Array(e.length+1).join("1")}),n=t.replace(Qr,"ᄢ㍄").indexOf("|");if(n>-1)return{filters:e.slice(n),value:e.slice(0,n),expr:!0}}return{value:e,filters:"",expr:!0}}function st(e){for(var t,n,r=[],a=0;;){if(n=e.indexOf(gn,a),-1===n)break;if(t=e.slice(a,n),t&&r.push({value:t,filters:"",expr:!1}),a=n+gn.length,n=e.indexOf(yn,a),-1===n)break;t=e.slice(a,n),t&&r.push(lt(t,a)),a=n+yn.length}return t=e.slice(a),t&&r.push({value:t,expr:!1,filters:""}),r}function ct(e,t,n){var r=[];if(tokens=st(e.data),tokens.length){for(var a=0;token=tokens[a++];){var i=_t.createTextNode(token.value);token.expr&&(token.value=token.value.replace(Fr,function(){return token.oneTime=!0,""}),token.type="text",token.element=i,token.filters=token.filters.replace(Zr,function(){return token.type="html",""}),token.pos=1e3*n+a,r.push(token)),Yt.appendChild(i)}e.parentNode.replaceChild(Yt,e),r.length&&tt(r,t)}}function ut(e,t,n){var r=e.templateCache&&e.templateCache[t];if(r){for(var a,i=_t.createDocumentFragment();a=r.firstChild;)i.appendChild(a);return i}return avalon.parseHTML(n)}function ft(e){return null==e?"":e}function pt(e,t,n){return t.param.replace(/\w+/g,function(r){var a=avalon.duplexHooks[r];a&&"function"==typeof a[n]&&(e=a[n](e,t))}),e}function dt(){for(var e=pa.length-1;e>=0;e--){var t=pa[e];t()===!1&&pa.splice(e,1)}pa.length||clearInterval(fa)}function vt(e,t,n,r){var a=e.template.cloneNode(!0),i=avalon.slice(a.childNodes);a.insertBefore(_t.createComment(e.signature),a.firstChild),t.appendChild(a);var o=[n].concat(e.vmodels),l={nodes:i,vmodels:o};r.push(l)}function ht(e){for(var t,n=[],r=e.element.parentNode.childNodes,a=0;t=r[a++];)if(t.nodeValue===e.signature)n.push(t);else if(t.nodeValue===e.signature+":end")break;return n}function mt(e,t,n){for(;;){var r=t.previousSibling;if(!r)break;if(r.parentNode.removeChild(r),n&&n.call(r),r===e)break}}function gt(){var e=g({$key:"",$outer:{},$host:{},$val:{get:function(){return this.$host[this.$key]},set:function(e){this.$host[this.$key]=e}}},{$val:1});return e.$id=Zt("$proxy$with"),e}function yt(e,t,n){e=e||ma.pop(),e?e.$reinitialize():e=gt();var r=n.$repeat;return e.$key=t,e.$host=r,e.$outer=n.$outer,r.$events?e.$events.$val=r.$events[t]:e.$events={},e}function bt(e){xt(e)}function xt(e){e.forEach(function(e){Ct(e,ga)}),e.length=0}function wt(e){var t={$host:[],$outer:{},$index:0,$first:!1,$last:!1,$remove:avalon.noop};t[e]={get:function(){var t=this.$events,n=t.$index;t.$index=t[e];try{return this.$host[this.$index]}finally{t.$index=n}},set:function(e){try{var t=this.$events,n=t.$index;t.$index=[],this.$host.set(this.$index,e)}finally{t.$index=n}}};var n={$last:1,$first:1,$index:1},r=g(t,n);return r.$id=Zt("$proxy$each"),r}function $t(e,t){for(var n,r=t.param||"el",a=0,i=ga.length;i>a;a++){var o=ga[a];o&&o.hasOwnProperty(r)&&(n=o,ga.splice(a,1))}n||(n=wt(r));var l=t.$repeat,s=l.length-1;return n.$index=e,n.$first=0===e,n.$last=e===s,n.$host=l,n.$outer=t.$outer,n.$remove=function(){return l.removeAt(n.$index)},n}function Ct(e,t){for(var n in e.$events){var r=e.$events[n];Array.isArray(r)&&(r.forEach(function(e){"object"==typeof e&&D(e)}),r.length=0)}e.$host=e.$outer={},t.unshift(e)>h.maxRepeatSize&&t.pop()}function kt(e,t){var n="_"+e;if(!kt[n]){var r=_t.createElement(e);Xt.appendChild(r),t=Wt?getComputedStyle(r,null).display:r.currentStyle.display,Xt.removeChild(r),kt[n]=t}return kt[n]}function Tt(e,t,n,r){e=(e+"").replace(/[^0-9+\-Ee.]/g,"");var a=isFinite(+e)?+e:0,i=isFinite(+t)?Math.abs(t):3,o=r||",",l=n||".",s="",c=function(e,t){var n=Math.pow(10,t);return""+(Math.round(e*n)/n).toFixed(t)};return s=(i?c(a,i):""+Math.round(a)).split("."),s[0].length>3&&(s[0]=s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g,o)),(s[1]||"").length<i&&(s[1]=s[1]||"",s[1]+=new Array(i-s[1].length+1).join("0")),s.join(l)}function Et(){try{Xt.doScroll("left"),Oa()}catch(e){setTimeout(Et)}}var At=new Date-0,_t=e.document,Ot=_t.getElementsByTagName("head")[0],Nt=Ot.insertBefore(document.createElement("avalon"),Ot.firstChild);Nt.innerHTML="X<style id='avalonStyle'>.avalonHide{ display: none!important }</style>",Nt.setAttribute("ms-skip","1"),Nt.className="avalonHide";var Mt,St=/\[native code\]/,jt="$"+At,Lt=e.require,Ht=e.define,Dt=!1,Pt=/[^, ]+/g,Ft=/^(?:object|array)$/,Bt=/^\[object SVG\w*Element\]$/,Rt=/^\[object (?:Window|DOMWindow|global)\]$/,It=Object.prototype,Vt=It.hasOwnProperty,zt=It.toString,Ut=Array.prototype,qt=Ut.slice,Wt=e.dispatchEvent,Xt=_t.documentElement,Yt=_t.createDocumentFragment(),Gt=_t.createElement("div"),Jt={};"Boolean Number String Function Array Date RegExp Object Error".replace(Pt,function(e){Jt["[object "+e+"]"]=e.toLowerCase()});var Zt=function(e){return e=e||"avalon",String(Math.random()+Math.random()).replace(/\d\.\d{4}/,e)},Qt=o();avalon=function(e){return new avalon.init(e)},avalon.profile=function(){e.console&&avalon.config.profile&&Function.apply.call(console.log,console,arguments)},avalon.nextTick=new function(){function t(){for(var e=a.length,t=0;e>t;t++)a[t]();a=a.slice(e)}var n=e.setImmediate,r=e.MutationObserver;if(n)return n.bind(e);var a=[];if(r){var i=document.createTextNode("avalon");return new r(t).observe(i,{characterData:!0}),function(e){a.push(e),i.data=Math.random()}}return e.VBArray?function(e){a.push(e);var n=_t.createElement("script");n.onreadystatechange=function(){t(),n.onreadystatechange=null,Ot.removeChild(n),n=null},Ot.appendChild(n)}:function(e){setTimeout(e,4)}},avalon.init=function(e){this[0]=this.element=e},avalon.fn=avalon.prototype=avalon.init.prototype,avalon.type=function(e){return null==e?String(e):"object"==typeof e||"function"==typeof e?Jt[zt.call(e)]||"object":typeof e};var Kt="object"==typeof alert?function(e){try{return/^\s*\bfunction\b/.test(e+"")}catch(t){return!1}}:function(e){return"[object Function]"===zt.call(e)};avalon.isFunction=Kt,avalon.isWindow=function(e){return e?e==e.document&&e.document!=e:!1},l(e)&&(avalon.isWindow=l);var en;for(en in avalon({}))break;var tn="0"!==en;avalon.isPlainObject=function(e,t){if(!e||"object"!==avalon.type(e)||e.nodeType||avalon.isWindow(e))return!1;try{if(e.constructor&&!Vt.call(e,"constructor")&&!Vt.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(n){return!1}if(tn)for(t in e)return Vt.call(e,t);for(t in e);return void 0===t||Vt.call(e,t)},St.test(Object.getPrototypeOf)&&(avalon.isPlainObject=function(e){return"[object Object]"===zt.call(e)&&Object.getPrototypeOf(e)===It}),avalon.mix=avalon.fn.mix=function(){var e,t,n,r,a,i,o=arguments[0]||{},l=1,s=arguments.length,c=!1;for("boolean"==typeof o&&(c=o,o=arguments[1]||{},l++),"object"==typeof o||Kt(o)||(o={}),l===s&&(o=this,l--);s>l;l++)if(null!=(e=arguments[l]))for(t in e){n=o[t];try{r=e[t]}catch(u){continue}o!==r&&(c&&r&&(avalon.isPlainObject(r)||(a=Array.isArray(r)))?(a?(a=!1,i=n&&Array.isArray(n)?n:[]):i=n&&avalon.isPlainObject(n)?n:{},o[t]=avalon.mix(c,i,r)):void 0!==r&&(o[t]=r))}return o},avalon.mix({rword:Pt,subscribers:jt,version:1.46,ui:{},log:n,slice:Wt?function(e,t,n){return qt.call(e,t,n)}:function(e,t,n){var r=[],a=e.length;if(void 0===n&&(n=a),"number"==typeof n&&isFinite(n)){t=s(t,a),n=s(n,a);for(var i=t;n>i;++i)r[i-t]=e[i]}return r},noop:r,error:function(e,t){throw(t||Error)(e)},oneObject:i,range:function(e,t,n){n||(n=1),null==t&&(t=e||0,e=0);for(var r=-1,a=Math.max(0,Math.ceil((t-e)/n)),i=new Array(a);++r<a;)i[r]=e,e+=n;return i},eventHooks:[],bind:function(e,t,n,r){var a=avalon.eventHooks,i=a[t];"object"==typeof i&&(t=i.type,i.deel&&(n=i.deel(e,t,n,r)));var o=Wt?n:function(t){n.call(e,v(t))};return Wt?e.addEventListener(t,o,!!r):e.attachEvent("on"+t,o),o},unbind:function(e,t,n,a){var i=avalon.eventHooks,o=i[t],l=n||r;"object"==typeof o&&(t=o.type,o.deel&&(n=o.deel(e,t,n,!1))),Wt?e.removeEventListener(t,l,!!a):e.detachEvent("on"+t,l)},css:function(e,t,n){e instanceof avalon&&(e=e[0]);var r,a=/[_-]/.test(t)?I(t):t;if(t=avalon.cssName(a)||a,void 0===n||"boolean"==typeof n){r=ar[a+":get"]||ar["@:get"],"background"===t&&(t="backgroundColor");var i=r(e,t);return n===!0?parseFloat(i)||0:i}if(""===n)e.style[t]="";else{if(null==n||n!==n)return;isFinite(n)&&!avalon.cssNumber[a]&&(n+="px"),r=ar[a+":set"]||ar["@:set"],r(e,t,n)}},each:function(e,t){if(e){var n=0;if(c(e))for(var r=e.length;r>n&&t(n,e[n])!==!1;n++);else for(n in e)if(e.hasOwnProperty(n)&&t(n,e[n])===!1)break}},getWidgetData:function(e,t){var n=avalon(e).data(),r={};for(var a in n)0===a.indexOf(t)&&(r[a.replace(t,"").replace(/\w/,function(e){return e.toLowerCase()})]=n[a]);return r},Array:{ensure:function(e,t){return-1===e.indexOf(t)?e.push(t):void 0},removeAt:function(e,t){return!!e.splice(t,1).length},remove:function(e,t){var n=e.indexOf(t);return~n?avalon.Array.removeAt(e,n):!1}}});var nn=avalon.bindingHandlers={},rn=avalon.bindingExecutors={},an=new function(){function e(e){this.size=0,this.limit=e,this.head=this.tail=void 0,this._keymap={}}var t=e.prototype;return t.put=function(e,t){var n={key:e,value:t};return this._keymap[e]=n,this.tail?(this.tail.newer=n,n.older=this.tail):this.head=n,this.tail=n,this.size===this.limit?this.shift():this.size++,t},t.shift=function(){var e=this.head;e&&(this.head=this.head.newer,this.head.older=e.newer=e.older=this._keymap[e.key]=void 0,delete this._keymap[e.key])},t.get=function(e){var t=this._keymap[e];if(void 0!==t)return t===this.tail?t.value:(t.newer&&(t===this.head&&(this.head=t.newer),t.newer.older=t.older),t.older&&(t.older.newer=t.newer),t.newer=void 0,t.older=this.tail,this.tail&&(this.tail.newer=t),this.tail=t,t.value)},e};if(!"司徒正美".trim){var on=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;String.prototype.trim=function(){return this.replace(on,"")}}var ln=!{toString:null}.propertyIsEnumerable("toString"),sn=function(){}.propertyIsEnumerable("prototype"),cn=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],un=cn.length;if(Object.keys||(Object.keys=function(e){var t=[],n=sn&&"function"==typeof e;if("string"==typeof e||e&&e.callee)for(var r=0;r<e.length;++r)t.push(String(r));else for(var a in e)n&&"prototype"===a||!Vt.call(e,a)||t.push(String(a));if(ln)for(var i=e.constructor,o=i&&i.prototype===e,l=0;un>l;l++){var s=cn[l];o&&"constructor"===s||!Vt.call(e,s)||t.push(s)}return t}),Array.isArray||(Array.isArray=function(e){return"[object Array]"===zt.call(e)}),r.bind||(Function.prototype.bind=function(e){if(arguments.length<2&&void 0===e)return this;var t=this,n=arguments;return function(){var r,a=[];for(r=1;r<n.length;r++)a.push(n[r]);for(r=0;r<arguments.length;r++)a.push(arguments[r]);return t.apply(e,a)}}),St.test([].map)||avalon.mix(Ut,{indexOf:function(e,t){var n=this.length,r=~~t;for(0>r&&(r+=n);n>r;r++)if(this[r]===e)return r;return-1},lastIndexOf:function(e,t){var n=this.length,r=null==t?n-1:t;for(0>r&&(r=Math.max(0,n+r));r>=0;r--)if(this[r]===e)return r;return-1},forEach:u("","_",""),filter:u("r=[],j=0,","if(_)r[j++]=this[i]","return r"),map:u("r=[],","r[i]=_","return r"),some:u("","if(_)return true","return false"),every:u("","if(!_)return false","return true")}),avalon.contains=f,_t.contains||(_t.contains=function(e){return f(_t,e)}),e.SVGElement){_t.createTextNode("x").contains||(Node.prototype.contains=function(e){return!!(16&this.compareDocumentPosition(e))});var fn="http://www.w3.org/2000/svg",pn=_t.createElementNS(fn,"svg");pn.innerHTML='<circle cx="50" cy="50" r="40" fill="red" />',Bt.test(pn.firstChild)||Object.defineProperties(SVGElement.prototype,{outerHTML:{enumerable:!0,configurable:!0,get:p,set:function(e){var t=this.tagName.toLowerCase(),n=this.parentNode,r=avalon.parseHTML(e);if("svg"===t)n.insertBefore(r,this);else{var a=_t.createDocumentFragment();d(r,a),n.insertBefore(a,this)}n.removeChild(this)}},innerHTML:{enumerable:!0,configurable:!0,get:function(){var e=this.outerHTML,t=new RegExp("<"+this.nodeName+'\\b(?:(["\'])[^"]*?(\\1)|[^>])*>',"i"),n=new RegExp("</"+this.nodeName+">$","i");return e.replace(t,"").replace(n,"")},set:function(e){if(avalon.clearHTML){avalon.clearHTML(this);var t=avalon.parseHTML(e);d(t,this)}}}})}!Xt.outerHTML&&e.HTMLElement&&HTMLElement.prototype.__defineGetter__("outerHTML",p);var dn=/^(?:mouse|contextmenu|drag)|click/,vn=avalon.eventHooks;if("onmouseenter"in Xt||avalon.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){vn[e]={type:t,deel:function(t,n,r){return function(n){var a=n.relatedTarget;return a&&(a===t||16&t.compareDocumentPosition(a))?void 0:(delete n.type,n.type=e,r.call(t,n))}}}}),avalon.each({AnimationEvent:"animationend",WebKitAnimationEvent:"webkitAnimationEnd"},function(t,n){e[t]&&!vn.animationend&&(vn.animationend={type:n})}),"oninput"in _t.createElement("input")||(vn.input={type:"propertychange",deel:function(e,t,n){return function(t){return"value"===t.propertyName?(t.type="input",n.call(e,t)):void 0}}}),void 0===_t.onmousewheel){var hn=void 0!==_t.onwheel?"wheel":"DOMMouseScroll",mn="wheel"===hn?"deltaY":"detail";vn.mousewheel={type:hn,deel:function(e,t,n){return function(t){t.wheelDeltaY=t.wheelDelta=t[mn]>0?-120:120,t.wheelDeltaX=0,Object.defineProperty&&Object.defineProperty(t,"type",{value:"mousewheel"}),n.call(e,t)}}}}var gn,yn,bn,xn,wn,$n=/[-.*+?^${}()|[\]\/\\]/g,Cn={loader:function(t){var n=Mt&&t;e.require=n?Mt:Lt,e.define=n?Mt.define:Ht},interpolate:function(e){if(gn=e[0],yn=e[1],gn===yn)throw new SyntaxError("openTag===closeTag");var t=gn+"test"+yn;if(Gt.innerHTML=t,Gt.innerHTML!==t&&Gt.innerHTML.indexOf("&lt;")>-1)throw new SyntaxError("此定界符不合法");h.openTag=gn,h.closeTag=yn,Gt.innerHTML="";var n=m(gn),r=m(yn);bn=new RegExp(n+"(.*?)"+r),xn=new RegExp(n+"(.*?)"+r,"g"),wn=new RegExp(n+".*?"+r+"|\\sms-")}};h.debug=!0,h.plugins=Cn,h.plugins.interpolate(["{{","}}"]),h.paths={},h.shim={},h.maxRepeatSize=100,avalon.config=h;var kn=/(\w+)\[(avalonctrl)="(\S+)"\]/,Tn=_t.querySelectorAll?function(e){return _t.querySelectorAll(e)}:function(e){for(var t,n=e.match(kn),r=_t.getElementsByTagName(n[1]),a=[],i=0;t=r[i++];)t.getAttribute(n[2])===n[3]&&a.push(t);return a},En={$watch:function(e,t){if("function"==typeof t){var n=this.$events[e];n?n.push(t):this.$events[e]=[t]}else this.$events=this.$watch.backup;return this},$unwatch:function(e,t){var n=arguments.length;if(0===n)this.$watch.backup=this.$events,this.$events={};else if(1===n)this.$events[e]=[];else for(var r=this.$events[e]||[],a=r.length;~--a<0;)if(r[a]===t)return r.splice(a,1);return this},$fire:function(e){var t,n,r,a;/^(\w+)!(\S+)$/.test(e)&&(t=RegExp.$1,e=RegExp.$2);var i=this.$events;if(i){var o=qt.call(arguments,1),l=[e].concat(o);if("all"===t)for(n in avalon.vmodels)r=avalon.vmodels[n],r!==this&&r.$fire.apply(r,l);else if("up"===t||"down"===t){var s=i.expr?Tn(i.expr):[];if(0===s.length)return;for(n in avalon.vmodels)if(r=avalon.vmodels[n],r!==this&&r.$events.expr){var c=Tn(r.$events.expr);if(0===c.length)continue;Ut.forEach.call(c,function(e){Ut.forEach.call(s,function(n){var a="down"===t?n.contains(e):e.contains(n);a&&(e._avalon=r)})})}var u=_t.getElementsByTagName("*"),f=[];for(Ut.forEach.call(u,function(e){e._avalon&&(f.push(e._avalon),e._avalon="",e.removeAttribute("_avalon"))}),"up"===t&&f.reverse(),n=0;(a=f[n++])&&a.$fire.apply(a,l)!==!1;);}else{var p=i[e]||[],d=i.$all||[];for(n=0;a=p[n++];)Kt(a)&&a.apply(this,o);for(n=0;a=d[n++];)Kt(a)&&a.apply(this,arguments)}}}},An=avalon.vmodels={};avalon.define=function(e,t){var a=e.$id||e;if(a||n("warning: vm必须指定$id"),An[a]&&n("warning: "+a+" 已经存在于avalon.vmodels中"),"object"==typeof e)var i=g(e);else{var o={$watch:r};t(o),i=g(o),Dt=!0,t(i),Dt=!1}return i.$id=a,An[a]=i};var _n=String("$id,$watch,$unwatch,$fire,$events,$model,$skipArray,$reinitialize").match(Pt),On=Object.defineProperty,Nn=!0;try{On({},"_",{value:"x"});var Mn=Object.defineProperties}catch(Sn){Nn=!1}var jn=Object.is||function(e,t){return 0===e&&0===t?1/e===1/t:e!==e?t!==t:e===t},Ln=Wt?function(e){var t={};for(var n in e)t[n]={get:e[n],set:e[n],enumerable:!0,configurable:!0};return t}:function(e){return e};if(!Nn&&("__defineGetter__"in avalon&&(On=function(e,t,n){return"value"in n&&(e[t]=n.value),"get"in n&&e.__defineGetter__(t,n.get),"set"in n&&e.__defineSetter__(t,n.set),e},Mn=function(e,t){for(var n in t)t.hasOwnProperty(n)&&On(e,n,t[n]);return e}),Qt)){var Hn={};e.execScript(["Function parseVB(code)"," ExecuteGlobal(code)","End Function"].join("\n"),"VBScript"),Mn=function(t,n,r){var a=[];a.push("\r\n Private [__data__], [__proxy__]"," Public Default Function [__const__](d"+At+", p"+At+")"," Set [__data__] = d"+At+": set [__proxy__] = p"+At," Set [__const__] = Me"," End Function");for(t in r)n.hasOwnProperty(t)||a.push(" Public ["+t+"]");_n.forEach(function(e){n.hasOwnProperty(e)||a.push(" Public ["+e+"]")}),a.push(" Public [hasOwnProperty]");for(t in n)a.push(" Public Property Let ["+t+"](val"+At+")",' Call [__proxy__](Me,[__data__], "'+t+'", val'+At+")"," End Property"," Public Property Set ["+t+"](val"+At+")",' Call [__proxy__](Me,[__data__], "'+t+'", val'+At+")"," End Property"," Public Property Get ["+t+"]"," On Error Resume Next"," Set["+t+'] = [__proxy__](Me,[__data__],"'+t+'")'," If Err.Number <> 0 Then"," ["+t+'] = [__proxy__](Me,[__data__],"'+t+'")'," End If"," On Error Goto 0"," End Property");a.push("End Class");var i=a.join("\r\n"),o=Hn[i];o||(o=Zt("VBClass"),e.parseVB("Class "+o+i),e.parseVB(["Function "+o+"Factory(a, b)"," Dim o"," Set o = (New "+o+")(a, b)"," Set "+o+"Factory = o","End Function"].join("\r\n")),Hn[i]=o);var l=e[o+"Factory"](n,A);return l}}var Dn=Ut.splice,Pn={_splice:Dn,_fire:function(e,t,n){S(this.$events[jt],e,t,n)},size:function(){return this._.length},pushArray:function(e){var t=e.length,n=this.length;return t&&(Ut.push.apply(this.$model,e),O.call(this,"add",n,t,Math.max(0,n-1))),t+n},push:function(){var e,t=[],n=arguments.length;for(e=0;n>e;e++)t[e]=arguments[e];return this.pushArray(t)},unshift:function(){var e=arguments.length,t=this.length;return e&&(Ut.unshift.apply(this.$model,arguments),O.call(this,"add",0,e,0)),e+t},shift:function(){if(this.length){var e=this.$model.shift();return O.call(this,"del",0,1,0),e}},pop:function(){var e=this.length;if(e){var t=this.$model.pop();return O.call(this,"del",e-1,1,Math.max(0,e-2)),t}},splice:function(e){var t,n=arguments.length,r=[],a=Dn.apply(this.$model,arguments);
2
+ return a.length&&(r.push("del",e,a.length,0),t=!0),n>2&&(t?r.splice(3,1,0,"add",e,n-2):r.push("add",e,n-2,0),t=!0),t?O.apply(this,r):[]},contains:function(e){return-1!==this.indexOf(e)},remove:function(e){return this.removeAt(this.indexOf(e))},removeAt:function(e){return e>=0?(this.$model.splice(e,1),O.call(this,"del",e,1,0)):[]},clear:function(){return this.$model.length=this.length=this._.length=0,this._fire("clear",0),this},removeAll:function(e){if(Array.isArray(e))for(var t=this.length-1;t>=0;t--)-1!==e.indexOf(this[t])&&this.removeAt(t);else if("function"==typeof e)for(t=this.length-1;t>=0;t--){var n=this[t];e(n,t)&&this.removeAt(t)}else this.clear()},ensure:function(e){return this.contains(e)||this.push(e),this},set:function(e,t){if(e<this.length&&e>-1){var n=avalon.type(t);t&&t.$model&&(t=t.$model);var r=this[e];if("object"===n)for(var a in t)r.hasOwnProperty(a)&&(r[a]=t[a]);else"array"===n?r.clear().push.apply(r,t):r!==t&&(this[e]=t,this.$model[e]=t,this._fire("set",e,t))}return this}};"sort,reverse".replace(Pt,function(e){Pn[e]=function(){var t,n=this.$model,r=n.concat(),a=Math.random(),i=[];Ut[e].apply(n,arguments);for(var o=0,l=r.length;l>o;o++){var s=n[o],c=r[o];if(jn(s,c))i.push(o);else{var u=r.indexOf(s);i.push(u),r[u]=a,t=!0}}return t&&(N(this,i),this._fire("move",i),this._fire("index",0)),this}});var Fn=function(){var e,t=[];return{begin:function(n){t.push(e),e=n},end:function(){e=t.pop()},collectDependency:function(t,n){e&&e.callback(t,n)}}}(),Bn=/^(duplex|on)$/;avalon.injectBinding=function(e){var t=e.evaluator;if(t){Fn.begin({callback:function(t,n){M(t.$events[n._name],e)}});try{var r=Bn.test(e.type)?e:t.apply(0,e.args);void 0===r&&delete e.evaluator,e.handler(r,e.element,e)}catch(a){n("warning:exception throwed in [avalon.injectBinding] ",a),delete e.evaluator;var i=e.element;if(3===i.nodeType){var o=i.parentNode;h.commentInterpolate?o.replaceChild(_t.createComment(e.value),i):i.data=gn+(e.oneTime?"::":"")+e.value+yn}}finally{Fn.end()}}};var Rn=0,In=avalon.$$subscribers=[],Vn=new Date,zn={},Un={area:[1,"<map>","</map>"],param:[1,"<object>","</object>"],col:[2,"<table><colgroup>","</colgroup></table>"],legend:[1,"<fieldset>","</fieldset>"],option:[1,"<select multiple='multiple'>","</select>"],thead:[1,"<table>","</table>"],tr:[2,"<table>","</table>"],td:[3,"<table><tr>","</tr></table>"],g:[1,'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">',"</svg>"],_default:Wt?[0,"",""]:[1,"X<div>","</div>"]};Un.th=Un.td,Un.optgroup=Un.option,Un.tbody=Un.tfoot=Un.colgroup=Un.caption=Un.thead,String("circle,defs,ellipse,image,line,path,polygon,polyline,rect,symbol,text,use").replace(Pt,function(e){Un[e]=Un.g});var qn=/<([\w:]+)/,Wn=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,Xn=Wt?/[^\d\D]/:/(<(?:script|link|style|meta|noscript))/gi,Yn=i(["","text/javascript","text/ecmascript","application/ecmascript","application/javascript"]),Gn=/<(?:tb|td|tf|th|tr|col|opt|leg|cap|area)/,Jn=_t.createElement("script"),Zn=/<|&#?\w+;/;avalon.parseHTML=function(e){var t=Yt.cloneNode(!1);if("string"!=typeof e)return t;if(!Zn.test(e))return t.appendChild(_t.createTextNode(e)),t;e=e.replace(Wn,"<$1></$2>").trim();var n,r,a=(qn.exec(e)||["",""])[1].toLowerCase(),i=Un[a]||Un._default,o=Gt;Wt||(e=e.replace(Xn,"<br class=msNoScope>$1")),o.innerHTML=i[1]+e+i[2];var l=o.getElementsByTagName("script");if(l.length)for(var s,c=0;s=l[c++];)Yn[s.type]&&(r=Jn.cloneNode(!1),Ut.forEach.call(s.attributes,function(e){e&&e.specified&&(r[e.name]=e.value,r.setAttribute(e.name,e.value))}),r.text=s.text,s.parentNode.replaceChild(r,s));if(!Wt){var u="X<div>"===i[1]?o.lastChild.firstChild:o.lastChild;if(u&&"TABLE"===u.tagName&&"tbody"!==a)for(l=u.childNodes,c=0;s=l[c++];)if("TBODY"===s.tagName&&!s.innerHTML){u.removeChild(s);break}l=o.getElementsByTagName("br");for(var f=l.length;s=l[--f];)"msNoScope"===s.className&&s.parentNode.removeChild(s);for(l=o.all,c=0;s=l[c++];)F(s)&&B(s)}for(c=i[0];c--;o=o.lastChild);for(;n=o.firstChild;)t.appendChild(n);return t},avalon.innerHTML=function(e,t){if(!Wt&&!Xn.test(t)&&!Gn.test(t))try{return void(e.innerHTML=t)}catch(n){}var r=this.parseHTML(t);this.clearHTML(e).appendChild(r)},avalon.clearHTML=function(e){for(e.textContent="";e.firstChild;)e.removeChild(e.firstChild);return e};var Qn={_toString:function(){var e=this.node,t=e.className,n="string"==typeof t?t:t.baseVal;return n.split(/\s+/).join(" ")},_contains:function(e){return(" "+this+" ").indexOf(" "+e+" ")>-1},_add:function(e){this.contains(e)||this._set(this+" "+e)},_remove:function(e){this._set((" "+this+" ").replace(" "+e+" "," "))},__set:function(e){e=e.trim();var t=this.node;Bt.test(t)?t.setAttribute("class",e):t.className=e}};"add,remove".replace(Pt,function(e){avalon.fn[e+"Class"]=function(t){var n=this[0];return t&&"string"==typeof t&&n&&1===n.nodeType&&t.replace(/\S+/g,function(t){V(n)[e](t)}),this}}),avalon.fn.mix({hasClass:function(e){var t=this[0]||{};return 1===t.nodeType&&V(t).contains(e)},toggleClass:function(e,t){for(var n,r=0,a=String(e).split(/\s+/),i="boolean"==typeof t;n=a[r++];){var o=i?t:!this.hasClass(n);this[o?"addClass":"removeClass"](n)}return this},attr:function(e,t){return 2===arguments.length?(this[0].setAttribute(e,t),this):this[0].getAttribute(e)},data:function(e,t){switch(e="data-"+R(e||""),arguments.length){case 2:return this.attr(e,t),this;case 1:var n=this.attr(e);return z(n);case 0:var r={};return Ut.forEach.call(this[0].attributes,function(t){t&&(e=t.name,e.indexOf("data-")||(e=I(e.slice(5)),r[e]=z(t.value)))}),r}},removeData:function(e){return e="data-"+R(e),this[0].removeAttribute(e),this},css:function(e,t){if(avalon.isPlainObject(e))for(var n in e)avalon.css(this,n,e[n]);else var r=avalon.css(this,e,t);return void 0!==r?r:this},position:function(){var e,t,n=this[0],r={top:0,left:0};if(n)return"fixed"===this.css("position")?t=n.getBoundingClientRect():(e=this.offsetParent(),t=this.offset(),"HTML"!==e[0].tagName&&(r=e.offset()),r.top+=avalon.css(e[0],"borderTopWidth",!0),r.left+=avalon.css(e[0],"borderLeftWidth",!0),r.top-=e.scrollTop(),r.left-=e.scrollLeft()),{top:t.top-r.top-avalon.css(n,"marginTop",!0),left:t.left-r.left-avalon.css(n,"marginLeft",!0)}},offsetParent:function(){for(var e=this[0].offsetParent;e&&"static"===avalon.css(e,"position");)e=e.offsetParent;return avalon(e||Xt)},bind:function(e,t,n){return this[0]?avalon.bind(this[0],e,t,n):void 0},unbind:function(e,t,n){return this[0]&&avalon.unbind(this[0],e,t,n),this},val:function(e){var t=this[0];if(t&&1===t.nodeType){var n=0===arguments.length,r=n?":get":":set",a=mr[W(t)+r];if(a)var i=a(t,e);else{if(n)return(t.value||"").replace(/\r/g,"");t.value=e}}return n?i:this}});var Kn=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/,er=/^[\],:{}\s]*$/,tr=/(?:^|:|,)(?:\s*\[)+/g,nr=/\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,rr=/"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g;avalon.parseJSON=e.JSON?JSON.parse:function(e){if("string"==typeof e){if(e=e.trim(),e&&er.test(e.replace(nr,"@").replace(rr,"]").replace(tr,"")))return new Function("return "+e)();avalon.error("Invalid JSON: "+e)}return e},avalon.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(e,t){avalon.fn[e]=function(n){var r=this[0]||{},a=U(r),i="scrollTop"===e;return arguments.length?void(a?a.scrollTo(i?avalon(a).scrollLeft():n,i?n:avalon(a).scrollTop()):r[e]=n):a?t in a?a[t]:Xt[e]:r[e]}});var ar=avalon.cssHooks={},ir=["","-webkit-","-o-","-moz-","-ms-"],or={"float":Wt?"cssFloat":"styleFloat"};if(avalon.cssNumber=i("animationIterationCount,columnCount,order,flex,flexGrow,flexShrink,fillOpacity,fontWeight,lineHeight,opacity,orphans,widows,zIndex,zoom"),avalon.cssName=function(e,t,n){if(or[e])return or[e];t=t||Xt.style;for(var r=0,a=ir.length;a>r;r++)if(n=I(ir[r]+e),n in t)return or[e]=n;return null},ar["@:set"]=function(e,t,n){try{e.style[t]=n}catch(r){}},e.getComputedStyle)ar["@:get"]=function(e,t){if(!e||!e.style)throw new Error("getComputedStyle要求传入一个节点 "+e);var n,r=getComputedStyle(e,null);return r&&(n="filter"===t?r.getPropertyValue(t):r[t],""===n&&(n=e.style[t])),n},ar["opacity:get"]=function(e){var t=ar["@:get"](e,"opacity");return""===t?"1":t};else{var lr=/^-?(?:\d*\.)?\d+(?!px)[^\d\s]+$/i,sr=/^(top|right|bottom|left)$/,cr=/alpha\([^)]*\)/i,ur=!!e.XDomainRequest,fr="DXImageTransform.Microsoft.Alpha",pr={thin:ur?"1px":"2px",medium:ur?"3px":"4px",thick:ur?"5px":"6px"};ar["@:get"]=function(e,t){var n=e.currentStyle,r=n[t];if(lr.test(r)&&!sr.test(r)){var a=e.style,i=a.left,o=e.runtimeStyle.left;e.runtimeStyle.left=n.left,a.left="fontSize"===t?"1em":r||0,r=a.pixelLeft+"px",a.left=i,e.runtimeStyle.left=o}return"medium"===r&&(t=t.replace("Width","Style"),"none"===n[t]&&(r="0px")),""===r?"auto":pr[r]||r},ar["opacity:set"]=function(e,t,n){var r=e.style,a=isFinite(n)&&1>=n?"alpha(opacity="+100*n+")":"",i=r.filter||"";r.zoom=1,r.filter=(cr.test(i)?i.replace(cr,a):i+" "+a).trim(),r.filter||r.removeAttribute("filter")},ar["opacity:get"]=function(e){var t=e.filters.alpha||e.filters[fr],n=t&&t.enabled?t.opacity:100;return n/100+""}}"top,left".replace(Pt,function(e){ar[e+":get"]=function(t){var n=ar["@:get"](t,e);return/px$/.test(n)?n:avalon(t).position()[e]+"px"}});var dr={position:"absolute",visibility:"hidden",display:"block"},vr=/^(none|table(?!-c[ea]).+)/;"Width,Height".replace(Pt,function(e){var t=e.toLowerCase(),n="client"+e,r="scroll"+e,a="offset"+e;ar[t+":get"]=function(t,n,r){var i=-4;"number"==typeof r&&(i=r),n="Width"===e?["Left","Right"]:["Top","Bottom"];var o=t[a];return 2===i?o+avalon.css(t,"margin"+n[0],!0)+avalon.css(t,"margin"+n[1],!0):(0>i&&(o=o-avalon.css(t,"border"+n[0]+"Width",!0)-avalon.css(t,"border"+n[1]+"Width",!0)),-4===i&&(o=o-avalon.css(t,"padding"+n[0],!0)-avalon.css(t,"padding"+n[1],!0)),o)},ar[t+"&get"]=function(e){var n=[];q(e,n);for(var r,a=ar[t+":get"](e),i=0;r=n[i++];){e=r.node;for(var o in r)"string"==typeof r[o]&&(e.style[o]=r[o])}return a},avalon.fn[t]=function(i){var o=this[0];if(0===arguments.length){if(o.setTimeout)return o["inner"+e]||o.document.documentElement[n];if(9===o.nodeType){var l=o.documentElement;return Math.max(o.body[r],l[r],o.body[a],l[a],l[n])}return ar[t+"&get"](o)}return this.css(t,i)},avalon.fn["inner"+e]=function(){return ar[t+":get"](this[0],void 0,-2)},avalon.fn["outer"+e]=function(e){return ar[t+":get"](this[0],void 0,e===!0?2:0)}}),avalon.fn.offset=function(){var e=this[0],t={left:0,top:0};if(!e||!e.tagName||!e.ownerDocument)return t;var n=e.ownerDocument,r=n.body,a=n.documentElement,i=n.defaultView||n.parentWindow;if(!avalon.contains(a,e))return t;e.getBoundingClientRect&&(t=e.getBoundingClientRect());var o=a.clientTop||r.clientTop,l=a.clientLeft||r.clientLeft,s=Math.max(i.pageYOffset||0,a.scrollTop,r.scrollTop),c=Math.max(i.pageXOffset||0,a.scrollLeft,r.scrollLeft);return{top:t.top+s-o,left:t.left+c-l}};var hr=/^<option(?:\s+\w+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+))?)*\s+value[\s=]/i,mr={"option:get":Qt?function(e){return hr.test(e.outerHTML)?e.value:e.text.trim()}:function(e){return e.value},"select:get":function(e,t){for(var n,r=e.options,a=e.selectedIndex,i=mr["option:get"],o="select-one"===e.type||0>a,l=o?null:[],s=o?a+1:r.length,c=0>a?s:o?a:0;s>c;c++)if(n=r[c],(n.selected||c===a)&&!n.disabled){if(t=i(n),o)return t;l.push(t)}return l},"select:set":function(e,t,n){t=[].concat(t);for(var r,a=mr["option:get"],i=0;r=e.options[i++];)(r.selected=t.indexOf(a(r))>-1)&&(n=!0);n||(e.selectedIndex=-1)}},gr={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},yr=e.JSON&&JSON.stringify||function(e){return'"'+e.replace(/[\\\"\x00-\x1f]/g,function(e){var t=gr[e];return"string"==typeof t?t:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})+'"'},br=["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"].join(","),xr=/\/\*[\w\W]*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|"(?:[^"\\]|\\[\w\W])*"|'(?:[^'\\]|\\[\w\W])*'|[\s\t\n]*\.[\s\t\n]*[$\w\.]+/g,wr=/[^\w$]+/g,$r=new RegExp(["\\b"+br.replace(/,/g,"\\b|\\b")+"\\b"].join("|"),"g"),Cr=/\b\d[^,]*/g,kr=/^,+|,+$/g,Tr=new an(512),Er=function(e){var t=","+e.trim(),n=Tr.get(t);if(n)return n;var r=e.replace(xr,"").replace(wr,",").replace($r,"").replace(Cr,"").replace(kr,"").split(/^$|,+/);return Tr.put(t,Y(r))},Ar=new an(128),_r=/\w\[.*\]|\w\.\w/,Or=/(\$proxy\$[a-z]+)\d+$/,Nr=/\)\s*$/,Mr=/\)\s*\|/g,Sr=/\|\s*([$\w]+)/g,jr=/"\s*\["/g,Lr=/"\s*\(/g;avalon.parseExprProxy=Q,avalon.scan=function(e,t){e=e||Xt;var n=t?[].concat(t):[];ot(e,n)};var Hr=i("area,base,basefont,br,col,command,embed,hr,img,input,link,meta,param,source,track,wbr,noscript,script,style,textarea".toUpperCase()),Dr=function(e,t,n){var r=e.getAttribute(t);if(r)for(var a,i=0;a=n[i++];)if(a.hasOwnProperty(r)&&"function"==typeof a[r])return a[r]},Pr=Qt&&e.MutationObserver?function(e){for(var t,n=e.firstChild;n;){var r=n.nextSibling;3===n.nodeType?t?(t.nodeValue+=n.nodeValue,e.removeChild(n)):t=n:t=null,n=r}}:0,Fr=/^\s*::/,Br=/ms-(\w+)-?(.*)/,Rr={"if":10,repeat:90,data:100,widget:110,each:1400,"with":1500,duplex:2e3,on:3e3},Ir=i("animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scan,scroll,submit"),Vr=i("value,title,alt,checked,selected,disabled,readonly,enabled"),zr=/^if|widget|repeat$/,Ur=/^each|with|html|include$/;if(!Wt)var qr=new an(512),Wr=/\s+(ms-[^=\s]+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,Xr=/^['"]/,Yr=/<\w+\b(?:(["'])[^"]*?(\1)|[^>])*>/i,Gr=/&amp;/g,Jr=function(e){var t=e.outerHTML;if("</"===t.slice(0,2)||!t.trim())return[];var n,r,a,i=t.match(Yr)[0],o=[],l=qr.get(i);if(l)return l;for(;r=Wr.exec(i);){a=r[2],a&&(a=(Xr.test(a)?a.slice(1,-1):a).replace(Gr,"&"));var s=r[1].toLowerCase();n=s.match(Br);var c={name:s,specified:!0,value:a||""};o.push(c)}return qr.put(i,o)};var Zr=/\|\s*html(?:\b|$)/,Qr=/\|\|/g,Kr=/&lt;/g,ea=/&gt;/g,ta=/(['"])(\\\1|.)+?\1/g,na=["autofocus,autoplay,async,allowTransparency,checked,controls","declare,disabled,defer,defaultChecked,defaultSelected","contentEditable,isMap,loop,multiple,noHref,noResize,noShade","open,readOnly,selected"].join(","),ra={};na.replace(Pt,function(e){ra[e.toLowerCase()]=e});var aa={"accept-charset":"acceptCharset","char":"ch",charoff:"chOff","class":"className","for":"htmlFor","http-equiv":"httpEquiv"},ia=["accessKey,bgColor,cellPadding,cellSpacing,codeBase,codeType,colSpan","dateTime,defaultValue,frameBorder,longDesc,maxLength,marginWidth,marginHeight","rowSpan,tabIndex,useMap,vSpace,valueType,vAlign"].join(",");ia.replace(Pt,function(e){aa[e.toLowerCase()]=e});var oa=/<noscript.*?>(?:[\s\S]+?)<\/noscript>/gim,la=/<noscript.*?>([\s\S]+?)<\/noscript>/im,sa=function(){return new(e.XMLHttpRequest||ActiveXObject)("Microsoft.XMLHTTP")},ca=avalon.templateCache={};nn.attr=function(e,t){var n=Z(e.value.trim());if("include"===e.type){var r=e.element;e.includeRendered=Dr(r,"data-include-rendered",t),e.includeLoaded=Dr(r,"data-include-loaded",t);var a=e.includeReplace=!!avalon(r).data("includeReplace");avalon(r).data("includeCache")&&(e.templateCache={}),e.startInclude=_t.createComment("ms-include"),e.endInclude=_t.createComment("ms-include-end"),a?(e.element=e.startInclude,r.parentNode.insertBefore(e.startInclude,r),r.parentNode.insertBefore(e.endInclude,r.nextSibling)):(r.insertBefore(e.startInclude,r.firstChild),r.appendChild(e.endInclude))}e.handlerName="attr",Q(n,t,e)},rn.attr=function(t,n,r){var a=r.type,i=r.param;if("css"===a)avalon(n).css(i,t);else if("attr"===a){var o=t===!1||null===t||void 0===t;!Wt&&aa[i]&&(i=aa[i]);var l=ra[i];if("boolean"==typeof n[l]&&(n[l]=!!t,t||(o=!0)),o)return n.removeAttribute(i);var s=Bt.test(n)?!1:_t.namespaces&&F(n)?!0:i in n.cloneNode(!1);s?n[i]=t+"":n.setAttribute(i,t)}else if("include"===a&&t){var c=r.vmodels,u=r.includeRendered,f=r.includeLoaded,p=r.includeReplace,d=p?n.parentNode:n,v=function(e){if(f){var n=f.apply(d,[e].concat(c));"string"==typeof n&&(e=n)}u&&K(d,function(){u.call(d)},0/0);var a=r.includeLastID;if(r.templateCache&&a&&a!==t){var i=r.templateCache[a];i||(i=r.templateCache[a]=_t.createElement("div"),Nt.appendChild(i))}for(r.includeLastID=t;;){var o=r.startInclude.nextSibling;if(!o||o===r.endInclude)break;d.removeChild(o),i&&i.appendChild(o)}var l=ut(r,t,e),s=avalon.slice(l.childNodes);d.insertBefore(l,r.endInclude),it(s,c)};if("src"===r.param)if("string"==typeof ca[t])avalon.nextTick(function(){v(ca[t])});else if(Array.isArray(ca[t]))ca[t].push(v);else{var h=sa();h.onreadystatechange=function(){if(4===h.readyState){var e=h.status;if(e>=200&&300>e||304===e||1223===e){for(var n,r=h.responseText,a=0;n=ca[t][a++];)n(r);ca[t]=r}}},ca[t]=[v],h.open("GET",t,!0),"withCredentials"in h&&(h.withCredentials=!0),h.setRequestHeader("X-Requested-With","XMLHttpRequest"),h.send(null)}else{var m=t&&1===t.nodeType?t:_t.getElementById(t);if(m){if("NOSCRIPT"===m.tagName&&!m.innerHTML&&!m.fixIE78){h=sa(),h.open("GET",location,!1),h.send(null);for(var g=_t.getElementsByTagName("noscript"),y=(h.responseText||"").match(oa)||[],b=y.length,x=0;b>x;x++){var w=g[x];w&&(w.style.display="none",w.fixIE78=(y[x].match(la)||["","&nbsp;"])[1])}}avalon.nextTick(function(){v(m.fixIE78||m.value||m.innerText||m.innerHTML)})}}}else if(Xt.hasAttribute||"string"!=typeof t||"src"!==a&&"href"!==a||(t=t.replace(/&amp;/g,"&")),n[a]=t,e.chrome&&"EMBED"===n.tagName){var $=n.parentNode,C=document.createComment("ms-src");$.replaceChild(C,n),$.replaceChild(n,C)}},"title,alt,src,value,css,include,href".replace(Pt,function(e){nn[e]=nn.attr}),nn["class"]=function(e,t){var n,r=e.param,a=e.value;if(e.handlerName="class",!r||isFinite(r)){e.param="";var i=a.replace(xn,function(e){return e.replace(/./g,"0")}).indexOf(":");if(-1===i){var o=a;n=!0}else o=a.slice(0,i),n=a.slice(i+1);o=bn.test(a)?Z(o):yr(o),e.expr="["+o+","+n+"]"}else e.expr="["+yr(r)+","+a+"]",e.oldStyle=r;var l=e.type;if("hover"===l||"active"===l){if(!e.hasBindEvent){var s=e.element,c=avalon(s),u="mouseenter",f="mouseleave";if("active"===l){s.tabIndex=s.tabIndex||-1,u="mousedown",f="mouseup";var p=c.bind("mouseleave",function(){e.toggleClass&&c.removeClass(e.newClass)})}}var d=c.bind(u,function(){e.toggleClass&&c.addClass(e.newClass)}),v=c.bind(f,function(){e.toggleClass&&c.removeClass(e.newClass)});e.rollback=function(){c.unbind("mouseleave",p),c.unbind(u,d),c.unbind(f,v)},e.hasBindEvent=!0}Q(e.expr,t,e)},rn["class"]=function(e,t,n){var r=avalon(t);n.newClass=e[0],n.toggleClass=!!e[1],n.oldClass&&n.newClass!==n.oldClass&&r.removeClass(n.oldClass),n.oldClass=n.newClass,"class"===n.type&&(n.oldStyle?r.toggleClass(n.oldStyle,!!e[1]):r.toggleClass(n.newClass,n.toggleClass))},"hover,active".replace(Pt,function(e){nn[e]=nn["class"]}),rn.data=function(e,t,n){var r="data-"+n.param;e&&"object"==typeof e?t[r]=e:t.setAttribute(r,String(e))};var ua=nn.duplex=function(e,t){var a,o=e.element;if(Q(e.value,t,e,1),e.changed=Dr(o,"data-duplex-changed",t)||r,e.evaluator&&e.args){var l=[],s=i("string,number,boolean,checked");"radio"===o.type&&""===e.param&&(e.param="checked"),o.msData&&(o.msData["ms-duplex"]=e.value),e.param.replace(/\w+/g,function(t){/^(checkbox|radio)$/.test(o.type)&&/^(radio|checked)$/.test(t)&&("radio"===t&&n("ms-duplex-radio已经更名为ms-duplex-checked"),t="checked",e.isChecked=!0),"bool"===t?(t="boolean",n("ms-duplex-bool已经更名为ms-duplex-boolean")):"text"===t&&(t="string",n("ms-duplex-text已经更名为ms-duplex-string")),s[t]&&(a=!0),avalon.Array.ensure(l,t)}),a||l.push("string"),e.param=l.join("-"),e.bound=function(t,n){o.addEventListener?o.addEventListener(t,n,!1):o.attachEvent("on"+t,n);var r=e.rollback;e.rollback=function(){o.avalonSetter=null,avalon.unbind(o,t,n),r&&r()}};for(var c in avalon.vmodels){var u=avalon.vmodels[c];u.$fire("avalon-ms-duplex-init",e)}var f=e.pipe||(e.pipe=pt);f(null,e,"init");var p=o.tagName;ua[p]&&ua[p](o,e.evaluator.apply(null,e.args),e)}};avalon.duplexHooks={checked:{get:function(e,t){return!t.element.oldValue}},string:{get:function(e){return e},set:ft},"boolean":{get:function(e){return"true"===e},set:ft},number:{get:function(e,t){var n=parseFloat(e);if(-e===-n)return n;var r=/strong|medium|weak/.exec(t.element.getAttribute("data-duplex-number"))||["medium"];switch(r[0]){case"strong":return 0;case"medium":return""===e?"":0;case"weak":return e}},set:ft}};var fa,pa=[];avalon.tick=function(e){1===pa.push(e)&&(fa=setInterval(dt,60))};var da=r,va=/text|password|hidden/;!new function(){function e(e){t[this.tagName].call(this,e),va.test(this.type)&&!this.msFocus&&this.avalonSetter&&this.avalonSetter()}try{var t={},n=HTMLInputElement.prototype,r=HTMLTextAreaElement.prototype,a=HTMLInputElement.prototype;Object.getOwnPropertyNames(a),t.INPUT=Object.getOwnPropertyDescriptor(n,"value").set,Object.defineProperty(n,"value",{set:e}),t.TEXTAREA=Object.getOwnPropertyDescriptor(r,"value").set,Object.defineProperty(r,"value",{set:e})}catch(i){da=avalon.tick}},Qt&&avalon.bind(_t,"selectionchange",function(){var e=_t.activeElement;e&&"function"==typeof e.avalonSetter&&e.avalonSetter()}),ua.INPUT=function(e,t,r){function a(e){r.changed.call(this,e,r)}function i(){f=!0}function o(){f=!1}function l(e){setTimeout(function(){p(e)})}var s=e.type,c=r.bound,u=avalon(e),f=!1,p=function(){var n=e.value;if(!f&&n!==e.oldValue){var i=r.pipe(n,r,"get");u.data("duplexObserve")!==!1&&(t(i),a.call(e,i))}};if(r.handler=function(){var n=r.pipe(t(),r,"set")+"";n!==e.oldValue&&(e.value=e.oldValue=n)},r.isChecked||"radio"===s){var d=6===Qt;p=function(){if(u.data("duplexObserve")!==!1){var n=r.pipe(e.value,r,"get");t(n),a.call(e,n)}},r.handler=function(){var n=t(),a=r.isChecked?!!n:n+""===e.value;e.oldValue=a,d?setTimeout(function(){e.defaultChecked=a,e.checked=a},31):e.checked=a},c("click",p)}else if("checkbox"===s)p=function(){if(u.data("duplexObserve")!==!1){var i=e.checked?"ensure":"remove",o=t();Array.isArray(o)||(n("ms-duplex应用于checkbox上要对应一个数组"),o=[o]);var l=r.pipe(e.value,r,"get");avalon.Array[i](o,l),a.call(e,o)}},r.handler=function(){var n=[].concat(t()),a=r.pipe(e.value,r,"get");e.checked=n.indexOf(a)>-1},c(Wt?"change":"click",p);else{var v=e.getAttribute("data-duplex-event")||"input";e.attributes["data-event"]&&n("data-event指令已经废弃,请改用data-duplex-event"),v.replace(Pt,function(e){switch(e){case"input":Qt?(Qt>8?c("input",p):c("propertychange",function(e){"value"===e.propertyName&&p()}),c("dragend",l)):(c("input",p),c("compositionstart",i),c("compositionend",o),c("DOMAutoComplete",p));break;default:c(e,p)}}),c("focus",function(){e.msFocus=!0}),c("blur",function(){e.msFocus=!1}),va.test(s)&&da(function(){if(Xt.contains(e))e.msFocus||e.oldValue===e.value||p();else if(!e.msRetain)return!1}),e.avalonSetter=p}e.oldValue=e.value,avalon.injectBinding(r),a.call(e,e.value)},ua.TEXTAREA=ua.INPUT,ua.SELECT=function(e,t,r){function a(){if(i.data("duplexObserve")!==!1){var n=i.val();n=Array.isArray(n)?n.map(function(e){return r.pipe(e,r,"get")}):r.pipe(n,r,"get"),n+""!==e.oldValue&&t(n),r.changed.call(e,n,r)}}var i=avalon(e);r.handler=function(){var r=t();r=r&&r.$model||r,Array.isArray(r)?e.multiple||n("ms-duplex在<select multiple=true>上要求对应一个数组"):e.multiple&&n("ms-duplex在<select multiple=false>不能对应一个数组"),r=Array.isArray(r)?r.map(String):r+"",r+""!==e.oldValue&&(i.val(r),e.oldValue=r+"")},r.bound("change",a),e.msCallback=function(){avalon.injectBinding(r),r.changed.call(e,t(),r)}},rn.html=function(e,t,n){var r=1!==t.nodeType,a=r?t.parentNode:t;if(a&&(e=null==e?"":e,n.oldText!==e)){if(n.oldText=e,3===t.nodeType){var i=Zt("html");a.insertBefore(_t.createComment(i),t),n.element=_t.createComment(i+":end"),a.replaceChild(n.element,t),t=n.element}if("object"!=typeof e)var o=avalon.parseHTML(String(e));else if(11===e.nodeType)o=e;else if(1===e.nodeType||e.item){var l=1===e.nodeType?e.childNodes:e.item;for(o=Yt.cloneNode(!0);l[0];)o.appendChild(l[0])}if(l=avalon.slice(o.childNodes),r){for(var s=t.nodeValue.slice(0,-4);;){var c=t.previousSibling;if(!c||8===c.nodeType&&c.nodeValue===s)break;a.removeChild(c)}a.insertBefore(o,t)}else avalon.clearHTML(t).appendChild(o);it(l,n.vmodels)}},nn["if"]=nn.data=nn.text=nn.html=function(e,t){Q(e.value,t,e)},rn["if"]=function(e,t,n){try{if(!t.parentNode)return}catch(r){return}if(e)8===t.nodeType&&(t.parentNode.replaceChild(n.template,t),t.ifRemove=null,t=n.element=n.template),t.getAttribute(n.name)&&(t.removeAttribute(n.name),rt(t,n.vmodels)),n.rollback=null;else if(1===t.nodeType){var a=n.element=_t.createComment("ms-if");t.parentNode.replaceChild(a,t),t.ifRemove=a,n.template=t,Nt.appendChild(t),n.rollback=function(){t.parentNode===Nt&&Nt.removeChild(t)}}};var ha=/\(([^)]*)\)/;nn.on=function(e,t){var n=e.value;e.type="on";var r=e.param.replace(/-\d+$/,"");if("function"==typeof nn.on[r+"Hook"]&&nn.on[r+"Hook"](e),n.indexOf("(")>0&&n.indexOf(")")>-1){var a=(n.match(ha)||["",""])[1].trim();(""===a||"$event"===a)&&(n=n.replace(ha,""))}Q(n,t,e)},rn.on=function(e,t,n){e=function(e){var t=n.evaluator||r;return t.apply(this,n.args.concat(e))};var a=n.param.replace(/-\d+$/,"");if("scan"===a)e.call(t,{type:a});else if("function"==typeof n.specialBind)n.specialBind(t,e);else var i=avalon.bind(t,a,e);n.rollback=function(){"function"==typeof n.specialUnbind?n.specialUnbind():avalon.unbind(t,a,i)}},nn.repeat=function(e,t){var n=e.type;Q(e.value,t,e,1),e.proxies=[];var r=!1;try{var a=e.$repeat=e.evaluator.apply(0,e.args||[]),i=avalon.type(a);"object"!==i&&"array"!==i?(r=!0,avalon.log("warning:"+e.value+"只能是对象或数组")):e.xtype=i}catch(o){r=!0}var l=e.value.split(".")||[];if(l.length>1){l.pop();for(var s,c=l[0],u=0;s=t[u++];)if(s&&s.hasOwnProperty(c)){var f=s[c].$events||{};f[jt]=f[jt]||[],f[jt].push(e);break}}var p=e.element;if(1===p.nodeType){p.removeAttribute(e.name),e.sortedCallback=Dr(p,"data-with-sorted",t),e.renderedCallback=Dr(p,"data-"+n+"-rendered",t);var d=Zt(n),v=_t.createComment(d),h=_t.createComment(d+":end");if(e.signature=d,e.template=Yt.cloneNode(!1),"repeat"===n){var m=p.parentNode;m.replaceChild(h,p),m.insertBefore(v,h),e.template.appendChild(p)}else{for(;p.firstChild;)e.template.appendChild(p.firstChild);p.appendChild(v),p.appendChild(h)}e.element=h,e.handler=rn.repeat,e.rollback=function(){var t=e.element;t&&e.handler("clear")}}if(!r){e.$outer={};var g="$key",y="$val";for(Array.isArray(a)&&(g="$first",y="$last"),u=0;s=t[u++];)if(s.hasOwnProperty(g)&&s.hasOwnProperty(y)){e.$outer=s;break}var b=a.$events,x=(b||{})[jt];M(x,e),"object"===i?e.handler("append"):a.length&&e.handler("add",0,a.length)}},rn.repeat=function(e,t,n){var a=this;if(!e&&a.xtype){var i=a.$repeat,o=a.evaluator.apply(0,a.args||[]);if("array"===a.xtype){if(i.length===o.length)return;e="add",t=0,a.$repeat=o,n=o.length}else{if(E(i).join(";;")===E(o).join(";;"))return;e="append",a.$repeat=o}}if(e){var l,s,c=a.element,u=ht(a),f=c.parentNode,p=a.proxies,d=Yt.cloneNode(!1);switch(e){case"add":for(var v=t+n,h=[],m=t;v>m;m++){var g=$t(m,a);p.splice(m,0,g),vt(a,d,g,h)}for(f.insertBefore(d,u[t]||c),m=0;s=h[m++];)it(s.nodes,s.vmodels),s.nodes=s.vmodels=null;break;case"del":mt(u[t],u[t+n]||c);var y=p.splice(t,n);bt(y,"each");break;case"clear":l=u[0],l&&(mt(l,c),"object"===a.xtype?f.insertBefore(l,c):bt(p,"each"));break;case"move":if(l=u[0]){var b,x=l.nodeValue,w=[],$=[];for(mt(l,c,function(){$.unshift(this),this.nodeValue===x&&(w.unshift($),$=[])}),N(w,t),N(p,t);$=w.shift();)for(;b=$.shift();)d.appendChild(b);f.insertBefore(d,c)}break;case"index":for(var C=p.length-1;n=p[t];t++)n.$index=t,n.$first=0===t,n.$last=t===C;return;case"set":g=p[t],g&&S(g.$events[a.param||"el"]);break;case"append":var k=a.$repeat,T=Array.isArray(p)||!p?{}:p;a.proxies=T;var A=[];h=[];for(var _ in T)k.hasOwnProperty(_)||(Ct(T[_],ma),delete T[_]);for(_ in k)k.hasOwnProperty(_)&&"hasOwnProperty"!==_&&A.push(_);if(a.sortedCallback){var O=a.sortedCallback.call(f,A);O&&Array.isArray(O)&&O.length&&(A=O)}for(m=0;_=A[m++];)"hasOwnProperty"!==_&&(T[_]=yt(T[_],_,a),vt(a,d,T[_],h));for(f.insertBefore(d,c),m=0;s=h[m++];)it(s.nodes,s.vmodels),s.nodes=s.vmodels=null}if(!a.$repeat||a.$repeat.hasOwnProperty("$lock"))return;"clear"===e&&(e="del");var M=a.renderedCallback||r,j=arguments;f.oldValue&&"SELECT"===f.tagName&&avalon(f).val(f.oldValue.split(",")),M.apply(f,j)}},"with,each".replace(Pt,function(e){nn[e]=nn.repeat});var ma=[],ga=[];rn.text=function(e,t){if(e=null==e?"":e,3===t.nodeType)try{t.data=e}catch(n){}else"textContent"in t?t.textContent=e:t.innerText=e},avalon.parseDisplay=kt,nn.visible=function(e,t){Q(e.value,t,e)},rn.visible=function(e,t,n){e?(t.style.display=n.display||"","none"===avalon(t).css("display")&&(t.style.display=n.display=kt(t.nodeName))):t.style.display="none"},nn.widget=function(t,a){var i=t.value.match(Pt),o=t.element,l=i[0],s=i[1];s&&"$"!==s||(s=Zt(l));var c=i[2]||l,u=avalon.ui[l];if("function"==typeof u){a=o.vmodels||a;for(var f,p=0;f=a[p++];)if(f.hasOwnProperty(c)&&"object"==typeof f[c]){var d=f[c];d=d.$model||d;break}if(d){var v=d[l+"Id"];"string"==typeof v&&(n("warning!不再支持"+l+"Id"),s=v)}var h=avalon.getWidgetData(o,l);t.value=[l,s,c].join(","),t[l+"Id"]=s,t.evaluator=r,o.msData["ms-widget-id"]=s;var m=t[l+"Options"]=avalon.mix({},u.defaults,d||{},h);o.removeAttribute("ms-widget");var g=u(o,t,a)||{};if(g.$id){avalon.vmodels[s]=g,et(o,g);try{g.$init(function(){avalon.scan(o,[g].concat(a)),"function"==typeof m.onInit&&m.onInit.call(o,g,m,a)})}catch(y){}t.rollback=function(){try{g.$remove(),g.widgetElement=null}catch(e){}o.msData={},delete avalon.vmodels[g.$id]},L(t,ya),e.chrome&&o.addEventListener("DOMNodeRemovedFromDocument",function(){setTimeout(H)})}else avalon.scan(o,a)}else a.length&&(o.vmodels=a)};var ya=[],ba=/<script[^>]*>([\S\s]*?)<\/script\s*>/gim,xa=/\s+(on[^=\s]+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,wa=/<\w+\b(?:(["'])[^"]*?(\1)|[^>])*>/gi,$a={a:/\b(href)\=("javascript[^"]*"|'javascript[^']*')/gi,img:/\b(src)\=("javascript[^"]*"|'javascript[^']*')/gi,form:/\b(action)\=("javascript[^"]*"|'javascript[^']*')/gi},Ca=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,ka=/([^\#-~| |!])/g,Ta=avalon.filters={uppercase:function(e){return e.toUpperCase()},lowercase:function(e){return e.toLowerCase()},truncate:function(e,t,n){return t=t||30,n="string"==typeof n?n:"...",e.length>t?e.slice(0,t-n.length)+n:String(e)},$filter:function(e){for(var t=1,n=arguments.length;n>t;t++){var r=arguments[t],a=avalon.filters[r.shift()];if("function"==typeof a){var i=[e].concat(r);e=a.apply(null,i)}}return e},camelize:I,sanitize:function(e){return e.replace(ba,"").replace(wa,function(e){var t=e.toLowerCase().match(/<(\w+)\s/);if(t){var n=$a[t[1]];n&&(e=e.replace(n,function(e,t,n){var r=n.charAt(0);return t+"="+r+"javascript:void(0)"+r}))}return e.replace(xa," ").replace(/\s+/g," ")})},escape:function(e){return String(e).replace(/&/g,"&amp;").replace(Ca,function(e){var t=e.charCodeAt(0),n=e.charCodeAt(1);return"&#"+(1024*(t-55296)+(n-56320)+65536)+";"}).replace(ka,function(e){return"&#"+e.charCodeAt(0)+";"}).replace(/</g,"&lt;").replace(/>/g,"&gt;")},currency:function(e,t,n){return(t||"¥")+Tt(e,isFinite(n)?n:2)},number:Tt};!new function(){function e(e){return parseInt(e,10)||0}function t(e,t,n){var r="";for(0>e&&(r="-",e=-e),e=""+e;e.length<t;)e="0"+e;return n&&(e=e.substr(e.length-t)),r+e}function n(e,n,r,a){return function(i){var o=i["get"+e]();return(r>0||o>-r)&&(o+=r),0===o&&-12===r&&(o=12),t(o,n,a)}}function r(e,t){return function(n,r){var a=n["get"+e](),i=(t?"SHORT"+e:e).toUpperCase();return r[i][a]}}function a(e){var n=-1*e.getTimezoneOffset(),r=n>=0?"+":"";return r+=t(Math[n>0?"floor":"ceil"](n/60),2)+t(Math.abs(n%60),2)}function i(e,t){return e.getHours()<12?t.AMPMS[0]:t.AMPMS[1]}var o={yyyy:n("FullYear",4),yy:n("FullYear",2,0,!0),y:n("FullYear",1),MMMM:r("Month"),MMM:r("Month",!0),MM:n("Month",2,1),M:n("Month",1,1),dd:n("Date",2),d:n("Date",1),HH:n("Hours",2),H:n("Hours",1),hh:n("Hours",2,-12),h:n("Hours",1,-12),mm:n("Minutes",2),m:n("Minutes",1),ss:n("Seconds",2),s:n("Seconds",1),sss:n("Milliseconds",3),EEEE:r("Day"),EEE:r("Day",!0),a:i,Z:a},l=/((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z))(.*)/,s=/^\/Date\((\d+)\)\/$/;
3
+ Ta.date=function(t,n){var r,a,i=Ta.date.locate,c="",u=[];if(n=n||"mediumDate",n=i[n]||n,"string"==typeof t)if(/^\d+$/.test(t))t=e(t);else if(s.test(t))t=+RegExp.$1;else{var f=t.trim(),p=[0,0,0,0,0,0,0],d=new Date(0);f=f.replace(/^(\d+)\D(\d+)\D(\d+)/,function(t,n,r,a){var i=4===a.length?[a,n,r]:[n,r,a];return p[0]=e(i[0]),p[1]=e(i[1])-1,p[2]=e(i[2]),""});var v=d.setFullYear,h=d.setHours;f=f.replace(/[T\s](\d+):(\d+):?(\d+)?\.?(\d)?/,function(t,n,r,a,i){return p[3]=e(n),p[4]=e(r),p[5]=e(a),i&&(p[6]=Math.round(1e3*parseFloat("0."+i))),""});var m=0,g=0;f=f.replace(/Z|([+-])(\d\d):?(\d\d)/,function(t,n,r,a){return v=d.setUTCFullYear,h=d.setUTCHours,n&&(m=e(n+r),g=e(n+a)),""}),p[3]-=m,p[4]-=g,v.apply(d,p.slice(0,3)),h.apply(d,p.slice(3)),t=d}if("number"==typeof t&&(t=new Date(t)),"date"===avalon.type(t)){for(;n;)a=l.exec(n),a?(u=u.concat(a.slice(1)),n=u.pop()):(u.push(n),n=null);return u.forEach(function(e){r=o[e],c+=r?r(t,i):e.replace(/(^'|'$)/g,"").replace(/''/g,"'")}),c}};var c={AMPMS:{0:"上午",1:"下午"},DAY:{0:"星期日",1:"星期一",2:"星期二",3:"星期三",4:"星期四",5:"星期五",6:"星期六"},MONTH:{0:"1月",1:"2月",2:"3月",3:"4月",4:"5月",5:"6月",6:"7月",7:"8月",8:"9月",9:"10月",10:"11月",11:"12月"},SHORTDAY:{0:"周日",1:"周一",2:"周二",3:"周三",4:"周四",5:"周五",6:"周六"},fullDate:"y年M月d日EEEE",longDate:"y年M月d日",medium:"yyyy-M-d H:mm:ss",mediumDate:"yyyy-M-d",mediumTime:"H:mm:ss","short":"yy-M-d ah:mm",shortDate:"yy-M-d",shortTime:"ah:mm"};c.SHORTMONTH=c.MONTH,Ta.date.locate=c};var Ea=avalon.modules={"domReady!":{exports:avalon,state:3},avalon:{exports:avalon,state:4}};Ea.exports=Ea.avalon,new function(){function t(e,t){var r="js";e=e.replace(/^(\w+)\!/,function(e,t){return r=t,""}),"ready"===r&&(n("debug: ready!已经被废弃,请使用domReady!"),r="domReady");var a="";e=e.replace(D,function(e){return a=e,""});var i="."+r,o=/js|css/.test(i)?i:"";e=e.replace(/\.[a-z0-9]+$/g,function(e){return e===i?(o=e,""):e});var l=avalon.mix({query:a,ext:o,res:r,name:e,toUrl:m},t);return l.toUrl(e),l}function i(e){var t=e.name,n=e.res,r=Ea[t],a=t&&e.urlNoQuery;if(r&&r.state>=1)return t;if(r=Ea[a],r&&r.state>=3)return Mt(r.deps||[],r.factory,a),a;if(t&&!r){r=Ea[a]={id:a,state:1};var i=function(a){H[n]=a,a.load(t,e,function(e){arguments.length&&void 0!==e&&(r.exports=e),r.state=4,s()})};H[n]?i(H[n]):Mt([n],i)}return t?a:n+"!"}function o(e,t){for(var n,r=0;n=e[r++];)if(4!==Ea[n].state&&(n===t||o(Ea[n].deps,t)))return!0}function l(e,t,r){var a=u(e.src);return e.onload=e.onreadystatechange=e.onerror=null,t||r&&Ea[a]&&!Ea[a].state?(setTimeout(function(){Ot.removeChild(e),e=null}),void n("debug: 加载 "+a+" 失败"+t+" "+!Ea[a].state)):!0}function s(){e:for(var e,t=T.length;e=T[--t];){var n=Ea[e],r=n.deps;if(r){for(var a,i=0;a=r[i];i++)if(4!==Object(Ea[a]).state)continue e;4!==n.state&&(T.splice(t,1),v(n.id,n.deps,n.factory),s())}}}function c(e,t,r){function a(){var a=E.pop();a&&a.require(t),r&&r(),l(i,!1,!c)&&(n("debug: 已成功加载 "+e),t&&T.push(t),s())}var i=_t.createElement("script");i.className=jt;var o,c="onload"in i,u=c?"onload":"onreadystatechange",f=0;i[u]=c?a:function(){L.test(i.readyState)&&(++f,1===f?o=setTimeout(a,500):(clearTimeout(o),a()))},i.onerror=function(){l(i,!0)},Ot.insertBefore(i,Ot.firstChild),i.src=e,n("debug: 正准备加载 "+e)}function u(e){return(e||"").replace(D,"")}function f(e){return/^(?:[a-z]+:)?\/\//i.test(String(e))}function p(e,t){return"1"[0]?e[t]:e.getAttribute(t,4)}function d(){var t;try{a.b.c()}catch(n){t=n.stack,!t&&e.opera&&(t=(String(n).match(/of linked script \S+/g)||[]).join(" "))}if(t)return t=t.split(/[@ ]/g).pop(),t="("===t[0]?t.slice(1,-1):t.replace(/\s/,""),u(t.replace(/(:\d+)?:\d+$/i,""));for(var r,i=Ot.getElementsByTagName("script"),o=i.length;r=i[--o];)if(r.className===jt&&"interactive"===r.readyState){var l=p(r,"src");return r.className=u(l)}}function v(t,r,a){var i=Object(Ea[t]);i.state=4;for(var o,l=0,s=[];o=r[l++];)if("exports"===o){var c=i.exports||(i.exports={});s.push(c)}else s.push(Ea[o].exports);try{var u=a.apply(e,s)}catch(f){n("执行["+t+"]模块的factory抛错: ",f)}return void 0!==u&&(i.exports=u),P.test(t)&&delete Ea[t],delete i.factory,u}function m(e){0===e.indexOf(this.res+"!")&&(e=e.slice(this.res.length+1));var t=e,n=0,r=this.baseUrl,a=this.parentUrl||r;w(e,h.paths,function(e,r){t=t.replace(r,e),n=1}),n||w(e,h.packages,function(e,n,r){t=t.replace(r.name,r.location)}),this.mapUrl&&w(this.mapUrl,h.map,function(e){w(t,e,function(e,n){t=t.replace(n,e),a=r})});var i=this.ext;i&&n&&t.slice(-i.length)===i&&(t=t.slice(0,-i.length)),f(t)||(a=this.built||/^\w/.test(t)?r:a,t=C(a,t));var o=t+i;return t=o+this.query,o=t.replace(D,function(e){return this.query=e,""}),w(e,h.urlArgs,function(e){t+=(-1===t.indexOf("?")?"?":"&")+e}),this.url=t,this.urlNoQuery=o}function g(e,t,n){var r=x(e,t,n);return r.sort($),r}function y(e){return new RegExp("^"+e+"(/|$)")}function b(t){return function(){var n;return t.init&&(n=t.init.apply(e,arguments)),n||t.exports&&k(t.exports)}}function x(e,t,n){var r=[];for(var a in e)if(Vt.call(e,a)){var i={name:a,val:e[a]};r.push(i),i.reg="*"===a&&t?/^/:y(a),n&&"*"!==a&&(i.reg=new RegExp("/"+a.replace(/^\//,"")+"(/|$)"))}return r}function w(e,t,n){t=t||[];for(var r,a=0;r=t[a++];)if(r.reg.test(e))return n(r.val,r.name,r),!1}function $(e,t){var n=e.name,r=t.name;return"*"===r?-1:"*"===n?1:r.length-n.length}function C(e,t){if("/"!==e.charAt(e.length-1)&&(e+="/"),"./"===t.slice(0,2))return e+t.slice(2);if(".."===t.slice(0,2)){for(e+=t;F.test(e);)e=e.replace(F,"");return e}return"/"===t.slice(0,1)?e+t.slice(1):e+t}function k(t){if(!t)return t;var n=e;return t.split(".").forEach(function(e){n=n[e]}),n}var T=[],E=[],A=/\.js$/i,_=[],O=!1;Mt=avalon.require=function(e,n,a,o){if(O){Array.isArray(e)||avalon.error("require方法的第一个参数应为数组 "+e);var l=[],c={},u=a||"callback"+setTimeout("1");o=o||{},o.baseUrl=h.baseUrl;var f=!!o.built;if(a&&(o.parentUrl=a.substr(0,a.lastIndexOf("/")),o.mapUrl=a.replace(A,"")),f){var p=t(o.defineName,o);u=p.urlNoQuery}else e.forEach(function(e){var n=t(e,o),r=i(n);r&&(c[r]||(l.push(r),c[r]="司徒正美"))});var d=Ea[u];d&&4===d.state||(Ea[u]={id:u,deps:f?e.concat():l,factory:n||r,state:3}),d||T.push(u),s()}else if(_.push(avalon.slice(arguments)),arguments.length<=2){O=!0;for(var v,m=_.splice(0,_.length);v=m.shift();)Mt.apply(null,v)}},Mt.define=function(e,t,n){"string"!=typeof e&&(n=t,t=e,e="anonymous"),Array.isArray(t)||(n=t,t=[]);var r={built:!O,defineName:e},a=[t,n,r];n.require=function(e){if(a.splice(2,0,e),Ea[e]){Ea[e].state=3;var t=!1;try{t=o(Ea[e].deps,e)}catch(r){}t&&avalon.error(e+"模块与之前的模块存在循环依赖,请不要直接用script标签引入"+e+"模块")}delete n.require,Mt.apply(null,a)};var i=r.built?"unknown":d();if(i){var l=Ea[i];l&&(l.state=2),n.require(i)}else E.push(n)},Mt.config=h,Mt.define.amd=Ea;var N=h["orig.paths"]={},M=h["orig.map"]={},S=h.packages=[],j=h["orig.args"]={};avalon.mix(Cn,{paths:function(e){avalon.mix(N,e),h.paths=g(N)},map:function(e){avalon.mix(M,e);var t=g(M,1,1);avalon.each(t,function(e,t){t.val=g(t.val)}),h.map=t},packages:function(e){e=e.concat(S);for(var t,n={},r=[],a=0;t=e[a++];){t="string"==typeof t?{name:t}:t;var i=t.name;if(!n[i]){var o=C(t.location||i,t.main||"main");o=o.replace(A,""),r.push(t),n[i]=t.location=o,t.reg=y(i)}}h.packages=r.sort()},urlArgs:function(e){"string"==typeof e&&(e={"*":e}),avalon.mix(j,e),h.urlArgs=g(j,1)},baseUrl:function(e){if(!f(e)){var t=Ot.getElementsByTagName("base")[0];t&&Ot.removeChild(t);var n=_t.createElement("a");n.href=e,e=p(n,"href"),t&&Ot.insertBefore(t,Ot.firstChild)}e.length>3&&(h.baseUrl=e)},shim:function(e){for(var t in e){var n=e[t];Array.isArray(n)&&(n=e[t]={deps:n}),n.exportsFn||!n.exports&&!n.init||(n.exportsFn=b(n))}h.shim=e}});var L=/complete|loaded/,H=Mt.plugins={ready:{load:r},js:{load:function(e,t,n){var r=t.url,a=t.urlNoQuery,i=h.shim[e.replace(A,"")];i?Mt(i.deps||[],function(){var e=avalon.slice(arguments);c(r,a,function(){n(i.exportsFn?i.exportsFn.apply(0,e):void 0)})}):c(r,a)}},css:{load:function(e,t,r){var a=t.url,i=_t.createElement("link");i.rel="stylesheet",i.href=a,Ot.insertBefore(i,Ot.firstChild),n("debug: 已成功加载 "+a),r()}},text:{load:function(e,t,r){var a=t.url,i=sa();i.onreadystatechange=function(){if(4===i.readyState){var e=i.status;e>399&&600>e?avalon.error(a+" 对应资源不存在或没有开启 CORS"):(n("debug: 已成功加载 "+a),r(i.responseText))}};var o="_="+(new Date-0),l=-1===a.indexOf("?")?a+"?"+o:a+"&"+o;i.open("GET",l,!0),"withCredentials"in i&&(i.withCredentials=!0),i.setRequestHeader("X-Requested-With","XMLHttpRequest"),i.send(),n("debug: 正准备加载 "+a)}}};Mt.checkDeps=s;var D=/(\?[^#]*)$/,P=/^callback\d+$/,F=/\/\w+\/\.\./,B=_t.scripts[_t.scripts.length-1],R=B.getAttribute("data-main");if(R){Cn.baseUrl(R);var I=h.baseUrl;h.baseUrl=I.slice(0,I.lastIndexOf("/")+1),c(I.replace(A,"")+".js")}else{var V=u(p(B,"src"));h.baseUrl=V.slice(0,V.lastIndexOf("/")+1)}};var Aa,_a=[],Oa=function(e){for(Aa=!0,Mt&&(Ea["domReady!"].state=4,Mt.checkDeps());e=_a.shift();)e(avalon)};if("complete"===_t.readyState)setTimeout(Oa);else if(Wt)_t.addEventListener("DOMContentLoaded",Oa);else{_t.attachEvent("onreadystatechange",function(){"complete"===_t.readyState&&Oa()});try{var Na=null===e.frameElement}catch(Sn){}Xt.doScroll&&Na&&e.external&&Et()}avalon.bind(e,"load",Oa),avalon.ready=function(e){Aa?e(avalon):_a.push(e)},avalon.config({loader:!0}),avalon.ready(function(){avalon.scan(_t.body)}),"function"==typeof define&&define.amd&&define("avalon",[],function(){return avalon});var Ma=e.avalon;return avalon.noConflict=function(t){return t&&e.avalon===avalon&&(e.avalon=Ma),avalon},void 0===t&&(e.avalon=avalon),avalon});
@@ -5,7 +5,7 @@
5
5
  http://weibo.com/jslouvre/
6
6
 
7
7
  Released under the MIT license
8
- avalon.mobile.js 1.41 built in 2015.4.4
8
+ avalon.mobile.js 1.46 built in 2015.9.11
9
9
  support IE10+ and other browsers
10
10
  ==================================================*/
11
11
  (function(global, factory) {
@@ -76,10 +76,10 @@ var aslice = ap.slice
76
76
  var Registry = {} //将函数曝光到此对象上,方便访问器收集依赖
77
77
  var W3C = window.dispatchEvent
78
78
  var root = DOC.documentElement
79
- var hyperspace = DOC.createDocumentFragment()
79
+ var avalonFragment = DOC.createDocumentFragment()
80
80
  var cinerator = DOC.createElement("div")
81
81
  var class2type = {}
82
- "Boolean Number String Function Array Date RegExp Object Error".replace(rword, function(name) {
82
+ "Boolean Number String Function Array Date RegExp Object Error".replace(rword, function (name) {
83
83
  class2type["[object " + name + "]"] = name.toLowerCase()
84
84
  })
85
85
 
@@ -101,30 +101,35 @@ function oneObject(array, val) {
101
101
  }
102
102
 
103
103
  //生成UUID http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
104
- var generateID = function(prefix) {
104
+ var generateID = function (prefix) {
105
105
  prefix = prefix || "avalon"
106
- return (prefix + Math.random() + Math.random()).replace(/0\./g, "")
106
+ return String(Math.random() + Math.random()).replace(/\d\.\d{4}/, prefix)
107
107
  }
108
108
  function IE() {
109
109
  if (window.VBArray) {
110
110
  var mode = document.documentMode
111
111
  return mode ? mode : window.XMLHttpRequest ? 7 : 6
112
112
  } else {
113
- return 0
113
+ return NaN
114
114
  }
115
115
  }
116
116
  var IEVersion = IE()
117
117
 
118
- avalon = function(el) { //创建jQuery式的无new 实例化结构
118
+ avalon = function (el) { //创建jQuery式的无new 实例化结构
119
119
  return new avalon.init(el)
120
120
  }
121
121
 
122
+ avalon.profile = function () {
123
+ if (window.console && avalon.config.profile) {
124
+ Function.apply.call(console.log, console, arguments)
125
+ }
126
+ }
127
+
122
128
  /*视浏览器情况采用最快的异步回调*/
123
- avalon.nextTick = new function() {// jshint ignore:line
129
+ avalon.nextTick = new function () {// jshint ignore:line
124
130
  var tickImmediate = window.setImmediate
125
131
  var tickObserver = window.MutationObserver
126
- var tickPost = W3C && window.postMessage
127
- if (tickImmediate) {
132
+ if (tickImmediate) {//IE10 \11 edage
128
133
  return tickImmediate.bind(window)
129
134
  }
130
135
 
@@ -137,32 +142,32 @@ avalon.nextTick = new function() {// jshint ignore:line
137
142
  queue = queue.slice(n)
138
143
  }
139
144
 
140
- if (tickObserver) {
145
+ if (tickObserver) {// 支持MutationObserver
141
146
  var node = document.createTextNode("avalon")
142
147
  new tickObserver(callback).observe(node, {characterData: true})// jshint ignore:line
143
- return function(fn) {
148
+ return function (fn) {
144
149
  queue.push(fn)
145
150
  node.data = Math.random()
146
151
  }
147
152
  }
148
153
 
149
- if (tickPost) {
150
- window.addEventListener("message", function(e) {
151
- var source = e.source
152
- if ((source === window || source === null) && e.data === "process-tick") {
153
- e.stopPropagation()
154
- callback()
155
- }
156
- })
157
-
158
- return function(fn) {
154
+ if (window.VBArray) {
155
+ return function (fn) {
159
156
  queue.push(fn)
160
- window.postMessage('process-tick', '*')
157
+ var node = DOC.createElement("script")
158
+ node.onreadystatechange = function () {
159
+ callback() //在interactive阶段就触发
160
+ node.onreadystatechange = null
161
+ head.removeChild(node)
162
+ node = null
163
+ }
164
+ head.appendChild(node)
161
165
  }
162
166
  }
163
167
 
164
- return function(fn) {
165
- setTimeout(fn, 0)
168
+
169
+ return function (fn) {
170
+ setTimeout(fn, 4)
166
171
  }
167
172
  }// jshint ignore:line
168
173
  /*********************************************************************
@@ -263,7 +268,7 @@ function _number(a, len) { //用于模拟slice, splice的效果
263
268
  avalon.mix({
264
269
  rword: rword,
265
270
  subscribers: subscribers,
266
- version: 1.41,
271
+ version: 1.46,
267
272
  ui: {},
268
273
  log: log,
269
274
  slice: function(nodes, start, end) {
@@ -466,6 +471,7 @@ var Cache = new function() {// jshint ignore:line
466
471
  entry.newer =
467
472
  entry.older =
468
473
  this._keymap[entry.key] = void 0
474
+ delete this._keymap[entry.key] //#1029
469
475
  }
470
476
  }
471
477
  p.get = function(key) {
@@ -642,7 +648,6 @@ if (DOC.onmousewheel === void 0) {
642
648
  }
643
649
  }
644
650
  }
645
-
646
651
  /*********************************************************************
647
652
  * 配置系统 *
648
653
  **********************************************************************/
@@ -680,15 +685,15 @@ var plugins = {
680
685
  openTag = array[0]
681
686
  closeTag = array[1]
682
687
  if (openTag === closeTag) {
683
- throw new SyntaxError("openTag!==closeTag")
684
- } else if (array + "" === "<!--,-->") {
685
- kernel.commentInterpolate = true
688
+ throw new SyntaxError("openTag===closeTag")
686
689
  } else {
687
690
  var test = openTag + "test" + closeTag
688
691
  cinerator.innerHTML = test
689
692
  if (cinerator.innerHTML !== test && cinerator.innerHTML.indexOf("&lt;") > -1) {
690
693
  throw new SyntaxError("此定界符不合法")
691
694
  }
695
+ kernel.openTag = openTag
696
+ kernel.closeTag = closeTag
692
697
  cinerator.innerHTML = ""
693
698
  }
694
699
  var o = escapeRegExp(openTag),
@@ -777,8 +782,8 @@ var EventBus = {
777
782
  }
778
783
  //循环两个vmodel中的节点,查找匹配(向上匹配或者向下匹配)的节点并设置标识
779
784
  /* jshint ignore:start */
780
- Array.prototype.forEach.call(eventNodes, function (node) {
781
- Array.prototype.forEach.call(elements, function (element) {
785
+ ap.forEach.call(eventNodes, function (node) {
786
+ ap.forEach.call(elements, function (element) {
782
787
  var ok = special === "down" ? element.contains(node) : //向下捕获
783
788
  node.contains(element) //向上冒泡
784
789
  if (ok) {
@@ -792,7 +797,7 @@ var EventBus = {
792
797
  }
793
798
  var nodes = DOC.getElementsByTagName("*") //实现节点排序
794
799
  var alls = []
795
- Array.prototype.forEach.call(nodes, function (el) {
800
+ ap.forEach.call(nodes, function (el) {
796
801
  if (el._avalon) {
797
802
  alls.push(el._avalon)
798
803
  el._avalon = ""
@@ -821,12 +826,11 @@ var EventBus = {
821
826
  }
822
827
  }
823
828
  }
824
-
825
829
  /*********************************************************************
826
830
  * modelFactory *
827
831
  **********************************************************************/
828
832
  //avalon最核心的方法的两个方法之一(另一个是avalon.scan),返回一个ViewModel(VM)
829
- var VMODELS = avalon.vmodels = createMap() //所有vmodel都储存在这里
833
+ var VMODELS = avalon.vmodels = {} //所有vmodel都储存在这里
830
834
  avalon.define = function (id, factory) {
831
835
  var $id = id.$id || id
832
836
  if (!$id) {
@@ -852,194 +856,271 @@ avalon.define = function (id, factory) {
852
856
  }
853
857
 
854
858
  //一些不需要被监听的属性
855
- var $$skipArray = String("$id,$watch,$unwatch,$fire,$events,$model,$skipArray").match(rword)
856
-
857
- function isObservable(name, value, $skipArray) {
858
- if (isFunction(value) || value && value.nodeType) {
859
- return false
860
- }
861
- if ($skipArray.indexOf(name) !== -1) {
862
- return false
863
- }
864
- if ($$skipArray.indexOf(name) !== -1) {
865
- return false
866
- }
867
- var $special = $skipArray.$special
868
- if (name && name.charAt(0) === "$" && !$special[name]) {
869
- return false
870
- }
871
- return true
872
- }
873
- //ms-with,ms-each, ms-repeat绑定生成的代理对象储存池
874
- var midway = createMap()
875
- function getNewValue(accessor, name, value, $vmodel) {
876
- switch (accessor.type) {
877
- case 0://计算属性
878
- var getter = accessor.get
879
- var setter = accessor.set
880
- if (isFunction(setter)) {
881
- var $events = $vmodel.$events
882
- var lock = $events[name]
883
- $events[name] = [] //清空回调,防止内部冒泡而触发多次$fire
884
- setter.call($vmodel, value)
885
- $events[name] = lock
886
- }
887
- return getter.call($vmodel) //同步$model
888
- case 1://监控属性
889
- return value
890
- case 2://对象属性(包括数组与哈希)
891
- if (value !== $vmodel.$model[name]) {
892
- var svmodel = accessor.svmodel = objectFactory($vmodel, name, value, accessor.valueType)
893
- value = svmodel.$model //同步$model
894
- var fn = midway[svmodel.$id]
895
- fn && fn() //同步视图
896
- }
897
- return value
898
- }
899
- }
859
+ var $$skipArray = String("$id,$watch,$unwatch,$fire,$events,$model,$skipArray,$reinitialize").match(rword)
900
860
 
901
861
  function modelFactory(source, $special, $model) {
902
862
  if (Array.isArray(source)) {
903
863
  var arr = source.concat()
904
864
  source.length = 0
905
- var collection = Collection(source)// jshint ignore:line
865
+ var collection = arrayFactory(source)// jshint ignore:line
906
866
  collection.pushArray(arr)
907
867
  return collection
908
868
  }
909
- //0 null undefined || Node || VModel
869
+ //0 null undefined || Node || VModel(fix IE6-8 createWithProxy $val: val引发的BUG)
910
870
  if (!source || source.nodeType > 0 || (source.$id && source.$events)) {
911
871
  return source
912
872
  }
913
- if (!Array.isArray(source.$skipArray)) {
914
- source.$skipArray = []
915
- }
916
- source.$skipArray.$special = $special || createMap() //强制要监听的属性
873
+ var $skipArray = Array.isArray(source.$skipArray) ? source.$skipArray : []
874
+ $skipArray.$special = $special || createMap() //强制要监听的属性
917
875
  var $vmodel = {} //要返回的对象, 它在IE6-8下可能被偷龙转凤
918
876
  $model = $model || {} //vmodels.$model属性
919
877
  var $events = createMap() //vmodel.$events属性
920
- var watchedProperties = createMap() //监控属性
921
- var initCallbacks = [] //初始化才执行的函数
922
- for (var i in source) {
923
- (function (name, val) {
924
- $model[name] = val
925
- if (!isObservable(name, val, source.$skipArray)) {
926
- return //过滤所有非监控属性
927
- }
878
+ var accessors = createMap() //监控属性
879
+ var computed = []
880
+ $$skipArray.forEach(function (name) {
881
+ delete source[name]
882
+ })
883
+
884
+ var names = Object.keys(source)
885
+ /* jshint ignore:start */
886
+ names.forEach(function (name, accessor) {
887
+ var val = source[name]
888
+ $model[name] = val
889
+ if (isObservable(name, val, $skipArray)) {
928
890
  //总共产生三种accessor
929
891
  $events[name] = []
930
892
  var valueType = avalon.type(val)
931
- var accessor = function (newValue) {
932
- var name = accessor._name
933
- var $vmodel = this
934
- var $model = $vmodel.$model
935
- var oldValue = $model[name]
936
- var $events = $vmodel.$events
937
-
938
- if (arguments.length) {
939
- if (stopRepeatAssign) {
940
- return
941
- }
942
- //计算属性与对象属性需要重新计算newValue
943
- if (accessor.type !== 1) {
944
- newValue = getNewValue(accessor, name, newValue, $vmodel)
945
- if (!accessor.type)
946
- return
947
- }
948
- if (!isEqual(oldValue, newValue)) {
949
- $model[name] = newValue
950
- notifySubscribers($events[name]) //同步视图
951
- safeFire($vmodel, name, newValue, oldValue) //触发$watch回调
952
- }
953
- } else {
954
- if (accessor.type === 0) { //type 0 计算属性 1 监控属性 2 对象属性
955
- //计算属性不需要收集视图刷新函数,都是由其他监控属性代劳
956
- newValue = accessor.get.call($vmodel)
957
- if (oldValue !== newValue) {
958
- $model[name] = newValue
959
- //这里不用同步视图
960
- safeFire($vmodel, name, newValue, oldValue) //触发$watch回调
961
- }
962
- return newValue
963
- } else {
964
- collectSubscribers($events[name]) //收集视图函数
965
- return accessor.svmodel || oldValue
966
- }
967
- }
968
- }
969
893
  //总共产生三种accessor
970
894
  if (valueType === "object" && isFunction(val.get) && Object.keys(val).length <= 2) {
971
- //第1种为计算属性, 因变量,通过其他监控属性触发其改变
972
- accessor.set = val.set
973
- accessor.get = val.get
974
- accessor.type = 0
975
- initCallbacks.push(function () {
976
- var data = {
977
- evaluator: function () {
978
- data.type = Math.random(),
979
- data.element = null
980
- $model[name] = accessor.get.call($vmodel)
981
- },
982
- element: head,
983
- type: Math.random(),
984
- handler: noop,
985
- args: []
986
- }
987
- Registry[expose] = data
988
- accessor.call($vmodel)
989
- delete Registry[expose]
990
- })
895
+ accessor = makeComputedAccessor(name, val)
896
+ computed.push(accessor)
991
897
  } else if (rcomplexType.test(valueType)) {
992
- //第2种为对象属性,产生子VM与监控数组
993
- accessor.type = 2
994
- accessor.valueType = valueType
995
- initCallbacks.push(function () {
996
- var svmodel = modelFactory(val, 0, $model[name])
997
- accessor.svmodel = svmodel
998
- svmodel.$events[subscribers] = $events[name]
999
- })
898
+ // issue #940 解决$model层次依赖丢失 https://github.com/RubyLouvre/avalon/issues/940
899
+ accessor = makeComplexAccessor(name, val, valueType, $events[name], $model)
1000
900
  } else {
1001
- accessor.type = 1
1002
- //第3种为监控属性,对应简单的数据类型,自变量
901
+ accessor = makeSimpleAccessor(name, val)
1003
902
  }
1004
- accessor._name = name
1005
- watchedProperties[name] = accessor
1006
- })(i, source[i])// jshint ignore:line
1007
- }
1008
-
1009
- $$skipArray.forEach(function (name) {
1010
- delete source[name]
1011
- delete $model[name] //这些特殊属性不应该在$model中出现
903
+ accessors[name] = accessor
904
+ }
1012
905
  })
1013
-
1014
- $vmodel = Object.defineProperties($vmodel, descriptorFactory(watchedProperties), source) //生成一个空的ViewModel
1015
- for (var name in source) {
1016
- if (!watchedProperties[name]) {
906
+ /* jshint ignore:end */
907
+ $vmodel = Object.defineProperties($vmodel, descriptorFactory(accessors)) //生成一个空的ViewModel
908
+ for (var i = 0; i < names.length; i++) {
909
+ var name = names[i]
910
+ if (!accessors[name]) {
1017
911
  $vmodel[name] = source[name]
1018
912
  }
1019
913
  }
1020
914
  //添加$id, $model, $events, $watch, $unwatch, $fire
1021
- $vmodel.$id = generateID()
1022
- $vmodel.$model = $model
1023
- $vmodel.$events = $events
1024
- for (i in EventBus) {
1025
- $vmodel[i] = EventBus[i]
915
+ hideProperty($vmodel, "$id", generateID())
916
+ hideProperty($vmodel, "$model", $model)
917
+ hideProperty($vmodel, "$events", $events)
918
+ /* jshint ignore:start */
919
+ hideProperty($vmodel, "hasOwnProperty", function (name) {
920
+ return name in this.$model
921
+ })
922
+ /* jshint ignore:end */
923
+ for (var i in EventBus) {
924
+ hideProperty($vmodel, i, EventBus[i])
925
+ }
926
+
927
+ $vmodel.$reinitialize = function () {
928
+ computed.forEach(function (accessor) {
929
+ delete accessor._value
930
+ delete accessor.oldArgs
931
+ accessor.digest = function () {
932
+ accessor.call($vmodel)
933
+ }
934
+ dependencyDetection.begin({
935
+ callback: function (vm, dependency) {//dependency为一个accessor
936
+ var name = dependency._name
937
+ if (dependency !== accessor) {
938
+ var list = vm.$events[name]
939
+ accessor.vm = $vmodel
940
+ injectDependency(list, accessor.digest)
941
+ }
942
+ }
943
+ })
944
+ try {
945
+ accessor.get.call($vmodel)
946
+ } finally {
947
+ dependencyDetection.end()
948
+ }
949
+ })
1026
950
  }
951
+ $vmodel.$reinitialize()
952
+ return $vmodel
953
+ }
1027
954
 
1028
- Object.defineProperty($vmodel, "hasOwnProperty", {
1029
- value: function (name) {
1030
- return name in this.$model
1031
- },
1032
- writable: false,
955
+ function hideProperty(host, name, value) {
956
+ Object.defineProperty(host, name, {
957
+ value: value,
958
+ writable: true,
1033
959
  enumerable: false,
1034
960
  configurable: true
1035
961
  })
962
+ }
1036
963
 
1037
- initCallbacks.forEach(function (cb) { //收集依赖
1038
- cb()
1039
- })
1040
- return $vmodel
964
+ function keysVM(obj) {
965
+ var arr = Object.keys(obj)
966
+ for (var i = 0; i < $$skipArray.length; i++) {
967
+ var index = arr.indexOf($$skipArray[i])
968
+ if (index !== -1) {
969
+ arr.splice(index, 1)
970
+ }
971
+ }
972
+ return arr
973
+ }
974
+ //创建一个简单访问器
975
+ function makeSimpleAccessor(name, value) {
976
+ function accessor(value) {
977
+ var oldValue = accessor._value
978
+ if (arguments.length > 0) {
979
+ if (!stopRepeatAssign && !isEqual(value, oldValue)) {
980
+ accessor.updateValue(this, value)
981
+ accessor.notify(this, value, oldValue)
982
+ }
983
+ return this
984
+ } else {
985
+ dependencyDetection.collectDependency(this, accessor)
986
+ return oldValue
987
+ }
988
+ }
989
+ accessorFactory(accessor, name)
990
+ accessor._value = value
991
+ return accessor;
992
+ }
993
+
994
+ ///创建一个计算访问器
995
+ function makeComputedAccessor(name, options) {
996
+ function accessor(value) {//计算属性
997
+ var oldValue = accessor._value
998
+ var init = ("_value" in accessor)
999
+ if (arguments.length > 0) {
1000
+ if (stopRepeatAssign) {
1001
+ return this
1002
+ }
1003
+ if (typeof accessor.set === "function") {
1004
+ if (accessor.oldArgs !== value) {
1005
+ accessor.oldArgs = value
1006
+ var $events = this.$events
1007
+ var lock = $events[name]
1008
+ $events[name] = [] //清空回调,防止内部冒泡而触发多次$fire
1009
+ accessor.set.call(this, value)
1010
+ $events[name] = lock
1011
+ value = accessor.get.call(this)
1012
+ if (value !== oldValue) {
1013
+ accessor.updateValue(this, value)
1014
+ accessor.notify(this, value, oldValue) //触发$watch回调
1015
+ }
1016
+ }
1017
+ }
1018
+ return this
1019
+ } else {
1020
+ //将依赖于自己的高层访问器或视图刷新函数(以绑定对象形式)放到自己的订阅数组中
1021
+ //将自己注入到低层访问器的订阅数组中
1022
+ value = accessor.get.call(this)
1023
+ accessor.updateValue(this, value)
1024
+ if (init && oldValue !== value) {
1025
+ accessor.notify(this, value, oldValue) //触发$watch回调
1026
+ }
1027
+ return value
1028
+ }
1029
+ }
1030
+ accessor.set = options.set
1031
+ accessor.get = options.get
1032
+ accessorFactory(accessor, name)
1033
+ return accessor
1034
+ }
1035
+
1036
+
1037
+ //创建一个复杂访问器
1038
+ function makeComplexAccessor(name, initValue, valueType, list, parentModel) {
1039
+ function accessor(value) {
1040
+ var oldValue = accessor._value
1041
+ var son = accessor._vmodel
1042
+ if (arguments.length > 0) {
1043
+ if (stopRepeatAssign) {
1044
+ return this
1045
+ }
1046
+ if (valueType === "array") {
1047
+ var a = son, b = value,
1048
+ an = a.length,
1049
+ bn = b.length
1050
+ a.$lock = true
1051
+ if (an > bn) {
1052
+ a.splice(bn, an - bn)
1053
+ } else if (bn > an) {
1054
+ a.push.apply(a, b.slice(an))
1055
+ }
1056
+ var n = Math.min(an, bn)
1057
+ for (var i = 0; i < n; i++) {
1058
+ a.set(i, b[i])
1059
+ }
1060
+ delete a.$lock
1061
+ a._fire("set")
1062
+ } else if (valueType === "object") {
1063
+ var observes = this.$events[name] || []
1064
+ var newObject = avalon.mix(true, {}, value)
1065
+ for (i in son) {
1066
+ if (son.hasOwnProperty(i) && ohasOwn.call(newObject, i)) {
1067
+ son[i] = newObject[i]
1068
+ }
1069
+ }
1070
+ son = accessor._vmodel = modelFactory(value)
1071
+ son.$events[subscribers] = observes
1072
+ if (observes.length) {
1073
+ observes.forEach(function (data) {
1074
+ if(!data.type) {
1075
+ return //防止模板先加载报错
1076
+ }
1077
+ if (data.rollback) {
1078
+ data.rollback() //还原 ms-with ms-on
1079
+ }
1080
+ bindingHandlers[data.type](data, data.vmodels)
1081
+ })
1082
+ }
1083
+ }
1084
+ accessor.updateValue(this, son.$model)
1085
+ accessor.notify(this, this._value, oldValue)
1086
+ return this
1087
+ } else {
1088
+ dependencyDetection.collectDependency(this, accessor)
1089
+ return son
1090
+ }
1091
+ }
1092
+ accessorFactory(accessor, name)
1093
+ if (Array.isArray(initValue)) {
1094
+ parentModel[name] = initValue
1095
+ } else {
1096
+ parentModel[name] = parentModel[name] || {}
1097
+ }
1098
+ var son = accessor._vmodel = modelFactory(initValue, 0, parentModel[name])
1099
+ son.$events[subscribers] = list
1100
+ return accessor
1101
+ }
1102
+
1103
+ function globalUpdateValue(vmodel, value) {
1104
+ vmodel.$model[this._name] = this._value = value
1105
+ }
1106
+ function globalUpdateModelValue(vmodel, value) {
1107
+ vmodel.$model[this._name] = value
1108
+ }
1109
+ function globalNotify(vmodel, value, oldValue) {
1110
+ var name = this._name
1111
+ var array = vmodel.$events[name] //刷新值
1112
+ if (array) {
1113
+ fireDependencies(array) //同步视图
1114
+ EventBus.$fire.call(vmodel, name, value, oldValue) //触发$watch回调
1115
+ }
1041
1116
  }
1042
1117
 
1118
+ function accessorFactory(accessor, name) {
1119
+ accessor._name = name
1120
+ //同时更新_value与model
1121
+ accessor.updateValue = globalUpdateValue
1122
+ accessor.notify = globalNotify
1123
+ }
1043
1124
  //比较两个值是否相等
1044
1125
  var isEqual = Object.is || function (v1, v2) {
1045
1126
  if (v1 === 0 && v2 === 0) {
@@ -1051,14 +1132,22 @@ var isEqual = Object.is || function (v1, v2) {
1051
1132
  }
1052
1133
  }
1053
1134
 
1054
- function safeFire(a, b, c, d) {
1055
- if (a.$events) {
1056
- EventBus.$fire.call(a, b, c, d)
1135
+ function isObservable(name, value, $skipArray) {
1136
+ if (isFunction(value) || value && value.nodeType) {
1137
+ return false
1138
+ }
1139
+ if ($skipArray.indexOf(name) !== -1) {
1140
+ return false
1141
+ }
1142
+ var $special = $skipArray.$special
1143
+ if (name && name.charAt(0) === "$" && !$special[name]) {
1144
+ return false
1057
1145
  }
1146
+ return true
1058
1147
  }
1059
1148
 
1060
1149
  var descriptorFactory = function (obj) {
1061
- var descriptors = createMap()
1150
+ var descriptors = {}
1062
1151
  for (var i in obj) {
1063
1152
  descriptors[i] = {
1064
1153
  get: obj[i],
@@ -1070,50 +1159,12 @@ var descriptorFactory = function (obj) {
1070
1159
  return descriptors
1071
1160
  }
1072
1161
 
1073
- //应用于第2种accessor
1074
- function objectFactory(parent, name, value, valueType) {
1075
- //a为原来的VM, b为新数组或新对象
1076
- var son = parent[name]
1077
- if (valueType === "array") {
1078
- if (!Array.isArray(value) || son === value) {
1079
- return son //fix https://github.com/RubyLouvre/avalon/issues/261
1080
- }
1081
- son._.$unwatch()
1082
- son.clear()
1083
- son._.$watch()
1084
- son.pushArray(value.concat())
1085
- return son
1086
- } else {
1087
- var iterators = parent.$events[name]
1088
- var pool = son.$events.$withProxyPool
1089
- if (pool) {
1090
- recycleProxies(pool, "with")
1091
- son.$events.$withProxyPool = null
1092
- }
1093
- var ret = modelFactory(value)
1094
- ret.$events[subscribers] = iterators
1095
- midway[ret.$id] = function (data) {
1096
- while (data = iterators.shift()) {
1097
- (function (el) {
1098
- avalon.nextTick(function () {
1099
- var type = el.type
1100
- if (type && bindingHandlers[type]) { //#753
1101
- el.rollback && el.rollback() //还原 ms-with ms-on
1102
- bindingHandlers[type](el, el.vmodels)
1103
- }
1104
- })
1105
- })(data)// jshint ignore:line
1106
- }
1107
- delete midway[ret.$id]
1108
- }
1109
- return ret
1110
- }
1111
- }
1162
+
1112
1163
  /*********************************************************************
1113
1164
  * 监控数组(与ms-each, ms-repeat配合使用) *
1114
1165
  **********************************************************************/
1115
1166
 
1116
- function Collection(model) {
1167
+ function arrayFactory(model) {
1117
1168
  var array = []
1118
1169
  array.$id = generateID()
1119
1170
  array.$model = model //数据模型
@@ -1128,7 +1179,7 @@ function Collection(model) {
1128
1179
  for (var i in EventBus) {
1129
1180
  array[i] = EventBus[i]
1130
1181
  }
1131
- avalon.mix(array, CollectionPrototype)
1182
+ avalon.mix(array, arrayPrototype)
1132
1183
  return array
1133
1184
  }
1134
1185
 
@@ -1136,7 +1187,7 @@ function mutateArray(method, pos, n, index, method2, pos2, n2) {
1136
1187
  var oldLen = this.length, loop = 2
1137
1188
  while (--loop) {
1138
1189
  switch (method) {
1139
- case "add":
1190
+ case "add":
1140
1191
  /* jshint ignore:start */
1141
1192
  var array = this.$model.slice(pos, pos + n).map(function (el) {
1142
1193
  if (rcomplexType.test(avalon.type(el))) {
@@ -1170,10 +1221,10 @@ function mutateArray(method, pos, n, index, method2, pos2, n2) {
1170
1221
  }
1171
1222
 
1172
1223
  var _splice = ap.splice
1173
- var CollectionPrototype = {
1224
+ var arrayPrototype = {
1174
1225
  _splice: _splice,
1175
1226
  _fire: function (method, a, b) {
1176
- notifySubscribers(this.$events[subscribers], method, a, b)
1227
+ fireDependencies(this.$events[subscribers], method, a, b)
1177
1228
  },
1178
1229
  size: function () { //取得数组长度,这个函数可以同步视图,length不能
1179
1230
  return this._.length
@@ -1259,11 +1310,13 @@ var CollectionPrototype = {
1259
1310
  },
1260
1311
  removeAll: function (all) { //移除N个元素
1261
1312
  if (Array.isArray(all)) {
1262
- all.forEach(function (el) {
1263
- this.remove(el)
1264
- }, this)
1265
- } else if (typeof all === "function") {
1266
1313
  for (var i = this.length - 1; i >= 0; i--) {
1314
+ if (all.indexOf(this[i]) !== -1) {
1315
+ this.removeAt(i)
1316
+ }
1317
+ }
1318
+ } else if (typeof all === "function") {
1319
+ for ( i = this.length - 1; i >= 0; i--) {
1267
1320
  var el = this[i]
1268
1321
  if (all(el, i)) {
1269
1322
  this.removeAt(i)
@@ -1280,7 +1333,7 @@ var CollectionPrototype = {
1280
1333
  return this
1281
1334
  },
1282
1335
  set: function (index, val) {
1283
- if (index >= 0) {
1336
+ if (index < this.length && index > -1) {
1284
1337
  var valueType = avalon.type(val)
1285
1338
  if (val && val.$model) {
1286
1339
  val = val.$model
@@ -1303,6 +1356,15 @@ var CollectionPrototype = {
1303
1356
  return this
1304
1357
  }
1305
1358
  }
1359
+ //相当于原来bindingExecutors.repeat 的index分支
1360
+ function resetIndex(array, pos) {
1361
+ var last = array.length - 1
1362
+ for (var el; el = array[pos]; pos++) {
1363
+ el.$index = pos
1364
+ el.$first = pos === 0
1365
+ el.$last = pos === last
1366
+ }
1367
+ }
1306
1368
 
1307
1369
  function sortByIndex(array, indexes) {
1308
1370
  var map = {};
@@ -1319,7 +1381,7 @@ function sortByIndex(array, indexes) {
1319
1381
  }
1320
1382
 
1321
1383
  "sort,reverse".replace(rword, function (method) {
1322
- CollectionPrototype[method] = function () {
1384
+ arrayPrototype[method] = function () {
1323
1385
  var newArray = this.$model//这是要排序的新数组
1324
1386
  var oldArray = newArray.concat() //保持原来状态的旧数组
1325
1387
  var mask = Math.random()
@@ -1340,28 +1402,57 @@ function sortByIndex(array, indexes) {
1340
1402
  }
1341
1403
  if (hasSort) {
1342
1404
  sortByIndex(this, indexes)
1405
+ // sortByIndex(this.$proxy, indexes)
1343
1406
  this._fire("move", indexes)
1344
- this._fire("index", 0)
1407
+ this._fire("index", 0)
1345
1408
  }
1346
1409
  return this
1347
1410
  }
1348
1411
  })
1349
1412
 
1413
+
1350
1414
  /*********************************************************************
1351
1415
  * 依赖调度系统 *
1352
1416
  **********************************************************************/
1417
+ //检测两个对象间的依赖关系
1418
+ var dependencyDetection = (function () {
1419
+ var outerFrames = []
1420
+ var currentFrame
1421
+ return {
1422
+ begin: function (accessorObject) {
1423
+ //accessorObject为一个拥有callback的对象
1424
+ outerFrames.push(currentFrame)
1425
+ currentFrame = accessorObject
1426
+ },
1427
+ end: function () {
1428
+ currentFrame = outerFrames.pop()
1429
+ },
1430
+ collectDependency: function (vmodel, accessor) {
1431
+ if (currentFrame) {
1432
+ //被dependencyDetection.begin调用
1433
+ currentFrame.callback(vmodel, accessor);
1434
+ }
1435
+ }
1436
+ };
1437
+ })()
1438
+ //将绑定对象注入到其依赖项的订阅数组中
1353
1439
  var ronduplex = /^(duplex|on)$/
1354
-
1355
- function registerSubscriber(data) {
1356
- Registry[expose] = data //暴光此函数,方便collectSubscribers收集
1357
- avalon.openComputedCollect = true
1358
- var fn = data.evaluator
1359
- if (fn) { //如果是求值函数
1440
+ avalon.injectBinding = function (data) {
1441
+ var valueFn = data.evaluator
1442
+ if (valueFn) { //如果是求值函数
1443
+ dependencyDetection.begin({
1444
+ callback: function (vmodel, dependency) {
1445
+ injectDependency(vmodel.$events[dependency._name], data)
1446
+ }
1447
+ })
1360
1448
  try {
1361
- var c = ronduplex.test(data.type) ? data : fn.apply(0, data.args)
1362
- data.handler(c, data.element, data)
1449
+ var value = ronduplex.test(data.type) ? data : valueFn.apply(0, data.args)
1450
+ if(value === void 0){
1451
+ delete data.evaluator
1452
+ }
1453
+ data.handler(value, data.element, data)
1363
1454
  } catch (e) {
1364
- //log("warning:exception throwed in [registerSubscriber] " + e)
1455
+ log("warning:exception throwed in [avalon.injectBinding] " , e)
1365
1456
  delete data.evaluator
1366
1457
  var node = data.element
1367
1458
  if (node.nodeType === 3) {
@@ -1369,126 +1460,160 @@ function registerSubscriber(data) {
1369
1460
  if (kernel.commentInterpolate) {
1370
1461
  parent.replaceChild(DOC.createComment(data.value), node)
1371
1462
  } else {
1372
- node.data = openTag + data.value + closeTag
1463
+ node.data = openTag + (data.oneTime ? "::" : "") + data.value + closeTag
1373
1464
  }
1374
1465
  }
1466
+ } finally {
1467
+ dependencyDetection.end()
1375
1468
  }
1376
1469
  }
1377
- avalon.openComputedCollect = false
1378
- delete Registry[expose]
1379
1470
  }
1380
1471
 
1381
- function collectSubscribers(list) { //收集依赖于这个访问器的订阅者
1382
- var data = Registry[expose]
1383
- if (list && data && avalon.Array.ensure(list, data) && data.element) { //只有数组不存在此元素才push进去
1384
- addSubscribers(data, list)
1472
+ //将依赖项(比它高层的访问器或构建视图刷新函数的绑定对象)注入到订阅者数组
1473
+ function injectDependency(list, data) {
1474
+ if (data.oneTime)
1475
+ return
1476
+ if (list && avalon.Array.ensure(list, data) && data.element) {
1477
+ injectDisposeQueue(data, list)
1478
+ if (new Date() - beginTime > 444 ) {
1479
+ rejectDisposeQueue()
1480
+ }
1385
1481
  }
1386
1482
  }
1387
1483
 
1388
-
1389
- function addSubscribers(data, list) {
1390
- data.$uuid = data.$uuid || generateID()
1391
- list.$uuid = list.$uuid || generateID()
1392
- var obj = {
1393
- data: data,
1394
- list: list,
1395
- $$uuid: data.$uuid + list.$uuid
1396
- }
1397
- if (!$$subscribers[obj.$$uuid]) {
1398
- $$subscribers[obj.$$uuid] = 1
1399
- $$subscribers.push(obj)
1484
+ //通知依赖于这个访问器的订阅者更新自身
1485
+ function fireDependencies(list) {
1486
+ if (list && list.length) {
1487
+ if (new Date() - beginTime > 444 && typeof list[0] === "object") {
1488
+ rejectDisposeQueue()
1489
+ }
1490
+ var args = aslice.call(arguments, 1)
1491
+ for (var i = list.length, fn; fn = list[--i]; ) {
1492
+ var el = fn.element
1493
+ if (el && el.parentNode) {
1494
+ try {
1495
+ var valueFn = fn.evaluator
1496
+ if (fn.$repeat) {
1497
+ fn.handler.apply(fn, args) //处理监控数组的方法
1498
+ }else if("$repeat" in fn || !valueFn ){//如果没有eval,先eval
1499
+ bindingHandlers[fn.type](fn, fn.vmodels)
1500
+ } else if (fn.type !== "on") { //事件绑定只能由用户触发,不能由程序触发
1501
+ var value = valueFn.apply(0, fn.args || [])
1502
+ fn.handler(value, el, fn)
1503
+ }
1504
+ } catch (e) {
1505
+ console.log(e)
1506
+ }
1507
+ }
1508
+ }
1400
1509
  }
1401
1510
  }
1402
-
1403
- function disposeData(data) {
1404
- data.element = null
1405
- data.rollback && data.rollback()
1406
- for (var key in data) {
1407
- data[key] = null
1511
+ /*********************************************************************
1512
+ * 定时GC回收机制 *
1513
+ **********************************************************************/
1514
+ var disposeCount = 0
1515
+ var disposeQueue = avalon.$$subscribers = []
1516
+ var beginTime = new Date()
1517
+ var oldInfo = {}
1518
+ //var uuid2Node = {}
1519
+ function getUid(elem, makeID) { //IE9+,标准浏览器
1520
+ if (!elem.uuid && !makeID) {
1521
+ elem.uuid = ++disposeCount
1408
1522
  }
1523
+ return elem.uuid
1409
1524
  }
1410
1525
 
1411
- function isRemove(el) {
1412
- try {//IE下,如果文本节点脱离DOM树,访问parentNode会报错
1413
- if (!el.parentNode) {
1414
- return true
1526
+ //添加到回收列队中
1527
+ function injectDisposeQueue(data, list) {
1528
+ var elem = data.element
1529
+ if (!data.uuid) {
1530
+ if (elem.nodeType !== 1) {
1531
+ data.uuid = data.type + (data.pos || 0) + "-" + getUid(elem.parentNode)
1532
+ } else {
1533
+ data.uuid = data.name + "-" + getUid(elem)
1415
1534
  }
1416
- } catch (e) {
1417
- return true
1418
1535
  }
1419
- return el.msRetain ? 0 : (el.nodeType === 1 ? typeof el.sourceIndex === "number" ?
1420
- el.sourceIndex === 0 : !root.contains(el) : !avalon.contains(root, el))
1536
+ var lists = data.lists || (data.lists = [])
1537
+ avalon.Array.ensure(lists, list)
1538
+ list.$uuid = list.$uuid || generateID()
1539
+ if (!disposeQueue[data.uuid]) {
1540
+ disposeQueue[data.uuid] = 1
1541
+ disposeQueue.push(data)
1542
+ }
1421
1543
  }
1422
- var $$subscribers = avalon.$$subscribers = []
1423
- var beginTime = new Date()
1424
- var oldInfo = {}
1425
- function removeSubscribers() {
1426
- var i = $$subscribers.length
1544
+
1545
+ function rejectDisposeQueue(data) {
1546
+ if (avalon.optimize)
1547
+ return
1548
+ var i = disposeQueue.length
1427
1549
  var n = i
1428
- var k = 0
1429
- var obj
1430
- var types = []
1550
+ var allTypes = []
1551
+ var iffishTypes = {}
1431
1552
  var newInfo = {}
1432
- var needTest = {}
1433
- while (obj = $$subscribers[--i]) {
1434
- var data = obj.data
1553
+ //对页面上所有绑定对象进行分门别类, 只检测个数发生变化的类型
1554
+ while (data = disposeQueue[--i]) {
1435
1555
  var type = data.type
1436
1556
  if (newInfo[type]) {
1437
1557
  newInfo[type]++
1438
1558
  } else {
1439
1559
  newInfo[type] = 1
1440
- types.push(type)
1560
+ allTypes.push(type)
1441
1561
  }
1442
1562
  }
1443
1563
  var diff = false
1444
- types.forEach(function(type) {
1564
+ allTypes.forEach(function (type) {
1445
1565
  if (oldInfo[type] !== newInfo[type]) {
1446
- needTest[type] = 1
1566
+ iffishTypes[type] = 1
1447
1567
  diff = true
1448
1568
  }
1449
1569
  })
1450
1570
  i = n
1451
- //avalon.log("需要检测的个数 " + i)
1452
1571
  if (diff) {
1453
- //avalon.log("有需要移除的元素")
1454
- while (obj = $$subscribers[--i]) {
1455
- data = obj.data
1456
- if (data.element === void 0)
1572
+ while (data = disposeQueue[--i]) {
1573
+ if (data.element === null) {
1574
+ disposeQueue.splice(i, 1)
1457
1575
  continue
1458
- if (needTest[data.type] && isRemove(data.element)) { //如果它没有在DOM树
1459
- k++
1460
- $$subscribers.splice(i, 1)
1461
- delete $$subscribers[obj.$$uuid]
1462
- avalon.Array.remove(obj.list, data)
1463
- //log("debug: remove " + data.type)
1576
+ }
1577
+ if (iffishTypes[data.type] && shouldDispose(data.element)) { //如果它没有在DOM树
1578
+ disposeQueue.splice(i, 1)
1579
+ delete disposeQueue[data.uuid]
1580
+ //delete uuid2Node[data.element.uuid]
1581
+ var lists = data.lists
1582
+ for (var k = 0, list; list = lists[k++]; ) {
1583
+ avalon.Array.remove(lists, list)
1584
+ avalon.Array.remove(list, data)
1585
+ }
1464
1586
  disposeData(data)
1465
- obj.data = obj.list = null
1466
1587
  }
1467
1588
  }
1468
1589
  }
1469
1590
  oldInfo = newInfo
1470
- // avalon.log("已经移除的个数 " + k)
1471
1591
  beginTime = new Date()
1472
1592
  }
1473
1593
 
1474
- function notifySubscribers(list) { //通知依赖于这个访问器的订阅者更新自身
1475
- if (list && list.length) {
1476
- if (new Date() - beginTime > 444 && typeof list[0] === "object") {
1477
- removeSubscribers()
1478
- }
1479
- var args = aslice.call(arguments, 1)
1480
- for (var i = list.length, fn; fn = list[--i]; ) {
1481
- var el = fn.element
1482
- if (el && el.parentNode) {
1483
- if (fn.$repeat) {
1484
- fn.handler.apply(fn, args) //处理监控数组的方法
1485
- } else if (fn.type !== "on") { //事件绑定只能由用户触发,不能由程序触发
1486
- var fun = fn.evaluator || noop
1487
- fn.handler(fun.apply(0, fn.args || []), el, fn)
1488
- }
1489
- }
1594
+ function disposeData(data) {
1595
+ delete disposeQueue[data.uuid] // 先清除,不然无法回收了
1596
+ data.element = null
1597
+ data.rollback && data.rollback()
1598
+ for (var key in data) {
1599
+ data[key] = null
1600
+ }
1601
+ }
1602
+
1603
+ function shouldDispose(el) {
1604
+ try {//IE下,如果文本节点脱离DOM树,访问parentNode会报错
1605
+ var fireError = el.parentNode.nodeType
1606
+ } catch (e) {
1607
+ return true
1608
+ }
1609
+ if (el.ifRemove) {
1610
+ // 如果节点被放到ifGroup,才移除
1611
+ if (!root.contains(el.ifRemove) && (ifGroup === el.parentNode)) {
1612
+ el.parentNode && el.parentNode.removeChild(el)
1613
+ return true
1490
1614
  }
1491
1615
  }
1616
+ return el.msRetain ? 0 : (el.nodeType === 1 ? !root.contains(el) : !avalon.contains(root, el))
1492
1617
  }
1493
1618
 
1494
1619
  /************************************************************************
@@ -1521,7 +1646,7 @@ var scriptTypes = oneObject(["", "text/javascript", "text/ecmascript", "applicat
1521
1646
  var script = DOC.createElement("script")
1522
1647
  var rhtml = /<|&#?\w+;/
1523
1648
  avalon.parseHTML = function(html) {
1524
- var fragment = hyperspace.cloneNode(false)
1649
+ var fragment = avalonFragment.cloneNode(false)
1525
1650
  if (typeof html !== "string" ) {
1526
1651
  return fragment
1527
1652
  }
@@ -1569,351 +1694,30 @@ avalon.clearHTML = function(node) {
1569
1694
  }
1570
1695
 
1571
1696
  /*********************************************************************
1572
- * 扫描系统 *
1697
+ * avalon的原型方法定义区 *
1573
1698
  **********************************************************************/
1574
1699
 
1575
- avalon.scan = function(elem, vmodel, group) {
1576
- elem = elem || root
1577
- var vmodels = vmodel ? [].concat(vmodel) : []
1578
- scanTag(elem, vmodels)
1700
+ function hyphen(target) {
1701
+ //转换为连字符线风格
1702
+ return target.replace(/([a-z\d])([A-Z]+)/g, "$1-$2").toLowerCase()
1579
1703
  }
1580
1704
 
1581
- //http://www.w3.org/TR/html5/syntax.html#void-elements
1582
- var stopScan = oneObject("area,base,basefont,br,col,command,embed,hr,img,input,link,meta,param,source,track,wbr,noscript,script,style,textarea".toUpperCase())
1583
-
1584
- function checkScan(elem, callback, innerHTML) {
1585
- var id = setTimeout(function() {
1586
- var currHTML = elem.innerHTML
1587
- clearTimeout(id)
1588
- if (currHTML === innerHTML) {
1589
- callback()
1590
- } else {
1591
- checkScan(elem, callback, currHTML)
1592
- }
1705
+ function camelize(target) {
1706
+ //转换为驼峰风格
1707
+ if (target.indexOf("-") < 0 && target.indexOf("_") < 0) {
1708
+ return target //提前判断,提高getStyle等的效率
1709
+ }
1710
+ return target.replace(/[-_][^-_]/g, function(match) {
1711
+ return match.charAt(1).toUpperCase()
1593
1712
  })
1594
1713
  }
1595
1714
 
1596
-
1597
- function createSignalTower(elem, vmodel) {
1598
- var id = elem.getAttribute("avalonctrl") || vmodel.$id
1599
- elem.setAttribute("avalonctrl", id)
1600
- vmodel.$events.expr = elem.tagName + '[avalonctrl="' + id + '"]'
1601
- }
1602
-
1603
- var getBindingCallback = function(elem, name, vmodels) {
1604
- var callback = elem.getAttribute(name)
1605
- if (callback) {
1606
- for (var i = 0, vm; vm = vmodels[i++]; ) {
1607
- if (vm.hasOwnProperty(callback) && typeof vm[callback] === "function") {
1608
- return vm[callback]
1609
- }
1610
- }
1611
- }
1612
- }
1613
-
1614
- function executeBindings(bindings, vmodels) {
1615
- for (var i = 0, data; data = bindings[i++]; ) {
1616
- data.vmodels = vmodels
1617
- bindingHandlers[data.type](data, vmodels)
1618
- if (data.evaluator && data.element && data.element.nodeType === 1) { //移除数据绑定,防止被二次解析
1619
- //chrome使用removeAttributeNode移除不存在的特性节点时会报错 https://github.com/RubyLouvre/avalon/issues/99
1620
- data.element.removeAttribute(data.name)
1621
- }
1622
- }
1623
- bindings.length = 0
1624
- }
1625
-
1626
- //https://github.com/RubyLouvre/avalon/issues/636
1627
- var mergeTextNodes = IEVersion && window.MutationObserver ? function (elem) {
1628
- var node = elem.firstChild, text
1629
- while (node) {
1630
- var aaa = node.nextSibling
1631
- if (node.nodeType === 3) {
1632
- if (text) {
1633
- text.nodeValue += node.nodeValue
1634
- elem.removeChild(node)
1635
- } else {
1636
- text = node
1637
- }
1638
- } else {
1639
- text = null
1640
- }
1641
- node = aaa
1642
- }
1643
- } : 0
1644
-
1645
- var rmsAttr = /ms-(\w+)-?(.*)/
1646
- var priorityMap = {
1647
- "if": 10,
1648
- "repeat": 90,
1649
- "data": 100,
1650
- "widget": 110,
1651
- "each": 1400,
1652
- "with": 1500,
1653
- "duplex": 2000,
1654
- "on": 3000
1655
- }
1656
-
1657
- var events = oneObject("animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scan,scroll,submit")
1658
- var obsoleteAttrs = oneObject("value,title,alt,checked,selected,disabled,readonly,enabled")
1659
- function bindingSorter(a, b) {
1660
- return a.priority - b.priority
1661
- }
1662
-
1663
- function scanAttr(elem, vmodels) {
1664
- //防止setAttribute, removeAttribute时 attributes自动被同步,导致for循环出错
1665
- var attributes = elem.hasAttributes() ? avalon.slice(elem.attributes) : []
1666
- var bindings = [],
1667
- msData = createMap(),
1668
- match
1669
- for (var i = 0, attr; attr = attributes[i++]; ) {
1670
- if (attr.specified) {
1671
- if (match = attr.name.match(rmsAttr)) {
1672
- //如果是以指定前缀命名的
1673
- var type = match[1]
1674
- var param = match[2] || ""
1675
- var value = attr.value
1676
- var name = attr.name
1677
- msData[name] = value
1678
- if (events[type]) {
1679
- param = type
1680
- type = "on"
1681
- } else if (obsoleteAttrs[type]) {
1682
- log("warning!请改用ms-attr-" + type + "代替ms-" + type + "!")
1683
- if (type === "enabled") {//吃掉ms-enabled绑定,用ms-disabled代替
1684
- log("warning!ms-enabled或ms-attr-enabled已经被废弃")
1685
- type = "disabled"
1686
- value = "!(" + value + ")"
1687
- }
1688
- param = type
1689
- type = "attr"
1690
- elem.removeAttribute(name)
1691
- name = "ms-attr-" + param
1692
- elem.setAttribute(name, value)
1693
- match = [name]
1694
- msData[name] = value
1695
- }
1696
- if (typeof bindingHandlers[type] === "function") {
1697
- var binding = {
1698
- type: type,
1699
- param: param,
1700
- element: elem,
1701
- name: match[0],
1702
- value: value,
1703
- priority: type in priorityMap ? priorityMap[type] : type.charCodeAt(0) * 10 + (Number(param) || 0)
1704
- }
1705
- if (type === "html" || type === "text") {
1706
- var token = getToken(value)
1707
- avalon.mix(binding, token)
1708
- binding.filters = binding.filters.replace(rhasHtml, function () {
1709
- binding.type = "html"
1710
- binding.group = 1
1711
- return ""
1712
- })// jshint ignore:line
1713
- }
1714
- if (name === "ms-if-loop") {
1715
- binding.priority += 100
1716
- }
1717
- if (vmodels.length) {
1718
- bindings.push(binding)
1719
- if (type === "widget") {
1720
- elem.msData = elem.msData || msData
1721
- }
1722
- }
1723
- }
1724
- }
1725
- }
1726
- }
1727
- var control = elem.type
1728
- if (control && msData["ms-duplex"]) {
1729
- if (msData["ms-attr-checked"] && /radio|checkbox/.test(control)) {
1730
- log("warning!" + control + "控件不能同时定义ms-attr-checked与ms-duplex")
1731
- }
1732
- if (msData["ms-attr-value"] && /text|password/.test(control)) {
1733
- log("warning!" + control + "控件不能同时定义ms-attr-value与ms-duplex")
1734
- }
1735
- }
1736
- bindings.sort(bindingSorter)
1737
- var scanNode = true
1738
- for (i = 0; binding = bindings[i]; i++) {
1739
- type = binding.type
1740
- if (rnoscanAttrBinding.test(type)) {
1741
- return executeBindings(bindings.slice(0, i + 1), vmodels)
1742
- } else if (scanNode) {
1743
- scanNode = !rnoscanNodeBinding.test(type)
1744
- }
1745
- }
1746
- executeBindings(bindings, vmodels)
1747
- if (scanNode && !stopScan[elem.tagName] && rbind.test(elem.innerHTML + elem.textContent)) {
1748
- mergeTextNodes && mergeTextNodes(elem)
1749
- scanNodeList(elem, vmodels) //扫描子孙元素
1750
- }
1751
- }
1752
-
1753
- var rnoscanAttrBinding = /^if|widget|repeat$/
1754
- var rnoscanNodeBinding = /^each|with|html|include$/
1755
- function scanNodeList(parent, vmodels) {
1756
- var node = parent.firstChild
1757
- while (node) {
1758
- var nextNode = node.nextSibling
1759
- scanNode(node, node.nodeType, vmodels)
1760
- node = nextNode
1761
- }
1762
- }
1763
-
1764
- function scanNodeArray(nodes, vmodels) {
1765
- for (var i = 0, node; node = nodes[i++]; ) {
1766
- scanNode(node, node.nodeType, vmodels)
1767
- }
1768
- }
1769
- function scanNode(node, nodeType, vmodels) {
1770
- if (nodeType === 1) {
1771
- scanTag(node, vmodels) //扫描元素节点
1772
- } else if (nodeType === 3 && rexpr.test(node.data)){
1773
- scanText(node, vmodels) //扫描文本节点
1774
- } else if (kernel.commentInterpolate && nodeType === 8 && !rexpr.test(node.nodeValue)) {
1775
- scanText(node, vmodels) //扫描注释节点
1776
- }
1777
- }
1778
- function scanTag(elem, vmodels, node) {
1779
- //扫描顺序 ms-skip(0) --> ms-important(1) --> ms-controller(2) --> ms-if(10) --> ms-repeat(100)
1780
- //--> ms-if-loop(110) --> ms-attr(970) ...--> ms-each(1400)-->ms-with(1500)--〉ms-duplex(2000)垫后
1781
- var a = elem.getAttribute("ms-skip")
1782
- var b = elem.getAttributeNode("ms-important")
1783
- var c = elem.getAttributeNode("ms-controller")
1784
- if (typeof a === "string") {
1785
- return
1786
- } else if (node = b || c) {
1787
- var newVmodel = avalon.vmodels[node.value]
1788
- if (!newVmodel) {
1789
- return
1790
- }
1791
- //ms-important不包含父VM,ms-controller相反
1792
- vmodels = node === b ? [newVmodel] : [newVmodel].concat(vmodels)
1793
- elem.removeAttribute(node.name) //removeAttributeNode不会刷新[ms-controller]样式规则
1794
- elem.classList.remove(node.name)
1795
- createSignalTower(elem, newVmodel)
1796
- }
1797
- scanAttr(elem, vmodels) //扫描特性节点
1798
- }
1799
- var rhasHtml = /\|\s*html\s*/,
1800
- r11a = /\|\|/g,
1801
- rlt = /&lt;/g,
1802
- rgt = /&gt;/g
1803
- rstringLiteral = /(['"])(\\\1|.)+?\1/g
1804
- function getToken(value) {
1805
- if (value.indexOf("|") > 0) {
1806
- var scapegoat = value.replace( rstringLiteral, function(_){
1807
- return Array(_.length+1).join("1")// jshint ignore:line
1808
- })
1809
- var index = scapegoat.replace(r11a, "\u1122\u3344").indexOf("|") //干掉所有短路或
1810
- if (index > -1) {
1811
- return {
1812
- filters: value.slice(index),
1813
- value: value.slice(0, index),
1814
- expr: true
1815
- }
1816
- }
1817
- }
1818
- return {
1819
- value: value,
1820
- filters: "",
1821
- expr: true
1822
- }
1823
- }
1824
-
1825
- function scanExpr(str) {
1826
- var tokens = [],
1827
- value, start = 0,
1828
- stop
1829
- do {
1830
- stop = str.indexOf(openTag, start)
1831
- if (stop === -1) {
1832
- break
1833
- }
1834
- value = str.slice(start, stop)
1835
- if (value) { // {{ 左边的文本
1836
- tokens.push({
1837
- value: value,
1838
- filters: "",
1839
- expr: false
1840
- })
1841
- }
1842
- start = stop + openTag.length
1843
- stop = str.indexOf(closeTag, start)
1844
- if (stop === -1) {
1845
- break
1846
- }
1847
- value = str.slice(start, stop)
1848
- if (value) { //处理{{ }}插值表达式
1849
- tokens.push(getToken(value))
1850
- }
1851
- start = stop + closeTag.length
1852
- } while (1)
1853
- value = str.slice(start)
1854
- if (value) { //}} 右边的文本
1855
- tokens.push({
1856
- value: value,
1857
- expr: false,
1858
- filters: ""
1859
- })
1860
- }
1861
- return tokens
1862
- }
1863
-
1864
- function scanText(textNode, vmodels) {
1865
- var bindings = []
1866
- if (textNode.nodeType === 8) {
1867
- var token = getToken(textNode.nodeValue)
1868
- var tokens = [token]
1869
- } else {
1870
- tokens = scanExpr(textNode.data)
1871
- }
1872
- if (tokens.length) {
1873
- for (var i = 0; token = tokens[i++]; ) {
1874
- var node = DOC.createTextNode(token.value) //将文本转换为文本节点,并替换原来的文本节点
1875
- if (token.expr) {
1876
- token.type = "text"
1877
- token.element = node
1878
- token.filters = token.filters.replace(rhasHtml, function() {
1879
- token.type = "html"
1880
- token.group = 1
1881
- return ""
1882
- })// jshint ignore:line
1883
- bindings.push(token) //收集带有插值表达式的文本
1884
- }
1885
- hyperspace.appendChild(node)
1886
- }
1887
- textNode.parentNode.replaceChild(hyperspace, textNode)
1888
- if (bindings.length)
1889
- executeBindings(bindings, vmodels)
1890
- }
1891
- }
1892
-
1893
-
1894
- /*********************************************************************
1895
- * avalon的原型方法定义区 *
1896
- **********************************************************************/
1897
- function hyphen(target) {
1898
- //转换为连字符线风格
1899
- return target.replace(/([a-z\d])([A-Z]+)/g, "$1-$2").toLowerCase()
1900
- }
1901
- function camelize(target) {
1902
- //转换为驼峰风格
1903
- if (target.indexOf("-") < 0 && target.indexOf("_") < 0) {
1904
- return target //提前判断,提高getStyle等的效率
1905
- }
1906
- return target.replace(/[-_][^-_]/g, function (match) {
1907
- return match.charAt(1).toUpperCase()
1908
- })
1909
- }
1910
-
1911
- "add,remove".replace(rword, function (method) {
1912
- avalon.fn[method + "Class"] = function (cls) {
1715
+ "add,remove".replace(rword, function(method) {
1716
+ avalon.fn[method + "Class"] = function(cls) {
1913
1717
  var el = this[0]
1914
1718
  //https://developer.mozilla.org/zh-CN/docs/Mozilla/Firefox/Releases/26
1915
1719
  if (cls && typeof cls === "string" && el && el.nodeType === 1) {
1916
- cls.replace(/\S+/g, function (c) {
1720
+ cls.replace(/\S+/g, function(c) {
1917
1721
  el.classList[method](c)
1918
1722
  })
1919
1723
  }
@@ -1922,13 +1726,13 @@ function camelize(target) {
1922
1726
  })
1923
1727
 
1924
1728
  avalon.fn.mix({
1925
- hasClass: function (cls) {
1729
+ hasClass: function(cls) {
1926
1730
  var el = this[0] || {} //IE10+, chrome8+, firefox3.6+, safari5.1+,opera11.5+支持classList,chrome24+,firefox26+支持classList2.0
1927
1731
  return el.nodeType === 1 && el.classList.contains(cls)
1928
1732
  },
1929
- toggleClass: function (value, stateVal) {
1733
+ toggleClass: function(value, stateVal) {
1930
1734
  var className, i = 0
1931
- var classNames = value.split(/\s+/)
1735
+ var classNames = String(value).split(/\s+/)
1932
1736
  var isBool = typeof stateVal === "boolean"
1933
1737
  while ((className = classNames[i++])) {
1934
1738
  var state = isBool ? stateVal : !this.hasClass(className)
@@ -1936,7 +1740,7 @@ avalon.fn.mix({
1936
1740
  }
1937
1741
  return this
1938
1742
  },
1939
- attr: function (name, value) {
1743
+ attr: function(name, value) {
1940
1744
  if (arguments.length === 2) {
1941
1745
  this[0].setAttribute(name, value)
1942
1746
  return this
@@ -1944,7 +1748,7 @@ avalon.fn.mix({
1944
1748
  return this[0].getAttribute(name)
1945
1749
  }
1946
1750
  },
1947
- data: function (name, value) {
1751
+ data: function(name, value) {
1948
1752
  name = "data-" + hyphen(name || "")
1949
1753
  switch (arguments.length) {
1950
1754
  case 2:
@@ -1955,7 +1759,7 @@ avalon.fn.mix({
1955
1759
  return parseData(val)
1956
1760
  case 0:
1957
1761
  var ret = {}
1958
- ap.forEach.call(this[0].attributes, function (attr) {
1762
+ ap.forEach.call(this[0].attributes, function(attr) {
1959
1763
  if (attr) {
1960
1764
  name = attr.name
1961
1765
  if (!name.indexOf("data-")) {
@@ -1967,12 +1771,12 @@ avalon.fn.mix({
1967
1771
  return ret
1968
1772
  }
1969
1773
  },
1970
- removeData: function (name) {
1774
+ removeData: function(name) {
1971
1775
  name = "data-" + hyphen(name)
1972
1776
  this[0].removeAttribute(name)
1973
1777
  return this
1974
1778
  },
1975
- css: function (name, value) {
1779
+ css: function(name, value) {
1976
1780
  if (avalon.isPlainObject(name)) {
1977
1781
  for (var i in name) {
1978
1782
  avalon.css(this, i, name[i])
@@ -1982,13 +1786,13 @@ avalon.fn.mix({
1982
1786
  }
1983
1787
  return ret !== void 0 ? ret : this
1984
1788
  },
1985
- position: function () {
1789
+ position: function() {
1986
1790
  var offsetParent, offset,
1987
- elem = this[0],
1988
- parentOffset = {
1989
- top: 0,
1990
- left: 0
1991
- };
1791
+ elem = this[0],
1792
+ parentOffset = {
1793
+ top: 0,
1794
+ left: 0
1795
+ };
1992
1796
  if (!elem) {
1993
1797
  return
1994
1798
  }
@@ -2002,31 +1806,34 @@ avalon.fn.mix({
2002
1806
  }
2003
1807
  parentOffset.top += avalon.css(offsetParent[0], "borderTopWidth", true)
2004
1808
  parentOffset.left += avalon.css(offsetParent[0], "borderLeftWidth", true)
1809
+ // Subtract offsetParent scroll positions
1810
+ parentOffset.top -= offsetParent.scrollTop()
1811
+ parentOffset.left -= offsetParent.scrollLeft()
2005
1812
  }
2006
1813
  return {
2007
1814
  top: offset.top - parentOffset.top - avalon.css(elem, "marginTop", true),
2008
1815
  left: offset.left - parentOffset.left - avalon.css(elem, "marginLeft", true)
2009
1816
  }
2010
1817
  },
2011
- offsetParent: function () {
1818
+ offsetParent: function() {
2012
1819
  var offsetParent = this[0].offsetParent
2013
1820
  while (offsetParent && avalon.css(offsetParent, "position") === "static") {
2014
1821
  offsetParent = offsetParent.offsetParent;
2015
1822
  }
2016
1823
  return avalon(offsetParent || root)
2017
1824
  },
2018
- bind: function (type, fn, phase) {
1825
+ bind: function(type, fn, phase) {
2019
1826
  if (this[0]) { //此方法不会链
2020
1827
  return avalon.bind(this[0], type, fn, phase)
2021
1828
  }
2022
1829
  },
2023
- unbind: function (type, fn, phase) {
1830
+ unbind: function(type, fn, phase) {
2024
1831
  if (this[0]) {
2025
1832
  avalon.unbind(this[0], type, fn, phase)
2026
1833
  }
2027
1834
  return this
2028
1835
  },
2029
- val: function (value) {
1836
+ val: function(value) {
2030
1837
  var node = this[0]
2031
1838
  if (node && node.nodeType === 1) {
2032
1839
  var get = arguments.length === 0
@@ -2045,7 +1852,8 @@ avalon.fn.mix({
2045
1852
  })
2046
1853
 
2047
1854
  if (root.dataset) {
2048
- avalon.fn.data = function (name, val) {
1855
+ avalon.fn.data = function(name, val) {
1856
+ name = name && camelize(name)
2049
1857
  var dataset = this[0].dataset
2050
1858
  switch (arguments.length) {
2051
1859
  case 2:
@@ -2071,19 +1879,18 @@ function parseData(data) {
2071
1879
  if (typeof data === "object")
2072
1880
  return data
2073
1881
  data = data === "true" ? true :
2074
- data === "false" ? false :
2075
- data === "null" ? null : +data + "" === data ? +data : rbrace.test(data) ? JSON.parse(data) : data
2076
- } catch (e) {
2077
- }
1882
+ data === "false" ? false :
1883
+ data === "null" ? null : +data + "" === data ? +data : rbrace.test(data) ? JSON.parse(data) : data
1884
+ } catch (e) {}
2078
1885
  return data
2079
1886
  }
2080
1887
  avalon.each({
2081
1888
  scrollLeft: "pageXOffset",
2082
1889
  scrollTop: "pageYOffset"
2083
- }, function (method, prop) {
2084
- avalon.fn[method] = function (val) {
1890
+ }, function(method, prop) {
1891
+ avalon.fn[method] = function(val) {
2085
1892
  var node = this[0] || {}, win = getWindow(node),
2086
- top = method === "scrollTop"
1893
+ top = method === "scrollTop"
2087
1894
  if (!arguments.length) {
2088
1895
  return win ? win[prop] : node[method]
2089
1896
  } else {
@@ -2102,13 +1909,13 @@ function getWindow(node) {
2102
1909
 
2103
1910
  //=============================css相关==================================
2104
1911
  var cssHooks = avalon.cssHooks = createMap()
2105
- var prefixes = ["", "-webkit-", "-moz-", "-ms-"]//去掉opera-15的支持
1912
+ var prefixes = ["", "-webkit-", "-moz-", "-ms-"] //去掉opera-15的支持
2106
1913
  var cssMap = {
2107
1914
  "float": "cssFloat"
2108
1915
  }
2109
- avalon.cssNumber = oneObject("columnCount,order,fillOpacity,fontWeight,lineHeight,opacity,orphans,widows,zIndex,zoom")
1916
+ avalon.cssNumber = oneObject("animationIterationCount,columnCount,order,flex,flexGrow,flexShrink,fillOpacity,fontWeight,lineHeight,opacity,orphans,widows,zIndex,zoom")
2110
1917
 
2111
- avalon.cssName = function (name, host, camelCase) {
1918
+ avalon.cssName = function(name, host, camelCase) {
2112
1919
  if (cssMap[name]) {
2113
1920
  return cssMap[name]
2114
1921
  }
@@ -2121,33 +1928,33 @@ avalon.cssName = function (name, host, camelCase) {
2121
1928
  }
2122
1929
  return null
2123
1930
  }
2124
- cssHooks["@:set"] = function (node, name, value) {
1931
+ cssHooks["@:set"] = function(node, name, value) {
2125
1932
  node.style[name] = value
2126
1933
  }
2127
1934
 
2128
- cssHooks["@:get"] = function (node, name) {
1935
+ cssHooks["@:get"] = function(node, name) {
2129
1936
  if (!node || !node.style) {
2130
1937
  throw new Error("getComputedStyle要求传入一个节点 " + node)
2131
1938
  }
2132
1939
  var ret, computed = getComputedStyle(node)
2133
- if (computed) {
2134
- ret = name === "filter" ? computed.getPropertyValue(name) : computed[name]
2135
- if (ret === "") {
2136
- ret = node.style[name] //其他浏览器需要我们手动取内联样式
1940
+ if (computed) {
1941
+ ret = name === "filter" ? computed.getPropertyValue(name) : computed[name]
1942
+ if (ret === "") {
1943
+ ret = node.style[name] //其他浏览器需要我们手动取内联样式
1944
+ }
2137
1945
  }
2138
- }
2139
1946
  return ret
2140
1947
  }
2141
- cssHooks["opacity:get"] = function (node) {
1948
+ cssHooks["opacity:get"] = function(node) {
2142
1949
  var ret = cssHooks["@:get"](node, "opacity")
2143
1950
  return ret === "" ? "1" : ret
2144
1951
  }
2145
1952
 
2146
- "top,left".replace(rword, function (name) {
2147
- cssHooks[name + ":get"] = function (node) {
1953
+ "top,left".replace(rword, function(name) {
1954
+ cssHooks[name + ":get"] = function(node) {
2148
1955
  var computed = cssHooks["@:get"](node, name)
2149
1956
  return /px$/.test(computed) ? computed :
2150
- avalon(node).position()[name] + "px"
1957
+ avalon(node).position()[name] + "px"
2151
1958
  }
2152
1959
  })
2153
1960
  var cssShow = {
@@ -2157,125 +1964,125 @@ var cssShow = {
2157
1964
  }
2158
1965
  var rdisplayswap = /^(none|table(?!-c[ea]).+)/
2159
1966
 
2160
- function showHidden(node, array) {
2161
- //http://www.cnblogs.com/rubylouvre/archive/2012/10/27/2742529.html
2162
- if (node.offsetWidth <= 0) { //opera.offsetWidth可能小于0
2163
- var styles = getComputedStyle(node, null)
2164
- if (rdisplayswap.test(styles["display"])) {
2165
- var obj = {
2166
- node: node
1967
+ function showHidden(node, array) {
1968
+ //http://www.cnblogs.com/rubylouvre/archive/2012/10/27/2742529.html
1969
+ if (node.offsetWidth <= 0) { //opera.offsetWidth可能小于0
1970
+ var styles = getComputedStyle(node, null)
1971
+ if (rdisplayswap.test(styles["display"])) {
1972
+ var obj = {
1973
+ node: node
1974
+ }
1975
+ for (var name in cssShow) {
1976
+ obj[name] = styles[name]
1977
+ node.style[name] = cssShow[name]
1978
+ }
1979
+ array.push(obj)
2167
1980
  }
2168
- for (var name in cssShow) {
2169
- obj[name] = styles[name]
2170
- node.style[name] = cssShow[name]
1981
+ var parent = node.parentNode
1982
+ if (parent && parent.nodeType === 1) {
1983
+ showHidden(parent, array)
2171
1984
  }
2172
- array.push(obj)
2173
- }
2174
- var parent = node.parentNode
2175
- if (parent && parent.nodeType === 1) {
2176
- showHidden(parent, array)
2177
1985
  }
2178
1986
  }
2179
- }
2180
1987
 
2181
- "Width,Height".replace(rword, function (name) {//fix 481
2182
- var method = name.toLowerCase(),
1988
+ "Width,Height".replace(rword, function(name) { //fix 481
1989
+ var method = name.toLowerCase(),
2183
1990
  clientProp = "client" + name,
2184
1991
  scrollProp = "scroll" + name,
2185
1992
  offsetProp = "offset" + name
2186
- cssHooks[method + ":get"] = function (node, which, override) {
2187
- var boxSizing = -4
2188
- if (typeof override === "number") {
2189
- boxSizing = override
1993
+ cssHooks[method + ":get"] = function(node, which, override) {
1994
+ var boxSizing = -4
1995
+ if (typeof override === "number") {
1996
+ boxSizing = override
1997
+ }
1998
+ which = name === "Width" ? ["Left", "Right"] : ["Top", "Bottom"]
1999
+ var ret = node[offsetProp] // border-box 0
2000
+ if (boxSizing === 2) { // margin-box 2
2001
+ return ret + avalon.css(node, "margin" + which[0], true) + avalon.css(node, "margin" + which[1], true)
2002
+ }
2003
+ if (boxSizing < 0) { // padding-box -2
2004
+ ret = ret - avalon.css(node, "border" + which[0] + "Width", true) - avalon.css(node, "border" + which[1] + "Width", true)
2005
+ }
2006
+ if (boxSizing === -4) { // content-box -4
2007
+ ret = ret - avalon.css(node, "padding" + which[0], true) - avalon.css(node, "padding" + which[1], true)
2008
+ }
2009
+ return ret
2010
+ }
2011
+ cssHooks[method + "&get"] = function(node) {
2012
+ var hidden = [];
2013
+ showHidden(node, hidden);
2014
+ var val = cssHooks[method + ":get"](node)
2015
+ for (var i = 0, obj; obj = hidden[i++];) {
2016
+ node = obj.node
2017
+ for (var n in obj) {
2018
+ if (typeof obj[n] === "string") {
2019
+ node.style[n] = obj[n]
2020
+ }
2021
+ }
2022
+ }
2023
+ return val;
2190
2024
  }
2191
- which = name === "Width" ? ["Left", "Right"] : ["Top", "Bottom"]
2192
- var ret = node[offsetProp] // border-box 0
2193
- if (boxSizing === 2) { // margin-box 2
2194
- return ret + avalon.css(node, "margin" + which[0], true) + avalon.css(node, "margin" + which[1], true)
2025
+ avalon.fn[method] = function(value) { //会忽视其display
2026
+ var node = this[0]
2027
+ if (arguments.length === 0) {
2028
+ if (node.setTimeout) { //取得窗口尺寸,IE9后可以用node.innerWidth /innerHeight代替
2029
+ return node["inner" + name]
2030
+ }
2031
+ if (node.nodeType === 9) { //取得页面尺寸
2032
+ var doc = node.documentElement
2033
+ //FF chrome html.scrollHeight< body.scrollHeight
2034
+ //IE 标准模式 : html.scrollHeight> body.scrollHeight
2035
+ //IE 怪异模式 : html.scrollHeight 最大等于可视窗口多一点?
2036
+ return Math.max(node.body[scrollProp], doc[scrollProp], node.body[offsetProp], doc[offsetProp], doc[clientProp])
2037
+ }
2038
+ return cssHooks[method + "&get"](node)
2039
+ } else {
2040
+ return this.css(method, value)
2041
+ }
2195
2042
  }
2196
- if (boxSizing < 0) { // padding-box -2
2197
- ret = ret - avalon.css(node, "border" + which[0] + "Width", true) - avalon.css(node, "border" + which[1] + "Width", true)
2043
+ avalon.fn["inner" + name] = function() {
2044
+ return cssHooks[method + ":get"](this[0], void 0, -2)
2198
2045
  }
2199
- if (boxSizing === -4) { // content-box -4
2200
- ret = ret - avalon.css(node, "padding" + which[0], true) - avalon.css(node, "padding" + which[1], true)
2046
+ avalon.fn["outer" + name] = function(includeMargin) {
2047
+ return cssHooks[method + ":get"](this[0], void 0, includeMargin === true ? 2 : 0)
2201
2048
  }
2202
- return ret
2203
- }
2204
- cssHooks[method + "&get"] = function (node) {
2205
- var hidden = [];
2206
- showHidden(node, hidden);
2207
- var val = cssHooks[method + ":get"](node)
2208
- for (var i = 0, obj; obj = hidden[i++]; ) {
2209
- node = obj.node
2210
- for (var n in obj) {
2211
- if (typeof obj[n] === "string") {
2212
- node.style[n] = obj[n]
2049
+ })
2050
+ avalon.fn.offset = function() { //取得距离页面左右角的坐标
2051
+ var node = this[0]
2052
+ try {
2053
+ var rect = node.getBoundingClientRect()
2054
+ // Make sure element is not hidden (display: none) or disconnected
2055
+ // https://github.com/jquery/jquery/pull/2043/files#r23981494
2056
+ if (rect.width || rect.height || node.getClientRects().length) {
2057
+ var doc = node.ownerDocument
2058
+ var root = doc.documentElement
2059
+ var win = doc.defaultView
2060
+ return {
2061
+ top: rect.top + win.pageYOffset - root.clientTop,
2062
+ left: rect.left + win.pageXOffset - root.clientLeft
2213
2063
  }
2214
2064
  }
2215
- }
2216
- return val;
2217
- }
2218
- avalon.fn[method] = function (value) { //会忽视其display
2219
- var node = this[0]
2220
- if (arguments.length === 0) {
2221
- if (node.setTimeout) { //取得窗口尺寸,IE9后可以用node.innerWidth /innerHeight代替
2222
- return node["inner" + name]
2223
- }
2224
- if (node.nodeType === 9) { //取得页面尺寸
2225
- var doc = node.documentElement
2226
- //FF chrome html.scrollHeight< body.scrollHeight
2227
- //IE 标准模式 : html.scrollHeight> body.scrollHeight
2228
- //IE 怪异模式 : html.scrollHeight 最大等于可视窗口多一点?
2229
- return Math.max(node.body[scrollProp], doc[scrollProp], node.body[offsetProp], doc[offsetProp], doc[clientProp])
2230
- }
2231
- return cssHooks[method + "&get"](node)
2232
- } else {
2233
- return this.css(method, value)
2234
- }
2235
- }
2236
- avalon.fn["inner" + name] = function () {
2237
- return cssHooks[method + ":get"](this[0], void 0, -2)
2238
- }
2239
- avalon.fn["outer" + name] = function (includeMargin) {
2240
- return cssHooks[method + ":get"](this[0], void 0, includeMargin === true ? 2 : 0)
2241
- }
2242
- })
2243
- avalon.fn.offset = function () { //取得距离页面左右角的坐标
2244
- var node = this[0]
2245
- try {
2246
- var rect = node.getBoundingClientRect()
2247
- // Make sure element is not hidden (display: none) or disconnected
2248
- // https://github.com/jquery/jquery/pull/2043/files#r23981494
2249
- if (rect.width || rect.height || node.getClientRects().length) {
2250
- var doc = node.ownerDocument
2251
- var root = doc.documentElement
2252
- var win = doc.defaultView
2065
+ } catch (e) {
2253
2066
  return {
2254
- top: rect.top + win.pageYOffset - root.clientTop,
2255
- left: rect.left + win.pageXOffset - root.clientLeft
2067
+ left: 0,
2068
+ top: 0
2256
2069
  }
2257
2070
  }
2258
- } catch (e) {
2259
- return {
2260
- left: 0,
2261
- top: 0
2262
- }
2263
2071
  }
2264
- }
2265
- //=============================val相关=======================
2072
+ //=============================val相关=======================
2266
2073
 
2267
- function getValType(el) {
2268
- var ret = el.tagName.toLowerCase()
2269
- return ret === "input" && /checkbox|radio/.test(el.type) ? "checked" : ret
2270
- }
2074
+ function getValType(elem) {
2075
+ var ret = elem.tagName.toLowerCase()
2076
+ return ret === "input" && /checkbox|radio/.test(elem.type) ? "checked" : ret
2077
+ }
2271
2078
  var valHooks = {
2272
- "select:get": function (node, value) {
2079
+ "select:get": function(node, value) {
2273
2080
  var option, options = node.options,
2274
- index = node.selectedIndex,
2275
- one = node.type === "select-one" || index < 0,
2276
- values = one ? null : [],
2277
- max = one ? index + 1 : options.length,
2278
- i = index < 0 ? max : one ? index : 0
2081
+ index = node.selectedIndex,
2082
+ one = node.type === "select-one" || index < 0,
2083
+ values = one ? null : [],
2084
+ max = one ? index + 1 : options.length,
2085
+ i = index < 0 ? max : one ? index : 0
2279
2086
  for (; i < max; i++) {
2280
2087
  option = options[i]
2281
2088
  //旧式IE在reset后不会改变selected,需要改用i === index判定
@@ -2292,9 +2099,9 @@ var valHooks = {
2292
2099
  }
2293
2100
  return values
2294
2101
  },
2295
- "select:set": function (node, values, optionSet) {
2102
+ "select:set": function(node, values, optionSet) {
2296
2103
  values = [].concat(values) //强制转换为数组
2297
- for (var i = 0, el; el = node.options[i++]; ) {
2104
+ for (var i = 0, el; el = node.options[i++];) {
2298
2105
  if ((el.selected = values.indexOf(el.value) > -1)) {
2299
2106
  optionSet = true
2300
2107
  }
@@ -2304,7 +2111,6 @@ var valHooks = {
2304
2111
  }
2305
2112
  }
2306
2113
  }
2307
-
2308
2114
  /*********************************************************************
2309
2115
  * 编译系统 *
2310
2116
  **********************************************************************/
@@ -2324,10 +2130,10 @@ var rsplit = /[^\w$]+/g
2324
2130
  var rkeywords = new RegExp(["\\b" + keywords.replace(/,/g, '\\b|\\b') + "\\b"].join('|'), 'g')
2325
2131
  var rnumber = /\b\d[^,]*/g
2326
2132
  var rcomma = /^,+|,+$/g
2327
- var cacheVars = new Cache(512)
2133
+ var variablePool = new Cache(512)
2328
2134
  var getVariables = function (code) {
2329
2135
  var key = "," + code.trim()
2330
- var ret = cacheVars.get(key)
2136
+ var ret = variablePool.get(key)
2331
2137
  if (ret) {
2332
2138
  return ret
2333
2139
  }
@@ -2338,7 +2144,7 @@ var getVariables = function (code) {
2338
2144
  .replace(rnumber, "")
2339
2145
  .replace(rcomma, "")
2340
2146
  .split(/^$|,+/)
2341
- return cacheVars.put(key, uniqSet(match))
2147
+ return variablePool.put(key, uniqSet(match))
2342
2148
  }
2343
2149
  /*添加赋值语句*/
2344
2150
 
@@ -2371,7 +2177,7 @@ function uniqSet(array) {
2371
2177
  return ret
2372
2178
  }
2373
2179
  //缓存求值函数,以便多次利用
2374
- var cacheExprs = new Cache(128)
2180
+ var evaluatorPool = new Cache(128)
2375
2181
  //取得求值函数及其传参
2376
2182
  var rduplex = /\w\[.*\]|\w\.\w/
2377
2183
  var rproxy = /(\$proxy\$[a-z]+)\d+$/
@@ -2395,142 +2201,496 @@ function parseFilter(val, filters) {
2395
2201
  .replace(rthimLeftParentheses, function () {
2396
2202
  return '",'
2397
2203
  }) + "]"
2398
- return "return avalon.filters.$filter(" + val + ", " + filters + ")"
2204
+ return "return this.filters.$filter(" + val + ", " + filters + ")"
2205
+ }
2206
+
2207
+ function parseExpr(code, scopes, data) {
2208
+ var dataType = data.type
2209
+ var filters = data.filters || ""
2210
+ var exprId = scopes.map(function (el) {
2211
+ return String(el.$id).replace(rproxy, "$1")
2212
+ }) + code + dataType + filters
2213
+ var vars = getVariables(code).concat(),
2214
+ assigns = [],
2215
+ names = [],
2216
+ args = [],
2217
+ prefix = ""
2218
+ //args 是一个对象数组, names 是将要生成的求值函数的参数
2219
+ scopes = uniqSet(scopes)
2220
+ data.vars = []
2221
+ for (var i = 0, sn = scopes.length; i < sn; i++) {
2222
+ if (vars.length) {
2223
+ var name = "vm" + expose + "_" + i
2224
+ names.push(name)
2225
+ args.push(scopes[i])
2226
+ assigns.push.apply(assigns, addAssign(vars, scopes[i], name, data))
2227
+ }
2228
+ }
2229
+ if (!assigns.length && dataType === "duplex") {
2230
+ return
2231
+ }
2232
+ if (dataType !== "duplex" && (code.indexOf("||") > -1 || code.indexOf("&&") > -1)) {
2233
+ //https://github.com/RubyLouvre/avalon/issues/583
2234
+ data.vars.forEach(function (v) {
2235
+ var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig")
2236
+ code = code.replace(reg, function (_, cap) {
2237
+ var c = _.charAt(v.length)
2238
+ //var r = IEVersion ? code.slice(arguments[1] + _.length) : RegExp.rightContext
2239
+ //https://github.com/RubyLouvre/avalon/issues/966
2240
+ var r = code.slice(cap + _.length)
2241
+ var method = /^\s*\(/.test(r)
2242
+ if (c === "." || c === "[" || method) {//比如v为aa,我们只匹配aa.bb,aa[cc],不匹配aaa.xxx
2243
+ var name = "var" + String(Math.random()).replace(/^0\./, "")
2244
+ if (method) {//array.size()
2245
+ var array = _.split(".")
2246
+ if (array.length > 2) {
2247
+ var last = array.pop()
2248
+ assigns.push(name + " = " + array.join("."))
2249
+ return name + "." + last
2250
+ } else {
2251
+ return _
2252
+ }
2253
+ }
2254
+ assigns.push(name + " = " + _)
2255
+ return name
2256
+ } else {
2257
+ return _
2258
+ }
2259
+ })
2260
+ })
2261
+ }
2262
+ //---------------args----------------
2263
+ data.args = args
2264
+ //---------------cache----------------
2265
+ delete data.vars
2266
+ var fn = evaluatorPool.get(exprId) //直接从缓存,免得重复生成
2267
+ if (fn) {
2268
+ data.evaluator = fn
2269
+ return
2270
+ }
2271
+ prefix = assigns.join(", ")
2272
+ if (prefix) {
2273
+ prefix = "var " + prefix
2274
+ }
2275
+ if (/\S/.test(filters)) { //文本绑定,双工绑定才有过滤器
2276
+ if (!/text|html/.test(data.type)) {
2277
+ throw Error("ms-" + data.type + "不支持过滤器")
2278
+ }
2279
+ code = "\nvar ret" + expose + " = " + code + ";\r\n"
2280
+ code += parseFilter("ret" + expose, filters)
2281
+ try {
2282
+ fn = Function.apply(noop, names.concat("'use strict';\n" + prefix + code))
2283
+ data.evaluator = evaluatorPool.put(exprId, function() {
2284
+ return fn.apply(avalon, arguments)//确保可以在编译代码中使用this获取avalon对象
2285
+ })
2286
+ } catch (e) {
2287
+ log("debug: parse error," + e.message)
2288
+ }
2289
+ vars = assigns = names = null //释放内存
2290
+ return
2291
+ } else if (dataType === "duplex") { //双工绑定
2292
+ var _body = "'use strict';\nreturn function(vvv){\n\t" +
2293
+ prefix +
2294
+ ";\n\tif(!arguments.length){\n\t\treturn " +
2295
+ code +
2296
+ "\n\t}\n\t" + (!rduplex.test(code) ? vars.get : code) +
2297
+ "= vvv;\n} "
2298
+ try {
2299
+ fn = Function.apply(noop, names.concat(_body))
2300
+ data.evaluator = evaluatorPool.put(exprId, fn)
2301
+ } catch (e) {
2302
+ log("debug: parse error," + e.message)
2303
+ }
2304
+ vars = assigns = names = null //释放内存
2305
+ return
2306
+ } else if (dataType === "on") { //事件绑定
2307
+ if (code.indexOf("(") === -1) {
2308
+ code += ".call(this, $event)"
2309
+ } else {
2310
+ code = code.replace("(", ".call(this,")
2311
+ }
2312
+ names.push("$event")
2313
+ code = "\nreturn " + code + ";" //IE全家 Function("return ")出错,需要Function("return ;")
2314
+ var lastIndex = code.lastIndexOf("\nreturn")
2315
+ var header = code.slice(0, lastIndex)
2316
+ var footer = code.slice(lastIndex)
2317
+ code = header + "\n" + footer
2318
+ } else { //其他绑定
2319
+ code = "\nreturn " + code + ";" //IE全家 Function("return ")出错,需要Function("return ;")
2320
+ }
2321
+ try {
2322
+ fn = Function.apply(noop, names.concat("'use strict';\n" + prefix + code))
2323
+ data.evaluator = evaluatorPool.put(exprId, fn)
2324
+ } catch (e) {
2325
+ log("debug: parse error," + e.message)
2326
+ }
2327
+ vars = assigns = names = null //释放内存
2328
+ }
2329
+ function stringifyExpr(code) {
2330
+ var hasExpr = rexpr.test(code) //比如ms-class="width{{w}}"的情况
2331
+ if (hasExpr) {
2332
+ var array = scanExpr(code)
2333
+ if (array.length === 1) {
2334
+ return array[0].value
2335
+ }
2336
+ return array.map(function (el) {
2337
+ return el.expr ? "(" + el.value + ")" : quote(el.value)
2338
+ }).join(" + ")
2339
+ } else {
2340
+ return code
2341
+ }
2342
+ }
2343
+ //parseExpr的智能引用代理
2344
+
2345
+ function parseExprProxy(code, scopes, data, noRegister) {
2346
+ code = code || "" //code 可能未定义
2347
+ parseExpr(code, scopes, data)
2348
+ if (data.evaluator && !noRegister) {
2349
+ data.handler = bindingExecutors[data.handlerName || data.type]
2350
+ //方便调试
2351
+ //这里非常重要,我们通过判定视图刷新函数的element是否在DOM树决定
2352
+ //将它移出订阅者列表
2353
+ avalon.injectBinding(data)
2354
+ }
2355
+ }
2356
+ avalon.parseExprProxy = parseExprProxy
2357
+ /*********************************************************************
2358
+ * 扫描系统 *
2359
+ **********************************************************************/
2360
+
2361
+ avalon.scan = function(elem, vmodel) {
2362
+ elem = elem || root
2363
+ var vmodels = vmodel ? [].concat(vmodel) : []
2364
+ scanTag(elem, vmodels)
2365
+ }
2366
+
2367
+ //http://www.w3.org/TR/html5/syntax.html#void-elements
2368
+ var stopScan = oneObject("area,base,basefont,br,col,command,embed,hr,img,input,link,meta,param,source,track,wbr,noscript,script,style,textarea".toUpperCase())
2369
+
2370
+ function checkScan(elem, callback, innerHTML) {
2371
+ var id = setTimeout(function() {
2372
+ var currHTML = elem.innerHTML
2373
+ clearTimeout(id)
2374
+ if (currHTML === innerHTML) {
2375
+ callback()
2376
+ } else {
2377
+ checkScan(elem, callback, currHTML)
2378
+ }
2379
+ })
2380
+ }
2381
+
2382
+
2383
+ function createSignalTower(elem, vmodel) {
2384
+ var id = elem.getAttribute("avalonctrl") || vmodel.$id
2385
+ elem.setAttribute("avalonctrl", id)
2386
+ vmodel.$events.expr = elem.tagName + '[avalonctrl="' + id + '"]'
2387
+ }
2388
+
2389
+ var getBindingCallback = function(elem, name, vmodels) {
2390
+ var callback = elem.getAttribute(name)
2391
+ if (callback) {
2392
+ for (var i = 0, vm; vm = vmodels[i++]; ) {
2393
+ if (vm.hasOwnProperty(callback) && typeof vm[callback] === "function") {
2394
+ return vm[callback]
2395
+ }
2396
+ }
2397
+ }
2398
+ }
2399
+
2400
+ function executeBindings(bindings, vmodels) {
2401
+ for (var i = 0, data; data = bindings[i++]; ) {
2402
+ data.vmodels = vmodels
2403
+ bindingHandlers[data.type](data, vmodels)
2404
+ if (data.evaluator && data.element && data.element.nodeType === 1) { //移除数据绑定,防止被二次解析
2405
+ //chrome使用removeAttributeNode移除不存在的特性节点时会报错 https://github.com/RubyLouvre/avalon/issues/99
2406
+ data.element.removeAttribute(data.name)
2407
+ }
2408
+ }
2409
+ bindings.length = 0
2410
+ }
2411
+
2412
+ //https://github.com/RubyLouvre/avalon/issues/636
2413
+ var mergeTextNodes = IEVersion && window.MutationObserver ? function (elem) {
2414
+ var node = elem.firstChild, text
2415
+ while (node) {
2416
+ var aaa = node.nextSibling
2417
+ if (node.nodeType === 3) {
2418
+ if (text) {
2419
+ text.nodeValue += node.nodeValue
2420
+ elem.removeChild(node)
2421
+ } else {
2422
+ text = node
2423
+ }
2424
+ } else {
2425
+ text = null
2426
+ }
2427
+ node = aaa
2428
+ }
2429
+ } : 0
2430
+ var roneTime = /^\s*::/
2431
+ var rmsAttr = /ms-(\w+)-?(.*)/
2432
+ var priorityMap = {
2433
+ "if": 10,
2434
+ "repeat": 90,
2435
+ "data": 100,
2436
+ "widget": 110,
2437
+ "each": 1400,
2438
+ "with": 1500,
2439
+ "duplex": 2000,
2440
+ "on": 3000
2441
+ }
2442
+
2443
+ var events = oneObject("animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scan,scroll,submit")
2444
+ var obsoleteAttrs = oneObject("value,title,alt,checked,selected,disabled,readonly,enabled")
2445
+ function bindingSorter(a, b) {
2446
+ return a.priority - b.priority
2447
+ }
2448
+
2449
+ function scanAttr(elem, vmodels, match) {
2450
+ var scanNode = true
2451
+ if (vmodels.length) {
2452
+ var attributes = elem.attributes
2453
+ var bindings = []
2454
+ var fixAttrs = []
2455
+ var uniq = {}
2456
+ var msData = createMap()
2457
+ for (var i = 0, attr; attr = attributes[i++]; ) {
2458
+ if (attr.specified) {
2459
+ if (match = attr.name.match(rmsAttr)) {
2460
+ //如果是以指定前缀命名的
2461
+ var type = match[1]
2462
+ var param = match[2] || ""
2463
+ var value = attr.value
2464
+ var name = attr.name
2465
+ if (uniq[name]) {//IE8下ms-repeat,ms-with BUG
2466
+ continue
2467
+ }
2468
+ uniq[name] = 1
2469
+ if (events[type]) {
2470
+ param = type
2471
+ type = "on"
2472
+ } else if (obsoleteAttrs[type]) {
2473
+ if (type === "enabled") {//吃掉ms-enabled绑定,用ms-disabled代替
2474
+ log("warning!ms-enabled或ms-attr-enabled已经被废弃")
2475
+ type = "disabled"
2476
+ value = "!(" + value + ")"
2477
+ }
2478
+ param = type
2479
+ type = "attr"
2480
+ name = "ms-" + type + "-" + param
2481
+ fixAttrs.push([attr.name, name, value])
2482
+ }
2483
+ msData[name] = value
2484
+ if (typeof bindingHandlers[type] === "function") {
2485
+ var newValue = value.replace(roneTime, "")
2486
+ var oneTime = value !== newValue
2487
+ var binding = {
2488
+ type: type,
2489
+ param: param,
2490
+ element: elem,
2491
+ name: name,
2492
+ value: newValue,
2493
+ oneTime: oneTime,
2494
+ priority: (priorityMap[type] || type.charCodeAt(0) * 10) + (Number(param.replace(/\D/g, "")) || 0)
2495
+ }
2496
+ if (type === "html" || type === "text") {
2497
+ var token = getToken(value)
2498
+ avalon.mix(binding, token)
2499
+ binding.filters = binding.filters.replace(rhasHtml, function () {
2500
+ binding.type = "html"
2501
+ binding.group = 1
2502
+ return ""
2503
+ })// jshint ignore:line
2504
+ } else if (type === "duplex") {
2505
+ var hasDuplex = name
2506
+ } else if (name === "ms-if-loop") {
2507
+ binding.priority += 100
2508
+ }
2509
+ bindings.push(binding)
2510
+ if (type === "widget") {
2511
+ elem.msData = elem.msData || msData
2512
+ }
2513
+ }
2514
+ }
2515
+ }
2516
+ }
2517
+ if (bindings.length) {
2518
+ bindings.sort(bindingSorter)
2519
+ fixAttrs.forEach(function (arr) {
2520
+ log("warning!请改用" + arr[1] + "代替" + arr[0] + "!")
2521
+ elem.removeAttribute(arr[0])
2522
+ elem.setAttribute(arr[1], arr[2])
2523
+ })
2524
+ var control = elem.type
2525
+ if (control && hasDuplex) {
2526
+ if (msData["ms-attr-value"] && elem.type === "text") {
2527
+ log("warning!" + control + "控件不能同时定义ms-attr-value与" + hasDuplex)
2528
+ }
2529
+ }
2530
+
2531
+ for (i = 0; binding = bindings[i]; i++) {
2532
+ type = binding.type
2533
+ if (rnoscanAttrBinding.test(type)) {
2534
+ return executeBindings(bindings.slice(0, i + 1), vmodels)
2535
+ } else if (scanNode) {
2536
+ scanNode = !rnoscanNodeBinding.test(type)
2537
+ }
2538
+ }
2539
+ executeBindings(bindings, vmodels)
2540
+ }
2541
+ }
2542
+ if (scanNode && !stopScan[elem.tagName] && rbind.test(elem.innerHTML + elem.textContent)) {
2543
+ mergeTextNodes && mergeTextNodes(elem)
2544
+ scanNodeList(elem, vmodels) //扫描子孙元素
2545
+ }
2399
2546
  }
2400
2547
 
2401
- function parseExpr(code, scopes, data) {
2402
- var dataType = data.type
2403
- var filters = data.filters || ""
2404
- var exprId = scopes.map(function (el) {
2405
- return String(el.$id).replace(rproxy, "$1")
2406
- }) + code + dataType + filters
2407
- var vars = getVariables(code).concat(),
2408
- assigns = [],
2409
- names = [],
2410
- args = [],
2411
- prefix = ""
2412
- //args 是一个对象数组, names 是将要生成的求值函数的参数
2413
- scopes = uniqSet(scopes)
2414
- data.vars = []
2415
- for (var i = 0, sn = scopes.length; i < sn; i++) {
2416
- if (vars.length) {
2417
- var name = "vm" + expose + "_" + i
2418
- names.push(name)
2419
- args.push(scopes[i])
2420
- assigns.push.apply(assigns, addAssign(vars, scopes[i], name, data))
2548
+ var rnoscanAttrBinding = /^if|widget|repeat$/
2549
+ var rnoscanNodeBinding = /^each|with|html|include$/
2550
+ function scanNodeList(parent, vmodels) {
2551
+ var nodes = avalon.slice(parent.childNodes)
2552
+ scanNodeArray(nodes, vmodels)
2553
+ }
2554
+
2555
+ function scanNodeArray(nodes, vmodels) {
2556
+ for (var i = 0, node; node = nodes[i++];) {
2557
+ switch (node.nodeType) {
2558
+ case 1:
2559
+ scanTag(node, vmodels) //扫描元素节点
2560
+ if (node.msCallback) {
2561
+ node.msCallback()
2562
+ node.msCallback = void 0
2563
+ }
2564
+ break
2565
+ case 3:
2566
+ if(rexpr.test(node.nodeValue)){
2567
+ scanText(node, vmodels, i) //扫描文本节点
2568
+ }
2569
+ break
2421
2570
  }
2422
2571
  }
2423
- if (!assigns.length && dataType === "duplex") {
2572
+ }
2573
+
2574
+
2575
+ function scanTag(elem, vmodels, node) {
2576
+ //扫描顺序 ms-skip(0) --> ms-important(1) --> ms-controller(2) --> ms-if(10) --> ms-repeat(100)
2577
+ //--> ms-if-loop(110) --> ms-attr(970) ...--> ms-each(1400)-->ms-with(1500)--〉ms-duplex(2000)垫后
2578
+ var a = elem.getAttribute("ms-skip")
2579
+ var b = elem.getAttributeNode("ms-important")
2580
+ var c = elem.getAttributeNode("ms-controller")
2581
+ if (typeof a === "string") {
2424
2582
  return
2583
+ } else if (node = b || c) {
2584
+ var newVmodel = avalon.vmodels[node.value]
2585
+ if (!newVmodel) {
2586
+ return
2587
+ }
2588
+ //ms-important不包含父VM,ms-controller相反
2589
+ vmodels = node === b ? [newVmodel] : [newVmodel].concat(vmodels)
2590
+ elem.removeAttribute(node.name) //removeAttributeNode不会刷新[ms-controller]样式规则
2591
+ elem.classList.remove(node.name)
2592
+ createSignalTower(elem, newVmodel)
2425
2593
  }
2426
- if (dataType !== "duplex" && (code.indexOf("||") > -1 || code.indexOf("&&") > -1)) {
2427
- //https://github.com/RubyLouvre/avalon/issues/583
2428
- data.vars.forEach(function (v) {
2429
- var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig")
2430
- code = code.replace(reg, function (_) {
2431
- var c = _.charAt(v.length)
2432
- var r = IEVersion ? code.slice(arguments[1] + _.length) : RegExp.rightContext
2433
- var method = /^\s*\(/.test(r)
2434
- if (c === "." || c === "[" || method) {//比如v为aa,我们只匹配aa.bb,aa[cc],不匹配aaa.xxx
2435
- var name = "var" + String(Math.random()).replace(/^0\./, "")
2436
- if (method) {//array.size()
2437
- var array = _.split(".")
2438
- if (array.length > 2) {
2439
- var last = array.pop()
2440
- assigns.push(name + " = " + array.join("."))
2441
- return name + "." + last
2442
- } else {
2443
- return _
2444
- }
2445
- }
2446
- assigns.push(name + " = " + _)
2447
- return name
2448
- } else {
2449
- return _
2450
- }
2451
- })
2594
+ scanAttr(elem, vmodels) //扫描特性节点
2595
+ }
2596
+ var rhasHtml = /\|\s*html(?:\b|$)/,
2597
+ r11a = /\|\|/g,
2598
+ rlt = /&lt;/g,
2599
+ rgt = /&gt;/g,
2600
+ rstringLiteral = /(['"])(\\\1|.)+?\1/g
2601
+ function getToken(value) {
2602
+ if (value.indexOf("|") > 0) {
2603
+ var scapegoat = value.replace(rstringLiteral, function (_) {
2604
+ return Array(_.length + 1).join("1")// jshint ignore:line
2452
2605
  })
2606
+ var index = scapegoat.replace(r11a, "\u1122\u3344").indexOf("|") //干掉所有短路或
2607
+ if (index > -1) {
2608
+ return {
2609
+ filters: value.slice(index),
2610
+ value: value.slice(0, index),
2611
+ expr: true
2612
+ }
2613
+ }
2453
2614
  }
2454
- //---------------args----------------
2455
- data.args = args
2456
- //---------------cache----------------
2457
- var fn = cacheExprs.get(exprId) //直接从缓存,免得重复生成
2458
- if (fn) {
2459
- data.evaluator = fn
2460
- return
2461
- }
2462
- prefix = assigns.join(", ")
2463
- if (prefix) {
2464
- prefix = "var " + prefix
2615
+ return {
2616
+ value: value,
2617
+ filters: "",
2618
+ expr: true
2465
2619
  }
2466
- if (/\S/.test(filters)) { //文本绑定,双工绑定才有过滤器
2467
- if (!/text|html/.test(data.type)) {
2468
- throw Error("ms-" + data.type + "不支持过滤器")
2620
+ }
2621
+
2622
+ function scanExpr(str) {
2623
+ var tokens = [],
2624
+ value, start = 0,
2625
+ stop
2626
+ do {
2627
+ stop = str.indexOf(openTag, start)
2628
+ if (stop === -1) {
2629
+ break
2469
2630
  }
2470
- code = "\nvar ret" + expose + " = " + code + ";\r\n"
2471
- code += parseFilter("ret" + expose, filters)
2472
- } else if (dataType === "duplex") { //双工绑定
2473
- var _body = "'use strict';\nreturn function(vvv){\n\t" +
2474
- prefix +
2475
- ";\n\tif(!arguments.length){\n\t\treturn " +
2476
- code +
2477
- "\n\t}\n\t" + (!rduplex.test(code) ? vars.get : code) +
2478
- "= vvv;\n} "
2479
- try {
2480
- fn = Function.apply(noop, names.concat(_body))
2481
- data.evaluator = cacheExprs.put(exprId, fn)
2482
- } catch (e) {
2483
- log("debug: parse error," + e.message)
2631
+ value = str.slice(start, stop)
2632
+ if (value) { // {{ 左边的文本
2633
+ tokens.push({
2634
+ value: value,
2635
+ filters: "",
2636
+ expr: false
2637
+ })
2484
2638
  }
2485
- return
2486
- } else if (dataType === "on") { //事件绑定
2487
- if (code.indexOf("(") === -1) {
2488
- code += ".call(this, $event)"
2489
- } else {
2490
- code = code.replace("(", ".call(this,")
2639
+ start = stop + openTag.length
2640
+ stop = str.indexOf(closeTag, start)
2641
+ if (stop === -1) {
2642
+ break
2491
2643
  }
2492
- names.push("$event")
2493
- code = "\nreturn " + code + ";" //IE全家 Function("return ")出错,需要Function("return ;")
2494
- var lastIndex = code.lastIndexOf("\nreturn")
2495
- var header = code.slice(0, lastIndex)
2496
- var footer = code.slice(lastIndex)
2497
- code = header + "\n" + footer
2498
- } else { //其他绑定
2499
- code = "\nreturn " + code + ";" //IE全家 Function("return ")出错,需要Function("return ;")
2500
- }
2501
- try {
2502
- fn = Function.apply(noop, names.concat("'use strict';\n" + prefix + code))
2503
- data.evaluator = cacheExprs.put(exprId, fn)
2504
- } catch (e) {
2505
- log("debug: parse error," + e.message)
2506
- } finally {
2507
- vars = assigns = names = null //释放内存
2644
+ value = str.slice(start, stop)
2645
+ if (value) { //处理{{ }}插值表达式
2646
+ tokens.push(getToken(value, start))
2647
+ }
2648
+ start = stop + closeTag.length
2649
+ } while (1)
2650
+ value = str.slice(start)
2651
+ if (value) { //}} 右边的文本
2652
+ tokens.push({
2653
+ value: value,
2654
+ expr: false,
2655
+ filters: ""
2656
+ })
2508
2657
  }
2658
+ return tokens
2509
2659
  }
2510
2660
 
2511
-
2512
- //parseExpr的智能引用代理
2513
-
2514
- function parseExprProxy(code, scopes, data, tokens, noregister) {
2515
- if (Array.isArray(tokens)) {
2516
- code = tokens.map(function (el) {
2517
- return el.expr ? "(" + el.value + ")" : quote(el.value)
2518
- }).join(" + ")
2519
- }
2520
- parseExpr(code, scopes, data)
2521
- if (data.evaluator && !noregister) {
2522
- data.handler = bindingExecutors[data.handlerName || data.type]
2523
- //方便调试
2524
- //这里非常重要,我们通过判定视图刷新函数的element是否在DOM树决定
2525
- //将它移出订阅者列表
2526
- registerSubscriber(data)
2661
+ function scanText(textNode, vmodels, index) {
2662
+ var bindings = []
2663
+ tokens = scanExpr(textNode.data)
2664
+ if (tokens.length) {
2665
+ for (var i = 0; token = tokens[i++]; ) {
2666
+ var node = DOC.createTextNode(token.value) //将文本转换为文本节点,并替换原来的文本节点
2667
+ if (token.expr) {
2668
+ token.value = token.value.replace(roneTime, function () {
2669
+ token.oneTime = true
2670
+ return ""
2671
+ })// jshint ignore:line
2672
+ token.type = "text"
2673
+ token.element = node
2674
+ token.filters = token.filters.replace(rhasHtml, function (a, b,c) {
2675
+ token.type = "html"
2676
+ return ""
2677
+ })// jshint ignore:line
2678
+ token.pos = index * 1000 + i
2679
+ bindings.push(token) //收集带有插值表达式的文本
2680
+ }
2681
+ avalonFragment.appendChild(node)
2682
+ }
2683
+ textNode.parentNode.replaceChild(avalonFragment, textNode)
2684
+ if (bindings.length)
2685
+ executeBindings(bindings, vmodels)
2527
2686
  }
2528
2687
  }
2529
- avalon.parseExprProxy = parseExprProxy
2688
+
2530
2689
  var bools = ["autofocus,autoplay,async,allowTransparency,checked,controls",
2531
2690
  "declare,disabled,defer,defaultChecked,defaultSelected",
2532
2691
  "contentEditable,isMap,loop,multiple,noHref,noResize,noShade",
2533
- "open,readOnly,selected"].join(",")
2692
+ "open,readOnly,selected"
2693
+ ].join(",")
2534
2694
  var boolMap = {}
2535
2695
  bools.replace(rword, function (name) {
2536
2696
  boolMap[name.toLowerCase()] = name
@@ -2547,7 +2707,8 @@ var propMap = {//属性名映射
2547
2707
 
2548
2708
  var anomaly = ["accessKey,bgColor,cellPadding,cellSpacing,codeBase,codeType,colSpan",
2549
2709
  "dateTime,defaultValue,frameBorder,longDesc,maxLength,marginWidth,marginHeight",
2550
- "rowSpan,tabIndex,useMap,vSpace,valueType,vAlign"].join(",")
2710
+ "rowSpan,tabIndex,useMap,vSpace,valueType,vAlign"
2711
+ ].join(",")
2551
2712
  anomaly.replace(rword, function (name) {
2552
2713
  propMap[name.toLowerCase()] = name
2553
2714
  })
@@ -2556,21 +2717,13 @@ var rnoscripts = /<noscript.*?>(?:[\s\S]+?)<\/noscript>/img
2556
2717
  var rnoscriptText = /<noscript.*?>([\s\S]+?)<\/noscript>/im
2557
2718
 
2558
2719
  var getXHR = function () {
2559
- return new (window.XMLHttpRequest || ActiveXObject)("Microsoft.XMLHTTP")// jshint ignore:line
2720
+ return new (window.XMLHttpRequest || ActiveXObject)("Microsoft.XMLHTTP") // jshint ignore:line
2560
2721
  }
2561
2722
 
2562
- var cacheTmpls = avalon.templateCache = {}
2723
+ var templatePool = avalon.templateCache = {}
2563
2724
 
2564
2725
  bindingHandlers.attr = function (data, vmodels) {
2565
- var text = data.value.trim(),
2566
- simple = true
2567
- if (text.indexOf(openTag) > -1 && text.indexOf(closeTag) > 2) {
2568
- simple = false
2569
- if (rexpr.test(text) && RegExp.rightContext === "" && RegExp.leftContext === "") {
2570
- simple = true
2571
- text = RegExp.$1
2572
- }
2573
- }
2726
+ var value = stringifyExpr(data.value.trim())
2574
2727
  if (data.type === "include") {
2575
2728
  var elem = data.element
2576
2729
  data.includeRendered = getBindingCallback(elem, "data-include-rendered", vmodels)
@@ -2591,7 +2744,7 @@ bindingHandlers.attr = function (data, vmodels) {
2591
2744
  }
2592
2745
  }
2593
2746
  data.handlerName = "attr" //handleName用于处理多种绑定共用同一种bindingExecutor的情况
2594
- parseExprProxy(text, vmodels, data, (simple ? 0 : scanExpr(data.value)))
2747
+ parseExprProxy(value, vmodels, data)
2595
2748
  }
2596
2749
 
2597
2750
  bindingExecutors.attr = function (val, elem, data) {
@@ -2600,28 +2753,29 @@ bindingExecutors.attr = function (val, elem, data) {
2600
2753
  if (method === "css") {
2601
2754
  avalon(elem).css(attrName, val)
2602
2755
  } else if (method === "attr") {
2756
+
2603
2757
  // ms-attr-class="xxx" vm.xxx="aaa bbb ccc"将元素的className设置为aaa bbb ccc
2604
2758
  // ms-attr-class="xxx" vm.xxx=false 清空元素的所有类名
2605
2759
  // ms-attr-name="yyy" vm.yyy="ooo" 为元素设置name属性
2606
- if (boolMap[attrName]) {
2607
- var bool = boolMap[attrName]
2608
- if (typeof elem[bool] === "boolean") {
2609
- // IE6-11不支持动态设置fieldset的disabled属性,IE11下样式是生效了,但无法阻止用户对其底下的input元素进行设值……
2610
- return elem[bool] = !!val
2611
- }
2612
- }
2613
2760
  var toRemove = (val === false) || (val === null) || (val === void 0)
2614
2761
 
2615
2762
  if (!W3C && propMap[attrName]) { //旧式IE下需要进行名字映射
2616
2763
  attrName = propMap[attrName]
2617
2764
  }
2765
+ var bool = boolMap[attrName]
2766
+ if (typeof elem[bool] === "boolean") {
2767
+ elem[bool] = !!val //布尔属性必须使用el.xxx = true|false方式设值
2768
+ if (!val) { //如果为false, IE全系列下相当于setAttribute(xxx,''),会影响到样式,需要进一步处理
2769
+ toRemove = true
2770
+ }
2771
+ }
2618
2772
  if (toRemove) {
2619
2773
  return elem.removeAttribute(attrName)
2620
2774
  }
2621
2775
  //SVG只能使用setAttribute(xxx, yyy), VML只能使用elem.xxx = yyy ,HTML的固有属性必须elem.xxx = yyy
2622
2776
  var isInnate = rsvg.test(elem) ? false : (DOC.namespaces && isVML(elem)) ? true : attrName in elem.cloneNode(false)
2623
2777
  if (isInnate) {
2624
- elem[attrName] = val
2778
+ elem[attrName] = val + ""
2625
2779
  } else {
2626
2780
  elem.setAttribute(attrName, val)
2627
2781
  }
@@ -2633,7 +2787,9 @@ bindingExecutors.attr = function (val, elem, data) {
2633
2787
  var target = replace ? elem.parentNode : elem
2634
2788
  var scanTemplate = function (text) {
2635
2789
  if (loaded) {
2636
- text = loaded.apply(target, [text].concat(vmodels))
2790
+ var newText = loaded.apply(target, [text].concat(vmodels))
2791
+ if (typeof newText === "string")
2792
+ text = newText
2637
2793
  }
2638
2794
  if (rendered) {
2639
2795
  checkScan(target, function () {
@@ -2666,20 +2822,27 @@ bindingExecutors.attr = function (val, elem, data) {
2666
2822
  }
2667
2823
 
2668
2824
  if (data.param === "src") {
2669
- if (cacheTmpls[val]) {
2825
+ if (typeof templatePool[val] === "string") {
2670
2826
  avalon.nextTick(function () {
2671
- scanTemplate(cacheTmpls[val])
2827
+ scanTemplate(templatePool[val])
2672
2828
  })
2829
+ } else if (Array.isArray(templatePool[val])) { //#805 防止在循环绑定中发出许多相同的请求
2830
+ templatePool[val].push(scanTemplate)
2673
2831
  } else {
2674
2832
  var xhr = getXHR()
2675
2833
  xhr.onreadystatechange = function () {
2676
2834
  if (xhr.readyState === 4) {
2677
2835
  var s = xhr.status
2678
2836
  if (s >= 200 && s < 300 || s === 304 || s === 1223) {
2679
- scanTemplate(cacheTmpls[val] = xhr.responseText)
2837
+ var text = xhr.responseText
2838
+ for (var f = 0, fn; fn = templatePool[val][f++]; ) {
2839
+ fn(text)
2840
+ }
2841
+ templatePool[val] = text
2680
2842
  }
2681
2843
  }
2682
2844
  }
2845
+ templatePool[val] = [scanTemplate]
2683
2846
  xhr.open("GET", val, true)
2684
2847
  if ("withCredentials" in xhr) {
2685
2848
  xhr.withCredentials = true
@@ -2730,13 +2893,14 @@ bindingExecutors.attr = function (val, elem, data) {
2730
2893
  function getTemplateNodes(data, id, text) {
2731
2894
  var div = data.templateCache && data.templateCache[id]
2732
2895
  if (div) {
2733
- var dom = DOC.createDocumentFragment(), firstChild
2896
+ var dom = DOC.createDocumentFragment(),
2897
+ firstChild
2734
2898
  while (firstChild = div.firstChild) {
2735
2899
  dom.appendChild(firstChild)
2736
2900
  }
2737
2901
  return dom
2738
2902
  }
2739
- return avalon.parseHTML(text)
2903
+ return avalon.parseHTML(text)
2740
2904
  }
2741
2905
 
2742
2906
  //这几个指令都可以使用插值表达式,如ms-src="aaa/{{b}}/{{c}}.html"
@@ -2745,92 +2909,85 @@ function getTemplateNodes(data, id, text) {
2745
2909
  })
2746
2910
  //根据VM的属性值或表达式的值切换类名,ms-class="xxx yyy zzz:flag"
2747
2911
  //http://www.cnblogs.com/rubylouvre/archive/2012/12/17/2818540.html
2748
- bindingHandlers["class"] = function(data, vmodels) {
2749
- var oldStyle = data.param,
2750
- text = data.value,
2912
+ bindingHandlers["class"] = function (binding, vmodels) {
2913
+ var oldStyle = binding.param,
2914
+ text = binding.value,
2751
2915
  rightExpr
2752
- data.handlerName = "class"
2916
+ binding.handlerName = "class"
2753
2917
  if (!oldStyle || isFinite(oldStyle)) {
2754
- data.param = "" //去掉数字
2755
- var noExpr = text.replace(rexprg, function(a) {
2918
+ binding.param = "" //去掉数字
2919
+ var colonIndex = text.replace(rexprg, function (a) {
2756
2920
  return a.replace(/./g, "0")
2757
- //return Math.pow(10, a.length - 1) //将插值表达式插入10的N-1次方来占位
2758
- })
2759
- var colonIndex = noExpr.indexOf(":") //取得第一个冒号的位置
2921
+ }).indexOf(":") //取得第一个冒号的位置
2760
2922
  if (colonIndex === -1) { // 比如 ms-class="aaa bbb ccc" 的情况
2761
2923
  var className = text
2762
- } else { // 比如 ms-class-1="ui-state-active:checked" 的情况
2924
+ rightExpr = true
2925
+ } else { // 比如 ms-class-1="ui-state-active:checked" 的情况
2763
2926
  className = text.slice(0, colonIndex)
2764
2927
  rightExpr = text.slice(colonIndex + 1)
2765
- parseExpr(rightExpr, vmodels, data) //决定是添加还是删除
2766
- if (!data.evaluator) {
2767
- log("debug: ms-class '" + (rightExpr || "").trim() + "' 不存在于VM中")
2768
- return false
2769
- } else {
2770
- data._evaluator = data.evaluator
2771
- data._args = data.args
2772
- }
2773
2928
  }
2774
- var hasExpr = rexpr.test(className) //比如ms-class="width{{w}}"的情况
2775
- if (!hasExpr) {
2776
- data.immobileClass = className
2929
+ if (!rexpr.test(text)) {
2930
+ className = quote(className)
2931
+ } else {
2932
+ className = stringifyExpr(className)
2777
2933
  }
2778
- parseExprProxy("", vmodels, data, (hasExpr ? scanExpr(className) : 0))
2934
+ binding.expr = "[" + className + "," + rightExpr + "]"
2779
2935
  } else {
2780
- data.immobileClass = data.oldStyle = data.param
2781
- parseExprProxy(text, vmodels, data)
2936
+ binding.expr = '[' + quote(oldStyle) + "," + text + "]"
2937
+ binding.oldStyle = oldStyle
2938
+ }
2939
+ var method = binding.type
2940
+ if (method === "hover" || method === "active") { //确保只绑定一次
2941
+ if (!binding.hasBindEvent) {
2942
+ var elem = binding.element
2943
+ var $elem = avalon(elem)
2944
+ var activate = "mouseenter" //在移出移入时切换类名
2945
+ var abandon = "mouseleave"
2946
+ if (method === "active") { //在聚焦失焦中切换类名
2947
+ elem.tabIndex = elem.tabIndex || -1
2948
+ activate = "mousedown"
2949
+ abandon = "mouseup"
2950
+ var fn0 = $elem.bind("mouseleave", function () {
2951
+ binding.toggleClass && $elem.removeClass(binding.newClass)
2952
+ })
2953
+ }
2954
+ }
2955
+
2956
+ var fn1 = $elem.bind(activate, function () {
2957
+ binding.toggleClass && $elem.addClass(binding.newClass)
2958
+ })
2959
+ var fn2 = $elem.bind(abandon, function () {
2960
+ binding.toggleClass && $elem.removeClass(binding.newClass)
2961
+ })
2962
+ binding.rollback = function () {
2963
+ $elem.unbind("mouseleave", fn0)
2964
+ $elem.unbind(activate, fn1)
2965
+ $elem.unbind(abandon, fn2)
2966
+ }
2967
+ binding.hasBindEvent = true
2782
2968
  }
2969
+ parseExprProxy(binding.expr, vmodels, binding)
2783
2970
  }
2784
2971
 
2785
- bindingExecutors ["class"] = function(val, elem, data) {
2786
- var $elem = avalon(elem),
2787
- method = data.type
2788
- if (method === "class" && data.oldStyle) { //如果是旧风格
2789
- $elem.toggleClass(data.oldStyle, !!val)
2790
- } else {
2791
- //如果存在冒号就有求值函数
2792
- data.toggleClass = data._evaluator ? !!data._evaluator.apply(elem, data._args) : true
2793
- data.newClass = data.immobileClass || val
2794
- if (data.oldClass && data.newClass !== data.oldClass) {
2795
- $elem.removeClass(data.oldClass)
2796
- }
2797
- data.oldClass = data.newClass
2798
- switch (method) {
2799
- case "class":
2800
- $elem.toggleClass(data.newClass, data.toggleClass)
2801
- break
2802
- case "hover":
2803
- case "active":
2804
- if (!data.hasBindEvent) { //确保只绑定一次
2805
- var activate = "mouseenter" //在移出移入时切换类名
2806
- var abandon = "mouseleave"
2807
- if (method === "active") { //在聚焦失焦中切换类名
2808
- elem.tabIndex = elem.tabIndex || -1
2809
- activate = "mousedown"
2810
- abandon = "mouseup"
2811
- var fn0 = $elem.bind("mouseleave", function() {
2812
- data.toggleClass && $elem.removeClass(data.newClass)
2813
- })
2814
- }
2815
- var fn1 = $elem.bind(activate, function() {
2816
- data.toggleClass && $elem.addClass(data.newClass)
2817
- })
2818
- var fn2 = $elem.bind(abandon, function() {
2819
- data.toggleClass && $elem.removeClass(data.newClass)
2820
- })
2821
- data.rollback = function() {
2822
- $elem.unbind("mouseleave", fn0)
2823
- $elem.unbind(activate, fn1)
2824
- $elem.unbind(abandon, fn2)
2825
- }
2826
- data.hasBindEvent = true
2827
- }
2828
- break;
2972
+ bindingExecutors["class"] = function (arr, elem, binding) {
2973
+ var $elem = avalon(elem)
2974
+ binding.newClass = arr[0]
2975
+ binding.toggleClass = !!arr[1]
2976
+ if (binding.oldClass && binding.newClass !== binding.oldClass) {
2977
+ $elem.removeClass(binding.oldClass)
2978
+ }
2979
+ binding.oldClass = binding.newClass
2980
+ if (binding.type === "class") {
2981
+ if (binding.oldStyle) {
2982
+ $elem.toggleClass(binding.oldStyle, !!arr[1])
2983
+ } else {
2984
+ $elem.toggleClass(binding.newClass, binding.toggleClass)
2829
2985
  }
2830
2986
  }
2987
+
2831
2988
  }
2832
2989
 
2833
- "hover,active".replace(rword, function(method) {
2990
+ "hover,active".replace(rword, function (method) {
2834
2991
  bindingHandlers[method] = bindingHandlers["class"]
2835
2992
  })
2836
2993
  //ms-controller绑定已经在scanTag 方法中实现
@@ -2839,21 +2996,20 @@ bindingExecutors ["class"] = function(val, elem, data) {
2839
2996
 
2840
2997
  // bindingHandlers.data 定义在if.js
2841
2998
  bindingExecutors.data = function(val, elem, data) {
2842
- var key = "data-" + data.param
2843
- if (val && typeof val === "object") {
2844
- elem[key] = val
2845
- } else {
2846
- elem.setAttribute(key, String(val))
2847
- }
2999
+ var key = "data-" + data.param
3000
+ if (val && typeof val === "object") {
3001
+ elem[key] = val
3002
+ } else {
3003
+ elem.setAttribute(key, String(val))
3004
+ }
2848
3005
  }
2849
-
2850
3006
  //双工绑定
2851
- var duplexBinding = bindingHandlers.duplex = function (data, vmodels) {
3007
+ var duplexBinding = bindingHandlers.duplex = function(data, vmodels) {
2852
3008
  var elem = data.element,
2853
- hasCast
2854
- parseExprProxy(data.value, vmodels, data, 0, 1)
3009
+ hasCast
3010
+ parseExprProxy(data.value, vmodels, data, 1)
2855
3011
 
2856
- data.changed = getBindingCallback(elem, "data-duplex-changed", vmodels) || noop
3012
+ data.changed = getBindingCallback(elem, "data-duplex-changed", vmodels) || noop
2857
3013
  if (data.evaluator && data.args) {
2858
3014
  var params = []
2859
3015
  var casting = oneObject("string,number,boolean,checked")
@@ -2863,7 +3019,7 @@ var duplexBinding = bindingHandlers.duplex = function (data, vmodels) {
2863
3019
  if (elem.msData) {
2864
3020
  elem.msData["ms-duplex"] = data.value
2865
3021
  }
2866
- data.param.replace(/\w+/g, function (name) {
3022
+ data.param.replace(/\w+/g, function(name) {
2867
3023
  if (/^(checkbox|radio)$/.test(elem.type) && /^(radio|checked)$/.test(name)) {
2868
3024
  if (name === "radio")
2869
3025
  log("ms-duplex-radio已经更名为ms-duplex-checked")
@@ -2886,14 +3042,14 @@ var duplexBinding = bindingHandlers.duplex = function (data, vmodels) {
2886
3042
  params.push("string")
2887
3043
  }
2888
3044
  data.param = params.join("-")
2889
- data.bound = function (type, callback) {
3045
+ data.bound = function(type, callback) {
2890
3046
  if (elem.addEventListener) {
2891
3047
  elem.addEventListener(type, callback, false)
2892
3048
  } else {
2893
3049
  elem.attachEvent("on" + type, callback)
2894
3050
  }
2895
3051
  var old = data.rollback
2896
- data.rollback = function () {
3052
+ data.rollback = function() {
2897
3053
  elem.avalonSetter = null
2898
3054
  avalon.unbind(elem, type, callback)
2899
3055
  old && old()
@@ -2910,29 +3066,30 @@ var duplexBinding = bindingHandlers.duplex = function (data, vmodels) {
2910
3066
  }
2911
3067
  }
2912
3068
  //不存在 bindingExecutors.duplex
2913
- function fixNull(val) {
2914
- return val == null ? "" : val
2915
- }
3069
+
3070
+ function fixNull(val) {
3071
+ return val == null ? "" : val
3072
+ }
2916
3073
  avalon.duplexHooks = {
2917
3074
  checked: {
2918
- get: function (val, data) {
3075
+ get: function(val, data) {
2919
3076
  return !data.element.oldValue
2920
3077
  }
2921
3078
  },
2922
3079
  string: {
2923
- get: function (val) { //同步到VM
3080
+ get: function(val) { //同步到VM
2924
3081
  return val
2925
3082
  },
2926
3083
  set: fixNull
2927
3084
  },
2928
3085
  "boolean": {
2929
- get: function (val) {
3086
+ get: function(val) {
2930
3087
  return val === "true"
2931
3088
  },
2932
3089
  set: fixNull
2933
3090
  },
2934
3091
  number: {
2935
- get: function (val, data) {
3092
+ get: function(val, data) {
2936
3093
  var number = parseFloat(val)
2937
3094
  if (-val === -number) {
2938
3095
  return number
@@ -2952,7 +3109,7 @@ avalon.duplexHooks = {
2952
3109
  }
2953
3110
 
2954
3111
  function pipe(val, data, action, e) {
2955
- data.param.replace(/\w+/g, function (name) {
3112
+ data.param.replace(/\w+/g, function(name) {
2956
3113
  var hook = avalon.duplexHooks[name]
2957
3114
  if (hook && typeof hook[action] === "function") {
2958
3115
  val = hook[action](val, data)
@@ -2963,44 +3120,41 @@ function pipe(val, data, action, e) {
2963
3120
 
2964
3121
  var TimerID, ribbon = []
2965
3122
 
2966
- avalon.tick = function (fn) {
2967
- if (ribbon.push(fn) === 1) {
2968
- TimerID = setInterval(ticker, 60)
3123
+ avalon.tick = function(fn) {
3124
+ if (ribbon.push(fn) === 1) {
3125
+ TimerID = setInterval(ticker, 60)
3126
+ }
2969
3127
  }
2970
- }
2971
3128
 
2972
- function ticker() {
2973
- for (var n = ribbon.length - 1; n >= 0; n--) {
2974
- var el = ribbon[n]
2975
- if (el() === false) {
2976
- ribbon.splice(n, 1)
3129
+ function ticker() {
3130
+ for (var n = ribbon.length - 1; n >= 0; n--) {
3131
+ var el = ribbon[n]
3132
+ if (el() === false) {
3133
+ ribbon.splice(n, 1)
3134
+ }
3135
+ }
3136
+ if (!ribbon.length) {
3137
+ clearInterval(TimerID)
2977
3138
  }
2978
3139
  }
2979
- if (!ribbon.length) {
2980
- clearInterval(TimerID)
2981
- }
2982
- }
2983
3140
 
2984
3141
  var watchValueInTimer = noop
2985
3142
  var rmsinput = /text|password|hidden/
2986
- new function () {// jshint ignore:line
2987
- try {//#272 IE9-IE11, firefox
3143
+ new function() { // jshint ignore:line
3144
+ try { //#272 IE9-IE11, firefox
2988
3145
  var setters = {}
2989
3146
  var aproto = HTMLInputElement.prototype
2990
3147
  var bproto = HTMLTextAreaElement.prototype
2991
- function newSetter(value) {// jshint ignore:line
2992
- if (avalon.contains(root, this)) {
3148
+ function newSetter(value) { // jshint ignore:line
2993
3149
  setters[this.tagName].call(this, value)
2994
- if (!rmsinput.test(this.type))
2995
- return
2996
- if (!this.msFocus && this.avalonSetter) {
3150
+ if (rmsinput.test(this.type) && !this.msFocus && this.avalonSetter) {
2997
3151
  this.avalonSetter()
2998
3152
  }
2999
- }
3000
3153
  }
3001
3154
  var inputProto = HTMLInputElement.prototype
3002
3155
  Object.getOwnPropertyNames(inputProto) //故意引发IE6-8等浏览器报错
3003
3156
  setters["INPUT"] = Object.getOwnPropertyDescriptor(aproto, "value").set
3157
+
3004
3158
  Object.defineProperty(aproto, "value", {
3005
3159
  set: newSetter
3006
3160
  })
@@ -3009,67 +3163,66 @@ new function () {// jshint ignore:line
3009
3163
  set: newSetter
3010
3164
  })
3011
3165
  } catch (e) {
3166
+ //在chrome 43中 ms-duplex终于不需要使用定时器实现双向绑定了
3167
+ // http://updates.html5rocks.com/2015/04/DOM-attributes-now-on-the-prototype
3168
+ // https://docs.google.com/document/d/1jwA8mtClwxI-QJuHT7872Z0pxpZz8PBkf2bGAbsUtqs/edit?pli=1
3012
3169
  watchValueInTimer = avalon.tick
3013
3170
  }
3014
- }// jshint ignore:line
3171
+ } // jshint ignore:line
3172
+ //处理radio, checkbox, text, textarea, password
3173
+ duplexBinding.INPUT = function(element, evaluator, data) {
3174
+ var $type = element.type,
3175
+ bound = data.bound,
3176
+ $elem = avalon(element),
3177
+ composing = false
3178
+
3179
+ function callback(value) {
3180
+ data.changed.call(this, value, data)
3181
+ }
3015
3182
 
3183
+ function compositionStart() {
3184
+ composing = true
3185
+ }
3016
3186
 
3017
- //处理radio, checkbox, text, textarea, password
3018
- duplexBinding.INPUT = function (element, evaluator, data) {
3019
- var $type = element.type,
3020
- bound = data.bound,
3021
- $elem = avalon(element),
3187
+ function compositionEnd() {
3022
3188
  composing = false
3023
- function callback(value) {
3024
- data.changed.call(this, value, data)
3025
- }
3026
- function compositionStart() {
3027
- composing = true
3028
- }
3029
- function compositionEnd() {
3030
- composing = false
3031
- }
3032
- //当value变化时改变model的值
3189
+ }
3190
+ //当value变化时改变model的值
3033
3191
 
3034
- var updateVModel = function () {
3035
- if (composing)//处理中文输入法在minlengh下引发的BUG
3192
+ var updateVModel = function() {
3193
+ var val = element.value //防止递归调用形成死循环
3194
+ if (composing || val === element.oldValue) //处理中文输入法在minlengh下引发的BUG
3036
3195
  return
3037
- var val = element.oldValue = element.value //防止递归调用形成死循环
3038
3196
  var lastValue = data.pipe(val, data, "get")
3039
- if ($elem.data("duplex-observe") !== false) {
3197
+ if ($elem.data("duplexObserve") !== false) {
3040
3198
  evaluator(lastValue)
3041
3199
  callback.call(element, lastValue)
3042
- if ($elem.data("duplex-focus")) {
3043
- avalon.nextTick(function () {
3044
- element.focus()
3045
- })
3046
- }
3047
3200
  }
3048
3201
  }
3049
3202
  //当model变化时,它就会改变value的值
3050
- data.handler = function () {
3203
+ data.handler = function() {
3051
3204
  var val = data.pipe(evaluator(), data, "set") + ""
3052
3205
  if (val !== element.oldValue) {
3053
- element.value = val
3206
+ element.value = element.oldValue = val
3054
3207
  }
3055
3208
  }
3056
3209
  if (data.isChecked || $type === "radio") {
3057
- updateVModel = function () {
3058
- if ($elem.data("duplex-observe") !== false) {
3210
+ updateVModel = function() {
3211
+ if ($elem.data("duplexObserve") !== false) {
3059
3212
  var lastValue = data.pipe(element.value, data, "get")
3060
3213
  evaluator(lastValue)
3061
3214
  callback.call(element, lastValue)
3062
3215
  }
3063
3216
  }
3064
- data.handler = function () {
3217
+ data.handler = function() {
3065
3218
  var val = evaluator()
3066
- var checked = data.isChecked ? !!val : val + "" === element.value
3219
+ var checked = data.isChecked ? !! val : val + "" === element.value
3067
3220
  element.checked = element.oldValue = checked
3068
3221
  }
3069
3222
  bound("click", updateVModel)
3070
3223
  } else if ($type === "checkbox") {
3071
- updateVModel = function () {
3072
- if ($elem.data("duplex-observe") !== false) {
3224
+ updateVModel = function() {
3225
+ if ($elem.data("duplexObserve") !== false) {
3073
3226
  var method = element.checked ? "ensure" : "remove"
3074
3227
  var array = evaluator()
3075
3228
  if (!Array.isArray(array)) {
@@ -3080,7 +3233,7 @@ duplexBinding.INPUT = function (element, evaluator, data) {
3080
3233
  callback.call(element, array)
3081
3234
  }
3082
3235
  }
3083
- data.handler = function () {
3236
+ data.handler = function() {
3084
3237
  var array = [].concat(evaluator()) //强制转换为数组
3085
3238
  element.checked = array.indexOf(data.pipe(element.value, data, "get")) > -1
3086
3239
  }
@@ -3090,7 +3243,7 @@ duplexBinding.INPUT = function (element, evaluator, data) {
3090
3243
  if (element.attributes["data-event"]) {
3091
3244
  log("data-event指令已经废弃,请改用data-duplex-event")
3092
3245
  }
3093
- events.replace(rword, function (name) {
3246
+ events.replace(rword, function(name) {
3094
3247
  switch (name) {
3095
3248
  case "input":
3096
3249
  bound("input", updateVModel)
@@ -3105,14 +3258,14 @@ duplexBinding.INPUT = function (element, evaluator, data) {
3105
3258
  break
3106
3259
  }
3107
3260
  })
3108
- bound("focus", function () {
3261
+ bound("focus", function() {
3109
3262
  element.msFocus = true
3110
3263
  })
3111
- bound("blur", function () {
3264
+ bound("blur", function() {
3112
3265
  element.msFocus = false
3113
3266
  })
3114
3267
  if (rmsinput.test($type)) {
3115
- watchValueInTimer(function () {
3268
+ watchValueInTimer(function() {
3116
3269
  if (root.contains(element)) {
3117
3270
  if (!element.msFocus && element.oldValue !== element.value) {
3118
3271
  updateVModel()
@@ -3127,28 +3280,29 @@ duplexBinding.INPUT = function (element, evaluator, data) {
3127
3280
  }
3128
3281
 
3129
3282
  element.oldValue = element.value
3130
- registerSubscriber(data)
3283
+ avalon.injectBinding(data)
3131
3284
  callback.call(element, element.value)
3132
3285
  }
3133
3286
  duplexBinding.TEXTAREA = duplexBinding.INPUT
3134
3287
  duplexBinding.SELECT = function(element, evaluator, data) {
3135
3288
  var $elem = avalon(element)
3136
- function updateVModel() {
3137
- if ($elem.data("duplex-observe") !== false) {
3138
- var val = $elem.val() //字符串或字符串数组
3139
- if (Array.isArray(val)) {
3140
- val = val.map(function(v) {
3141
- return data.pipe(v, data, "get")
3142
- })
3143
- } else {
3144
- val = data.pipe(val, data, "get")
3145
- }
3146
- if (val + "" !== element.oldValue) {
3147
- evaluator(val)
3289
+
3290
+ function updateVModel() {
3291
+ if ($elem.data("duplexObserve") !== false) {
3292
+ var val = $elem.val() //字符串或字符串数组
3293
+ if (Array.isArray(val)) {
3294
+ val = val.map(function(v) {
3295
+ return data.pipe(v, data, "get")
3296
+ })
3297
+ } else {
3298
+ val = data.pipe(val, data, "get")
3299
+ }
3300
+ if (val + "" !== element.oldValue) {
3301
+ evaluator(val)
3302
+ }
3303
+ data.changed.call(element, val, data)
3148
3304
  }
3149
- data.changed.call(element, val, data)
3150
3305
  }
3151
- }
3152
3306
  data.handler = function() {
3153
3307
  var val = evaluator()
3154
3308
  val = val && val.$model || val
@@ -3169,74 +3323,77 @@ duplexBinding.SELECT = function(element, evaluator, data) {
3169
3323
  }
3170
3324
  }
3171
3325
  data.bound("change", updateVModel)
3172
- checkScan(element, function() {
3173
- registerSubscriber(data)
3326
+ element.msCallback = function() {
3327
+ avalon.injectBinding(data)
3174
3328
  data.changed.call(element, evaluator(), data)
3175
- }, NaN)
3329
+ }
3176
3330
  }
3177
-
3178
-
3179
3331
  // bindingHandlers.html 定义在if.js
3180
- bindingExecutors.html = function(val, elem, data) {
3181
- val = val == null ? "" : val
3182
- var isHtmlFilter = "group" in data
3332
+ bindingExecutors.html = function (val, elem, data) {
3333
+ var isHtmlFilter = elem.nodeType !== 1
3183
3334
  var parent = isHtmlFilter ? elem.parentNode : elem
3184
3335
  if (!parent)
3185
3336
  return
3186
- if (val.nodeType === 11) { //将val转换为文档碎片
3187
- var fragment = val
3337
+ val = val == null ? "" : val
3338
+ if (data.oldText !== val) {
3339
+ data.oldText = val
3340
+ } else {
3341
+ return
3342
+ }
3343
+ if (elem.nodeType === 3) {
3344
+ var signature = generateID("html")
3345
+ parent.insertBefore(DOC.createComment(signature), elem)
3346
+ data.element = DOC.createComment(signature + ":end")
3347
+ parent.replaceChild(data.element, elem)
3348
+ elem = data.element
3349
+ }
3350
+ if (typeof val !== "object") {//string, number, boolean
3351
+ var fragment = avalon.parseHTML(String(val))
3352
+ } else if (val.nodeType === 11) { //将val转换为文档碎片
3353
+ fragment = val
3188
3354
  } else if (val.nodeType === 1 || val.item) {
3189
- var nodes = val.nodeType === 1 ? val.childNodes : val.item ? val : []
3190
- fragment = hyperspace.cloneNode(true)
3355
+ var nodes = val.nodeType === 1 ? val.childNodes : val.item
3356
+ fragment = avalonFragment.cloneNode(true)
3191
3357
  while (nodes[0]) {
3192
3358
  fragment.appendChild(nodes[0])
3193
3359
  }
3194
- } else {
3195
- fragment = avalon.parseHTML(val)
3196
3360
  }
3361
+
3362
+ nodes = avalon.slice(fragment.childNodes)
3197
3363
  //插入占位符, 如果是过滤器,需要有节制地移除指定的数量,如果是html指令,直接清空
3198
- var comment = DOC.createComment("ms-html")
3199
3364
  if (isHtmlFilter) {
3200
- parent.insertBefore(comment, elem)
3201
- var n = data.group, i = 1
3202
- while (i < n) {
3203
- var node = elem.nextSibling
3204
- if (node) {
3365
+ var endValue = elem.nodeValue.slice(0, -4)
3366
+ while (true) {
3367
+ var node = elem.previousSibling
3368
+ if (!node || node.nodeType === 8 && node.nodeValue === endValue) {
3369
+ break
3370
+ } else {
3205
3371
  parent.removeChild(node)
3206
- i++
3207
3372
  }
3208
3373
  }
3209
- parent.removeChild(elem)
3210
- data.element = comment //防止被CG
3374
+ parent.insertBefore(fragment, elem)
3211
3375
  } else {
3212
- avalon.clearHTML(parent).appendChild(comment)
3213
- }
3214
- if (isHtmlFilter) {
3215
- data.group = fragment.childNodes.length || 1
3216
- }
3217
- nodes = avalon.slice(fragment.childNodes)
3218
- if (nodes[0]) {
3219
- if (comment.parentNode)
3220
- comment.parentNode.replaceChild(fragment, comment)
3221
- if (isHtmlFilter) {
3222
- data.element = nodes[0]
3223
- }
3376
+ avalon.clearHTML(elem).appendChild(fragment)
3224
3377
  }
3225
3378
  scanNodeArray(nodes, data.vmodels)
3226
3379
  }
3227
-
3228
3380
  bindingHandlers["if"] =
3229
- bindingHandlers.data =
3230
- bindingHandlers.text =
3231
- bindingHandlers.html =
3232
- function(data, vmodels) {
3233
- parseExprProxy(data.value, vmodels, data)
3234
- }
3381
+ bindingHandlers.data =
3382
+ bindingHandlers.text =
3383
+ bindingHandlers.html =
3384
+ function(data, vmodels) {
3385
+ parseExprProxy(data.value, vmodels, data)
3386
+ }
3235
3387
 
3236
3388
  bindingExecutors["if"] = function(val, elem, data) {
3389
+ try {
3390
+ if(!elem.parentNode) return
3391
+ } catch(e) {return}
3237
3392
  if (val) { //插回DOM树
3238
3393
  if (elem.nodeType === 8) {
3239
3394
  elem.parentNode.replaceChild(data.template, elem)
3395
+ elem.ifRemove = null
3396
+ // animate.enter(data.template, elem.parentNode)
3240
3397
  elem = data.element = data.template //这时可能为null
3241
3398
  }
3242
3399
  if (elem.getAttribute(data.name)) {
@@ -3248,6 +3405,8 @@ bindingExecutors["if"] = function(val, elem, data) {
3248
3405
  if (elem.nodeType === 1) {
3249
3406
  var node = data.element = DOC.createComment("ms-if")
3250
3407
  elem.parentNode.replaceChild(node, elem)
3408
+ elem.ifRemove = node
3409
+ // animate.leave(elem, node.parentNode, node)
3251
3410
  data.template = elem //元素节点
3252
3411
  ifGroup.appendChild(elem)
3253
3412
  data.rollback = function() {
@@ -3258,8 +3417,6 @@ bindingExecutors["if"] = function(val, elem, data) {
3258
3417
  }
3259
3418
  }
3260
3419
  }
3261
-
3262
-
3263
3420
  //ms-important绑定已经在scanTag 方法中实现
3264
3421
  //ms-include绑定已由ms-attr绑定实现
3265
3422
 
@@ -3303,11 +3460,9 @@ bindingExecutors.on = function(callback, elem, data) {
3303
3460
  }
3304
3461
  }
3305
3462
  }
3306
-
3307
-
3308
- bindingHandlers.repeat = function(data, vmodels) {
3463
+ bindingHandlers.repeat = function (data, vmodels) {
3309
3464
  var type = data.type
3310
- parseExprProxy(data.value, vmodels, data, 0, 1)
3465
+ parseExprProxy(data.value, vmodels, data, 1)
3311
3466
  data.proxies = []
3312
3467
  var freturn = false
3313
3468
  try {
@@ -3316,11 +3471,12 @@ bindingHandlers.repeat = function(data, vmodels) {
3316
3471
  if (xtype !== "object" && xtype !== "array") {
3317
3472
  freturn = true
3318
3473
  avalon.log("warning:" + data.value + "只能是对象或数组")
3474
+ } else {
3475
+ data.xtype = xtype
3319
3476
  }
3320
3477
  } catch (e) {
3321
3478
  freturn = true
3322
3479
  }
3323
-
3324
3480
  var arr = data.value.split(".") || []
3325
3481
  if (arr.length > 1) {
3326
3482
  arr.pop()
@@ -3334,41 +3490,43 @@ bindingHandlers.repeat = function(data, vmodels) {
3334
3490
  }
3335
3491
  }
3336
3492
  }
3493
+
3337
3494
  var elem = data.element
3338
- elem.removeAttribute(data.name)
3339
-
3340
- data.sortedCallback = getBindingCallback(elem, "data-with-sorted", vmodels)
3341
- data.renderedCallback = getBindingCallback(elem, "data-" + type + "-rendered", vmodels)
3342
- var signature = generateID(type)
3343
- var comment = data.element = DOC.createComment(signature + ":end")
3344
- data.clone = DOC.createComment(signature)
3345
- hyperspace.appendChild(comment)
3346
-
3347
- if (type === "each" || type === "with") {
3348
- data.template = elem.innerHTML.trim()
3349
- avalon.clearHTML(elem).appendChild(comment)
3350
- } else {
3351
- data.template = elem.outerHTML.trim()
3352
- elem.parentNode.replaceChild(comment, elem)
3353
- }
3354
- data.template = avalon.parseHTML(data.template)
3355
- data.rollback = function() {
3356
- var elem = data.element
3357
- if (!elem)
3358
- return
3359
- bindingExecutors.repeat.call(data, "clear")
3360
- var parentNode = elem.parentNode
3361
- var content = data.template
3362
- var target = content.firstChild
3363
- parentNode.replaceChild(content, elem)
3364
- var start = data.$stamp
3365
- start && start.parentNode && start.parentNode.removeChild(start)
3366
- target = data.element = data.type === "repeat" ? target : parentNode
3495
+ if (elem.nodeType === 1) {
3496
+ elem.removeAttribute(data.name)
3497
+ data.sortedCallback = getBindingCallback(elem, "data-with-sorted", vmodels)
3498
+ data.renderedCallback = getBindingCallback(elem, "data-" + type + "-rendered", vmodels)
3499
+ var signature = generateID(type)
3500
+ var start = DOC.createComment(signature)
3501
+ var end = DOC.createComment(signature + ":end")
3502
+ data.signature = signature
3503
+ data.template = avalonFragment.cloneNode(false)
3504
+ if (type === "repeat") {
3505
+ var parent = elem.parentNode
3506
+ parent.replaceChild(end, elem)
3507
+ parent.insertBefore(start, end)
3508
+ data.template.appendChild(elem)
3509
+ } else {
3510
+ while (elem.firstChild) {
3511
+ data.template.appendChild(elem.firstChild)
3512
+ }
3513
+ elem.appendChild(start)
3514
+ elem.appendChild(end)
3515
+ }
3516
+ data.element = end
3517
+ data.handler = bindingExecutors.repeat
3518
+ data.rollback = function () {
3519
+ var elem = data.element
3520
+ if (!elem)
3521
+ return
3522
+ data.handler("clear")
3523
+ }
3367
3524
  }
3525
+
3368
3526
  if (freturn) {
3369
3527
  return
3370
3528
  }
3371
- data.handler = bindingExecutors.repeat
3529
+
3372
3530
  data.$outer = {}
3373
3531
  var check0 = "$key"
3374
3532
  var check1 = "$val"
@@ -3376,6 +3534,7 @@ bindingHandlers.repeat = function(data, vmodels) {
3376
3534
  check0 = "$first"
3377
3535
  check1 = "$last"
3378
3536
  }
3537
+
3379
3538
  for (i = 0; v = vmodels[i++]; ) {
3380
3539
  if (v.hasOwnProperty(check0) && v.hasOwnProperty(check1)) {
3381
3540
  data.$outer = v
@@ -3384,81 +3543,101 @@ bindingHandlers.repeat = function(data, vmodels) {
3384
3543
  }
3385
3544
  var $events = $repeat.$events
3386
3545
  var $list = ($events || {})[subscribers]
3387
- if ($list && avalon.Array.ensure($list, data)) {
3388
- addSubscribers(data, $list)
3389
- }
3546
+ injectDependency($list, data)
3390
3547
  if (xtype === "object") {
3391
- data.$with = true
3392
- var pool = !$events ? {} : $events.$withProxyPool || ($events.$withProxyPool = {})
3393
- data.handler("append", $repeat, pool)
3548
+ data.handler("append")
3394
3549
  } else if ($repeat.length) {
3395
3550
  data.handler("add", 0, $repeat.length)
3396
3551
  }
3397
3552
  }
3398
3553
 
3399
- bindingExecutors.repeat = function(method, pos, el) {
3554
+ bindingExecutors.repeat = function (method, pos, el) {
3555
+ var data = this
3556
+ if (!method && data.xtype) {
3557
+ var old = data.$repeat
3558
+ var neo = data.evaluator.apply(0, data.args || [])
3559
+
3560
+ if (data.xtype === "array") {
3561
+ if (old.length === neo.length) {
3562
+ return
3563
+ }
3564
+ method = "add"
3565
+ pos = 0
3566
+ data.$repeat = neo
3567
+ el = neo.length
3568
+ } else {
3569
+ if (keysVM(old).join(";;") === keysVM(neo).join(";;")) {
3570
+ return
3571
+ }
3572
+ method = "append"
3573
+ data.$repeat = neo
3574
+ }
3575
+ }
3400
3576
  if (method) {
3401
- var data = this
3577
+ var start, fragment
3402
3578
  var end = data.element
3579
+ var comments = getComments(data)
3403
3580
  var parent = end.parentNode
3404
3581
  var proxies = data.proxies
3405
- var transation = hyperspace.cloneNode(false)
3582
+ var transation = avalonFragment.cloneNode(false)
3406
3583
  switch (method) {
3407
- case "add": //在pos位置后添加el数组(pos为数字,el为数组)
3584
+ case "add": //在pos位置后添加el数组(pos为插入位置,el为要插入的个数)
3408
3585
  var n = pos + el
3409
- var array = data.$repeat
3410
- var last = array.length - 1
3411
- var fragments = [], fragment
3412
- var start = locateNode(data, pos)
3586
+ var fragments = []
3413
3587
  for (var i = pos; i < n; i++) {
3414
3588
  var proxy = eachProxyAgent(i, data)
3415
3589
  proxies.splice(i, 0, proxy)
3416
3590
  shimController(data, transation, proxy, fragments)
3417
3591
  }
3418
- parent.insertBefore(transation, start)
3592
+ parent.insertBefore(transation, comments[pos] || end)
3419
3593
  for (i = 0; fragment = fragments[i++]; ) {
3420
3594
  scanNodeArray(fragment.nodes, fragment.vmodels)
3421
3595
  fragment.nodes = fragment.vmodels = null
3422
3596
  }
3597
+
3423
3598
  break
3424
3599
  case "del": //将pos后的el个元素删掉(pos, el都是数字)
3425
- start = proxies[pos].$stamp
3426
- end = locateNode(data, pos + el)
3427
- sweepNodes(start, end)
3600
+ sweepNodes(comments[pos], comments[pos + el] || end)
3428
3601
  var removed = proxies.splice(pos, el)
3429
3602
  recycleProxies(removed, "each")
3430
3603
  break
3431
3604
  case "clear":
3432
- var check = data.$stamp || proxies[0]
3433
- if (check) {
3434
- start = check.$stamp || check
3605
+ start = comments[0]
3606
+ if (start) {
3435
3607
  sweepNodes(start, end)
3608
+ if (data.xtype === "object") {
3609
+ parent.insertBefore(start, end)
3610
+ }else{
3611
+ recycleProxies(proxies, "each")
3612
+ }
3436
3613
  }
3437
- recycleProxies(proxies, "each")
3438
3614
  break
3439
3615
  case "move":
3440
- start = proxies[0].$stamp
3441
- var signature = start.nodeValue
3442
- var rooms = []
3443
- var room = [], node
3444
- sweepNodes(start, end, function() {
3445
- room.unshift(this)
3446
- if (this.nodeValue === signature) {
3447
- rooms.unshift(room)
3448
- room = []
3449
- }
3450
- })
3451
- sortByIndex(proxies, pos)
3452
- sortByIndex(rooms, pos)
3453
- while (room = rooms.shift()) {
3454
- while (node = room.shift()) {
3455
- transation.appendChild(node)
3616
+ start = comments[0]
3617
+ if (start) {
3618
+ var signature = start.nodeValue
3619
+ var rooms = []
3620
+ var room = [],
3621
+ node
3622
+ sweepNodes(start, end, function () {
3623
+ room.unshift(this)
3624
+ if (this.nodeValue === signature) {
3625
+ rooms.unshift(room)
3626
+ room = []
3627
+ }
3628
+ })
3629
+ sortByIndex(rooms, pos)
3630
+ sortByIndex(proxies, pos)
3631
+ while (room = rooms.shift()) {
3632
+ while (node = room.shift()) {
3633
+ transation.appendChild(node)
3634
+ }
3456
3635
  }
3636
+ parent.insertBefore(transation, end)
3457
3637
  }
3458
- parent.insertBefore(transation, end)
3459
3638
  break
3460
3639
  case "index": //将proxies中的第pos个起的所有元素重新索引
3461
- last = proxies.length - 1
3640
+ var last = proxies.length - 1
3462
3641
  for (; el = proxies[pos]; pos++) {
3463
3642
  el.$index = pos
3464
3643
  el.$first = pos === 0
@@ -3468,15 +3647,23 @@ bindingExecutors.repeat = function(method, pos, el) {
3468
3647
  case "set": //将proxies中的第pos个元素的VM设置为el(pos为数字,el任意)
3469
3648
  proxy = proxies[pos]
3470
3649
  if (proxy) {
3471
- notifySubscribers(proxy.$events.$index)
3650
+ fireDependencies(proxy.$events[data.param || "el"])
3472
3651
  }
3473
- return
3474
- case "append": //将pos的键值对从el中取出(pos为一个普通对象,el为预先生成好的代理VM对象池)
3475
- var pool = el
3652
+ break
3653
+ case "append":
3654
+ var object = data.$repeat //原来第2参数, 被循环对象
3655
+ var pool = Array.isArray(proxies) ||!proxies ? {}: proxies //代理对象组成的hash
3656
+ data.proxies = pool
3476
3657
  var keys = []
3477
3658
  fragments = []
3478
- for (var key in pos) { //得到所有键名
3479
- if (pos.hasOwnProperty(key) && key !== "hasOwnProperty") {
3659
+ for (var key in pool) {
3660
+ if (!object.hasOwnProperty(key)) {
3661
+ proxyRecycler(pool[key], withProxyPool) //去掉之前的代理VM
3662
+ delete(pool[key])
3663
+ }
3664
+ }
3665
+ for (key in object) { //得到所有键名
3666
+ if (object.hasOwnProperty(key) && key !== "hasOwnProperty") {
3480
3667
  keys.push(key)
3481
3668
  }
3482
3669
  }
@@ -3488,14 +3675,11 @@ bindingExecutors.repeat = function(method, pos, el) {
3488
3675
  }
3489
3676
  for (i = 0; key = keys[i++]; ) {
3490
3677
  if (key !== "hasOwnProperty") {
3491
- if (!pool[key]) {
3492
- pool[key] = withProxyAgent(key, data)
3493
- }
3678
+ pool[key] = withProxyAgent(pool[key], key, data)
3494
3679
  shimController(data, transation, pool[key], fragments)
3495
3680
  }
3496
3681
  }
3497
- var comment = data.$stamp = data.clone
3498
- parent.insertBefore(comment, end)
3682
+
3499
3683
  parent.insertBefore(transation, end)
3500
3684
  for (i = 0; fragment = fragments[i++]; ) {
3501
3685
  scanNodeArray(fragment.nodes, fragment.vmodels)
@@ -3503,29 +3687,26 @@ bindingExecutors.repeat = function(method, pos, el) {
3503
3687
  }
3504
3688
  break
3505
3689
  }
3690
+ if (!data.$repeat || data.$repeat.hasOwnProperty("$lock")) //IE6-8 VBScript对象会报错, 有时候data.$repeat不存在
3691
+ return
3506
3692
  if (method === "clear")
3507
3693
  method = "del"
3508
3694
  var callback = data.renderedCallback || noop,
3509
3695
  args = arguments
3510
- checkScan(parent, function() {
3511
- callback.apply(parent, args)
3512
- if (parent.oldValue && parent.tagName === "SELECT") { //fix #503
3513
- avalon(parent).val(parent.oldValue.split(","))
3514
- }
3515
- }, NaN)
3696
+ if (parent.oldValue && parent.tagName === "SELECT") { //fix #503
3697
+ avalon(parent).val(parent.oldValue.split(","))
3698
+ }
3699
+ callback.apply(parent, args)
3516
3700
  }
3517
3701
  }
3518
-
3519
- "with,each".replace(rword, function(name) {
3702
+ "with,each".replace(rword, function (name) {
3520
3703
  bindingHandlers[name] = bindingHandlers.repeat
3521
3704
  })
3522
3705
 
3523
3706
  function shimController(data, transation, proxy, fragments) {
3524
3707
  var content = data.template.cloneNode(true)
3525
3708
  var nodes = avalon.slice(content.childNodes)
3526
- if (proxy.$stamp) {
3527
- content.insertBefore(proxy.$stamp, content.firstChild)
3528
- }
3709
+ content.insertBefore(DOC.createComment(data.signature), content.firstChild)
3529
3710
  transation.appendChild(content)
3530
3711
  var nv = [proxy].concat(data.vmodels)
3531
3712
  var fragment = {
@@ -3535,11 +3716,21 @@ function shimController(data, transation, proxy, fragments) {
3535
3716
  fragments.push(fragment)
3536
3717
  }
3537
3718
 
3538
- function locateNode(data, pos) {
3539
- var proxy = data.proxies[pos]
3540
- return proxy ? proxy.$stamp : data.element
3719
+ function getComments(data) {
3720
+ var ret = []
3721
+ var nodes = data.element.parentNode.childNodes
3722
+ for (var i = 0, node; node = nodes[i++]; ) {
3723
+ if (node.nodeValue === data.signature) {
3724
+ ret.push(node)
3725
+ } else if (node.nodeValue === data.signature + ":end") {
3726
+ break
3727
+ }
3728
+ }
3729
+ return ret
3541
3730
  }
3542
3731
 
3732
+
3733
+ //移除掉start与end之间的节点(保留end)
3543
3734
  function sweepNodes(start, end, callback) {
3544
3735
  while (true) {
3545
3736
  var node = end.previousSibling
@@ -3556,24 +3747,89 @@ function sweepNodes(start, end, callback) {
3556
3747
  // 为ms-each,ms-with, ms-repeat会创建一个代理VM,
3557
3748
  // 通过它们保持一个下上文,让用户能调用$index,$first,$last,$remove,$key,$val,$outer等属性与方法
3558
3749
  // 所有代理VM的产生,消费,收集,存放通过xxxProxyFactory,xxxProxyAgent, recycleProxies,xxxProxyPool实现
3559
- var eachProxyPool = []
3560
3750
  var withProxyPool = []
3751
+ function withProxyFactory() {
3752
+ var proxy = modelFactory({
3753
+ $key: "",
3754
+ $outer: {},
3755
+ $host: {},
3756
+ $val: {
3757
+ get: function () {
3758
+ return this.$host[this.$key]
3759
+ },
3760
+ set: function (val) {
3761
+ this.$host[this.$key] = val
3762
+ }
3763
+ }
3764
+ }, {
3765
+ $val: 1
3766
+ })
3767
+ proxy.$id = generateID("$proxy$with")
3768
+ return proxy
3769
+ }
3770
+
3771
+ function withProxyAgent(proxy, key, data) {
3772
+ proxy = proxy || withProxyPool.pop()
3773
+ if (!proxy) {
3774
+ proxy = withProxyFactory()
3775
+ } else {
3776
+ proxy.$reinitialize()
3777
+ }
3778
+ var host = data.$repeat
3779
+ proxy.$key = key
3780
+
3781
+ proxy.$host = host
3782
+ proxy.$outer = data.$outer
3783
+ if (host.$events) {
3784
+ proxy.$events.$val = host.$events[key]
3785
+ } else {
3786
+ proxy.$events = {}
3787
+ }
3788
+ return proxy
3789
+ }
3790
+
3791
+
3792
+ function recycleProxies(proxies) {
3793
+ eachProxyRecycler(proxies)
3794
+ }
3795
+ function eachProxyRecycler(proxies) {
3796
+ proxies.forEach(function (proxy) {
3797
+ proxyRecycler(proxy, eachProxyPool)
3798
+ })
3799
+ proxies.length = 0
3800
+ }
3801
+
3802
+
3803
+ var eachProxyPool = []
3561
3804
  function eachProxyFactory(name) {
3562
3805
  var source = {
3563
3806
  $host: [],
3564
3807
  $outer: {},
3565
- $stamp: 1,
3566
3808
  $index: 0,
3567
3809
  $first: false,
3568
3810
  $last: false,
3569
3811
  $remove: avalon.noop
3570
3812
  }
3571
3813
  source[name] = {
3572
- get: function() {
3573
- return this.$host[this.$index]
3814
+ get: function () {
3815
+ var e = this.$events
3816
+ var array = e.$index
3817
+ e.$index = e[name] //#817 通过$index为el收集依赖
3818
+ try {
3819
+ return this.$host[this.$index]
3820
+ } finally {
3821
+ e.$index = array
3822
+ }
3574
3823
  },
3575
- set: function(val) {
3576
- this.$host.set(this.$index, val)
3824
+ set: function (val) {
3825
+ try {
3826
+ var e = this.$events
3827
+ var array = e.$index
3828
+ e.$index = []
3829
+ this.$host.set(this.$index, val)
3830
+ } finally {
3831
+ e.$index = array
3832
+ }
3577
3833
  }
3578
3834
  }
3579
3835
  var second = {
@@ -3582,14 +3838,13 @@ function eachProxyFactory(name) {
3582
3838
  $index: 1
3583
3839
  }
3584
3840
  var proxy = modelFactory(source, second)
3585
- var e = proxy.$events
3586
- e[name] = e.$first = e.$last = e.$index
3587
3841
  proxy.$id = generateID("$proxy$each")
3588
3842
  return proxy
3589
3843
  }
3590
3844
 
3591
3845
  function eachProxyAgent(index, data) {
3592
- var param = data.param || "el", proxy
3846
+ var param = data.param || "el",
3847
+ proxy
3593
3848
  for (var i = 0, n = eachProxyPool.length; i < n; i++) {
3594
3849
  var candidate = eachProxyPool[i]
3595
3850
  if (candidate && candidate.hasOwnProperty(param)) {
@@ -3607,93 +3862,45 @@ function eachProxyAgent(index, data) {
3607
3862
  proxy.$last = index === last
3608
3863
  proxy.$host = host
3609
3864
  proxy.$outer = data.$outer
3610
- proxy.$stamp = data.clone.cloneNode(false)
3611
- proxy.$remove = function() {
3865
+ proxy.$remove = function () {
3612
3866
  return host.removeAt(proxy.$index)
3613
3867
  }
3614
3868
  return proxy
3615
3869
  }
3616
3870
 
3617
- function withProxyFactory() {
3618
- var proxy = modelFactory({
3619
- $key: "",
3620
- $outer: {},
3621
- $host: {},
3622
- $val: {
3623
- get: function() {
3624
- return this.$host[this.$key]
3625
- },
3626
- set: function(val) {
3627
- this.$host[this.$key] = val
3628
- }
3629
- }
3630
- }, {
3631
- $val: 1
3632
- })
3633
- proxy.$id = generateID("$proxy$with")
3634
- return proxy
3635
- }
3636
3871
 
3637
- function withProxyAgent(key, data) {
3638
- var proxy = withProxyPool.pop()
3639
- if (!proxy) {
3640
- proxy = withProxyFactory()
3872
+ function proxyRecycler(proxy, proxyPool) {
3873
+ for (var i in proxy.$events) {
3874
+ var arr = proxy.$events[i]
3875
+ if (Array.isArray(arr)) {
3876
+ arr.forEach(function (data) {
3877
+ if (typeof data === "object")
3878
+ disposeData(data)
3879
+ })// jshint ignore:line
3880
+ arr.length = 0
3881
+ }
3641
3882
  }
3642
- var host = data.$repeat
3643
- proxy.$key = key
3644
- proxy.$host = host
3645
- proxy.$outer = data.$outer
3646
- if (host.$events) {
3647
- proxy.$events.$val = host.$events[key]
3648
- } else {
3649
- proxy.$events = {}
3883
+ proxy.$host = proxy.$outer = {}
3884
+ if (proxyPool.unshift(proxy) > kernel.maxRepeatSize) {
3885
+ proxyPool.pop()
3650
3886
  }
3651
- return proxy
3652
- }
3653
-
3654
- function recycleProxies(proxies, type) {
3655
- var proxyPool = type === "each" ? eachProxyPool : withProxyPool
3656
- avalon.each(proxies, function(key, proxy) {
3657
- if (proxy.$events) {
3658
- for (var i in proxy.$events) {
3659
- if (Array.isArray(proxy.$events[i])) {
3660
- proxy.$events[i].forEach(function(data) {
3661
- if (typeof data === "object")
3662
- disposeData(data)
3663
- })// jshint ignore:line
3664
- proxy.$events[i].length = 0
3665
- }
3666
- }
3667
- proxy.$host = proxy.$outer = {}
3668
- if (proxyPool.unshift(proxy) > kernel.maxRepeatSize) {
3669
- proxyPool.pop()
3670
- }
3671
- }
3672
- })
3673
- if (type === "each")
3674
- proxies.length = 0
3675
3887
  }
3676
3888
 
3677
-
3678
-
3679
-
3680
3889
  /*********************************************************************
3681
3890
  * 各种指令 *
3682
3891
  **********************************************************************/
3683
3892
  //ms-skip绑定已经在scanTag 方法中实现
3684
3893
  // bindingHandlers.text 定义在if.js
3685
3894
  bindingExecutors.text = function(val, elem) {
3686
- val = val == null ? "" : val //不在页面上显示undefined null
3687
- if (elem.nodeType === 3) { //绑定在文本节点上
3688
- try { //IE对游离于DOM树外的节点赋值会报错
3689
- elem.data = val
3690
- } catch (e) {
3691
- }
3692
- } else { //绑定在特性节点上
3693
- elem.textContent = val
3694
- }
3895
+ val = val == null ? "" : val //不在页面上显示undefined null
3896
+ if (elem.nodeType === 3) { //绑定在文本节点上
3897
+ try { //IE对游离于DOM树外的节点赋值会报错
3898
+ elem.data = val
3899
+ } catch (e) {}
3900
+ } else { //绑定在特性节点上
3901
+ elem.textContent = val
3902
+ }
3695
3903
  }
3696
-
3697
3904
  function parseDisplay(nodeName, val) {
3698
3905
  //用于取得此类标签的默认display值
3699
3906
  var key = "_" + nodeName
@@ -3713,42 +3920,33 @@ function parseDisplay(nodeName, val) {
3713
3920
 
3714
3921
  avalon.parseDisplay = parseDisplay
3715
3922
 
3716
- bindingHandlers.visible = function(data, vmodels) {
3717
- var elem = avalon(data.element)
3718
- var display = elem.css("display")
3719
- if (display === "none") {
3720
- var style = elem[0].style
3721
- var has = /visibility/i.test(style.cssText)
3722
- var visible = elem.css("visibility")
3723
- style.display = ""
3724
- style.visibility = "hidden"
3725
- display = elem.css("display")
3726
- if (display === "none") {
3727
- display = parseDisplay(elem[0].nodeName)
3728
- }
3729
- style.visibility = has ? visible : ""
3730
- }
3731
- data.display = display
3923
+ bindingHandlers.visible = function (data, vmodels) {
3732
3924
  parseExprProxy(data.value, vmodels, data)
3733
3925
  }
3734
3926
 
3735
- bindingExecutors.visible = function(val, elem, data) {
3736
- elem.style.display = val ? data.display : "none"
3927
+ bindingExecutors.visible = function (val, elem, binding) {
3928
+ if (val) {
3929
+ elem.style.display = binding.display || ""
3930
+ if (avalon(elem).css("display") === "none") {
3931
+ elem.style.display = binding.display = parseDisplay(elem.nodeName)
3932
+ }
3933
+ } else {
3934
+ elem.style.display = "none"
3935
+ }
3737
3936
  }
3738
-
3739
3937
  bindingHandlers.widget = function(data, vmodels) {
3740
3938
  var args = data.value.match(rword)
3741
3939
  var elem = data.element
3742
3940
  var widget = args[0]
3743
3941
  var id = args[1]
3744
- if (!id || id === "$") {//没有定义或为$时,取组件名+随机数
3942
+ if (!id || id === "$") { //没有定义或为$时,取组件名+随机数
3745
3943
  id = generateID(widget)
3746
3944
  }
3747
- var optName = args[2] || widget//没有定义,取组件名
3945
+ var optName = args[2] || widget //没有定义,取组件名
3748
3946
  var constructor = avalon.ui[widget]
3749
3947
  if (typeof constructor === "function") { //ms-widget="tabs,tabsAAA,optname"
3750
3948
  vmodels = elem.vmodels || vmodels
3751
- for (var i = 0, v; v = vmodels[i++]; ) {
3949
+ for (var i = 0, v; v = vmodels[i++];) {
3752
3950
  if (v.hasOwnProperty(optName) && typeof v[optName] === "object") {
3753
3951
  var vmOptions = v[optName]
3754
3952
  vmOptions = vmOptions.$model || vmOptions
@@ -3758,6 +3956,7 @@ bindingHandlers.widget = function(data, vmodels) {
3758
3956
  if (vmOptions) {
3759
3957
  var wid = vmOptions[widget + "Id"]
3760
3958
  if (typeof wid === "string") {
3959
+ log("warning!不再支持" + widget + "Id")
3761
3960
  id = wid
3762
3961
  }
3763
3962
  }
@@ -3773,27 +3972,26 @@ bindingHandlers.widget = function(data, vmodels) {
3773
3972
  if (vmodel.$id) {
3774
3973
  avalon.vmodels[id] = vmodel
3775
3974
  createSignalTower(elem, vmodel)
3776
- if (vmodel.hasOwnProperty("$init")) {
3975
+ try {
3777
3976
  vmodel.$init(function() {
3778
3977
  avalon.scan(elem, [vmodel].concat(vmodels))
3779
3978
  if (typeof options.onInit === "function") {
3780
3979
  options.onInit.call(elem, vmodel, options, vmodels)
3781
3980
  }
3782
3981
  })
3783
- }
3982
+ } catch (e) {}
3784
3983
  data.rollback = function() {
3785
3984
  try {
3786
- vmodel.widgetElement = null
3787
3985
  vmodel.$remove()
3788
- } catch (e) {
3789
- }
3986
+ vmodel.widgetElement = null // 放到$remove后边
3987
+ } catch (e) {}
3790
3988
  elem.msData = {}
3791
3989
  delete avalon.vmodels[vmodel.$id]
3792
3990
  }
3793
- addSubscribers(data, widgetList)
3991
+ injectDisposeQueue(data, widgetList)
3794
3992
  if (window.chrome) {
3795
3993
  elem.addEventListener("DOMNodeRemovedFromDocument", function() {
3796
- setTimeout(removeSubscribers)
3994
+ setTimeout(rejectDisposeQueue)
3797
3995
  })
3798
3996
  }
3799
3997
  } else {
@@ -3863,7 +4061,7 @@ var filters = avalon.filters = {
3863
4061
  truncate: function(str, length, truncation) {
3864
4062
  //length,新字符串长度,truncation,新字符串的结尾的字段,返回新字符串
3865
4063
  length = length || 30
3866
- truncation = truncation === void(0) ? "..." : truncation
4064
+ truncation = typeof truncation === "string" ? truncation : "..."
3867
4065
  return str.length > length ? str.slice(0, length - truncation.length) + truncation : String(str)
3868
4066
  },
3869
4067
  $filter: function(val) {
@@ -4400,7 +4598,7 @@ new function () {// jshint ignore:line
4400
4598
  pkg = typeof pkg === "string" ? {name: pkg} : pkg
4401
4599
  var name = pkg.name
4402
4600
  if (!uniq[name]) {
4403
- var url = pkg.location ? pkg.location : joinPath(name, pkg.main || "main")
4601
+ var url = joinPath(pkg.location || name, pkg.main || "main")
4404
4602
  url = url.replace(rjsext, "")
4405
4603
  ret.push(pkg)
4406
4604
  uniq[name] = pkg.location = url
@@ -4562,7 +4760,9 @@ new function () {// jshint ignore:line
4562
4760
  onLoad(xhr.responseText)
4563
4761
  }
4564
4762
  }
4565
- xhr.open("GET", url, true)
4763
+ var time = "_=" + (new Date() - 0)
4764
+ var _url = url.indexOf("?") === -1 ? url + "?" + time : url + "&" + time
4765
+ xhr.open("GET", _url, true)
4566
4766
  if ("withCredentials" in xhr) {//这是处理跨域
4567
4767
  xhr.withCredentials = true
4568
4768
  }
@@ -4633,7 +4833,7 @@ new function () {// jshint ignore:line
4633
4833
  try {
4634
4834
  var ret = factory.apply(window, array)
4635
4835
  } catch (e) {
4636
- log("执行[" + id + "]模块的factory抛错: " + e)
4836
+ log("执行[" + id + "]模块的factory抛错: ", e)
4637
4837
  }
4638
4838
  if (ret !== void 0) {
4639
4839
  module.exports = ret
@@ -4684,6 +4884,10 @@ new function () {// jshint ignore:line
4684
4884
  //5. 还原扩展名,query
4685
4885
  var urlNoQuery = url + ext
4686
4886
  url = urlNoQuery + this.query
4887
+ urlNoQuery = url.replace(rquery, function (a) {
4888
+ this.query = a
4889
+ return ""
4890
+ })
4687
4891
  //6. 处理urlArgs
4688
4892
  eachIndexArray(id, kernel.urlArgs, function (value) {
4689
4893
  url += (url.indexOf("?") === -1 ? "?" : "&") + value;
@@ -4835,39 +5039,24 @@ avalon.ready(function () {
4835
5039
  avalon.scan(DOC.body)
4836
5040
  })
4837
5041
  new function() {// jshint ignore:line
4838
- // http://www.cnblogs.com/yexiaochai/p/3462657.html
5042
+ var touchProxy = {}
5043
+ var IEtouch = navigator.pointerEnabled
5044
+ var IEMStouch = navigator.msPointerEnabled
4839
5045
  var ua = navigator.userAgent
4840
5046
  var isAndroid = ua.indexOf("Android") > 0
4841
- var isIOS = /iP(ad|hone|od)/.test(ua)
5047
+ var isGoingtoFixTouchEndEvent = isAndroid && ua.match(/Firefox|Opera/gi)
5048
+ //合成做成触屏事件所需要的各种原生事件
5049
+ var touchNames = ["touchstart", "touchmove", "touchend", "touchcancel"]
5050
+ var touchTimeout = null
5051
+ var longTapTimeout = null
5052
+ var dragDistance = 30
5053
+ var clickDuration = 750 //小于750ms是点击,长于它是长按或拖动
4842
5054
  var me = bindingHandlers.on
4843
- var touchProxy = {}
4844
5055
 
4845
- var IE11touch = navigator.pointerEnabled
4846
- var IE9_10touch = navigator.msPointerEnabled
4847
- var w3ctouch = (function() {
4848
- var supported = isIOS || false
4849
- //http://stackoverflow.com/questions/5713393/creating-and-firing-touch-events-on-a-touch-enabled-browser
4850
- try {
4851
- var div = document.createElement("div")
4852
- div.ontouchstart = function() {
4853
- supported = true
4854
- }
4855
- var e = document.createEvent("TouchEvent")
4856
- e.initUIEvent("touchstart", true, true)
4857
- div.dispatchEvent(e)
4858
- } catch (err) {
4859
- }
4860
- div = div.ontouchstart = null
4861
- return supported
4862
- })()
4863
- var touchSupported = !!(w3ctouch || IE11touch || IE9_10touch)
4864
- //合成做成触屏事件所需要的各种原生事件
4865
- var touchNames = ["mousedown", "mousemove", "mouseup", ""]
4866
- if (w3ctouch) {
4867
- touchNames = ["touchstart", "touchmove", "touchend", "touchcancel"]
4868
- } else if (IE11touch) {
5056
+ if (IEtouch) {
4869
5057
  touchNames = ["pointerdown", "pointermove", "pointerup", "pointercancel"]
4870
- } else if (IE9_10touch) {
5058
+ }
5059
+ if (IEMStouch) {
4871
5060
  touchNames = ["MSPointerDown", "MSPointerMove", "MSPointerUp", "MSPointerCancel"]
4872
5061
  }
4873
5062
  function isPrimaryTouch(event){
@@ -4878,140 +5067,132 @@ new function() {// jshint ignore:line
4878
5067
  return (e.type === 'pointer'+type || e.type.toLowerCase() === 'mspointer'+type)
4879
5068
  }
4880
5069
 
4881
- var touchTimeout, longTapTimeout
4882
5070
  //判定滑动方向
4883
5071
  function swipeDirection(x1, x2, y1, y2) {
4884
5072
  return Math.abs(x1 - x2) >=
4885
5073
  Math.abs(y1 - y2) ? (x1 - x2 > 0 ? "left" : "right") : (y1 - y2 > 0 ? "up" : "down")
4886
5074
  }
4887
- function getCoordinates(event) {
4888
- var touches = event.touches && event.touches.length ? event.touches : [event];
4889
- var e = event.changedTouches ? event.changedTouches[0] : touches[0]
4890
- return {
4891
- x: e.clientX,
4892
- y: e.clientY
4893
- }
4894
- }
5075
+
4895
5076
  function fireEvent(el, name, detail) {
4896
5077
  var event = document.createEvent("Events")
4897
5078
  event.initEvent(name, true, true)
4898
- event.fireByAvalon = true//签名,标记事件是由avalon触发
4899
- //event.isTrusted = false 设置这个opera会报错
4900
- if (detail)
5079
+ if (detail) {
4901
5080
  event.detail = detail
5081
+ }
4902
5082
  el.dispatchEvent(event)
4903
5083
  }
5084
+
4904
5085
  function onMouse(event) {
4905
- if (event.fireByAvalon) {
4906
- return true
4907
- }
4908
- if (event.stopImmediatePropagation) {
4909
- event.stopImmediatePropagation()
4910
- } else {
4911
- event.propagationStopped = true
5086
+ var target = event.target,
5087
+ element = touchProxy.element
5088
+
5089
+ if (element && element !== target) {
5090
+ var type = target.type || '',
5091
+ targetTag = target.tagName.toLowerCase(),
5092
+ elementTag = element.tagName.toLowerCase()
5093
+ // 通过手机的“前往”提交表单时不可禁止默认行为;通过label focus input时也不可以阻止默认行为
5094
+ if ((targetTag === 'input' && elementTag === "label") || type === 'submit') {
5095
+ return false
5096
+ }
5097
+ if (event.stopImmediatePropagation) {
5098
+ event.stopImmediatePropagation()
5099
+ } else {
5100
+ event.propagationStopped = true
5101
+ }
5102
+ event.stopPropagation()
5103
+ event.preventDefault()
4912
5104
  }
4913
- event.stopPropagation()
4914
- event.preventDefault()
4915
5105
  }
4916
5106
  function cancelLongTap() {
4917
5107
  if (longTapTimeout) clearTimeout(longTapTimeout)
4918
5108
  longTapTimeout = null
4919
5109
  }
4920
5110
  function touchstart(event) {
4921
- var _isPointerType = isPointerEventType(event, 'down'),
5111
+ var _isPointerType = isPointerEventType(event, "down"),
4922
5112
  firstTouch = _isPointerType ? event : event.touches[0],
4923
- element = 'tagName' in firstTouch.target ? firstTouch.target: firstTouch.target.parentNode,
5113
+ element = "tagName" in firstTouch.target ? firstTouch.target: firstTouch.target.parentNode,
4924
5114
  now = Date.now(),
4925
5115
  delta = now - (touchProxy.last || now)
4926
5116
 
4927
5117
  if (_isPointerType && !isPrimaryTouch(event)) return
4928
-
4929
- avalon.mix(touchProxy, getCoordinates(event))
4930
- touchProxy.mx = 0
4931
- touchProxy.my = 0
5118
+ if (touchProxy.x1 || touchProxy.y1) {
5119
+ touchProxy.x1 = undefined
5120
+ touchProxy.y1 = undefined
5121
+ }
4932
5122
  if (delta > 0 && delta <= 250) {
4933
5123
  touchProxy.isDoubleTap = true
4934
5124
  }
5125
+ touchProxy.x = firstTouch.pageX
5126
+ touchProxy.y = firstTouch.pageY
5127
+ touchProxy.mx = 0
5128
+ touchProxy.my = 0
4935
5129
  touchProxy.last = now
4936
5130
  touchProxy.element = element
4937
- /*
4938
- 当触发hold和longtap事件时会触发touchcancel事件,从而阻止touchend事件的触发,继而保证在同时绑定tap和hold(longtap)事件时只触发其中一个事件
4939
- */
4940
- avalon(element).addClass(fastclick.activeClass)
5131
+
4941
5132
  longTapTimeout = setTimeout(function() {
4942
5133
  longTapTimeout = null
4943
5134
  fireEvent(element, "hold")
4944
5135
  fireEvent(element, "longtap")
4945
5136
  touchProxy = {}
4946
- avalon(element).removeClass(fastclick.activeClass)
4947
- }, fastclick.clickDuration)
5137
+ }, clickDuration)
4948
5138
  return true
4949
5139
  }
4950
5140
  function touchmove(event) {
5141
+
4951
5142
  var _isPointerType = isPointerEventType(event, 'down'),
4952
- e = getCoordinates(event)
5143
+ firstTouch = _isPointerType ? event : event.touches[0],
5144
+ x = firstTouch.pageX,
5145
+ y = firstTouch.pageY
4953
5146
  if (_isPointerType && !isPrimaryTouch(event)) return
4954
-
5147
+ /*
5148
+ android下某些浏览器触发了touchmove事件的话touchend事件不触发,禁用touchmove可以解决此bug
5149
+ http://stackoverflow.com/questions/14486804/understanding-touch-events
5150
+ */
5151
+ if (isGoingtoFixTouchEndEvent && Math.abs(touchProxy.x - x) > 10) {
5152
+ event.preventDefault()
5153
+ }
4955
5154
  cancelLongTap()
4956
- touchProxy.mx += Math.abs(touchProxy.x - e.x)
4957
- touchProxy.my += Math.abs(touchProxy.y - e.y)
5155
+
5156
+ touchProxy.x1 = x // touchend事件没有pageX、pageY始终为0,且没有clientX和clientY事件
5157
+ touchProxy.y1 = y
5158
+ touchProxy.mx += Math.abs(touchProxy.x - x)
5159
+ touchProxy.my += Math.abs(touchProxy.y - y)
4958
5160
  }
4959
5161
  function touchend(event) {
4960
- var _isPointerType = isPointerEventType(event, 'down')
5162
+ var _isPointerType = isPointerEventType(event, 'down'),
4961
5163
  element = touchProxy.element
4962
5164
 
4963
5165
  if (_isPointerType && !isPrimaryTouch(event)) return
5166
+ if (!element) return // longtap|hold触发后touchProxy为{}
4964
5167
 
4965
- if (!element) {
4966
- return
4967
- }
4968
5168
  cancelLongTap()
4969
- var e = getCoordinates(event)
4970
- var totalX = Math.abs(touchProxy.x - e.x)
4971
- var totalY = Math.abs(touchProxy.y - e.y)
4972
- if (totalX > 30 || totalY > 30) {
5169
+ if ((touchProxy.x1 && Math.abs(touchProxy.x1 - touchProxy.x) > dragDistance) || (touchProxy.y1 && Math.abs(touchProxy.y1 - touchProxy.y) > dragDistance)) {
4973
5170
  //如果用户滑动的距离有点大,就认为是swipe事件
4974
- var direction = swipeDirection(touchProxy.x, e.x, touchProxy.y, e.y)
5171
+ var direction = swipeDirection(touchProxy.x, touchProxy.x1, touchProxy.y, touchProxy.y1)
4975
5172
  var details = {
4976
5173
  direction: direction
4977
5174
  }
4978
5175
  fireEvent(element, "swipe", details)
4979
5176
  fireEvent(element, "swipe" + direction, details)
4980
- avalon(element).removeClass(fastclick.activeClass)
4981
5177
  touchProxy = {}
4982
5178
  } else {
4983
- if (fastclick.canClick(element) && touchProxy.mx < fastclick.dragDistance && touchProxy.my < fastclick.dragDistance) {
4984
- // 失去焦点的处理
4985
- if (document.activeElement && document.activeElement !== element) {
4986
- document.activeElement.blur()
4987
- }
4988
- //如果此元素不为表单元素,或者它没有disabled
4989
- var forElement
4990
- if (element.tagName.toLowerCase() === "label") {
4991
- forElement = element.htmlFor ? document.getElementById(element.htmlFor) : null
4992
- }
4993
- if (forElement) {
4994
- fastclick.focus(forElement)
4995
- } else {
4996
- fastclick.focus(element)
4997
- }
4998
- event.preventDefault()
5179
+ if (touchProxy.mx < dragDistance && touchProxy.my < dragDistance) {
4999
5180
  fireEvent(element, 'tap')
5000
- avalon.fastclick.fireEvent(element, "click", event)
5001
- avalon(element).removeClass(fastclick.activeClass)
5002
5181
  if (touchProxy.isDoubleTap) {
5003
5182
  fireEvent(element, "doubletap")
5004
- avalon.fastclick.fireEvent(element, "dblclick", event)
5005
5183
  touchProxy = {}
5006
- avalon(element).removeClass(fastclick.activeClass)
5184
+ touchProxy.element = element
5007
5185
  } else {
5008
5186
  touchTimeout = setTimeout(function() {
5009
5187
  clearTimeout(touchTimeout)
5010
5188
  touchTimeout = null
5011
- touchProxy = {}
5012
- avalon(element).removeClass(fastclick.activeClass)
5189
+ if (touchProxy.element) fireEvent(touchProxy.element, "singletap")
5190
+ touchProxy = {};
5191
+ touchProxy.element = element
5013
5192
  }, 250)
5014
5193
  }
5194
+ } else {
5195
+ touchProxy = {}
5015
5196
  }
5016
5197
  }
5017
5198
  }
@@ -5028,71 +5209,7 @@ new function() {// jshint ignore:line
5028
5209
  touchProxy = {}
5029
5210
  })
5030
5211
  }
5031
- //fastclick只要是处理移动端点击存在300ms延迟的问题
5032
- //这是苹果乱搞异致的,他们想在小屏幕设备上通过快速点击两次,将放大了的网页缩放至原始比例。
5033
- var fastclick = avalon.fastclick = {
5034
- activeClass: "ms-click-active",
5035
- clickDuration: 750, //小于750ms是点击,长于它是长按或拖动
5036
- dragDistance: 30, //最大移动的距离
5037
- fireEvent: function(element, type, event) {
5038
- var clickEvent = document.createEvent("MouseEvents")
5039
- clickEvent.initMouseEvent(type, true, true, window, 1, event.screenX, event.screenY,
5040
- event.clientX, event.clientY, false, false, false, false, 0, null)
5041
- Object.defineProperty(clickEvent, "fireByAvalon", {
5042
- value: true
5043
- })
5044
- element.dispatchEvent(clickEvent)
5045
- },
5046
- focus: function(target) {
5047
- if (this.canFocus(target)) {
5048
- //https://github.com/RubyLouvre/avalon/issues/254
5049
- var value = target.value
5050
- target.value = value
5051
- if (isIOS && target.setSelectionRange && target.type.indexOf("date") !== 0 && target.type !== 'time') {
5052
- // iOS 7, date datetime等控件直接对selectionStart,selectionEnd赋值会抛错
5053
- var n = value.length
5054
- target.setSelectionRange(n, n)
5055
- } else {
5056
- target.focus()
5057
- }
5058
- }
5059
- },
5060
- canClick: function(target) {
5061
- switch (target.nodeName.toLowerCase()) {
5062
- case "textarea":
5063
- case "select":
5064
- case "input":
5065
- return !target.disabled
5066
- default:
5067
- return true
5068
- }
5069
- },
5070
- canFocus: function(target) {
5071
- switch (target.nodeName.toLowerCase()) {
5072
- case "textarea":
5073
- return true;
5074
- case "select":
5075
- return !isAndroid
5076
- case "input":
5077
- switch (target.type) {
5078
- case "button":
5079
- case "checkbox":
5080
- case "file":
5081
- case "image":
5082
- case "radio":
5083
- case "submit":
5084
- return false
5085
- }
5086
- // No point in attempting to focus disabled inputs
5087
- return !target.disabled && !target.readOnly
5088
- default:
5089
- return false
5090
- }
5091
- }
5092
- };
5093
-
5094
-
5095
- ["swipe", "swipeleft", "swiperight", "swipeup", "swipedown", "doubletap", "tap", "dblclick", "longtap", "hold"].forEach(function(method) {
5212
+ ["swipe", "swipeleft", "swiperight", "swipeup", "swipedown", "doubletap", "tap", "singletap", "dblclick", "longtap", "hold"].forEach(function(method) {
5096
5213
  me[method + "Hook"] = me["clickHook"]
5097
5214
  })
5098
5215
 
@@ -5129,6 +5246,7 @@ new function() {// jshint ignore:line
5129
5246
  if (noGlobal === void 0) {
5130
5247
  window.avalon = avalon
5131
5248
  }
5249
+
5132
5250
  return avalon
5133
5251
 
5134
5252
  }));