From 26b2f647f96fa2876c6f4789ed4b36e58c2a4c9f Mon Sep 17 00:00:00 2001 From: TANG <40519806@qq.com> Date: Fri, 23 Dec 2016 13:44:12 +0800 Subject: [PATCH] Released on 20161223. --- dist/mvvm.js | 103 ++++++++++++++++++++++++++++++++++------------ dist/mvvm.min.js | 6 +-- dist/sugar.js | 103 ++++++++++++++++++++++++++++++++++------------ dist/sugar.min.js | 8 ++-- 4 files changed, 161 insertions(+), 59 deletions(-) diff --git a/dist/mvvm.js b/dist/mvvm.js index c6861e7a..f3331ab1 100644 --- a/dist/mvvm.js +++ b/dist/mvvm.js @@ -1,7 +1,7 @@ /*! - * mvvm.js v1.3.7 (c) 2016 TANG + * mvvm.js v1.3.8 (c) 2016 TANG * Released under the MIT license - * Sat Dec 10 2016 09:54:56 GMT+0800 (CST) + * Fri Dec 23 2016 13:44:08 GMT+0800 (CST) */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : @@ -1546,7 +1546,6 @@ return; } - // 未指定参数,则原生事件对象作为唯一参数 if (!args.length) { args.push(e); @@ -1927,6 +1926,7 @@ var vforAlias = '__vfor__'; var vforGuid = '__vforid__'; + var vforDirIds = '__vfordirids__'; var regForExp = /(.*) (?:in|of) (.*)/; var partlyMethods = 'push|pop|shift|unshift|splice'.split('|'); @@ -2043,6 +2043,14 @@ } } + /** + * 移除该选项中的所有指令实例 + * @param {Element} frag + */ + vfor.dropDirectives = function (frag) { + this.vm.dropDirective(frag[vforDirIds]); + } + /** * 更新视图 * @param {Array} newArray [新数组] @@ -2124,8 +2132,7 @@ for (var i = 0; i < childs.length; i++) { var child = childs[i]; if (child[vforAlias] === this$1.alias) { - this$1.hook('before', child, count++); - parent.removeChild(child); + this$1.removeChild(child, count++); i--; } } @@ -2186,7 +2193,10 @@ def(frag, vforGuid, makeVforGuid()); // 编译片段 - vm.compile(frag, true, scope, this.desc.once); + var dirIds = vm.compile(frag, true, scope, this.desc.once); + + // 挂载指令 id 集合,以便销毁内存占用 + def(frag, vforDirIds, dirIds); listFragment.appendChild(frag); @@ -2247,9 +2257,12 @@ /** * 删除一条选项 * @param {Element} child + * @param {Number} index */ - vfor.removeChild = function (child) { + vfor.removeChild = function (child, index) { if (child) { + this.dropDirectives(child); + this.hook('before', child, index); this.$parent.removeChild(child); } } @@ -2260,8 +2273,7 @@ vfor.shift = function () { var first = this.getFirst(); if (first) { - this.hook('before', first, 0); - this.removeChild(first); + this.removeChild(first, 0); } } @@ -2271,8 +2283,7 @@ vfor.pop = function () { var last = this.getLast(); if (last) { - this.hook('before', last, this.length); - this.removeChild(last); + this.removeChild(last, this.length); } } @@ -2331,8 +2342,7 @@ each(oldList, function (child, index) { // 删除范围内 if (index >= start && index < start + deleteCont) { - this.hook('before', child, index); - this.removeChild(child); + this.removeChild(child, index); } }, this); oldList = null; @@ -2428,7 +2438,9 @@ } this.$parent = parent; - + // 指令实例 id 缓存 + this.$dirIds = null; + this.$elseDirIds = null; // 状态钩子 this.hooks = getHooks(this.vm, el); @@ -2490,16 +2502,24 @@ // 渲染 & 更新视图 if (isRender) { - vm.compile(tpl, true, this.scope, this.desc.once); + var dirIds = vm.compile(tpl, true, this.scope, this.desc.once); var insert = parent.insertBefore(tpl, anchor); this.hook('after', insert, isElse); def(insert, '__vif__', true); + + if (isElse) { + this.$elseDirIds = dirIds; + } else { + this.$dirIds = dirIds; + } } // 不渲染的情况需要移除 DOM 索引的引用 else { var el = anchor.previousSibling; if (el && el.__vif__) { this.hook('before', el, isElse); + var dirIds$1 = isElse ? this.$elseDirIds : this.dirIds; + vm.dropDirective(dirIds$1); removeDOMRegister(vm, template); parent.removeChild(el); } @@ -3455,8 +3475,12 @@ this.$element = element; // DOM 注册索引 this.$regEles = {}; + // 指令实例唯一 id + this.$dirGuid = 1000; + // 指令 id 集合 + this.$dirGuids = []; // 指令实例缓存 - this.$directives = []; + this.$directives = {}; // 钩子和统一回调作用域 this.$context = option.context || this; @@ -3507,8 +3531,11 @@ var children = element.childNodes; var parentOnce = !!once || isOnceNode(element); - if (root && hasDirective(element)) { - this.$queue.push([element, scope]); + if (root) { + this.$dirGuids.length = 0; + if (hasDirective(element)) { + this.$queue.push([element, scope]); + } } def(element, '__vonce__', parentOnce); @@ -3536,6 +3563,7 @@ if (root) { this.compileAll(); + return this.$dirGuids.slice(0); } } @@ -3544,7 +3572,7 @@ */ cp.compileAll = function () { each(this.$queue, function (tuple) { - this.complieNode(tuple); + this.compileNode(tuple); return null; }, this); @@ -3555,7 +3583,7 @@ * 收集并编译节点指令 * @param {Array} tuple [node, scope] */ - cp.complieNode = function (tuple) { + cp.compileNode = function (tuple) { var node = tuple[0]; var scope = tuple[1]; @@ -3646,7 +3674,7 @@ if (once) { dirParser.destroy(); } else { - this.$directives.push(dirParser); + this.saveDirective(dirParser); } } else { warn('[' + directive + '] is an unknown directive!'); @@ -3684,10 +3712,36 @@ if (once) { directive.destroy(); } else { - this.$directives.push(directive); + this.saveDirective(directive); } } + /** + * 缓存一个指令实例到队列 + * @param {Directive} directive [已编译的指令实例] + */ + cp.saveDirective = function (directive) { + var guid = this.$dirGuid++; + this.$dirGuids.push(guid); + this.$directives[guid] = directive; + } + + /** + * 移除指令实例 + * @param {Array} guids [指令实例 id 集合] + */ + cp.dropDirective = function (guids) { + var directives = this.$directives; + each(guids, function (guid) { + var directive = directives[guid]; + if (directive) { + directive.destroy(); + delete directives[guid]; + return null; + } + }, this); + } + /** * 停止编译节点的剩余指令 * 如含有其他指令的 vfor 节点 @@ -3733,10 +3787,7 @@ cp.destroy = function () { this.$data = null; empty(this.$element); - each(this.$directives, function (directive) { - directive.destroy(); - return null; - }); + this.dropDirective(Object.keys(this.$directives)); } /** diff --git a/dist/mvvm.min.js b/dist/mvvm.min.js index 777a3ff3..10b30d77 100644 --- a/dist/mvvm.min.js +++ b/dist/mvvm.min.js @@ -1,6 +1,6 @@ /*! - * mvvm.js v1.3.7 (c) 2016 TANG + * mvvm.js v1.3.8 (c) 2016 TANG * Released under the MIT license - * Sat Dec 10 2016 09:54:59 GMT+0800 (CST) + * Fri Dec 23 2016 13:44:11 GMT+0800 (CST) */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.MVVM=e()}(this,function(){"use strict";function t(t,e){return typeof t===e}function e(t){return"[object Object]"===ee.toString.call(t)}function n(t){return Array.isArray(t)}function i(e){return t(e,"function")}function s(e){return t(e,"string")}function r(e){return t(e,"boolean")}function o(e){return t(e,"number")&&!isNaN(e)}function h(t){return!(!t||!e(t)||t.nodeType||t===t.window)&&!(t.constructor&&!ne.call(t.constructor.prototype,"isPrototypeOf"))}function u(t){return 0===Object.keys(t).length}function a(t){return null==t?"":t.toString()}function c(t){if(s(t)){var e=Number(t);return o(e)?e:t}return t}function f(){}function l(){ie&&ie.warn.apply(ie,arguments)}function d(){ie&&ie.error.apply(ie,arguments)}function p(t,e){return t&&ne.call(t,e)}function v(t,e,n,i){return Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!!i,configurable:!0})}function _(t,i,s){var r,o;if(s||(s=this),n(t))for(r=0;r]+>/g.test(t)){var n=y("div");n.innerHTML=t,e=w(n)}else e=$(),e.appendChild(document.createTextNode(t));return e}function k(t){return t.replace(se,"")}function O(t,e,n){if(!e)return t;for(var i=e.split(".");i.length>1&&p(t,i[0]);)t=t[i.shift()];return e=i[0],"undefined"!=typeof n?void(t[e]=n):t[e]}function C(t){this.path=t,this.watchers=[],this.guid=re++}function A(t){return t}function N(t){return""}function D(t){var e=t.charCodeAt(0);if(e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57)return ue;switch(e){case 91:case 93:case 46:case 34:case 39:return ae;default:return ce}}function E(t){var e=[],n=t.split(""),i=n.length-1,s=D(n[0]);return le.init(s),_(n,function(t,n){var s=D(t),r=le.set(s,t);r&&e.push(r),n===i&&le.saves&&(e.push(le.saves),le.reset())}),e}function I(t,e){for(;e.length;)t=t[e.shift()];return t}function T(t){return E(k(t))}function j(t,n,i){var s=g(i),r=s.pop(),o=I(t,s);e(o)&&(o[r]=n)}function L(t){var e=we.length;return we[e]=t,'"'+e+'"'}function S(t,e){return we[e]}function P(t){var e=t.charAt(0),n=t.slice(1);return ge.test(n)?t:(n=n.indexOf('"')>-1?n.replace(de,S):n,e+"scope."+n)}function U(t){return me.test(t)&&!pe.test(t)&&0!==t.indexOf("Math.")}function W(t){return U(t)?"scope."+t:(t=(" "+t).replace(ve,L),t=t.replace(_e,P),t=t.replace(de,S))}function M(t){if($e.test(t))return l("Avoid using unallow keyword in expression ["+t+"]"),f;try{return new Function("scope","return "+W(t)+";")}catch(e){return d("Invalid generated expression: ["+t+"]"),f}}function V(t){var e=T(t);return e.length?function(t,n){j(t,n,e)}:(d("Invalid setter expression ["+t+"]"),f)}function z(t,e){var n=t&&t.__ob__,i=n&&n.dep.guid;if(i){if(xe.indexOf(i)>-1)return;xe.push(i)}_(t,function(t){z(t,!1)}),e&&(xe.length=0)}function F(t,e,n,s){this.vm=t,b(this,e),this.callback=n,this.context=s||this,this.depIds=[],this.newDepIds=[],this.shallowIds=[],this.depends=[],this.newDepends=[];var r=e.once,o=e.expression,h=i(o);this.getter=h?o:M(o),this.setter=!r&&e.duplex?V(o):null,this.oldVal=null,this.value=r?this.getValue():this.get()}function R(t){this.parser=t,this.scope=t.scope}function H(t,e,n,i){this.vm=t,this.el=e,this.desc=n,this.scope=i,this.parse()}function q(t){return t.prototype=Object.create(H.prototype)}function B(t){return 1===t.nodeType}function Z(t){return 3===t.nodeType}function G(t){for(;t.firstChild;)t.removeChild(t.firstChild);return t}function Q(t,e){return t.getAttribute(e)||""}function J(t,e){t.removeAttribute(e)}function K(t,e,n){return null==n||n===!1?J(t,e):void(n===!0?(t[e]=n,X(t,e)||t.setAttribute(e,"")):n!==Q(t,e)&&t.setAttribute(e,n))}function X(t,e){return t.hasAttribute(e)}function Y(t,e){var n,i=t.classList;return i?i.contains(e):(n=" "+Q(t,"class")+" ",n.indexOf(" "+e+" ")>-1)}function tt(t,e){var n,i=t.classList;e&&!Y(t,e)&&(i?i.add(e):(n=" "+Q(t,"class")+" ",n.indexOf(" "+e+" ")===-1&&K(t,"class",(n+e).trim())))}function et(t,e){var n,i,s=t.classList;if(e&&Y(t,e)){if(s)s.remove(e);else{for(i=" "+e+" ",n=" "+Q(t,"class")+" ";n.indexOf(i)>-1;)n=n.replace(i," ");K(t,"class",n.trim())}t.className||J(t,"class")}}function nt(t,e,n,i){t.addEventListener(e,n,i)}function it(t,e,n,i){t.removeEventListener(e,n,i)}function st(t){var e,n,i=k(t),s=i.match(De),r=s&&s[0];return r?(n=i.substr(0,i.indexOf(r)),e="["+r.substr(1,r.length-2)+"]"):n=i,{func:n,args:e}}function rt(t){var e={},n=t.trim();if(Ne.test(n)){var i=n.length;n=n.substr(1,i-2).replace(/\s/g,"");var s=n.match(Ie);_(s,function(t){var n=t.split(":"),i=n[0],s=n[1];i&&s&&(i=i.replace(Ee,""),e[i]=s)})}return e}function ot(t,e){var n,i=t.indexOf("."),s="";i>-1?(n=t.substr(0,i),s=t.substr(i+1,t.length)):n=t;var r=st(e),o=r.func,h=r.args;return{type:n,dress:s,func:o,args:h}}function ht(t){var e=[],n=t.args,i=t.expression;if(n)e.push(ot(n,i));else{var s=rt(i);_(s,function(t,n){e.push(ot(n,t))})}return e}function ut(t,e){var n,i=e.split("."),s=i.indexOf("self")>-1,r=i.indexOf("stop")>-1,o=i.indexOf("one")>-1,h=i.indexOf("prevent")>-1,u=i.indexOf("capture")>-1;return 0===t.indexOf("key")&&_(i,function(t){if(Ae.test(t))return n=+t,!1}),{self:s,stop:r,prevent:h,capture:u,keyCode:n,one:o}}function at(){this.cache={},this.funcWatchers=[],this.argsWatchers=[],H.apply(this,arguments)}function ct(){H.apply(this,arguments)}function ft(t){for(var e=0;e=e&&t.call(t)},e)}function zt(t,e){for(var n=[],i=t.options,s=0;s-1?(n=i.substr(r+1),e=i.substr(0,r)):e=i,{args:n,attr:i,directive:e,expression:s}}function Kt(t){t.__afterHook__||v(t,"__afterHook__",Q(t,"v-hook:after")),t.__beforeHook__||v(t,"__beforeHook__",Q(t,"v-hook:before"))}function Xt(t,e){var n,i,s;return function(r,o,h){var u=r.path;u===n&&o===i&&h===s||(t.apply(e,arguments),n=u,i=o,s=h)}}function Yt(t){var n=t.model,s=t.view,r=t.computed,o=t.watchAll;return B(s)?e(n)?(this.$queue=[],this.$data=n,this.$element=s,this.$regEles={},this.$directives=[],this.$context=t.context||this,this.$ob=mt(this.$data),r&&yt(this.$data,r),this.$afters=[],this.$hooks=t.hooks||{},this.$customs=t.customs||{},this.$unifyCb=i(o)?Xt(o,this.$context):null,void(t.lazy||this.mount())):l("model must be a type of Object: ",n):l("view must be a type of DOMElement: ",s)}function te(t){var n=t.context||t.model;_(t.model,function(e,s){i(e)&&(t.model[s]=e.bind(n))}),_(t.methods,function(e,i){t.model[i]=e.bind(n)}),this.__ct__=n,this.__bk__=g(t.model),this.__vm__=new Yt(t),this.$data=this.__vm__.$data,this.$els=this.__vm__.$regEles,_(t.watches,function(t,n){i(t)?this.watch(n,t,!1):e(t)&&this.watch(n,t.handler,t.deep)},this)}var ee=Object.prototype,ne=ee.hasOwnProperty,ie=window.console,se=/\s/g,re=0;C.watcher=null;var oe=C.prototype;oe.addWatcher=function(t){this.watchers.push(t)},oe.removeWatcher=function(t){this.watchers.$remove(t)},oe.depend=function(){C.watcher&&C.watcher.addDepend(this)},oe.beforeNotify=function(){_(this.watchers,function(t){t.beforeUpdate()})},oe.notify=function(t){_(this.watchers,function(e){e.update(t,this)},this)};var he=0,ue=1,ae=2,ce=1,fe=[0,A,N,A],le={init:function(t){this.saves="",this.state=t},set:function(t,e){var n=this.get(t),i=n.keepIdent,s=n.tobeQuote,r=n.tobeIdent;if(i)this.save(t,e);else{if(s){var o=this.saves;return this.saves="",this.change(t),o}r&&(this.save(t,e),this.change(t))}},get:function(t){var e=this.state,n=e===ue&&t===ue,i=(e===ue||e===he)&&t===ae,s=e===ae&&t===ae,r=(e===ae||e===he)&&t===ue;return{keepIdent:n,tobeQuote:i,keepQuote:s,tobeIdent:r}},change:function(t){this.state=t},save:function(t,e){this.saves+=fe[t](e)},reset:function(){this.saves="",this.state=he}},de=/"(\d+)"/g,pe=/^(true|false)$/,ve=/[\{,]\s*[\w\$_]+\s*:|('[^']*'|"[^"]*")|typeof /g,_e=/[^\w$\.]([A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\])*)/g,me=/^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/,be="Math.parseInt.parseFloat.Date.this.true.false.null.undefined.Infinity.NaN.isNaN.isFinite.decodeURI.decodeURIComponent.encodeURI.encodeURIComponent",ge=new RegExp("^("+be.replace(/\./g,"\\b|")+"\\b)"),ye="var.const.let.if.else.for.in.continue.switch.case.break.default.function.return.do.while.delete.try.catch.throw.finally.with.import.export.instanceof.yield.await",$e=new RegExp("^("+ye.replace(/\./g,"\\b|")+"\\b)"),we=[],xe=[],ke=F.prototype;ke.getScope=function(){return this.context.scope||this.vm.$data},ke.getValue=function(){var t=this.getScope();return this.getter.call(t,t)},ke.setValue=function(t){var e=this.getScope();this.setter&&this.setter.call(e,e,t)},ke.get=function(){this.beforeGet();var t=this.getValue();return this.deep&&(this.shallowIds=g(this.newDepIds),z(t,!0)),this.afterGet(),t},ke.beforeGet=function(){C.watcher=this},ke.addDepend=function(t){var e=t.guid,n=this.newDepIds;n.indexOf(e)<0&&(n.push(e),this.newDepends.push(t),this.depIds.indexOf(e)<0&&t.addWatcher(this))},ke.removeDepends=function(t){_(this.depends,function(e){t?t.call(this,e)&&e.removeWatcher(this):e.removeWatcher(this)},this)},ke.afterGet=function(){C.watcher=null,this.removeDepends(function(t){return this.newDepIds.indexOf(t.guid)<0}),this.depIds=g(this.newDepIds),this.newDepIds.length=0,this.depends=g(this.newDepends),this.newDepends.length=0},ke.beforeUpdate=function(){this.oldVal=g(this.value)},ke.update=function(t,e){var n=this.oldVal,i=this.vm.$unifyCb,s=this.value=this.get(),r=this.callback;if(r&&n!==s){var o=this.deep&&this.shallowIds.indexOf(e.guid)<0;r.call(this.context,s,n,o,t)}i&&i({action:t,path:e.path},s,n)},ke.destroy=function(){this.value=null,this.removeDepends(),this.getter=this.setter=null,this.vm=this.callback=this.context=null};var Oe=R.prototype;Oe.mount=function(){var t=this.parser,e=this.watcher=new F(t.vm,t.desc,this.update,this);this.update(e.value)},Oe.destroy=function(){this.watcher.destroy(),this.parser=this.scope=null},Oe.update=function(){var t=this.parser;t.update.apply(t,arguments)},Oe.get=function(){return this.watcher.value},Oe.set=function(t){this.watcher.setValue(t)};var Ce=H.prototype;Ce.bind=function(){this.directive=new R(this),this.directive.mount()},Ce.destroy=function(){var t=this.directive;t?t.destroy():i(this._destroy)&&this._destroy(),this.vm=this.el=this.desc=this.scope=null};var Ae=/^(\d)*$/,Ne=/^\{.*\}$/,De=/(\(.*\))/,Ee=/(^'*)|('*$)|(^"*)|("*$)/g,Ie=/[^,]+:[^:]+((?=,[^:]+:)|$)/g,Te=2e3,je="__vonid__",Le=q(at);Le.parse=function(){_(ht(this.desc),function(t){this.parseEvent(t)},this)},Le.getExpDesc=function(t){return b({},this.desc,{expression:t})},Le.parseEvent=function(t){var e=t.func,n=t.args,s=t.type,r=t.dress,o=r.indexOf("capture")>-1;if("$remove"===e)return this.bindRemoveEvent(s,r);var h=this.getExpDesc(e),u=new F(this.vm,h,function(t,e){this.off(s,e,o),this.bindEvent(s,r,t,n)},this),a=u.value;return i(a)?(this.bindEvent(s,r,a,n),void(h.once?u.destroy():this.funcWatchers.push(u))):(u.destroy(),l("Directive ["+this.desc.attr+"] must be a type of Function"))},Le.bindRemoveEvent=function(t,e){var n=this.scope;if(!n)return l("The specify event $remove must be used in v-for scope");var i=n.__alias__;this.bindEvent(t,e,function(){n.__viterator__.$remove(n[i])},"["+i+"]")},Le.bindEvent=function(t,e,n,i){var s=ut(t,e),r=s.self,o=s.stop,h=s.prevent,u=s.capture,a=s.keyCode,c=s.one;v(this.scope||this.vm.$data,"$event","__e__");var f=[];if(i){var l=this.getExpDesc(i),d=new F(this.vm,l,function(t){f=t},this);f=d.value,l.once?d.destroy():this.argsWatchers.push(d)}var p,m=this.el,b=function(t){r&&t.target!==m||a&&a!==t.keyCode||(f.length?_(f,function(e,n){("__e__"===e||e instanceof Event)&&(f[n]=t)}):f.push(t),h&&t.preventDefault(),o&&t.stopPropagation(),n.apply(this,f))},g=Te++,y=this;c?(p=function(e){b(e),y.off(t,p,u)},p[je]=g):(n[je]=g,p=b),this.cache[g]=p,this.on(t,p,u)},Le.on=function(t,e,n){nt(this.el,t,e,n)},Le.off=function(t,e,n){var i=this.cache,s=e[je],r=i[s];r&&(it(this.el,t,r,n),delete i[s])},Le._destroy=function(){m(this.cache),_(this.funcWatchers,function(t){t.destroy()}),_(this.argsWatchers,function(t){t.destroy()})};var Se=q(ct);Se.parse=function(){if(this.scope)l("v-el can not be used inside v-for! Consider use v-custom to handle v-for element.");else{var t=this.desc.expression;this.vm.$regEles[t]=this.el}};var Pe="__proto__"in{},Ue=Array.prototype,We=Object.create(Ue);_(["pop","push","sort","shift","splice","unshift","reverse"],function(t){var e=Ue[t];v(We,t,function(){for(var n=arguments,i=[],s=this.__ob__,r=0;r=this.length&&(t=this.length),this.splice(t,1,e)[0]}),v(Ue,"$remove",function(t){var e=this.indexOf(t);if(e>-1)return this.splice(e,1)});var Me=Object.getOwnPropertyNames(We),Ve="__vfor__",ze="__vforid__",Fe=/(.*) (?:in|of) (.*)/,Re="push|pop|shift|unshift|splice".split("|"),He=q(xt);He.parse=function(){var t=this.el,e=this.desc,n=t.parentNode,i=e.expression,s=i.match(Fe);if(!s)return l('The format of v-for must be like "item in/of items"!');if(1!==n.nodeType)return l("v-for cannot use in the root element!");if(X(t,"v-if"))return l("Do not use v-if and v-for on the same element! Consider filtering the source Array instead.");var r=s[1],o=s[2];this.length=0,this.scopes=[],this.init=!0,this.alias=r,this.partly=!1,this.partlyArgs=[],this.$parent=n,this.end=t.nextSibling,this.start=t.previousSibling,this.bodyDirs=t.__dirs__,this.tpl=t.cloneNode(!0),this.hooks=$t(this.vm,t),this.isOption="OPTION"===t.tagName&&"SELECT"===n.tagName,e.expression=o,this.bind(),this.updateModel()},He.updateModel=function(){if(this.isOption){var t=this.$parent.__vmodel__;t&&t.forceUpdate()}},He.hook=function(t,e,n){var s=this.hooks[t];i(s)&&(s.call(this.vm.$context,e,n,e[ze]),e=null)},He.update=function(t,e,n,i){this.length=t&&t.length,this.init?(this.$parent.replaceChild(this.buildList(t),this.el),this.el=null,this.init=!1):i&&Re.indexOf(i.method)>-1?(this.partly=!0,this.updatePartly(t,i),this.partly=!1):(this.recompileList(t),this.updateModel())},He.updatePartly=function(t,e){var n=[],i=e.args,s=e.method,r=this.scopes;switch(this[s].call(this,t,i),s){case"pop":case"shift":break;case"push":case"unshift":n=this.partlyArgs;break;case"splice":n=i.slice(0,2),Array.prototype.push.apply(n,this.partlyArgs)}r[s].apply(r,n),this.partlyArgs.length=0,_(r,function(t,e){t.$index=e})},He.recompileList=function(t){for(var e=this,n=0,i=this.$parent,s=i.childNodes,r=0;r1&&n.block(this.el),v(a,Ve,u),v(a,ze,wt()),n.compile(a,!0,f,this.desc.once),r.appendChild(a),this.hook("after",a,h)},this),r},He.getChilds=function(){for(var t=this,e=[],n=this.$parent.childNodes,i=0;i=n&&e0,tn={bind:function(){function t(t){i&&(t=t.trim());var e=Ft(t,r);o?Vt(function(){n.onDebounce=!0,h.set(e)},c(o)):h.set(e)}var e,n=this,i=this.trim,s=this.lazy,r=this.number,o=this.debounce,h=this.directive;this.on("compositionstart",function(){e=!0}),this.on("compositionend",function(){e=!1,s||t(this.value)}),this.on("input",function(){e||s||t(this.value)}),this.on("blur",function(){t(this.value)}),this.on("change",function(){t(this.value)}),Ye&&(this.on("cut",function(){var e=this;Vt(function(){return t(e.value)})}),this.on("keyup",function(e){var n=e.keyCode;8!==n&&46!==n||t(this.value)}))},update:function(t){var e=this.el,n=a(t);e.value===n||this.onDebounce||(e.value=n)}},en={bind:function(){var t=this.number,e=this.directive;this.on("change",function(){e.set(Ft(this.value,t))})},update:function(t){var e=this.el;e.checked=e.value===a(t)}},nn={bind:function(){var t=this.multi,e=this.number,n=this.directive;this.on("change",function(){var i=t?zt(this,e):Ft(this.value,e);n.set(i)}),this.vm.after(this.forceUpdate,this)},update:function(t){var e=this.el,i=this.multi,s=this.desc.expression;if(e.selectedIndex=-1,i&&!n(t))return l(" has no multiple propperty");for(var r=e.options,o=0;o-1:u===a(t)}},forceUpdate:function(){this.update(this.directive.get())}},sn={bind:function(){var t=this.number,e=this.directive;this.on("change",function(){var i=e.get(),s=this.checked;if(r(i))e.set(s);else if(n(i)){var o=Ft(this.value,t),h=Rt(o,i);s&&h===-1?i.push(o):h>-1&&i.splice(h,1)}})},update:function(t){var e=this.el,i=Ft(e.value,this.number);return n(t)||r(t)?void(e.checked=r(t)?t:Rt(i,t)>-1):l("Checkbox v-model value must be a type of Boolean or Array")}},rn=["input","select","textarea"],on=q(Ht);on.parse=function(){var t=this.el,e=this.desc,n=t.tagName.toLowerCase(),i="input"===n?Q(t,"type"):n;return rn.indexOf(n)<0?l("v-model only for using in "+rn.join(", ")):U(e.expression)?(e.duplex=!0,void this.bindDuplex(i)):l("v-model directive value can be use by static expression")},on.bindDuplex=function(t){var e,n=this.el;switch(t){case"text":case"password":case"textarea":e=tn,this.trim=X(n,"trim"),this.lazy=X(n,"lazy"),this.debounce=Q(n,"debounce");break;case"radio":e=en;break;case"checkbox":e=sn;break;case"select":e=nn,v(n,"__vmodel__",this),this.multi=X(n,"multiple"),this.forceUpdate=nn.forceUpdate.bind(this)}return e?(this.number=X(n,"number"),this.update=e.update.bind(this),this.bind(),void(this.desc.once||e.bind.call(this))):l("Do not use incorrect form-type with v-model: ",n)},on.on=function(t,e){nt(this.el,t,e,!1)};var hn=q(qt);hn.parse=function(){var t=this.desc,e=this.vm.$customs[t.args];return i(e)?(this.update=e,void this.bind()):l("Custom directive ["+t.attr+"] must define with a refresh function!")};var un={von:at,vel:ct,vif:At,vfor:xt,vtext:Nt,vhtml:Dt,vshow:Tt,vbind:Mt,vmodel:Ht,vcustom:qt},an=/\n/g,cn=/\{\{(.+?)\}\}/g,fn=/(\{\{.*\}\})/,ln=["velse","vpre","vcloak","vonce","vhook"],dn=Yt.prototype;dn.mount=function(){this.$done=!1,this.$fragment=w(this.$element),this.compile(this.$fragment,!0)},dn.compile=function(t,e,n,i){var s=this,r=t.childNodes,o=!!i||Zt(t);e&&Qt(t)&&this.$queue.push([t,n]),v(t,"__vonce__",o);for(var h=0;h1&&o!==h.length-1){var l=h.splice(o,1)[0];h.push(l),l=null}i&&(v(e,"__dirs__",h.length),h=[i],i=null),_(h,function(t){this.parse(e,t,n)},this)}else Z(e)&&this.parseText(e,n)},dn.parse=function(t,e,n){var i=t.__vonce__,s=Jt(e),r=s.directive,o="v"+r.substr(2),h=un[o];if(J(t,s.attr),!(ln.indexOf(o)>-1))if(h){s.once=i;var u=new h(this,t,s,n);i?u.destroy():this.$directives.push(u)}else l("["+r+"] is an unknown directive!")},dn.parseText=function(t,e){var n=[],i={},s=t.parentNode&&t.parentNode.__vonce__,r=t.textContent.trim().replace(an,""),o=r.split(cn),h=r.match(cn);_(o,function(t){h.indexOf("{{"+t+"}}")>-1?n.push("("+t+")"):t&&n.push('"'+t+'"')}),i.once=s,i.expression=n.join("+");var u=new un.vtext(this,t,i,e);s?u.destroy():this.$directives.push(u)},dn.block=function(t){_(this.$queue,function(e){if(t===e[0])return null})},dn.after=function(t,e){this.$afters.push([t,e])},dn.completed=function(){0!==this.$queue.length||this.$done||(this.$done=!0,this.$element.appendChild(this.$fragment),_(this.$afters,function(t){return t[0].call(t[1]),null}))},dn.destroy=function(){this.$data=null,G(this.$element),_(this.$directives,function(t){return t.destroy(),null})};var pn=te.prototype;return pn.mount=function(){this.__vm__.mount()},pn.get=function(t){var e=this.$data;return s(t)?O(e,t):e},pn.getCopy=function(t){return g(this.get(t))},pn.set=function(t,n){var i=this.$data;s(t)?O(i,t,n):e(t)&&_(t,function(t,e){O(i,e,t)})},pn.reset=function(t){var e=this.$data,i=g(this.__bk__);s(t)?e[t]=i[t]:n(t)?_(t,function(t){e[t]=i[t]}):_(e,function(t,n){e[n]=i[n]})},pn.watch=function(t,e,n){return new F(this,{deep:n,expression:t},e.bind(this.__ct__))},pn.destroy=function(){this.__vm__.destroy(),this.__vm__=this.__ct__=this.__bk__=this.$data=this.$els=null},te}); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.MVVM=e()}(this,function(){"use strict";function t(t,e){return typeof t===e}function e(t){return"[object Object]"===ee.toString.call(t)}function i(t){return Array.isArray(t)}function n(e){return t(e,"function")}function s(e){return t(e,"string")}function r(e){return t(e,"boolean")}function o(e){return t(e,"number")&&!isNaN(e)}function h(t){return!(!t||!e(t)||t.nodeType||t===t.window)&&!(t.constructor&&!ie.call(t.constructor.prototype,"isPrototypeOf"))}function u(t){return 0===Object.keys(t).length}function a(t){return null==t?"":t.toString()}function c(t){if(s(t)){var e=Number(t);return o(e)?e:t}return t}function f(){}function l(){ne&&ne.warn.apply(ne,arguments)}function d(){ne&&ne.error.apply(ne,arguments)}function p(t,e){return t&&ie.call(t,e)}function v(t,e,i,n){return Object.defineProperty(t,e,{value:i,writable:!0,enumerable:!!n,configurable:!0})}function _(t,n,s){var r,o;if(s||(s=this),i(t))for(r=0;r]+>/g.test(t)){var i=y("div");i.innerHTML=t,e=w(i)}else e=$(),e.appendChild(document.createTextNode(t));return e}function k(t){return t.replace(se,"")}function O(t,e,i){if(!e)return t;for(var n=e.split(".");n.length>1&&p(t,n[0]);)t=t[n.shift()];return e=n[0],"undefined"!=typeof i?void(t[e]=i):t[e]}function C(t){this.path=t,this.watchers=[],this.guid=re++}function D(t){return t}function A(t){return""}function N(t){var e=t.charCodeAt(0);if(e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57)return ue;switch(e){case 91:case 93:case 46:case 34:case 39:return ae;default:return ce}}function I(t){var e=[],i=t.split(""),n=i.length-1,s=N(i[0]);return le.init(s),_(i,function(t,i){var s=N(t),r=le.set(s,t);r&&e.push(r),i===n&&le.saves&&(e.push(le.saves),le.reset())}),e}function E(t,e){for(;e.length;)t=t[e.shift()];return t}function T(t){return I(k(t))}function j(t,i,n){var s=g(n),r=s.pop(),o=E(t,s);e(o)&&(o[r]=i)}function L(t){var e=we.length;return we[e]=t,'"'+e+'"'}function S(t,e){return we[e]}function P(t){var e=t.charAt(0),i=t.slice(1);return ge.test(i)?t:(i=i.indexOf('"')>-1?i.replace(de,S):i,e+"scope."+i)}function U(t){return me.test(t)&&!pe.test(t)&&0!==t.indexOf("Math.")}function W(t){return U(t)?"scope."+t:(t=(" "+t).replace(ve,L),t=t.replace(_e,P),t=t.replace(de,S))}function G(t){if($e.test(t))return l("Avoid using unallow keyword in expression ["+t+"]"),f;try{return new Function("scope","return "+W(t)+";")}catch(e){return d("Invalid generated expression: ["+t+"]"),f}}function M(t){var e=T(t);return e.length?function(t,i){j(t,i,e)}:(d("Invalid setter expression ["+t+"]"),f)}function V(t,e){var i=t&&t.__ob__,n=i&&i.dep.guid;if(n){if(xe.indexOf(n)>-1)return;xe.push(n)}_(t,function(t){V(t,!1)}),e&&(xe.length=0)}function z(t,e,i,s){this.vm=t,b(this,e),this.callback=i,this.context=s||this,this.depIds=[],this.newDepIds=[],this.shallowIds=[],this.depends=[],this.newDepends=[];var r=e.once,o=e.expression,h=n(o);this.getter=h?o:G(o),this.setter=!r&&e.duplex?M(o):null,this.oldVal=null,this.value=r?this.getValue():this.get()}function F(t){this.parser=t,this.scope=t.scope}function R(t,e,i,n){this.vm=t,this.el=e,this.desc=i,this.scope=n,this.parse()}function H(t){return t.prototype=Object.create(R.prototype)}function q(t){return 1===t.nodeType}function B(t){return 3===t.nodeType}function Z(t){for(;t.firstChild;)t.removeChild(t.firstChild);return t}function Q(t,e){return t.getAttribute(e)||""}function J(t,e){t.removeAttribute(e)}function K(t,e,i){return null==i||i===!1?J(t,e):void(i===!0?(t[e]=i,X(t,e)||t.setAttribute(e,"")):i!==Q(t,e)&&t.setAttribute(e,i))}function X(t,e){return t.hasAttribute(e)}function Y(t,e){var i,n=t.classList;return n?n.contains(e):(i=" "+Q(t,"class")+" ",i.indexOf(" "+e+" ")>-1)}function tt(t,e){var i,n=t.classList;e&&!Y(t,e)&&(n?n.add(e):(i=" "+Q(t,"class")+" ",i.indexOf(" "+e+" ")===-1&&K(t,"class",(i+e).trim())))}function et(t,e){var i,n,s=t.classList;if(e&&Y(t,e)){if(s)s.remove(e);else{for(n=" "+e+" ",i=" "+Q(t,"class")+" ";i.indexOf(n)>-1;)i=i.replace(n," ");K(t,"class",i.trim())}t.className||J(t,"class")}}function it(t,e,i,n){t.addEventListener(e,i,n)}function nt(t,e,i,n){t.removeEventListener(e,i,n)}function st(t){var e,i,n=k(t),s=n.match(Ne),r=s&&s[0];return r?(i=n.substr(0,n.indexOf(r)),e="["+r.substr(1,r.length-2)+"]"):i=n,{func:i,args:e}}function rt(t){var e={},i=t.trim();if(Ae.test(i)){var n=i.length;i=i.substr(1,n-2).replace(/\s/g,"");var s=i.match(Ee);_(s,function(t){var i=t.split(":"),n=i[0],s=i[1];n&&s&&(n=n.replace(Ie,""),e[n]=s)})}return e}function ot(t,e){var i,n=t.indexOf("."),s="";n>-1?(i=t.substr(0,n),s=t.substr(n+1,t.length)):i=t;var r=st(e),o=r.func,h=r.args;return{type:i,dress:s,func:o,args:h}}function ht(t){var e=[],i=t.args,n=t.expression;if(i)e.push(ot(i,n));else{var s=rt(n);_(s,function(t,i){e.push(ot(i,t))})}return e}function ut(t,e){var i,n=e.split("."),s=n.indexOf("self")>-1,r=n.indexOf("stop")>-1,o=n.indexOf("one")>-1,h=n.indexOf("prevent")>-1,u=n.indexOf("capture")>-1;return 0===t.indexOf("key")&&_(n,function(t){if(De.test(t))return i=+t,!1}),{self:s,stop:r,prevent:h,capture:u,keyCode:i,one:o}}function at(){this.cache={},this.funcWatchers=[],this.argsWatchers=[],R.apply(this,arguments)}function ct(){R.apply(this,arguments)}function ft(t){for(var e=0;e=e&&t.call(t)},e)}function Vt(t,e){for(var i=[],n=t.options,s=0;s-1?(i=n.substr(r+1),e=n.substr(0,r)):e=n,{args:i,attr:n,directive:e,expression:s}}function Kt(t){t.__afterHook__||v(t,"__afterHook__",Q(t,"v-hook:after")),t.__beforeHook__||v(t,"__beforeHook__",Q(t,"v-hook:before"))}function Xt(t,e){var i,n,s;return function(r,o,h){var u=r.path;u===i&&o===n&&h===s||(t.apply(e,arguments),i=u,n=o,s=h)}}function Yt(t){var i=t.model,s=t.view,r=t.computed,o=t.watchAll;return q(s)?e(i)?(this.$queue=[],this.$data=i,this.$element=s,this.$regEles={},this.$dirGuid=1e3,this.$dirGuids=[],this.$directives={},this.$context=t.context||this,this.$ob=mt(this.$data),r&&yt(this.$data,r),this.$afters=[],this.$hooks=t.hooks||{},this.$customs=t.customs||{},this.$unifyCb=n(o)?Xt(o,this.$context):null,void(t.lazy||this.mount())):l("model must be a type of Object: ",i):l("view must be a type of DOMElement: ",s)}function te(t){var i=t.context||t.model;_(t.model,function(e,s){n(e)&&(t.model[s]=e.bind(i))}),_(t.methods,function(e,n){t.model[n]=e.bind(i)}),this.__ct__=i,this.__bk__=g(t.model),this.__vm__=new Yt(t),this.$data=this.__vm__.$data,this.$els=this.__vm__.$regEles,_(t.watches,function(t,i){n(t)?this.watch(i,t,!1):e(t)&&this.watch(i,t.handler,t.deep)},this)}var ee=Object.prototype,ie=ee.hasOwnProperty,ne=window.console,se=/\s/g,re=0;C.watcher=null;var oe=C.prototype;oe.addWatcher=function(t){this.watchers.push(t)},oe.removeWatcher=function(t){this.watchers.$remove(t)},oe.depend=function(){C.watcher&&C.watcher.addDepend(this)},oe.beforeNotify=function(){_(this.watchers,function(t){t.beforeUpdate()})},oe.notify=function(t){_(this.watchers,function(e){e.update(t,this)},this)};var he=0,ue=1,ae=2,ce=1,fe=[0,D,A,D],le={init:function(t){this.saves="",this.state=t},set:function(t,e){var i=this.get(t),n=i.keepIdent,s=i.tobeQuote,r=i.tobeIdent;if(n)this.save(t,e);else{if(s){var o=this.saves;return this.saves="",this.change(t),o}r&&(this.save(t,e),this.change(t))}},get:function(t){var e=this.state,i=e===ue&&t===ue,n=(e===ue||e===he)&&t===ae,s=e===ae&&t===ae,r=(e===ae||e===he)&&t===ue;return{keepIdent:i,tobeQuote:n,keepQuote:s,tobeIdent:r}},change:function(t){this.state=t},save:function(t,e){this.saves+=fe[t](e)},reset:function(){this.saves="",this.state=he}},de=/"(\d+)"/g,pe=/^(true|false)$/,ve=/[\{,]\s*[\w\$_]+\s*:|('[^']*'|"[^"]*")|typeof /g,_e=/[^\w$\.]([A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\])*)/g,me=/^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/,be="Math.parseInt.parseFloat.Date.this.true.false.null.undefined.Infinity.NaN.isNaN.isFinite.decodeURI.decodeURIComponent.encodeURI.encodeURIComponent",ge=new RegExp("^("+be.replace(/\./g,"\\b|")+"\\b)"),ye="var.const.let.if.else.for.in.continue.switch.case.break.default.function.return.do.while.delete.try.catch.throw.finally.with.import.export.instanceof.yield.await",$e=new RegExp("^("+ye.replace(/\./g,"\\b|")+"\\b)"),we=[],xe=[],ke=z.prototype;ke.getScope=function(){return this.context.scope||this.vm.$data},ke.getValue=function(){var t=this.getScope();return this.getter.call(t,t)},ke.setValue=function(t){var e=this.getScope();this.setter&&this.setter.call(e,e,t)},ke.get=function(){this.beforeGet();var t=this.getValue();return this.deep&&(this.shallowIds=g(this.newDepIds),V(t,!0)),this.afterGet(),t},ke.beforeGet=function(){C.watcher=this},ke.addDepend=function(t){var e=t.guid,i=this.newDepIds;i.indexOf(e)<0&&(i.push(e),this.newDepends.push(t),this.depIds.indexOf(e)<0&&t.addWatcher(this))},ke.removeDepends=function(t){_(this.depends,function(e){t?t.call(this,e)&&e.removeWatcher(this):e.removeWatcher(this)},this)},ke.afterGet=function(){C.watcher=null,this.removeDepends(function(t){return this.newDepIds.indexOf(t.guid)<0}),this.depIds=g(this.newDepIds),this.newDepIds.length=0,this.depends=g(this.newDepends),this.newDepends.length=0},ke.beforeUpdate=function(){this.oldVal=g(this.value)},ke.update=function(t,e){var i=this.oldVal,n=this.vm.$unifyCb,s=this.value=this.get(),r=this.callback;if(r&&i!==s){var o=this.deep&&this.shallowIds.indexOf(e.guid)<0;r.call(this.context,s,i,o,t)}n&&n({action:t,path:e.path},s,i)},ke.destroy=function(){this.value=null,this.removeDepends(),this.getter=this.setter=null,this.vm=this.callback=this.context=null};var Oe=F.prototype;Oe.mount=function(){var t=this.parser,e=this.watcher=new z(t.vm,t.desc,this.update,this);this.update(e.value)},Oe.destroy=function(){this.watcher.destroy(),this.parser=this.scope=null},Oe.update=function(){var t=this.parser;t.update.apply(t,arguments)},Oe.get=function(){return this.watcher.value},Oe.set=function(t){this.watcher.setValue(t)};var Ce=R.prototype;Ce.bind=function(){this.directive=new F(this),this.directive.mount()},Ce.destroy=function(){var t=this.directive;t?t.destroy():n(this._destroy)&&this._destroy(),this.vm=this.el=this.desc=this.scope=null};var De=/^(\d)*$/,Ae=/^\{.*\}$/,Ne=/(\(.*\))/,Ie=/(^'*)|('*$)|(^"*)|("*$)/g,Ee=/[^,]+:[^:]+((?=,[^:]+:)|$)/g,Te=2e3,je="__vonid__",Le=H(at);Le.parse=function(){_(ht(this.desc),function(t){this.parseEvent(t)},this)},Le.getExpDesc=function(t){return b({},this.desc,{expression:t})},Le.parseEvent=function(t){var e=t.func,i=t.args,s=t.type,r=t.dress,o=r.indexOf("capture")>-1;if("$remove"===e)return this.bindRemoveEvent(s,r);var h=this.getExpDesc(e),u=new z(this.vm,h,function(t,e){this.off(s,e,o),this.bindEvent(s,r,t,i)},this),a=u.value;return n(a)?(this.bindEvent(s,r,a,i),void(h.once?u.destroy():this.funcWatchers.push(u))):(u.destroy(),l("Directive ["+this.desc.attr+"] must be a type of Function"))},Le.bindRemoveEvent=function(t,e){var i=this.scope;if(!i)return l("The specify event $remove must be used in v-for scope");var n=i.__alias__;this.bindEvent(t,e,function(){i.__viterator__.$remove(i[n])},"["+n+"]")},Le.bindEvent=function(t,e,i,n){var s=ut(t,e),r=s.self,o=s.stop,h=s.prevent,u=s.capture,a=s.keyCode,c=s.one;v(this.scope||this.vm.$data,"$event","__e__");var f=[];if(n){var l=this.getExpDesc(n),d=new z(this.vm,l,function(t){f=t},this);f=d.value,l.once?d.destroy():this.argsWatchers.push(d)}var p,m=this.el,b=function(t){r&&t.target!==m||a&&a!==t.keyCode||(f.length?_(f,function(e,i){("__e__"===e||e instanceof Event)&&(f[i]=t)}):f.push(t),h&&t.preventDefault(),o&&t.stopPropagation(),i.apply(this,f))},g=Te++,y=this;c?(p=function(e){b(e),y.off(t,p,u)},p[je]=g):(i[je]=g,p=b),this.cache[g]=p,this.on(t,p,u)},Le.on=function(t,e,i){it(this.el,t,e,i)},Le.off=function(t,e,i){var n=this.cache,s=e[je],r=n[s];r&&(nt(this.el,t,r,i),delete n[s])},Le._destroy=function(){m(this.cache),_(this.funcWatchers,function(t){t.destroy()}),_(this.argsWatchers,function(t){t.destroy()})};var Se=H(ct);Se.parse=function(){if(this.scope)l("v-el can not be used inside v-for! Consider use v-custom to handle v-for element.");else{var t=this.desc.expression;this.vm.$regEles[t]=this.el}};var Pe="__proto__"in{},Ue=Array.prototype,We=Object.create(Ue);_(["pop","push","sort","shift","splice","unshift","reverse"],function(t){var e=Ue[t];v(We,t,function(){for(var i=arguments,n=[],s=this.__ob__,r=0;r=this.length&&(t=this.length),this.splice(t,1,e)[0]}),v(Ue,"$remove",function(t){var e=this.indexOf(t);if(e>-1)return this.splice(e,1)});var Ge=Object.getOwnPropertyNames(We),Me="__vfor__",Ve="__vforid__",ze="__vfordirids__",Fe=/(.*) (?:in|of) (.*)/,Re="push|pop|shift|unshift|splice".split("|"),He=H(xt);He.parse=function(){var t=this.el,e=this.desc,i=t.parentNode,n=e.expression,s=n.match(Fe);if(!s)return l('The format of v-for must be like "item in/of items"!');if(1!==i.nodeType)return l("v-for cannot use in the root element!");if(X(t,"v-if"))return l("Do not use v-if and v-for on the same element! Consider filtering the source Array instead.");var r=s[1],o=s[2];this.length=0,this.scopes=[],this.init=!0,this.alias=r,this.partly=!1,this.partlyArgs=[],this.$parent=i,this.end=t.nextSibling,this.start=t.previousSibling,this.bodyDirs=t.__dirs__,this.tpl=t.cloneNode(!0),this.hooks=$t(this.vm,t),this.isOption="OPTION"===t.tagName&&"SELECT"===i.tagName,e.expression=o,this.bind(),this.updateModel()},He.updateModel=function(){if(this.isOption){var t=this.$parent.__vmodel__;t&&t.forceUpdate()}},He.hook=function(t,e,i){var s=this.hooks[t];n(s)&&(s.call(this.vm.$context,e,i,e[Ve]),e=null)},He.dropDirectives=function(t){this.vm.dropDirective(t[ze])},He.update=function(t,e,i,n){this.length=t&&t.length,this.init?(this.$parent.replaceChild(this.buildList(t),this.el),this.el=null,this.init=!1):n&&Re.indexOf(n.method)>-1?(this.partly=!0,this.updatePartly(t,n),this.partly=!1):(this.recompileList(t),this.updateModel())},He.updatePartly=function(t,e){var i=[],n=e.args,s=e.method,r=this.scopes;switch(this[s].call(this,t,n),s){case"pop":case"shift":break;case"push":case"unshift":i=this.partlyArgs;break;case"splice":i=n.slice(0,2),Array.prototype.push.apply(i,this.partlyArgs)}r[s].apply(r,i),this.partlyArgs.length=0,_(r,function(t,e){t.$index=e})},He.recompileList=function(t){for(var e=this,i=0,n=this.$parent,s=n.childNodes,r=0;r1&&i.block(this.el),v(a,Me,u),v(a,Ve,wt());var l=i.compile(a,!0,f,this.desc.once);v(a,ze,l),r.appendChild(a),this.hook("after",a,h)},this),r},He.getChilds=function(){for(var t=this,e=[],i=this.$parent.childNodes,n=0;n=i&&e0,ei={bind:function(){function t(t){n&&(t=t.trim());var e=zt(t,r);o?Mt(function(){i.onDebounce=!0,h.set(e)},c(o)):h.set(e)}var e,i=this,n=this.trim,s=this.lazy,r=this.number,o=this.debounce,h=this.directive;this.on("compositionstart",function(){e=!0}),this.on("compositionend",function(){e=!1,s||t(this.value)}),this.on("input",function(){e||s||t(this.value)}),this.on("blur",function(){t(this.value)}),this.on("change",function(){t(this.value)}),ti&&(this.on("cut",function(){var e=this;Mt(function(){return t(e.value)})}),this.on("keyup",function(e){var i=e.keyCode;8!==i&&46!==i||t(this.value)}))},update:function(t){var e=this.el,i=a(t);e.value===i||this.onDebounce||(e.value=i)}},ii={bind:function(){var t=this.number,e=this.directive;this.on("change",function(){e.set(zt(this.value,t))})},update:function(t){var e=this.el;e.checked=e.value===a(t)}},ni={bind:function(){var t=this.multi,e=this.number,i=this.directive;this.on("change",function(){var n=t?Vt(this,e):zt(this.value,e);i.set(n)}),this.vm.after(this.forceUpdate,this)},update:function(t){var e=this.el,n=this.multi,s=this.desc.expression;if(e.selectedIndex=-1,n&&!i(t))return l(" has no multiple propperty");for(var r=e.options,o=0;o-1:u===a(t)}},forceUpdate:function(){this.update(this.directive.get())}},si={bind:function(){var t=this.number,e=this.directive;this.on("change",function(){var n=e.get(),s=this.checked;if(r(n))e.set(s);else if(i(n)){var o=zt(this.value,t),h=Ft(o,n);s&&h===-1?n.push(o):h>-1&&n.splice(h,1)}})},update:function(t){var e=this.el,n=zt(e.value,this.number);return i(t)||r(t)?void(e.checked=r(t)?t:Ft(n,t)>-1):l("Checkbox v-model value must be a type of Boolean or Array")}},ri=["input","select","textarea"],oi=H(Rt);oi.parse=function(){var t=this.el,e=this.desc,i=t.tagName.toLowerCase(),n="input"===i?Q(t,"type"):i;return ri.indexOf(i)<0?l("v-model only for using in "+ri.join(", ")):U(e.expression)?(e.duplex=!0,void this.bindDuplex(n)):l("v-model directive value can be use by static expression")},oi.bindDuplex=function(t){var e,i=this.el;switch(t){case"text":case"password":case"textarea":e=ei,this.trim=X(i,"trim"),this.lazy=X(i,"lazy"),this.debounce=Q(i,"debounce");break;case"radio":e=ii;break;case"checkbox":e=si;break;case"select":e=ni,v(i,"__vmodel__",this),this.multi=X(i,"multiple"),this.forceUpdate=ni.forceUpdate.bind(this)}return e?(this.number=X(i,"number"),this.update=e.update.bind(this),this.bind(),void(this.desc.once||e.bind.call(this))):l("Do not use incorrect form-type with v-model: ",i)},oi.on=function(t,e){it(this.el,t,e,!1)};var hi=H(Ht);hi.parse=function(){var t=this.desc,e=this.vm.$customs[t.args];return n(e)?(this.update=e,void this.bind()):l("Custom directive ["+t.attr+"] must define with a refresh function!")};var ui={von:at,vel:ct,vif:Dt,vfor:xt,vtext:At,vhtml:Nt,vshow:Tt,vbind:Gt,vmodel:Rt,vcustom:Ht},ai=/\n/g,ci=/\{\{(.+?)\}\}/g,fi=/(\{\{.*\}\})/,li=["velse","vpre","vcloak","vonce","vhook"],di=Yt.prototype;di.mount=function(){this.$done=!1,this.$fragment=w(this.$element),this.compile(this.$fragment,!0)},di.compile=function(t,e,i,n){var s=this,r=t.childNodes,o=!!n||Bt(t);e&&(this.$dirGuids.length=0,Qt(t)&&this.$queue.push([t,i])),v(t,"__vonce__",o);for(var h=0;h1&&o!==h.length-1){var l=h.splice(o,1)[0];h.push(l),l=null}n&&(v(e,"__dirs__",h.length),h=[n],n=null),_(h,function(t){this.parse(e,t,i)},this)}else B(e)&&this.parseText(e,i)},di.parse=function(t,e,i){var n=t.__vonce__,s=Jt(e),r=s.directive,o="v"+r.substr(2),h=ui[o];if(J(t,s.attr),!(li.indexOf(o)>-1))if(h){s.once=n;var u=new h(this,t,s,i);n?u.destroy():this.saveDirective(u)}else l("["+r+"] is an unknown directive!")},di.parseText=function(t,e){var i=[],n={},s=t.parentNode&&t.parentNode.__vonce__,r=t.textContent.trim().replace(ai,""),o=r.split(ci),h=r.match(ci);_(o,function(t){h.indexOf("{{"+t+"}}")>-1?i.push("("+t+")"):t&&i.push('"'+t+'"')}),n.once=s,n.expression=i.join("+");var u=new ui.vtext(this,t,n,e);s?u.destroy():this.saveDirective(u)},di.saveDirective=function(t){var e=this.$dirGuid++;this.$dirGuids.push(e),this.$directives[e]=t},di.dropDirective=function(t){var e=this.$directives;_(t,function(t){var i=e[t];if(i)return i.destroy(),delete e[t],null},this)},di.block=function(t){_(this.$queue,function(e){if(t===e[0])return null})},di.after=function(t,e){this.$afters.push([t,e])},di.completed=function(){0!==this.$queue.length||this.$done||(this.$done=!0,this.$element.appendChild(this.$fragment),_(this.$afters,function(t){return t[0].call(t[1]),null}))},di.destroy=function(){this.$data=null,Z(this.$element),this.dropDirective(Object.keys(this.$directives))};var pi=te.prototype;return pi.mount=function(){this.__vm__.mount()},pi.get=function(t){var e=this.$data;return s(t)?O(e,t):e},pi.getCopy=function(t){return g(this.get(t))},pi.set=function(t,i){var n=this.$data;s(t)?O(n,t,i):e(t)&&_(t,function(t,e){O(n,e,t)})},pi.reset=function(t){var e=this.$data,n=g(this.__bk__);s(t)?e[t]=n[t]:i(t)?_(t,function(t){e[t]=n[t]}):_(e,function(t,i){e[i]=n[i]})},pi.watch=function(t,e,i){return new z(this,{deep:i,expression:t},e.bind(this.__ct__))},pi.destroy=function(){this.__vm__.destroy(),this.__vm__=this.__ct__=this.__bk__=this.$data=this.$els=null},te}); \ No newline at end of file diff --git a/dist/sugar.js b/dist/sugar.js index 466277f5..637d3a4c 100644 --- a/dist/sugar.js +++ b/dist/sugar.js @@ -1,7 +1,7 @@ /*! - * sugar.js v1.3.7 (c) 2016 TANG + * sugar.js v1.3.8 (c) 2016 TANG * Released under the MIT license - * Sat Dec 10 2016 09:54:55 GMT+0800 (CST) + * Fri Dec 23 2016 13:44:07 GMT+0800 (CST) */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : @@ -2246,7 +2246,6 @@ return; } - // 未指定参数,则原生事件对象作为唯一参数 if (!args.length) { args.push(e); @@ -2627,6 +2626,7 @@ var vforAlias = '__vfor__'; var vforGuid = '__vforid__'; + var vforDirIds = '__vfordirids__'; var regForExp = /(.*) (?:in|of) (.*)/; var partlyMethods = 'push|pop|shift|unshift|splice'.split('|'); @@ -2743,6 +2743,14 @@ } } + /** + * 移除该选项中的所有指令实例 + * @param {Element} frag + */ + vfor.dropDirectives = function (frag) { + this.vm.dropDirective(frag[vforDirIds]); + } + /** * 更新视图 * @param {Array} newArray [新数组] @@ -2824,8 +2832,7 @@ for (var i = 0; i < childs.length; i++) { var child = childs[i]; if (child[vforAlias] === this$1.alias) { - this$1.hook('before', child, count++); - parent.removeChild(child); + this$1.removeChild(child, count++); i--; } } @@ -2886,7 +2893,10 @@ def(frag, vforGuid, makeVforGuid()); // 编译片段 - vm.compile(frag, true, scope, this.desc.once); + var dirIds = vm.compile(frag, true, scope, this.desc.once); + + // 挂载指令 id 集合,以便销毁内存占用 + def(frag, vforDirIds, dirIds); listFragment.appendChild(frag); @@ -2947,9 +2957,12 @@ /** * 删除一条选项 * @param {Element} child + * @param {Number} index */ - vfor.removeChild = function (child) { + vfor.removeChild = function (child, index) { if (child) { + this.dropDirectives(child); + this.hook('before', child, index); this.$parent.removeChild(child); } } @@ -2960,8 +2973,7 @@ vfor.shift = function () { var first = this.getFirst(); if (first) { - this.hook('before', first, 0); - this.removeChild(first); + this.removeChild(first, 0); } } @@ -2971,8 +2983,7 @@ vfor.pop = function () { var last = this.getLast(); if (last) { - this.hook('before', last, this.length); - this.removeChild(last); + this.removeChild(last, this.length); } } @@ -3031,8 +3042,7 @@ each(oldList, function (child, index) { // 删除范围内 if (index >= start && index < start + deleteCont) { - this.hook('before', child, index); - this.removeChild(child); + this.removeChild(child, index); } }, this); oldList = null; @@ -3128,7 +3138,9 @@ } this.$parent = parent; - + // 指令实例 id 缓存 + this.$dirIds = null; + this.$elseDirIds = null; // 状态钩子 this.hooks = getHooks(this.vm, el); @@ -3190,16 +3202,24 @@ // 渲染 & 更新视图 if (isRender) { - vm.compile(tpl, true, this.scope, this.desc.once); + var dirIds = vm.compile(tpl, true, this.scope, this.desc.once); var insert = parent.insertBefore(tpl, anchor); this.hook('after', insert, isElse); def(insert, '__vif__', true); + + if (isElse) { + this.$elseDirIds = dirIds; + } else { + this.$dirIds = dirIds; + } } // 不渲染的情况需要移除 DOM 索引的引用 else { var el = anchor.previousSibling; if (el && el.__vif__) { this.hook('before', el, isElse); + var dirIds$1 = isElse ? this.$elseDirIds : this.dirIds; + vm.dropDirective(dirIds$1); removeDOMRegister(vm, template); parent.removeChild(el); } @@ -4155,8 +4175,12 @@ this.$element = element; // DOM 注册索引 this.$regEles = {}; + // 指令实例唯一 id + this.$dirGuid = 1000; + // 指令 id 集合 + this.$dirGuids = []; // 指令实例缓存 - this.$directives = []; + this.$directives = {}; // 钩子和统一回调作用域 this.$context = option.context || this; @@ -4207,8 +4231,11 @@ var children = element.childNodes; var parentOnce = !!once || isOnceNode(element); - if (root && hasDirective(element)) { - this.$queue.push([element, scope]); + if (root) { + this.$dirGuids.length = 0; + if (hasDirective(element)) { + this.$queue.push([element, scope]); + } } def(element, '__vonce__', parentOnce); @@ -4236,6 +4263,7 @@ if (root) { this.compileAll(); + return this.$dirGuids.slice(0); } } @@ -4244,7 +4272,7 @@ */ cp.compileAll = function () { each(this.$queue, function (tuple) { - this.complieNode(tuple); + this.compileNode(tuple); return null; }, this); @@ -4255,7 +4283,7 @@ * 收集并编译节点指令 * @param {Array} tuple [node, scope] */ - cp.complieNode = function (tuple) { + cp.compileNode = function (tuple) { var node = tuple[0]; var scope = tuple[1]; @@ -4346,7 +4374,7 @@ if (once) { dirParser.destroy(); } else { - this.$directives.push(dirParser); + this.saveDirective(dirParser); } } else { warn('[' + directive + '] is an unknown directive!'); @@ -4384,10 +4412,36 @@ if (once) { directive.destroy(); } else { - this.$directives.push(directive); + this.saveDirective(directive); } } + /** + * 缓存一个指令实例到队列 + * @param {Directive} directive [已编译的指令实例] + */ + cp.saveDirective = function (directive) { + var guid = this.$dirGuid++; + this.$dirGuids.push(guid); + this.$directives[guid] = directive; + } + + /** + * 移除指令实例 + * @param {Array} guids [指令实例 id 集合] + */ + cp.dropDirective = function (guids) { + var directives = this.$directives; + each(guids, function (guid) { + var directive = directives[guid]; + if (directive) { + directive.destroy(); + delete directives[guid]; + return null; + } + }, this); + } + /** * 停止编译节点的剩余指令 * 如含有其他指令的 vfor 节点 @@ -4433,10 +4487,7 @@ cp.destroy = function () { this.$data = null; empty(this.$element); - each(this.$directives, function (directive) { - directive.destroy(); - return null; - }); + this.dropDirective(Object.keys(this.$directives)); } /** diff --git a/dist/sugar.min.js b/dist/sugar.min.js index c28ae64e..30a44bb6 100644 --- a/dist/sugar.min.js +++ b/dist/sugar.min.js @@ -1,7 +1,7 @@ /*! - * sugar.js v1.3.7 (c) 2016 TANG + * sugar.js v1.3.8 (c) 2016 TANG * Released under the MIT license - * Sat Dec 10 2016 09:54:57 GMT+0800 (CST) + * Fri Dec 23 2016 13:44:09 GMT+0800 (CST) */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Sugar=e()}(this,function(){"use strict";function t(t,e){return typeof t===e}function e(t){return"[object Object]"===me.toString.call(t)}function n(t){return Array.isArray(t)}function i(e){return t(e,"function")}function s(e){return t(e,"string")}function r(e){return t(e,"boolean")}function o(e){return t(e,"number")&&!isNaN(e)}function a(t){return!(!t||!e(t)||t.nodeType||t===t.window)&&!(t.constructor&&!ge.call(t.constructor.prototype,"isPrototypeOf"))}function h(t){return 0===Object.keys(t).length}function u(t){return null==t?"":t.toString()}function c(t){if(s(t)){var e=Number(t);return o(e)?e:t}return t}function l(){}function f(){be&&be.warn.apply(be,arguments)}function d(){be&&be.error.apply(be,arguments)}function p(t,e){return t&&ge.call(t,e)}function v(t,e,n,i){return Object.defineProperty(t,e,{value:n,writable:!0,enumerable:!!i,configurable:!0})}function _(t,i,s){var r,o;if(s||(s=this),n(t))for(r=0;r]+>/g.test(t)){var n=y("div");n.innerHTML=t,e=x(n)}else e=w(),e.appendChild(document.createTextNode(t));return e}function C(t){return t.replace(ye,"")}function k(t,e,n){if(!e)return t;for(var i=e.split(".");i.length>1&&p(t,i[0]);)t=t[i.shift()];return e=i[0],"undefined"!=typeof n?void(t[e]=n):t[e]}function O(t,e,n,i,s,r){var o=r||this,a=new XMLHttpRequest;return a.open(n,e,!0),a.onreadystatechange=function(){var e=a.status,n=null,i=null;if(4===a.readyState){var r=a.responseText;if("text"!==t)try{r=JSON.parse(r)}catch(t){}200===e?n={success:!0,result:r}:i={result:null,success:!1,status:e},s.call(o,i,n)}},i&&a.setRequestHeader("Content-type","application/x-www-form-urlencoded"),a.send(i),a}function A(t,e,n,s,r){var o=[];return i(e)&&(r=s,s=n,n=e,e=null),_(e,function(t,e){o.push(e+"="+encodeURIComponent(t))}),o.length&&(t=t+"?"+o.join("&")),O(r||"json",t,"GET",null,n,s)}function N(t,e,n,i){return O("json",t,"POST",e?JSON.stringify(e):null,n,i)}function D(t,e,n,i){return A(t,e,n,i,"text")}function E(t,e){return i(e)&&Ce.test(ke.call(e))?function(){this.Super=t,e.apply(this,arguments)}:e}function j(){}function S(t){return t.charAt(0).toUpperCase()+t.substr(1)}function I(t){var e=null;return _($e,function(n){if((n.__rd__&&n.__rd__.name)===t)return e=n,!1}),e}function T(t,e,n,i){return{type:t,from:e,to:null,count:0,name:n,param:i,method:"on"+S(n),returns:null}}function L(t,e){var n=t[e.method];if(i(n))return e.to=t,++e.count,n.call(t,e)}function P(t,e,n){i(e)&&e.call(n,t)}function R(t,e,n,i,s){for(var r=T("fire",t,e,n),o=t.getParent();o;){var a=L(o,r);if(a===!1)return void P(r,i,s);r.from=o,o=o.getParent()}P(r,i,s)}function q(t,e,n,i,s){for(var r=T("broadcast",t,e,n),o=t.getChilds(!0).slice(0);o.length;){var a=o.shift(),h=L(a,r);h!==!1&&(r.from=a,Array.prototype.push.apply(o,a.getChilds(!0)))}P(r,i,s)}function M(t,n,i,r,o,a){if(s(n)){var h,u=n.split("."),c=I(u.shift());u.length?_(u,function(t){return h=c.getChild(t),c=h,null}):h=c,c=null,e(h)&&(n=h)}var l=T("notify",t,i,r);return e(n)?(L(n,l),void P(l,o,a)):(P(l,o,a),f("Component: ["+n+"] is not exist!"))}function U(t,n,i,s){var r=T("globalCast","__core__",t,n);_($e,function(t,n){e(t)&&"0"!==n&&L(t,r)}),P(r,i,s)}function z(t){this.path=t,this.watchers=[],this.guid=Se++}function W(t){return t}function F(t){return""}function H(t){var e=t.charCodeAt(0);if(e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57)return Le;switch(e){case 91:case 93:case 46:case 34:case 39:return Pe;default:return Re}}function B(t){var e=[],n=t.split(""),i=n.length-1,s=H(n[0]);return Me.init(s),_(n,function(t,n){var s=H(t),r=Me.set(s,t);r&&e.push(r),n===i&&Me.saves&&(e.push(Me.saves),Me.reset())}),e}function V(t,e){for(;e.length;)t=t[e.shift()];return t}function G(t){return B(C(t))}function Z(t,n,i){var s=b(i),r=s.pop(),o=V(t,s);e(o)&&(o[r]=n)}function Q(t){var e=Qe.length;return Qe[e]=t,'"'+e+'"'}function J(t,e){return Qe[e]}function X(t){var e=t.charAt(0),n=t.slice(1);return Ve.test(n)?t:(n=n.indexOf('"')>-1?n.replace(Ue,J):n,e+"scope."+n)}function K(t){return He.test(t)&&!ze.test(t)&&0!==t.indexOf("Math.")}function Y(t){return K(t)?"scope."+t:(t=(" "+t).replace(We,Q),t=t.replace(Fe,X),t=t.replace(Ue,J))}function tt(t){if(Ze.test(t))return f("Avoid using unallow keyword in expression ["+t+"]"),l;try{return new Function("scope","return "+Y(t)+";")}catch(e){return d("Invalid generated expression: ["+t+"]"),l}}function et(t){var e=G(t);return e.length?function(t,n){Z(t,n,e)}:(d("Invalid setter expression ["+t+"]"),l)}function nt(t,e){var n=t&&t.__ob__,i=n&&n.dep.guid;if(i){if(Je.indexOf(i)>-1)return;Je.push(i)}_(t,function(t){nt(t,!1)}),e&&(Je.length=0)}function it(t,e,n,s){this.vm=t,g(this,e),this.callback=n,this.context=s||this,this.depIds=[],this.newDepIds=[],this.shallowIds=[],this.depends=[],this.newDepends=[];var r=e.once,o=e.expression,a=i(o);this.getter=a?o:tt(o),this.setter=!r&&e.duplex?et(o):null,this.oldVal=null,this.value=r?this.getValue():this.get()}function st(t){this.parser=t,this.scope=t.scope}function rt(t,e,n,i){this.vm=t,this.el=e,this.desc=n,this.scope=i,this.parse()}function ot(t){return t.prototype=Object.create(rt.prototype)}function at(t){return 1===t.nodeType}function ht(t){return 3===t.nodeType}function ut(t){for(;t.firstChild;)t.removeChild(t.firstChild);return t}function ct(t,e){return t.getAttribute(e)||""}function lt(t,e){t.removeAttribute(e)}function ft(t,e,n){return null==n||n===!1?lt(t,e):void(n===!0?(t[e]=n,dt(t,e)||t.setAttribute(e,"")):n!==ct(t,e)&&t.setAttribute(e,n))}function dt(t,e){return t.hasAttribute(e)}function pt(t,e){var n,i=t.classList;return i?i.contains(e):(n=" "+ct(t,"class")+" ",n.indexOf(" "+e+" ")>-1)}function vt(t,e){var n,i=t.classList;e&&!pt(t,e)&&(i?i.add(e):(n=" "+ct(t,"class")+" ",n.indexOf(" "+e+" ")===-1&&ft(t,"class",(n+e).trim())))}function _t(t,e){var n,i,s=t.classList;if(e&&pt(t,e)){if(s)s.remove(e);else{for(i=" "+e+" ",n=" "+ct(t,"class")+" ";n.indexOf(i)>-1;)n=n.replace(i," ");ft(t,"class",n.trim())}t.className||lt(t,"class")}}function mt(t,e,n,i){t.addEventListener(e,n,i)}function gt(t,e,n,i){t.removeEventListener(e,n,i)}function bt(){this.empty=ut,this.getAttr=ct,this.removeAttr=lt,this.setAttr=ft,this.hasAttr=dt,this.hasClass=pt,this.addClass=vt,this.removeClass=_t,this.addEvent=mt,this.removeEvent=gt}function yt(t){var e,n,i=C(t),s=i.match(nn),r=s&&s[0];return r?(n=i.substr(0,i.indexOf(r)),e="["+r.substr(1,r.length-2)+"]"):n=i,{func:n,args:e}}function wt(t){var e={},n=t.trim();if(en.test(n)){var i=n.length;n=n.substr(1,i-2).replace(/\s/g,"");var s=n.match(rn);_(s,function(t){var n=t.split(":"),i=n[0],s=n[1];i&&s&&(i=i.replace(sn,""),e[i]=s)})}return e}function xt(t,e){var n,i=t.indexOf("."),s="";i>-1?(n=t.substr(0,i),s=t.substr(i+1,t.length)):n=t;var r=yt(e),o=r.func,a=r.args;return{type:n,dress:s,func:o,args:a}}function $t(t){var e=[],n=t.args,i=t.expression;if(n)e.push(xt(n,i));else{var s=wt(i);_(s,function(t,n){e.push(xt(n,t))})}return e}function Ct(t,e){var n,i=e.split("."),s=i.indexOf("self")>-1,r=i.indexOf("stop")>-1,o=i.indexOf("one")>-1,a=i.indexOf("prevent")>-1,h=i.indexOf("capture")>-1;return 0===t.indexOf("key")&&_(i,function(t){if(tn.test(t))return n=+t,!1}),{self:s,stop:r,prevent:a,capture:h,keyCode:n,one:o}}function kt(){this.cache={},this.funcWatchers=[],this.argsWatchers=[],rt.apply(this,arguments)}function Ot(){rt.apply(this,arguments)}function At(t){for(var e=0;e=e&&t.call(t)},e)}function ie(t,e){for(var n=[],i=t.options,s=0;s-1?(n=i.substr(r+1),e=i.substr(0,r)):e=i,{args:n,attr:i,directive:e,expression:s}}function de(t){t.__afterHook__||v(t,"__afterHook__",ct(t,"v-hook:after")),t.__beforeHook__||v(t,"__beforeHook__",ct(t,"v-hook:before"))}function pe(t,e){var n,i,s;return function(r,o,a){var h=r.path;h===n&&o===i&&a===s||(t.apply(e,arguments),n=h,i=o,s=a)}}function ve(t){var n=t.model,s=t.view,r=t.computed,o=t.watchAll;return at(s)?e(n)?(this.$queue=[],this.$data=n,this.$element=s,this.$regEles={},this.$directives=[],this.$context=t.context||this,this.$ob=It(this.$data),r&&Pt(this.$data,r),this.$afters=[],this.$hooks=t.hooks||{},this.$customs=t.customs||{},this.$unifyCb=i(o)?pe(o,this.$context):null,void(t.lazy||this.mount())):f("model must be a type of Object: ",n):f("view must be a type of DOMElement: ",s)}function _e(t){var n=t.context||t.model;_(t.model,function(e,s){i(e)&&(t.model[s]=e.bind(n))}),_(t.methods,function(e,i){t.model[i]=e.bind(n)}),this.__ct__=n,this.__bk__=b(t.model),this.__vm__=new ve(t),this.$data=this.__vm__.$data,this.$els=this.__vm__.$regEles,_(t.watches,function(t,n){i(t)?this.watch(n,t,!1):e(t)&&this.watch(n,t.handler,t.deep)},this)}var me=Object.prototype,ge=me.hasOwnProperty,be=window.console,ye=/\s/g,we=Object.create(null);we.def=v,we.each=_,we.copy=b,we.config=k,we.extend=g,we.hasOwn=p,we.isFunc=i,we.isBool=r,we.isArray=n,we.isObject=e,we.isNumber=o,we.isString=s,we.isEmptyObject=h;var xe=Object.create(null);xe.get=A,xe.post=N,xe.load=D;var $e={id:1,length:0},Ce=/\b\.Super\b/,ke=Function.prototype.toString;j.extend=function(t){function e(t,e,n){var r=s[t];i(r)&&r.call(this,g(!0,n,e))}function n(){}var s=this.prototype,r=n.prototype=Object.create(s);return _(t,function(t,n){r[n]=E(e,t)}),t=null,n.extend=this.extend,r.constructor=n,n};var Oe={fire:R,broadcast:q,notify:M,globalCast:U},Ae="map",Ne="array",De=j.extend({__rd__:{},create:function(t,e,n){if(!s(t))return f("Module name ["+t+"] must be a type of String");if(!i(e))return f("Module Class ["+e+"] must be a type of Component");var r=this.__rd__;if(p(r,Ne)||(r[Ne]=[],r[Ae]={}),r[Ae][t])return f("Module ["+t+"] is already exists!");var o=new e(n),a={name:t,id:$e.id++,pid:r.id||0};return o.__rd__=a,$e[a.id]=o,$e.length++,r[Ne].push(o),r[Ae][t]=o,i(o.init)&&o.init(n,this),o},getParent:function(){var t=this.__rd__,e=t&&t.pid;return $e[e]||null},getChild:function(t){var e=this.__rd__;return e&&e[Ae]&&e[Ae][t]||null},getChilds:function(t){var e=this.__rd__;return t=r(t)&&t,t?e[Ne]||[]:e[Ae]||{}},_removeChild:function(t){for(var e=this.__rd__,n=e[Ae]||{},i=e[Ne]||[],s=n[t],r=0,o=i.length;r-1;if("$remove"===e)return this.bindRemoveEvent(s,r);var a=this.getExpDesc(e),h=new it(this.vm,a,function(t,e){this.off(s,e,o),this.bindEvent(s,r,t,n)},this),u=h.value;return i(u)?(this.bindEvent(s,r,u,n),void(a.once?h.destroy():this.funcWatchers.push(h))):(h.destroy(),f("Directive ["+this.desc.attr+"] must be a type of Function"))},hn.bindRemoveEvent=function(t,e){var n=this.scope;if(!n)return f("The specify event $remove must be used in v-for scope");var i=n.__alias__;this.bindEvent(t,e,function(){n.__viterator__.$remove(n[i])},"["+i+"]")},hn.bindEvent=function(t,e,n,i){var s=Ct(t,e),r=s.self,o=s.stop,a=s.prevent,h=s.capture,u=s.keyCode,c=s.one;v(this.scope||this.vm.$data,"$event","__e__");var l=[];if(i){var f=this.getExpDesc(i),d=new it(this.vm,f,function(t){l=t},this);l=d.value,f.once?d.destroy():this.argsWatchers.push(d)}var p,m=this.el,g=function(t){r&&t.target!==m||u&&u!==t.keyCode||(l.length?_(l,function(e,n){("__e__"===e||e instanceof Event)&&(l[n]=t)}):l.push(t),a&&t.preventDefault(),o&&t.stopPropagation(),n.apply(this,l))},b=on++,y=this;c?(p=function(e){g(e),y.off(t,p,h)},p[an]=b):(n[an]=b,p=g),this.cache[b]=p,this.on(t,p,h)},hn.on=function(t,e,n){mt(this.el,t,e,n)},hn.off=function(t,e,n){var i=this.cache,s=e[an],r=i[s];r&&(gt(this.el,t,r,n),delete i[s])},hn._destroy=function(){m(this.cache),_(this.funcWatchers,function(t){t.destroy()}),_(this.argsWatchers,function(t){t.destroy()})};var un=ot(Ot);un.parse=function(){if(this.scope)f("v-el can not be used inside v-for! Consider use v-custom to handle v-for element.");else{var t=this.desc.expression;this.vm.$regEles[t]=this.el}};var cn="__proto__"in{},ln=Array.prototype,fn=Object.create(ln);_(["pop","push","sort","shift","splice","unshift","reverse"],function(t){var e=ln[t];v(fn,t,function(){for(var n=arguments,i=[],s=this.__ob__,r=0;r=this.length&&(t=this.length),this.splice(t,1,e)[0]}),v(ln,"$remove",function(t){var e=this.indexOf(t);if(e>-1)return this.splice(e,1)});var dn=Object.getOwnPropertyNames(fn),pn="__vfor__",vn="__vforid__",_n=/(.*) (?:in|of) (.*)/,mn="push|pop|shift|unshift|splice".split("|"),gn=ot(Mt);gn.parse=function(){var t=this.el,e=this.desc,n=t.parentNode,i=e.expression,s=i.match(_n);if(!s)return f('The format of v-for must be like "item in/of items"!');if(1!==n.nodeType)return f("v-for cannot use in the root element!");if(dt(t,"v-if"))return f("Do not use v-if and v-for on the same element! Consider filtering the source Array instead.");var r=s[1],o=s[2];this.length=0,this.scopes=[],this.init=!0,this.alias=r,this.partly=!1,this.partlyArgs=[],this.$parent=n,this.end=t.nextSibling,this.start=t.previousSibling,this.bodyDirs=t.__dirs__,this.tpl=t.cloneNode(!0),this.hooks=Rt(this.vm,t),this.isOption="OPTION"===t.tagName&&"SELECT"===n.tagName,e.expression=o,this.bind(),this.updateModel()},gn.updateModel=function(){if(this.isOption){var t=this.$parent.__vmodel__;t&&t.forceUpdate()}},gn.hook=function(t,e,n){var s=this.hooks[t];i(s)&&(s.call(this.vm.$context,e,n,e[vn]),e=null)},gn.update=function(t,e,n,i){this.length=t&&t.length,this.init?(this.$parent.replaceChild(this.buildList(t),this.el),this.el=null,this.init=!1):i&&mn.indexOf(i.method)>-1?(this.partly=!0,this.updatePartly(t,i),this.partly=!1):(this.recompileList(t),this.updateModel())},gn.updatePartly=function(t,e){var n=[],i=e.args,s=e.method,r=this.scopes;switch(this[s].call(this,t,i),s){case"pop":case"shift":break;case"push":case"unshift":n=this.partlyArgs;break;case"splice":n=i.slice(0,2),Array.prototype.push.apply(n,this.partlyArgs)}r[s].apply(r,n),this.partlyArgs.length=0,_(r,function(t,e){t.$index=e})},gn.recompileList=function(t){for(var e=this,n=0,i=this.$parent,s=i.childNodes,r=0;r1&&n.block(this.el),v(u,pn,h),v(u,vn,qt()),n.compile(u,!0,l,this.desc.once),r.appendChild(u),this.hook("after",u,a)},this),r},gn.getChilds=function(){for(var t=this,e=[],n=this.$parent.childNodes,i=0;i=n&&e0,Nn={bind:function(){function t(t){i&&(t=t.trim());var e=se(t,r);o?ne(function(){n.onDebounce=!0,a.set(e)},c(o)):a.set(e)}var e,n=this,i=this.trim,s=this.lazy,r=this.number,o=this.debounce,a=this.directive;this.on("compositionstart",function(){e=!0}),this.on("compositionend",function(){e=!1,s||t(this.value)}),this.on("input",function(){e||s||t(this.value)}),this.on("blur",function(){t(this.value)}),this.on("change",function(){t(this.value)}),An&&(this.on("cut",function(){var e=this;ne(function(){return t(e.value)})}),this.on("keyup",function(e){var n=e.keyCode;8!==n&&46!==n||t(this.value)}))},update:function(t){var e=this.el,n=u(t);e.value===n||this.onDebounce||(e.value=n)}},Dn={bind:function(){var t=this.number,e=this.directive;this.on("change",function(){e.set(se(this.value,t))})},update:function(t){var e=this.el;e.checked=e.value===u(t)}},En={bind:function(){var t=this.multi,e=this.number,n=this.directive;this.on("change",function(){var i=t?ie(this,e):se(this.value,e);n.set(i)}),this.vm.after(this.forceUpdate,this)},update:function(t){var e=this.el,i=this.multi,s=this.desc.expression;if(e.selectedIndex=-1,i&&!n(t))return f(" has no multiple propperty");for(var r=e.options,o=0;o-1:h===u(t)}},forceUpdate:function(){this.update(this.directive.get())}},jn={bind:function(){var t=this.number,e=this.directive;this.on("change",function(){var i=e.get(),s=this.checked;if(r(i))e.set(s);else if(n(i)){var o=se(this.value,t),a=re(o,i);s&&a===-1?i.push(o):a>-1&&i.splice(a,1)}})},update:function(t){var e=this.el,i=se(e.value,this.number);return n(t)||r(t)?void(e.checked=r(t)?t:re(i,t)>-1):f("Checkbox v-model value must be a type of Boolean or Array")}},Sn=["input","select","textarea"],In=ot(oe);In.parse=function(){var t=this.el,e=this.desc,n=t.tagName.toLowerCase(),i="input"===n?ct(t,"type"):n;return Sn.indexOf(n)<0?f("v-model only for using in "+Sn.join(", ")):K(e.expression)?(e.duplex=!0,void this.bindDuplex(i)):f("v-model directive value can be use by static expression")},In.bindDuplex=function(t){var e,n=this.el;switch(t){case"text":case"password":case"textarea":e=Nn,this.trim=dt(n,"trim"),this.lazy=dt(n,"lazy"),this.debounce=ct(n,"debounce");break;case"radio":e=Dn;break;case"checkbox":e=jn;break;case"select":e=En,v(n,"__vmodel__",this),this.multi=dt(n,"multiple"),this.forceUpdate=En.forceUpdate.bind(this)}return e?(this.number=dt(n,"number"),this.update=e.update.bind(this),this.bind(),void(this.desc.once||e.bind.call(this))):f("Do not use incorrect form-type with v-model: ",n)},In.on=function(t,e){mt(this.el,t,e,!1)};var Tn=ot(ae);Tn.parse=function(){var t=this.desc,e=this.vm.$customs[t.args];return i(e)?(this.update=e,void this.bind()):f("Custom directive ["+t.attr+"] must define with a refresh function!")};var Ln={von:kt,vel:Ot,vif:Ft,vfor:Mt,vtext:Ht,vhtml:Bt,vshow:Zt,vbind:ee,vmodel:oe,vcustom:ae},Pn=/\n/g,Rn=/\{\{(.+?)\}\}/g,qn=/(\{\{.*\}\})/,Mn=["velse","vpre","vcloak","vonce","vhook"],Un=ve.prototype;Un.mount=function(){this.$done=!1,this.$fragment=x(this.$element),this.compile(this.$fragment,!0)},Un.compile=function(t,e,n,i){var s=this,r=t.childNodes,o=!!i||ue(t);e&&le(t)&&this.$queue.push([t,n]),v(t,"__vonce__",o);for(var a=0;a1&&o!==a.length-1){var f=a.splice(o,1)[0];a.push(f),f=null}i&&(v(e,"__dirs__",a.length),a=[i],i=null),_(a,function(t){this.parse(e,t,n)},this)}else ht(e)&&this.parseText(e,n)},Un.parse=function(t,e,n){var i=t.__vonce__,s=fe(e),r=s.directive,o="v"+r.substr(2),a=Ln[o];if(lt(t,s.attr),!(Mn.indexOf(o)>-1))if(a){s.once=i;var h=new a(this,t,s,n);i?h.destroy():this.$directives.push(h)}else f("["+r+"] is an unknown directive!")},Un.parseText=function(t,e){var n=[],i={},s=t.parentNode&&t.parentNode.__vonce__,r=t.textContent.trim().replace(Pn,""),o=r.split(Rn),a=r.match(Rn);_(o,function(t){a.indexOf("{{"+t+"}}")>-1?n.push("("+t+")"):t&&n.push('"'+t+'"')}),i.once=s,i.expression=n.join("+");var h=new Ln.vtext(this,t,i,e);s?h.destroy():this.$directives.push(h)},Un.block=function(t){_(this.$queue,function(e){if(t===e[0])return null})},Un.after=function(t,e){this.$afters.push([t,e])},Un.completed=function(){0!==this.$queue.length||this.$done||(this.$done=!0,this.$element.appendChild(this.$fragment),_(this.$afters,function(t){return t[0].call(t[1]),null}))},Un.destroy=function(){ -this.$data=null,ut(this.$element),_(this.$directives,function(t){return t.destroy(),null})};var zn=_e.prototype;zn.mount=function(){this.__vm__.mount()},zn.get=function(t){var e=this.$data;return s(t)?k(e,t):e},zn.getCopy=function(t){return b(this.get(t))},zn.set=function(t,n){var i=this.$data;s(t)?k(i,t,n):e(t)&&_(t,function(t,e){k(i,e,t)})},zn.reset=function(t){var e=this.$data,i=b(this.__bk__);s(t)?e[t]=i[t]:n(t)?_(t,function(t){e[t]=i[t]}):_(e,function(t,n){e[n]=i[n]})},zn.watch=function(t,e,n){return new it(this,{deep:n,expression:t},e.bind(this.__ct__))},zn.destroy=function(){this.__vm__.destroy(),this.__vm__=this.__ct__=this.__bk__=this.$data=this.$els=null};var Wn=1e3,Fn="__eventid__",Hn=De.extend({init:function(t){this.__config__=g(!0,{target:null,replace:!1,tag:"div",css:null,attr:null,class:"",view:"",template:"",tplParam:null,model:null,methods:null,watches:null,watchAll:null,computed:null,customs:null,hooks:null,lazy:!1,childs:null,cbRender:"afterRender"},t),this.el=null,this.vm=null,this.$=new bt,this.__visible__="",this.__ready__=!1,this.__listeners__={},i(this.beforeRender)&&this.beforeRender(),this.getConfig("template")?this._loadTemplate():this._render()},_loadTemplate:function(){var t=this.getConfig(),e=t.template;xe.load(e,t.tplParam,function(t,n){var i;t?(i=t.status+": "+e,f(t)):i=n.result,this.setConfig("view",i),this._render()},this)},_render:function(){if(this.__ready__)return this;this.__ready__=!0;var t=this.getConfig(),n=t.target,r=n instanceof HTMLElement;r?this.el=y(t.tag):this.el=document.querySelector(n);var o=t.class;o&&s(o)&&_(o.split(" "),function(t){vt(this.el,t)},this),e(t.css)&&_(t.css,function(t,e){this.el.style[e]=t},this),e(t.attr)&&_(t.attr,function(t,e){ft(this.el,e,t)},this),t.view&&this.el.appendChild($(t.view));var a=t.model;e(a)&&(this.vm=new _e({view:this.el,model:a,methods:t.methods,watches:t.watches,watchAll:t.watchAll,computed:t.computed,customs:t.customs,hooks:t.hooks,context:this,lazy:t.lazy}));var h=this.el.style.display;this.__visible__="none"===h?"":h,_(t.childs,this._buildBatchChilds,this),r&&(t.replace?n.parentNode.replaceChild(this.el,n):n.appendChild(this.el));var u=this[t.cbRender];i(u)&&u.call(this)},_buildBatchChilds:function(t,e){var n=this,i=this.queryAll(e.toLowerCase());switch(i.length||(i=this.queryAll("[name="+e+"]")),i.length){case 0:f("Cannot find target element for sub component ["+e+"]");break;case 1:this._createChild(i[0],e,t);break;default:for(var s=0;s]+>/g.test(t)){var i=y("div");i.innerHTML=t,e=x(i)}else e=w(),e.appendChild(document.createTextNode(t));return e}function C(t){return t.replace(ye,"")}function k(t,e,i){if(!e)return t;for(var n=e.split(".");n.length>1&&p(t,n[0]);)t=t[n.shift()];return e=n[0],"undefined"!=typeof i?void(t[e]=i):t[e]}function O(t,e,i,n,s,r){var o=r||this,a=new XMLHttpRequest;return a.open(i,e,!0),a.onreadystatechange=function(){var e=a.status,i=null,n=null;if(4===a.readyState){var r=a.responseText;if("text"!==t)try{r=JSON.parse(r)}catch(t){}200===e?i={success:!0,result:r}:n={result:null,success:!1,status:e},s.call(o,n,i)}},n&&a.setRequestHeader("Content-type","application/x-www-form-urlencoded"),a.send(n),a}function A(t,e,i,s,r){var o=[];return n(e)&&(r=s,s=i,i=e,e=null),_(e,function(t,e){o.push(e+"="+encodeURIComponent(t))}),o.length&&(t=t+"?"+o.join("&")),O(r||"json",t,"GET",null,i,s)}function D(t,e,i,n){return O("json",t,"POST",e?JSON.stringify(e):null,i,n)}function N(t,e,i,n){return A(t,e,i,n,"text")}function E(t,e){return n(e)&&Ce.test(ke.call(e))?function(){this.Super=t,e.apply(this,arguments)}:e}function I(){}function j(t){return t.charAt(0).toUpperCase()+t.substr(1)}function S(t){var e=null;return _($e,function(i){if((i.__rd__&&i.__rd__.name)===t)return e=i,!1}),e}function T(t,e,i,n){return{type:t,from:e,to:null,count:0,name:i,param:n,method:"on"+j(i),returns:null}}function L(t,e){var i=t[e.method];if(n(i))return e.to=t,++e.count,i.call(t,e)}function P(t,e,i){n(e)&&e.call(i,t)}function R(t,e,i,n,s){for(var r=T("fire",t,e,i),o=t.getParent();o;){var a=L(o,r);if(a===!1)return void P(r,n,s);r.from=o,o=o.getParent()}P(r,n,s)}function q(t,e,i,n,s){for(var r=T("broadcast",t,e,i),o=t.getChilds(!0).slice(0);o.length;){var a=o.shift(),h=L(a,r);h!==!1&&(r.from=a,Array.prototype.push.apply(o,a.getChilds(!0)))}P(r,n,s)}function M(t,i,n,r,o,a){if(s(i)){var h,u=i.split("."),c=S(u.shift());u.length?_(u,function(t){return h=c.getChild(t),c=h,null}):h=c,c=null,e(h)&&(i=h)}var l=T("notify",t,n,r);return e(i)?(L(i,l),void P(l,o,a)):(P(l,o,a),f("Component: ["+i+"] is not exist!"))}function U(t,i,n,s){var r=T("globalCast","__core__",t,i);_($e,function(t,i){e(t)&&"0"!==i&&L(t,r)}),P(r,n,s)}function z(t){this.path=t,this.watchers=[],this.guid=je++}function G(t){return t}function W(t){return""}function F(t){var e=t.charCodeAt(0);if(e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57)return Le;switch(e){case 91:case 93:case 46:case 34:case 39:return Pe;default:return Re}}function H(t){var e=[],i=t.split(""),n=i.length-1,s=F(i[0]);return Me.init(s),_(i,function(t,i){var s=F(t),r=Me.set(s,t);r&&e.push(r),i===n&&Me.saves&&(e.push(Me.saves),Me.reset())}),e}function B(t,e){for(;e.length;)t=t[e.shift()];return t}function V(t){return H(C(t))}function Z(t,i,n){var s=b(n),r=s.pop(),o=B(t,s);e(o)&&(o[r]=i)}function Q(t){var e=Qe.length;return Qe[e]=t,'"'+e+'"'}function J(t,e){return Qe[e]}function X(t){var e=t.charAt(0),i=t.slice(1);return Be.test(i)?t:(i=i.indexOf('"')>-1?i.replace(Ue,J):i,e+"scope."+i)}function K(t){return Fe.test(t)&&!ze.test(t)&&0!==t.indexOf("Math.")}function Y(t){return K(t)?"scope."+t:(t=(" "+t).replace(Ge,Q),t=t.replace(We,X),t=t.replace(Ue,J))}function tt(t){if(Ze.test(t))return f("Avoid using unallow keyword in expression ["+t+"]"),l;try{return new Function("scope","return "+Y(t)+";")}catch(e){return d("Invalid generated expression: ["+t+"]"),l}}function et(t){var e=V(t);return e.length?function(t,i){Z(t,i,e)}:(d("Invalid setter expression ["+t+"]"),l)}function it(t,e){var i=t&&t.__ob__,n=i&&i.dep.guid;if(n){if(Je.indexOf(n)>-1)return;Je.push(n)}_(t,function(t){it(t,!1)}),e&&(Je.length=0)}function nt(t,e,i,s){this.vm=t,g(this,e),this.callback=i,this.context=s||this,this.depIds=[],this.newDepIds=[],this.shallowIds=[],this.depends=[],this.newDepends=[];var r=e.once,o=e.expression,a=n(o);this.getter=a?o:tt(o),this.setter=!r&&e.duplex?et(o):null,this.oldVal=null,this.value=r?this.getValue():this.get()}function st(t){this.parser=t,this.scope=t.scope}function rt(t,e,i,n){this.vm=t,this.el=e,this.desc=i,this.scope=n,this.parse()}function ot(t){return t.prototype=Object.create(rt.prototype)}function at(t){return 1===t.nodeType}function ht(t){return 3===t.nodeType}function ut(t){for(;t.firstChild;)t.removeChild(t.firstChild);return t}function ct(t,e){return t.getAttribute(e)||""}function lt(t,e){t.removeAttribute(e)}function ft(t,e,i){return null==i||i===!1?lt(t,e):void(i===!0?(t[e]=i,dt(t,e)||t.setAttribute(e,"")):i!==ct(t,e)&&t.setAttribute(e,i))}function dt(t,e){return t.hasAttribute(e)}function pt(t,e){var i,n=t.classList;return n?n.contains(e):(i=" "+ct(t,"class")+" ",i.indexOf(" "+e+" ")>-1)}function vt(t,e){var i,n=t.classList;e&&!pt(t,e)&&(n?n.add(e):(i=" "+ct(t,"class")+" ",i.indexOf(" "+e+" ")===-1&&ft(t,"class",(i+e).trim())))}function _t(t,e){var i,n,s=t.classList;if(e&&pt(t,e)){if(s)s.remove(e);else{for(n=" "+e+" ",i=" "+ct(t,"class")+" ";i.indexOf(n)>-1;)i=i.replace(n," ");ft(t,"class",i.trim())}t.className||lt(t,"class")}}function mt(t,e,i,n){t.addEventListener(e,i,n)}function gt(t,e,i,n){t.removeEventListener(e,i,n)}function bt(){this.empty=ut,this.getAttr=ct,this.removeAttr=lt,this.setAttr=ft,this.hasAttr=dt,this.hasClass=pt,this.addClass=vt,this.removeClass=_t,this.addEvent=mt,this.removeEvent=gt}function yt(t){var e,i,n=C(t),s=n.match(ii),r=s&&s[0];return r?(i=n.substr(0,n.indexOf(r)),e="["+r.substr(1,r.length-2)+"]"):i=n,{func:i,args:e}}function wt(t){var e={},i=t.trim();if(ei.test(i)){var n=i.length;i=i.substr(1,n-2).replace(/\s/g,"");var s=i.match(si);_(s,function(t){var i=t.split(":"),n=i[0],s=i[1];n&&s&&(n=n.replace(ni,""),e[n]=s)})}return e}function xt(t,e){var i,n=t.indexOf("."),s="";n>-1?(i=t.substr(0,n),s=t.substr(n+1,t.length)):i=t;var r=yt(e),o=r.func,a=r.args;return{type:i,dress:s,func:o,args:a}}function $t(t){var e=[],i=t.args,n=t.expression;if(i)e.push(xt(i,n));else{var s=wt(n);_(s,function(t,i){e.push(xt(i,t))})}return e}function Ct(t,e){var i,n=e.split("."),s=n.indexOf("self")>-1,r=n.indexOf("stop")>-1,o=n.indexOf("one")>-1,a=n.indexOf("prevent")>-1,h=n.indexOf("capture")>-1;return 0===t.indexOf("key")&&_(n,function(t){if(ti.test(t))return i=+t,!1}),{self:s,stop:r,prevent:a,capture:h,keyCode:i,one:o}}function kt(){this.cache={},this.funcWatchers=[],this.argsWatchers=[],rt.apply(this,arguments)}function Ot(){rt.apply(this,arguments)}function At(t){for(var e=0;e=e&&t.call(t)},e)}function ne(t,e){for(var i=[],n=t.options,s=0;s-1?(i=n.substr(r+1),e=n.substr(0,r)):e=n,{args:i,attr:n,directive:e,expression:s}}function de(t){t.__afterHook__||v(t,"__afterHook__",ct(t,"v-hook:after")),t.__beforeHook__||v(t,"__beforeHook__",ct(t,"v-hook:before"))}function pe(t,e){var i,n,s;return function(r,o,a){var h=r.path;h===i&&o===n&&a===s||(t.apply(e,arguments),i=h,n=o,s=a)}}function ve(t){var i=t.model,s=t.view,r=t.computed,o=t.watchAll;return at(s)?e(i)?(this.$queue=[],this.$data=i,this.$element=s,this.$regEles={},this.$dirGuid=1e3,this.$dirGuids=[],this.$directives={},this.$context=t.context||this,this.$ob=St(this.$data),r&&Pt(this.$data,r),this.$afters=[],this.$hooks=t.hooks||{},this.$customs=t.customs||{},this.$unifyCb=n(o)?pe(o,this.$context):null,void(t.lazy||this.mount())):f("model must be a type of Object: ",i):f("view must be a type of DOMElement: ",s)}function _e(t){var i=t.context||t.model;_(t.model,function(e,s){n(e)&&(t.model[s]=e.bind(i))}),_(t.methods,function(e,n){t.model[n]=e.bind(i)}),this.__ct__=i,this.__bk__=b(t.model),this.__vm__=new ve(t),this.$data=this.__vm__.$data,this.$els=this.__vm__.$regEles,_(t.watches,function(t,i){n(t)?this.watch(i,t,!1):e(t)&&this.watch(i,t.handler,t.deep)},this)}var me=Object.prototype,ge=me.hasOwnProperty,be=window.console,ye=/\s/g,we=Object.create(null);we.def=v,we.each=_,we.copy=b,we.config=k,we.extend=g,we.hasOwn=p,we.isFunc=n,we.isBool=r,we.isArray=i,we.isObject=e,we.isNumber=o,we.isString=s,we.isEmptyObject=h;var xe=Object.create(null);xe.get=A,xe.post=D,xe.load=N;var $e={id:1,length:0},Ce=/\b\.Super\b/,ke=Function.prototype.toString;I.extend=function(t){function e(t,e,i){var r=s[t];n(r)&&r.call(this,g(!0,i,e))}function i(){}var s=this.prototype,r=i.prototype=Object.create(s);return _(t,function(t,i){r[i]=E(e,t)}),t=null,i.extend=this.extend,r.constructor=i,i};var Oe={fire:R,broadcast:q,notify:M,globalCast:U},Ae="map",De="array",Ne=I.extend({__rd__:{},create:function(t,e,i){if(!s(t))return f("Module name ["+t+"] must be a type of String");if(!n(e))return f("Module Class ["+e+"] must be a type of Component");var r=this.__rd__;if(p(r,De)||(r[De]=[],r[Ae]={}),r[Ae][t])return f("Module ["+t+"] is already exists!");var o=new e(i),a={name:t,id:$e.id++,pid:r.id||0};return o.__rd__=a,$e[a.id]=o,$e.length++,r[De].push(o),r[Ae][t]=o,n(o.init)&&o.init(i,this),o},getParent:function(){var t=this.__rd__,e=t&&t.pid;return $e[e]||null},getChild:function(t){var e=this.__rd__;return e&&e[Ae]&&e[Ae][t]||null},getChilds:function(t){var e=this.__rd__;return t=r(t)&&t,t?e[De]||[]:e[Ae]||{}},_removeChild:function(t){for(var e=this.__rd__,i=e[Ae]||{},n=e[De]||[],s=i[t],r=0,o=n.length;r-1;if("$remove"===e)return this.bindRemoveEvent(s,r);var a=this.getExpDesc(e),h=new nt(this.vm,a,function(t,e){this.off(s,e,o),this.bindEvent(s,r,t,i)},this),u=h.value;return n(u)?(this.bindEvent(s,r,u,i),void(a.once?h.destroy():this.funcWatchers.push(h))):(h.destroy(),f("Directive ["+this.desc.attr+"] must be a type of Function"))},ai.bindRemoveEvent=function(t,e){var i=this.scope;if(!i)return f("The specify event $remove must be used in v-for scope");var n=i.__alias__;this.bindEvent(t,e,function(){i.__viterator__.$remove(i[n])},"["+n+"]")},ai.bindEvent=function(t,e,i,n){var s=Ct(t,e),r=s.self,o=s.stop,a=s.prevent,h=s.capture,u=s.keyCode,c=s.one;v(this.scope||this.vm.$data,"$event","__e__");var l=[];if(n){var f=this.getExpDesc(n),d=new nt(this.vm,f,function(t){l=t},this);l=d.value,f.once?d.destroy():this.argsWatchers.push(d)}var p,m=this.el,g=function(t){r&&t.target!==m||u&&u!==t.keyCode||(l.length?_(l,function(e,i){("__e__"===e||e instanceof Event)&&(l[i]=t)}):l.push(t),a&&t.preventDefault(),o&&t.stopPropagation(),i.apply(this,l))},b=ri++,y=this;c?(p=function(e){g(e),y.off(t,p,h)},p[oi]=b):(i[oi]=b,p=g),this.cache[b]=p,this.on(t,p,h)},ai.on=function(t,e,i){mt(this.el,t,e,i)},ai.off=function(t,e,i){var n=this.cache,s=e[oi],r=n[s];r&&(gt(this.el,t,r,i),delete n[s])},ai._destroy=function(){m(this.cache),_(this.funcWatchers,function(t){t.destroy()}),_(this.argsWatchers,function(t){t.destroy()})};var hi=ot(Ot);hi.parse=function(){if(this.scope)f("v-el can not be used inside v-for! Consider use v-custom to handle v-for element.");else{var t=this.desc.expression;this.vm.$regEles[t]=this.el}};var ui="__proto__"in{},ci=Array.prototype,li=Object.create(ci);_(["pop","push","sort","shift","splice","unshift","reverse"],function(t){var e=ci[t];v(li,t,function(){for(var i=arguments,n=[],s=this.__ob__,r=0;r=this.length&&(t=this.length),this.splice(t,1,e)[0]}),v(ci,"$remove",function(t){var e=this.indexOf(t);if(e>-1)return this.splice(e,1)});var fi=Object.getOwnPropertyNames(li),di="__vfor__",pi="__vforid__",vi="__vfordirids__",_i=/(.*) (?:in|of) (.*)/,mi="push|pop|shift|unshift|splice".split("|"),gi=ot(Mt);gi.parse=function(){var t=this.el,e=this.desc,i=t.parentNode,n=e.expression,s=n.match(_i);if(!s)return f('The format of v-for must be like "item in/of items"!');if(1!==i.nodeType)return f("v-for cannot use in the root element!");if(dt(t,"v-if"))return f("Do not use v-if and v-for on the same element! Consider filtering the source Array instead.");var r=s[1],o=s[2];this.length=0,this.scopes=[],this.init=!0,this.alias=r,this.partly=!1,this.partlyArgs=[],this.$parent=i,this.end=t.nextSibling,this.start=t.previousSibling,this.bodyDirs=t.__dirs__,this.tpl=t.cloneNode(!0),this.hooks=Rt(this.vm,t),this.isOption="OPTION"===t.tagName&&"SELECT"===i.tagName,e.expression=o,this.bind(),this.updateModel()},gi.updateModel=function(){if(this.isOption){var t=this.$parent.__vmodel__;t&&t.forceUpdate()}},gi.hook=function(t,e,i){var s=this.hooks[t];n(s)&&(s.call(this.vm.$context,e,i,e[pi]),e=null)},gi.dropDirectives=function(t){this.vm.dropDirective(t[vi])},gi.update=function(t,e,i,n){this.length=t&&t.length,this.init?(this.$parent.replaceChild(this.buildList(t),this.el),this.el=null,this.init=!1):n&&mi.indexOf(n.method)>-1?(this.partly=!0,this.updatePartly(t,n),this.partly=!1):(this.recompileList(t),this.updateModel())},gi.updatePartly=function(t,e){var i=[],n=e.args,s=e.method,r=this.scopes;switch(this[s].call(this,t,n),s){case"pop":case"shift":break;case"push":case"unshift":i=this.partlyArgs;break;case"splice":i=n.slice(0,2),Array.prototype.push.apply(i,this.partlyArgs)}r[s].apply(r,i),this.partlyArgs.length=0,_(r,function(t,e){t.$index=e})},gi.recompileList=function(t){for(var e=this,i=0,n=this.$parent,s=n.childNodes,r=0;r1&&i.block(this.el),v(u,di,h),v(u,pi,qt());var f=i.compile(u,!0,l,this.desc.once);v(u,vi,f),r.appendChild(u),this.hook("after",u,a)},this),r},gi.getChilds=function(){for(var t=this,e=[],i=this.$parent.childNodes,n=0;n=i&&e0,Di={bind:function(){function t(t){n&&(t=t.trim());var e=se(t,r);o?ie(function(){i.onDebounce=!0,a.set(e)},c(o)):a.set(e)}var e,i=this,n=this.trim,s=this.lazy,r=this.number,o=this.debounce,a=this.directive;this.on("compositionstart",function(){e=!0}),this.on("compositionend",function(){e=!1,s||t(this.value)}),this.on("input",function(){e||s||t(this.value)}),this.on("blur",function(){t(this.value)}),this.on("change",function(){t(this.value)}),Ai&&(this.on("cut",function(){var e=this;ie(function(){return t(e.value)})}),this.on("keyup",function(e){var i=e.keyCode;8!==i&&46!==i||t(this.value)}))},update:function(t){var e=this.el,i=u(t);e.value===i||this.onDebounce||(e.value=i)}},Ni={bind:function(){var t=this.number,e=this.directive;this.on("change",function(){e.set(se(this.value,t))})},update:function(t){var e=this.el;e.checked=e.value===u(t)}},Ei={bind:function(){var t=this.multi,e=this.number,i=this.directive;this.on("change",function(){var n=t?ne(this,e):se(this.value,e);i.set(n)}),this.vm.after(this.forceUpdate,this)},update:function(t){var e=this.el,n=this.multi,s=this.desc.expression;if(e.selectedIndex=-1,n&&!i(t))return f(" has no multiple propperty");for(var r=e.options,o=0;o-1:h===u(t)}},forceUpdate:function(){this.update(this.directive.get())}},Ii={bind:function(){var t=this.number,e=this.directive;this.on("change",function(){var n=e.get(),s=this.checked;if(r(n))e.set(s);else if(i(n)){var o=se(this.value,t),a=re(o,n);s&&a===-1?n.push(o):a>-1&&n.splice(a,1)}})},update:function(t){var e=this.el,n=se(e.value,this.number);return i(t)||r(t)?void(e.checked=r(t)?t:re(n,t)>-1):f("Checkbox v-model value must be a type of Boolean or Array")}},ji=["input","select","textarea"],Si=ot(oe);Si.parse=function(){var t=this.el,e=this.desc,i=t.tagName.toLowerCase(),n="input"===i?ct(t,"type"):i;return ji.indexOf(i)<0?f("v-model only for using in "+ji.join(", ")):K(e.expression)?(e.duplex=!0,void this.bindDuplex(n)):f("v-model directive value can be use by static expression")},Si.bindDuplex=function(t){var e,i=this.el;switch(t){case"text":case"password":case"textarea":e=Di,this.trim=dt(i,"trim"),this.lazy=dt(i,"lazy"),this.debounce=ct(i,"debounce");break;case"radio":e=Ni;break;case"checkbox":e=Ii;break;case"select":e=Ei,v(i,"__vmodel__",this),this.multi=dt(i,"multiple"),this.forceUpdate=Ei.forceUpdate.bind(this)}return e?(this.number=dt(i,"number"),this.update=e.update.bind(this),this.bind(),void(this.desc.once||e.bind.call(this))):f("Do not use incorrect form-type with v-model: ",i)},Si.on=function(t,e){mt(this.el,t,e,!1)};var Ti=ot(ae);Ti.parse=function(){var t=this.desc,e=this.vm.$customs[t.args];return n(e)?(this.update=e,void this.bind()):f("Custom directive ["+t.attr+"] must define with a refresh function!")};var Li={von:kt,vel:Ot,vif:Wt,vfor:Mt,vtext:Ft,vhtml:Ht,vshow:Zt,vbind:ee,vmodel:oe,vcustom:ae},Pi=/\n/g,Ri=/\{\{(.+?)\}\}/g,qi=/(\{\{.*\}\})/,Mi=["velse","vpre","vcloak","vonce","vhook"],Ui=ve.prototype;Ui.mount=function(){this.$done=!1,this.$fragment=x(this.$element),this.compile(this.$fragment,!0)},Ui.compile=function(t,e,i,n){var s=this,r=t.childNodes,o=!!n||ue(t);e&&(this.$dirGuids.length=0,le(t)&&this.$queue.push([t,i])),v(t,"__vonce__",o);for(var a=0;a1&&o!==a.length-1){var f=a.splice(o,1)[0];a.push(f),f=null}n&&(v(e,"__dirs__",a.length),a=[n],n=null),_(a,function(t){this.parse(e,t,i)},this)}else ht(e)&&this.parseText(e,i)},Ui.parse=function(t,e,i){var n=t.__vonce__,s=fe(e),r=s.directive,o="v"+r.substr(2),a=Li[o];if(lt(t,s.attr),!(Mi.indexOf(o)>-1))if(a){s.once=n;var h=new a(this,t,s,i);n?h.destroy():this.saveDirective(h)}else f("["+r+"] is an unknown directive!")},Ui.parseText=function(t,e){var i=[],n={},s=t.parentNode&&t.parentNode.__vonce__,r=t.textContent.trim().replace(Pi,""),o=r.split(Ri),a=r.match(Ri);_(o,function(t){a.indexOf("{{"+t+"}}")>-1?i.push("("+t+")"):t&&i.push('"'+t+'"')}),n.once=s,n.expression=i.join("+");var h=new Li.vtext(this,t,n,e);s?h.destroy():this.saveDirective(h)},Ui.saveDirective=function(t){var e=this.$dirGuid++; +this.$dirGuids.push(e),this.$directives[e]=t},Ui.dropDirective=function(t){var e=this.$directives;_(t,function(t){var i=e[t];if(i)return i.destroy(),delete e[t],null},this)},Ui.block=function(t){_(this.$queue,function(e){if(t===e[0])return null})},Ui.after=function(t,e){this.$afters.push([t,e])},Ui.completed=function(){0!==this.$queue.length||this.$done||(this.$done=!0,this.$element.appendChild(this.$fragment),_(this.$afters,function(t){return t[0].call(t[1]),null}))},Ui.destroy=function(){this.$data=null,ut(this.$element),this.dropDirective(Object.keys(this.$directives))};var zi=_e.prototype;zi.mount=function(){this.__vm__.mount()},zi.get=function(t){var e=this.$data;return s(t)?k(e,t):e},zi.getCopy=function(t){return b(this.get(t))},zi.set=function(t,i){var n=this.$data;s(t)?k(n,t,i):e(t)&&_(t,function(t,e){k(n,e,t)})},zi.reset=function(t){var e=this.$data,n=b(this.__bk__);s(t)?e[t]=n[t]:i(t)?_(t,function(t){e[t]=n[t]}):_(e,function(t,i){e[i]=n[i]})},zi.watch=function(t,e,i){return new nt(this,{deep:i,expression:t},e.bind(this.__ct__))},zi.destroy=function(){this.__vm__.destroy(),this.__vm__=this.__ct__=this.__bk__=this.$data=this.$els=null};var Gi=1e3,Wi="__eventid__",Fi=Ne.extend({init:function(t){this.__config__=g(!0,{target:null,replace:!1,tag:"div",css:null,attr:null,class:"",view:"",template:"",tplParam:null,model:null,methods:null,watches:null,watchAll:null,computed:null,customs:null,hooks:null,lazy:!1,childs:null,cbRender:"afterRender"},t),this.el=null,this.vm=null,this.$=new bt,this.__visible__="",this.__ready__=!1,this.__listeners__={},n(this.beforeRender)&&this.beforeRender(),this.getConfig("template")?this._loadTemplate():this._render()},_loadTemplate:function(){var t=this.getConfig(),e=t.template;xe.load(e,t.tplParam,function(t,i){var n;t?(n=t.status+": "+e,f(t)):n=i.result,this.setConfig("view",n),this._render()},this)},_render:function(){if(this.__ready__)return this;this.__ready__=!0;var t=this.getConfig(),i=t.target,r=i instanceof HTMLElement;r?this.el=y(t.tag):this.el=document.querySelector(i);var o=t.class;o&&s(o)&&_(o.split(" "),function(t){vt(this.el,t)},this),e(t.css)&&_(t.css,function(t,e){this.el.style[e]=t},this),e(t.attr)&&_(t.attr,function(t,e){ft(this.el,e,t)},this),t.view&&this.el.appendChild($(t.view));var a=t.model;e(a)&&(this.vm=new _e({view:this.el,model:a,methods:t.methods,watches:t.watches,watchAll:t.watchAll,computed:t.computed,customs:t.customs,hooks:t.hooks,context:this,lazy:t.lazy}));var h=this.el.style.display;this.__visible__="none"===h?"":h,_(t.childs,this._buildBatchChilds,this),r&&(t.replace?i.parentNode.replaceChild(this.el,i):i.appendChild(this.el));var u=this[t.cbRender];n(u)&&u.call(this)},_buildBatchChilds:function(t,e){var i=this,n=this.queryAll(e.toLowerCase());switch(n.length||(n=this.queryAll("[name="+e+"]")),n.length){case 0:f("Cannot find target element for sub component ["+e+"]");break;case 1:this._createChild(n[0],e,t);break;default:for(var s=0;s