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.
- checksums.yaml +13 -5
- data/lib/avalon-rails/version.rb +1 -1
- data/vendor/assets/javascripts/avalon.js +2066 -1877
- data/vendor/assets/javascripts/avalon.min.js +3 -3
- data/vendor/assets/javascripts/avalon.mobile.js +1653 -1535
- data/vendor/assets/javascripts/avalon.mobile.min.js +3 -3
- data/vendor/assets/javascripts/avalon.mobile.old.js +2030 -1928
- data/vendor/assets/javascripts/avalon.mobile.shim.js +1660 -1548
- data/vendor/assets/javascripts/avalon.modern.js +1481 -1276
- data/vendor/assets/javascripts/avalon.modern.min.js +2 -2
- data/vendor/assets/javascripts/avalon.modern.shim.js +1488 -1289
- data/vendor/assets/javascripts/avalon.shim.js +1863 -1684
- metadata +7 -7
@@ -1,2 +1,2 @@
|
|
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(){avalon.config.debug&&console.log.apply(console,arguments)}function r(){return Object.create(null)}function i(){}function o(e,t){"string"==typeof e&&(e=e.match(bt)||[]);for(var n={},a=void 0!==t?t:1,r=0,i=e.length;i>r;r++)n[e[r]]=a;return n}function l(){if(e.VBArray){var t=document.documentMode;return t?t:e.XMLHttpRequest?7:6}return 0}function s(e){if(e&&"object"==typeof e){var t=e.length,n=Tt.call(e);if(/(Array|List|Collection|Map|Arguments)\]$/.test(n))return!0;if("[object Object]"===n&&t===t>>>0)return!0}return!1}function c(e,t){if(e&&e.childNodes)for(var n,a=e.childNodes,r=0;n=a[r++];)if(n.tagName){var i=ft.createElementNS(Ft,n.tagName.toLowerCase());kt.forEach.call(n.attributes,function(e){i.setAttribute(e.name,e.value)}),c(n,i),t.appendChild(i)}}function u(e){for(var t in e)if(At.call(e,t)){var n=e[t];"function"==typeof u.plugins[t]?u.plugins[t](n):"object"==typeof u[t]?avalon.mix(u[t],n):u[t]=n}return this}function f(e){return(e+"").replace(Yt,"\\$&")}function p(e,t,n){if(Pt(t)||t&&t.nodeType)return!1;if(-1!==n.indexOf(e))return!1;if(-1!==Kt.indexOf(e))return!1;var a=n.$special;return e&&"$"===e.charAt(0)&&!a[e]?!1:!0}function d(e,t,n,a){switch(e.type){case 0:var r=e.get,i=e.set;if(Pt(i)){var o=a.$events,l=o[t];o[t]=[],i.call(a,n),o[t]=l}return r.call(a);case 1:return n;case 2:if(n!==a.$model[t]){var s=e.svmodel=m(a,t,n,e.valueType);n=s.$model;var c=en[s.$id];c&&c()}return n}}function v(e,t,n){if(Array.isArray(e)){var a=e.concat();e.length=0;var o=g(e);return o.pushArray(a),o}if(!e||e.nodeType>0||e.$id&&e.$events)return e;Array.isArray(e.$skipArray)||(e.$skipArray=[]),e.$skipArray.$special=t||r();var l={};n=n||{};var s=r(),c=r(),u=[];for(var f in e)!function(t,a){if(n[t]=a,p(t,a,e.$skipArray)){s[t]=[];var r=avalon.type(a),o=function(e){var t=o._name,n=this,a=n.$model,r=a[t],i=n.$events;return arguments.length?void(yt||(1===o.type||(e=d(o,t,e,n),o.type))&&(tn(r,e)||(a[t]=e,k(i[t]),h(n,t,e,r)))):0===o.type?(e=o.get.call(n),r!==e&&(a[t]=e,h(n,t,e,r)),e):(x(i[t]),o.svmodel||r)};"object"===r&&Pt(a.get)&&Object.keys(a).length<=2?(o.set=a.set,o.get=a.get,o.type=0,u.push(function(){var e={evaluator:function(){e.type=Math.random(),e.element=null,n[t]=o.get.call(l)},element:pt,type:Math.random(),handler:i,args:[]};Mt[ut]=e,o.call(l),delete Mt[ut]})):$t.test(r)?(o.type=2,o.valueType=r,u.push(function(){var e=v(a,0,n[t]);o.svmodel=e,e.$events[ht]=s[t]})):o.type=1,o._name=t,c[t]=o}}(f,e[f]);Kt.forEach(function(t){delete e[t],delete n[t]}),l=Object.defineProperties(l,nn(c),e);for(var m in e)c[m]||(l[m]=e[m]);l.$id=St(),l.$model=n,l.$events=s;for(f in Jt)l[f]=Jt[f];return Object.defineProperty(l,"hasOwnProperty",{value:function(e){return e in this.$model},writable:!1,enumerable:!1,configurable:!0}),u.forEach(function(e){e()}),l}function h(e,t,n,a){e.$events&&Jt.$fire.call(e,t,n,a)}function m(e,t,n,a){var r=e[t];if("array"===a)return Array.isArray(n)&&r!==n?(r._.$unwatch(),r.clear(),r._.$watch(),r.pushArray(n.concat()),r):r;var i=e.$events[t],o=r.$events.$withProxyPool;o&&(lt(o,"with"),r.$events.$withProxyPool=null);var l=v(n);return l.$events[ht]=i,en[l.$id]=function(e){for(;e=i.shift();)!function(e){avalon.nextTick(function(){var t=e.type;t&&Rt[t]&&(e.rollback&&e.rollback(),Rt[t](e,e.vmodels))})}(e);delete en[l.$id]},l}function g(e){var t=[];t.$id=St(),t.$model=e,t.$events={},t.$events[ht]=[],t._=v({length:e.length}),t._.$watch("length",function(e,n){t.$fire("length",e,n)});for(var n in Jt)t[n]=Jt[n];return avalon.mix(t,rn),t}function y(e,t,n,a,r,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 $t.test(avalon.type(e))?e.$id?e:v(e,0,e):e});an.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)}r&&(e=r,t=i,n=o,s=2,r=0)}return this._fire("index",a),this.length!==l&&(this._.length=this.length),u}function b(e,t){for(var n={},a=0,r=t.length;r>a;a++){n[a]=e[a];var i=t[a];i in n?(e[a]=n[i],delete n[i]):e[a]=e[i]}}function $(e){Mt[ut]=e,avalon.openComputedCollect=!0;var t=e.evaluator;if(t)try{var n=on.test(e.type)?e:t.apply(0,e.args);e.handler(n,e.element,e)}catch(a){delete e.evaluator;var r=e.element;if(3===r.nodeType){var i=r.parentNode;u.commentInterpolate?i.replaceChild(ft.createComment(e.value),r):r.data=Vt+e.value+qt}}avalon.openComputedCollect=!1,delete Mt[ut]}function x(e){var t=Mt[ut];e&&t&&avalon.Array.ensure(e,t)&&t.element&&w(t,e)}function w(e,t){e.$uuid=e.$uuid||St(),t.$uuid=t.$uuid||St();var n={data:e,list:t,$$uuid:e.$uuid+t.$uuid};ln[n.$$uuid]||(ln[n.$$uuid]=1,ln.push(n))}function C(e){e.element=null,e.rollback&&e.rollback();for(var t in e)e[t]=null}function A(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:!Nt.contains(e):!avalon.contains(Nt,e)}function T(){for(var e,t=ln.length,n=t,a=0,r=[],i={},o={};e=ln[--t];){var l=e.data,s=l.type;i[s]?i[s]++:(i[s]=1,r.push(s))}var c=!1;if(r.forEach(function(e){cn[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]&&A(l.element)&&(a++,ln.splice(t,1),delete ln[e.$$uuid],avalon.Array.remove(e.list,l),C(l),e.data=e.list=null);cn=i,sn=new Date}function k(e){if(e&&e.length){new Date-sn>444&&"object"==typeof e[0]&&T();for(var t,n=Et.call(arguments,1),a=e.length;t=e[--a];){var r=t.element;if(r&&r.parentNode)if(t.$repeat)t.handler.apply(t,n);else if("on"!==t.type){var o=t.evaluator||i;t.handler(o.apply(0,t.args||[]),r,t)}}}}function E(e,t,n){var a=setTimeout(function(){var r=e.innerHTML;clearTimeout(a),r===n?t():E(e,t,r)})}function M(e,t){var n=e.getAttribute("avalonctrl")||t.$id;e.setAttribute("avalonctrl",n),t.$events.expr=e.tagName+'[avalonctrl="'+n+'"]'}function O(e,t){for(var n,a=0;n=e[a++];)n.vmodels=t,Rt[n.type](n,t),n.evaluator&&n.element&&1===n.element.nodeType&&n.element.removeAttribute(n.name);e.length=0}function N(e,t){return e.priority-t.priority}function L(e,t){for(var a,i,o=e.hasAttributes()?avalon.slice(e.attributes):[],l=[],s=r(),c=0;i=o[c++];)if(i.specified&&(a=i.name.match(bn))){var u=a[1],f=a[2]||"",p=i.value,d=i.name;if(s[d]=p,xn[u]?(f=u,u="on"):wn[u]&&(n("warning!请改用ms-attr-"+u+"代替ms-"+u+"!"),"enabled"===u&&(n("warning!ms-enabled或ms-attr-enabled已经被废弃"),u="disabled",p="!("+p+")"),f=u,u="attr",e.removeAttribute(d),d="ms-attr-"+f,e.setAttribute(d,p),a=[d],s[d]=p),"function"==typeof Rt[u]){var v={type:u,param:f,element:e,name:a[0],value:p,priority:u in $n?$n[u]:10*u.charCodeAt(0)+(Number(f)||0)};if("html"===u||"text"===u){var h=P(p);avalon.mix(v,h),v.filters=v.filters.replace(Tn,function(){return v.type="html",v.group=1,""})}"ms-if-loop"===d&&(v.priority+=100),t.length&&(l.push(v),"widget"===u&&(e.msData=e.msData||s))}}var m=e.type;m&&s["ms-duplex"]&&(s["ms-attr-checked"]&&/radio|checkbox/.test(m)&&n("warning!"+m+"控件不能同时定义ms-attr-checked与ms-duplex"),s["ms-attr-value"]&&/text|password/.test(m)&&n("warning!"+m+"控件不能同时定义ms-attr-value与ms-duplex")),l.sort(N);var g=!0;for(c=0;v=l[c];c++){if(u=v.type,Cn.test(u))return O(l.slice(0,c+1),t);g&&(g=!An.test(u))}O(l,t),g&&!mn[e.tagName]&&Xt.test(e.innerHTML+e.textContent)&&(yn&&yn(e),j(e,t))}function j(e,t){for(var n=e.firstChild;n;){var a=n.nextSibling;S(n,n.nodeType,t),n=a}}function H(e,t){for(var n,a=0;n=e[a++];)S(n,n.nodeType,t)}function S(e,t,n){1===t?D(e,n):3===t&&zt.test(e.data)?I(e,n):u.commentInterpolate&&8===t&&!zt.test(e.nodeValue)&&I(e,n)}function D(e,t,n){var a=e.getAttribute("ms-skip"),r=e.getAttributeNode("ms-important"),i=e.getAttributeNode("ms-controller");if("string"!=typeof a){if(n=r||i){var o=avalon.vmodels[n.value];if(!o)return;t=n===r?[o]:[o].concat(t),e.removeAttribute(n.name),e.classList.remove(n.name),M(e,o)}L(e,t)}}function P(e){if(e.indexOf("|")>0){var t=e.replace(rstringLiteral,function(e){return Array(e.length+1).join("1")}),n=t.replace(kn,"ᄢ㍄").indexOf("|");if(n>-1)return{filters:e.slice(n),value:e.slice(0,n),expr:!0}}return{value:e,filters:"",expr:!0}}function R(e){for(var t,n,a=[],r=0;;){if(n=e.indexOf(Vt,r),-1===n)break;if(t=e.slice(r,n),t&&a.push({value:t,filters:"",expr:!1}),r=n+Vt.length,n=e.indexOf(qt,r),-1===n)break;t=e.slice(r,n),t&&a.push(P(t)),r=n+qt.length}return t=e.slice(r),t&&a.push({value:t,expr:!1,filters:""}),a}function I(e,t){var n=[];if(8===e.nodeType)var a=P(e.nodeValue),r=[a];else r=R(e.data);if(r.length){for(var i=0;a=r[i++];){var o=ft.createTextNode(a.value);a.expr&&(a.type="text",a.element=o,a.filters=a.filters.replace(Tn,function(){return a.type="html",a.group=1,""}),n.push(a)),Lt.appendChild(o)}e.parentNode.replaceChild(Lt,e),n.length&&O(n,t)}}function _(e){return e.replace(/([a-z\d])([A-Z]+)/g,"$1-$2").toLowerCase()}function F(e){return e.indexOf("-")<0&&e.indexOf("_")<0?e:e.replace(/[-_][^-_]/g,function(e){return e.charAt(1).toUpperCase()})}function B(e){try{if("object"==typeof e)return e;e="true"===e?!0:"false"===e?!1:"null"===e?null:+e+""===e?+e:En.test(e)?JSON.parse(e):e}catch(t){}return e}function U(e){return e.window&&e.document?e:9===e.nodeType?e.defaultView:!1}function V(e,t){if(e.offsetWidth<=0){var n=getComputedStyle(e,null);if(jn.test(n.display)){var a={node:e};for(var r in Ln)a[r]=n[r],e.style[r]=Ln[r];t.push(a)}var i=e.parentNode;i&&1===i.nodeType&&V(i,t)}}function q(e){var t=e.tagName.toLowerCase();return"input"===t&&/checkbox|radio/.test(e.type)?"checked":t}function z(e,t,n,a){for(var r,i=[],o=" = "+n+".",l=e.length;r=e[--l];)t.hasOwnProperty(r)&&(i.push(r+o+r),a.vars.push(r),"duplex"===a.type&&(e.get=n+"."+r),e.splice(l,1));return i}function W(e){for(var t=[],n={},a=0;a<e.length;a++){var r=e[a],i=r&&"string"==typeof r.$id?r.$id:r;n[i]||(n[i]=t.push(r))}return t}function X(e,t){return t=t.replace(Wn,"").replace(Xn,function(){return"],|"}).replace(Yn,function(e,t){return"["+Sn(t)}).replace(Gn,function(){return'"],["'}).replace(Zn,function(){return'",'})+"]","return avalon.filters.$filter("+e+", "+t+")"}function Y(e,t,a){var r=a.type,o=a.filters||"",l=t.map(function(e){return String(e.$id).replace(zn,"$1")})+e+r+o,s=Un(e).concat(),c=[],u=[],f=[],p="";t=W(t),a.vars=[];for(var d=0,v=t.length;v>d;d++)if(s.length){var h="vm"+ut+"_"+d;u.push(h),f.push(t[d]),c.push.apply(c,z(s,t[d],h,a))}if(c.length||"duplex"!==r){"duplex"!==r&&(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 a=n.charAt(t.length),r=Dt?e.slice(arguments[1]+n.length):RegExp.rightContext,i=/^\s*\(/.test(r);if("."===a||"["===a||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=Vn.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"+ut+" = "+e+";\r\n",e+=X("ret"+ut,o)}else{if("duplex"===r){var g="'use strict';\nreturn function(vvv){\n "+p+";\n if(!arguments.length){\n return "+e+"\n }\n "+(qn.test(e)?e:s.get)+"= vvv;\n} ";try{m=Function.apply(i,u.concat(g)),a.evaluator=Vn.put(l,m)}catch(y){n("debug: parse error,"+y.message)}return}if("on"===r){-1===e.indexOf("(")?e+=".call(this, $event)":e=e.replace("(",".call(this,"),u.push("$event"),e="\nreturn "+e+";";var b=e.lastIndexOf("\nreturn"),$=e.slice(0,b),x=e.slice(b);e=$+"\n"+x}else e="\nreturn "+e+";"}try{m=Function.apply(i,u.concat("'use strict';\n"+p+e)),a.evaluator=Vn.put(l,m)}catch(y){n("debug: parse error,"+y.message)}finally{s=c=u=null}}}function G(e,t,n,a,r){Array.isArray(a)&&(e=a.map(function(e){return e.expr?"("+e.value+")":Sn(e.value)}).join(" + ")),Y(e,t,n),n.evaluator&&!r&&(n.handler=It[n.handlerName||n.type],$(n))}function Z(e,t,n){var a=e.templateCache&&e.templateCache[t];if(a){for(var r,i=ft.createDocumentFragment();r=a.firstChild;)i.appendChild(r);return i}return avalon.parseHTML(n)}function J(e){return null==e?"":e}function Q(e,t,n){return t.param.replace(/\w+/g,function(a){var r=avalon.duplexHooks[a];r&&"function"==typeof r[n]&&(e=r[n](e,t))}),e}function K(){for(var e=la.length-1;e>=0;e--){var t=la[e];t()===!1&&la.splice(e,1)}la.length||clearInterval(oa)}function et(e,t,n,a){var r=e.template.cloneNode(!0),i=avalon.slice(r.childNodes);n.$stamp&&r.insertBefore(n.$stamp,r.firstChild),t.appendChild(r);var o=[n].concat(e.vmodels),l={nodes:i,vmodels:o};a.push(l)}function tt(e,t){var n=e.proxies[t];return n?n.$stamp:e.element}function nt(e,t,n){for(;;){var a=t.previousSibling;if(!a)break;if(a.parentNode.removeChild(a),n&&n.call(a),a===e)break}}function at(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},a=v(t,n),r=a.$events;return r[e]=r.$first=r.$last=r.$index,a.$id=St("$proxy$each"),a}function rt(e,t){for(var n,a=t.param||"el",r=0,i=fa.length;i>r;r++){var o=fa[r];o&&o.hasOwnProperty(a)&&(n=o,fa.splice(r,1))}n||(n=at(a));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 it(){var e=v({$key:"",$outer:{},$host:{},$val:{get:function(){return this.$host[this.$key]},set:function(e){this.$host[this.$key]=e}}},{$val:1});return e.$id=St("$proxy$with"),e}function ot(e,t){var n=pa.pop();n||(n=it());var a=t.$repeat;return n.$key=e,n.$host=a,n.$outer=t.$outer,a.$events?n.$events.$val=a.$events[e]:n.$events={},n}function lt(e,t){var n="each"===t?fa:pa;avalon.each(e,function(e,t){if(t.$events){for(var a in t.$events)Array.isArray(t.$events[a])&&(t.$events[a].forEach(function(e){"object"==typeof e&&C(e)}),t.$events[a].length=0);t.$host=t.$outer={},n.unshift(t)>u.maxRepeatSize&&n.pop()}}),"each"===t&&(e.length=0)}function st(e,t){var n="_"+e;if(!st[n]){var a=ft.createElement(e);Nt.appendChild(a),t=Ot?getComputedStyle(a,null).display:a.currentStyle.display,Nt.removeChild(a),st[n]=t}return st[n]}function ct(e,t,n,a){e=(e+"").replace(/[^0-9+\-Ee.]/g,"");var r=isFinite(+e)?+e:0,i=isFinite(+t)?Math.abs(t):3,o=a||",",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(r,i):""+Math.round(r)).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)}var ut=Date.now(),ft=e.document,pt=ft.head;pt.insertAdjacentHTML("afterBegin",'<avalon ms-skip class="avalonHide"><style id="avalonStyle">.avalonHide{ display: none!important }</style></avalon>');var dt,vt=pt.firstChild,ht="$"+ut,mt=e.require,gt=e.define,yt=!1,bt=/[^, ]+/g,$t=/^(?:object|array)$/,xt=/^\[object SVG\w*Element\]$/,wt=/^\[object (?:Window|DOMWindow|global)\]$/,Ct=Object.prototype,At=Ct.hasOwnProperty,Tt=Ct.toString,kt=Array.prototype,Et=kt.slice,Mt={},Ot=e.dispatchEvent,Nt=ft.documentElement,Lt=ft.createDocumentFragment(),jt=ft.createElement("div"),Ht={};"Boolean Number String Function Array Date RegExp Object Error".replace(bt,function(e){Ht["[object "+e+"]"]=e.toLowerCase()});var St=function(e){return e=e||"avalon",(e+Math.random()+Math.random()).replace(/0\./g,"")},Dt=l();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,a=e.MutationObserver,r=Ot&&e.postMessage;if(n)return n.bind(e);var i=[];if(a){var o=document.createTextNode("avalon");return new a(t).observe(o,{characterData:!0}),function(e){i.push(e),o.data=Math.random()}}return r?(e.addEventListener("message",function(n){var a=n.source;a!==e&&null!==a||"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?Ht[Tt.call(e)]||"object":typeof e};var Pt=function(e){return"[object Function]"===Tt.call(e)};avalon.isFunction=Pt,avalon.isWindow=function(e){return wt.test(Tt.call(e))},avalon.isPlainObject=function(e){return"[object Object]"===Tt.call(e)&&Object.getPrototypeOf(e)===Ct},avalon.mix=avalon.fn.mix=function(){var e,t,n,a,r,i,o=arguments[0]||{},l=1,s=arguments.length,c=!1;for("boolean"==typeof o&&(c=o,o=arguments[1]||{},l++),"object"==typeof o||Pt(o)||(o={}),l===s&&(o=this,l--);s>l;l++)if(null!=(e=arguments[l]))for(t in e)n=o[t],a=e[t],o!==a&&(c&&a&&(avalon.isPlainObject(a)||(r=Array.isArray(a)))?(r?(r=!1,i=n&&Array.isArray(n)?n:[]):i=n&&avalon.isPlainObject(n)?n:{},o[t]=avalon.mix(c,i,a)):void 0!==a&&(o[t]=a));return o},avalon.mix({rword:bt,subscribers:ht,version:1.41,ui:{},log:n,slice:function(e,t,n){return Et.call(e,t,n)},noop:i,error:function(e,t){throw new(t||Error)(e)},oneObject:o,range:function(e,t,n){n||(n=1),null==t&&(t=e||0,e=0);for(var a=-1,r=Math.max(0,Math.ceil((t-e)/n)),i=new Array(r);++a<r;)i[a]=e,e+=n;return i},eventHooks:{},bind:function(e,t,n,a){var r=avalon.eventHooks,i=r[t];return"object"==typeof i&&(t=i.type,i.deel&&(n=i.deel(e,t,n,a))),n.unbind||e.addEventListener(t,n,!!a),n},unbind:function(e,t,n,a){var r=avalon.eventHooks,o=r[t],l=n||i;"object"==typeof o&&(t=o.type,o.deel&&(n=o.deel(e,t,n,!1))),e.removeEventListener(t,l,!!a)},css:function(e,t,n){e instanceof avalon&&(e=e[0]);var a,r=/[_-]/.test(t)?F(t):t;if(t=avalon.cssName(r)||r,void 0===n||"boolean"==typeof n){a=Mn[r+":get"]||Mn["@:get"],"background"===t&&(t="backgroundColor");var i=a(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[r]&&(n+="px"),a=Mn[r+":set"]||Mn["@:set"],a(e,t,n)}},each:function(e,t){if(e){var n=0;if(s(e))for(var a=e.length;a>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(),a={};for(var r in n)0===r.indexOf(t)&&(a[r.replace(t,"").replace(/\w/,function(e){return e.toLowerCase()})]=n[r]);return a},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 Rt=avalon.bindingHandlers={},It=avalon.bindingExecutors={},_t=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(ft.contains||(Node.prototype.contains=function(e){return!!(16&this.compareDocumentPosition(e))}),avalon.contains=function(e,t){try{for(;t=t.parentNode;)if(t===e)return!0;return!1}catch(n){return!1}},e.SVGElement){var Ft="http://www.w3.org/2000/svg",Bt=ft.createElementNS(Ft,"svg");Bt.innerHTML='<circle cx="50" cy="50" r="40" fill="red" />',xt.test(Bt.firstChild)||Object.defineProperties(SVGElement.prototype,{outerHTML:{enumerable:!0,configurable:!0,get:function(){return(new XMLSerializer).serializeToString(this)},set:function(e){var t=this.tagName.toLowerCase(),n=this.parentNode,a=avalon.parseHTML(e);if("svg"===t)n.insertBefore(a,this);else{var r=ft.createDocumentFragment();c(a,r),n.insertBefore(r,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);c(t,this)}}}})}var Ut=avalon.eventHooks;"onmouseenter"in Nt||avalon.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){Ut[e]={type:t,deel:function(t,n,a){return function(n){var r=n.relatedTarget;return r&&(r===t||16&t.compareDocumentPosition(r))?void 0:(delete n.type,n.type=e,a.call(t,n))}}}}),avalon.each({AnimationEvent:"animationend",WebKitAnimationEvent:"webkitAnimationEnd"},function(t,n){e[t]&&!Ut.animationend&&(Ut.animationend={type:n})}),void 0===ft.onmousewheel&&(Ut.mousewheel={type:"wheel",deel:function(e,t,n){return function(t){t.wheelDeltaY=t.wheelDelta=t.deltaY>0?-120:120,t.wheelDeltaX=0,Object.defineProperty(t,"type",{value:"mousewheel"}),n.call(e,t)}}});var Vt,qt,zt,Wt,Xt,Yt=/[-.*+?^${}()|[\]\/\\]/g,Gt={loader:function(t){var n=dt&&t;e.require=n?dt:mt,e.define=n?dt.define:gt},interpolate:function(e){if(Vt=e[0],qt=e[1],Vt===qt)throw new SyntaxError("openTag!==closeTag");if(e+""=="<!--,-->")u.commentInterpolate=!0;else{var t=Vt+"test"+qt;if(jt.innerHTML=t,jt.innerHTML!==t&&jt.innerHTML.indexOf("<")>-1)throw new SyntaxError("此定界符不合法");jt.innerHTML=""}var n=f(Vt),a=f(qt);zt=new RegExp(n+"(.*?)"+a),Wt=new RegExp(n+"(.*?)"+a,"g"),Xt=new RegExp(n+".*?"+a+"|\\sms-")}};u.debug=!0,u.plugins=Gt,u.plugins.interpolate(["{{","}}"]),u.paths={},u.shim={},u.maxRepeatSize=100,avalon.config=u;var Zt=function(e){return ft.querySelectorAll(e)},Jt={$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 a=this.$events[e]||[],r=a.length;~--r<0;)if(a[r]===t)return a.splice(r,1);return this},$fire:function(e){var t,n,a,r;/^(\w+)!(\S+)$/.test(e)&&(t=RegExp.$1,e=RegExp.$2);var i=this.$events;if(i){var o=Et.call(arguments,1),l=[e].concat(o);if("all"===t)for(n in avalon.vmodels)a=avalon.vmodels[n],a!==this&&a.$fire.apply(a,l);else if("up"===t||"down"===t){var s=i.expr?Zt(i.expr):[];if(0===s.length)return;for(n in avalon.vmodels)if(a=avalon.vmodels[n],a!==this&&a.$events.expr){var c=Zt(a.$events.expr);if(0===c.length)continue;Array.prototype.forEach.call(c,function(e){Array.prototype.forEach.call(s,function(n){var r="down"===t?n.contains(e):e.contains(n);r&&(e._avalon=a)})})}var u=ft.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;(r=f[n++])&&r.$fire.apply(r,l)!==!1;);}else{var p=i[e]||[],d=i.$all||[];for(n=0;r=p[n++];)Pt(r)&&r.apply(this,o);for(n=0;r=d[n++];)Pt(r)&&r.apply(this,arguments)}}}},Qt=avalon.vmodels=r();avalon.define=function(e,t){var a=e.$id||e;if(a||n("warning: vm必须指定$id"),Qt[a]&&n("warning: "+a+" 已经存在于avalon.vmodels中"),"object"==typeof e)var r=v(e);else{var o={$watch:i};t(o),r=v(o),yt=!0,t(r),yt=!1}return r.$id=a,Qt[a]=r};var Kt=String("$id,$watch,$unwatch,$fire,$events,$model,$skipArray").match(bt),en=r(),tn=Object.is||function(e,t){return 0===e&&0===t?1/e===1/t:e!==e?t!==t:e===t},nn=function(e){var t=r();for(var n in e)t[n]={get:e[n],set:e[n],enumerable:!0,configurable:!0};return t},an=kt.splice,rn={_splice:an,_fire:function(e,t,n){k(this.$events[ht],e,t,n)},size:function(){return this._.length},pushArray:function(e){var t=e.length,n=this.length;return t&&(kt.push.apply(this.$model,e),y.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&&(kt.unshift.apply(this.$model,arguments),y.call(this,"add",0,e,0)),e+t},shift:function(){if(this.length){var e=this.$model.shift();return y.call(this,"del",0,1,0),e}},pop:function(){var e=this.length;if(e){var t=this.$model.pop();return y.call(this,"del",e-1,1,Math.max(0,e-2)),t}},splice:function(e){var t,n=arguments.length,a=[],r=an.apply(this.$model,arguments);return r.length&&(a.push("del",e,r.length,0),t=!0),n>2&&(t?a.splice(3,1,0,"add",e,n-2):a.push("add",e,n-2,0),t=!0),t?y.apply(this,a):[]},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),y.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 a=this[e];if("object"===n)for(var r in t)a.hasOwnProperty(r)&&(a[r]=t[r]);else"array"===n?a.clear().push.apply(a,t):a!==t&&(this[e]=t,this.$model[e]=t,this._fire("set",e,t))}return this}};"sort,reverse".replace(bt,function(e){rn[e]=function(){var t,n=this.$model,a=n.concat(),r=Math.random(),i=[];kt[e].apply(n,arguments);for(var o=0,l=a.length;l>o;o++){var s=n[o],c=a[o];if(tn(s,c))i.push(o);else{var u=a.indexOf(s);i.push(u),a[u]=r,t=!0}}return t&&(b(this,i),this._fire("move",i),this._fire("index",0)),this}});var on=/^(duplex|on)$/,ln=avalon.$$subscribers=[],sn=new Date,cn={},un=new function(){avalon.mix(this,{option:ft.createElement("select"),thead:ft.createElement("table"),td:ft.createElement("tr"),area:ft.createElement("map"),tr:ft.createElement("tbody"),col:ft.createElement("colgroup"),legend:ft.createElement("fieldset"),_default:ft.createElement("div"),g:ft.createElementNS("http://www.w3.org/2000/svg","svg")}),this.optgroup=this.option,this.tbody=this.tfoot=this.colgroup=this.caption=this.thead,this.th=this.td};String("circle,defs,ellipse,image,line,path,polygon,polyline,rect,symbol,text,use").replace(bt,function(e){un[e]=un.g});var fn=/<([\w:]+)/,pn=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,dn=o(["","text/javascript","text/ecmascript","application/ecmascript","application/javascript"]),vn=ft.createElement("script"),hn=/<|&#?\w+;/;avalon.parseHTML=function(e){var t=Lt.cloneNode(!1);if("string"!=typeof e)return t;if(!hn.test(e))return t.appendChild(ft.createTextNode(e)),t;e=e.replace(pn,"<$1></$2>").trim();var n,a=(fn.exec(e)||["",""])[1].toLowerCase(),r=un[a]||un._default;r.innerHTML=e;var i=r.getElementsByTagName("script");if(i.length)for(var o,l=0;o=i[l++];)if(dn[o.type]){var s=vn.cloneNode(!1);kt.forEach.call(o.attributes,function(e){s.setAttribute(e.name,e.value)}),s.text=o.text,o.parentNode.replaceChild(s,o)}for(;n=r.firstChild;)t.appendChild(n);return t},avalon.innerHTML=function(e,t){var n=this.parseHTML(t);this.clearHTML(e).appendChild(n)},avalon.clearHTML=function(e){for(e.textContent="";e.firstChild;)e.removeChild(e.firstChild);return e},avalon.scan=function(e,t){e=e||Nt;var n=t?[].concat(t):[];D(e,n)};var mn=o("area,base,basefont,br,col,command,embed,hr,img,input,link,meta,param,source,track,wbr,noscript,script,style,textarea".toUpperCase()),gn=function(e,t,n){var a=e.getAttribute(t);if(a)for(var r,i=0;r=n[i++];)if(r.hasOwnProperty(a)&&"function"==typeof r[a])return r[a]},yn=Dt&&e.MutationObserver?function(e){for(var t,n=e.firstChild;n;){var a=n.nextSibling;3===n.nodeType?t?(t.nodeValue+=n.nodeValue,e.removeChild(n)):t=n:t=null,n=a}}:0,bn=/ms-(\w+)-?(.*)/,$n={"if":10,repeat:90,data:100,widget:110,each:1400,"with":1500,duplex:2e3,on:3e3},xn=o("animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scan,scroll,submit"),wn=o("value,title,alt,checked,selected,disabled,readonly,enabled"),Cn=/^if|widget|repeat$/,An=/^each|with|html|include$/,Tn=/\|\s*html\s*/,kn=/\|\|/g;rstringLiteral=/(['"])(\\\1|.)+?\1/g,"add,remove".replace(bt,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){n.classList[e](t)}),this}}),avalon.fn.mix({hasClass:function(e){var t=this[0]||{};return 1===t.nodeType&&t.classList.contains(e)},toggleClass:function(e,t){for(var n,a=0,r=e.split(/\s+/),i="boolean"==typeof t;n=r[a++];){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-"+_(e||""),arguments.length){case 2:return this.attr(e,t),this;case 1:var n=this.attr(e);return B(n);case 0:var a={};return kt.forEach.call(this[0].attributes,function(t){t&&(e=t.name,e.indexOf("data-")||(e=F(e.slice(5)),a[e]=B(t.value)))}),a}},removeData:function(e){return e="data-"+_(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 a=avalon.css(this,e,t);return void 0!==a?a:this},position:function(){var e,t,n=this[0],a={top:0,left:0};if(n)return"fixed"===this.css("position")?t=n.getBoundingClientRect():(e=this.offsetParent(),t=this.offset(),"HTML"!==e[0].tagName&&(a=e.offset()),a.top+=avalon.css(e[0],"borderTopWidth",!0),a.left+=avalon.css(e[0],"borderLeftWidth",!0)),{top:t.top-a.top-avalon.css(n,"marginTop",!0),left:t.left-a.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||Nt)},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,a=n?":get":":set",r=Hn[q(t)+a];if(r)var i=r(t,e);else{if(n)return(t.value||"").replace(/\r/g,"");t.value=e}}return n?i:this}}),Nt.dataset&&(avalon.fn.data=function(e,t){var n=this[0].dataset;switch(arguments.length){case 2:return n[e]=t,this;case 1:return t=n[e],B(t);case 0:var a=r();for(e in n)a[e]=B(n[e]);return a}});var En=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/;avalon.parseJSON=JSON.parse,avalon.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(e,t){avalon.fn[e]=function(n){var a=this[0]||{},r=U(a),i="scrollTop"===e;return arguments.length?void(r?r.scrollTo(i?r[t]:n,i?n:r[t]):a[e]=n):r?r[t]:a[e]}});var Mn=avalon.cssHooks=r(),On=["","-webkit-","-moz-","-ms-"],Nn={"float":"cssFloat"};avalon.cssNumber=o("columnCount,order,fillOpacity,fontWeight,lineHeight,opacity,orphans,widows,zIndex,zoom"),avalon.cssName=function(e,t,n){if(Nn[e])return Nn[e];t=t||Nt.style;for(var a=0,r=On.length;r>a;a++)if(n=F(On[a]+e),n in t)return Nn[e]=n;return null},Mn["@:set"]=function(e,t,n){e.style[t]=n},Mn["@:get"]=function(e,t){if(!e||!e.style)throw new Error("getComputedStyle要求传入一个节点 "+e);var n,a=getComputedStyle(e);return a&&(n="filter"===t?a.getPropertyValue(t):a[t],""===n&&(n=e.style[t])),n},Mn["opacity:get"]=function(e){var t=Mn["@:get"](e,"opacity");return""===t?"1":t},"top,left".replace(bt,function(e){Mn[e+":get"]=function(t){var n=Mn["@:get"](t,e);return/px$/.test(n)?n:avalon(t).position()[e]+"px"}});var Ln={position:"absolute",visibility:"hidden",display:"block"},jn=/^(none|table(?!-c[ea]).+)/;"Width,Height".replace(bt,function(e){var t=e.toLowerCase(),n="client"+e,a="scroll"+e,r="offset"+e;Mn[t+":get"]=function(t,n,a){var i=-4;"number"==typeof a&&(i=a),n="Width"===e?["Left","Right"]:["Top","Bottom"];var o=t[r];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)
|
2
|
-
},Mn[t+"&get"]=function(e){var n=[];V(e,n);for(var a,r=Mn[t+":get"](e),i=0;a=n[i++];){e=a.node;for(var o in a)"string"==typeof a[o]&&(e.style[o]=a[o])}return r},avalon.fn[t]=function(i){var o=this[0];if(0===arguments.length){if(o.setTimeout)return o["inner"+e];if(9===o.nodeType){var l=o.documentElement;return Math.max(o.body[a],l[a],o.body[r],l[r],l[n])}return Mn[t+"&get"](o)}return this.css(t,i)},avalon.fn["inner"+e]=function(){return Mn[t+":get"](this[0],void 0,-2)},avalon.fn["outer"+e]=function(e){return Mn[t+":get"](this[0],void 0,e===!0?2:0)}}),avalon.fn.offset=function(){var e=this[0];try{var t=e.getBoundingClientRect();if(t.width||t.height||e.getClientRects().length){var n=e.ownerDocument,a=n.documentElement,r=n.defaultView;return{top:t.top+r.pageYOffset-a.clientTop,left:t.left+r.pageXOffset-a.clientLeft}}}catch(i){return{left:0,top:0}}};var Hn={"select:get":function(e,t){for(var n,a=e.options,r=e.selectedIndex,i="select-one"===e.type||0>r,o=i?null:[],l=i?r+1:a.length,s=0>r?l:i?r:0;l>s;s++)if(n=a[s],(n.selected||s===r)&&!n.disabled){if(t=n.value,i)return t;o.push(t)}return o},"select:set":function(e,t,n){t=[].concat(t);for(var a,r=0;a=e.options[r++];)(a.selected=t.indexOf(a.value)>-1)&&(n=!0);n||(e.selectedIndex=-1)}},Sn=JSON.stringify,Dn=["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(","),Pn=/\/\*[\w\W]*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|"(?:[^"\\]|\\[\w\W])*"|'(?:[^'\\]|\\[\w\W])*'|[\s\t\n]*\.[\s\t\n]*[$\w\.]+/g,Rn=/[^\w$]+/g,In=new RegExp(["\\b"+Dn.replace(/,/g,"\\b|\\b")+"\\b"].join("|"),"g"),_n=/\b\d[^,]*/g,Fn=/^,+|,+$/g,Bn=new _t(512),Un=function(e){var t=","+e.trim(),n=Bn.get(t);if(n)return n;var a=e.replace(Pn,"").replace(Rn,",").replace(In,"").replace(_n,"").replace(Fn,"").split(/^$|,+/);return Bn.put(t,W(a))},Vn=new _t(128),qn=/\w\[.*\]|\w\.\w/,zn=/(\$proxy\$[a-z]+)\d+$/,Wn=/\)\s*$/,Xn=/\)\s*\|/g,Yn=/\|\s*([$\w]+)/g,Gn=/"\s*\["/g,Zn=/"\s*\(/g;avalon.parseExprProxy=G;var Jn=["autofocus,autoplay,async,allowTransparency,checked,controls","declare,disabled,defer,defaultChecked,defaultSelected","contentEditable,isMap,loop,multiple,noHref,noResize,noShade","open,readOnly,selected"].join(","),Qn={};Jn.replace(bt,function(e){Qn[e.toLowerCase()]=e});var Kn={"accept-charset":"acceptCharset","char":"ch",charoff:"chOff","class":"className","for":"htmlFor","http-equiv":"httpEquiv"},ea=["accessKey,bgColor,cellPadding,cellSpacing,codeBase,codeType,colSpan","dateTime,defaultValue,frameBorder,longDesc,maxLength,marginWidth,marginHeight","rowSpan,tabIndex,useMap,vSpace,valueType,vAlign"].join(",");ea.replace(bt,function(e){Kn[e.toLowerCase()]=e});var ta=/<noscript.*?>(?:[\s\S]+?)<\/noscript>/gim,na=/<noscript.*?>([\s\S]+?)<\/noscript>/im,aa=function(){return new(e.XMLHttpRequest||ActiveXObject)("Microsoft.XMLHTTP")},ra=avalon.templateCache={};Rt.attr=function(e,t){var n=e.value.trim(),a=!0;if(n.indexOf(Vt)>-1&&n.indexOf(qt)>2&&(a=!1,zt.test(n)&&""===RegExp.rightContext&&""===RegExp.leftContext&&(a=!0,n=RegExp.$1)),"include"===e.type){var r=e.element;e.includeRendered=gn(r,"data-include-rendered",t),e.includeLoaded=gn(r,"data-include-loaded",t);var i=e.includeReplace=!!avalon(r).data("includeReplace");avalon(r).data("includeCache")&&(e.templateCache={}),e.startInclude=ft.createComment("ms-include"),e.endInclude=ft.createComment("ms-include-end"),i?(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",G(n,t,e,a?0:R(e.value))},It.attr=function(t,n,a){var r=a.type,i=a.param;if("css"===r)avalon(n).css(i,t);else if("attr"===r){if(Qn[i]){var o=Qn[i];if("boolean"==typeof n[o])return n[o]=!!t}var l=t===!1||null===t||void 0===t;if(!Ot&&Kn[i]&&(i=Kn[i]),l)return n.removeAttribute(i);var s=xt.test(n)?!1:ft.namespaces&&isVML(n)?!0:i in n.cloneNode(!1);s?n[i]=t:n.setAttribute(i,t)}else if("include"===r&&t){var c=a.vmodels,u=a.includeRendered,f=a.includeLoaded,p=a.includeReplace,d=p?n.parentNode:n,v=function(e){f&&(e=f.apply(d,[e].concat(c))),u&&E(d,function(){u.call(d)},0/0);var n=a.includeLastID;if(a.templateCache&&n&&n!==t){var r=a.templateCache[n];r||(r=a.templateCache[n]=ft.createElement("div"),vt.appendChild(r))}for(a.includeLastID=t;;){var i=a.startInclude.nextSibling;if(!i||i===a.endInclude)break;d.removeChild(i),r&&r.appendChild(i)}var o=Z(a,t,e),l=avalon.slice(o.childNodes);d.insertBefore(o,a.endInclude),H(l,c)};if("src"===a.param)if(ra[t])avalon.nextTick(function(){v(ra[t])});else{var h=aa();h.onreadystatechange=function(){if(4===h.readyState){var e=h.status;(e>=200&&300>e||304===e||1223===e)&&v(ra[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:ft.getElementById(t);if(m){if("NOSCRIPT"===m.tagName&&!m.innerHTML&&!m.fixIE78){h=aa(),h.open("GET",location,!1),h.send(null);for(var g=ft.getElementsByTagName("noscript"),y=(h.responseText||"").match(ta)||[],b=y.length,$=0;b>$;$++){var x=g[$];x&&(x.style.display="none",x.fixIE78=(y[$].match(na)||[""," "])[1])}}avalon.nextTick(function(){v(m.fixIE78||m.value||m.innerText||m.innerHTML)})}}}else if(Nt.hasAttribute||"string"!=typeof t||"src"!==r&&"href"!==r||(t=t.replace(/&/g,"&")),n[r]=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(bt,function(e){Rt[e]=Rt.attr}),Rt["class"]=function(e,t){var a,r=e.param,i=e.value;if(e.handlerName="class",!r||isFinite(r)){e.param="";var o=i.replace(Wt,function(e){return e.replace(/./g,"0")}),l=o.indexOf(":");if(-1===l)var s=i;else{if(s=i.slice(0,l),a=i.slice(l+1),Y(a,t,e),!e.evaluator)return n("debug: ms-class '"+(a||"").trim()+"' 不存在于VM中"),!1;e._evaluator=e.evaluator,e._args=e.args}var c=zt.test(s);c||(e.immobileClass=s),G("",t,e,c?R(s):0)}else e.immobileClass=e.oldStyle=e.param,G(i,t,e)},It["class"]=function(e,t,n){var a=avalon(t),r=n.type;if("class"===r&&n.oldStyle)a.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&&a.removeClass(n.oldClass),n.oldClass=n.newClass,r){case"class":a.toggleClass(n.newClass,n.toggleClass);break;case"hover":case"active":if(!n.hasBindEvent){var i="mouseenter",o="mouseleave";if("active"===r){t.tabIndex=t.tabIndex||-1,i="mousedown",o="mouseup";var l=a.bind("mouseleave",function(){n.toggleClass&&a.removeClass(n.newClass)})}var s=a.bind(i,function(){n.toggleClass&&a.addClass(n.newClass)}),c=a.bind(o,function(){n.toggleClass&&a.removeClass(n.newClass)});n.rollback=function(){a.unbind("mouseleave",l),a.unbind(i,s),a.unbind(o,c)},n.hasBindEvent=!0}}},"hover,active".replace(bt,function(e){Rt[e]=Rt["class"]}),It.data=function(e,t,n){var a="data-"+n.param;e&&"object"==typeof e?t[a]=e:t.setAttribute(a,String(e))};var ia=Rt.duplex=function(e,t){var a,r=e.element;if(G(e.value,t,e,0,1),e.changed=gn(r,"data-duplex-changed",t)||i,e.evaluator&&e.args){var l=[],s=o("string,number,boolean,checked");"radio"===r.type&&""===e.param&&(e.param="checked"),r.msData&&(r.msData["ms-duplex"]=e.value),e.param.replace(/\w+/g,function(t){/^(checkbox|radio)$/.test(r.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){r.addEventListener?r.addEventListener(t,n,!1):r.attachEvent("on"+t,n);var a=e.rollback;e.rollback=function(){r.avalonSetter=null,avalon.unbind(r,t,n),a&&a()}};for(var c in avalon.vmodels){var u=avalon.vmodels[c];u.$fire("avalon-ms-duplex-init",e)}var f=e.pipe||(e.pipe=Q);f(null,e,"init");var p=r.tagName;ia[p]&&ia[p](r,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:J},"boolean":{get:function(e){return"true"===e},set:J},number:{get:function(e,t){var n=parseFloat(e);if(-e===-n)return n;var a=/strong|medium|weak/.exec(t.element.getAttribute("data-duplex-number"))||["medium"];switch(a[0]){case"strong":return 0;case"medium":return""===e?"":0;case"weak":return e}},set:J}};var oa,la=[];avalon.tick=function(e){1===la.push(e)&&(oa=setInterval(K,60))};var sa=i,ca=/text|password|hidden/;!new function(){function e(e){if(avalon.contains(Nt,this)){if(t[this.tagName].call(this,e),!ca.test(this.type))return;!this.msFocus&&this.avalonSetter&&this.avalonSetter()}}try{var t={},n=HTMLInputElement.prototype,a=HTMLTextAreaElement.prototype,r=HTMLInputElement.prototype;Object.getOwnPropertyNames(r),t.INPUT=Object.getOwnPropertyDescriptor(n,"value").set,Object.defineProperty(n,"value",{set:e}),t.TEXTAREA=Object.getOwnPropertyDescriptor(a,"value").set,Object.defineProperty(a,"value",{set:e})}catch(i){sa=avalon.tick}},ia.INPUT=function(e,t,a){function r(e){a.changed.call(this,e,a)}function i(){u=!0}function o(){u=!1}var l=e.type,s=a.bound,c=avalon(e),u=!1,f=function(){if(!u){var n=e.oldValue=e.value,i=a.pipe(n,a,"get");c.data("duplex-observe")!==!1&&(t(i),r.call(e,i),c.data("duplex-focus")&&avalon.nextTick(function(){e.focus()}))}};if(a.handler=function(){var n=a.pipe(t(),a,"set")+"";n!==e.oldValue&&(e.value=n)},a.isChecked||"radio"===l)f=function(){if(c.data("duplex-observe")!==!1){var n=a.pipe(e.value,a,"get");t(n),r.call(e,n)}},a.handler=function(){var n=t(),r=a.isChecked?!!n:n+""===e.value;e.checked=e.oldValue=r},s("click",f);else if("checkbox"===l)f=function(){if(c.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,a.pipe(e.value,a,"get")),r.call(e,o)}},a.handler=function(){var n=[].concat(t());e.checked=n.indexOf(a.pipe(e.value,a,"get"))>-1},s("change",f);else{var p=e.getAttribute("data-duplex-event")||"input";e.attributes["data-event"]&&n("data-event指令已经废弃,请改用data-duplex-event"),p.replace(bt,function(e){switch(e){case"input":s("input",f),s("DOMAutoComplete",f),Dt||(s("compositionstart",i),s("compositionend",o));break;default:s(e,f)}}),s("focus",function(){e.msFocus=!0}),s("blur",function(){e.msFocus=!1}),ca.test(l)&&sa(function(){if(Nt.contains(e))e.msFocus||e.oldValue===e.value||f();else if(!e.msRetain)return!1}),e.avalonSetter=f}e.oldValue=e.value,$(a),r.call(e,e.value)},ia.TEXTAREA=ia.INPUT,ia.SELECT=function(e,t,a){function r(){if(i.data("duplex-observe")!==!1){var n=i.val();n=Array.isArray(n)?n.map(function(e){return a.pipe(e,a,"get")}):a.pipe(n,a,"get"),n+""!==e.oldValue&&t(n),a.changed.call(e,n,a)}}var i=avalon(e);a.handler=function(){var a=t();a=a&&a.$model||a,Array.isArray(a)?e.multiple||n("ms-duplex在<select multiple=true>上要求对应一个数组"):e.multiple&&n("ms-duplex在<select multiple=false>不能对应一个数组"),a=Array.isArray(a)?a.map(String):a+"",a+""!==e.oldValue&&(i.val(a),e.oldValue=a+"")},a.bound("change",r),E(e,function(){$(a),a.changed.call(e,t(),a)},0/0)},It.html=function(e,t,n){e=null==e?"":e;var a="group"in n,r=a?t.parentNode:t;if(r){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=Lt.cloneNode(!0);o[0];)i.appendChild(o[0])}else i=avalon.parseHTML(e);var l=ft.createComment("ms-html");if(a){r.insertBefore(l,t);for(var s=n.group,c=1;s>c;){var u=t.nextSibling;u&&(r.removeChild(u),c++)}r.removeChild(t),n.element=l}else avalon.clearHTML(r).appendChild(l);a&&(n.group=i.childNodes.length||1),o=avalon.slice(i.childNodes),o[0]&&(l.parentNode&&l.parentNode.replaceChild(i,l),a&&(n.element=o[0])),H(o,n.vmodels)}},Rt["if"]=Rt.data=Rt.text=Rt.html=function(e,t){G(e.value,t,e)},It["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),L(t,n.vmodels)),n.rollback=null;else if(1===t.nodeType){var a=n.element=ft.createComment("ms-if");t.parentNode.replaceChild(a,t),n.template=t,vt.appendChild(t),n.rollback=function(){t.parentNode===vt&&vt.removeChild(t)}}};var ua=/\(([^)]*)\)/;Rt.on=function(e,t){var n=e.value;e.type="on";var a=e.param.replace(/-\d+$/,"");if("function"==typeof Rt.on[a+"Hook"]&&Rt.on[a+"Hook"](e),n.indexOf("(")>0&&n.indexOf(")")>-1){var r=(n.match(ua)||["",""])[1].trim();(""===r||"$event"===r)&&(n=n.replace(ua,""))}G(n,t,e)},It.on=function(e,t,n){e=function(e){var t=n.evaluator||i;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 r=avalon.bind(t,a,e);n.rollback=function(){"function"==typeof n.specialUnbind?n.specialUnbind():avalon.unbind(t,a,r)}},Rt.repeat=function(e,t){var n=e.type;G(e.value,t,e,0,1),e.proxies=[];var a=!1;try{var r=e.$repeat=e.evaluator.apply(0,e.args||[]),i=avalon.type(r);"object"!==i&&"array"!==i&&(a=!0,avalon.log("warning:"+e.value+"只能是对象或数组"))}catch(o){a=!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[ht]=f[ht]||[],f[ht].push(e);break}}var p=e.element;p.removeAttribute(e.name),e.sortedCallback=gn(p,"data-with-sorted",t),e.renderedCallback=gn(p,"data-"+n+"-rendered",t);var d=St(n),v=e.element=ft.createComment(d+":end");if(e.clone=ft.createComment(d),Lt.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){It.repeat.call(e,"clear");var n=t.parentNode,a=e.template,r=a.firstChild;n.replaceChild(a,t);var i=e.$stamp;i&&i.parentNode&&i.parentNode.removeChild(i),r=e.element="repeat"===e.type?r:n}},!a){e.handler=It.repeat,e.$outer={};var h="$key",m="$val";for(Array.isArray(r)&&(h="$first",m="$last"),u=0;s=t[u++];)if(s.hasOwnProperty(h)&&s.hasOwnProperty(m)){e.$outer=s;break}var g=r.$events,y=(g||{})[ht];if(y&&avalon.Array.ensure(y,e)&&w(e,y),"object"===i){e.$with=!0;var b=g?g.$withProxyPool||(g.$withProxyPool={}):{};e.handler("append",r,b)}else r.length&&e.handler("add",0,r.length)}},It.repeat=function(e,t,n){if(e){var a=this,r=a.element,o=r.parentNode,l=a.proxies,s=Lt.cloneNode(!1);switch(e){case"add":for(var c,u=t+n,f=a.$repeat,p=f.length-1,d=[],v=tt(a,t),h=t;u>h;h++){var m=rt(h,a);l.splice(h,0,m),et(a,s,m,d)}for(o.insertBefore(s,v),h=0;c=d[h++];)H(c.nodes,c.vmodels),c.nodes=c.vmodels=null;break;case"del":v=l[t].$stamp,r=tt(a,t+n),nt(v,r);var g=l.splice(t,n);lt(g,"each");break;case"clear":var y=a.$stamp||l[0];y&&(v=y.$stamp||y,nt(v,r)),lt(l,"each");break;case"move":v=l[0].$stamp;var $,x=v.nodeValue,w=[],C=[];for(nt(v,r,function(){C.unshift(this),this.nodeValue===x&&(w.unshift(C),C=[])}),b(l,t),b(w,t);C=w.shift();)for(;$=C.shift();)s.appendChild($);o.insertBefore(s,r);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&&k(m.$events.$index));case"append":var A=n,T=[];d=[];for(var M in t)t.hasOwnProperty(M)&&"hasOwnProperty"!==M&&T.push(M);if(a.sortedCallback){var O=a.sortedCallback.call(o,T);O&&Array.isArray(O)&&O.length&&(T=O)}for(h=0;M=T[h++];)"hasOwnProperty"!==M&&(A[M]||(A[M]=ot(M,a)),et(a,s,A[M],d));var N=a.$stamp=a.clone;for(o.insertBefore(N,r),o.insertBefore(s,r),h=0;c=d[h++];)H(c.nodes,c.vmodels),c.nodes=c.vmodels=null}"clear"===e&&(e="del");var L=a.renderedCallback||i,j=arguments;E(o,function(){L.apply(o,j),o.oldValue&&"SELECT"===o.tagName&&avalon(o).val(o.oldValue.split(","))},0/0)}},"with,each".replace(bt,function(e){Rt[e]=Rt.repeat});var fa=[],pa=[];It.text=function(e,t){if(e=null==e?"":e,3===t.nodeType)try{t.data=e}catch(n){}else t.textContent=e},avalon.parseDisplay=st,Rt.visible=function(e,t){var n=avalon(e.element),a=n.css("display");if("none"===a){var r=n[0].style,i=/visibility/i.test(r.cssText),o=n.css("visibility");r.display="",r.visibility="hidden",a=n.css("display"),"none"===a&&(a=st(n[0].nodeName)),r.visibility=i?o:""}e.display=a,G(e.value,t,e)},It.visible=function(e,t,n){t.style.display=e?n.display:"none"},Rt.widget=function(t,n){var a=t.value.match(bt),r=t.element,o=a[0],l=a[1];l&&"$"!==l||(l=St(o));var s=a[2]||o,c=avalon.ui[o];if("function"==typeof c){n=r.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(r,o);t.value=[o,l,s].join(","),t[o+"Id"]=l,t.evaluator=i,r.msData["ms-widget-id"]=l;var h=t[o+"Options"]=avalon.mix({},c.defaults,p||{},v);r.removeAttribute("ms-widget");var m=c(r,t,n)||{};m.$id?(avalon.vmodels[l]=m,M(r,m),m.hasOwnProperty("$init")&&m.$init(function(){avalon.scan(r,[m].concat(n)),"function"==typeof h.onInit&&h.onInit.call(r,m,h,n)}),t.rollback=function(){try{m.widgetElement=null,m.$remove()}catch(e){}r.msData={},delete avalon.vmodels[m.$id]},w(t,da),e.chrome&&r.addEventListener("DOMNodeRemovedFromDocument",function(){setTimeout(T)})):avalon.scan(r,n)}else n.length&&(r.vmodels=n)};var da=[],va=/<script[^>]*>([\S\s]*?)<\/script\s*>/gim,ha=/\s+(on[^=\s]+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,ma=/<\w+\b(?:(["'])[^"]*?(\1)|[^>])*>/gi,ga={a:/\b(href)\=("javascript[^"]*"|'javascript[^']*')/gi,img:/\b(src)\=("javascript[^"]*"|'javascript[^']*')/gi,form:/\b(action)\=("javascript[^"]*"|'javascript[^']*')/gi},ya=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,ba=/([^\#-~| |!])/g,$a=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 a=arguments[t],r=avalon.filters[a.shift()];if("function"==typeof r){var i=[e].concat(a);e=r.apply(null,i)}}return e},camelize:F,sanitize:function(e){return e.replace(va,"").replace(ma,function(e){var t=e.toLowerCase().match(/<(\w+)\s/);if(t){var n=ga[t[1]];n&&(e=e.replace(n,function(e,t,n){var a=n.charAt(0);return t+"="+a+"javascript:void(0)"+a}))}return e.replace(ha," ").replace(/\s+/g," ")})},escape:function(e){return String(e).replace(/&/g,"&").replace(ya,function(e){var t=e.charCodeAt(0),n=e.charCodeAt(1);return"&#"+(1024*(t-55296)+(n-56320)+65536)+";"}).replace(ba,function(e){return"&#"+e.charCodeAt(0)+";"}).replace(/</g,"<").replace(/>/g,">")},currency:function(e,t,n){return(t||"¥")+ct(e,isFinite(n)?n:2)},number:ct};!new function(){function e(e){return parseInt(e,10)||0}function t(e,t,n){var a="";for(0>e&&(a="-",e=-e),e=""+e;e.length<t;)e="0"+e;return n&&(e=e.substr(e.length-t)),a+e}function n(e,n,a,r){return function(i){var o=i["get"+e]();return(a>0||o>-a)&&(o+=a),0===o&&-12===a&&(o=12),t(o,n,r)}}function a(e,t){return function(n,a){var r=n["get"+e](),i=(t?"SHORT"+e:e).toUpperCase();return a[i][r]}}function r(e){var n=-1*e.getTimezoneOffset(),a=n>=0?"+":"";return a+=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:a("Month"),MMM:a("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:a("Day"),EEE:a("Day",!0),a:i,Z:r},l=/((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z))(.*)/,s=/^\/Date\((\d+)\)\/$/;$a.date=function(t,n){var a,r,i=$a.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,a,r){var i=4===r.length?[r,n,a]:[n,a,r];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,a,r,i){return p[3]=e(n),p[4]=e(a),p[5]=e(r),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,a,r){return v=d.setUTCFullYear,h=d.setUTCHours,n&&(m=e(n+a),g=e(n+r)),""}),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;)r=l.exec(n),r?(u=u.concat(r.slice(1)),n=u.pop()):(u.push(n),n=null);return u.forEach(function(e){a=o[e],c+=a?a(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,$a.date.locate=c};var xa=avalon.modules={"domReady!":{exports:avalon,state:3},avalon:{exports:avalon,state:4}};xa.exports=xa.avalon,new function(){function t(e,t){var a="js";e=e.replace(/^(\w+)\!/,function(e,t){return a=t,""}),"ready"===a&&(n("debug: ready!已经被废弃,请使用domReady!"),a="domReady");var r="";e=e.replace(D,function(e){return r=e,""});var i="."+a,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:r,ext:o,res:a,name:e,toUrl:m},t);return l.toUrl(e),l}function o(e){var t=e.name,n=e.res,a=xa[t],r=t&&e.urlNoQuery;if(a&&a.state>=1)return t;if(a=xa[r],a&&a.state>=3)return dt(a.deps||[],a.factory,r),r;if(t&&!a){a=xa[r]={id:r,state:1};var i=function(r){S[n]=r,r.load(t,e,function(e){arguments.length&&void 0!==e&&(a.exports=e),a.state=4,c()})};S[n]?i(S[n]):dt([n],i)}return t?r:n+"!"}function l(e,t){for(var n,a=0;n=e[a++];)if(4!==xa[n].state&&(n===t||l(xa[n].deps,t)))return!0}function s(e,t){var a=p(e.src);return e.onload=e.onerror=null,t?(setTimeout(function(){pt.removeChild(e),e=null}),void n("debug: 加载 "+a+" 失败"+t+" "+!xa[a].state)):!0}function c(){e:for(var e,t=T.length;e=T[--t];){var n=xa[e],a=n.deps;if(a){for(var r,i=0;r=a[i];i++)if(4!==Object(xa[r]).state)continue e;4!==n.state&&(T.splice(t,1),h(n.id,n.deps,n.factory),c())}}}function f(e,t,a){var r=ft.createElement("script");r.className=ht,r.onload=function(){var r=k.pop();r&&r.require(t),a&&a(),n("debug: 已成功加载 "+e),t&&T.push(t),c()},r.onerror=function(){s(r,!0)},pt.insertBefore(r,pt.firstChild),r.src=e,n("debug: 正准备加载 "+e)}function p(e){return(e||"").replace(D,"")}function d(e){return/^(?:[a-z]+:)?\/\//i.test(String(e))}function v(){var e;try{a.b.c()}catch(t){e=t.stack}if(e)return e=e.split(/[@ ]/g).pop(),e="("===e[0]?e.slice(1,-1):e.replace(/\s/,""),p(e.replace(/(:\d+)?:\d+$/i,""));for(var n,r=pt.getElementsByTagName("script"),i=r.length;n=r[--i];)if(n.className===ht&&"interactive"===n.readyState){var o=n.src;return n.className=p(o)}}function h(t,a,i){var o=Object(xa[t]);o.state=4;for(var l,s=0,c=[];l=a[s++];)if("exports"===l){var u=o.exports||(o.exports=r());c.push(u)}else c.push(xa[l].exports);try{var f=i.apply(e,c)}catch(p){n("执行["+t+"]模块的factory抛错: "+p)}return void 0!==f&&(o.exports=f),P.test(t)&&delete xa[t],delete o.factory,f}function m(e){0===e.indexOf(this.res+"!")&&(e=e.slice(this.res.length+1));var t=e,n=0,a=this.baseUrl,r=this.parentUrl||a;x(e,u.paths,function(e,a){t=t.replace(a,e),n=1}),n||x(e,u.packages,function(e,n,a){t=t.replace(a.name,a.location)}),this.mapUrl&&x(this.mapUrl,u.map,function(e){x(t,e,function(e,n){t=t.replace(n,e),r=a})});var i=this.ext;i&&n&&t.slice(-i.length)===i&&(t=t.slice(0,-i.length)),d(t)||(r=this.built||/^\w/.test(t)?a:r,t=C(r,t));var o=t+i;return t=o+this.query,x(e,u.urlArgs,function(e){t+=(-1===t.indexOf("?")?"?":"&")+e}),this.url=t,this.urlNoQuery=o}function g(e,t,n){var a=$(e,t,n);return a.sort(w),a}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&&A(t.exports)}}function $(e,t,n){var a=[];for(var r in e){var i={name:r,val:e[r]};a.push(i),i.reg="*"===r&&t?/^/:y(r),n&&"*"!==r&&(i.reg=new RegExp("/"+r.replace(/^\//,"")+"(/|$)"))}return a}function x(e,t,n){t=t||[];for(var a,r=0;a=t[r++];)if(a.reg.test(e))return n(a.val,a.name,a),!1}function w(e,t){var n=e.name,a=t.name;return"*"===a?-1:"*"===n?1:a.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;R.test(e);)e=e.replace(R,"");return e}return"/"===t.slice(0,1)?e+t.slice(1):e+t}function A(t){if(!t)return t;var n=e;return t.split(".").forEach(function(e){n=n[e]}),n}var T=[],k=[],E=/\.js$/i,M=[],O=!1;dt=avalon.require=function(e,n,a,l){if(O){Array.isArray(e)||avalon.error("require方法的第一个参数应为数组 "+e);var s=[],f=r(),p=a||"callback"+setTimeout("1");l=l||r(),l.baseUrl=u.baseUrl;var d=!!l.built;if(a&&(l.parentUrl=a.substr(0,a.lastIndexOf("/")),l.mapUrl=a.replace(E,"")),d){var v=t(l.defineName,l);p=v.urlNoQuery}else e.forEach(function(e){var n=t(e,l),a=o(n);a&&(f[a]||(s.push(a),f[a]="司徒正美"))});var h=xa[p];h&&4===h.state||(xa[p]={id:p,deps:d?e.concat():s,factory:n||i,state:3}),h||T.push(p),c()}else if(M.push(avalon.slice(arguments)),arguments.length<=2){O=!0;for(var m,g=M.splice(0,M.length);m=g.shift();)dt.apply(null,m)}},dt.define=function(e,t,n){"string"!=typeof e&&(n=t,t=e,e="anonymous"),Array.isArray(t)||(n=t,t=[]);var a={built:!O,defineName:e},r=[t,n,a];n.require=function(e){if(r.splice(2,0,e),xa[e]){xa[e].state=3;var t=!1;try{t=l(xa[e].deps,e)}catch(a){}t&&avalon.error(e+"模块与之前的模块存在循环依赖,请不要直接用script标签引入"+e+"模块")}delete n.require,dt.apply(null,r)};var i=a.built?"unknown":v();if(i){var o=xa[i];o&&(o.state=2),n.require(i)}else k.push(n)},dt.config=u,dt.define.amd=xa;var N=u["orig.paths"]=r(),L=u["orig.map"]=r(),j=u.packages=[],H=u["orig.args"]=r();avalon.mix(Gt,{paths:function(e){avalon.mix(N,e),u.paths=g(N)},map:function(e){avalon.mix(L,e);var t=g(L,1,1);avalon.each(t,function(e,t){t.val=g(t.val)}),u.map=t},packages:function(e){e=e.concat(j);for(var t,n=r(),a=[],i=0;t=e[i++];){t="string"==typeof t?{name:t}:t;var o=t.name;if(!n[o]){var l=t.location?t.location:C(o,t.main||"main");l=l.replace(E,""),a.push(t),n[o]=t.location=l,t.reg=y(o)}}u.packages=a.sort()},urlArgs:function(e){"string"==typeof e&&(e={"*":e}),avalon.mix(H,e),u.urlArgs=g(H,1)},baseUrl:function(e){if(!d(e)){var t=pt.getElementsByTagName("base")[0];t&&pt.removeChild(t);var n=ft.createElement("a");n.href=e,e=n.href,t&&pt.insertBefore(t,pt.firstChild)}e.length>3&&(u.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))}u.shim=e}});var S=dt.plugins={ready:{load:i},js:{load:function(e,t,n){var a=t.url,r=t.urlNoQuery,i=u.shim[e.replace(E,"")];i?dt(i.deps||[],function(){var e=avalon.slice(arguments);f(a,r,function(){n(i.exportsFn?i.exportsFn.apply(0,e):void 0)})}):f(a,r)}},css:{load:function(e,t,a){var r=t.url;pt.insertAdjacentHTML("afterBegin",'<link rel="stylesheet" href="'+r+'">'),n("debug: 已成功加载 "+r),a()}},text:{load:function(e,t,a){var r=t.url,i=aa();i.onload=function(){var e=i.status;e>399&&600>e?avalon.error(r+" 对应资源不存在或没有开启 CORS"):(n("debug: 已成功加载 "+r),a(i.responseText))},i.open("GET",r,!0),"withCredentials"in i&&(i.withCredentials=!0),i.setRequestHeader("X-Requested-With","XMLHttpRequest"),i.send(),n("debug: 正准备加载 "+r)}}};dt.checkDeps=c;var D=/(\?[^#]*)$/,P=/^callback\d+$/,R=/\/\w+\/\.\./,I=ft.scripts[ft.scripts.length-1],_=I.getAttribute("data-main");if(_){Gt.baseUrl(_);var F=u.baseUrl;u.baseUrl=F.slice(0,F.lastIndexOf("/")+1),f(F.replace(E,"")+".js")}else{var B=p(I.src);u.baseUrl=B.slice(0,B.lastIndexOf("/")+1)}};var wa,Ca=[],Aa=function(e){for(wa=!0,dt&&(xa["domReady!"].state=4,dt.checkDeps());e=Ca.shift();)e(avalon)};"complete"===ft.readyState?setTimeout(Aa):ft.addEventListener("DOMContentLoaded",Aa),e.addEventListener("load",Aa),avalon.ready=function(e){wa?e(avalon):Ca.push(e)},avalon.config({loader:!0}),avalon.ready(function(){avalon.scan(ft.body)}),"function"==typeof define&&define.amd&&define("avalon",[],function(){return avalon});var Ta=e.avalon;return avalon.noConflict=function(t){return t&&e.avalon===avalon&&(e.avalon=Ta),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(){avalon.config.debug&&console.log.apply(console,arguments)}function r(){return Object.create(null)}function i(){}function o(e,t){"string"==typeof e&&(e=e.match(At)||[]);for(var n={},a=void 0!==t?t:1,r=0,i=e.length;i>r;r++)n[e[r]]=a;return n}function l(){if(e.VBArray){var t=document.documentMode;return t?t:e.XMLHttpRequest?7:6}return 0/0}function s(e){if(e&&"object"==typeof e){var t=e.length,n=St.call(e);if(/(Array|List|Collection|Map|Arguments)\]$/.test(n))return!0;if("[object Object]"===n&&t===t>>>0)return!0}return!1}function c(e,t){if(e&&e.childNodes)for(var n,a=e.childNodes,r=0;n=a[r++];)if(n.tagName){var i=yt.createElementNS(Wt,n.tagName.toLowerCase());Lt.forEach.call(n.attributes,function(e){i.setAttribute(e.name,e.value)}),c(n,i),t.appendChild(i)}}function u(e){for(var t in e)if(jt.call(e,t)){var n=e[t];"function"==typeof u.plugins[t]?u.plugins[t](n):"object"==typeof u[t]?avalon.mix(u[t],n):u[t]=n}return this}function f(e){return(e+"").replace(en,"\\$&")}function d(e,t,n){if(Array.isArray(e)){var a=e.concat();e.length=0;var i=w(e);return i.pushArray(a),i}if(!e||e.nodeType>0||e.$id&&e.$events)return e;var o=Array.isArray(e.$skipArray)?e.$skipArray:[];o.$special=t||r();var l={};n=n||{};var s=r(),c=r(),u=[];on.forEach(function(t){delete e[t]});var f=Object.keys(e);f.forEach(function(t,a){var r=e[t];if(n[t]=r,x(t,r,o)){s[t]=[];var i=avalon.type(r);"object"===i&&Vt(r.get)&&Object.keys(r).length<=2?(a=m(t,r),u.push(a)):a=Et.test(i)?g(t,r,i,s[t],n):h(t,r),c[t]=a}}),l=Object.defineProperties(l,sn(c));for(var d=0;d<f.length;d++){var v=f[d];c[v]||(l[v]=e[v])}p(l,"$id",It()),p(l,"$model",n),p(l,"$events",s),p(l,"hasOwnProperty",function(e){return e in this.$model});for(var d in an)p(l,d,an[d]);return l.$reinitialize=function(){u.forEach(function(e){delete e._value,delete e.oldArgs,e.digest=function(){e.call(l)},fn.begin({callback:function(t,n){var a=n._name;if(n!==e){var r=t.$events[a];e.vm=l,T(r,e.digest)}}});try{e.get.call(l)}finally{fn.end()}})},l.$reinitialize(),l}function p(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!1,configurable:!0})}function v(e){for(var t=Object.keys(e),n=0;n<on.length;n++){var a=t.indexOf(on[n]);-1!==a&&t.splice(a,1)}return t}function h(e,t){function n(e){var t=n._value;return arguments.length>0?(Tt||ln(e,t)||(n.updateValue(this,e),n.notify(this,e,t)),this):(fn.collectDependency(this,n),t)}return $(n,e),n._value=t,n}function m(e,t){function n(t){var a=n._value,r="_value"in n;if(arguments.length>0){if(Tt)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!==a&&(n.updateValue(this,t),n.notify(this,t,a))}return this}return t=n.get.call(this),n.updateValue(this,t),r&&a!==t&&n.notify(this,t,a),t}return n.set=t.set,n.get=t.get,$(n,e),n}function g(e,t,n,a,r){function i(t){var a=i._value,r=i._vmodel;if(arguments.length>0){if(Tt)return this;if("array"===n){var o=r,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]||[],v=avalon.mix(!0,{},t);for(f in r)r.hasOwnProperty(f)&&jt.call(v,f)&&(r[f]=v[f]);r=i._vmodel=d(t),r.$events[wt]=p,p.length&&p.forEach(function(e){e.type&&(e.rollback&&e.rollback(),Ut[e.type](e,e.vmodels))})}return i.updateValue(this,r.$model),i.notify(this,this._value,a),this}return fn.collectDependency(this,i),r}$(i,e),r[e]=Array.isArray(t)?t:r[e]||{};var o=i._vmodel=d(t,0,r[e]);return o.$events[wt]=a,i}function y(e,t){e.$model[this._name]=this._value=t}function b(e,t,n){var a=this._name,r=e.$events[a];r&&(A(r),an.$fire.call(e,a,t,n))}function $(e,t){e._name=t,e.updateValue=y,e.notify=b}function x(e,t,n){if(Vt(t)||t&&t.nodeType)return!1;if(-1!==n.indexOf(e))return!1;var a=n.$special;return e&&"$"===e.charAt(0)&&!a[e]?!1:!0}function w(e){var t=[];t.$id=It(),t.$model=e,t.$events={},t.$events[wt]=[],t._=d({length:e.length}),t._.$watch("length",function(e,n){t.$fire("length",e,n)});for(var n in an)t[n]=an[n];return avalon.mix(t,un),t}function C(e,t,n,a,r,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 Et.test(avalon.type(e))?e.$id?e:d(e,0,e):e});cn.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)}r&&(e=r,t=i,n=o,s=2,r=0)}return this._fire("index",a),this.length!==l&&(this._.length=this.length),u}function k(e,t){for(var n={},a=0,r=t.length;r>a;a++){n[a]=e[a];var i=t[a];i in n?(e[a]=n[i],delete n[i]):e[a]=e[i]}}function T(e,t){t.oneTime||e&&avalon.Array.ensure(e,t)&&t.element&&(O(t,e),new Date-hn>444&&M())}function A(e){if(e&&e.length){new Date-hn>444&&"object"==typeof e[0]&&M();for(var t,n=Ht.call(arguments,1),a=e.length;t=e[--a];){var r=t.element;if(r&&r.parentNode)try{var i=t.evaluator;if(t.$repeat)t.handler.apply(t,n);else if("$repeat"in t||!i)Ut[t.type](t,t.vmodels);else if("on"!==t.type){var o=i.apply(0,t.args||[]);t.handler(o,r,t)}}catch(l){console.log(l)}}}}function E(e,t){return e.uuid||t||(e.uuid=++pn),e.uuid}function O(e,t){var n=e.element;e.uuid||(e.uuid=1!==n.nodeType?e.type+(e.pos||0)+"-"+E(n.parentNode):e.name+"-"+E(n));var a=e.lists||(e.lists=[]);avalon.Array.ensure(a,t),t.$uuid=t.$uuid||It(),vn[e.uuid]||(vn[e.uuid]=1,vn.push(e))}function M(e){if(!avalon.optimize){for(var t=vn.length,n=t,a=[],r={},i={};e=vn[--t];){var o=e.type;i[o]?i[o]++:(i[o]=1,a.push(o))}var l=!1;if(a.forEach(function(e){mn[e]!==i[e]&&(r[e]=1,l=!0)}),t=n,l)for(;e=vn[--t];)if(null!==e.element){if(r[e.type]&&j(e.element)){vn.splice(t,1),delete vn[e.uuid];for(var s,c=e.lists,u=0;s=c[u++];)avalon.Array.remove(c,s),avalon.Array.remove(s,e);N(e)}}else vn.splice(t,1);mn=i,hn=new Date}}function N(e){delete vn[e.uuid],e.element=null,e.rollback&&e.rollback();for(var t in e)e[t]=null}function j(e){try{{e.parentNode.nodeType}}catch(t){return!0}return e.ifRemove&&!Rt.contains(e.ifRemove)&&xt===e.parentNode?(e.parentNode&&e.parentNode.removeChild(e),!0):e.msRetain?0:1===e.nodeType?!Rt.contains(e):!avalon.contains(Rt,e)}function S(e){return e.replace(/([a-z\d])([A-Z]+)/g,"$1-$2").toLowerCase()}function L(e){return e.indexOf("-")<0&&e.indexOf("_")<0?e:e.replace(/[-_][^-_]/g,function(e){return e.charAt(1).toUpperCase()})}function H(e){try{if("object"==typeof e)return e;e="true"===e?!0:"false"===e?!1:"null"===e?null:+e+""===e?+e:Cn.test(e)?JSON.parse(e):e}catch(t){}return e}function D(e){return e.window&&e.document?e:9===e.nodeType?e.defaultView:!1}function R(e,t){if(e.offsetWidth<=0){var n=getComputedStyle(e,null);if(On.test(n.display)){var a={node:e};for(var r in En)a[r]=n[r],e.style[r]=En[r];t.push(a)}var i=e.parentNode;i&&1===i.nodeType&&R(i,t)}}function _(e){var t=e.tagName.toLowerCase();return"input"===t&&/checkbox|radio/.test(e.type)?"checked":t}function P(e,t,n,a){for(var r,i=[],o=" = "+n+".",l=e.length;r=e[--l];)t.hasOwnProperty(r)&&(i.push(r+o+r),a.vars.push(r),"duplex"===a.type&&(e.get=n+"."+r),e.splice(l,1));return i}function B(e){for(var t=[],n={},a=0;a<e.length;a++){var r=e[a],i=r&&"string"==typeof r.$id?r.$id:r;n[i]||(n[i]=t.push(r))}return t}function I(e,t){return t=t.replace(Vn,"").replace(Un,function(){return"],|"}).replace(zn,function(e,t){return"["+Nn(t)}).replace(qn,function(){return'"],["'}).replace(Wn,function(){return'",'})+"]","return this.filters.$filter("+e+", "+t+")"}function F(e,t,a){var r=a.type,o=a.filters||"",l=t.map(function(e){return String(e.$id).replace(Fn,"$1")})+e+r+o,s=Pn(e).concat(),c=[],u=[],f=[],d="";t=B(t),a.vars=[];for(var p=0,v=t.length;v>p;p++)if(s.length){var h="vm"+gt+"_"+p;u.push(h),f.push(t[p]),c.push.apply(c,P(s,t[p],h,a))}if(c.length||"duplex"!==r){"duplex"!==r&&(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,a){var r=n.charAt(t.length),i=e.slice(a+n.length),o=/^\s*\(/.test(i);if("."===r||"["===r||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=Bn.get(l);if(m)return void(a.evaluator=m);if(d=c.join(", "),d&&(d="var "+d),/\S/.test(o)){if(!/text|html/.test(a.type))throw Error("ms-"+a.type+"不支持过滤器");e="\nvar ret"+gt+" = "+e+";\r\n",e+=I("ret"+gt,o);try{m=Function.apply(i,u.concat("'use strict';\n"+d+e)),a.evaluator=Bn.put(l,function(){return m.apply(avalon,arguments)})}catch(g){n("debug: parse error,"+g.message)}return void(s=c=u=null)}if("duplex"===r){var y="'use strict';\nreturn function(vvv){\n "+d+";\n if(!arguments.length){\n return "+e+"\n }\n "+(In.test(e)?e:s.get)+"= vvv;\n} ";try{m=Function.apply(i,u.concat(y)),a.evaluator=Bn.put(l,m)}catch(g){n("debug: parse error,"+g.message)}return void(s=c=u=null)}if("on"===r){-1===e.indexOf("(")?e+=".call(this, $event)":e=e.replace("(",".call(this,"),u.push("$event"),e="\nreturn "+e+";";var b=e.lastIndexOf("\nreturn"),$=e.slice(0,b),x=e.slice(b);e=$+"\n"+x}else e="\nreturn "+e+";";try{m=Function.apply(i,u.concat("'use strict';\n"+d+e)),a.evaluator=Bn.put(l,m)}catch(g){n("debug: parse error,"+g.message)}s=c=u=null}}function V(e){var t=Jt.test(e);if(t){var n=K(e);return 1===n.length?n[0].value:n.map(function(e){return e.expr?"("+e.value+")":Nn(e.value)}).join(" + ")}return e}function U(e,t,n,a){e=e||"",F(e,t,n),n.evaluator&&!a&&(n.handler=zt[n.handlerName||n.type],avalon.injectBinding(n))}function z(e,t,n){var a=setTimeout(function(){var r=e.innerHTML;clearTimeout(a),r===n?t():z(e,t,r)})}function q(e,t){var n=e.getAttribute("avalonctrl")||t.$id;e.setAttribute("avalonctrl",n),t.$events.expr=e.tagName+'[avalonctrl="'+n+'"]'}function W(e,t){for(var n,a=0;n=e[a++];)n.vmodels=t,Ut[n.type](n,t),n.evaluator&&n.element&&1===n.element.nodeType&&n.element.removeAttribute(n.name);e.length=0}function X(e,t){return e.priority-t.priority}function Y(e,t,a){var i=!0;if(t.length){for(var o,l=e.attributes,s=[],c=[],u={},f=r(),d=0;o=l[d++];)if(o.specified&&(a=o.name.match(Jn))){var p=a[1],v=a[2]||"",h=o.value,m=o.name;if(u[m])continue;if(u[m]=1,Kn[p]?(v=p,p="on"):ea[p]&&("enabled"===p&&(n("warning!ms-enabled或ms-attr-enabled已经被废弃"),p="disabled",h="!("+h+")"),v=p,p="attr",m="ms-"+p+"-"+v,c.push([o.name,m,h])),f[m]=h,"function"==typeof Ut[p]){var g=h.replace(Zn,""),y=h!==g,b={type:p,param:v,element:e,name:m,value:g,oneTime:y,priority:(Qn[p]||10*p.charCodeAt(0))+(Number(v.replace(/\D/g,""))||0)};if("html"===p||"text"===p){var $=Q(h);avalon.mix(b,$),b.filters=b.filters.replace(aa,function(){return b.type="html",b.group=1,""})}else if("duplex"===p)var x=m;else"ms-if-loop"===m&&(b.priority+=100);s.push(b),"widget"===p&&(e.msData=e.msData||f)}}if(s.length){s.sort(X),c.forEach(function(t){n("warning!请改用"+t[1]+"代替"+t[0]+"!"),e.removeAttribute(t[0]),e.setAttribute(t[1],t[2])});var w=e.type;for(w&&x&&f["ms-attr-value"]&&"text"===e.type&&n("warning!"+w+"控件不能同时定义ms-attr-value与"+x),d=0;b=s[d];d++){if(p=b.type,ta.test(p))return W(s.slice(0,d+1),t);i&&(i=!na.test(p))}W(s,t)}}i&&!Xn[e.tagName]&&Kt.test(e.innerHTML+e.textContent)&&(Gn&&Gn(e),G(e,t))}function G(e,t){var n=avalon.slice(e.childNodes);Z(n,t)}function Z(e,t){for(var n,a=0;n=e[a++];)switch(n.nodeType){case 1:J(n,t),n.msCallback&&(n.msCallback(),n.msCallback=void 0);break;case 3:Jt.test(n.nodeValue)&&et(n,t,a)}}function J(e,t,n){var a=e.getAttribute("ms-skip"),r=e.getAttributeNode("ms-important"),i=e.getAttributeNode("ms-controller");if("string"!=typeof a){if(n=r||i){var o=avalon.vmodels[n.value];if(!o)return;t=n===r?[o]:[o].concat(t),e.removeAttribute(n.name),e.classList.remove(n.name),q(e,o)}Y(e,t)}}function Q(e){if(e.indexOf("|")>0){var t=e.replace(ia,function(e){return Array(e.length+1).join("1")}),n=t.replace(ra,"ᄢ㍄").indexOf("|");if(n>-1)return{filters:e.slice(n),value:e.slice(0,n),expr:!0}}return{value:e,filters:"",expr:!0}}function K(e){for(var t,n,a=[],r=0;;){if(n=e.indexOf(Gt,r),-1===n)break;if(t=e.slice(r,n),t&&a.push({value:t,filters:"",expr:!1}),r=n+Gt.length,n=e.indexOf(Zt,r),-1===n)break;t=e.slice(r,n),t&&a.push(Q(t,r)),r=n+Zt.length}return t=e.slice(r),t&&a.push({value:t,expr:!1,filters:""}),a}function et(e,t,n){var a=[];if(tokens=K(e.data),tokens.length){for(var r=0;token=tokens[r++];){var i=yt.createTextNode(token.value);token.expr&&(token.value=token.value.replace(Zn,function(){return token.oneTime=!0,""}),token.type="text",token.element=i,token.filters=token.filters.replace(aa,function(){return token.type="html",""}),token.pos=1e3*n+r,a.push(token)),_t.appendChild(i)}e.parentNode.replaceChild(_t,e),a.length&&W(a,t)}}function tt(e,t,n){var a=e.templateCache&&e.templateCache[t];if(a){for(var r,i=yt.createDocumentFragment();r=a.firstChild;)i.appendChild(r);return i}return avalon.parseHTML(n)}function nt(e){return null==e?"":e}function at(e,t,n){return t.param.replace(/\w+/g,function(a){var r=avalon.duplexHooks[a];r&&"function"==typeof r[n]&&(e=r[n](e,t))}),e}function rt(){for(var e=ma.length-1;e>=0;e--){var t=ma[e];t()===!1&&ma.splice(e,1)}ma.length||clearInterval(ha)}function it(e,t,n,a){var r=e.template.cloneNode(!0),i=avalon.slice(r.childNodes);r.insertBefore(yt.createComment(e.signature),r.firstChild),t.appendChild(r);var o=[n].concat(e.vmodels),l={nodes:i,vmodels:o};a.push(l)}function ot(e){for(var t,n=[],a=e.element.parentNode.childNodes,r=0;t=a[r++];)if(t.nodeValue===e.signature)n.push(t);else if(t.nodeValue===e.signature+":end")break;return n}function lt(e,t,n){for(;;){var a=t.previousSibling;if(!a)break;if(a.parentNode.removeChild(a),n&&n.call(a),a===e)break}}function st(){var e=d({$key:"",$outer:{},$host:{},$val:{get:function(){return this.$host[this.$key]},set:function(e){this.$host[this.$key]=e}}},{$val:1});return e.$id=It("$proxy$with"),e}function ct(e,t,n){e=e||$a.pop(),e?e.$reinitialize():e=st();var a=n.$repeat;return e.$key=t,e.$host=a,e.$outer=n.$outer,a.$events?e.$events.$val=a.$events[t]:e.$events={},e}function ut(e){ft(e)}function ft(e){e.forEach(function(e){vt(e,xa)}),e.length=0}function dt(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},a=d(t,n);return a.$id=It("$proxy$each"),a}function pt(e,t){for(var n,a=t.param||"el",r=0,i=xa.length;i>r;r++){var o=xa[r];o&&o.hasOwnProperty(a)&&(n=o,xa.splice(r,1))}n||(n=dt(a));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 vt(e,t){for(var n in e.$events){var a=e.$events[n];Array.isArray(a)&&(a.forEach(function(e){"object"==typeof e&&N(e)}),a.length=0)}e.$host=e.$outer={},t.unshift(e)>u.maxRepeatSize&&t.pop()}function ht(e,t){var n="_"+e;if(!ht[n]){var a=yt.createElement(e);Rt.appendChild(a),t=Dt?getComputedStyle(a,null).display:a.currentStyle.display,Rt.removeChild(a),ht[n]=t}return ht[n]}function mt(e,t,n,a){e=(e+"").replace(/[^0-9+\-Ee.]/g,"");var r=isFinite(+e)?+e:0,i=isFinite(+t)?Math.abs(t):3,o=a||",",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(r,i):""+Math.round(r)).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)}var gt=Date.now(),yt=e.document,bt=yt.head;bt.insertAdjacentHTML("afterBegin",'<avalon ms-skip class="avalonHide"><style id="avalonStyle">.avalonHide{ display: none!important }</style></avalon>');var $t,xt=bt.firstChild,wt="$"+gt,Ct=e.require,kt=e.define,Tt=!1,At=/[^, ]+/g,Et=/^(?:object|array)$/,Ot=/^\[object SVG\w*Element\]$/,Mt=/^\[object (?:Window|DOMWindow|global)\]$/,Nt=Object.prototype,jt=Nt.hasOwnProperty,St=Nt.toString,Lt=Array.prototype,Ht=Lt.slice,Dt=e.dispatchEvent,Rt=yt.documentElement,_t=yt.createDocumentFragment(),Pt=yt.createElement("div"),Bt={};"Boolean Number String Function Array Date RegExp Object Error".replace(At,function(e){Bt["[object "+e+"]"]=e.toLowerCase()});var It=function(e){return e=e||"avalon",String(Math.random()+Math.random()).replace(/\d\.\d{4}/,e)},Ft=l();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=r.length,t=0;e>t;t++)r[t]();r=r.slice(e)}var n=e.setImmediate,a=e.MutationObserver;if(n)return n.bind(e);var r=[];if(a){var i=document.createTextNode("avalon");return new a(t).observe(i,{characterData:!0}),function(e){r.push(e),i.data=Math.random()}}return e.VBArray?function(e){r.push(e);var n=yt.createElement("script");n.onreadystatechange=function(){t(),n.onreadystatechange=null,bt.removeChild(n),n=null},bt.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?Bt[St.call(e)]||"object":typeof e};var Vt=function(e){return"[object Function]"===St.call(e)};avalon.isFunction=Vt,avalon.isWindow=function(e){return Mt.test(St.call(e))},avalon.isPlainObject=function(e){return"[object Object]"===St.call(e)&&Object.getPrototypeOf(e)===Nt},avalon.mix=avalon.fn.mix=function(){var e,t,n,a,r,i,o=arguments[0]||{},l=1,s=arguments.length,c=!1;for("boolean"==typeof o&&(c=o,o=arguments[1]||{},l++),"object"==typeof o||Vt(o)||(o={}),l===s&&(o=this,l--);s>l;l++)if(null!=(e=arguments[l]))for(t in e)n=o[t],a=e[t],o!==a&&(c&&a&&(avalon.isPlainObject(a)||(r=Array.isArray(a)))?(r?(r=!1,i=n&&Array.isArray(n)?n:[]):i=n&&avalon.isPlainObject(n)?n:{},o[t]=avalon.mix(c,i,a)):void 0!==a&&(o[t]=a));return o},avalon.mix({rword:At,subscribers:wt,version:1.46,ui:{},log:n,slice:function(e,t,n){return Ht.call(e,t,n)},noop:i,error:function(e,t){throw new(t||Error)(e)},oneObject:o,range:function(e,t,n){n||(n=1),null==t&&(t=e||0,e=0);for(var a=-1,r=Math.max(0,Math.ceil((t-e)/n)),i=new Array(r);++a<r;)i[a]=e,e+=n;return i},eventHooks:{},bind:function(e,t,n,a){var r=avalon.eventHooks,i=r[t];return"object"==typeof i&&(t=i.type,i.deel&&(n=i.deel(e,t,n,a))),n.unbind||e.addEventListener(t,n,!!a),n},unbind:function(e,t,n,a){var r=avalon.eventHooks,o=r[t],l=n||i;"object"==typeof o&&(t=o.type,o.deel&&(n=o.deel(e,t,n,!1))),e.removeEventListener(t,l,!!a)},css:function(e,t,n){e instanceof avalon&&(e=e[0]);var a,r=/[_-]/.test(t)?L(t):t;if(t=avalon.cssName(r)||r,void 0===n||"boolean"==typeof n){a=kn[r+":get"]||kn["@:get"],"background"===t&&(t="backgroundColor");var i=a(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[r]&&(n+="px"),a=kn[r+":set"]||kn["@:set"],a(e,t,n)}},each:function(e,t){if(e){var n=0;if(s(e))for(var a=e.length;a>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(),a={};for(var r in n)0===r.indexOf(t)&&(a[r.replace(t,"").replace(/\w/,function(e){return e.toLowerCase()})]=n[r]);return a},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 Ut=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,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(yt.contains||(Node.prototype.contains=function(e){return!!(16&this.compareDocumentPosition(e))}),avalon.contains=function(e,t){try{for(;t=t.parentNode;)if(t===e)return!0;return!1}catch(n){return!1}},e.SVGElement){var Wt="http://www.w3.org/2000/svg",Xt=yt.createElementNS(Wt,"svg");Xt.innerHTML='<circle cx="50" cy="50" r="40" fill="red" />',Ot.test(Xt.firstChild)||Object.defineProperties(SVGElement.prototype,{outerHTML:{enumerable:!0,configurable:!0,get:function(){return(new XMLSerializer).serializeToString(this)},set:function(e){var t=this.tagName.toLowerCase(),n=this.parentNode,a=avalon.parseHTML(e);if("svg"===t)n.insertBefore(a,this);else{var r=yt.createDocumentFragment();c(a,r),n.insertBefore(r,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);c(t,this)}}}})}var Yt=avalon.eventHooks;"onmouseenter"in Rt||avalon.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){Yt[e]={type:t,deel:function(t,n,a){return function(n){var r=n.relatedTarget;return r&&(r===t||16&t.compareDocumentPosition(r))?void 0:(delete n.type,n.type=e,a.call(t,n))}}}}),avalon.each({AnimationEvent:"animationend",WebKitAnimationEvent:"webkitAnimationEnd"},function(t,n){e[t]&&!Yt.animationend&&(Yt.animationend={type:n})}),void 0===yt.onmousewheel&&(Yt.mousewheel={type:"wheel",deel:function(e,t,n){return function(t){t.wheelDeltaY=t.wheelDelta=t.deltaY>0?-120:120,t.wheelDeltaX=0,Object.defineProperty(t,"type",{value:"mousewheel"}),n.call(e,t)}}});var Gt,Zt,Jt,Qt,Kt,en=/[-.*+?^${}()|[\]\/\\]/g,tn={loader:function(t){var n=$t&&t;e.require=n?$t:Ct,e.define=n?$t.define:kt},interpolate:function(e){if(Gt=e[0],Zt=e[1],Gt===Zt)throw new SyntaxError("openTag===closeTag");var t=Gt+"test"+Zt;if(Pt.innerHTML=t,Pt.innerHTML!==t&&Pt.innerHTML.indexOf("<")>-1)throw new SyntaxError("此定界符不合法");u.openTag=Gt,u.closeTag=Zt,Pt.innerHTML="";var n=f(Gt),a=f(Zt);Jt=new RegExp(n+"(.*?)"+a),Qt=new RegExp(n+"(.*?)"+a,"g"),Kt=new RegExp(n+".*?"+a+"|\\sms-")}};u.debug=!0,u.plugins=tn,u.plugins.interpolate(["{{","}}"]),u.paths={},u.shim={},u.maxRepeatSize=100,avalon.config=u;var nn=function(e){return yt.querySelectorAll(e)},an={$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 a=this.$events[e]||[],r=a.length;~--r<0;)if(a[r]===t)return a.splice(r,1);return this},$fire:function(e){var t,n,a,r;/^(\w+)!(\S+)$/.test(e)&&(t=RegExp.$1,e=RegExp.$2);var i=this.$events;if(i){var o=Ht.call(arguments,1),l=[e].concat(o);if("all"===t)for(n in avalon.vmodels)a=avalon.vmodels[n],a!==this&&a.$fire.apply(a,l);else if("up"===t||"down"===t){var s=i.expr?nn(i.expr):[];if(0===s.length)return;for(n in avalon.vmodels)if(a=avalon.vmodels[n],a!==this&&a.$events.expr){var c=nn(a.$events.expr);if(0===c.length)continue;Lt.forEach.call(c,function(e){Lt.forEach.call(s,function(n){var r="down"===t?n.contains(e):e.contains(n);r&&(e._avalon=a)})})}var u=yt.getElementsByTagName("*"),f=[];for(Lt.forEach.call(u,function(e){e._avalon&&(f.push(e._avalon),e._avalon="",e.removeAttribute("_avalon"))}),"up"===t&&f.reverse(),n=0;(r=f[n++])&&r.$fire.apply(r,l)!==!1;);}else{var d=i[e]||[],p=i.$all||[];for(n=0;r=d[n++];)Vt(r)&&r.apply(this,o);for(n=0;r=p[n++];)Vt(r)&&r.apply(this,arguments)}}}},rn=avalon.vmodels={};avalon.define=function(e,t){var a=e.$id||e;if(a||n("warning: vm必须指定$id"),rn[a]&&n("warning: "+a+" 已经存在于avalon.vmodels中"),"object"==typeof e)var r=d(e);else{var o={$watch:i};t(o),r=d(o),Tt=!0,t(r),Tt=!1}return r.$id=a,rn[a]=r};var on=String("$id,$watch,$unwatch,$fire,$events,$model,$skipArray,$reinitialize").match(At),ln=Object.is||function(e,t){return 0===e&&0===t?1/e===1/t:e!==e?t!==t:e===t},sn=function(e){var t={};for(var n in e)t[n]={get:e[n],set:e[n],enumerable:!0,configurable:!0};return t},cn=Lt.splice,un={_splice:cn,_fire:function(e,t,n){A(this.$events[wt],e,t,n)},size:function(){return this._.length},pushArray:function(e){var t=e.length,n=this.length;return t&&(Lt.push.apply(this.$model,e),C.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&&(Lt.unshift.apply(this.$model,arguments),C.call(this,"add",0,e,0)),e+t},shift:function(){if(this.length){var e=this.$model.shift();return C.call(this,"del",0,1,0),e}},pop:function(){var e=this.length;if(e){var t=this.$model.pop();return C.call(this,"del",e-1,1,Math.max(0,e-2)),t}},splice:function(e){var t,n=arguments.length,a=[],r=cn.apply(this.$model,arguments);return r.length&&(a.push("del",e,r.length,0),t=!0),n>2&&(t?a.splice(3,1,0,"add",e,n-2):a.push("add",e,n-2,0),t=!0),t?C.apply(this,a):[]},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),C.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 a=this[e];if("object"===n)for(var r in t)a.hasOwnProperty(r)&&(a[r]=t[r]);else"array"===n?a.clear().push.apply(a,t):a!==t&&(this[e]=t,this.$model[e]=t,this._fire("set",e,t))}return this}};"sort,reverse".replace(At,function(e){un[e]=function(){var t,n=this.$model,a=n.concat(),r=Math.random(),i=[];Lt[e].apply(n,arguments);for(var o=0,l=a.length;l>o;o++){var s=n[o],c=a[o];if(ln(s,c))i.push(o);else{var u=a.indexOf(s);i.push(u),a[u]=r,t=!0}}return t&&(k(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)}}}(),dn=/^(duplex|on)$/;avalon.injectBinding=function(e){var t=e.evaluator;if(t){fn.begin({callback:function(t,n){T(t.$events[n._name],e)}});try{var a=dn.test(e.type)?e:t.apply(0,e.args);void 0===a&&delete e.evaluator,e.handler(a,e.element,e)}catch(r){n("warning:exception throwed in [avalon.injectBinding] ",r),delete e.evaluator;var i=e.element;if(3===i.nodeType){var o=i.parentNode;u.commentInterpolate?o.replaceChild(yt.createComment(e.value),i):i.data=Gt+(e.oneTime?"::":"")+e.value+Zt}}finally{fn.end()}}};var pn=0,vn=avalon.$$subscribers=[],hn=new Date,mn={},gn=new function(){avalon.mix(this,{option:yt.createElement("select"),thead:yt.createElement("table"),td:yt.createElement("tr"),area:yt.createElement("map"),tr:yt.createElement("tbody"),col:yt.createElement("colgroup"),legend:yt.createElement("fieldset"),_default:yt.createElement("div"),g:yt.createElementNS("http://www.w3.org/2000/svg","svg")}),this.optgroup=this.option,this.tbody=this.tfoot=this.colgroup=this.caption=this.thead,this.th=this.td};String("circle,defs,ellipse,image,line,path,polygon,polyline,rect,symbol,text,use").replace(At,function(e){gn[e]=gn.g});var yn=/<([\w:]+)/,bn=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,$n=o(["","text/javascript","text/ecmascript","application/ecmascript","application/javascript"]),xn=yt.createElement("script"),wn=/<|&#?\w+;/;avalon.parseHTML=function(e){var t=_t.cloneNode(!1);if("string"!=typeof e)return t;if(!wn.test(e))return t.appendChild(yt.createTextNode(e)),t;e=e.replace(bn,"<$1></$2>").trim();var n,a=(yn.exec(e)||["",""])[1].toLowerCase(),r=gn[a]||gn._default;r.innerHTML=e;var i=r.getElementsByTagName("script");if(i.length)for(var o,l=0;o=i[l++];)if($n[o.type]){var s=xn.cloneNode(!1);Lt.forEach.call(o.attributes,function(e){s.setAttribute(e.name,e.value)}),s.text=o.text,o.parentNode.replaceChild(s,o)}for(;n=r.firstChild;)t.appendChild(n);return t},avalon.innerHTML=function(e,t){var n=this.parseHTML(t);this.clearHTML(e).appendChild(n)},avalon.clearHTML=function(e){for(e.textContent="";e.firstChild;)e.removeChild(e.firstChild);return e},"add,remove".replace(At,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){n.classList[e](t)}),this}}),avalon.fn.mix({hasClass:function(e){var t=this[0]||{};return 1===t.nodeType&&t.classList.contains(e)},toggleClass:function(e,t){for(var n,a=0,r=String(e).split(/\s+/),i="boolean"==typeof t;n=r[a++];){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-"+S(e||""),arguments.length){case 2:return this.attr(e,t),this;case 1:var n=this.attr(e);return H(n);case 0:var a={};return Lt.forEach.call(this[0].attributes,function(t){t&&(e=t.name,e.indexOf("data-")||(e=L(e.slice(5)),a[e]=H(t.value)))}),a}},removeData:function(e){return e="data-"+S(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 a=avalon.css(this,e,t);return void 0!==a?a:this},position:function(){var e,t,n=this[0],a={top:0,left:0};if(n)return"fixed"===this.css("position")?t=n.getBoundingClientRect():(e=this.offsetParent(),t=this.offset(),"HTML"!==e[0].tagName&&(a=e.offset()),a.top+=avalon.css(e[0],"borderTopWidth",!0),a.left+=avalon.css(e[0],"borderLeftWidth",!0),a.top-=e.scrollTop(),a.left-=e.scrollLeft()),{top:t.top-a.top-avalon.css(n,"marginTop",!0),left:t.left-a.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,a=n?":get":":set",r=Mn[_(t)+a];if(r)var i=r(t,e);else{if(n)return(t.value||"").replace(/\r/g,"");t.value=e}}return n?i:this}}),Rt.dataset&&(avalon.fn.data=function(e,t){e=e&&L(e);var n=this[0].dataset;switch(arguments.length){case 2:return n[e]=t,this;case 1:return t=n[e],H(t);case 0:var a=r();for(e in n)a[e]=H(n[e]);return a}});var Cn=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/;avalon.parseJSON=JSON.parse,avalon.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(e,t){avalon.fn[e]=function(n){var a=this[0]||{},r=D(a),i="scrollTop"===e;return arguments.length?void(r?r.scrollTo(i?r[t]:n,i?n:r[t]):a[e]=n):r?r[t]:a[e]}});var kn=avalon.cssHooks=r(),Tn=["","-webkit-","-moz-","-ms-"],An={"float":"cssFloat"};avalon.cssNumber=o("animationIterationCount,columnCount,order,flex,flexGrow,flexShrink,fillOpacity,fontWeight,lineHeight,opacity,orphans,widows,zIndex,zoom"),avalon.cssName=function(e,t,n){if(An[e])return An[e];t=t||Rt.style;for(var a=0,r=Tn.length;r>a;a++)if(n=L(Tn[a]+e),n in t)return An[e]=n;
|
2
|
+
return null},kn["@:set"]=function(e,t,n){e.style[t]=n},kn["@:get"]=function(e,t){if(!e||!e.style)throw new Error("getComputedStyle要求传入一个节点 "+e);var n,a=getComputedStyle(e);return a&&(n="filter"===t?a.getPropertyValue(t):a[t],""===n&&(n=e.style[t])),n},kn["opacity:get"]=function(e){var t=kn["@:get"](e,"opacity");return""===t?"1":t},"top,left".replace(At,function(e){kn[e+":get"]=function(t){var n=kn["@:get"](t,e);return/px$/.test(n)?n:avalon(t).position()[e]+"px"}});var En={position:"absolute",visibility:"hidden",display:"block"},On=/^(none|table(?!-c[ea]).+)/;"Width,Height".replace(At,function(e){var t=e.toLowerCase(),n="client"+e,a="scroll"+e,r="offset"+e;kn[t+":get"]=function(t,n,a){var i=-4;"number"==typeof a&&(i=a),n="Width"===e?["Left","Right"]:["Top","Bottom"];var o=t[r];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)},kn[t+"&get"]=function(e){var n=[];R(e,n);for(var a,r=kn[t+":get"](e),i=0;a=n[i++];){e=a.node;for(var o in a)"string"==typeof a[o]&&(e.style[o]=a[o])}return r},avalon.fn[t]=function(i){var o=this[0];if(0===arguments.length){if(o.setTimeout)return o["inner"+e];if(9===o.nodeType){var l=o.documentElement;return Math.max(o.body[a],l[a],o.body[r],l[r],l[n])}return kn[t+"&get"](o)}return this.css(t,i)},avalon.fn["inner"+e]=function(){return kn[t+":get"](this[0],void 0,-2)},avalon.fn["outer"+e]=function(e){return kn[t+":get"](this[0],void 0,e===!0?2:0)}}),avalon.fn.offset=function(){var e=this[0];try{var t=e.getBoundingClientRect();if(t.width||t.height||e.getClientRects().length){var n=e.ownerDocument,a=n.documentElement,r=n.defaultView;return{top:t.top+r.pageYOffset-a.clientTop,left:t.left+r.pageXOffset-a.clientLeft}}}catch(i){return{left:0,top:0}}};var Mn={"select:get":function(e,t){for(var n,a=e.options,r=e.selectedIndex,i="select-one"===e.type||0>r,o=i?null:[],l=i?r+1:a.length,s=0>r?l:i?r:0;l>s;s++)if(n=a[s],(n.selected||s===r)&&!n.disabled){if(t=n.value,i)return t;o.push(t)}return o},"select:set":function(e,t,n){t=[].concat(t);for(var a,r=0;a=e.options[r++];)(a.selected=t.indexOf(a.value)>-1)&&(n=!0);n||(e.selectedIndex=-1)}},Nn=JSON.stringify,jn=["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(","),Sn=/\/\*[\w\W]*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|"(?:[^"\\]|\\[\w\W])*"|'(?:[^'\\]|\\[\w\W])*'|[\s\t\n]*\.[\s\t\n]*[$\w\.]+/g,Ln=/[^\w$]+/g,Hn=new RegExp(["\\b"+jn.replace(/,/g,"\\b|\\b")+"\\b"].join("|"),"g"),Dn=/\b\d[^,]*/g,Rn=/^,+|,+$/g,_n=new qt(512),Pn=function(e){var t=","+e.trim(),n=_n.get(t);if(n)return n;var a=e.replace(Sn,"").replace(Ln,",").replace(Hn,"").replace(Dn,"").replace(Rn,"").split(/^$|,+/);return _n.put(t,B(a))},Bn=new qt(128),In=/\w\[.*\]|\w\.\w/,Fn=/(\$proxy\$[a-z]+)\d+$/,Vn=/\)\s*$/,Un=/\)\s*\|/g,zn=/\|\s*([$\w]+)/g,qn=/"\s*\["/g,Wn=/"\s*\(/g;avalon.parseExprProxy=U,avalon.scan=function(e,t){e=e||Rt;var n=t?[].concat(t):[];J(e,n)};var Xn=o("area,base,basefont,br,col,command,embed,hr,img,input,link,meta,param,source,track,wbr,noscript,script,style,textarea".toUpperCase()),Yn=function(e,t,n){var a=e.getAttribute(t);if(a)for(var r,i=0;r=n[i++];)if(r.hasOwnProperty(a)&&"function"==typeof r[a])return r[a]},Gn=Ft&&e.MutationObserver?function(e){for(var t,n=e.firstChild;n;){var a=n.nextSibling;3===n.nodeType?t?(t.nodeValue+=n.nodeValue,e.removeChild(n)):t=n:t=null,n=a}}:0,Zn=/^\s*::/,Jn=/ms-(\w+)-?(.*)/,Qn={"if":10,repeat:90,data:100,widget:110,each:1400,"with":1500,duplex:2e3,on:3e3},Kn=o("animationend,blur,change,input,click,dblclick,focus,keydown,keypress,keyup,mousedown,mouseenter,mouseleave,mousemove,mouseout,mouseover,mouseup,scan,scroll,submit"),ea=o("value,title,alt,checked,selected,disabled,readonly,enabled"),ta=/^if|widget|repeat$/,na=/^each|with|html|include$/,aa=/\|\s*html(?:\b|$)/,ra=/\|\|/g,ia=/(['"])(\\\1|.)+?\1/g,oa=["autofocus,autoplay,async,allowTransparency,checked,controls","declare,disabled,defer,defaultChecked,defaultSelected","contentEditable,isMap,loop,multiple,noHref,noResize,noShade","open,readOnly,selected"].join(","),la={};oa.replace(At,function(e){la[e.toLowerCase()]=e});var sa={"accept-charset":"acceptCharset","char":"ch",charoff:"chOff","class":"className","for":"htmlFor","http-equiv":"httpEquiv"},ca=["accessKey,bgColor,cellPadding,cellSpacing,codeBase,codeType,colSpan","dateTime,defaultValue,frameBorder,longDesc,maxLength,marginWidth,marginHeight","rowSpan,tabIndex,useMap,vSpace,valueType,vAlign"].join(",");ca.replace(At,function(e){sa[e.toLowerCase()]=e});var ua=/<noscript.*?>(?:[\s\S]+?)<\/noscript>/gim,fa=/<noscript.*?>([\s\S]+?)<\/noscript>/im,da=function(){return new(e.XMLHttpRequest||ActiveXObject)("Microsoft.XMLHTTP")},pa=avalon.templateCache={};Ut.attr=function(e,t){var n=V(e.value.trim());if("include"===e.type){var a=e.element;e.includeRendered=Yn(a,"data-include-rendered",t),e.includeLoaded=Yn(a,"data-include-loaded",t);var r=e.includeReplace=!!avalon(a).data("includeReplace");avalon(a).data("includeCache")&&(e.templateCache={}),e.startInclude=yt.createComment("ms-include"),e.endInclude=yt.createComment("ms-include-end"),r?(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",U(n,t,e)},zt.attr=function(t,n,a){var r=a.type,i=a.param;if("css"===r)avalon(n).css(i,t);else if("attr"===r){var o=t===!1||null===t||void 0===t;!Dt&&sa[i]&&(i=sa[i]);var l=la[i];if("boolean"==typeof n[l]&&(n[l]=!!t,t||(o=!0)),o)return n.removeAttribute(i);var s=Ot.test(n)?!1:yt.namespaces&&isVML(n)?!0:i in n.cloneNode(!1);s?n[i]=t+"":n.setAttribute(i,t)}else if("include"===r&&t){var c=a.vmodels,u=a.includeRendered,f=a.includeLoaded,d=a.includeReplace,p=d?n.parentNode:n,v=function(e){if(f){var n=f.apply(p,[e].concat(c));"string"==typeof n&&(e=n)}u&&z(p,function(){u.call(p)},0/0);var r=a.includeLastID;if(a.templateCache&&r&&r!==t){var i=a.templateCache[r];i||(i=a.templateCache[r]=yt.createElement("div"),xt.appendChild(i))}for(a.includeLastID=t;;){var o=a.startInclude.nextSibling;if(!o||o===a.endInclude)break;p.removeChild(o),i&&i.appendChild(o)}var l=tt(a,t,e),s=avalon.slice(l.childNodes);p.insertBefore(l,a.endInclude),Z(s,c)};if("src"===a.param)if("string"==typeof pa[t])avalon.nextTick(function(){v(pa[t])});else if(Array.isArray(pa[t]))pa[t].push(v);else{var h=da();h.onreadystatechange=function(){if(4===h.readyState){var e=h.status;if(e>=200&&300>e||304===e||1223===e){for(var n,a=h.responseText,r=0;n=pa[t][r++];)n(a);pa[t]=a}}},pa[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:yt.getElementById(t);if(m){if("NOSCRIPT"===m.tagName&&!m.innerHTML&&!m.fixIE78){h=da(),h.open("GET",location,!1),h.send(null);for(var g=yt.getElementsByTagName("noscript"),y=(h.responseText||"").match(ua)||[],b=y.length,$=0;b>$;$++){var x=g[$];x&&(x.style.display="none",x.fixIE78=(y[$].match(fa)||[""," "])[1])}}avalon.nextTick(function(){v(m.fixIE78||m.value||m.innerText||m.innerHTML)})}}}else if(Rt.hasAttribute||"string"!=typeof t||"src"!==r&&"href"!==r||(t=t.replace(/&/g,"&")),n[r]=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(At,function(e){Ut[e]=Ut.attr}),Ut["class"]=function(e,t){var n,a=e.param,r=e.value;if(e.handlerName="class",!a||isFinite(a)){e.param="";var i=r.replace(Qt,function(e){return e.replace(/./g,"0")}).indexOf(":");if(-1===i){var o=r;n=!0}else o=r.slice(0,i),n=r.slice(i+1);o=Jt.test(r)?V(o):Nn(o),e.expr="["+o+","+n+"]"}else e.expr="["+Nn(a)+","+r+"]",e.oldStyle=a;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 d=c.bind("mouseleave",function(){e.toggleClass&&c.removeClass(e.newClass)})}}var p=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",d),c.unbind(u,p),c.unbind(f,v)},e.hasBindEvent=!0}U(e.expr,t,e)},zt["class"]=function(e,t,n){var a=avalon(t);n.newClass=e[0],n.toggleClass=!!e[1],n.oldClass&&n.newClass!==n.oldClass&&a.removeClass(n.oldClass),n.oldClass=n.newClass,"class"===n.type&&(n.oldStyle?a.toggleClass(n.oldStyle,!!e[1]):a.toggleClass(n.newClass,n.toggleClass))},"hover,active".replace(At,function(e){Ut[e]=Ut["class"]}),zt.data=function(e,t,n){var a="data-"+n.param;e&&"object"==typeof e?t[a]=e:t.setAttribute(a,String(e))};var va=Ut.duplex=function(e,t){var a,r=e.element;if(U(e.value,t,e,1),e.changed=Yn(r,"data-duplex-changed",t)||i,e.evaluator&&e.args){var l=[],s=o("string,number,boolean,checked");"radio"===r.type&&""===e.param&&(e.param="checked"),r.msData&&(r.msData["ms-duplex"]=e.value),e.param.replace(/\w+/g,function(t){/^(checkbox|radio)$/.test(r.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){r.addEventListener?r.addEventListener(t,n,!1):r.attachEvent("on"+t,n);var a=e.rollback;e.rollback=function(){r.avalonSetter=null,avalon.unbind(r,t,n),a&&a()}};for(var c in avalon.vmodels){var u=avalon.vmodels[c];u.$fire("avalon-ms-duplex-init",e)}var f=e.pipe||(e.pipe=at);f(null,e,"init");var d=r.tagName;va[d]&&va[d](r,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:nt},"boolean":{get:function(e){return"true"===e},set:nt},number:{get:function(e,t){var n=parseFloat(e);if(-e===-n)return n;var a=/strong|medium|weak/.exec(t.element.getAttribute("data-duplex-number"))||["medium"];switch(a[0]){case"strong":return 0;case"medium":return""===e?"":0;case"weak":return e}},set:nt}};var ha,ma=[];avalon.tick=function(e){1===ma.push(e)&&(ha=setInterval(rt,60))};var ga=i,ya=/text|password|hidden/;!new function(){function e(e){t[this.tagName].call(this,e),ya.test(this.type)&&!this.msFocus&&this.avalonSetter&&this.avalonSetter()}try{var t={},n=HTMLInputElement.prototype,a=HTMLTextAreaElement.prototype,r=HTMLInputElement.prototype;Object.getOwnPropertyNames(r),t.INPUT=Object.getOwnPropertyDescriptor(n,"value").set,Object.defineProperty(n,"value",{set:e}),t.TEXTAREA=Object.getOwnPropertyDescriptor(a,"value").set,Object.defineProperty(a,"value",{set:e})}catch(i){ga=avalon.tick}},va.INPUT=function(e,t,a){function r(e){a.changed.call(this,e,a)}function i(){u=!0}function o(){u=!1}var l=e.type,s=a.bound,c=avalon(e),u=!1,f=function(){var n=e.value;if(!u&&n!==e.oldValue){var i=a.pipe(n,a,"get");c.data("duplexObserve")!==!1&&(t(i),r.call(e,i))}};if(a.handler=function(){var n=a.pipe(t(),a,"set")+"";n!==e.oldValue&&(e.value=e.oldValue=n)},a.isChecked||"radio"===l)f=function(){if(c.data("duplexObserve")!==!1){var n=a.pipe(e.value,a,"get");t(n),r.call(e,n)}},a.handler=function(){var n=t(),r=a.isChecked?!!n:n+""===e.value;e.checked=e.oldValue=r},s("click",f);else if("checkbox"===l)f=function(){if(c.data("duplexObserve")!==!1){var i=e.checked?"ensure":"remove",o=t();Array.isArray(o)||(n("ms-duplex应用于checkbox上要对应一个数组"),o=[o]),avalon.Array[i](o,a.pipe(e.value,a,"get")),r.call(e,o)}},a.handler=function(){var n=[].concat(t());e.checked=n.indexOf(a.pipe(e.value,a,"get"))>-1},s("change",f);else{var d=e.getAttribute("data-duplex-event")||"input";e.attributes["data-event"]&&n("data-event指令已经废弃,请改用data-duplex-event"),d.replace(At,function(e){switch(e){case"input":s("input",f),s("DOMAutoComplete",f),Ft||(s("compositionstart",i),s("compositionend",o));break;default:s(e,f)}}),s("focus",function(){e.msFocus=!0}),s("blur",function(){e.msFocus=!1}),ya.test(l)&&ga(function(){if(Rt.contains(e))e.msFocus||e.oldValue===e.value||f();else if(!e.msRetain)return!1}),e.avalonSetter=f}e.oldValue=e.value,avalon.injectBinding(a),r.call(e,e.value)},va.TEXTAREA=va.INPUT,va.SELECT=function(e,t,a){function r(){if(i.data("duplexObserve")!==!1){var n=i.val();n=Array.isArray(n)?n.map(function(e){return a.pipe(e,a,"get")}):a.pipe(n,a,"get"),n+""!==e.oldValue&&t(n),a.changed.call(e,n,a)}}var i=avalon(e);a.handler=function(){var a=t();a=a&&a.$model||a,Array.isArray(a)?e.multiple||n("ms-duplex在<select multiple=true>上要求对应一个数组"):e.multiple&&n("ms-duplex在<select multiple=false>不能对应一个数组"),a=Array.isArray(a)?a.map(String):a+"",a+""!==e.oldValue&&(i.val(a),e.oldValue=a+"")},a.bound("change",r),e.msCallback=function(){avalon.injectBinding(a),a.changed.call(e,t(),a)}},zt.html=function(e,t,n){var a=1!==t.nodeType,r=a?t.parentNode:t;if(r&&(e=null==e?"":e,n.oldText!==e)){if(n.oldText=e,3===t.nodeType){var i=It("html");r.insertBefore(yt.createComment(i),t),n.element=yt.createComment(i+":end"),r.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=_t.cloneNode(!0);l[0];)o.appendChild(l[0])}if(l=avalon.slice(o.childNodes),a){for(var s=t.nodeValue.slice(0,-4);;){var c=t.previousSibling;if(!c||8===c.nodeType&&c.nodeValue===s)break;r.removeChild(c)}r.insertBefore(o,t)}else avalon.clearHTML(t).appendChild(o);Z(l,n.vmodels)}},Ut["if"]=Ut.data=Ut.text=Ut.html=function(e,t){U(e.value,t,e)},zt["if"]=function(e,t,n){try{if(!t.parentNode)return}catch(a){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),Y(t,n.vmodels)),n.rollback=null;else if(1===t.nodeType){var r=n.element=yt.createComment("ms-if");t.parentNode.replaceChild(r,t),t.ifRemove=r,n.template=t,xt.appendChild(t),n.rollback=function(){t.parentNode===xt&&xt.removeChild(t)}}};var ba=/\(([^)]*)\)/;Ut.on=function(e,t){var n=e.value;e.type="on";var a=e.param.replace(/-\d+$/,"");if("function"==typeof Ut.on[a+"Hook"]&&Ut.on[a+"Hook"](e),n.indexOf("(")>0&&n.indexOf(")")>-1){var r=(n.match(ba)||["",""])[1].trim();(""===r||"$event"===r)&&(n=n.replace(ba,""))}U(n,t,e)},zt.on=function(e,t,n){e=function(e){var t=n.evaluator||i;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 r=avalon.bind(t,a,e);n.rollback=function(){"function"==typeof n.specialUnbind?n.specialUnbind():avalon.unbind(t,a,r)}},Ut.repeat=function(e,t){var n=e.type;U(e.value,t,e,1),e.proxies=[];var a=!1;try{var r=e.$repeat=e.evaluator.apply(0,e.args||[]),i=avalon.type(r);"object"!==i&&"array"!==i?(a=!0,avalon.log("warning:"+e.value+"只能是对象或数组")):e.xtype=i}catch(o){a=!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[wt]=f[wt]||[],f[wt].push(e);break}}var d=e.element;if(1===d.nodeType){d.removeAttribute(e.name),e.sortedCallback=Yn(d,"data-with-sorted",t),e.renderedCallback=Yn(d,"data-"+n+"-rendered",t);var p=It(n),v=yt.createComment(p),h=yt.createComment(p+":end");if(e.signature=p,e.template=_t.cloneNode(!1),"repeat"===n){var m=d.parentNode;m.replaceChild(h,d),m.insertBefore(v,h),e.template.appendChild(d)}else{for(;d.firstChild;)e.template.appendChild(d.firstChild);d.appendChild(v),d.appendChild(h)}e.element=h,e.handler=zt.repeat,e.rollback=function(){var t=e.element;t&&e.handler("clear")}}if(!a){e.$outer={};var g="$key",y="$val";for(Array.isArray(r)&&(g="$first",y="$last"),u=0;s=t[u++];)if(s.hasOwnProperty(g)&&s.hasOwnProperty(y)){e.$outer=s;break}var b=r.$events,$=(b||{})[wt];T($,e),"object"===i?e.handler("append"):r.length&&e.handler("add",0,r.length)}},zt.repeat=function(e,t,n){var a=this;if(!e&&a.xtype){var r=a.$repeat,o=a.evaluator.apply(0,a.args||[]);if("array"===a.xtype){if(r.length===o.length)return;e="add",t=0,a.$repeat=o,n=o.length}else{if(v(r).join(";;")===v(o).join(";;"))return;e="append",a.$repeat=o}}if(e){var l,s,c=a.element,u=ot(a),f=c.parentNode,d=a.proxies,p=_t.cloneNode(!1);switch(e){case"add":for(var h=t+n,m=[],g=t;h>g;g++){var y=pt(g,a);d.splice(g,0,y),it(a,p,y,m)}for(f.insertBefore(p,u[t]||c),g=0;s=m[g++];)Z(s.nodes,s.vmodels),s.nodes=s.vmodels=null;break;case"del":lt(u[t],u[t+n]||c);var b=d.splice(t,n);ut(b,"each");break;case"clear":l=u[0],l&&(lt(l,c),"object"===a.xtype?f.insertBefore(l,c):ut(d,"each"));break;case"move":if(l=u[0]){var $,x=l.nodeValue,w=[],C=[];for(lt(l,c,function(){C.unshift(this),this.nodeValue===x&&(w.unshift(C),C=[])}),k(w,t),k(d,t);C=w.shift();)for(;$=C.shift();)p.appendChild($);f.insertBefore(p,c)}break;case"index":for(var T=d.length-1;n=d[t];t++)n.$index=t,n.$first=0===t,n.$last=t===T;return;case"set":y=d[t],y&&A(y.$events[a.param||"el"]);break;case"append":var E=a.$repeat,O=Array.isArray(d)||!d?{}:d;a.proxies=O;var M=[];m=[];for(var N in O)E.hasOwnProperty(N)||(vt(O[N],$a),delete O[N]);for(N in E)E.hasOwnProperty(N)&&"hasOwnProperty"!==N&&M.push(N);if(a.sortedCallback){var j=a.sortedCallback.call(f,M);j&&Array.isArray(j)&&j.length&&(M=j)}for(g=0;N=M[g++];)"hasOwnProperty"!==N&&(O[N]=ct(O[N],N,a),it(a,p,O[N],m));for(f.insertBefore(p,c),g=0;s=m[g++];)Z(s.nodes,s.vmodels),s.nodes=s.vmodels=null}if(!a.$repeat||a.$repeat.hasOwnProperty("$lock"))return;"clear"===e&&(e="del");var S=a.renderedCallback||i,L=arguments;f.oldValue&&"SELECT"===f.tagName&&avalon(f).val(f.oldValue.split(",")),S.apply(f,L)}},"with,each".replace(At,function(e){Ut[e]=Ut.repeat});var $a=[],xa=[];zt.text=function(e,t){if(e=null==e?"":e,3===t.nodeType)try{t.data=e}catch(n){}else t.textContent=e},avalon.parseDisplay=ht,Ut.visible=function(e,t){U(e.value,t,e)},zt.visible=function(e,t,n){e?(t.style.display=n.display||"","none"===avalon(t).css("display")&&(t.style.display=n.display=ht(t.nodeName))):t.style.display="none"},Ut.widget=function(t,a){var r=t.value.match(At),o=t.element,l=r[0],s=r[1];s&&"$"!==s||(s=It(l));var c=r[2]||l,u=avalon.ui[l];if("function"==typeof u){a=o.vmodels||a;for(var f,d=0;f=a[d++];)if(f.hasOwnProperty(c)&&"object"==typeof f[c]){var p=f[c];p=p.$model||p;break}if(p){var v=p[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=i,o.msData["ms-widget-id"]=s;var m=t[l+"Options"]=avalon.mix({},u.defaults,p||{},h);o.removeAttribute("ms-widget");var g=u(o,t,a)||{};if(g.$id){avalon.vmodels[s]=g,q(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]},O(t,wa),e.chrome&&o.addEventListener("DOMNodeRemovedFromDocument",function(){setTimeout(M)})}else avalon.scan(o,a)}else a.length&&(o.vmodels=a)};var wa=[],Ca=/<script[^>]*>([\S\s]*?)<\/script\s*>/gim,ka=/\s+(on[^=\s]+)(?:=("[^"]*"|'[^']*'|[^\s>]+))?/g,Ta=/<\w+\b(?:(["'])[^"]*?(\1)|[^>])*>/gi,Aa={a:/\b(href)\=("javascript[^"]*"|'javascript[^']*')/gi,img:/\b(src)\=("javascript[^"]*"|'javascript[^']*')/gi,form:/\b(action)\=("javascript[^"]*"|'javascript[^']*')/gi},Ea=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,Oa=/([^\#-~| |!])/g,Ma=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 a=arguments[t],r=avalon.filters[a.shift()];if("function"==typeof r){var i=[e].concat(a);e=r.apply(null,i)}}return e},camelize:L,sanitize:function(e){return e.replace(Ca,"").replace(Ta,function(e){var t=e.toLowerCase().match(/<(\w+)\s/);if(t){var n=Aa[t[1]];n&&(e=e.replace(n,function(e,t,n){var a=n.charAt(0);return t+"="+a+"javascript:void(0)"+a}))}return e.replace(ka," ").replace(/\s+/g," ")})},escape:function(e){return String(e).replace(/&/g,"&").replace(Ea,function(e){var t=e.charCodeAt(0),n=e.charCodeAt(1);return"&#"+(1024*(t-55296)+(n-56320)+65536)+";"}).replace(Oa,function(e){return"&#"+e.charCodeAt(0)+";"}).replace(/</g,"<").replace(/>/g,">")},currency:function(e,t,n){return(t||"¥")+mt(e,isFinite(n)?n:2)},number:mt};!new function(){function e(e){return parseInt(e,10)||0}function t(e,t,n){var a="";for(0>e&&(a="-",e=-e),e=""+e;e.length<t;)e="0"+e;return n&&(e=e.substr(e.length-t)),a+e}function n(e,n,a,r){return function(i){var o=i["get"+e]();return(a>0||o>-a)&&(o+=a),0===o&&-12===a&&(o=12),t(o,n,r)}}function a(e,t){return function(n,a){var r=n["get"+e](),i=(t?"SHORT"+e:e).toUpperCase();return a[i][r]}}function r(e){var n=-1*e.getTimezoneOffset(),a=n>=0?"+":"";return a+=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:a("Month"),MMM:a("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:a("Day"),EEE:a("Day",!0),a:i,Z:r},l=/((?:[^yMdHhmsaZE']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z))(.*)/,s=/^\/Date\((\d+)\)\/$/;Ma.date=function(t,n){var a,r,i=Ma.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(),d=[0,0,0,0,0,0,0],p=new Date(0);f=f.replace(/^(\d+)\D(\d+)\D(\d+)/,function(t,n,a,r){var i=4===r.length?[r,n,a]:[n,a,r];return d[0]=e(i[0]),d[1]=e(i[1])-1,d[2]=e(i[2]),""});var v=p.setFullYear,h=p.setHours;f=f.replace(/[T\s](\d+):(\d+):?(\d+)?\.?(\d)?/,function(t,n,a,r,i){return d[3]=e(n),d[4]=e(a),d[5]=e(r),i&&(d[6]=Math.round(1e3*parseFloat("0."+i))),""});var m=0,g=0;f=f.replace(/Z|([+-])(\d\d):?(\d\d)/,function(t,n,a,r){return v=p.setUTCFullYear,h=p.setUTCHours,n&&(m=e(n+a),g=e(n+r)),""}),d[3]-=m,d[4]-=g,v.apply(p,d.slice(0,3)),h.apply(p,d.slice(3)),t=p}if("number"==typeof t&&(t=new Date(t)),"date"===avalon.type(t)){for(;n;)r=l.exec(n),r?(u=u.concat(r.slice(1)),n=u.pop()):(u.push(n),n=null);return u.forEach(function(e){a=o[e],c+=a?a(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,Ma.date.locate=c};var Na=avalon.modules={"domReady!":{exports:avalon,state:3},avalon:{exports:avalon,state:4}};Na.exports=Na.avalon,new function(){function t(e,t){var a="js";e=e.replace(/^(\w+)\!/,function(e,t){return a=t,""}),"ready"===a&&(n("debug: ready!已经被废弃,请使用domReady!"),a="domReady");var r="";e=e.replace(D,function(e){return r=e,""});var i="."+a,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:r,ext:o,res:a,name:e,toUrl:m},t);return l.toUrl(e),l}function o(e){var t=e.name,n=e.res,a=Na[t],r=t&&e.urlNoQuery;if(a&&a.state>=1)return t;if(a=Na[r],a&&a.state>=3)return $t(a.deps||[],a.factory,r),r;if(t&&!a){a=Na[r]={id:r,state:1};var i=function(r){H[n]=r,r.load(t,e,function(e){arguments.length&&void 0!==e&&(a.exports=e),a.state=4,c()})};H[n]?i(H[n]):$t([n],i)}return t?r:n+"!"}function l(e,t){for(var n,a=0;n=e[a++];)if(4!==Na[n].state&&(n===t||l(Na[n].deps,t)))return!0}function s(e,t){var a=d(e.src);return e.onload=e.onerror=null,t?(setTimeout(function(){bt.removeChild(e),e=null}),void n("debug: 加载 "+a+" 失败"+t+" "+!Na[a].state)):!0}function c(){e:for(var e,t=T.length;e=T[--t];){var n=Na[e],a=n.deps;if(a){for(var r,i=0;r=a[i];i++)if(4!==Object(Na[r]).state)continue e;4!==n.state&&(T.splice(t,1),h(n.id,n.deps,n.factory),c())}}}function f(e,t,a){var r=yt.createElement("script");r.className=wt,r.onload=function(){var r=A.pop();r&&r.require(t),a&&a(),n("debug: 已成功加载 "+e),t&&T.push(t),c()},r.onerror=function(){s(r,!0)},bt.insertBefore(r,bt.firstChild),r.src=e,n("debug: 正准备加载 "+e)}function d(e){return(e||"").replace(D,"")}function p(e){return/^(?:[a-z]+:)?\/\//i.test(String(e))}function v(){var e;try{a.b.c()}catch(t){e=t.stack}if(e)return e=e.split(/[@ ]/g).pop(),e="("===e[0]?e.slice(1,-1):e.replace(/\s/,""),d(e.replace(/(:\d+)?:\d+$/i,""));for(var n,r=bt.getElementsByTagName("script"),i=r.length;n=r[--i];)if(n.className===wt&&"interactive"===n.readyState){var o=n.src;return n.className=d(o)}}function h(t,a,i){var o=Object(Na[t]);o.state=4;for(var l,s=0,c=[];l=a[s++];)if("exports"===l){var u=o.exports||(o.exports=r());c.push(u)}else c.push(Na[l].exports);try{var f=i.apply(e,c)}catch(d){n("执行["+t+"]模块的factory抛错: ",d)}return void 0!==f&&(o.exports=f),R.test(t)&&delete Na[t],delete o.factory,f}function m(e){0===e.indexOf(this.res+"!")&&(e=e.slice(this.res.length+1));var t=e,n=0,a=this.baseUrl,r=this.parentUrl||a;x(e,u.paths,function(e,a){t=t.replace(a,e),n=1}),n||x(e,u.packages,function(e,n,a){t=t.replace(a.name,a.location)}),this.mapUrl&&x(this.mapUrl,u.map,function(e){x(t,e,function(e,n){t=t.replace(n,e),r=a})});var i=this.ext;i&&n&&t.slice(-i.length)===i&&(t=t.slice(0,-i.length)),p(t)||(r=this.built||/^\w/.test(t)?a:r,t=C(r,t));var o=t+i;return t=o+this.query,o=t.replace(D,function(e){return this.query=e,""}),x(e,u.urlArgs,function(e){t+=(-1===t.indexOf("?")?"?":"&")+e}),this.url=t,this.urlNoQuery=o}function g(e,t,n){var a=$(e,t,n);return a.sort(w),a}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 $(e,t,n){var a=[];for(var r in e){var i={name:r,val:e[r]};a.push(i),i.reg="*"===r&&t?/^/:y(r),n&&"*"!==r&&(i.reg=new RegExp("/"+r.replace(/^\//,"")+"(/|$)"))}return a}function x(e,t,n){t=t||[];for(var a,r=0;a=t[r++];)if(a.reg.test(e))return n(a.val,a.name,a),!1}function w(e,t){var n=e.name,a=t.name;return"*"===a?-1:"*"===n?1:a.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;_.test(e);)e=e.replace(_,"");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=[],A=[],E=/\.js$/i,O=[],M=!1;$t=avalon.require=function(e,n,a,l){if(M){Array.isArray(e)||avalon.error("require方法的第一个参数应为数组 "+e);var s=[],f=r(),d=a||"callback"+setTimeout("1");l=l||r(),l.baseUrl=u.baseUrl;var p=!!l.built;if(a&&(l.parentUrl=a.substr(0,a.lastIndexOf("/")),l.mapUrl=a.replace(E,"")),p){var v=t(l.defineName,l);d=v.urlNoQuery}else e.forEach(function(e){var n=t(e,l),a=o(n);a&&(f[a]||(s.push(a),f[a]="司徒正美"))});var h=Na[d];h&&4===h.state||(Na[d]={id:d,deps:p?e.concat():s,factory:n||i,state:3}),h||T.push(d),c()}else if(O.push(avalon.slice(arguments)),arguments.length<=2){M=!0;for(var m,g=O.splice(0,O.length);m=g.shift();)$t.apply(null,m)}},$t.define=function(e,t,n){"string"!=typeof e&&(n=t,t=e,e="anonymous"),Array.isArray(t)||(n=t,t=[]);var a={built:!M,defineName:e},r=[t,n,a];n.require=function(e){if(r.splice(2,0,e),Na[e]){Na[e].state=3;var t=!1;try{t=l(Na[e].deps,e)}catch(a){}t&&avalon.error(e+"模块与之前的模块存在循环依赖,请不要直接用script标签引入"+e+"模块")}delete n.require,$t.apply(null,r)};var i=a.built?"unknown":v();if(i){var o=Na[i];o&&(o.state=2),n.require(i)}else A.push(n)},$t.config=u,$t.define.amd=Na;var N=u["orig.paths"]=r(),j=u["orig.map"]=r(),S=u.packages=[],L=u["orig.args"]=r();avalon.mix(tn,{paths:function(e){avalon.mix(N,e),u.paths=g(N)},map:function(e){avalon.mix(j,e);var t=g(j,1,1);avalon.each(t,function(e,t){t.val=g(t.val)}),u.map=t},packages:function(e){e=e.concat(S);for(var t,n=r(),a=[],i=0;t=e[i++];){t="string"==typeof t?{name:t}:t;var o=t.name;if(!n[o]){var l=C(t.location||o,t.main||"main");l=l.replace(E,""),a.push(t),n[o]=t.location=l,t.reg=y(o)}}u.packages=a.sort()},urlArgs:function(e){"string"==typeof e&&(e={"*":e}),avalon.mix(L,e),u.urlArgs=g(L,1)},baseUrl:function(e){if(!p(e)){var t=bt.getElementsByTagName("base")[0];t&&bt.removeChild(t);var n=yt.createElement("a");n.href=e,e=n.href,t&&bt.insertBefore(t,bt.firstChild)}e.length>3&&(u.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))}u.shim=e}});var H=$t.plugins={ready:{load:i},js:{load:function(e,t,n){var a=t.url,r=t.urlNoQuery,i=u.shim[e.replace(E,"")];i?$t(i.deps||[],function(){var e=avalon.slice(arguments);f(a,r,function(){n(i.exportsFn?i.exportsFn.apply(0,e):void 0)})}):f(a,r)}},css:{load:function(e,t,a){var r=t.url;bt.insertAdjacentHTML("afterBegin",'<link rel="stylesheet" href="'+r+'">'),n("debug: 已成功加载 "+r),a()}},text:{load:function(e,t,a){var r=t.url,i=da();i.onload=function(){var e=i.status;e>399&&600>e?avalon.error(r+" 对应资源不存在或没有开启 CORS"):(n("debug: 已成功加载 "+r),a(i.responseText))};var o="_="+(new Date-0),l=-1===r.indexOf("?")?r+"?"+o:r+"&"+o;i.open("GET",l,!0),"withCredentials"in i&&(i.withCredentials=!0),i.setRequestHeader("X-Requested-With","XMLHttpRequest"),i.send(),n("debug: 正准备加载 "+r)}}};$t.checkDeps=c;var D=/(\?[^#]*)$/,R=/^callback\d+$/,_=/\/\w+\/\.\./,P=yt.scripts[yt.scripts.length-1],B=P.getAttribute("data-main");if(B){tn.baseUrl(B);var I=u.baseUrl;u.baseUrl=I.slice(0,I.lastIndexOf("/")+1),f(I.replace(E,"")+".js")}else{var F=d(P.src);u.baseUrl=F.slice(0,F.lastIndexOf("/")+1)}};var ja,Sa=[],La=function(e){for(ja=!0,$t&&(Na["domReady!"].state=4,$t.checkDeps());e=Sa.shift();)e(avalon)};"complete"===yt.readyState?setTimeout(La):yt.addEventListener("DOMContentLoaded",La),e.addEventListener("load",La),avalon.ready=function(e){ja?e(avalon):Sa.push(e)},avalon.config({loader:!0}),avalon.ready(function(){avalon.scan(yt.body)}),"function"==typeof define&&define.amd&&define("avalon",[],function(){return avalon});var Ha=e.avalon;return avalon.noConflict=function(t){return t&&e.avalon===avalon&&(e.avalon=Ha),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.modern.shim.js(无加载器版本) 1.
|
8
|
+
avalon.modern.shim.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
|
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 (
|
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
|
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
|
-
|
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 (
|
150
|
-
|
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
|
-
|
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
|
-
|
165
|
-
|
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.
|
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
|
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("<") > -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
|
-
|
781
|
-
|
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
|
-
|
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 =
|
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 =
|
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
|
-
|
914
|
-
|
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
|
921
|
-
var
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
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
|
-
|
972
|
-
accessor
|
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
|
-
|
993
|
-
accessor
|
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
|
1002
|
-
//第3种为监控属性,对应简单的数据类型,自变量
|
901
|
+
accessor = makeSimpleAccessor(name, val)
|
1003
902
|
}
|
1004
|
-
|
1005
|
-
|
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(
|
1015
|
-
for (var
|
1016
|
-
|
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
|
1022
|
-
$vmodel
|
1023
|
-
$vmodel
|
1024
|
-
|
1025
|
-
|
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])
|
1026
925
|
}
|
1027
926
|
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
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
|
+
})
|
950
|
+
}
|
951
|
+
$vmodel.$reinitialize()
|
952
|
+
return $vmodel
|
953
|
+
}
|
954
|
+
|
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
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
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
|
1055
|
-
if (
|
1056
|
-
|
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 =
|
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
|
-
|
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
|
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,
|
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
|
-
|
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
|
1224
|
+
var arrayPrototype = {
|
1174
1225
|
_splice: _splice,
|
1175
1226
|
_fire: function (method, a, b) {
|
1176
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
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
|
1362
|
-
|
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
|
-
|
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
|
-
|
1382
|
-
|
1383
|
-
if (
|
1384
|
-
|
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
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
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
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
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
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
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
|
-
|
1420
|
-
|
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
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
var i =
|
1544
|
+
|
1545
|
+
function rejectDisposeQueue(data) {
|
1546
|
+
if (avalon.optimize)
|
1547
|
+
return
|
1548
|
+
var i = disposeQueue.length
|
1427
1549
|
var n = i
|
1428
|
-
var
|
1429
|
-
var
|
1430
|
-
var types = []
|
1550
|
+
var allTypes = []
|
1551
|
+
var iffishTypes = {}
|
1431
1552
|
var newInfo = {}
|
1432
|
-
|
1433
|
-
while (
|
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
|
-
|
1560
|
+
allTypes.push(type)
|
1441
1561
|
}
|
1442
1562
|
}
|
1443
1563
|
var diff = false
|
1444
|
-
|
1564
|
+
allTypes.forEach(function (type) {
|
1445
1565
|
if (oldInfo[type] !== newInfo[type]) {
|
1446
|
-
|
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
|
-
|
1454
|
-
|
1455
|
-
|
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
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
delete
|
1462
|
-
|
1463
|
-
|
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
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
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 =
|
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
|
-
|
1576
|
-
|
1577
|
-
|
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
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
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
|
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 = /</g,
|
1802
|
-
rgt = />/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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
-
|
1988
|
-
|
1989
|
-
|
1990
|
-
|
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
|
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
|
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
|
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
|
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
|
-
|
2075
|
-
|
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
|
2084
|
-
avalon.fn[method] = function
|
1890
|
+
}, function(method, prop) {
|
1891
|
+
avalon.fn[method] = function(val) {
|
2085
1892
|
var node = this[0] || {}, win = getWindow(node),
|
2086
|
-
|
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
|
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
|
1931
|
+
cssHooks["@:set"] = function(node, name, value) {
|
2125
1932
|
node.style[name] = value
|
2126
1933
|
}
|
2127
1934
|
|
2128
|
-
cssHooks["@:get"] = function
|
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
|
-
|
2134
|
-
|
2135
|
-
|
2136
|
-
|
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
|
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
|
2147
|
-
cssHooks[name + ":get"] = function
|
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
|
-
|
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
|
-
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2166
|
-
|
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
|
-
|
2169
|
-
|
2170
|
-
|
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
|
2182
|
-
|
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
|
-
|
2187
|
-
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2191
|
-
|
2192
|
-
|
2193
|
-
|
2194
|
-
|
2195
|
-
|
2196
|
-
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
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;
|
2201
2024
|
}
|
2202
|
-
|
2203
|
-
|
2204
|
-
|
2205
|
-
|
2206
|
-
|
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]
|
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]
|
2213
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)
|
2214
2041
|
}
|
2215
2042
|
}
|
2216
|
-
|
2217
|
-
|
2218
|
-
|
2043
|
+
avalon.fn["inner" + name] = function() {
|
2044
|
+
return cssHooks[method + ":get"](this[0], void 0, -2)
|
2045
|
+
}
|
2046
|
+
avalon.fn["outer" + name] = function(includeMargin) {
|
2047
|
+
return cssHooks[method + ":get"](this[0], void 0, includeMargin === true ? 2 : 0)
|
2048
|
+
}
|
2049
|
+
})
|
2050
|
+
avalon.fn.offset = function() { //取得距离页面左右角的坐标
|
2219
2051
|
var node = this[0]
|
2220
|
-
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2224
|
-
if (
|
2225
|
-
var doc = node.
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2229
|
-
|
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
|
2063
|
+
}
|
2230
2064
|
}
|
2231
|
-
|
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
|
-
|
2255
|
-
|
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(
|
2268
|
-
|
2269
|
-
|
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
|
2079
|
+
"select:get": function(node, value) {
|
2273
2080
|
var option, options = node.options,
|
2274
|
-
|
2275
|
-
|
2276
|
-
|
2277
|
-
|
2278
|
-
|
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
|
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
|
2133
|
+
var variablePool = new Cache(512)
|
2328
2134
|
var getVariables = function (code) {
|
2329
2135
|
var key = "," + code.trim()
|
2330
|
-
var ret =
|
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
|
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
|
2180
|
+
var evaluatorPool = new Cache(128)
|
2375
2181
|
//取得求值函数及其传参
|
2376
2182
|
var rduplex = /\w\[.*\]|\w\.\w/
|
2377
2183
|
var rproxy = /(\$proxy\$[a-z]+)\d+$/
|
@@ -2395,7 +2201,7 @@ function parseFilter(val, filters) {
|
|
2395
2201
|
.replace(rthimLeftParentheses, function () {
|
2396
2202
|
return '",'
|
2397
2203
|
}) + "]"
|
2398
|
-
return "return
|
2204
|
+
return "return this.filters.$filter(" + val + ", " + filters + ")"
|
2399
2205
|
}
|
2400
2206
|
|
2401
2207
|
function parseExpr(code, scopes, data) {
|
@@ -2427,9 +2233,11 @@ function parseExpr(code, scopes, data) {
|
|
2427
2233
|
//https://github.com/RubyLouvre/avalon/issues/583
|
2428
2234
|
data.vars.forEach(function (v) {
|
2429
2235
|
var reg = new RegExp("\\b" + v + "(?:\\.\\w+|\\[\\w+\\])+", "ig")
|
2430
|
-
code = code.replace(reg, function (_) {
|
2236
|
+
code = code.replace(reg, function (_, cap) {
|
2431
2237
|
var c = _.charAt(v.length)
|
2432
|
-
var r = IEVersion ? code.slice(arguments[1] + _.length) : RegExp.rightContext
|
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)
|
2433
2241
|
var method = /^\s*\(/.test(r)
|
2434
2242
|
if (c === "." || c === "[" || method) {//比如v为aa,我们只匹配aa.bb,aa[cc],不匹配aaa.xxx
|
2435
2243
|
var name = "var" + String(Math.random()).replace(/^0\./, "")
|
@@ -2454,7 +2262,8 @@ function parseExpr(code, scopes, data) {
|
|
2454
2262
|
//---------------args----------------
|
2455
2263
|
data.args = args
|
2456
2264
|
//---------------cache----------------
|
2457
|
-
|
2265
|
+
delete data.vars
|
2266
|
+
var fn = evaluatorPool.get(exprId) //直接从缓存,免得重复生成
|
2458
2267
|
if (fn) {
|
2459
2268
|
data.evaluator = fn
|
2460
2269
|
return
|
@@ -2469,6 +2278,16 @@ function parseExpr(code, scopes, data) {
|
|
2469
2278
|
}
|
2470
2279
|
code = "\nvar ret" + expose + " = " + code + ";\r\n"
|
2471
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
|
2472
2291
|
} else if (dataType === "duplex") { //双工绑定
|
2473
2292
|
var _body = "'use strict';\nreturn function(vvv){\n\t" +
|
2474
2293
|
prefix +
|
@@ -2478,10 +2297,11 @@ function parseExpr(code, scopes, data) {
|
|
2478
2297
|
"= vvv;\n} "
|
2479
2298
|
try {
|
2480
2299
|
fn = Function.apply(noop, names.concat(_body))
|
2481
|
-
data.evaluator =
|
2300
|
+
data.evaluator = evaluatorPool.put(exprId, fn)
|
2482
2301
|
} catch (e) {
|
2483
2302
|
log("debug: parse error," + e.message)
|
2484
2303
|
}
|
2304
|
+
vars = assigns = names = null //释放内存
|
2485
2305
|
return
|
2486
2306
|
} else if (dataType === "on") { //事件绑定
|
2487
2307
|
if (code.indexOf("(") === -1) {
|
@@ -2500,37 +2320,377 @@ function parseExpr(code, scopes, data) {
|
|
2500
2320
|
}
|
2501
2321
|
try {
|
2502
2322
|
fn = Function.apply(noop, names.concat("'use strict';\n" + prefix + code))
|
2503
|
-
data.evaluator =
|
2323
|
+
data.evaluator = evaluatorPool.put(exprId, fn)
|
2504
2324
|
} catch (e) {
|
2505
2325
|
log("debug: parse error," + e.message)
|
2506
|
-
} finally {
|
2507
|
-
vars = assigns = names = null //释放内存
|
2508
2326
|
}
|
2327
|
+
vars = assigns = names = null //释放内存
|
2509
2328
|
}
|
2510
|
-
|
2511
|
-
|
2512
|
-
|
2513
|
-
|
2514
|
-
|
2515
|
-
|
2516
|
-
|
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) {
|
2517
2337
|
return el.expr ? "(" + el.value + ")" : quote(el.value)
|
2518
2338
|
}).join(" + ")
|
2339
|
+
} else {
|
2340
|
+
return code
|
2519
2341
|
}
|
2342
|
+
}
|
2343
|
+
//parseExpr的智能引用代理
|
2344
|
+
|
2345
|
+
function parseExprProxy(code, scopes, data, noRegister) {
|
2346
|
+
code = code || "" //code 可能未定义
|
2520
2347
|
parseExpr(code, scopes, data)
|
2521
|
-
if (data.evaluator && !
|
2348
|
+
if (data.evaluator && !noRegister) {
|
2522
2349
|
data.handler = bindingExecutors[data.handlerName || data.type]
|
2523
2350
|
//方便调试
|
2524
2351
|
//这里非常重要,我们通过判定视图刷新函数的element是否在DOM树决定
|
2525
2352
|
//将它移出订阅者列表
|
2526
|
-
|
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
|
+
}
|
2546
|
+
}
|
2547
|
+
|
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
|
2570
|
+
}
|
2571
|
+
}
|
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") {
|
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)
|
2593
|
+
}
|
2594
|
+
scanAttr(elem, vmodels) //扫描特性节点
|
2595
|
+
}
|
2596
|
+
var rhasHtml = /\|\s*html(?:\b|$)/,
|
2597
|
+
r11a = /\|\|/g,
|
2598
|
+
rlt = /</g,
|
2599
|
+
rgt = />/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
|
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
|
+
}
|
2614
|
+
}
|
2615
|
+
return {
|
2616
|
+
value: value,
|
2617
|
+
filters: "",
|
2618
|
+
expr: true
|
2619
|
+
}
|
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
|
2630
|
+
}
|
2631
|
+
value = str.slice(start, stop)
|
2632
|
+
if (value) { // {{ 左边的文本
|
2633
|
+
tokens.push({
|
2634
|
+
value: value,
|
2635
|
+
filters: "",
|
2636
|
+
expr: false
|
2637
|
+
})
|
2638
|
+
}
|
2639
|
+
start = stop + openTag.length
|
2640
|
+
stop = str.indexOf(closeTag, start)
|
2641
|
+
if (stop === -1) {
|
2642
|
+
break
|
2643
|
+
}
|
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
|
+
})
|
2657
|
+
}
|
2658
|
+
return tokens
|
2659
|
+
}
|
2660
|
+
|
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
|
-
|
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"
|
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"
|
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
|
2723
|
+
var templatePool = avalon.templateCache = {}
|
2563
2724
|
|
2564
2725
|
bindingHandlers.attr = function (data, vmodels) {
|
2565
|
-
var
|
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(
|
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
|
-
|
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 (
|
2825
|
+
if (typeof templatePool[val] === "string") {
|
2670
2826
|
avalon.nextTick(function () {
|
2671
|
-
scanTemplate(
|
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
|
-
|
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(),
|
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
|
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(
|
2749
|
-
var oldStyle =
|
2750
|
-
text =
|
2912
|
+
bindingHandlers["class"] = function (binding, vmodels) {
|
2913
|
+
var oldStyle = binding.param,
|
2914
|
+
text = binding.value,
|
2751
2915
|
rightExpr
|
2752
|
-
|
2916
|
+
binding.handlerName = "class"
|
2753
2917
|
if (!oldStyle || isFinite(oldStyle)) {
|
2754
|
-
|
2755
|
-
var
|
2918
|
+
binding.param = "" //去掉数字
|
2919
|
+
var colonIndex = text.replace(rexprg, function (a) {
|
2756
2920
|
return a.replace(/./g, "0")
|
2757
|
-
|
2758
|
-
})
|
2759
|
-
var colonIndex = noExpr.indexOf(":") //取得第一个冒号的位置
|
2921
|
+
}).indexOf(":") //取得第一个冒号的位置
|
2760
2922
|
if (colonIndex === -1) { // 比如 ms-class="aaa bbb ccc" 的情况
|
2761
2923
|
var className = text
|
2762
|
-
|
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
|
-
|
2775
|
-
|
2776
|
-
|
2929
|
+
if (!rexpr.test(text)) {
|
2930
|
+
className = quote(className)
|
2931
|
+
} else {
|
2932
|
+
className = stringifyExpr(className)
|
2777
2933
|
}
|
2778
|
-
|
2934
|
+
binding.expr = "[" + className + "," + rightExpr + "]"
|
2779
2935
|
} else {
|
2780
|
-
|
2781
|
-
|
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
|
2786
|
-
var $elem = avalon(elem)
|
2787
|
-
|
2788
|
-
|
2789
|
-
|
2790
|
-
|
2791
|
-
|
2792
|
-
|
2793
|
-
|
2794
|
-
if (
|
2795
|
-
$elem.
|
2796
|
-
}
|
2797
|
-
|
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
|
-
|
2843
|
-
|
2844
|
-
|
2845
|
-
|
2846
|
-
|
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
|
3007
|
+
var duplexBinding = bindingHandlers.duplex = function(data, vmodels) {
|
2852
3008
|
var elem = data.element,
|
2853
|
-
|
2854
|
-
|
3009
|
+
hasCast
|
3010
|
+
parseExprProxy(data.value, vmodels, data, 1)
|
2855
3011
|
|
2856
|
-
|
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
|
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
|
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
|
-
|
2914
|
-
|
2915
|
-
|
3069
|
+
|
3070
|
+
function fixNull(val) {
|
3071
|
+
return val == null ? "" : val
|
3072
|
+
}
|
2916
3073
|
avalon.duplexHooks = {
|
2917
3074
|
checked: {
|
2918
|
-
get: function
|
3075
|
+
get: function(val, data) {
|
2919
3076
|
return !data.element.oldValue
|
2920
3077
|
}
|
2921
3078
|
},
|
2922
3079
|
string: {
|
2923
|
-
get: function
|
3080
|
+
get: function(val) { //同步到VM
|
2924
3081
|
return val
|
2925
3082
|
},
|
2926
3083
|
set: fixNull
|
2927
3084
|
},
|
2928
3085
|
"boolean": {
|
2929
|
-
get: function
|
3086
|
+
get: function(val) {
|
2930
3087
|
return val === "true"
|
2931
3088
|
},
|
2932
3089
|
set: fixNull
|
2933
3090
|
},
|
2934
3091
|
number: {
|
2935
|
-
get: function
|
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
|
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
|
2967
|
-
|
2968
|
-
|
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
|
-
|
2974
|
-
|
2975
|
-
|
2976
|
-
|
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
|
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 (
|
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
|
3015
|
-
|
3016
|
-
|
3171
|
+
} // jshint ignore:line
|
3017
3172
|
//处理radio, checkbox, text, textarea, password
|
3018
|
-
duplexBinding.INPUT = function
|
3173
|
+
duplexBinding.INPUT = function(element, evaluator, data) {
|
3019
3174
|
var $type = element.type,
|
3020
|
-
|
3021
|
-
|
3022
|
-
composing = false
|
3023
|
-
function callback(value) {
|
3024
|
-
data.changed.call(this, value, data)
|
3025
|
-
}
|
3026
|
-
function compositionStart() {
|
3027
|
-
composing = true
|
3028
|
-
}
|
3029
|
-
function compositionEnd() {
|
3175
|
+
bound = data.bound,
|
3176
|
+
$elem = avalon(element),
|
3030
3177
|
composing = false
|
3031
|
-
}
|
3032
|
-
//当value变化时改变model的值
|
3033
3178
|
|
3034
|
-
|
3035
|
-
|
3179
|
+
function callback(value) {
|
3180
|
+
data.changed.call(this, value, data)
|
3181
|
+
}
|
3182
|
+
|
3183
|
+
function compositionStart() {
|
3184
|
+
composing = true
|
3185
|
+
}
|
3186
|
+
|
3187
|
+
function compositionEnd() {
|
3188
|
+
composing = false
|
3189
|
+
}
|
3190
|
+
//当value变化时改变model的值
|
3191
|
+
|
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("
|
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("
|
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("
|
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
|
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
|
-
|
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
|
-
|
3137
|
-
|
3138
|
-
|
3139
|
-
|
3140
|
-
|
3141
|
-
|
3142
|
-
|
3143
|
-
|
3144
|
-
|
3145
|
-
|
3146
|
-
|
3147
|
-
|
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
|
-
|
3173
|
-
|
3326
|
+
element.msCallback = function() {
|
3327
|
+
avalon.injectBinding(data)
|
3174
3328
|
data.changed.call(element, evaluator(), data)
|
3175
|
-
}
|
3329
|
+
}
|
3176
3330
|
}
|
3177
|
-
|
3178
|
-
|
3179
3331
|
// bindingHandlers.html 定义在if.js
|
3180
|
-
bindingExecutors.html = function(val, elem, data) {
|
3181
|
-
|
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
|
-
|
3187
|
-
|
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
|
3190
|
-
fragment =
|
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
|
-
|
3201
|
-
|
3202
|
-
|
3203
|
-
|
3204
|
-
|
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.
|
3210
|
-
data.element = comment //防止被CG
|
3374
|
+
parent.insertBefore(fragment, elem)
|
3211
3375
|
} else {
|
3212
|
-
avalon.clearHTML(
|
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
|
-
|
3230
|
-
|
3231
|
-
|
3232
|
-
|
3233
|
-
|
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,
|
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.
|
3339
|
-
|
3340
|
-
|
3341
|
-
|
3342
|
-
|
3343
|
-
|
3344
|
-
|
3345
|
-
|
3346
|
-
|
3347
|
-
|
3348
|
-
|
3349
|
-
|
3350
|
-
|
3351
|
-
|
3352
|
-
|
3353
|
-
|
3354
|
-
|
3355
|
-
|
3356
|
-
|
3357
|
-
|
3358
|
-
|
3359
|
-
|
3360
|
-
|
3361
|
-
|
3362
|
-
|
3363
|
-
|
3364
|
-
|
3365
|
-
|
3366
|
-
|
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
|
-
|
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
|
-
|
3388
|
-
addSubscribers(data, $list)
|
3389
|
-
}
|
3546
|
+
injectDependency($list, data)
|
3390
3547
|
if (xtype === "object") {
|
3391
|
-
data
|
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
|
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 =
|
3582
|
+
var transation = avalonFragment.cloneNode(false)
|
3406
3583
|
switch (method) {
|
3407
|
-
case "add": //在pos位置后添加el数组(pos
|
3584
|
+
case "add": //在pos位置后添加el数组(pos为插入位置,el为要插入的个数)
|
3408
3585
|
var n = pos + el
|
3409
|
-
var
|
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,
|
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
|
-
|
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
|
-
|
3433
|
-
if (
|
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 =
|
3441
|
-
|
3442
|
-
|
3443
|
-
|
3444
|
-
|
3445
|
-
|
3446
|
-
|
3447
|
-
|
3448
|
-
|
3449
|
-
|
3450
|
-
|
3451
|
-
|
3452
|
-
|
3453
|
-
|
3454
|
-
|
3455
|
-
|
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
|
-
|
3650
|
+
fireDependencies(proxy.$events[data.param || "el"])
|
3472
3651
|
}
|
3473
|
-
|
3474
|
-
case "append":
|
3475
|
-
var
|
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
|
3479
|
-
if (
|
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
|
-
|
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
|
-
|
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
|
-
|
3511
|
-
|
3512
|
-
|
3513
|
-
|
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
|
-
|
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
|
3539
|
-
var
|
3540
|
-
|
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
|
-
|
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
|
-
|
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",
|
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.$
|
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
|
3638
|
-
var
|
3639
|
-
|
3640
|
-
|
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
|
-
|
3643
|
-
proxy
|
3644
|
-
|
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
|
-
|
3687
|
-
|
3688
|
-
|
3689
|
-
|
3690
|
-
|
3691
|
-
|
3692
|
-
|
3693
|
-
|
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,
|
3736
|
-
|
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
|
-
|
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
|
-
|
3789
|
-
}
|
3986
|
+
vmodel.widgetElement = null // 放到$remove后边
|
3987
|
+
} catch (e) {}
|
3790
3988
|
elem.msData = {}
|
3791
3989
|
delete avalon.vmodels[vmodel.$id]
|
3792
3990
|
}
|
3793
|
-
|
3991
|
+
injectDisposeQueue(data, widgetList)
|
3794
3992
|
if (window.chrome) {
|
3795
3993
|
elem.addEventListener("DOMNodeRemovedFromDocument", function() {
|
3796
|
-
setTimeout(
|
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 ===
|
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) {
|
@@ -4156,33 +4354,33 @@ new function() {// jshint ignore:line
|
|
4156
4354
|
/*********************************************************************
|
4157
4355
|
* END *
|
4158
4356
|
**********************************************************************/
|
4159
|
-
new function() {
|
4357
|
+
new function () {
|
4160
4358
|
avalon.config({
|
4161
4359
|
loader: false
|
4162
4360
|
})
|
4163
|
-
var fns = [],
|
4361
|
+
var fns = [], loaded = DOC.readyState === "complete", fn
|
4164
4362
|
function flush(f) {
|
4165
4363
|
loaded = 1
|
4166
4364
|
while (f = fns.shift())
|
4167
4365
|
f()
|
4168
4366
|
}
|
4169
|
-
|
4170
|
-
|
4171
|
-
|
4367
|
+
|
4368
|
+
avalon.bind(DOC, "DOMContentLoaded", fn = function () {
|
4369
|
+
avalon.unbind(DOC, "DOMContentLoaded", fn)
|
4370
|
+
flush()
|
4371
|
+
})
|
4372
|
+
|
4373
|
+
var id = setInterval(function () {
|
4374
|
+
if (document.readyState === "complete" && document.body) {
|
4375
|
+
clearInterval(id)
|
4172
4376
|
flush()
|
4173
|
-
}
|
4174
|
-
}
|
4175
|
-
|
4176
|
-
|
4177
|
-
clearInterval(id)
|
4178
|
-
flush()
|
4179
|
-
}
|
4180
|
-
}, 50)
|
4181
|
-
}
|
4182
|
-
avalon.ready = function(fn) {
|
4377
|
+
}
|
4378
|
+
}, 50)
|
4379
|
+
|
4380
|
+
avalon.ready = function (fn) {
|
4183
4381
|
loaded ? fn(avalon) : fns.push(fn)
|
4184
4382
|
}
|
4185
|
-
avalon.ready(function() {
|
4383
|
+
avalon.ready(function () {
|
4186
4384
|
avalon.scan(DOC.body)
|
4187
4385
|
})
|
4188
4386
|
}
|
@@ -4218,6 +4416,7 @@ new function() {
|
|
4218
4416
|
if (noGlobal === void 0) {
|
4219
4417
|
window.avalon = avalon
|
4220
4418
|
}
|
4419
|
+
|
4221
4420
|
return avalon
|
4222
4421
|
|
4223
4422
|
}));
|