Comparing version 0.9.3 to 0.10.0
/* | ||
Vue.js v0.9.3 | ||
Vue.js v0.10.0 | ||
(c) 2014 Evan You | ||
License: MIT | ||
*/ | ||
!function(){"use strict";function e(t,i,n){var r=e.resolve(t);if(null==r){n=n||t,i=i||"root";var s=new Error('Failed to require "'+n+'" from "'+i+'"');throw s.path=n,s.parent=i,s.require=!0,s}var o=e.modules[r];if(!o._resolving&&!o.exports){var a={};a.exports={},a.client=a.component=!0,o._resolving=!0,o.call(this,a.exports,e.relative(r),a),delete o._resolving,o.exports=a.exports}return o.exports}e.modules={},e.aliases={},e.resolve=function(t){"/"===t.charAt(0)&&(t=t.slice(1));for(var i=[t,t+".js",t+".json",t+"/index.js",t+"/index.json"],n=0;n<i.length;n++){var t=i[n];if(e.modules.hasOwnProperty(t))return t;if(e.aliases.hasOwnProperty(t))return e.aliases[t]}},e.normalize=function(e,t){var i=[];if("."!=t.charAt(0))return t;e=e.split("/"),t=t.split("/");for(var n=0;n<t.length;++n)".."==t[n]?e.pop():"."!=t[n]&&""!=t[n]&&i.push(t[n]);return e.concat(i).join("/")},e.register=function(t,i){e.modules[t]=i},e.alias=function(t,i){if(!e.modules.hasOwnProperty(t))throw new Error('Failed to alias "'+t+'", it does not exist');e.aliases[i]=t},e.relative=function(t){function i(e,t){for(var i=e.length;i--;)if(e[i]===t)return i;return-1}function n(i){var r=n.resolve(i);return e(r,t,i)}var r=e.normalize(t,"..");return n.resolve=function(n){var s=n.charAt(0);if("/"==s)return n.slice(1);if("."==s)return e.normalize(r,n);var o=t.split("/"),a=i(o,"deps")+1;return a||(a=0),n=o.slice(0,a+1).join("/")+"/deps/"+n},n.exists=function(t){return e.modules.hasOwnProperty(n.resolve(t))},n},e.register("vue/src/main.js",function(e,t,i){function n(e){var t=this;e=r(e,t.options,!0),a.processOptions(e);var i=function(i,n){n||(i=r(i,e,!0)),t.call(this,i,!0)},s=i.prototype=Object.create(t.prototype);a.defProtected(s,"constructor",i);var c=e.methods;if(c)for(var l in c)l in o.prototype||"function"!=typeof c[l]||(s[l]=c[l]);return i.extend=n,i.super=t,i.options=e,u.forEach(function(e){i[e]=o[e]}),i.use=o.use,i.require=o.require,i}function r(e,t,i){if(e=e||{},!t)return e;for(var n in t)if("el"!==n&&"methods"!==n){var s=e[n],o=t[n],c=a.typeOf(s),u=a.typeOf(o);i&&"Function"===c&&o?(e[n]=[s],Array.isArray(o)?e[n]=e[n].concat(o):e[n].push(o)):!i||"Object"!==c&&"Object"!==u?void 0===s&&(e[n]=o):e[n]=r(s,o)}return e}var s=t("./config"),o=t("./viewmodel"),a=t("./utils"),c=a.hash,u=["directive","filter","partial","effect","component"];t("./observer"),t("./transition"),o.options=s.globalAssets={directives:t("./directives"),filters:t("./filters"),partials:c(),effects:c(),components:c()},u.forEach(function(e){o[e]=function(t,i){var n=this.options[e+"s"];return n||(n=this.options[e+"s"]=c()),i?("partial"===e?i=a.toFragment(i):"component"===e&&(i=a.toConstructor(i)),n[t]=i,this):n[t]}}),o.config=function(e,t){if("string"==typeof e){if(void 0===t)return s[e];s[e]=t}else a.extend(s,e);return this},o.use=function(e){if("string"==typeof e)try{e=t(e)}catch(i){return a.warn("Cannot find plugin: "+e)}var n=[].slice.call(arguments,1);return n.unshift(this),"function"==typeof e.install?e.install.apply(e,n):e.apply(null,n),this},o.require=function(e){return t("./"+e)},o.extend=n,o.nextTick=a.nextTick,i.exports=o}),e.register("vue/src/emitter.js",function(e,t,i){function n(){this._ctx=this}var r=n.prototype,s=[].slice;r.on=function(e,t){return this._cbs=this._cbs||{},(this._cbs[e]=this._cbs[e]||[]).push(t),this},n.prototype.once=function(e,t){function i(){n.off(e,i),t.apply(this,arguments)}var n=this;return this._cbs=this._cbs||{},i.fn=t,this.on(e,i),this},n.prototype.off=function(e,t){if(this._cbs=this._cbs||{},!arguments.length)return this._cbs={},this;var i=this._cbs[e];if(!i)return this;if(1===arguments.length)return delete this._cbs[e],this;for(var n,r=0;r<i.length;r++)if(n=i[r],n===t||n.fn===t){i.splice(r,1);break}return this},n.prototype.emit=function(e){this._cbs=this._cbs||{};var t=s.call(arguments,1),i=this._cbs[e];if(i){i=i.slice(0);for(var n=0,r=i.length;r>n;n++)i[n].apply(this._ctx,t)}return this},i.exports=n}),e.register("vue/src/config.js",function(e,t,i){function n(){s.forEach(function(e){o.attrs[e]=r+"-"+e})}var r="v",s=["pre","ref","with","text","repeat","partial","component","animation","transition","effect"],o=i.exports={debug:!1,silent:!1,enterClass:"v-enter",leaveClass:"v-leave",interpolate:!0,attrs:{},get prefix(){return r},set prefix(e){r=e,n()}};n()}),e.register("vue/src/utils.js",function(e,t,i){var n,r=t("./config"),s=r.attrs,o={}.toString,a=window,c=a.console,u=a.setTimeout,l="classList"in document.documentElement,h=i.exports={hash:function(){return Object.create(null)},attr:function(e,t){var i=s[t],n=e.getAttribute(i);return null!==n&&e.removeAttribute(i),n},defProtected:function(e,t,i,n){e.hasOwnProperty(t)||Object.defineProperty(e,t,{value:i,enumerable:!!n,configurable:!0})},typeOf:function(e){return o.call(e).slice(8,-1)},bind:function(e,t){return function(i){return e.call(t,i)}},toText:function(e){var t=typeof e;return"string"===t||"boolean"===t||"number"===t&&e==e?e:"object"===t&&null!==e?JSON.stringify(e):""},extend:function(e,t,i){for(var n in t)i&&e[n]||(e[n]=t[n]);return e},unique:function(e){for(var t,i=h.hash(),n=e.length,r=[];n--;)t=e[n],i[t]||(i[t]=1,r.push(t));return r},toFragment:function(e){if("string"!=typeof e)return e;if("#"===e.charAt(0)){var t=document.getElementById(e.slice(1));if(!t)return;e=t.innerHTML}var i,n=document.createElement("div"),r=document.createDocumentFragment();for(n.innerHTML=e.trim();i=n.firstChild;)1===n.nodeType&&r.appendChild(i);return r},toConstructor:function(e){return n=n||t("./viewmodel"),"Object"===h.typeOf(e)?n.extend(e):"function"==typeof e?e:null},processOptions:function(e){var t,i=e.components,n=e.partials,r=e.template;if(i)for(t in i)i[t]=h.toConstructor(i[t]);if(n)for(t in n)n[t]=h.toFragment(n[t]);r&&(e.template=h.toFragment(r))},log:function(e){r.debug&&c&&c.log(e)},warn:function(e){!r.silent&&c&&(c.warn(e),r.debug&&c.trace&&c.trace(e))},nextTick:function(e){u(e,0)},addClass:function(e,t){if(l)e.classList.add(t);else{var i=" "+e.className+" ";i.indexOf(" "+t+" ")<0&&(e.className=(i+t).trim())}},removeClass:function(e,t){if(l)e.classList.remove(t);else{for(var i=" "+e.className+" ",n=" "+t+" ";i.indexOf(n)>=0;)i=i.replace(n," ");e.className=i.trim()}}}}),e.register("vue/src/compiler.js",function(e,t,i){function n(e,t){var i=this;i.init=!0,i.repeat=!1,i.destroyed=!1,i.delayReady=!1,t=i.options=t||g(),u.processOptions(t);var n=i.data=t.data||{};b(e,n,!0),b(e,t.methods,!0),b(i,t.compilerOptions);var s=i.el=i.setupElement(t);m("\nnew VM instance: "+s.tagName+"\n"),i.vm=s.vue_vm=e,i.bindings=g(),i.dirs=[],i.deferred=[],i.exps=[],i.computed=[],i.children=[],i.emitter=new o,i.emitter._ctx=e,i.delegators=g(),_(e,"$",g()),_(e,"$el",s),_(e,"$options",t),_(e,"$compiler",i);var a=t.parent,c=u.attr(s,"ref");a&&(i.parent=a.$compiler,a.$compiler.children.push(i),_(e,"$parent",a),c&&(i.childId=c,a.$[c]=e)),_(e,"$root",r(i).vm),i.setupObserver();var l=t.computed;if(l)for(var h in l)i.createBinding(h);t.paramAttributes&&t.paramAttributes.forEach(function(t){var i=s.getAttribute(t);e[t]=isNaN(i)||null===i?i:Number(i)}),i.execHook("created"),b(n,e),i.observeData(n),i.repeat&&(i.createBinding("$index"),n.$key&&i.createBinding("$key")),i.compile(s,!0),i.deferred.forEach(i.bindDirective,i),i.parseDeps(),i.rawContent=null,i.init=!1,i.delayReady||i.execHook("ready")}function r(e){for(;e.parent;)e=e.parent;return e}function s(e,t,i){Object.defineProperty(e,t,i)}var o=t("./emitter"),a=t("./observer"),c=t("./config"),u=t("./utils"),l=t("./binding"),h=t("./directive"),f=t("./text-parser"),d=t("./deps-parser"),p=t("./exp-parser"),v=[].slice,m=u.log,g=u.hash,b=u.extend,_=u.defProtected,y={}.hasOwnProperty,x=["created","ready","beforeDestroy","afterDestroy","attached","detached"],$=n.prototype;$.setupElement=function(e){var t="string"==typeof e.el?document.querySelector(e.el):e.el||document.createElement(e.tagName||"div"),i=e.template;if(i){for(var n,r=this.rawContent=document.createDocumentFragment();n=t.firstChild;)r.appendChild(n);if(e.replace&&1===i.childNodes.length){var s=i.childNodes[0].cloneNode(!0);t.parentNode&&(t.parentNode.insertBefore(s,t),t.parentNode.removeChild(t)),t=s}else t.appendChild(i.cloneNode(!0))}e.id&&(t.id=e.id),e.className&&(t.className=e.className);var o=e.attributes;if(o)for(var a in o)t.setAttribute(a,o[a]);return t},$.setupObserver=function(){function e(e){r(e),d.catcher.emit("get",a[e])}function t(e,t,i){u.emit("change:"+e,t,i),r(e),a[e].update(t)}function i(e,t){u.on("hook:"+e,function(){t.call(s.vm)})}function n(e){var t=s.children;if(t)for(var i,n=t.length;n--;)i=t[n],i.el.parentNode&&(e="hook:"+(e?"attached":"detached"),i.observer.emit(e),i.emitter.emit(e))}function r(e){a[e]||s.createBinding(e)}var s=this,a=s.bindings,c=s.options,u=s.observer=new o;u.proxies=g(),u._ctx=s.vm,u.on("get",e).on("set",t).on("mutate",t),x.forEach(function(e){var t=c[e];if(Array.isArray(t))for(var n=t.length;n--;)i(e,t[n]);else t&&i(e,t)}),u.on("hook:attached",function(){n(1)}).on("hook:detached",function(){n(0)})},$.observeData=function(e){function t(e){"$data"!==e&&r.update(i.data)}var i=this,n=i.observer;a.observe(e,"",n);var r=i.bindings.$data=new l(i,"$data");r.update(e),s(i.vm,"$data",{enumerable:!1,get:function(){return i.observer.emit("get","$data"),i.data},set:function(e){var t=i.data;a.unobserve(t,"",n),i.data=e,a.copyPaths(e,t),a.observe(e,"",n),i.observer.emit("set","$data",e)}}),n.on("set",t).on("mutate",t)},$.compile=function(e,t){var i=this,n=e.nodeType,r=e.tagName;if(1===n&&"SCRIPT"!==r){if(null!==u.attr(e,"pre"))return;var s,o,a,l,f=u.attr(e,"component")||r.toLowerCase(),d=i.getOption("components",f);if(s=u.attr(e,"repeat"))l=h.parse("repeat",s,i,e),l&&(l.Ctor=d,i.deferred.push(l));else if(t!==!0&&((o=u.attr(e,"with"))||d))o=h.split(o||""),o.forEach(function(t,n){var r=h.parse("with",t,i,e);r&&(r.Ctor=d,r.last=n===o.length-1,i.deferred.push(r))});else{if(e.vue_trans=u.attr(e,"transition"),e.vue_anim=u.attr(e,"animation"),e.vue_effect=u.attr(e,"effect"),a=u.attr(e,"partial")){var p=i.getOption("partials",a);p&&(e.innerHTML="",e.appendChild(p.cloneNode(!0)))}i.compileNode(e)}}else 3===n&&c.interpolate&&i.compileTextNode(e)},$.compileNode=function(e){var t,i,n=v.call(e.attributes),r=c.prefix+"-";if(n&&n.length){var s,o,a,u,l,d;for(t=n.length;t--;){if(s=n[t],o=!1,0===s.name.indexOf(r))for(o=!0,a=h.split(s.value),i=a.length;i--;)u=a[i],d=s.name.slice(r.length),l=h.parse(d,u,this,e),l&&this.bindDirective(l);else c.interpolate&&(u=f.parseAttr(s.value),u&&(l=h.parse("attr",s.name+":"+u,this,e),l&&this.bindDirective(l)));o&&"cloak"!==d&&e.removeAttribute(s.name)}}e.childNodes.length&&v.call(e.childNodes).forEach(this.compile,this)},$.compileTextNode=function(e){var t=f.parse(e.nodeValue);if(t){for(var i,n,r,s,o,a,l=0,d=t.length;d>l;l++){if(n=t[l],r=a=null,n.key)if(">"===n.key.charAt(0)){if(o=n.key.slice(1).trim(),"yield"===o)i=this.rawContent;else{if(s=this.getOption("partials",o),!s){u.warn("Unknown partial: "+o);continue}i=s.cloneNode(!0)}i&&(a=v.call(i.childNodes))}else n.html?(i=document.createComment(c.prefix+"-html"),r=h.parse("html",n.key,this,i)):(i=document.createTextNode(""),r=h.parse("text",n.key,this,i));else i=document.createTextNode(n);e.parentNode.insertBefore(i,e),r&&this.bindDirective(r),a&&a.forEach(this.compile,this)}e.parentNode.removeChild(e)}},$.bindDirective=function(e){if(this.dirs.push(e),e.isEmpty||e.isLiteral)return e.bind&&e.bind(),void 0;var t,i=this,n=e.key;if(e.isExp)t=i.createBinding(n,!0,e.isFn);else{for(;i&&!i.hasKey(n);)i=i.parent;i=i||this,t=i.bindings[n]||i.createBinding(n)}t.dirs.push(e),e.binding=t;var r=t.val();e.bind&&e.bind(r),e.update(r,!0)},$.createBinding=function(e,t,i){m(" created binding: "+e);var n=this,r=n.bindings,s=n.options.computed,o=new l(n,e,t,i);if(t)n.defineExp(e,o);else if(r[e]=o,o.root)s&&s[e]?n.defineComputed(e,o,s[e]):"$"!==e.charAt(0)?n.defineProp(e,o):n.defineMeta(e,o);else{a.ensurePath(n.data,e);var c=e.slice(0,e.lastIndexOf("."));r[c]||n.createBinding(c)}return o},$.defineProp=function(e,t){var i=this,n=i.data,r=n.__emitter__;e in n||(n[e]=void 0),!r||e in r.values||a.convertKey(n,e),t.value=n[e],s(i.vm,e,{get:function(){return i.data[e]},set:function(t){i.data[e]=t}})},$.defineMeta=function(e,t){var i=this.vm,n=this.observer,r=t.value=i[e]||this.data[e];delete this.data[e],s(i,e,{get:function(){return a.shouldGet&&n.emit("get",e),r},set:function(t){n.emit("set",e,t),r=t}})},$.defineExp=function(e,t){var i=p.parse(e,this);i&&(this.markComputed(t,i),this.exps.push(t))},$.defineComputed=function(e,t,i){this.markComputed(t,i),s(this.vm,e,{get:t.value.$get,set:t.value.$set})},$.markComputed=function(e,t){e.isComputed=!0,e.isFn?e.value=t:("function"==typeof t&&(t={$get:t}),e.value={$get:u.bind(t.$get,this.vm),$set:t.$set?u.bind(t.$set,this.vm):void 0}),this.computed.push(e)},$.getOption=function(e,t){var i=this.options,n=this.parent,r=c.globalAssets;return i[e]&&i[e][t]||(n?n.getOption(e,t):r[e]&&r[e][t])},$.execHook=function(e){e="hook:"+e,this.observer.emit(e),this.emitter.emit(e)},$.hasKey=function(e){var t=e.split(".")[0];return y.call(this.data,t)||y.call(this.vm,t)},$.parseDeps=function(){this.computed.length&&d.parse(this.computed)},$.addListener=function(e){var t=e.arg,i=this.delegators[t];i||(i=this.delegators[t]={targets:[],handler:function(e){for(var t,n=i.targets.length;n--;)t=i.targets[n],t.el.contains(e.target)&&t.handler&&t.handler(e)}},this.el.addEventListener(t,i.handler)),i.targets.push(e)},$.removeListener=function(e){var t=this.delegators[e.arg].targets;t.splice(t.indexOf(e),1)},$.destroy=function(){if(!this.destroyed){var e,t,i,n,r,s=this,o=s.vm,c=s.el,u=s.dirs,l=s.exps,h=s.bindings,f=s.delegators,d=s.children,p=s.parent;for(s.execHook("beforeDestroy"),a.unobserve(s.data,"",s.observer),e=u.length;e--;)i=u[e],i.binding&&i.binding.compiler!==s&&(n=i.binding.dirs,n&&n.splice(n.indexOf(i),1)),i.unbind();for(e=l.length;e--;)l[e].unbind();for(t in h)r=h[t],r&&r.unbind();for(t in f)c.removeEventListener(t,f[t].handler);for(e=d.length;e--;)d[e].destroy();p&&(p.children.splice(p.children.indexOf(s),1),s.childId&&delete p.vm.$[s.childId]),c===document.body?c.innerHTML="":o.$remove(),c.vue_vm=null,this.destroyed=!0,s.execHook("afterDestroy"),s.observer.off(),s.emitter.off()}},i.exports=n}),e.register("vue/src/viewmodel.js",function(e,t,i){function n(e){new s(this,e)}function r(e){return"string"==typeof e?document.querySelector(e):e}var s=t("./compiler"),o=t("./utils"),a=t("./transition"),c=t("./batcher"),u=[].slice,l=o.defProtected,h=o.nextTick,f=new c,d=1,p=n.prototype;l(p,"$set",function(e,t){for(var i=e.split("."),n=this,r=0,s=i.length-1;s>r;r++)n=n[i[r]];n[i[r]]=t}),l(p,"$watch",function(e,t){function i(){var e=u.call(arguments);f.push({id:n,override:!0,execute:function(){t.apply(r,e)}})}var n=d++,r=this;t._fn=i,r.$compiler.observer.on("change:"+e,i)}),l(p,"$unwatch",function(e,t){var i=["change:"+e],n=this.$compiler.observer;t&&i.push(t._fn),n.off.apply(n,i)}),l(p,"$destroy",function(){this.$compiler.destroy()}),l(p,"$broadcast",function(){for(var e,t=this.$compiler.children,i=t.length;i--;)e=t[i],e.emitter.emit.apply(e.emitter,arguments),e.vm.$broadcast.apply(e.vm,arguments)}),l(p,"$dispatch",function(){var e=this.$compiler,t=e.emitter,i=e.parent;t.emit.apply(t,arguments),i&&i.vm.$dispatch.apply(i.vm,arguments)}),["emit","on","off","once"].forEach(function(e){l(p,"$"+e,function(){var t=this.$compiler.emitter;t[e].apply(t,arguments)})}),l(p,"$appendTo",function(e,t){e=r(e);var i=this.$el;a(i,1,function(){e.appendChild(i),t&&h(t)},this.$compiler)}),l(p,"$remove",function(e){var t=this.$el,i=t.parentNode;i&&a(t,-1,function(){i.removeChild(t),e&&h(e)},this.$compiler)}),l(p,"$before",function(e,t){e=r(e);var i=this.$el,n=e.parentNode;n&&a(i,1,function(){n.insertBefore(i,e),t&&h(t)},this.$compiler)}),l(p,"$after",function(e,t){e=r(e);var i=this.$el,n=e.parentNode,s=e.nextSibling;n&&a(i,1,function(){s?n.insertBefore(i,s):n.appendChild(i),t&&h(t)},this.$compiler)}),i.exports=n}),e.register("vue/src/binding.js",function(e,t,i){function n(e,t,i,n){this.id=o++,this.value=void 0,this.isExp=!!i,this.isFn=n,this.root=!this.isExp&&-1===t.indexOf("."),this.compiler=e,this.key=t,this.dirs=[],this.subs=[],this.deps=[],this.unbound=!1}var r=t("./batcher"),s=new r,o=1,a=n.prototype;a.update=function(e){if((!this.isComputed||this.isFn)&&(this.value=e),this.dirs.length||this.subs.length){var t=this;s.push({id:this.id,execute:function(){return t.unbound?!1:(t._update(),void 0)}})}},a._update=function(){for(var e=this.dirs.length,t=this.val();e--;)this.dirs[e].update(t);this.pub()},a.val=function(){return this.isComputed&&!this.isFn?this.value.$get():this.value},a.pub=function(){for(var e=this.subs.length;e--;)this.subs[e].update()},a.unbind=function(){this.unbound=!0;for(var e=this.dirs.length;e--;)this.dirs[e].unbind();e=this.deps.length;for(var t;e--;)t=this.deps[e].subs,t.splice(t.indexOf(this),1)},i.exports=n}),e.register("vue/src/observer.js",function(e,t,i){function n(e){w(j,e,function(){var t,i,n=k.call(arguments),o=Array.prototype[e].apply(this,n);return"push"===e||"unshift"===e?t=n:"pop"===e||"shift"===e?i=[o]:"splice"===e&&(t=n.slice(2),i=o),r(this,t),s(this,i),this.__emitter__.emit("mutate",null,this,{method:e,args:n,result:o}),o},!O)}function r(e,t){if(t)for(var i,n,r=t.length;r--;)i=t[r],c(i)&&(u(i),l(i),n=i.__emitter__.owners,n.indexOf(e)<0&&n.push(e))}function s(e,t){if(t)for(var i,n=t.length;n--;)if(i=t[n],i&&i.__emitter__){var r=i.__emitter__.owners;r&&r.splice(r.indexOf(e))}}function o(e){if("function"==typeof e){for(var t=this.length,i=[];t--;)e(this[t])&&i.push(this.splice(t,1)[0]);return i.reverse()}return"number"!=typeof e&&(e=this.indexOf(e)),e>-1?this.splice(e,1)[0]:void 0}function a(e,t){if("function"==typeof e){for(var i,n=this.length,r=[];n--;)i=e(this[n]),void 0!==i&&r.push(this.splice(n,1,i)[0]);return r.reverse()}return"number"!=typeof e&&(e=this.indexOf(e)),e>-1?this.splice(e,1,t)[0]:void 0}function c(e){_=_||t("./viewmodel");var i=$(e);return!(i!==E&&i!==C||e instanceof _)}function u(e){if(e.__emitter__)return!0;var t=new y;return w(e,"__emitter__",t),t.on("set",function(){for(var t=e.__emitter__.owners,i=t.length;i--;)t[i].__emitter__.emit("set","","",!0)}),t.values=x.hash(),t.owners=[],!1}function l(e){var t=$(e);t===E?h(e):t===C&&f(e)}function h(e){for(var t in e)d(e,t)}function f(e){if(O)e.__proto__=j;else for(var t in j)w(e,t,j[t]);r(e,e)}function d(e,t){function i(e,i){s[t]=e,r.emit("set",t,e,i),Array.isArray(e)&&r.emit("set",t+".length",e.length),g(e,t,r)}var n=t.charAt(0);if("$"!==n&&"_"!==n){var r=e.__emitter__,s=r.values;i(e[t]),Object.defineProperty(e,t,{get:function(){var e=s[t];return N.shouldGet&&$(e)!==E&&r.emit("get",t),e},set:function(e){var n=s[t];b(n,t,r),v(e,n),i(e,!0)}})}}function p(e){var t=$(e),i=e&&e.__emitter__;if(t===C)i.emit("set","length",e.length);else if(t===E){var n,r;for(n in e)r=e[n],i.emit("set",n,r),p(r)}}function v(e,t){if($(t)===E&&$(e)===E){var i,n,r,s;for(i in t)i in e||(r=t[i],n=$(r),n===E?(s=e[i]={},v(s,r)):e[i]=n===C?[]:void 0)}}function m(e,t){for(var i,n=t.split("."),r=0,s=n.length-1;s>r;r++)i=n[r],e[i]||(e[i]={},e.__emitter__&&d(e,i)),e=e[i];$(e)===E&&(i=n[r],i in e||(e[i]=void 0,e.__emitter__&&d(e,i)))}function g(e,t,i){if(c(e)){var n=t?t+".":"",r=u(e),s=e.__emitter__;i.proxies=i.proxies||{};var o=i.proxies[n]={get:function(e){i.emit("get",n+e)},set:function(r,s,o){r&&i.emit("set",n+r,s),t&&o&&i.emit("set",t,e,!0)},mutate:function(e,r,s){var o=e?n+e:t;i.emit("mutate",o,r,s);var a=s.method;"sort"!==a&&"reverse"!==a&&i.emit("set",o+".length",r.length)}};s.on("get",o.get).on("set",o.set).on("mutate",o.mutate),r?p(e):l(e)}}function b(e,t,i){if(e&&e.__emitter__){t=t?t+".":"";var n=i.proxies[t];n&&(e.__emitter__.off("get",n.get).off("set",n.set).off("mutate",n.mutate),i.proxies[t]=null)}}var _,y=t("./emitter"),x=t("./utils"),$=x.typeOf,w=x.defProtected,k=[].slice,E="Object",C="Array",O={}.__proto__,j=Object.create(Array.prototype);["push","pop","shift","unshift","splice","sort","reverse"].forEach(n),w(j,"remove",o,!O),w(j,"set",a,!O),w(j,"replace",a,!O);var N=i.exports={shouldGet:!1,observe:g,unobserve:b,ensurePath:m,copyPaths:v,watch:l,convert:u,convertKey:d}}),e.register("vue/src/directive.js",function(e,t,i){function n(e,t,i,n,o){this.compiler=n,this.vm=n.vm,this.el=o;var a=""===t;if("function"==typeof e)this[a?"bind":"_update"]=e;else for(var c in e)"unbind"===c||"update"===c?this["_"+c]=e[c]:this[c]=e[c];if(a||this.isEmpty)return this.isEmpty=!0,void 0;this.expression=t.trim(),this.rawKey=i,r(this,i),this.isExp=!v.test(this.key)||p.test(this.key);var u=this.expression.slice(i.length).match(f);if(u){this.filters=[];for(var l,h=0,d=u.length;d>h;h++)l=s(u[h],this.compiler),l&&this.filters.push(l);this.filters.length||(this.filters=null)}else this.filters=null}function r(e,t){var i=t;if(t.indexOf(":")>-1){var n=t.match(h);i=n?n[2].trim():i,e.arg=n?n[1].trim():null}e.key=i}function s(e,t){var i=e.slice(1).match(d);if(i){i=i.map(function(e){return e.replace(/'/g,"").trim()});var n=i[0],r=t.getOption("filters",n)||c[n];return r?{name:n,apply:r,args:i.length>1?i.slice(1):null}:(o.warn("Unknown filter: "+n),void 0)}}var o=t("./utils"),a=t("./directives"),c=t("./filters"),u=/(?:['"](?:\\.|[^'"])*['"]|\((?:\\.|[^\)])*\)|\\.|[^,])+/g,l=/^(?:['"](?:\\.|[^'"])*['"]|\\.|[^\|]|\|\|)+/,h=/^([\w-$ ]+):(.+)$/,f=/\|[^\|]+/g,d=/[^\s']+|'[^']+'/g,p=/^\$(parent|root)\./,v=/^[\w\.$]+$/,m=n.prototype;m.update=function(e,t){var i=o.typeOf(e);(t||e!==this.value||"Object"===i||"Array"===i)&&(this.value=e,this._update&&this._update(this.filters?this.applyFilters(e):e,t))},m.applyFilters=function(e){for(var t,i=e,n=0,r=this.filters.length;r>n;n++)t=this.filters[n],i=t.apply.call(this.vm,i,t.args);return i},m.unbind=function(){this.el&&this.vm&&(this._unbind&&this._unbind(),this.vm=this.el=this.binding=this.compiler=null)},n.split=function(e){return e.indexOf(",")>-1?e.match(u)||[""]:[e]},n.parse=function(e,t,i,r){var s=i.getOption("directives",e)||a[e];if(!s)return o.warn("unknown directive: "+e);var c;if(t.indexOf("|")>-1){var u=t.match(l);u&&(c=u[0].trim())}else c=t.trim();return c||""===t?new n(s,t,c,i,r):o.warn("invalid directive expression: "+t)},i.exports=n}),e.register("vue/src/exp-parser.js",function(e,t,i){function n(e){return e=e.replace(p,"").replace(v,",").replace(d,"").replace(m,"").replace(g,""),e?e.split(/,+/):[]}function r(e,t){for(var i="",n=0,r=t;t&&!t.hasKey(e);)t=t.parent,n++;if(t){for(;n--;)i+="$parent.";t.bindings[e]||"$"===e.charAt(0)||t.createBinding(e)}else r.createBinding(e);return i}function s(e,t){var i;try{i=new Function(e)}catch(n){a.warn("Invalid expression: "+t)}return i}function o(e){return"$"===e.charAt(0)?"\\"+e:e}var a=t("./utils"),c=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g,u=/"(\d+)"/g,l=new RegExp("constructor".split("").join("['\"+, ]*")),h=/\\u\d\d\d\d/,f="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,undefined,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,Math",d=new RegExp(["\\b"+f.replace(/,/g,"\\b|\\b")+"\\b"].join("|"),"g"),p=/\/\*(?:.|\n)*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|'[^']*'|"[^"]*"|[\s\t\n]*\.[\s\t\n]*[$\w\.]+/g,v=/[^\w$]+/g,m=/\b\d[^,]*/g,g=/^,+|,+$/g;i.exports={parse:function(e,t){function i(e){var t=g.length;return g[t]=e,'"'+t+'"'}function f(e){var i=e.charAt(0);e=e.slice(1);var n="this."+r(e,t)+e;return m[e]||(v+=n+";",m[e]=1),i+n}function d(e,t){return g[t]}if(h.test(e)||l.test(e))return a.warn("Unsafe expression: "+e),function(){};var p=n(e);if(!p.length)return s("return "+e,e);p=a.unique(p);var v="",m=a.hash(),g=[],b=new RegExp("[^$\\w\\.]("+p.map(o).join("|")+")[$\\w\\.]*\\b","g"),_=("return "+e).replace(c,i).replace(b,f).replace(u,d);return _=v+_,s(_,e)}}}),e.register("vue/src/text-parser.js",function(e){function t(e){if(!n.test(e))return null;for(var t,i,s,o=[];t=e.match(n);)i=t.index,i>0&&o.push(e.slice(0,i)),s={key:t[1].trim()},r.test(t[0])&&(s.html=!0),o.push(s),e=e.slice(i+t[0].length);return e.length&&o.push(e),o}function i(e){var i=t(e);if(!i)return null;for(var n,r=[],s=0,o=i.length;o>s;s++)n=i[s],r.push(n.key||'"'+n+'"');return r.join("+")}var n=/{{{?([^{}]+?)}?}}/,r=/{{{[^{}]+}}}/;e.parse=t,e.parseAttr=i}),e.register("vue/src/deps-parser.js",function(e,t,i){function n(e){if(!e.isFn){s.log("\n- "+e.key);var t=s.hash();e.deps=[],a.on("get",function(i){var n=t[i.key];n&&n.compiler===i.compiler||(t[i.key]=i,s.log(" - "+i.key),e.deps.push(i),i.subs.push(e))}),e.value.$get(),a.off("get")}}var r=t("./emitter"),s=t("./utils"),o=t("./observer"),a=new r;i.exports={catcher:a,parse:function(e){s.log("\nparsing dependencies..."),o.shouldGet=!0,e.forEach(n),o.shouldGet=!1,s.log("\ndone.")}}}),e.register("vue/src/filters.js",function(e,t,i){var n={enter:13,tab:9,"delete":46,up:38,left:37,right:39,down:40,esc:27};i.exports={capitalize:function(e){return e||0===e?(e=e.toString(),e.charAt(0).toUpperCase()+e.slice(1)):""},uppercase:function(e){return e||0===e?e.toString().toUpperCase():""},lowercase:function(e){return e||0===e?e.toString().toLowerCase():""},currency:function(e,t){if(!e&&0!==e)return"";var i=t&&t[0]||"$",n=Math.floor(e).toString(),r=n.length%3,s=r>0?n.slice(0,r)+(n.length>3?",":""):"",o="."+e.toFixed(2).slice(-2);return i+s+n.slice(r).replace(/(\d{3})(?=\d)/g,"$1,")+o},pluralize:function(e,t){return t.length>1?t[e-1]||t[t.length-1]:t[e-1]||t[0]+"s"},key:function(e,t){if(e){var i=n[t[0]];return i||(i=parseInt(t[0],10)),function(t){t.keyCode===i&&e.call(this,t)}}}}}),e.register("vue/src/transition.js",function(e,t,i){function n(e,t,i,n){if(!o.trans)return i(),f.CSS_SKIP;var r,s=e.classList,c=e.vue_trans_cb,l=a.enterClass,h=a.leaveClass,d=n?o.anim:o.trans;return c&&(e.removeEventListener(d,c),s.remove(l),s.remove(h),e.vue_trans_cb=null),t>0?(s.add(l),i(),n?(r=function(t){t.target===e&&(e.removeEventListener(d,r),e.vue_trans_cb=null,s.remove(l))},e.addEventListener(d,r),e.vue_trans_cb=r):u.push({execute:function(){s.remove(l)}}),f.CSS_E):(e.offsetWidth||e.offsetHeight?(s.add(h),r=function(t){t.target===e&&(e.removeEventListener(d,r),e.vue_trans_cb=null,i(),s.remove(h))},e.addEventListener(d,r),e.vue_trans_cb=r):i(),f.CSS_L)}function r(e,t,i,n,r){function s(t,i){var n=l(function(){t(),u.splice(u.indexOf(n),1),u.length||(e.vue_timeouts=null)},i);u.push(n)}var o=r.getOption("effects",n);if(!o)return i(),f.JS_SKIP;var a=o.enter,c=o.leave,u=e.vue_timeouts;if(u)for(var d=u.length;d--;)h(u[d]);return u=e.vue_timeouts=[],t>0?"function"!=typeof a?(i(),f.JS_SKIP_E):(a(e,i,s),f.JS_E):"function"!=typeof c?(i(),f.JS_SKIP_L):(c(e,i,s),f.JS_L)}function s(){var e=document.createElement("vue"),t="transitionend",i={transition:t,mozTransition:t,webkitTransition:"webkitTransitionEnd"},n={};for(var r in i)if(void 0!==e.style[r]){n.trans=i[r];break}return n.anim=""===e.style.animation?"animationend":"webkitAnimationEnd",n}var o=s(),a=t("./config"),c=t("./batcher"),u=new c,l=window.setTimeout,h=window.clearTimeout,f={CSS_E:1,CSS_L:2,JS_E:3,JS_L:4,CSS_SKIP:-1,JS_SKIP:-2,JS_SKIP_E:-3,JS_SKIP_L:-4,INIT:-5,SKIP:-6};u._preFlush=function(){document.body.offsetHeight};var d=i.exports=function(e,t,i,s){var o=function(){i(),s.execHook(t>0?"attached":"detached")};if(s.init)return o(),f.INIT;var a=""===e.vue_trans,c=""===e.vue_anim,u=e.vue_effect;return u?r(e,t,o,u,s):a||c?n(e,t,o,c):(o(),f.SKIP)};d.codes=f}),e.register("vue/src/batcher.js",function(e,t,i){function n(){this.reset()}var r=t("./utils"),s=n.prototype;s.push=function(e){if(e.id&&this.has[e.id]){if(e.override){var t=this.has[e.id];t.cancelled=!0,this.queue.push(e),this.has[e.id]=e}}else this.queue.push(e),this.has[e.id]=e,this.waiting||(this.waiting=!0,r.nextTick(r.bind(this.flush,this)))},s.flush=function(){this._preFlush&&this._preFlush();for(var e=0;e<this.queue.length;e++){var t=this.queue[e];t.cancelled||t.execute()!==!1&&(this.has[t.id]=!1)}this.reset()},s.reset=function(){this.has=r.hash(),this.queue=[],this.waiting=!1},i.exports=n}),e.register("vue/src/directives/index.js",function(e,t,i){var n=t("../utils"),r=t("../config"),s=t("../transition");i.exports={on:t("./on"),repeat:t("./repeat"),model:t("./model"),"if":t("./if"),"with":t("./with"),html:t("./html"),style:t("./style"),attr:function(e){e||0===e?this.el.setAttribute(this.arg,e):this.el.removeAttribute(this.arg)},text:function(e){this.el.textContent=n.toText(e)},show:function(e){var t=this.el,i=e?"":"none",n=function(){t.style.display=i};s(t,e?1:-1,n,this.compiler)},"class":function(e){this.arg?n[e?"addClass":"removeClass"](this.el,this.arg):(this.lastVal&&n.removeClass(this.el,this.lastVal),e&&(n.addClass(this.el,e),this.lastVal=e))},cloak:{isEmpty:!0,bind:function(){var e=this.el;this.compiler.observer.once("hook:ready",function(){e.removeAttribute(r.prefix+"-cloak")})}}}}),e.register("vue/src/directives/if.js",function(e,t,i){var n=t("../config"),r=t("../transition");i.exports={bind:function(){this.parent=this.el.parentNode||this.el.vue_if_parent,this.ref=document.createComment(n.prefix+"-if-"+this.key);var e=this.el.vue_if_ref;e&&this.parent.insertBefore(this.ref,e),this.el.vue_if_ref=this.ref},update:function(e){function t(){if(n.parentNode){var e=n.nextSibling;e?s.insertBefore(o,e):s.appendChild(o),s.removeChild(n)}}function i(){n.parentNode||(s.insertBefore(n,o),s.removeChild(o))}var n=this.el;n.vue_if=!!e;var s=this.parent,o=this.ref,a=this.compiler;if(!s){if(!n.parentNode)return;s=this.parent=n.parentNode}e?r(n,1,i,a):r(n,-1,t,a)},unbind:function(){this.el.vue_if_ref=this.el.vue_if_parent=null;var e=this.ref;e.parentNode&&e.parentNode.removeChild(e)}}}),e.register("vue/src/directives/repeat.js",function(e,t,i){function n(e){var t,i,n=[];for(var r in e)t=e[r],i="Object"===c.typeOf(t)?t:{$value:t},l(i,"$key",r),n.push(i);return n}function r(e,t){for(var i=0,n=e.length;n>i;i++)if(e[i]===t||t.$value&&e[i].$value===t.$value)return i;return-1}function s(e){for(var t,i=e.length;i--;)t=e[i],t.$reused?t.$reused=!1:t.$destroy()}var o,a=t("../observer"),c=t("../utils"),u=t("../config"),l=c.defProtected,h={push:function(e){this.addItems(e.args,this.vms.length)},pop:function(){var e=this.vms.pop();e&&this.removeItems([e])},unshift:function(e){this.addItems(e.args)},shift:function(){var e=this.vms.shift();e&&this.removeItems([e])},splice:function(e){var t=e.args[0],i=e.args[1],n=void 0===i?this.vms.splice(t):this.vms.splice(t,i);this.removeItems(n),this.addItems(e.args.slice(2),t)},sort:function(){var e,t,i,n,r=this.vms,s=this.collection,o=s.length,a=new Array(o);for(e=0;o>e;e++)for(n=s[e],t=0;o>t;t++)if(i=r[t],i.$data===n){a[e]=i;break}for(e=0;o>e;e++)this.container.insertBefore(a[e].$el,this.ref);this.vms=a},reverse:function(){var e=this.vms;e.reverse();for(var t=0,i=e.length;i>t;t++)this.container.insertBefore(e[t].$el,this.ref)}};i.exports={bind:function(){var e=this.el,i=this.container=e.parentNode;o=o||t("../viewmodel"),this.Ctor=this.Ctor||o,this.childId=c.attr(e,"ref"),this.ref=document.createComment(u.prefix+"-repeat-"+this.key),i.insertBefore(this.ref,e),i.removeChild(e),this.initiated=!1,this.collection=null,this.vms=null;var n=this;this.mutationListener=function(e,t,i){var r=i.method;if(h[r].call(n,i),"push"!==r&&"pop"!==r)for(var s=t.length;s--;)n.vms[s].$index=s;("push"===r||"unshift"===r||"splice"===r)&&n.changed()}},update:function(e,t){if(e!==this.collection&&e!==this.object){"Object"===c.typeOf(e)&&(e=this.convertObject(e)),this.reset(),this.initiated||e&&e.length||this.dryBuild(),this.old=this.collection;var i=this.oldVMs=this.vms;e=this.collection=e||[],this.vms=[],this.childId&&(this.vm.$[this.childId]=this.vms),a.convert(e)||a.watch(e),e.__emitter__.on("mutate",this.mutationListener),e.length&&(e.forEach(this.build,this),t||this.changed()),i&&s(i),this.old=this.oldVMs=null}},addItems:function(e,t){t=t||0; | ||
for(var i=0,n=e.length;n>i;i++){var r=this.build(e[i],t+i);this.updateObject(r,1)}},removeItems:function(e){for(var t=e.length;t--;)e[t].$destroy(),this.updateObject(e[t],-1)},changed:function(){if(!this.queued){this.queued=!0;var e=this;c.nextTick(function(){e.compiler&&(e.compiler.parseDeps(),e.queued=!1)})}},dryBuild:function(){new this.Ctor({el:this.el.cloneNode(!0),parent:this.vm,compilerOptions:{repeat:!0}}).$destroy(),this.initiated=!0},build:function(e,t){var i,n,s,o,a,u=this.container,l=this.vms,h=this.collection,f=l.length>t?l[t].$el:this.ref;return f.parentNode||(f=f.vue_if_ref),n=this.old?r(this.old,e):-1,s=n>-1,s?(o=this.oldVMs[n],o.$reused=!0):(i=this.el.cloneNode(!0),i.vue_if_parent=u,i.vue_if_ref=f,a="Object"!==c.typeOf(e),a&&(e={$value:e}),e.$index=t,o=new this.Ctor({el:i,data:e,parent:this.vm,compilerOptions:{repeat:!0}}),a&&o.$compiler.observer.on("set",function(e,t){"$value"===e&&(h[o.$index]=t)})),l.splice(t,0,o),o.$index=t,i=o.$el,s?u.insertBefore(i.parentNode?i:i.vue_if_ref,f):i.vue_if!==!1&&(this.compiler.init?(u.insertBefore(i,f),o.$compiler.execHook("attached")):o.$before(f)),o},convertObject:function(e){this.object&&this.object.__emitter__.off("set",this.updateRepeater),this.object=e;var t=e.$repeater||n(e);e.$repeater||l(e,"$repeater",t);var i=this;return this.updateRepeater=function(e,t){if(-1===e.indexOf("."))for(var n,r=i.vms.length;r--;)if(n=i.vms[r],n.$key===e){n.$data!==t&&n.$value!==t&&("$value"in n?n.$value=t:n.$data=t);break}},e.__emitter__.on("set",this.updateRepeater),t},updateObject:function(e,t){var i=this.object;if(i&&e.$key){var n=e.$key,r=e.$value||e.$data;t>0?(i[n]=r,a.convertKey(i,n)):delete i[n],i.__emitter__.emit("set",n,r,!0)}},reset:function(e){this.childId&&delete this.vm.$[this.childId],this.collection&&(this.collection.__emitter__.off("mutate",this.mutationListener),e&&s(this.vms))},unbind:function(){this.reset(!0)}}}),e.register("vue/src/directives/on.js",function(e,t,i){var n=t("../utils").warn;i.exports={isFn:!0,bind:function(){this.bubbles="blur"!==this.arg&&"focus"!==this.arg,this.bubbles&&this.binding.compiler.addListener(this)},update:function(e){if("function"!=typeof e)return n('Directive "on" expects a function value.');var t=this.vm,i=this.binding.compiler.vm,r=this.binding.isExp,s=function(n){n.targetVM=t,e.call(r?t:i,n)};this.bubbles||(this.reset(),this.el.addEventListener(this.arg,s)),this.handler=s},reset:function(){this.el.removeEventListener(this.arg,this.handler)},unbind:function(){this.bubbles?this.binding.compiler.removeListener(this):this.reset()}}}),e.register("vue/src/directives/model.js",function(e,t,i){function n(e){return o.call(e.options,function(e){return e.selected}).map(function(e){return e.value||e.text})}var r=t("../utils"),s=navigator.userAgent.indexOf("MSIE 9.0")>0,o=[].filter;i.exports={bind:function(){var e=this,t=e.el,i=t.type,n=t.tagName;e.lock=!1,e.ownerVM=e.binding.compiler.vm,e.event=e.compiler.options.lazy||"SELECT"===n||"checkbox"===i||"radio"===i?"change":"input",e.attr="checkbox"===i?"checked":"INPUT"===n||"SELECT"===n||"TEXTAREA"===n?"value":"innerHTML","SELECT"===n&&t.hasAttribute("multiple")&&(this.multi=!0);var o=!1;e.cLock=function(){o=!0},e.cUnlock=function(){o=!1},t.addEventListener("compositionstart",this.cLock),t.addEventListener("compositionend",this.cUnlock),e.set=e.filters?function(){if(!o){var i;try{i=t.selectionStart}catch(n){}e._set(),r.nextTick(function(){void 0!==i&&t.setSelectionRange(i,i)})}}:function(){o||(e.lock=!0,e._set(),r.nextTick(function(){e.lock=!1}))},t.addEventListener(e.event,e.set),s&&(e.onCut=function(){r.nextTick(function(){e.set()})},e.onDel=function(t){(46===t.keyCode||8===t.keyCode)&&e.set()},t.addEventListener("cut",e.onCut),t.addEventListener("keyup",e.onDel))},_set:function(){this.ownerVM.$set(this.key,this.multi?n(this.el):this.el[this.attr])},update:function(e,t){if(t&&void 0===e)return this._set();if(!this.lock){var i=this.el;"SELECT"===i.tagName?(i.selectedIndex=-1,this.multi&&Array.isArray(e)?e.forEach(this.updateSelect,this):this.updateSelect(e)):"radio"===i.type?i.checked=e==i.value:"checkbox"===i.type?i.checked=!!e:i[this.attr]=r.toText(e)}},updateSelect:function(e){for(var t=this.el.options,i=t.length;i--;)if(t[i].value==e){t[i].selected=!0;break}},unbind:function(){var e=this.el;e.removeEventListener(this.event,this.set),e.removeEventListener("compositionstart",this.cLock),e.removeEventListener("compositionend",this.cUnlock),s&&(e.removeEventListener("cut",this.onCut),e.removeEventListener("keyup",this.onDel))}}}),e.register("vue/src/directives/with.js",function(e,t,i){var n,r=t("../utils").nextTick;i.exports={bind:function(){if(this.el.vue_vm){this.subVM=this.el.vue_vm;var e=this.subVM.$compiler;e.bindings[this.arg]||e.createBinding(this.arg)}else this.isEmpty&&this.build()},update:function(e,t){var i=this.subVM,n=this.arg||"$data";i?this.lock||i[n]===e||(i[n]=e):this.build(e),t&&(this.watch(),this.last&&this.subVM.$compiler.execHook("ready"))},build:function(e){n=n||t("../viewmodel");var i=this.Ctor||n,r=e;this.arg&&(r={},r[this.arg]=e),this.subVM=new i({el:this.el,data:r,parent:this.vm,compilerOptions:{delayReady:!this.last}})},watch:function(){if(this.arg){var e=this,t=e.key,i=e.binding.compiler.vm;this.subVM.$compiler.observer.on("change:"+this.arg,function(n){e.lock||(e.lock=!0,r(function(){e.lock=!1})),i.$set(t,n)})}},unbind:function(){this.subVM.$destroy()}}}),e.register("vue/src/directives/html.js",function(e,t,i){var n=t("../utils").toText,r=[].slice;i.exports={bind:function(){8===this.el.nodeType&&(this.holder=document.createElement("div"),this.nodes=[])},update:function(e){e=n(e),this.holder?this.swap(e):this.el.innerHTML=e},swap:function(e){for(var t,i=this.el.parentNode,n=this.holder,s=this.nodes,o=s.length;o--;)i.removeChild(s[o]);for(n.innerHTML=e,s=this.nodes=r.call(n.childNodes),o=0,t=s.length;t>o;o++)i.insertBefore(s[o],this.el)}}}),e.register("vue/src/directives/style.js",function(e,t,i){function n(e){return e[1].toUpperCase()}var r=/-([a-z])/g,s=["webkit","moz","ms"];i.exports={bind:function(){var e=this.arg;if(e){var t=e.charAt(0);"$"===t?(e=e.slice(1),this.prefixed=!0):"-"===t&&(e=e.slice(1)),this.prop=e.replace(r,n)}},update:function(e){var t=this.prop;if(t){if(this.el.style[t]=e,this.prefixed){t=t.charAt(0).toUpperCase()+t.slice(1);for(var i=s.length;i--;)this.el.style[s[i]+t]=e}}else this.el.style.cssText=e}}}),e.alias("vue/src/main.js","vue/index.js"),"object"==typeof exports?module.exports=e("vue"):"function"==typeof define&&define.amd?define(function(){return e("vue")}):window.Vue=e("vue")}(); | ||
!function(){"use strict";function e(t,i,n){var r=e.resolve(t);if(null!=r){var s=e.modules[r];if(!s._resolving&&!s.exports){var o={};o.exports={},o.client=o.component=!0,s._resolving=!0,s.call(this,o.exports,e.relative(r),o),delete s._resolving,s.exports=o.exports}return s.exports}}e.modules={},e.aliases={},e.exts=["",".js",".json","/index.js","/index.json"],e.resolve=function(t){"/"===t.charAt(0)&&(t=t.slice(1));for(var i=0;5>i;i++){var n=t+e.exts[i];if(e.modules.hasOwnProperty(n))return n;if(e.aliases.hasOwnProperty(n))return e.aliases[n]}},e.normalize=function(e,t){var i=[];if("."!=t.charAt(0))return t;e=e.split("/"),t=t.split("/");for(var n=0;n<t.length;++n)".."===t[n]?e.pop():"."!=t[n]&&""!=t[n]&&i.push(t[n]);return e.concat(i).join("/")},e.register=function(t,i){e.modules[t]=i},e.alias=function(t,i){e.modules.hasOwnProperty(t)&&(e.aliases[i]=t)},e.relative=function(t){function i(n){var r=i.resolve(n);return e(r,t,n)}var n=e.normalize(t,"..");return i.resolve=function(i){var r=i.charAt(0);if("/"===r)return i.slice(1);if("."===r)return e.normalize(n,i);for(var s=t.split("/"),o=s.length;o--&&"deps"!==s[o];);return i=s.slice(0,o+2).join("/")+"/deps/"+i},i.exists=function(t){return e.modules.hasOwnProperty(i.resolve(t))},i},e.register("vue/src/main.js",function(e,t,i){function n(e){var t=this;e.data&&(e.defaultData=e.data,delete e.data),e=r(e,t.options,!0),a.processOptions(e);var i=function(i,n){n||(i=r(i,e,!0)),t.call(this,i,!0)},s=i.prototype=Object.create(t.prototype);return a.defProtected(s,"constructor",i),i.extend=n,i.super=t,i.options=e,l.forEach(function(e){i[e]=o[e]}),i.use=o.use,i.require=o.require,i}function r(e,t,i){if(e=e||{},!t)return e;for(var n in t)if("el"!==n){var s=e[n],c=t[n];i&&"function"==typeof s&&c?(e[n]=[s],Array.isArray(c)?e[n]=e[n].concat(c):e[n].push(c)):!i||!a.isTrueObject(s)&&!a.isTrueObject(c)||c instanceof o?void 0===s&&(e[n]=c):e[n]=r(s,c)}return e}var s=t("./config"),o=t("./viewmodel"),a=t("./utils"),c=a.hash,l=["directive","filter","partial","effect","component"];t("./observer"),t("./transition"),o.options=s.globalAssets={directives:t("./directives"),filters:t("./filters"),partials:c(),effects:c(),components:c()},l.forEach(function(e){o[e]=function(t,i){var n=this.options[e+"s"];return n||(n=this.options[e+"s"]=c()),i?("partial"===e?i=a.toFragment(i):"component"===e?i=a.toConstructor(i):"filter"===e&&a.checkFilter(i),n[t]=i,this):n[t]}}),o.config=function(e,t){if("string"==typeof e){if(void 0===t)return s[e];s[e]=t}else a.extend(s,e);return this},o.use=function(e){if("string"==typeof e)try{e=t(e)}catch(i){return}var n=[].slice.call(arguments,1);return n.unshift(this),"function"==typeof e.install?e.install.apply(e,n):e.apply(null,n),this},o.require=function(e){return t("./"+e)},o.extend=n,o.nextTick=a.nextTick,i.exports=o}),e.register("vue/src/emitter.js",function(e,t,i){function n(e){this._ctx=e||this}var r=n.prototype;r.on=function(e,t){return this._cbs=this._cbs||{},(this._cbs[e]=this._cbs[e]||[]).push(t),this},n.prototype.once=function(e,t){function i(){n.off(e,i),t.apply(this,arguments)}var n=this;return this._cbs=this._cbs||{},i.fn=t,this.on(e,i),this},n.prototype.off=function(e,t){if(this._cbs=this._cbs||{},!arguments.length)return this._cbs={},this;var i=this._cbs[e];if(!i)return this;if(1===arguments.length)return delete this._cbs[e],this;for(var n,r=0;r<i.length;r++)if(n=i[r],n===t||n.fn===t){i.splice(r,1);break}return this},n.prototype.emit=function(e,t,i,n){this._cbs=this._cbs||{};var r=this._cbs[e];if(r){r=r.slice(0);for(var s=0,o=r.length;o>s;s++)r[s].call(this._ctx,t,i,n)}return this},i.exports=n}),e.register("vue/src/config.js",function(e,t,i){var n=t("./text-parser");i.exports={prefix:"v",debug:!1,silent:!1,enterClass:"v-enter",leaveClass:"v-leave",interpolate:!0},Object.defineProperty(i.exports,"delimiters",{get:function(){return n.delimiters},set:function(e){n.setDelimiters(e)}})}),e.register("vue/src/utils.js",function(e,t,i){var n,r=t("./config"),s={}.toString,o=window,a=(o.console,o.setTimeout),c=Object.defineProperty,l=/[^\w]this[^\w]/,u="object",h="classList"in document.documentElement,f=i.exports={get:function(e,t){if(t.indexOf(".")<0)return e[t];for(var i=t.split("."),n=-1,r=i.length;++n<r&&null!=e;)e=e[i[n]];return e},set:function(e,t,i){if(t.indexOf(".")<0)return e[t]=i,void 0;for(var n=t.split("."),r=-1,s=n.length-1;++r<s;)null==e[n[r]]&&(e[n[r]]={}),e=e[n[r]];e[n[r]]=i},baseKey:function(e){return e.indexOf(".")>0?e.split(".")[0]:e},hash:function(){return Object.create(null)},attr:function(e,t){var i=r.prefix+"-"+t,n=e.getAttribute(i);return null!==n&&e.removeAttribute(i),n},defProtected:function(e,t,i,n,r){c(e,t,{value:i,enumerable:n,writable:r,configurable:!0})},isObject:function(e){return typeof e===u&&e&&!Array.isArray(e)},isTrueObject:function(e){return"[object Object]"===s.call(e)},bind:function(e,t){return function(i){return e.call(t,i)}},guard:function(e){return null==e?"":"object"==typeof e?JSON.stringify(e):e},checkNumber:function(e){return isNaN(e)||null===e||"boolean"==typeof e?e:Number(e)},extend:function(e,t){for(var i in t)e[i]!==t[i]&&(e[i]=t[i]);return e},unique:function(e){for(var t,i=f.hash(),n=e.length,r=[];n--;)t=e[n],i[t]||(i[t]=1,r.push(t));return r},toFragment:function(e){if("string"!=typeof e)return e;if("#"===e.charAt(0)){var t=document.getElementById(e.slice(1));if(!t)return;if("TEMPLATE"===t.tagName&&t.content)return t.content;e=t.innerHTML}var i,n=document.createElement("div"),r=document.createDocumentFragment();for(n.innerHTML=e.trim();i=n.firstChild;)1===n.nodeType&&r.appendChild(i);return r},toConstructor:function(e){return n=n||t("./viewmodel"),f.isObject(e)?n.extend(e):"function"==typeof e?e:null},checkFilter:function(e){l.test(e.toString())&&(e.computed=!0)},processOptions:function(e){var t,i=e.components,n=e.partials,r=e.template,s=e.filters;if(i)for(t in i)i[t]=f.toConstructor(i[t]);if(n)for(t in n)n[t]=f.toFragment(n[t]);if(s)for(t in s)f.checkFilter(s[t]);r&&(e.template=f.toFragment(r))},nextTick:function(e){a(e,0)},addClass:function(e,t){if(h)e.classList.add(t);else{var i=" "+e.className+" ";i.indexOf(" "+t+" ")<0&&(e.className=(i+t).trim())}},removeClass:function(e,t){if(h)e.classList.remove(t);else{for(var i=" "+e.className+" ",n=" "+t+" ";i.indexOf(n)>=0;)i=i.replace(n," ");e.className=i.trim()}},objectToArray:function(e){var t,i,n=[];for(var r in e)t=e[r],i=f.isObject(t)?t:{$value:t},i.$key=r,n.push(i);return n}}}),e.register("vue/src/compiler.js",function(e,t,i){function n(e,t){var i,n,s=this;s.init=!0,s.destroyed=!1,t=s.options=t||{},l.processOptions(t),m(s,t.compilerOptions),s.repeat=s.repeat||!1,s.expCache=s.expCache||{};var a=s.el=s.setupElement(t);if(s.vm=a.vue_vm=e,s.bindings=l.hash(),s.dirs=[],s.deferred=[],s.computed=[],s.children=[],s.emitter=new o(e),t.methods)for(i in t.methods)s.createBinding(i);if(t.computed)for(i in t.computed)s.createBinding(i);e.$={},e.$el=a,e.$options=t,e.$compiler=s,e.$event=null;var c=t.parent;c&&(s.parent=c.$compiler,c.$compiler.children.push(s),e.$parent=c),e.$root=r(s).vm,s.setupObserver();var u=s.data=t.data||{},h=t.defaultData;if(h)for(i in h)g.call(u,i)||(u[i]=h[i]);var f=t.paramAttributes;if(f)for(n=f.length;n--;)u[f[n]]=l.checkNumber(s.eval(a.getAttribute(f[n])));m(e,u),e.$data=u,s.execHook("created"),u=s.data=e.$data;var p;for(i in e)p=e[i],"$"!==i.charAt(0)&&u[i]!==p&&"function"!=typeof p&&(u[i]=p);for(s.observeData(u),t.template&&this.resolveContent(),s.compile(a,!0),n=s.deferred.length;n--;)s.bindDirective(s.deferred[n]);s.deferred=null,this.computed.length&&d.parse(this.computed),s.init=!1,s.execHook("ready")}function r(e){for(;e.parent;)e=e.parent;return e}var s,o=t("./emitter"),a=t("./observer"),c=t("./config"),l=t("./utils"),u=t("./binding"),h=t("./directive"),f=t("./text-parser"),d=t("./deps-parser"),p=t("./exp-parser"),v=[].slice,m=l.extend,g={}.hasOwnProperty,b=Object.defineProperty,y=["created","ready","beforeDestroy","afterDestroy","attached","detached"],_=["if","repeat","view","component"],x=n.prototype;x.setupElement=function(e){var t,i,n,r,s,o="string"==typeof e.el?document.querySelector(e.el):e.el||document.createElement(e.tagName||"div"),a=e.template;if(a){if(o.hasChildNodes())for(this.rawContent=document.createElement("div");t=o.firstChild;)this.rawContent.appendChild(t);if(e.replace&&1===a.childNodes.length){if(i=a.childNodes[0].cloneNode(!0),o.parentNode&&(o.parentNode.insertBefore(i,o),o.parentNode.removeChild(o)),o.hasAttributes())for(n=o.attributes.length;n--;)r=o.attributes[n],i.setAttribute(r.name,r.value);o=i}else o.appendChild(a.cloneNode(!0))}if(e.id&&(o.id=e.id),e.className&&(o.className=e.className),s=e.attributes)for(r in s)o.setAttribute(r,s[r]);return o},x.resolveContent=function(){function e(e,t){for(var i=e.parentNode,n=0,r=t.length;r>n;n++)i.insertBefore(t[n],e);i.removeChild(e)}var t,i,n,r,s,o=v.call(this.el.getElementsByTagName("content")),a=this.rawContent;if(n=o.length){for(;n--;)t=o[n],a?(i=t.getAttribute("select"),i?t.content=v.call(a.querySelectorAll(i)):s=t):t.content=v.call(t.childNodes);for(n=0,r=o.length;r>n;n++)t=o[n],t!==s&&e(t,t.content);a&&s&&e(s,v.call(a.childNodes))}this.rawContent=null},x.setupObserver=function(){function e(e){r(e),d.catcher.emit("get",a[e])}function t(e,t,i){l.emit("change:"+e,t,i),r(e),a[e].update(t)}function i(e,t){l.on("hook:"+e,function(){t.call(s.vm)})}function n(e){var t=s.children;if(t)for(var i,n=t.length;n--;)i=t[n],i.el.parentNode&&(e="hook:"+(e?"attached":"detached"),i.observer.emit(e),i.emitter.emit(e))}function r(e){a[e]||s.createBinding(e)}var s=this,a=s.bindings,c=s.options,l=s.observer=new o;l.proxies={},l._ctx=s.vm,l.on("get",e).on("set",t).on("mutate",t);for(var u,h,f,p=y.length;p--;)if(h=y[p],f=c[h],Array.isArray(f))for(u=f.length;u--;)i(h,f[u]);else f&&i(h,f);l.on("hook:attached",function(){n(1)}).on("hook:detached",function(){n(0)})},x.observeData=function(e){function t(e){"$data"!==e&&i()}function i(){s.update(n.data),r.emit("change:$data",n.data)}var n=this,r=n.observer;a.observe(e,"",r);var s=n.bindings.$data=new u(n,"$data");s.update(e),b(n.vm,"$data",{get:function(){return n.observer.emit("get","$data"),n.data},set:function(e){var t=n.data;a.unobserve(t,"",r),n.data=e,a.copyPaths(e,t),a.observe(e,"",r),i()}}),r.on("set",t).on("mutate",t)},x.compile=function(e,t){var i=e.nodeType;1===i&&"SCRIPT"!==e.tagName?this.compileElement(e,t):3===i&&c.interpolate&&this.compileTextNode(e)},x.checkPriorityDir=function(e,t,i){var n,r,s;if("component"===e&&i!==!0&&(s=this.resolveComponent(t,void 0,!0))?(r=h.parse(e,"",this,t),r.Ctor=s):(n=l.attr(t,e),r=n&&h.parse(e,n,this,t)),r){if(i===!0)return;return this.deferred.push(r),!0}},x.compileElement=function(e,t){if("TEXTAREA"===e.tagName&&e.value&&(e.value=this.eval(e.value)),e.hasAttributes()||e.tagName.indexOf("-")>-1){if(null!==l.attr(e,"pre"))return;for(var i=0,n=_.length;n>i;i++)if(this.checkPriorityDir(_[i],e,t))return;e.vue_trans=l.attr(e,"transition"),e.vue_anim=l.attr(e,"animation"),e.vue_effect=this.eval(l.attr(e,"effect"));var r,s,o,a,u,d,p=c.prefix+"-",m=v.call(e.attributes),g=this.options.paramAttributes;for(i=m.length;i--;){if(r=m[i],s=!1,0===r.name.indexOf(p))for(s=!0,o=h.split(r.value),n=o.length;n--;)a=o[n],d=r.name.slice(p.length),u=h.parse(d,a,this,e),"with"===d?this.bindDirective(u,this.parent):this.bindDirective(u);else c.interpolate&&(a=f.parseAttr(r.value),a&&(u=h.parse("attr",r.name+":"+a,this,e),g&&g.indexOf(r.name)>-1?this.bindDirective(u,this.parent):this.bindDirective(u)));s&&"cloak"!==d&&e.removeAttribute(r.name)}}e.hasChildNodes()&&v.call(e.childNodes).forEach(this.compile,this)},x.compileTextNode=function(e){var t=f.parse(e.nodeValue);if(t){for(var i,n,r,s=0,o=t.length;o>s;s++)n=t[s],r=null,n.key?">"===n.key.charAt(0)?(i=document.createComment("ref"),r=h.parse("partial",n.key.slice(1),this,i)):n.html?(i=document.createComment(c.prefix+"-html"),r=h.parse("html",n.key,this,i)):(i=document.createTextNode(""),r=h.parse("text",n.key,this,i)):i=document.createTextNode(n),e.parentNode.insertBefore(i,e),this.bindDirective(r);e.parentNode.removeChild(e)}},x.bindDirective=function(e,t){if(e){if(this.dirs.push(e),e.isEmpty||e.isLiteral)return e.bind&&e.bind(),void 0;var i,n=t||this,r=e.key;if(e.isExp)i=n.createBinding(r,e);else{for(;n&&!n.hasKey(r);)n=n.parent;n=n||this,i=n.bindings[r]||n.createBinding(r)}i.dirs.push(e),e.binding=i;var s=i.val();e.bind&&e.bind(s),e.update(s,!0)}},x.createBinding=function(e,t){var i=this,n=i.options.methods,r=t&&t.isExp,s=t&&t.isFn||n&&n[e],o=i.bindings,c=i.options.computed,h=new u(i,e,r,s);if(r)i.defineExp(e,h,t);else if(s)o[e]=h,h.value=i.vm[e]=n[e];else if(o[e]=h,h.root)c&&c[e]?i.defineComputed(e,h,c[e]):"$"!==e.charAt(0)?i.defineProp(e,h):i.defineMeta(e,h);else if(c&&c[l.baseKey(e)])i.defineExp(e,h);else{a.ensurePath(i.data,e);var f=e.slice(0,e.lastIndexOf("."));o[f]||i.createBinding(f)}return h},x.defineProp=function(e,t){var i=this,n=i.data,r=n.__emitter__;g.call(n,e)||(n[e]=void 0),r&&!g.call(r.values,e)&&a.convertKey(n,e),t.value=n[e],b(i.vm,e,{get:function(){return i.data[e]},set:function(t){i.data[e]=t}})},x.defineMeta=function(e,t){var i=this.observer;t.value=this.data[e],delete this.data[e],b(this.vm,e,{get:function(){return a.shouldGet&&i.emit("get",e),t.value},set:function(t){i.emit("set",e,t)}})},x.defineExp=function(e,t,i){var n=i&&i.computeFilters&&i.filters,r=n?i.expression:e,s=this.expCache[r];s||(s=this.expCache[r]=p.parse(e,this,null,n)),s&&this.markComputed(t,s)},x.defineComputed=function(e,t,i){this.markComputed(t,i),b(this.vm,e,{get:t.value.$get,set:t.value.$set})},x.markComputed=function(e,t){e.isComputed=!0,e.isFn?e.value=t:("function"==typeof t&&(t={$get:t}),e.value={$get:l.bind(t.$get,this.vm),$set:t.$set?l.bind(t.$set,this.vm):void 0}),this.computed.push(e)},x.getOption=function(e,t){var i=this.options,n=this.parent,r=c.globalAssets;return i[e]&&i[e][t]||(n?n.getOption(e,t):r[e]&&r[e][t])},x.execHook=function(e){e="hook:"+e,this.observer.emit(e),this.emitter.emit(e)},x.hasKey=function(e){var t=l.baseKey(e);return g.call(this.data,t)||g.call(this.vm,t)},x.eval=function(e,t){var i=f.parseAttr(e);return i?p.eval(i,this,t):e},x.resolveComponent=function(e,i,n){s=s||t("./viewmodel");var r=l.attr(e,"component"),o=e.tagName,a=this.eval(r,i),c=o.indexOf("-")>0&&o.toLowerCase(),u=this.getOption("components",a||c);return n?""===r?s:u:u||s},x.destroy=function(){if(!this.destroyed){var e,t,i,n,r,s=this,o=s.vm,c=s.el,l=s.dirs,u=s.computed,h=s.bindings,f=s.children,d=s.parent;for(s.execHook("beforeDestroy"),a.unobserve(s.data,"",s.observer),e=l.length;e--;)i=l[e],i.binding&&i.binding.compiler!==s&&(n=i.binding.dirs,n&&n.splice(n.indexOf(i),1)),i.unbind();for(e=u.length;e--;)u[e].unbind();for(t in h)r=h[t],r&&r.unbind();for(e=f.length;e--;)f[e].destroy();d&&d.children.splice(d.children.indexOf(s),1),c===document.body?c.innerHTML="":o.$remove(),c.vue_vm=null,s.destroyed=!0,s.execHook("afterDestroy"),s.observer.off(),s.emitter.off()}},i.exports=n}),e.register("vue/src/viewmodel.js",function(e,t,i){function n(e){new s(this,e)}function r(e){return"string"==typeof e?document.querySelector(e):e}var s=t("./compiler"),o=t("./utils"),a=t("./transition"),c=t("./batcher"),l=[].slice,u=o.defProtected,h=o.nextTick,f=new c,d=1,p=n.prototype;u(p,"$get",function(e){var t=o.get(this,e);return void 0===t&&this.$parent?this.$parent.$get(e):t}),u(p,"$set",function(e,t){o.set(this,e,t)}),u(p,"$watch",function(e,t){function i(){var e=l.call(arguments);f.push({id:n,override:!0,execute:function(){t.apply(r,e)}})}var n=d++,r=this;t._fn=i,r.$compiler.observer.on("change:"+e,i)}),u(p,"$unwatch",function(e,t){var i=["change:"+e],n=this.$compiler.observer;t&&i.push(t._fn),n.off.apply(n,i)}),u(p,"$destroy",function(){this.$compiler.destroy()}),u(p,"$broadcast",function(){for(var e,t=this.$compiler.children,i=t.length;i--;)e=t[i],e.emitter.emit.apply(e.emitter,arguments),e.vm.$broadcast.apply(e.vm,arguments)}),u(p,"$dispatch",function(){var e=this.$compiler,t=e.emitter,i=e.parent;t.emit.apply(t,arguments),i&&i.vm.$dispatch.apply(i.vm,arguments)}),["emit","on","off","once"].forEach(function(e){u(p,"$"+e,function(){var t=this.$compiler.emitter;t[e].apply(t,arguments)})}),u(p,"$appendTo",function(e,t){e=r(e);var i=this.$el;a(i,1,function(){e.appendChild(i),t&&h(t)},this.$compiler)}),u(p,"$remove",function(e){var t=this.$el;a(t,-1,function(){t.parentNode&&t.parentNode.removeChild(t),e&&h(e)},this.$compiler)}),u(p,"$before",function(e,t){e=r(e);var i=this.$el;a(i,1,function(){e.parentNode.insertBefore(i,e),t&&h(t)},this.$compiler)}),u(p,"$after",function(e,t){e=r(e);var i=this.$el;a(i,1,function(){e.nextSibling?e.parentNode.insertBefore(i,e.nextSibling):e.parentNode.appendChild(i),t&&h(t)},this.$compiler)}),i.exports=n}),e.register("vue/src/binding.js",function(e,t,i){function n(e,t,i,n){this.id=o++,this.value=void 0,this.isExp=!!i,this.isFn=n,this.root=!this.isExp&&-1===t.indexOf("."),this.compiler=e,this.key=t,this.dirs=[],this.subs=[],this.deps=[],this.unbound=!1}var r=t("./batcher"),s=new r,o=1,a=n.prototype;a.update=function(e){if((!this.isComputed||this.isFn)&&(this.value=e),this.dirs.length||this.subs.length){var t=this;s.push({id:this.id,execute:function(){t.unbound||t._update()}})}},a._update=function(){for(var e=this.dirs.length,t=this.val();e--;)this.dirs[e].update(t);this.pub()},a.val=function(){return this.isComputed&&!this.isFn?this.value.$get():this.value},a.pub=function(){for(var e=this.subs.length;e--;)this.subs[e].update()},a.unbind=function(){this.unbound=!0;for(var e=this.dirs.length;e--;)this.dirs[e].unbind();e=this.deps.length;for(var t;e--;)t=this.deps[e].subs,t.splice(t.indexOf(this),1)},i.exports=n}),e.register("vue/src/observer.js",function(e,t,i){function n(e){x(j,e,function(){var t,i,n=E.call(arguments),o=Array.prototype[e].apply(this,n);return"push"===e||"unshift"===e?t=n:"pop"===e||"shift"===e?i=[o]:"splice"===e&&(t=n.slice(2),i=o),r(this,t),s(this,i),this.__emitter__.emit("mutate","",this,{method:e,args:n,result:o,inserted:t,removed:i}),o},!O)}function r(e,t){if(t)for(var i,n,r=t.length;r--;)i=t[r],o(i)&&(i.__emitter__||(a(i),l(i)),n=i.__emitter__.owners,n.indexOf(e)<0&&n.push(e))}function s(e,t){if(t)for(var i,n=t.length;n--;)if(i=t[n],i&&i.__emitter__){var r=i.__emitter__.owners;r&&r.splice(r.indexOf(e))}}function o(e){return"object"==typeof e&&e&&!e.$compiler}function a(e){if(e.__emitter__)return!0;var t=new y;return x(e,"__emitter__",t),t.on("set",function(t,i,n){n&&c(e)}).on("mutate",function(){c(e)}),t.values=_.hash(),t.owners=[],!1}function c(e){for(var t=e.__emitter__.owners,i=t.length;i--;)t[i].__emitter__.emit("set","","",!0)}function l(e){C(e)?f(e):h(e)}function u(e,t){if(O)e.__proto__=t;else for(var i in t)x(e,i,t[i])}function h(e){u(e,A);for(var t in e)d(e,t)}function f(e){u(e,j),r(e,e)}function d(e,t){function i(e,i){s[t]=e,r.emit("set",t,e,i),C(e)&&r.emit("set",t+".length",e.length,i),g(e,t,r)}var n=t.charAt(0);if("$"!==n&&"_"!==n){var r=e.__emitter__,s=r.values;i(e[t]),w(e,t,{enumerable:!0,configurable:!0,get:function(){var e=s[t];return N.shouldGet&&r.emit("get",t),e},set:function(e){var n=s[t];b(n,t,r),v(e,n),i(e,!0)}})}}function p(e){var t=e&&e.__emitter__;if(t)if(C(e))t.emit("set","length",e.length);else{var i,n;for(i in e)n=e[i],t.emit("set",i,n),p(n)}}function v(e,t){if($(e)&&$(t)){var i,n,r;for(i in t)k.call(e,i)||(n=t[i],C(n)?e[i]=[]:$(n)?(r=e[i]={},v(r,n)):e[i]=void 0)}}function m(e,t){for(var i,n=t.split("."),r=0,s=n.length-1;s>r;r++)i=n[r],e[i]||(e[i]={},e.__emitter__&&d(e,i)),e=e[i];$(e)&&(i=n[r],k.call(e,i)||(e[i]=void 0,e.__emitter__&&d(e,i)))}function g(e,t,i){if(o(e)){var n=t?t+".":"",r=a(e),s=e.__emitter__;i.proxies=i.proxies||{};var c=i.proxies[n]={get:function(e){i.emit("get",n+e)},set:function(r,s,o){r&&i.emit("set",n+r,s),t&&o&&i.emit("set",t,e,!0)},mutate:function(e,r,s){var o=e?n+e:t;i.emit("mutate",o,r,s);var a=s.method;"sort"!==a&&"reverse"!==a&&i.emit("set",o+".length",r.length)}};s.on("get",c.get).on("set",c.set).on("mutate",c.mutate),r?p(e):l(e)}}function b(e,t,i){if(e&&e.__emitter__){t=t?t+".":"";var n=i.proxies[t];n&&(e.__emitter__.off("get",n.get).off("set",n.set).off("mutate",n.mutate),i.proxies[t]=null)}}var y=t("./emitter"),_=t("./utils"),x=_.defProtected,$=_.isObject,C=Array.isArray,k={}.hasOwnProperty,w=Object.defineProperty,E=[].slice,O={}.__proto__,j=Object.create(Array.prototype);["push","pop","shift","unshift","splice","sort","reverse"].forEach(n),x(j,"$set",function(e,t){return this.splice(e,1,t)[0]},!O),x(j,"$remove",function(e){return"number"!=typeof e&&(e=this.indexOf(e)),e>-1?this.splice(e,1)[0]:void 0},!O);var A=Object.create(Object.prototype);x(A,"$add",function(e,t){k.call(this,e)||(this[e]=t,d(this,e),this.__emitter__.emit("set",e,t,!0))},!O),x(A,"$delete",function(e){k.call(this,e)&&(this[e]=void 0,delete this[e],this.__emitter__.emit("delete",e))},!O);var N=i.exports={shouldGet:!1,observe:g,unobserve:b,ensurePath:m,copyPaths:v,watch:l,convert:a,convertKey:d}}),e.register("vue/src/directive.js",function(e,t,i){function n(e,t,i,n,o,c){this.id=a++,this.name=e,this.compiler=o,this.vm=o.vm,this.el=c,this.computeFilters=!1;var l=""===i;if("function"==typeof t)this[l?"bind":"_update"]=t;else for(var u in t)"unbind"===u||"update"===u?this["_"+u]=t[u]:this[u]=t[u];if(l||this.isEmpty)return this.isEmpty=!0,void 0;this.expression=(this.isLiteral?o.eval(i):i).trim(),r(this,n);var f=this.expression.slice(n.length).match(h);if(f){this.filters=[];for(var v,m=0,g=f.length;g>m;m++)v=s(f[m],this.compiler),v&&(this.filters.push(v),v.apply.computed&&(this.computeFilters=!0));this.filters.length||(this.filters=null)}else this.filters=null;this.isExp=this.computeFilters||!p.test(this.key)||d.test(this.key)}function r(e,t){var i=t;if(t.indexOf(":")>-1){var n=t.match(u);i=n?n[2].trim():i,e.arg=n?n[1].trim():null}e.key=i}function s(e,t){var i=e.slice(1).match(f);if(i){var n=i[0],r=t.getOption("filters",n);if(r)return{name:n,apply:r,args:i.length>1?i.slice(1):null}}}var o=(t("./utils"),t("./directives")),a=1,c=/(?:['"](?:\\.|[^'"])*['"]|\((?:\\.|[^\)])*\)|\\.|[^,])+/g,l=/^(?:['"](?:\\.|[^'"])*['"]|\\.|[^\|]|\|\|)+/,u=/^([\w-$ ]+):(.+)$/,h=/\|[^\|]+/g,f=/[^\s']+|'[^']+'|[^\s"]+|"[^"]+"/g,d=/^\$(parent|root)\./,p=/^[\w\.$]+$/,v=n.prototype;v.update=function(e,t){(t||e!==this.value||e&&"object"==typeof e)&&(this.value=e,this._update&&this._update(this.filters&&!this.computeFilters?this.applyFilters(e):e,t))},v.applyFilters=function(e){for(var t,i=e,n=0,r=this.filters.length;r>n;n++)t=this.filters[n],i=t.apply.apply(this.vm,[i].concat(t.args));return i},v.unbind=function(){this.el&&this.vm&&(this._unbind&&this._unbind(),this.vm=this.el=this.binding=this.compiler=null)},n.split=function(e){return e.indexOf(",")>-1?e.match(c)||[""]:[e]},n.parse=function(e,t,i,r){var s=i.getOption("directives",e)||o[e];if(s){var a;if(t.indexOf("|")>-1){var c=t.match(l);c&&(a=c[0].trim())}else a=t.trim();return a||""===t?new n(e,s,t,a,i,r):void 0}},i.exports=n}),e.register("vue/src/exp-parser.js",function(e,t){function i(e){return e=e.replace(m,"").replace(g,",").replace(v,"").replace(b,"").replace(y,""),e?e.split(/,+/):[]}function n(e,t,i){var n="",r=0,s=t;if(i&&void 0!==a.get(i,e))return"$temp.";for(;t&&!t.hasKey(e);)t=t.parent,r++;if(t){for(;r--;)n+="$parent.";t.bindings[e]||"$"===e.charAt(0)||t.createBinding(e)}else s.createBinding(e);return n}function r(e,t){var i;try{i=new Function(e)}catch(n){}return i}function s(e){return"$"===e.charAt(0)?"\\"+e:e}function o(e){return e.indexOf('"')>-1?e.replace(d,"'"):e}var a=t("./utils"),c=/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g,l=/"(\d+)"/g,u=/\n/g,h=new RegExp("constructor".split("").join("['\"+, ]*")),f=/\\u\d\d\d\d/,d=/"/g,p="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,undefined,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,Math",v=new RegExp(["\\b"+p.replace(/,/g,"\\b|\\b")+"\\b"].join("|"),"g"),m=/\/\*(?:.|\n)*?\*\/|\/\/[^\n]*\n|\/\/[^\n]*$|'[^']*'|"[^"]*"|[\s\t\n]*\.[\s\t\n]*[$\w\.]+/g,g=/[^\w$]+/g,b=/\b\d[^,]*/g,y=/^,+|,+$/g;e.parse=function(e,t,d,p){function v(e){var t=x.length;return x[t]=e.replace(u,"\\n"),'"'+t+'"'}function m(e){var i=e.charAt(0);e=e.slice(1);var r="this."+n(e,t,d)+e;return _[e]||(y+=r+";",_[e]=1),i+r}function g(e,t){return x[t]}if(!f.test(e)&&!h.test(e)){var b=i(e);if(!b.length)return r("return "+e,e);b=a.unique(b);var y="",_=a.hash(),x=[],$=new RegExp("[^$\\w\\.]("+b.map(s).join("|")+")[$\\w\\.]*\\b","g"),C=(" "+e).replace(c,v).replace($,m).replace(l,g);if(p)for(var k,w,E=0,O=p.length;O>E;E++)w=p[E],k=w.args?',"'+w.args.map(o).join('","')+'"':"",C='this.$compiler.getOption("filters", "'+w.name+'").call(this,'+C+k+")";return C=y+"return "+C,r(C,e)}},e.eval=function(t,i,n){var r,s=e.parse(t,i,n);return s&&(i.vm.$temp=n,r=s.call(i.vm),delete i.vm.$temp),r}}),e.register("vue/src/text-parser.js",function(e){function t(){var e=i(o),t=i(a);return new RegExp(e+e+e+"?(.+?)"+t+"?"+t+t)}function i(e){return e.replace(c,"\\$&")}function n(i){e.delimiters=i,o=i[0],a=i[1],l=t()}function r(e){if(!l.test(e))return null;for(var t,i,n,r,s=[];t=e.match(l);)i=t.index,i>0&&s.push(e.slice(0,i)),n={key:t[1].trim()},r=t[0],n.html=r.charAt(2)===o&&r.charAt(r.length-3)===a,s.push(n),e=e.slice(i+t[0].length);return e.length&&s.push(e),s}function s(e){var t=r(e);if(!t)return null;if(1===t.length)return t[0].key;for(var i,n=[],s=0,o=t.length;o>s;s++)i=t[s],n.push(i.key?"("+i.key+")":'"'+i+'"');return n.join("+")}var o="{",a="}",c=/[-.*+?^${}()|[\]\/\\]/g,l=t();e.parse=r,e.parseAttr=s,e.setDelimiters=n,e.delimiters=[o,a]}),e.register("vue/src/deps-parser.js",function(e,t,i){function n(e){if(!e.isFn){var t=s.hash();e.deps=[],a.on("get",function(i){var n=t[i.key];n&&n.compiler===i.compiler||i.compiler.repeat&&i.compiler.parent===e.compiler||(t[i.key]=i,e.deps.push(i),i.subs.push(e))}),e.value.$get(),a.off("get")}}var r=t("./emitter"),s=t("./utils"),o=t("./observer"),a=new r;i.exports={catcher:a,parse:function(e){o.shouldGet=!0,e.forEach(n),o.shouldGet=!1}}}),e.register("vue/src/filters.js",function(e,t,i){function n(e,t){if(s.isObject(e)){for(var i in e)if(n(e[i],t))return!0}else if(null!=e)return e.toString().toLowerCase().indexOf(t)>-1}function r(e){return c.test(e)?e.slice(1,-1):void 0}var s=t("./utils"),o=s.get,a=[].slice,c=/^'.*'$/,l=i.exports=s.hash();l.capitalize=function(e){return e||0===e?(e=e.toString(),e.charAt(0).toUpperCase()+e.slice(1)):""},l.uppercase=function(e){return e||0===e?e.toString().toUpperCase():""},l.lowercase=function(e){return e||0===e?e.toString().toLowerCase():""},l.currency=function(e,t){if(!e&&0!==e)return"";t=t||"$";var i=Math.floor(e).toString(),n=i.length%3,r=n>0?i.slice(0,n)+(i.length>3?",":""):"",s="."+e.toFixed(2).slice(-2);return t+r+i.slice(n).replace(/(\d{3})(?=\d)/g,"$1,")+s},l.pluralize=function(e){var t=a.call(arguments,1);return t.length>1?t[e-1]||t[t.length-1]:t[e-1]||t[0]+"s"};var u={enter:13,tab:9,"delete":46,up:38,left:37,right:39,down:40,esc:27};l.key=function(e,t){if(e){var i=u[t];return i||(i=parseInt(t,10)),function(t){t.keyCode===i&&e.call(this,t)}}},l.filterBy=function(e,t,i,a){i&&"in"!==i&&(a=i);var c=r(t)||this.$get(t);return c?(c=c.toLowerCase(),a=a&&(r(a)||this.$get(a)),Array.isArray(e)||(e=s.objectToArray(e)),e.filter(function(e){return a?n(o(e,a),c):n(e,c)})):e},l.filterBy.computed=!0,l.orderBy=function(e,t,i){var n=r(t)||this.$get(t);if(!n)return e;Array.isArray(e)||(e=s.objectToArray(e));var a=1;return i&&("-1"===i?a=-1:"!"===i.charAt(0)?(i=i.slice(1),a=this.$get(i)?1:-1):a=this.$get(i)?-1:1),e.slice().sort(function(e,t){return e=o(e,n),t=o(t,n),e===t?0:e>t?a:-a})},l.orderBy.computed=!0}),e.register("vue/src/transition.js",function(e,t,i){function n(e,t,i,n){if(!o.trans)return i(),f.CSS_SKIP;var r,s=e.classList,c=e.vue_trans_cb,u=a.enterClass,h=a.leaveClass,d=n?o.anim:o.trans;return c&&(e.removeEventListener(d,c),s.remove(u),s.remove(h),e.vue_trans_cb=null),t>0?(s.add(u),i(),n?(r=function(t){t.target===e&&(e.removeEventListener(d,r),e.vue_trans_cb=null,s.remove(u))},e.addEventListener(d,r),e.vue_trans_cb=r):l.push({execute:function(){s.remove(u)}}),f.CSS_E):(e.offsetWidth||e.offsetHeight?(s.add(h),r=function(t){t.target===e&&(e.removeEventListener(d,r),e.vue_trans_cb=null,i(),s.remove(h))},e.addEventListener(d,r),e.vue_trans_cb=r):i(),f.CSS_L)}function r(e,t,i,n,r){function s(t,i){var n=u(function(){t(),l.splice(l.indexOf(n),1),l.length||(e.vue_timeouts=null)},i);l.push(n)}var o=r.getOption("effects",n);if(!o)return i(),f.JS_SKIP;var a=o.enter,c=o.leave,l=e.vue_timeouts;if(l)for(var d=l.length;d--;)h(l[d]);return l=e.vue_timeouts=[],t>0?"function"!=typeof a?(i(),f.JS_SKIP_E):(a(e,i,s),f.JS_E):"function"!=typeof c?(i(),f.JS_SKIP_L):(c(e,i,s),f.JS_L)}function s(){var e=document.createElement("vue"),t="transitionend",i={transition:t,mozTransition:t,webkitTransition:"webkitTransitionEnd"},n={};for(var r in i)if(void 0!==e.style[r]){n.trans=i[r];break}return n.anim=""===e.style.animation?"animationend":"webkitAnimationEnd",n}var o=s(),a=t("./config"),c=t("./batcher"),l=new c,u=window.setTimeout,h=window.clearTimeout,f={CSS_E:1,CSS_L:2,JS_E:3,JS_L:4,CSS_SKIP:-1,JS_SKIP:-2,JS_SKIP_E:-3,JS_SKIP_L:-4,INIT:-5,SKIP:-6};l._preFlush=function(){document.body.offsetHeight};var d=i.exports=function(e,t,i,s){var o=function(){i(),s.execHook(t>0?"attached":"detached")};if(s.init)return o(),f.INIT;var a=""===e.vue_trans,c=""===e.vue_anim,l=e.vue_effect;return l?r(e,t,o,l,s):a||c?n(e,t,o,c):(o(),f.SKIP)};d.codes=f}),e.register("vue/src/batcher.js",function(e,t,i){function n(){this.reset()}var r=t("./utils"),s=n.prototype;s.push=function(e){if(e.id&&this.has[e.id]){if(e.override){var t=this.has[e.id];t.cancelled=!0,this.queue.push(e),this.has[e.id]=e}}else this.queue.push(e),this.has[e.id]=e,this.waiting||(this.waiting=!0,r.nextTick(r.bind(this.flush,this)))},s.flush=function(){this._preFlush&&this._preFlush();for(var e=0;e<this.queue.length;e++){var t=this.queue[e];t.cancelled||t.execute()}this.reset()},s.reset=function(){this.has=r.hash(),this.queue=[],this.waiting=!1},i.exports=n}),e.register("vue/src/directives/index.js",function(e,t,i){var n=t("../utils"),r=t("../config"),s=t("../transition"),o=i.exports=n.hash();o.component={isLiteral:!0,bind:function(){this.el.vue_vm||(this.childVM=new this.Ctor({el:this.el,parent:this.vm}))},unbind:function(){this.childVM&&this.childVM.$destroy()}},o.attr={bind:function(){var e=this.vm.$options.paramAttributes;this.isParam=e&&e.indexOf(this.arg)>-1},update:function(e){e||0===e?this.el.setAttribute(this.arg,e):this.el.removeAttribute(this.arg),this.isParam&&(this.vm[this.arg]=n.checkNumber(e))}},o.text={bind:function(){this.attr=3===this.el.nodeType?"nodeValue":"textContent"},update:function(e){this.el[this.attr]=n.guard(e)}},o.show=function(e){var t=this.el,i=e?"":"none",n=function(){t.style.display=i};s(t,e?1:-1,n,this.compiler)},o["class"]=function(e){this.arg?n[e?"addClass":"removeClass"](this.el,this.arg):(this.lastVal&&n.removeClass(this.el,this.lastVal),e&&(n.addClass(this.el,e),this.lastVal=e))},o.cloak={isEmpty:!0,bind:function(){var e=this.el;this.compiler.observer.once("hook:ready",function(){e.removeAttribute(r.prefix+"-cloak")})}},o.ref={isLiteral:!0,bind:function(){var e=this.expression;e&&(this.vm.$parent.$[e]=this.vm)},unbind:function(){var e=this.expression;e&&delete this.vm.$parent.$[e]}},o.on=t("./on"),o.repeat=t("./repeat"),o.model=t("./model"),o["if"]=t("./if"),o["with"]=t("./with"),o.html=t("./html"),o.style=t("./style"),o.partial=t("./partial"),o.view=t("./view")}),e.register("vue/src/directives/if.js",function(e,t,i){var n=t("../utils");i.exports={bind:function(){this.parent=this.el.parentNode,this.ref=document.createComment("vue-if"),this.Ctor=this.compiler.resolveComponent(this.el),this.parent.insertBefore(this.ref,this.el),this.parent.removeChild(this.el),n.attr(this.el,"view"),n.attr(this.el,"repeat") | ||
},update:function(e){e?this.childVM||(this.childVM=new this.Ctor({el:this.el.cloneNode(!0),parent:this.vm}),this.compiler.init?this.parent.insertBefore(this.childVM.$el,this.ref):this.childVM.$before(this.ref)):this._unbind()},unbind:function(){this.childVM&&(this.childVM.$destroy(),this.childVM=null)}}}),e.register("vue/src/directives/repeat.js",function(e,t,i){function n(e,t){for(var i,n=0,r=e.length;r>n;n++)if(i=e[n],!i.$reused&&i.$value===t)return n;return-1}var r=t("../utils"),s=t("../config");i.exports={bind:function(){this.identifier="$r"+this.id,this.expCache=r.hash();var e=this.el,t=this.container=e.parentNode;this.childId=this.compiler.eval(r.attr(e,"ref")),this.ref=document.createComment(s.prefix+"-repeat-"+this.key),t.insertBefore(this.ref,e),t.removeChild(e),this.initiated=!1,this.collection=null,this.vms=null},update:function(e){Array.isArray(e)||r.isObject(e)&&(e=r.objectToArray(e)),this.initiated||e&&e.length||this.dryBuild(),this.oldVMs=this.vms,this.oldCollection=this.collection,e=this.collection=e||[];var t=e[0]&&r.isObject(e[0]);this.vms=this.oldCollection?this.diff(e,t):this.init(e,t),this.childId&&(this.vm.$[this.childId]=this.vms)},dryBuild:function(){var e=this.el.cloneNode(!0),t=this.compiler.resolveComponent(e);new t({el:e,parent:this.vm,data:{$index:0},compilerOptions:{repeat:!0,expCache:this.expCache}}).$destroy(),this.initiated=!0},init:function(e,t){for(var i,n=[],r=0,s=e.length;s>r;r++)i=this.build(e[r],r,t),n.push(i),this.compiler.init?this.container.insertBefore(i.$el,this.ref):i.$before(this.ref);return n},diff:function(e,t){var i,r,s,o,a,c,l,u,h=this.container,f=this.oldVMs,d=[];for(d.length=e.length,i=0,r=e.length;r>i;i++)s=e[i],t?(s.$index=i,s.__emitter__&&s.__emitter__[this.identifier]?s.$reused=!0:d[i]=this.build(s,i,t)):(a=n(f,s),a>-1?(f[a].$reused=!0,f[a].$data.$index=i):d[i]=this.build(s,i,t));for(i=0,r=f.length;r>i;i++)o=f[i],s=o.$data,s.$reused&&(o.$reused=!0,delete s.$reused),o.$reused?(o.$index=s.$index,s.$key&&s.$key!==o.$key&&(o.$key=s.$key),d[o.$index]=o):(delete s.__emitter__[this.identifier],o.$destroy());for(i=d.length;i--;)if(o=d[i],s=o.$data,c=d[i+1],o.$reused){for(u=o.$el.nextSibling;!u.vue_vm&&u!==this.ref;)u=u.nextSibling;if(l=u.vue_vm,l!==c)if(c){for(u=c.$el;!u.parentNode;)c=d[u.vue_vm.$index+1],u=c?c.$el:this.ref;h.insertBefore(o.$el,u)}else h.insertBefore(o.$el,this.ref);delete o.$reused,delete s.$index,delete s.$key}else o.$before(c?c.$el:this.ref);return d},build:function(e,t,i){var n,r,s=!i||this.arg;s&&(n=e,r=this.arg||"$value",e={},e[r]=n),e.$index=t;var o=this.el.cloneNode(!0),a=this.compiler.resolveComponent(o,e),c=new a({el:o,data:e,parent:this.vm,compilerOptions:{repeat:!0,expCache:this.expCache}});if(e.__emitter__[this.identifier]=!0,s){var l=this,u=function(e){l.lock=!0,l.collection.$set(c.$index,e),l.lock=!1};c.$compiler.observer.on("change:"+r,u)}return c},unbind:function(){if(this.childId&&delete this.vm.$[this.childId],this.vms)for(var e=this.vms.length;e--;)this.vms[e].$destroy()}}}),e.register("vue/src/directives/on.js",function(e,t,i){t("../utils");i.exports={isFn:!0,bind:function(){this.context=this.binding.isExp?this.vm:this.binding.compiler.vm},update:function(e){if("function"==typeof e){this._unbind();var t=this.vm,i=this.context;this.handler=function(n){n.targetVM=t,i.$event=n;var r=e.call(i,n);return i.$event=null,r},this.el.addEventListener(this.arg,this.handler)}},unbind:function(){this.el.removeEventListener(this.arg,this.handler)}}}),e.register("vue/src/directives/model.js",function(e,t,i){function n(e){return o.call(e.options,function(e){return e.selected}).map(function(e){return e.value||e.text})}var r=t("../utils"),s=navigator.userAgent.indexOf("MSIE 9.0")>0,o=[].filter;i.exports={bind:function(){var e=this,t=e.el,i=t.type,n=t.tagName;e.lock=!1,e.ownerVM=e.binding.compiler.vm,e.event=e.compiler.options.lazy||"SELECT"===n||"checkbox"===i||"radio"===i?"change":"input",e.attr="checkbox"===i?"checked":"INPUT"===n||"SELECT"===n||"TEXTAREA"===n?"value":"innerHTML","SELECT"===n&&t.hasAttribute("multiple")&&(this.multi=!0);var o=!1;e.cLock=function(){o=!0},e.cUnlock=function(){o=!1},t.addEventListener("compositionstart",this.cLock),t.addEventListener("compositionend",this.cUnlock),e.set=e.filters?function(){if(!o){var i;try{i=t.selectionStart}catch(n){}e._set(),r.nextTick(function(){void 0!==i&&t.setSelectionRange(i,i)})}}:function(){o||(e.lock=!0,e._set(),r.nextTick(function(){e.lock=!1}))},t.addEventListener(e.event,e.set),s&&(e.onCut=function(){r.nextTick(function(){e.set()})},e.onDel=function(t){(46===t.keyCode||8===t.keyCode)&&e.set()},t.addEventListener("cut",e.onCut),t.addEventListener("keyup",e.onDel))},_set:function(){this.ownerVM.$set(this.key,this.multi?n(this.el):this.el[this.attr])},update:function(e,t){if(t&&void 0===e)return this._set();if(!this.lock){var i=this.el;"SELECT"===i.tagName?(i.selectedIndex=-1,this.multi&&Array.isArray(e)?e.forEach(this.updateSelect,this):this.updateSelect(e)):"radio"===i.type?i.checked=e==i.value:"checkbox"===i.type?i.checked=!!e:i[this.attr]=r.guard(e)}},updateSelect:function(e){for(var t=this.el.options,i=t.length;i--;)if(t[i].value==e){t[i].selected=!0;break}},unbind:function(){var e=this.el;e.removeEventListener(this.event,this.set),e.removeEventListener("compositionstart",this.cLock),e.removeEventListener("compositionend",this.cUnlock),s&&(e.removeEventListener("cut",this.onCut),e.removeEventListener("keyup",this.onDel))}}}),e.register("vue/src/directives/with.js",function(e,t,i){var n=t("../utils");i.exports={bind:function(){var e=this,t=e.arg,i=e.key,r=e.compiler,s=e.binding.compiler;return r===s?(this.alone=!0,void 0):(t&&(r.bindings[t]||r.createBinding(t),r.observer.on("change:"+t,function(t){r.init||(e.lock||(e.lock=!0,n.nextTick(function(){e.lock=!1})),s.vm.$set(i,t))})),void 0)},update:function(e){this.alone||this.lock||(this.arg?this.vm.$set(this.arg,e):this.vm.$data=e)}}}),e.register("vue/src/directives/html.js",function(e,t,i){var n=t("../utils").guard,r=[].slice;i.exports={bind:function(){8===this.el.nodeType&&(this.holder=document.createElement("div"),this.nodes=[])},update:function(e){e=n(e),this.holder?this.swap(e):this.el.innerHTML=e},swap:function(e){for(var t,i=this.el.parentNode,n=this.holder,s=this.nodes,o=s.length;o--;)i.removeChild(s[o]);for(n.innerHTML=e,s=this.nodes=r.call(n.childNodes),o=0,t=s.length;t>o;o++)i.insertBefore(s[o],this.el)}}}),e.register("vue/src/directives/style.js",function(e,t,i){function n(e){return e[1].toUpperCase()}var r=/-([a-z])/g,s=["webkit","moz","ms"];i.exports={bind:function(){var e=this.arg;if(e){var t=e.charAt(0);"$"===t?(e=e.slice(1),this.prefixed=!0):"-"===t&&(e=e.slice(1)),this.prop=e.replace(r,n)}},update:function(e){var t=this.prop;if(t){if(this.el.style[t]=e,this.prefixed){t=t.charAt(0).toUpperCase()+t.slice(1);for(var i=s.length;i--;)this.el.style[s[i]+t]=e}}else this.el.style.cssText=e}}}),e.register("vue/src/directives/partial.js",function(e,t,i){t("../utils");i.exports={isLiteral:!0,bind:function(){var e=this.expression;if(e){var t=this.el,i=this.compiler,n=i.getOption("partials",e);if(n)if(n=n.cloneNode(!0),8===t.nodeType){var r=[].slice.call(n.childNodes),s=t.parentNode;s.insertBefore(n,t),s.removeChild(t),r.forEach(i.compile,i)}else t.innerHTML="",t.appendChild(n.cloneNode(!0))}}}}),e.register("vue/src/directives/view.js",function(e,t,i){i.exports={bind:function(){var e=this.raw=this.el,t=e.parentNode,i=this.ref=document.createComment("v-view");t.insertBefore(i,e),t.removeChild(e);for(var n,r=this.inner=document.createElement("div");n=e.firstChild;)r.appendChild(n)},update:function(e){this._unbind();var t=this.compiler.getOption("components",e);t&&(this.childVM=new t({el:this.raw.cloneNode(!0),parent:this.vm,compilerOptions:{rawContent:this.inner.cloneNode(!0)}}),this.el=this.childVM.$el,this.compiler.init?this.ref.parentNode.insertBefore(this.el,this.ref):this.childVM.$before(this.ref))},unbind:function(){this.childVM&&this.childVM.$destroy()}}}),e.alias("vue/src/main.js","vue/index.js"),"object"==typeof exports?module.exports=e("vue"):"function"==typeof define&&define.amd?define(function(){return e("vue")}):window.Vue=e("vue")}(); |
{ | ||
"name": "vue", | ||
"version": "0.9.3", | ||
"version": "0.10.0", | ||
"author": { | ||
@@ -34,3 +34,3 @@ "name": "Evan You", | ||
"grunt-saucelabs": "~4.1.2", | ||
"gulp-component": "~0.1.4", | ||
"gulp-component": "~0.1.6", | ||
"vinyl-fs": "~0.0.2", | ||
@@ -37,0 +37,0 @@ "jshint-stylish": "~0.1.4", |
@@ -15,3 +15,3 @@ <p align="center"><a href="http://vuejs.org" target="_blank"><img width="100"src="http://vuejs.org/images/logo.png"></a></p> | ||
- Building interface by composing reusable components | ||
- Flexibility to mix & match small libraries for a custom front-end stack | ||
- Flexibility to mix & match the view layer with other libraries | ||
@@ -48,3 +48,3 @@ It's really really easy to get started. Seriously, it's so easy: | ||
- General questions: check the [FAQ](https://github.com/yyx990803/vue/wiki/FAQ) first, if it's not addressed in there, ask [here](https://github.com/yyx990803/vue/issues/96). | ||
- General, non source-code related questions: check the [FAQ](https://github.com/yyx990803/vue/wiki/FAQ) first, if it's not addressed in there, ask [here](https://github.com/vuejs/Discussion/issues). | ||
- If you have a Vue-related project/component/tool, add it to [this list](https://github.com/yyx990803/vue/wiki/User-Contributed-Components-&-Tools)! | ||
@@ -51,0 +51,0 @@ - Bugs, suggestions & feature requests: [open an issue](https://github.com/yyx990803/vue/issues) |
@@ -32,5 +32,4 @@ var utils = require('./utils') | ||
var job = this.queue[i] | ||
if (job.cancelled) continue | ||
if (job.execute() !== false) { | ||
this.has[job.id] = false | ||
if (!job.cancelled) { | ||
job.execute() | ||
} | ||
@@ -37,0 +36,0 @@ } |
@@ -42,4 +42,2 @@ var Batcher = require('./batcher'), | ||
self._update() | ||
} else { | ||
return false | ||
} | ||
@@ -46,0 +44,0 @@ } |
@@ -10,10 +10,9 @@ var Emitter = require('./emitter'), | ||
ExpParser = require('./exp-parser'), | ||
ViewModel, | ||
// cache methods | ||
slice = [].slice, | ||
log = utils.log, | ||
makeHash = utils.hash, | ||
extend = utils.extend, | ||
def = utils.defProtected, | ||
hasOwn = ({}).hasOwnProperty, | ||
def = Object.defineProperty, | ||
@@ -25,2 +24,11 @@ // hooks to register | ||
'attached', 'detached' | ||
], | ||
// list of priority directives | ||
// that needs to be checked in specific order | ||
priorityDirectives = [ | ||
'if', | ||
'repeat', | ||
'view', | ||
'component' | ||
] | ||
@@ -34,67 +42,79 @@ | ||
var compiler = this | ||
var compiler = this, | ||
key, i | ||
// default state | ||
compiler.init = true | ||
compiler.repeat = false | ||
compiler.destroyed = false | ||
compiler.delayReady = false | ||
// process and extend options | ||
options = compiler.options = options || makeHash() | ||
options = compiler.options = options || {} | ||
utils.processOptions(options) | ||
// copy data, methods & compiler options | ||
var data = compiler.data = options.data || {} | ||
extend(vm, data, true) | ||
extend(vm, options.methods, true) | ||
// copy compiler options | ||
extend(compiler, options.compilerOptions) | ||
// repeat indicates this is a v-repeat instance | ||
compiler.repeat = compiler.repeat || false | ||
// expCache will be shared between v-repeat instances | ||
compiler.expCache = compiler.expCache || {} | ||
// initialize element | ||
var el = compiler.el = compiler.setupElement(options) | ||
log('\nnew VM instance: ' + el.tagName + '\n') | ||
utils.log('\nnew VM instance: ' + el.tagName + '\n') | ||
// set compiler properties | ||
compiler.vm = el.vue_vm = vm | ||
compiler.bindings = makeHash() | ||
compiler.dirs = [] | ||
// set other compiler properties | ||
compiler.vm = el.vue_vm = vm | ||
compiler.bindings = utils.hash() | ||
compiler.dirs = [] | ||
compiler.deferred = [] | ||
compiler.exps = [] | ||
compiler.computed = [] | ||
compiler.children = [] | ||
compiler.emitter = new Emitter() | ||
compiler.emitter._ctx = vm | ||
compiler.delegators = makeHash() | ||
compiler.emitter = new Emitter(vm) | ||
// set inenumerable VM properties | ||
def(vm, '$', makeHash()) | ||
def(vm, '$el', el) | ||
def(vm, '$options', options) | ||
def(vm, '$compiler', compiler) | ||
// create bindings for computed properties | ||
if (options.methods) { | ||
for (key in options.methods) { | ||
compiler.createBinding(key) | ||
} | ||
} | ||
// set parent VM | ||
// and register child id on parent | ||
var parentVM = options.parent, | ||
childId = utils.attr(el, 'ref') | ||
// create bindings for methods | ||
if (options.computed) { | ||
for (key in options.computed) { | ||
compiler.createBinding(key) | ||
} | ||
} | ||
// VM --------------------------------------------------------------------- | ||
// set VM properties | ||
vm.$ = {} | ||
vm.$el = el | ||
vm.$options = options | ||
vm.$compiler = compiler | ||
vm.$event = null | ||
// set parent & root | ||
var parentVM = options.parent | ||
if (parentVM) { | ||
compiler.parent = parentVM.$compiler | ||
parentVM.$compiler.children.push(compiler) | ||
def(vm, '$parent', parentVM) | ||
if (childId) { | ||
compiler.childId = childId | ||
parentVM.$[childId] = vm | ||
} | ||
vm.$parent = parentVM | ||
} | ||
vm.$root = getRoot(compiler).vm | ||
// set root | ||
def(vm, '$root', getRoot(compiler).vm) | ||
// DATA ------------------------------------------------------------------- | ||
// setup observer | ||
// this is necesarry for all hooks and data observation events | ||
compiler.setupObserver() | ||
// create bindings for computed properties | ||
var computed = options.computed | ||
if (computed) { | ||
for (var key in computed) { | ||
compiler.createBinding(key) | ||
// initialize data | ||
var data = compiler.data = options.data || {}, | ||
defaultData = options.defaultData | ||
if (defaultData) { | ||
for (key in defaultData) { | ||
if (!hasOwn.call(data, key)) { | ||
data[key] = defaultData[key] | ||
} | ||
} | ||
@@ -104,46 +124,78 @@ } | ||
// copy paramAttributes | ||
if (options.paramAttributes) { | ||
options.paramAttributes.forEach(function (attr) { | ||
var val = el.getAttribute(attr) | ||
vm[attr] = (isNaN(val) || val === null) | ||
? val | ||
: Number(val) | ||
}) | ||
var params = options.paramAttributes | ||
if (params) { | ||
i = params.length | ||
while (i--) { | ||
data[params[i]] = utils.checkNumber( | ||
compiler.eval( | ||
el.getAttribute(params[i]) | ||
) | ||
) | ||
} | ||
} | ||
// copy data properties to vm | ||
// so user can access them in the created hook | ||
extend(vm, data) | ||
vm.$data = data | ||
// beforeCompile hook | ||
compiler.execHook('created') | ||
// the user might have set some props on the vm | ||
// so copy it back to the data... | ||
extend(data, vm) | ||
// the user might have swapped the data ... | ||
data = compiler.data = vm.$data | ||
// observe the data | ||
// user might also set some properties on the vm | ||
// in which case we should copy back to $data | ||
var vmProp | ||
for (key in vm) { | ||
vmProp = vm[key] | ||
if ( | ||
key.charAt(0) !== '$' && | ||
data[key] !== vmProp && | ||
typeof vmProp !== 'function' | ||
) { | ||
data[key] = vmProp | ||
} | ||
} | ||
// now we can observe the data. | ||
// this will convert data properties to getter/setters | ||
// and emit the first batch of set events, which will | ||
// in turn create the corresponding bindings. | ||
compiler.observeData(data) | ||
// for repeated items, create index/key bindings | ||
// because they are ienumerable | ||
if (compiler.repeat) { | ||
compiler.createBinding('$index') | ||
if (data.$key) compiler.createBinding('$key') | ||
// COMPILE ---------------------------------------------------------------- | ||
// before compiling, resolve content insertion points | ||
if (options.template) { | ||
this.resolveContent() | ||
} | ||
// now parse the DOM, during which we will create necessary bindings | ||
// and bind the parsed directives | ||
// now parse the DOM and bind directives. | ||
// During this stage, we will also create bindings for | ||
// encountered keypaths that don't have a binding yet. | ||
compiler.compile(el, true) | ||
// bind deferred directives (child components) | ||
compiler.deferred.forEach(compiler.bindDirective, compiler) | ||
// Any directive that creates child VMs are deferred | ||
// so that when they are compiled, all bindings on the | ||
// parent VM have been created. | ||
i = compiler.deferred.length | ||
while (i--) { | ||
compiler.bindDirective(compiler.deferred[i]) | ||
} | ||
compiler.deferred = null | ||
// extract dependencies for computed properties | ||
compiler.parseDeps() | ||
// extract dependencies for computed properties. | ||
// this will evaluated all collected computed bindings | ||
// and collect get events that are emitted. | ||
if (this.computed.length) { | ||
DepsParser.parse(this.computed) | ||
} | ||
// done! | ||
compiler.rawContent = null | ||
compiler.init = false | ||
// post compile / ready hook | ||
if (!compiler.delayReady) { | ||
compiler.execHook('ready') | ||
} | ||
compiler.execHook('ready') | ||
} | ||
@@ -163,10 +215,13 @@ | ||
var template = options.template | ||
var template = options.template, | ||
child, replacer, i, attr, attrs | ||
if (template) { | ||
// collect anything already in there | ||
/* jshint boss: true */ | ||
var child, | ||
frag = this.rawContent = document.createDocumentFragment() | ||
while (child = el.firstChild) { | ||
frag.appendChild(child) | ||
if (el.hasChildNodes()) { | ||
this.rawContent = document.createElement('div') | ||
/* jshint boss: true */ | ||
while (child = el.firstChild) { | ||
this.rawContent.appendChild(child) | ||
} | ||
} | ||
@@ -176,3 +231,3 @@ // replace option: use the first node in | ||
if (options.replace && template.childNodes.length === 1) { | ||
var replacer = template.childNodes[0].cloneNode(true) | ||
replacer = template.childNodes[0].cloneNode(true) | ||
if (el.parentNode) { | ||
@@ -182,2 +237,11 @@ el.parentNode.insertBefore(replacer, el) | ||
} | ||
// copy over attributes | ||
if (el.hasAttributes()) { | ||
i = el.attributes.length | ||
while (i--) { | ||
attr = el.attributes[i] | ||
replacer.setAttribute(attr.name, attr.value) | ||
} | ||
} | ||
// replace | ||
el = replacer | ||
@@ -187,2 +251,3 @@ } else { | ||
} | ||
} | ||
@@ -193,5 +258,5 @@ | ||
if (options.className) el.className = options.className | ||
var attrs = options.attributes | ||
attrs = options.attributes | ||
if (attrs) { | ||
for (var attr in attrs) { | ||
for (attr in attrs) { | ||
el.setAttribute(attr, attrs[attr]) | ||
@@ -205,2 +270,55 @@ } | ||
/** | ||
* Deal with <content> insertion points | ||
* per the Web Components spec | ||
*/ | ||
CompilerProto.resolveContent = function () { | ||
var outlets = slice.call(this.el.getElementsByTagName('content')), | ||
raw = this.rawContent, | ||
outlet, select, i, j, main | ||
i = outlets.length | ||
if (i) { | ||
// first pass, collect corresponding content | ||
// for each outlet. | ||
while (i--) { | ||
outlet = outlets[i] | ||
if (raw) { | ||
select = outlet.getAttribute('select') | ||
if (select) { // select content | ||
outlet.content = | ||
slice.call(raw.querySelectorAll(select)) | ||
} else { // default content | ||
main = outlet | ||
} | ||
} else { // fallback content | ||
outlet.content = | ||
slice.call(outlet.childNodes) | ||
} | ||
} | ||
// second pass, actually insert the contents | ||
for (i = 0, j = outlets.length; i < j; i++) { | ||
outlet = outlets[i] | ||
if (outlet === main) continue | ||
insert(outlet, outlet.content) | ||
} | ||
// finally insert the main content | ||
if (raw && main) { | ||
insert(main, slice.call(raw.childNodes)) | ||
} | ||
} | ||
function insert (outlet, contents) { | ||
var parent = outlet.parentNode, | ||
i = 0, j = contents.length | ||
for (; i < j; i++) { | ||
parent.insertBefore(contents[i], outlet) | ||
} | ||
parent.removeChild(outlet) | ||
} | ||
this.rawContent = null | ||
} | ||
/** | ||
* Setup observer. | ||
@@ -220,3 +338,3 @@ * The observer listens for get/set/mutate events on all VM | ||
// so they can be referenced and removed later | ||
observer.proxies = makeHash() | ||
observer.proxies = {} | ||
observer._ctx = compiler.vm | ||
@@ -231,10 +349,12 @@ | ||
// register hooks | ||
hooks.forEach(function (hook) { | ||
var fns = options[hook] | ||
var i = hooks.length, j, hook, fns | ||
while (i--) { | ||
hook = hooks[i] | ||
fns = options[hook] | ||
if (Array.isArray(fns)) { | ||
var i = fns.length | ||
j = fns.length | ||
// since hooks were merged with child at head, | ||
// we loop reversely. | ||
while (i--) { | ||
registerHook(hook, fns[i]) | ||
while (j--) { | ||
registerHook(hook, fns[j]) | ||
} | ||
@@ -244,3 +364,3 @@ } else if (fns) { | ||
} | ||
}) | ||
} | ||
@@ -309,4 +429,3 @@ // broadcast attached/detached hooks | ||
// allow $data to be swapped | ||
defGetSet(compiler.vm, '$data', { | ||
enumerable: false, | ||
def(compiler.vm, '$data', { | ||
get: function () { | ||
@@ -322,3 +441,3 @@ compiler.observer.emit('get', '$data') | ||
Observer.observe(newData, '', observer) | ||
compiler.observer.emit('set', '$data', newData) | ||
update() | ||
} | ||
@@ -333,6 +452,9 @@ }) | ||
function onSet (key) { | ||
if (key !== '$data') { | ||
$dataBinding.update(compiler.data) | ||
} | ||
if (key !== '$data') update() | ||
} | ||
function update () { | ||
$dataBinding.update(compiler.data) | ||
observer.emit('change:$data', compiler.data) | ||
} | ||
} | ||
@@ -344,98 +466,84 @@ | ||
CompilerProto.compile = function (node, root) { | ||
var nodeType = node.nodeType | ||
if (nodeType === 1 && node.tagName !== 'SCRIPT') { // a normal node | ||
this.compileElement(node, root) | ||
} else if (nodeType === 3 && config.interpolate) { | ||
this.compileTextNode(node) | ||
} | ||
} | ||
var compiler = this, | ||
nodeType = node.nodeType, | ||
tagName = node.tagName | ||
/** | ||
* Check for a priority directive | ||
* If it is present and valid, return true to skip the rest | ||
*/ | ||
CompilerProto.checkPriorityDir = function (dirname, node, root) { | ||
var expression, directive, Ctor | ||
if ( | ||
dirname === 'component' && | ||
root !== true && | ||
(Ctor = this.resolveComponent(node, undefined, true)) | ||
) { | ||
directive = Directive.parse(dirname, '', this, node) | ||
directive.Ctor = Ctor | ||
} else { | ||
expression = utils.attr(node, dirname) | ||
directive = expression && Directive.parse(dirname, expression, this, node) | ||
} | ||
if (directive) { | ||
if (root === true) { | ||
utils.warn( | ||
'Directive v-' + dirname + ' cannot be used on an already instantiated ' + | ||
'VM\'s root node. Use it from the parent\'s template instead.' | ||
) | ||
return | ||
} | ||
this.deferred.push(directive) | ||
return true | ||
} | ||
} | ||
if (nodeType === 1 && tagName !== 'SCRIPT') { // a normal node | ||
/** | ||
* Compile normal directives on a node | ||
*/ | ||
CompilerProto.compileElement = function (node, root) { | ||
// skip anything with v-pre | ||
if (utils.attr(node, 'pre') !== null) return | ||
// textarea is pretty annoying | ||
// because its value creates childNodes which | ||
// we don't want to compile. | ||
if (node.tagName === 'TEXTAREA' && node.value) { | ||
node.value = this.eval(node.value) | ||
} | ||
// special attributes to check | ||
var repeatExp, | ||
withExp, | ||
partialId, | ||
directive, | ||
componentId = utils.attr(node, 'component') || tagName.toLowerCase(), | ||
componentCtor = compiler.getOption('components', componentId) | ||
// only compile if this element has attributes | ||
// or its tagName contains a hyphen (which means it could | ||
// potentially be a custom element) | ||
if (node.hasAttributes() || node.tagName.indexOf('-') > -1) { | ||
// It is important that we access these attributes | ||
// procedurally because the order matters. | ||
// | ||
// `utils.attr` removes the attribute once it gets the | ||
// value, so we should not access them all at once. | ||
// skip anything with v-pre | ||
if (utils.attr(node, 'pre') !== null) { | ||
return | ||
} | ||
// v-repeat has the highest priority | ||
// and we need to preserve all other attributes for it. | ||
/* jshint boss: true */ | ||
if (repeatExp = utils.attr(node, 'repeat')) { | ||
// repeat block cannot have v-id at the same time. | ||
directive = Directive.parse('repeat', repeatExp, compiler, node) | ||
if (directive) { | ||
directive.Ctor = componentCtor | ||
// defer child component compilation | ||
// so by the time they are compiled, the parent | ||
// would have collected all bindings | ||
compiler.deferred.push(directive) | ||
// check priority directives. | ||
// if any of them are present, it will take over the node with a childVM | ||
// so we can skip the rest | ||
for (var i = 0, l = priorityDirectives.length; i < l; i++) { | ||
if (this.checkPriorityDir(priorityDirectives[i], node, root)) { | ||
return | ||
} | ||
// v-with has 2nd highest priority | ||
} else if (root !== true && ((withExp = utils.attr(node, 'with')) || componentCtor)) { | ||
withExp = Directive.split(withExp || '') | ||
withExp.forEach(function (exp, i) { | ||
var directive = Directive.parse('with', exp, compiler, node) | ||
if (directive) { | ||
directive.Ctor = componentCtor | ||
// notify the directive that this is the | ||
// last expression in the group | ||
directive.last = i === withExp.length - 1 | ||
compiler.deferred.push(directive) | ||
} | ||
}) | ||
} else { | ||
// check transition & animation properties | ||
node.vue_trans = utils.attr(node, 'transition') | ||
node.vue_anim = utils.attr(node, 'animation') | ||
node.vue_effect = utils.attr(node, 'effect') | ||
// replace innerHTML with partial | ||
partialId = utils.attr(node, 'partial') | ||
if (partialId) { | ||
var partial = compiler.getOption('partials', partialId) | ||
if (partial) { | ||
node.innerHTML = '' | ||
node.appendChild(partial.cloneNode(true)) | ||
} | ||
} | ||
// finally, only normal directives left! | ||
compiler.compileNode(node) | ||
} | ||
} else if (nodeType === 3 && config.interpolate) { // text node | ||
// check transition & animation properties | ||
node.vue_trans = utils.attr(node, 'transition') | ||
node.vue_anim = utils.attr(node, 'animation') | ||
node.vue_effect = this.eval(utils.attr(node, 'effect')) | ||
compiler.compileTextNode(node) | ||
var prefix = config.prefix + '-', | ||
attrs = slice.call(node.attributes), | ||
params = this.options.paramAttributes, | ||
attr, isDirective, exps, exp, directive, dirname | ||
} | ||
} | ||
/** | ||
* Compile a normal node | ||
*/ | ||
CompilerProto.compileNode = function (node) { | ||
var i, j, | ||
attrs = slice.call(node.attributes), | ||
prefix = config.prefix + '-' | ||
// parse if has attributes | ||
if (attrs && attrs.length) { | ||
var attr, isDirective, exps, exp, directive, dirname | ||
// loop through all attributes | ||
i = attrs.length | ||
while (i--) { | ||
attr = attrs[i] | ||
@@ -450,10 +558,14 @@ isDirective = false | ||
// inside each attribute | ||
j = exps.length | ||
while (j--) { | ||
exp = exps[j] | ||
l = exps.length | ||
while (l--) { | ||
exp = exps[l] | ||
dirname = attr.name.slice(prefix.length) | ||
directive = Directive.parse(dirname, exp, this, node) | ||
if (directive) { | ||
if (dirname === 'with') { | ||
this.bindDirective(directive, this.parent) | ||
} else { | ||
this.bindDirective(directive) | ||
} | ||
} | ||
@@ -465,3 +577,7 @@ } else if (config.interpolate) { | ||
directive = Directive.parse('attr', attr.name + ':' + exp, this, node) | ||
if (directive) { | ||
if (params && params.indexOf(attr.name) > -1) { | ||
// a param attribute... we should use the parent binding | ||
// to avoid circular updates like size={{size}} | ||
this.bindDirective(directive, this.parent) | ||
} else { | ||
this.bindDirective(directive) | ||
@@ -476,5 +592,7 @@ } | ||
} | ||
} | ||
// recursively compile childNodes | ||
if (node.childNodes.length) { | ||
if (node.hasChildNodes()) { | ||
slice.call(node.childNodes).forEach(this.compile, this) | ||
@@ -491,27 +609,14 @@ } | ||
if (!tokens) return | ||
var el, token, directive, partial, partialId, partialNodes | ||
var el, token, directive | ||
for (var i = 0, l = tokens.length; i < l; i++) { | ||
token = tokens[i] | ||
directive = partialNodes = null | ||
directive = null | ||
if (token.key) { // a binding | ||
if (token.key.charAt(0) === '>') { // a partial | ||
partialId = token.key.slice(1).trim() | ||
if (partialId === 'yield') { | ||
el = this.rawContent | ||
} else { | ||
partial = this.getOption('partials', partialId) | ||
if (partial) { | ||
el = partial.cloneNode(true) | ||
} else { | ||
utils.warn('Unknown partial: ' + partialId) | ||
continue | ||
} | ||
} | ||
if (el) { | ||
// save an Array reference of the partial's nodes | ||
// so we can compile them AFTER appending the fragment | ||
partialNodes = slice.call(el.childNodes) | ||
} | ||
} else { // a real binding | ||
el = document.createComment('ref') | ||
directive = Directive.parse('partial', token.key.slice(1), this, el) | ||
} else { | ||
if (!token.html) { // text binding | ||
@@ -531,15 +636,5 @@ el = document.createTextNode('') | ||
node.parentNode.insertBefore(el, node) | ||
// bind directive | ||
if (directive) { | ||
this.bindDirective(directive) | ||
} | ||
this.bindDirective(directive) | ||
// compile partial after appending, because its children's parentNode | ||
// will change from the fragment to the correct parentNode. | ||
// This could affect directives that need access to its element's parentNode. | ||
if (partialNodes) { | ||
partialNodes.forEach(this.compile, this) | ||
} | ||
} | ||
@@ -552,4 +647,6 @@ node.parentNode.removeChild(node) | ||
*/ | ||
CompilerProto.bindDirective = function (directive) { | ||
CompilerProto.bindDirective = function (directive, bindingOwner) { | ||
if (!directive) return | ||
// keep track of it so we can unbind() later | ||
@@ -567,3 +664,3 @@ this.dirs.push(directive) | ||
var binding, | ||
compiler = this, | ||
compiler = bindingOwner || this, | ||
key = directive.key | ||
@@ -573,3 +670,3 @@ | ||
// expression bindings are always created on current compiler | ||
binding = compiler.createBinding(key, true, directive.isFn) | ||
binding = compiler.createBinding(key, directive) | ||
} else { | ||
@@ -602,7 +699,10 @@ // recursively locate which compiler owns the binding | ||
*/ | ||
CompilerProto.createBinding = function (key, isExp, isFn) { | ||
CompilerProto.createBinding = function (key, directive) { | ||
log(' created binding: ' + key) | ||
utils.log(' created binding: ' + key) | ||
var compiler = this, | ||
methods = compiler.options.methods, | ||
isExp = directive && directive.isExp, | ||
isFn = (directive && directive.isFn) || (methods && methods[key]), | ||
bindings = compiler.bindings, | ||
@@ -614,3 +714,6 @@ computed = compiler.options.computed, | ||
// expression bindings are anonymous | ||
compiler.defineExp(key, binding) | ||
compiler.defineExp(key, binding, directive) | ||
} else if (isFn) { | ||
bindings[key] = binding | ||
binding.value = compiler.vm[key] = methods[key] | ||
} else { | ||
@@ -629,4 +732,9 @@ bindings[key] = binding | ||
} | ||
} else if (computed && computed[utils.baseKey(key)]) { | ||
// nested path on computed property | ||
compiler.defineExp(key, binding) | ||
} else { | ||
// ensure path in data so it can be observed | ||
// ensure path in data so that computed properties that | ||
// access the path don't throw an error and can collect | ||
// dependencies | ||
Observer.ensurePath(compiler.data, key) | ||
@@ -649,3 +757,2 @@ var parentKey = key.slice(0, key.lastIndexOf('.')) | ||
CompilerProto.defineProp = function (key, binding) { | ||
var compiler = this, | ||
@@ -657,3 +764,3 @@ data = compiler.data, | ||
// so it can be observed | ||
if (!(key in data)) { | ||
if (!(hasOwn.call(data, key))) { | ||
data[key] = undefined | ||
@@ -664,3 +771,3 @@ } | ||
// is not observed, we need to add it to the observed keys. | ||
if (ob && !(key in ob.values)) { | ||
if (ob && !(hasOwn.call(ob.values, key))) { | ||
Observer.convertKey(data, key) | ||
@@ -671,3 +778,3 @@ } | ||
defGetSet(compiler.vm, key, { | ||
def(compiler.vm, key, { | ||
get: function () { | ||
@@ -688,17 +795,12 @@ return compiler.data[key] | ||
CompilerProto.defineMeta = function (key, binding) { | ||
var vm = this.vm, | ||
ob = this.observer, | ||
value = binding.value = vm[key] || this.data[key] | ||
// remove initital meta in data, since the same piece | ||
// of data can be observed by different VMs, each have | ||
// its own associated meta info. | ||
var ob = this.observer | ||
binding.value = this.data[key] | ||
delete this.data[key] | ||
defGetSet(vm, key, { | ||
def(this.vm, key, { | ||
get: function () { | ||
if (Observer.shouldGet) ob.emit('get', key) | ||
return value | ||
return binding.value | ||
}, | ||
set: function (val) { | ||
ob.emit('set', key, val) | ||
value = val | ||
} | ||
@@ -712,7 +814,11 @@ }) | ||
*/ | ||
CompilerProto.defineExp = function (key, binding) { | ||
var getter = ExpParser.parse(key, this) | ||
CompilerProto.defineExp = function (key, binding, directive) { | ||
var filters = directive && directive.computeFilters && directive.filters, | ||
exp = filters ? directive.expression : key, | ||
getter = this.expCache[exp] | ||
if (!getter) { | ||
getter = this.expCache[exp] = ExpParser.parse(key, this, null, filters) | ||
} | ||
if (getter) { | ||
this.markComputed(binding, getter) | ||
this.exps.push(binding) | ||
} | ||
@@ -726,3 +832,3 @@ } | ||
this.markComputed(binding, value) | ||
defGetSet(this.vm, key, { | ||
def(this.vm, key, { | ||
get: binding.value.$get, | ||
@@ -784,3 +890,3 @@ set: binding.value.$set | ||
CompilerProto.hasKey = function (key) { | ||
var baseKey = key.split('.')[0] | ||
var baseKey = utils.baseKey(key) | ||
return hasOwn.call(this.data, baseKey) || | ||
@@ -791,42 +897,38 @@ hasOwn.call(this.vm, baseKey) | ||
/** | ||
* Collect dependencies for computed properties | ||
* Do a one-time eval of a string that potentially | ||
* includes bindings. It accepts additional raw data | ||
* because we need to dynamically resolve v-component | ||
* before a childVM is even compiled... | ||
*/ | ||
CompilerProto.parseDeps = function () { | ||
if (!this.computed.length) return | ||
DepsParser.parse(this.computed) | ||
CompilerProto.eval = function (exp, data) { | ||
var parsed = TextParser.parseAttr(exp) | ||
return parsed | ||
? ExpParser.eval(parsed, this, data) | ||
: exp | ||
} | ||
/** | ||
* Add an event delegation listener | ||
* listeners are instances of directives with `isFn:true` | ||
* Resolve a Component constructor for an element | ||
* with the data to be used | ||
*/ | ||
CompilerProto.addListener = function (listener) { | ||
var event = listener.arg, | ||
delegator = this.delegators[event] | ||
if (!delegator) { | ||
// initialize a delegator | ||
delegator = this.delegators[event] = { | ||
targets: [], | ||
handler: function (e) { | ||
var i = delegator.targets.length, | ||
target | ||
while (i--) { | ||
target = delegator.targets[i] | ||
if (target.el.contains(e.target) && target.handler) { | ||
target.handler(e) | ||
} | ||
} | ||
} | ||
} | ||
this.el.addEventListener(event, delegator.handler) | ||
CompilerProto.resolveComponent = function (node, data, test) { | ||
// late require to avoid circular deps | ||
ViewModel = ViewModel || require('./viewmodel') | ||
var exp = utils.attr(node, 'component'), | ||
tagName = node.tagName, | ||
id = this.eval(exp, data), | ||
tagId = (tagName.indexOf('-') > 0 && tagName.toLowerCase()), | ||
Ctor = this.getOption('components', id || tagId) | ||
if (id && !Ctor) { | ||
utils.warn('Unknown component: ' + id) | ||
} | ||
delegator.targets.push(listener) | ||
} | ||
/** | ||
* Remove an event delegation listener | ||
*/ | ||
CompilerProto.removeListener = function (listener) { | ||
var targets = this.delegators[listener.arg].targets | ||
targets.splice(targets.indexOf(listener), 1) | ||
return test | ||
? exp === '' | ||
? ViewModel | ||
: Ctor | ||
: Ctor || ViewModel | ||
} | ||
@@ -848,5 +950,4 @@ | ||
directives = compiler.dirs, | ||
exps = compiler.exps, | ||
computed = compiler.computed, | ||
bindings = compiler.bindings, | ||
delegators = compiler.delegators, | ||
children = compiler.children, | ||
@@ -875,9 +976,9 @@ parent = compiler.parent | ||
// unbind all expressions (anonymous bindings) | ||
i = exps.length | ||
// unbind all computed, anonymous bindings | ||
i = computed.length | ||
while (i--) { | ||
exps[i].unbind() | ||
computed[i].unbind() | ||
} | ||
// unbind all own bindings | ||
// unbind all keypath bindings | ||
for (key in bindings) { | ||
@@ -890,7 +991,2 @@ binding = bindings[key] | ||
// remove all event delegators | ||
for (key in delegators) { | ||
el.removeEventListener(key, delegators[key].handler) | ||
} | ||
// destroy all children | ||
@@ -905,5 +1001,2 @@ i = children.length | ||
parent.children.splice(parent.children.indexOf(compiler), 1) | ||
if (compiler.childId) { | ||
delete parent.vm.$[compiler.childId] | ||
} | ||
} | ||
@@ -919,3 +1012,3 @@ | ||
this.destroyed = true | ||
compiler.destroyed = true | ||
// emit destroy hook | ||
@@ -941,9 +1034,2 @@ compiler.execHook('afterDestroy') | ||
/** | ||
* for convenience & minification | ||
*/ | ||
function defGetSet (obj, key, def) { | ||
Object.defineProperty(obj, key, def) | ||
} | ||
module.exports = Compiler |
@@ -1,39 +0,19 @@ | ||
var prefix = 'v', | ||
specialAttributes = [ | ||
'pre', | ||
'ref', | ||
'with', | ||
'text', | ||
'repeat', | ||
'partial', | ||
'component', | ||
'animation', | ||
'transition', | ||
'effect' | ||
], | ||
config = module.exports = { | ||
var TextParser = require('./text-parser') | ||
debug : false, | ||
silent : false, | ||
enterClass : 'v-enter', | ||
leaveClass : 'v-leave', | ||
interpolate : true, | ||
attrs : {}, | ||
module.exports = { | ||
prefix : 'v', | ||
debug : false, | ||
silent : false, | ||
enterClass : 'v-enter', | ||
leaveClass : 'v-leave', | ||
interpolate : true | ||
} | ||
get prefix () { | ||
return prefix | ||
}, | ||
set prefix (val) { | ||
prefix = val | ||
updatePrefix() | ||
} | ||
Object.defineProperty(module.exports, 'delimiters', { | ||
get: function () { | ||
return TextParser.delimiters | ||
}, | ||
set: function (delimiters) { | ||
TextParser.setDelimiters(delimiters) | ||
} | ||
function updatePrefix () { | ||
specialAttributes.forEach(function (attr) { | ||
config.attrs[attr] = prefix + '-' + attr | ||
}) | ||
} | ||
updatePrefix() | ||
}) |
@@ -17,3 +17,11 @@ var Emitter = require('./emitter'), | ||
var has = got[dep.key] | ||
if (has && has.compiler === dep.compiler) return | ||
if ( | ||
// avoid duplicate bindings | ||
(has && has.compiler === dep.compiler) || | ||
// avoid repeated items as dependency | ||
// since all inside changes trigger array change too | ||
(dep.compiler.repeat && dep.compiler.parent === binding.compiler) | ||
) { | ||
return | ||
} | ||
got[dep.key] = dep | ||
@@ -20,0 +28,0 @@ utils.log(' - ' + dep.key) |
var utils = require('./utils'), | ||
directives = require('./directives'), | ||
filters = require('./filters'), | ||
dirId = 1, | ||
@@ -16,3 +16,3 @@ // Regexes! | ||
FILTERS_RE = /\|[^\|]+/g, | ||
FILTER_TOKEN_RE = /[^\s']+|'[^']+'/g, | ||
FILTER_TOKEN_RE = /[^\s']+|'[^']+'|[^\s"]+|"[^"]+"/g, | ||
NESTING_RE = /^\$(parent|root)\./, | ||
@@ -25,7 +25,10 @@ SINGLE_VAR_RE = /^[\w\.$]+$/ | ||
*/ | ||
function Directive (definition, expression, rawKey, compiler, node) { | ||
function Directive (dirname, definition, expression, rawKey, compiler, node) { | ||
this.compiler = compiler | ||
this.vm = compiler.vm | ||
this.el = node | ||
this.id = dirId++ | ||
this.name = dirname | ||
this.compiler = compiler | ||
this.vm = compiler.vm | ||
this.el = node | ||
this.computeFilters = false | ||
@@ -53,8 +56,9 @@ var isEmpty = expression === '' | ||
this.expression = expression.trim() | ||
this.rawKey = rawKey | ||
this.expression = ( | ||
this.isLiteral | ||
? compiler.eval(expression) | ||
: expression | ||
).trim() | ||
parseKey(this, rawKey) | ||
this.isExp = !SINGLE_VAR_RE.test(this.key) || NESTING_RE.test(this.key) | ||
@@ -66,3 +70,11 @@ var filterExps = this.expression.slice(rawKey.length).match(FILTERS_RE) | ||
filter = parseFilter(filterExps[i], this.compiler) | ||
if (filter) this.filters.push(filter) | ||
if (filter) { | ||
this.filters.push(filter) | ||
if (filter.apply.computed) { | ||
// some special filters, e.g. filterBy & orderBy, | ||
// can involve VM properties and they often need to | ||
// be computed. | ||
this.computeFilters = true | ||
} | ||
} | ||
} | ||
@@ -73,2 +85,8 @@ if (!this.filters.length) this.filters = null | ||
} | ||
this.isExp = | ||
this.computeFilters || | ||
!SINGLE_VAR_RE.test(this.key) || | ||
NESTING_RE.test(this.key) | ||
} | ||
@@ -102,8 +120,5 @@ | ||
if (!tokens) return | ||
tokens = tokens.map(function (token) { | ||
return token.replace(/'/g, '').trim() | ||
}) | ||
var name = tokens[0], | ||
apply = compiler.getOption('filters', name) || filters[name] | ||
apply = compiler.getOption('filters', name) | ||
if (!apply) { | ||
@@ -129,8 +144,7 @@ utils.warn('Unknown filter: ' + name) | ||
DirProto.update = function (value, init) { | ||
var type = utils.typeOf(value) | ||
if (init || value !== this.value || type === 'Object' || type === 'Array') { | ||
if (init || value !== this.value || (value && typeof value === 'object')) { | ||
this.value = value | ||
if (this._update) { | ||
this._update( | ||
this.filters | ||
this.filters && !this.computeFilters | ||
? this.applyFilters(value) | ||
@@ -151,3 +165,3 @@ : value, | ||
filter = this.filters[i] | ||
filtered = filter.apply.call(this.vm, filtered, filter.args) | ||
filtered = filter.apply.apply(this.vm, [filtered].concat(filter.args)) | ||
} | ||
@@ -186,3 +200,6 @@ return filtered | ||
var dir = compiler.getOption('directives', dirname) || directives[dirname] | ||
if (!dir) return utils.warn('unknown directive: ' + dirname) | ||
if (!dir) { | ||
utils.warn('Unknown directive: ' + dirname) | ||
return | ||
} | ||
@@ -200,7 +217,9 @@ var rawKey | ||
// have a valid raw key, or be an empty directive | ||
return (rawKey || expression === '') | ||
? new Directive(dir, expression, rawKey, compiler, node) | ||
: utils.warn('invalid directive expression: ' + expression) | ||
if (rawKey || expression === '') { | ||
return new Directive(dirname, dir, expression, rawKey, compiler, node) | ||
} else { | ||
utils.warn('Invalid directive expression: ' + expression) | ||
} | ||
} | ||
module.exports = Directive |
@@ -1,4 +0,7 @@ | ||
var toText = require('../utils').toText, | ||
var guard = require('../utils').guard, | ||
slice = [].slice | ||
/** | ||
* Binding for innerHTML | ||
*/ | ||
module.exports = { | ||
@@ -17,3 +20,3 @@ | ||
update: function (value) { | ||
value = toText(value) | ||
value = guard(value) | ||
if (this.holder) { | ||
@@ -20,0 +23,0 @@ this.swap(value) |
@@ -1,14 +0,30 @@ | ||
var config = require('../config'), | ||
transition = require('../transition') | ||
var utils = require('../utils') | ||
/** | ||
* Manages a conditional child VM | ||
*/ | ||
module.exports = { | ||
bind: function () { | ||
this.parent = this.el.parentNode || this.el.vue_if_parent | ||
this.ref = document.createComment(config.prefix + '-if-' + this.key) | ||
var detachedRef = this.el.vue_if_ref | ||
if (detachedRef) { | ||
this.parent.insertBefore(this.ref, detachedRef) | ||
this.parent = this.el.parentNode | ||
this.ref = document.createComment('vue-if') | ||
this.Ctor = this.compiler.resolveComponent(this.el) | ||
// insert ref | ||
this.parent.insertBefore(this.ref, this.el) | ||
this.parent.removeChild(this.el) | ||
if (utils.attr(this.el, 'view')) { | ||
utils.warn( | ||
'Conflict: v-if cannot be used together with v-view. ' + | ||
'Just set v-view\'s binding value to empty string to empty it.' | ||
) | ||
} | ||
this.el.vue_if_ref = this.ref | ||
if (utils.attr(this.el, 'repeat')) { | ||
utils.warn( | ||
'Conflict: v-if cannot be used together with v-repeat. ' + | ||
'Use `v-show` or the `filterBy` filter instead.' | ||
) | ||
} | ||
}, | ||
@@ -18,53 +34,24 @@ | ||
var el = this.el | ||
// sometimes we need to create a VM on a detached node, | ||
// e.g. in v-repeat. In that case, store the desired v-if | ||
// state on the node itself so we can deal with it elsewhere. | ||
el.vue_if = !!value | ||
var parent = this.parent, | ||
ref = this.ref, | ||
compiler = this.compiler | ||
if (!parent) { | ||
if (!el.parentNode) { | ||
return | ||
} else { | ||
parent = this.parent = el.parentNode | ||
} | ||
} | ||
if (!value) { | ||
transition(el, -1, remove, compiler) | ||
} else { | ||
transition(el, 1, insert, compiler) | ||
} | ||
function remove () { | ||
if (!el.parentNode) return | ||
// insert the reference node | ||
var next = el.nextSibling | ||
if (next) { | ||
parent.insertBefore(ref, next) | ||
this._unbind() | ||
} else if (!this.childVM) { | ||
this.childVM = new this.Ctor({ | ||
el: this.el.cloneNode(true), | ||
parent: this.vm | ||
}) | ||
if (this.compiler.init) { | ||
this.parent.insertBefore(this.childVM.$el, this.ref) | ||
} else { | ||
parent.appendChild(ref) | ||
this.childVM.$before(this.ref) | ||
} | ||
parent.removeChild(el) | ||
} | ||
function insert () { | ||
if (el.parentNode) return | ||
parent.insertBefore(el, ref) | ||
parent.removeChild(ref) | ||
} | ||
}, | ||
unbind: function () { | ||
this.el.vue_if_ref = this.el.vue_if_parent = null | ||
var ref = this.ref | ||
if (ref.parentNode) { | ||
ref.parentNode.removeChild(ref) | ||
if (this.childVM) { | ||
this.childVM.$destroy() | ||
this.childVM = null | ||
} | ||
} | ||
} |
var utils = require('../utils'), | ||
config = require('../config'), | ||
transition = require('../transition') | ||
transition = require('../transition'), | ||
directives = module.exports = utils.hash() | ||
module.exports = { | ||
/** | ||
* Nest and manage a Child VM | ||
*/ | ||
directives.component = { | ||
isLiteral: true, | ||
bind: function () { | ||
if (!this.el.vue_vm) { | ||
this.childVM = new this.Ctor({ | ||
el: this.el, | ||
parent: this.vm | ||
}) | ||
} | ||
}, | ||
unbind: function () { | ||
if (this.childVM) { | ||
this.childVM.$destroy() | ||
} | ||
} | ||
} | ||
on : require('./on'), | ||
repeat : require('./repeat'), | ||
model : require('./model'), | ||
'if' : require('./if'), | ||
'with' : require('./with'), | ||
html : require('./html'), | ||
style : require('./style'), | ||
attr: function (value) { | ||
/** | ||
* Binding HTML attributes | ||
*/ | ||
directives.attr = { | ||
bind: function () { | ||
var params = this.vm.$options.paramAttributes | ||
this.isParam = params && params.indexOf(this.arg) > -1 | ||
}, | ||
update: function (value) { | ||
if (value || value === 0) { | ||
@@ -21,41 +40,91 @@ this.el.setAttribute(this.arg, value) | ||
} | ||
}, | ||
if (this.isParam) { | ||
this.vm[this.arg] = utils.checkNumber(value) | ||
} | ||
} | ||
} | ||
text: function (value) { | ||
this.el.textContent = utils.toText(value) | ||
/** | ||
* Binding textContent | ||
*/ | ||
directives.text = { | ||
bind: function () { | ||
this.attr = this.el.nodeType === 3 | ||
? 'nodeValue' | ||
: 'textContent' | ||
}, | ||
update: function (value) { | ||
this.el[this.attr] = utils.guard(value) | ||
} | ||
} | ||
show: function (value) { | ||
var el = this.el, | ||
target = value ? '' : 'none', | ||
change = function () { | ||
el.style.display = target | ||
} | ||
transition(el, value ? 1 : -1, change, this.compiler) | ||
}, | ||
/** | ||
* Binding CSS display property | ||
*/ | ||
directives.show = function (value) { | ||
var el = this.el, | ||
target = value ? '' : 'none', | ||
change = function () { | ||
el.style.display = target | ||
} | ||
transition(el, value ? 1 : -1, change, this.compiler) | ||
} | ||
'class': function (value) { | ||
if (this.arg) { | ||
utils[value ? 'addClass' : 'removeClass'](this.el, this.arg) | ||
} else { | ||
if (this.lastVal) { | ||
utils.removeClass(this.el, this.lastVal) | ||
} | ||
if (value) { | ||
utils.addClass(this.el, value) | ||
this.lastVal = value | ||
} | ||
/** | ||
* Binding CSS classes | ||
*/ | ||
directives['class'] = function (value) { | ||
if (this.arg) { | ||
utils[value ? 'addClass' : 'removeClass'](this.el, this.arg) | ||
} else { | ||
if (this.lastVal) { | ||
utils.removeClass(this.el, this.lastVal) | ||
} | ||
}, | ||
if (value) { | ||
utils.addClass(this.el, value) | ||
this.lastVal = value | ||
} | ||
} | ||
} | ||
cloak: { | ||
isEmpty: true, | ||
bind: function () { | ||
var el = this.el | ||
this.compiler.observer.once('hook:ready', function () { | ||
el.removeAttribute(config.prefix + '-cloak') | ||
}) | ||
/** | ||
* Only removed after the owner VM is ready | ||
*/ | ||
directives.cloak = { | ||
isEmpty: true, | ||
bind: function () { | ||
var el = this.el | ||
this.compiler.observer.once('hook:ready', function () { | ||
el.removeAttribute(config.prefix + '-cloak') | ||
}) | ||
} | ||
} | ||
/** | ||
* Store a reference to self in parent VM's $ | ||
*/ | ||
directives.ref = { | ||
isLiteral: true, | ||
bind: function () { | ||
var id = this.expression | ||
if (id) { | ||
this.vm.$parent.$[id] = this.vm | ||
} | ||
}, | ||
unbind: function () { | ||
var id = this.expression | ||
if (id) { | ||
delete this.vm.$parent.$[id] | ||
} | ||
} | ||
} | ||
} | ||
directives.on = require('./on') | ||
directives.repeat = require('./repeat') | ||
directives.model = require('./model') | ||
directives['if'] = require('./if') | ||
directives['with'] = require('./with') | ||
directives.html = require('./html') | ||
directives.style = require('./style') | ||
directives.partial = require('./partial') | ||
directives.view = require('./view') |
@@ -18,2 +18,5 @@ var utils = require('../utils'), | ||
/** | ||
* Two-way binding for form input elements | ||
*/ | ||
module.exports = { | ||
@@ -144,3 +147,3 @@ | ||
} else { | ||
el[this.attr] = utils.toText(value) | ||
el[this.attr] = utils.guard(value) | ||
} | ||
@@ -147,0 +150,0 @@ }, |
@@ -1,3 +0,6 @@ | ||
var warn = require('../utils').warn | ||
var utils = require('../utils') | ||
/** | ||
* Binding for event listeners | ||
*/ | ||
module.exports = { | ||
@@ -8,8 +11,5 @@ | ||
bind: function () { | ||
// blur and focus events do not bubble | ||
// so they can't be delegated | ||
this.bubbles = this.arg !== 'blur' && this.arg !== 'focus' | ||
if (this.bubbles) { | ||
this.binding.compiler.addListener(this) | ||
} | ||
this.context = this.binding.isExp | ||
? this.vm | ||
: this.binding.compiler.vm | ||
}, | ||
@@ -19,29 +19,21 @@ | ||
if (typeof handler !== 'function') { | ||
return warn('Directive "on" expects a function value.') | ||
utils.warn('Directive "v-on:' + this.expression + '" expects a method.') | ||
return | ||
} | ||
var targetVM = this.vm, | ||
ownerVM = this.binding.compiler.vm, | ||
isExp = this.binding.isExp, | ||
newHandler = function (e) { | ||
e.targetVM = targetVM | ||
handler.call(isExp ? targetVM : ownerVM, e) | ||
} | ||
if (!this.bubbles) { | ||
this.reset() | ||
this.el.addEventListener(this.arg, newHandler) | ||
this._unbind() | ||
var vm = this.vm, | ||
context = this.context | ||
this.handler = function (e) { | ||
e.targetVM = vm | ||
context.$event = e | ||
var res = handler.call(context, e) | ||
context.$event = null | ||
return res | ||
} | ||
this.handler = newHandler | ||
this.el.addEventListener(this.arg, this.handler) | ||
}, | ||
reset: function () { | ||
unbind: function () { | ||
this.el.removeEventListener(this.arg, this.handler) | ||
}, | ||
unbind: function () { | ||
if (this.bubbles) { | ||
this.binding.compiler.removeListener(this) | ||
} else { | ||
this.reset() | ||
} | ||
} | ||
} |
@@ -1,84 +0,22 @@ | ||
var Observer = require('../observer'), | ||
utils = require('../utils'), | ||
config = require('../config'), | ||
def = utils.defProtected, | ||
ViewModel // lazy def to avoid circular dependency | ||
var utils = require('../utils'), | ||
config = require('../config') | ||
/** | ||
* Mathods that perform precise DOM manipulation | ||
* based on mutator method triggered | ||
* Binding that manages VMs based on an Array | ||
*/ | ||
var mutationHandlers = { | ||
module.exports = { | ||
push: function (m) { | ||
this.addItems(m.args, this.vms.length) | ||
}, | ||
bind: function () { | ||
pop: function () { | ||
var vm = this.vms.pop() | ||
if (vm) this.removeItems([vm]) | ||
}, | ||
this.identifier = '$r' + this.id | ||
unshift: function (m) { | ||
this.addItems(m.args) | ||
}, | ||
// a hash to cache the same expressions on repeated instances | ||
// so they don't have to be compiled for every single instance | ||
this.expCache = utils.hash() | ||
shift: function () { | ||
var vm = this.vms.shift() | ||
if (vm) this.removeItems([vm]) | ||
}, | ||
splice: function (m) { | ||
var index = m.args[0], | ||
removed = m.args[1], | ||
removedVMs = removed === undefined | ||
? this.vms.splice(index) | ||
: this.vms.splice(index, removed) | ||
this.removeItems(removedVMs) | ||
this.addItems(m.args.slice(2), index) | ||
}, | ||
sort: function () { | ||
var vms = this.vms, | ||
col = this.collection, | ||
l = col.length, | ||
sorted = new Array(l), | ||
i, j, vm, data | ||
for (i = 0; i < l; i++) { | ||
data = col[i] | ||
for (j = 0; j < l; j++) { | ||
vm = vms[j] | ||
if (vm.$data === data) { | ||
sorted[i] = vm | ||
break | ||
} | ||
} | ||
} | ||
for (i = 0; i < l; i++) { | ||
this.container.insertBefore(sorted[i].$el, this.ref) | ||
} | ||
this.vms = sorted | ||
}, | ||
reverse: function () { | ||
var vms = this.vms | ||
vms.reverse() | ||
for (var i = 0, l = vms.length; i < l; i++) { | ||
this.container.insertBefore(vms[i].$el, this.ref) | ||
} | ||
} | ||
} | ||
module.exports = { | ||
bind: function () { | ||
var el = this.el, | ||
ctn = this.container = el.parentNode | ||
// extract child VM information, if any | ||
ViewModel = ViewModel || require('../viewmodel') | ||
this.Ctor = this.Ctor || ViewModel | ||
// extract child Id, if any | ||
this.childId = utils.attr(el, 'ref') | ||
this.childId = this.compiler.eval(utils.attr(el, 'ref')) | ||
@@ -94,33 +32,14 @@ // create a comment node as a reference node for DOM insertions | ||
var self = this | ||
this.mutationListener = function (path, arr, mutation) { | ||
var method = mutation.method | ||
mutationHandlers[method].call(self, mutation) | ||
if (method !== 'push' && method !== 'pop') { | ||
// update index | ||
var i = arr.length | ||
while (i--) { | ||
self.vms[i].$index = i | ||
} | ||
} | ||
if (method === 'push' || method === 'unshift' || method === 'splice') { | ||
// recalculate dependency | ||
self.changed() | ||
} | ||
} | ||
}, | ||
update: function (collection, init) { | ||
update: function (collection) { | ||
if ( | ||
collection === this.collection || | ||
collection === this.object | ||
) return | ||
if (utils.typeOf(collection) === 'Object') { | ||
collection = this.convertObject(collection) | ||
if (!Array.isArray(collection)) { | ||
if (utils.isObject(collection)) { | ||
collection = utils.objectToArray(collection) | ||
} else { | ||
utils.warn('v-repeat only accepts Array or Object values.') | ||
} | ||
} | ||
this.reset() | ||
// if initiating with an empty collection, we need to | ||
@@ -135,7 +54,11 @@ // force a compile so that we get all the bindings for | ||
// so we can reuse them if possible | ||
this.old = this.collection | ||
var oldVMs = this.oldVMs = this.vms | ||
this.oldVMs = this.vms | ||
this.oldCollection = this.collection | ||
collection = this.collection = collection || [] | ||
collection = this.collection = collection || [] | ||
this.vms = [] | ||
var isObject = collection[0] && utils.isObject(collection[0]) | ||
this.vms = this.oldCollection | ||
? this.diff(collection, isObject) | ||
: this.init(collection, isObject) | ||
if (this.childId) { | ||
@@ -145,63 +68,17 @@ this.vm.$[this.childId] = this.vms | ||
// If the collection is not already converted for observation, | ||
// we need to convert and watch it. | ||
if (!Observer.convert(collection)) { | ||
Observer.watch(collection) | ||
} | ||
// listen for collection mutation events | ||
collection.__emitter__.on('mutate', this.mutationListener) | ||
// create new VMs and append to DOM | ||
if (collection.length) { | ||
collection.forEach(this.build, this) | ||
if (!init) this.changed() | ||
} | ||
// destroy unused old VMs | ||
if (oldVMs) destroyVMs(oldVMs) | ||
this.old = this.oldVMs = null | ||
}, | ||
addItems: function (data, base) { | ||
base = base || 0 | ||
for (var i = 0, l = data.length; i < l; i++) { | ||
var vm = this.build(data[i], base + i) | ||
this.updateObject(vm, 1) | ||
} | ||
}, | ||
removeItems: function (data) { | ||
var i = data.length | ||
while (i--) { | ||
data[i].$destroy() | ||
this.updateObject(data[i], -1) | ||
} | ||
}, | ||
/** | ||
* Notify parent compiler that new items | ||
* have been added to the collection, it needs | ||
* to re-calculate computed property dependencies. | ||
* Batched to ensure it's called only once every event loop. | ||
*/ | ||
changed: function () { | ||
if (this.queued) return | ||
this.queued = true | ||
var self = this | ||
utils.nextTick(function () { | ||
if (!self.compiler) return | ||
self.compiler.parseDeps() | ||
self.queued = false | ||
}) | ||
}, | ||
/** | ||
* Run a dry build just to collect bindings | ||
*/ | ||
dryBuild: function () { | ||
new this.Ctor({ | ||
el : this.el.cloneNode(true), | ||
var el = this.el.cloneNode(true), | ||
Ctor = this.compiler.resolveComponent(el) | ||
new Ctor({ | ||
el : el, | ||
parent : this.vm, | ||
data : { $index: 0 }, | ||
compilerOptions: { | ||
repeat: true | ||
repeat: true, | ||
expCache: this.expCache | ||
} | ||
@@ -212,179 +89,175 @@ }).$destroy() | ||
init: function (collection, isObject) { | ||
var vm, vms = [] | ||
for (var i = 0, l = collection.length; i < l; i++) { | ||
vm = this.build(collection[i], i, isObject) | ||
vms.push(vm) | ||
if (this.compiler.init) { | ||
this.container.insertBefore(vm.$el, this.ref) | ||
} else { | ||
vm.$before(this.ref) | ||
} | ||
} | ||
return vms | ||
}, | ||
/** | ||
* Create a new child VM from a data object | ||
* passing along compiler options indicating this | ||
* is a v-repeat item. | ||
* Diff the new array with the old | ||
* and determine the minimum amount of DOM manipulations. | ||
*/ | ||
build: function (data, index) { | ||
diff: function (newCollection, isObject) { | ||
var ctn = this.container, | ||
vms = this.vms, | ||
col = this.collection, | ||
el, oldIndex, existing, item, nonObject | ||
var i, l, item, vm, | ||
oldIndex, | ||
targetNext, | ||
currentNext, | ||
nextEl, | ||
ctn = this.container, | ||
oldVMs = this.oldVMs, | ||
vms = [] | ||
// get our DOM insertion reference node | ||
var ref = vms.length > index | ||
? vms[index].$el | ||
: this.ref | ||
// if reference VM is detached by v-if, | ||
// use its v-if ref node instead | ||
if (!ref.parentNode) { | ||
ref = ref.vue_if_ref | ||
vms.length = newCollection.length | ||
// first pass, collect new reused and new created | ||
for (i = 0, l = newCollection.length; i < l; i++) { | ||
item = newCollection[i] | ||
if (isObject) { | ||
item.$index = i | ||
if (item.__emitter__ && item.__emitter__[this.identifier]) { | ||
// this piece of data is being reused. | ||
// record its final position in reused vms | ||
item.$reused = true | ||
} else { | ||
vms[i] = this.build(item, i, isObject) | ||
} | ||
} else { | ||
// we can't attach an identifier to primitive values | ||
// so have to do an indexOf... | ||
oldIndex = indexOf(oldVMs, item) | ||
if (oldIndex > -1) { | ||
// record the position on the existing vm | ||
oldVMs[oldIndex].$reused = true | ||
oldVMs[oldIndex].$data.$index = i | ||
} else { | ||
vms[i] = this.build(item, i, isObject) | ||
} | ||
} | ||
} | ||
// check if data already exists in the old array | ||
oldIndex = this.old ? indexOf(this.old, data) : -1 | ||
existing = oldIndex > -1 | ||
if (existing) { | ||
// existing, reuse the old VM | ||
item = this.oldVMs[oldIndex] | ||
// mark, so it won't be destroyed | ||
item.$reused = true | ||
} else { | ||
// new data, need to create new VM. | ||
// there's some preparation work to do... | ||
// first clone the template node | ||
el = this.el.cloneNode(true) | ||
// then we provide the parentNode for v-if | ||
// so that it can still work in a detached state | ||
el.vue_if_parent = ctn | ||
el.vue_if_ref = ref | ||
// wrap non-object value in an object | ||
nonObject = utils.typeOf(data) !== 'Object' | ||
if (nonObject) { | ||
data = { $value: data } | ||
// second pass, collect old reused and destroy unused | ||
for (i = 0, l = oldVMs.length; i < l; i++) { | ||
vm = oldVMs[i] | ||
item = vm.$data | ||
if (item.$reused) { | ||
vm.$reused = true | ||
delete item.$reused | ||
} | ||
// set index so vm can init with the correct | ||
// index instead of undefined | ||
data.$index = index | ||
// initialize the new VM | ||
item = new this.Ctor({ | ||
el : el, | ||
data : data, | ||
parent : this.vm, | ||
compilerOptions: { | ||
repeat: true | ||
if (vm.$reused) { | ||
// update the index to latest | ||
vm.$index = item.$index | ||
// the item could have had a new key | ||
if (item.$key && item.$key !== vm.$key) { | ||
vm.$key = item.$key | ||
} | ||
}) | ||
// for non-object values, listen for value change | ||
// so we can sync it back to the original Array | ||
if (nonObject) { | ||
item.$compiler.observer.on('set', function (key, val) { | ||
if (key === '$value') { | ||
col[item.$index] = val | ||
} | ||
}) | ||
vms[vm.$index] = vm | ||
} else { | ||
// this one can be destroyed. | ||
delete item.__emitter__[this.identifier] | ||
vm.$destroy() | ||
} | ||
} | ||
// put the item into the VM Array | ||
vms.splice(index, 0, item) | ||
// update the index | ||
item.$index = index | ||
// Finally, DOM operations... | ||
el = item.$el | ||
if (existing) { | ||
// we simplify need to re-insert the existing node | ||
// to its new position. However, it can possibly be | ||
// detached by v-if. in that case we insert its v-if | ||
// ref node instead. | ||
ctn.insertBefore(el.parentNode ? el : el.vue_if_ref, ref) | ||
} else { | ||
if (el.vue_if !== false) { | ||
if (this.compiler.init) { | ||
// do not transition on initial compile, | ||
// just manually insert. | ||
ctn.insertBefore(el, ref) | ||
item.$compiler.execHook('attached') | ||
} else { | ||
// give it some nice transition. | ||
item.$before(ref) | ||
// final pass, move/insert DOM elements | ||
i = vms.length | ||
while (i--) { | ||
vm = vms[i] | ||
item = vm.$data | ||
targetNext = vms[i + 1] | ||
if (vm.$reused) { | ||
nextEl = vm.$el.nextSibling | ||
// destroyed VMs' element might still be in the DOM | ||
// due to transitions | ||
while (!nextEl.vue_vm && nextEl !== this.ref) { | ||
nextEl = nextEl.nextSibling | ||
} | ||
currentNext = nextEl.vue_vm | ||
if (currentNext !== targetNext) { | ||
if (!targetNext) { | ||
ctn.insertBefore(vm.$el, this.ref) | ||
} else { | ||
nextEl = targetNext.$el | ||
// new VMs' element might not be in the DOM yet | ||
// due to transitions | ||
while (!nextEl.parentNode) { | ||
targetNext = vms[nextEl.vue_vm.$index + 1] | ||
nextEl = targetNext | ||
? targetNext.$el | ||
: this.ref | ||
} | ||
ctn.insertBefore(vm.$el, nextEl) | ||
} | ||
} | ||
delete vm.$reused | ||
delete item.$index | ||
delete item.$key | ||
} else { // a new vm | ||
vm.$before(targetNext ? targetNext.$el : this.ref) | ||
} | ||
} | ||
return item | ||
return vms | ||
}, | ||
/** | ||
* Convert an object to a repeater Array | ||
* and make sure changes in the object are synced to the repeater | ||
*/ | ||
convertObject: function (object) { | ||
build: function (data, index, isObject) { | ||
if (this.object) { | ||
this.object.__emitter__.off('set', this.updateRepeater) | ||
// wrap non-object values | ||
var raw, alias, | ||
wrap = !isObject || this.arg | ||
if (wrap) { | ||
raw = data | ||
alias = this.arg || '$value' | ||
data = {} | ||
data[alias] = raw | ||
} | ||
data.$index = index | ||
this.object = object | ||
var collection = object.$repeater || objectToArray(object) | ||
if (!object.$repeater) { | ||
def(object, '$repeater', collection) | ||
} | ||
var el = this.el.cloneNode(true), | ||
Ctor = this.compiler.resolveComponent(el, data), | ||
vm = new Ctor({ | ||
el: el, | ||
data: data, | ||
parent: this.vm, | ||
compilerOptions: { | ||
repeat: true, | ||
expCache: this.expCache | ||
} | ||
}) | ||
var self = this | ||
this.updateRepeater = function (key, val) { | ||
if (key.indexOf('.') === -1) { | ||
var i = self.vms.length, item | ||
while (i--) { | ||
item = self.vms[i] | ||
if (item.$key === key) { | ||
if (item.$data !== val && item.$value !== val) { | ||
if ('$value' in item) { | ||
item.$value = val | ||
} else { | ||
item.$data = val | ||
} | ||
} | ||
break | ||
} | ||
// attach an ienumerable identifier | ||
data.__emitter__[this.identifier] = true | ||
if (wrap) { | ||
var self = this, | ||
sync = function (val) { | ||
self.lock = true | ||
self.collection.$set(vm.$index, val) | ||
self.lock = false | ||
} | ||
} | ||
vm.$compiler.observer.on('change:' + alias, sync) | ||
} | ||
object.__emitter__.on('set', this.updateRepeater) | ||
return collection | ||
}, | ||
return vm | ||
/** | ||
* Sync changes from the $repeater Array | ||
* back to the represented Object | ||
*/ | ||
updateObject: function (vm, action) { | ||
var obj = this.object | ||
if (obj && vm.$key) { | ||
var key = vm.$key, | ||
val = vm.$value || vm.$data | ||
if (action > 0) { // new property | ||
obj[key] = val | ||
Observer.convertKey(obj, key) | ||
} else { | ||
delete obj[key] | ||
} | ||
obj.__emitter__.emit('set', key, val, true) | ||
} | ||
}, | ||
reset: function (destroy) { | ||
unbind: function () { | ||
if (this.childId) { | ||
delete this.vm.$[this.childId] | ||
} | ||
if (this.collection) { | ||
this.collection.__emitter__.off('mutate', this.mutationListener) | ||
if (destroy) { | ||
destroyVMs(this.vms) | ||
if (this.vms) { | ||
var i = this.vms.length | ||
while (i--) { | ||
this.vms[i].$destroy() | ||
} | ||
} | ||
}, | ||
unbind: function () { | ||
this.reset(true) | ||
} | ||
@@ -396,24 +269,9 @@ } | ||
/** | ||
* Convert an Object to a v-repeat friendly Array | ||
*/ | ||
function objectToArray (obj) { | ||
var res = [], val, data | ||
for (var key in obj) { | ||
val = obj[key] | ||
data = utils.typeOf(val) === 'Object' | ||
? val | ||
: { $value: val } | ||
def(data, '$key', key) | ||
res.push(data) | ||
} | ||
return res | ||
} | ||
/** | ||
* Find an object or a wrapped data object | ||
* from an Array | ||
*/ | ||
function indexOf (arr, obj) { | ||
for (var i = 0, l = arr.length; i < l; i++) { | ||
if (arr[i] === obj || (obj.$value && arr[i].$value === obj.$value)) { | ||
function indexOf (vms, obj) { | ||
for (var vm, i = 0, l = vms.length; i < l; i++) { | ||
vm = vms[i] | ||
if (!vm.$reused && vm.$value === obj) { | ||
return i | ||
@@ -423,17 +281,2 @@ } | ||
return -1 | ||
} | ||
/** | ||
* Destroy some VMs, yeah. | ||
*/ | ||
function destroyVMs (vms) { | ||
var i = vms.length, vm | ||
while (i--) { | ||
vm = vms[i] | ||
if (vm.$reused) { | ||
vm.$reused = false | ||
} else { | ||
vm.$destroy() | ||
} | ||
} | ||
} |
@@ -8,2 +8,5 @@ var camelRE = /-([a-z])/g, | ||
/** | ||
* Binding for CSS styles | ||
*/ | ||
module.exports = { | ||
@@ -10,0 +13,0 @@ |
@@ -1,88 +0,50 @@ | ||
var ViewModel, | ||
nextTick = require('../utils').nextTick | ||
var utils = require('../utils') | ||
/** | ||
* Binding for inheriting data from parent VMs. | ||
*/ | ||
module.exports = { | ||
bind: function () { | ||
if (this.el.vue_vm) { | ||
this.subVM = this.el.vue_vm | ||
var compiler = this.subVM.$compiler | ||
if (!compiler.bindings[this.arg]) { | ||
compiler.createBinding(this.arg) | ||
} | ||
} else if (this.isEmpty) { | ||
this.build() | ||
var self = this, | ||
childKey = self.arg, | ||
parentKey = self.key, | ||
compiler = self.compiler, | ||
owner = self.binding.compiler | ||
if (compiler === owner) { | ||
this.alone = true | ||
return | ||
} | ||
}, | ||
update: function (value, init) { | ||
var vm = this.subVM, | ||
key = this.arg || '$data' | ||
if (!vm) { | ||
this.build(value) | ||
} else if (!this.lock && vm[key] !== value) { | ||
vm[key] = value | ||
} | ||
if (init) { | ||
// watch after first set | ||
this.watch() | ||
// The v-with directive can have multiple expressions, | ||
// and we want to make sure when the ready hook is called | ||
// on the subVM, all these clauses have been properly set up. | ||
// So this is a hack that sniffs whether we have reached | ||
// the last expression. We hold off the subVM's ready hook | ||
// until we are actually ready. | ||
if (this.last) { | ||
this.subVM.$compiler.execHook('ready') | ||
if (childKey) { | ||
if (!compiler.bindings[childKey]) { | ||
compiler.createBinding(childKey) | ||
} | ||
// sync changes on child back to parent | ||
compiler.observer.on('change:' + childKey, function (val) { | ||
if (compiler.init) return | ||
if (!self.lock) { | ||
self.lock = true | ||
utils.nextTick(function () { | ||
self.lock = false | ||
}) | ||
} | ||
owner.vm.$set(parentKey, val) | ||
}) | ||
} | ||
}, | ||
build: function (value) { | ||
ViewModel = ViewModel || require('../viewmodel') | ||
var Ctor = this.Ctor || ViewModel, | ||
data = value | ||
if (this.arg) { | ||
data = {} | ||
data[this.arg] = value | ||
update: function (value) { | ||
// sync from parent | ||
if (!this.alone && !this.lock) { | ||
if (this.arg) { | ||
this.vm.$set(this.arg, value) | ||
} else { | ||
this.vm.$data = value | ||
} | ||
} | ||
this.subVM = new Ctor({ | ||
el : this.el, | ||
data : data, | ||
parent : this.vm, | ||
compilerOptions: { | ||
// it is important to delay the ready hook | ||
// so that when it's called, all `v-with` wathcers | ||
// would have been set up. | ||
delayReady: !this.last | ||
} | ||
}) | ||
}, | ||
/** | ||
* For inhertied keys, need to watch | ||
* and sync back to the parent | ||
*/ | ||
watch: function () { | ||
if (!this.arg) return | ||
var self = this, | ||
key = self.key, | ||
ownerVM = self.binding.compiler.vm | ||
this.subVM.$compiler.observer.on('change:' + this.arg, function (val) { | ||
if (!self.lock) { | ||
self.lock = true | ||
nextTick(function () { | ||
self.lock = false | ||
}) | ||
} | ||
ownerVM.$set(key, val) | ||
}) | ||
}, | ||
unbind: function () { | ||
// all watchers are turned off during destroy | ||
// so no need to worry about it | ||
this.subVM.$destroy() | ||
} | ||
} |
@@ -1,7 +0,6 @@ | ||
function Emitter () { | ||
this._ctx = this | ||
function Emitter (ctx) { | ||
this._ctx = ctx || this | ||
} | ||
var EmitterProto = Emitter.prototype, | ||
slice = [].slice | ||
var EmitterProto = Emitter.prototype | ||
@@ -19,3 +18,3 @@ EmitterProto.on = function(event, fn){ | ||
function on() { | ||
function on () { | ||
self.off(event, on) | ||
@@ -61,6 +60,5 @@ fn.apply(this, arguments) | ||
Emitter.prototype.emit = function(event){ | ||
Emitter.prototype.emit = function(event, a, b, c){ | ||
this._cbs = this._cbs || {} | ||
var args = slice.call(arguments, 1), | ||
callbacks = this._cbs[event] | ||
var callbacks = this._cbs[event] | ||
@@ -70,3 +68,3 @@ if (callbacks) { | ||
for (var i = 0, len = callbacks.length; i < len; i++) { | ||
callbacks[i].apply(this._ctx, args) | ||
callbacks[i].call(this._ctx, a, b, c) | ||
} | ||
@@ -73,0 +71,0 @@ } |
var utils = require('./utils'), | ||
stringSaveRE = /"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g, | ||
stringRestoreRE = /"(\d+)"/g, | ||
constructorRE = new RegExp('constructor'.split('').join('[\'"+, ]*')), | ||
unicodeRE = /\\u\d\d\d\d/ | ||
STR_SAVE_RE = /"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g, | ||
STR_RESTORE_RE = /"(\d+)"/g, | ||
NEWLINE_RE = /\n/g, | ||
CTOR_RE = new RegExp('constructor'.split('').join('[\'"+, ]*')), | ||
UNICODE_RE = /\\u\d\d\d\d/, | ||
QUOTE_RE = /"/g | ||
@@ -56,6 +58,12 @@ // Variable extraction scooped from https://github.com/RubyLouvre/avalon | ||
*/ | ||
function getRel (path, compiler) { | ||
function traceScope (path, compiler, data) { | ||
var rel = '', | ||
dist = 0, | ||
self = compiler | ||
if (data && utils.get(data, path) !== undefined) { | ||
// hack: temporarily attached data | ||
return '$temp.' | ||
} | ||
while (compiler) { | ||
@@ -88,3 +96,2 @@ if (compiler.hasKey(path)) { | ||
function makeGetter (exp, raw) { | ||
/* jshint evil: true */ | ||
var fn | ||
@@ -94,3 +101,3 @@ try { | ||
} catch (e) { | ||
utils.warn('Invalid expression: ' + raw) | ||
utils.warn('Error parsing expression: ' + raw) | ||
} | ||
@@ -109,63 +116,107 @@ return fn | ||
module.exports = { | ||
/** | ||
* Convert double quotes to single quotes | ||
* so they don't mess up the generated function body | ||
*/ | ||
function escapeQuote (v) { | ||
return v.indexOf('"') > -1 | ||
? v.replace(QUOTE_RE, '\'') | ||
: v | ||
} | ||
/** | ||
* Parse and return an anonymous computed property getter function | ||
* from an arbitrary expression, together with a list of paths to be | ||
* created as bindings. | ||
*/ | ||
parse: function (exp, compiler) { | ||
// unicode and 'constructor' are not allowed for XSS security. | ||
if (unicodeRE.test(exp) || constructorRE.test(exp)) { | ||
utils.warn('Unsafe expression: ' + exp) | ||
return function () {} | ||
} | ||
// extract variable names | ||
var vars = getVariables(exp) | ||
if (!vars.length) { | ||
return makeGetter('return ' + exp, exp) | ||
} | ||
vars = utils.unique(vars) | ||
var accessors = '', | ||
has = utils.hash(), | ||
strings = [], | ||
// construct a regex to extract all valid variable paths | ||
// ones that begin with "$" are particularly tricky | ||
// because we can't use \b for them | ||
pathRE = new RegExp( | ||
"[^$\\w\\.](" + | ||
vars.map(escapeDollar).join('|') + | ||
")[$\\w\\.]*\\b", 'g' | ||
), | ||
body = ('return ' + exp) | ||
.replace(stringSaveRE, saveStrings) | ||
.replace(pathRE, replacePath) | ||
.replace(stringRestoreRE, restoreStrings) | ||
body = accessors + body | ||
/** | ||
* Parse and return an anonymous computed property getter function | ||
* from an arbitrary expression, together with a list of paths to be | ||
* created as bindings. | ||
*/ | ||
exports.parse = function (exp, compiler, data, filters) { | ||
// unicode and 'constructor' are not allowed for XSS security. | ||
if (UNICODE_RE.test(exp) || CTOR_RE.test(exp)) { | ||
utils.warn('Unsafe expression: ' + exp) | ||
return | ||
} | ||
// extract variable names | ||
var vars = getVariables(exp) | ||
if (!vars.length) { | ||
return makeGetter('return ' + exp, exp) | ||
} | ||
vars = utils.unique(vars) | ||
function saveStrings (str) { | ||
var i = strings.length | ||
strings[i] = str | ||
return '"' + i + '"' | ||
} | ||
var accessors = '', | ||
has = utils.hash(), | ||
strings = [], | ||
// construct a regex to extract all valid variable paths | ||
// ones that begin with "$" are particularly tricky | ||
// because we can't use \b for them | ||
pathRE = new RegExp( | ||
"[^$\\w\\.](" + | ||
vars.map(escapeDollar).join('|') + | ||
")[$\\w\\.]*\\b", 'g' | ||
), | ||
body = (' ' + exp) | ||
.replace(STR_SAVE_RE, saveStrings) | ||
.replace(pathRE, replacePath) | ||
.replace(STR_RESTORE_RE, restoreStrings) | ||
function replacePath (path) { | ||
// keep track of the first char | ||
var c = path.charAt(0) | ||
path = path.slice(1) | ||
var val = 'this.' + getRel(path, compiler) + path | ||
if (!has[path]) { | ||
accessors += val + ';' | ||
has[path] = 1 | ||
} | ||
// don't forget to put that first char back | ||
return c + val | ||
// wrap expression with computed filters | ||
if (filters) { | ||
var args, filter | ||
for (var i = 0, l = filters.length; i < l; i++) { | ||
filter = filters[i] | ||
args = filter.args | ||
? ',"' + filter.args.map(escapeQuote).join('","') + '"' | ||
: '' | ||
body = | ||
'this.$compiler.getOption("filters", "' + | ||
filter.name + | ||
'").call(this,' + | ||
body + args + | ||
')' | ||
} | ||
} | ||
function restoreStrings (str, i) { | ||
return strings[i] | ||
body = accessors + 'return ' + body | ||
function saveStrings (str) { | ||
var i = strings.length | ||
// escape newlines in strings so the expression | ||
// can be correctly evaluated | ||
strings[i] = str.replace(NEWLINE_RE, '\\n') | ||
return '"' + i + '"' | ||
} | ||
function replacePath (path) { | ||
// keep track of the first char | ||
var c = path.charAt(0) | ||
path = path.slice(1) | ||
var val = 'this.' + traceScope(path, compiler, data) + path | ||
if (!has[path]) { | ||
accessors += val + ';' | ||
has[path] = 1 | ||
} | ||
// don't forget to put that first char back | ||
return c + val | ||
} | ||
return makeGetter(body, exp) | ||
function restoreStrings (str, i) { | ||
return strings[i] | ||
} | ||
return makeGetter(body, exp) | ||
} | ||
/** | ||
* Evaluate an expression in the context of a compiler. | ||
* Accepts additional data. | ||
*/ | ||
exports.eval = function (exp, compiler, data) { | ||
var getter = exports.parse(exp, compiler, data), res | ||
if (getter) { | ||
// hack: temporarily attach the additional data so | ||
// it can be accessed in the getter | ||
compiler.vm.$temp = data | ||
res = getter.call(compiler.vm) | ||
delete compiler.vm.$temp | ||
} | ||
return res | ||
} |
@@ -0,1 +1,70 @@ | ||
var utils = require('./utils'), | ||
get = utils.get, | ||
slice = [].slice, | ||
QUOTE_RE = /^'.*'$/, | ||
filters = module.exports = utils.hash() | ||
/** | ||
* 'abc' => 'Abc' | ||
*/ | ||
filters.capitalize = function (value) { | ||
if (!value && value !== 0) return '' | ||
value = value.toString() | ||
return value.charAt(0).toUpperCase() + value.slice(1) | ||
} | ||
/** | ||
* 'abc' => 'ABC' | ||
*/ | ||
filters.uppercase = function (value) { | ||
return (value || value === 0) | ||
? value.toString().toUpperCase() | ||
: '' | ||
} | ||
/** | ||
* 'AbC' => 'abc' | ||
*/ | ||
filters.lowercase = function (value) { | ||
return (value || value === 0) | ||
? value.toString().toLowerCase() | ||
: '' | ||
} | ||
/** | ||
* 12345 => $12,345.00 | ||
*/ | ||
filters.currency = function (value, sign) { | ||
if (!value && value !== 0) return '' | ||
sign = sign || '$' | ||
var s = Math.floor(value).toString(), | ||
i = s.length % 3, | ||
h = i > 0 ? (s.slice(0, i) + (s.length > 3 ? ',' : '')) : '', | ||
f = '.' + value.toFixed(2).slice(-2) | ||
return sign + h + s.slice(i).replace(/(\d{3})(?=\d)/g, '$1,') + f | ||
} | ||
/** | ||
* args: an array of strings corresponding to | ||
* the single, double, triple ... forms of the word to | ||
* be pluralized. When the number to be pluralized | ||
* exceeds the length of the args, it will use the last | ||
* entry in the array. | ||
* | ||
* e.g. ['single', 'double', 'triple', 'multiple'] | ||
*/ | ||
filters.pluralize = function (value) { | ||
var args = slice.call(arguments, 1) | ||
return args.length > 1 | ||
? (args[value - 1] || args[args.length - 1]) | ||
: (args[value - 1] || args[0] + 's') | ||
} | ||
/** | ||
* A special filter that takes a handler function, | ||
* wraps it so it only gets triggered on specific keypresses. | ||
* | ||
* v-on only | ||
*/ | ||
var keyCodes = { | ||
@@ -12,75 +81,111 @@ enter : 13, | ||
module.exports = { | ||
filters.key = function (handler, key) { | ||
if (!handler) return | ||
var code = keyCodes[key] | ||
if (!code) { | ||
code = parseInt(key, 10) | ||
} | ||
return function (e) { | ||
if (e.keyCode === code) { | ||
handler.call(this, e) | ||
} | ||
} | ||
} | ||
/** | ||
* 'abc' => 'Abc' | ||
*/ | ||
capitalize: function (value) { | ||
if (!value && value !== 0) return '' | ||
value = value.toString() | ||
return value.charAt(0).toUpperCase() + value.slice(1) | ||
}, | ||
/** | ||
* Filter filter for v-repeat | ||
*/ | ||
filters.filterBy = function (arr, searchKey, delimiter, dataKey) { | ||
/** | ||
* 'abc' => 'ABC' | ||
*/ | ||
uppercase: function (value) { | ||
return (value || value === 0) | ||
? value.toString().toUpperCase() | ||
: '' | ||
}, | ||
// allow optional `in` delimiter | ||
// because why not | ||
if (delimiter && delimiter !== 'in') { | ||
dataKey = delimiter | ||
} | ||
/** | ||
* 'AbC' => 'abc' | ||
*/ | ||
lowercase: function (value) { | ||
return (value || value === 0) | ||
? value.toString().toLowerCase() | ||
: '' | ||
}, | ||
// get the search string | ||
var search = stripQuotes(searchKey) || this.$get(searchKey) | ||
if (!search) return arr | ||
search = search.toLowerCase() | ||
/** | ||
* 12345 => $12,345.00 | ||
*/ | ||
currency: function (value, args) { | ||
if (!value && value !== 0) return '' | ||
var sign = (args && args[0]) || '$', | ||
s = Math.floor(value).toString(), | ||
i = s.length % 3, | ||
h = i > 0 ? (s.slice(0, i) + (s.length > 3 ? ',' : '')) : '', | ||
f = '.' + value.toFixed(2).slice(-2) | ||
return sign + h + s.slice(i).replace(/(\d{3})(?=\d)/g, '$1,') + f | ||
}, | ||
// get the optional dataKey | ||
dataKey = dataKey && (stripQuotes(dataKey) || this.$get(dataKey)) | ||
/** | ||
* args: an array of strings corresponding to | ||
* the single, double, triple ... forms of the word to | ||
* be pluralized. When the number to be pluralized | ||
* exceeds the length of the args, it will use the last | ||
* entry in the array. | ||
* | ||
* e.g. ['single', 'double', 'triple', 'multiple'] | ||
*/ | ||
pluralize: function (value, args) { | ||
return args.length > 1 | ||
? (args[value - 1] || args[args.length - 1]) | ||
: (args[value - 1] || args[0] + 's') | ||
}, | ||
// convert object to array | ||
if (!Array.isArray(arr)) { | ||
arr = utils.objectToArray(arr) | ||
} | ||
/** | ||
* A special filter that takes a handler function, | ||
* wraps it so it only gets triggered on specific keypresses. | ||
*/ | ||
key: function (handler, args) { | ||
if (!handler) return | ||
var code = keyCodes[args[0]] | ||
if (!code) { | ||
code = parseInt(args[0], 10) | ||
return arr.filter(function (item) { | ||
return dataKey | ||
? contains(get(item, dataKey), search) | ||
: contains(item, search) | ||
}) | ||
} | ||
filters.filterBy.computed = true | ||
/** | ||
* Sort fitler for v-repeat | ||
*/ | ||
filters.orderBy = function (arr, sortKey, reverseKey) { | ||
var key = stripQuotes(sortKey) || this.$get(sortKey) | ||
if (!key) return arr | ||
// convert object to array | ||
if (!Array.isArray(arr)) { | ||
arr = utils.objectToArray(arr) | ||
} | ||
var order = 1 | ||
if (reverseKey) { | ||
if (reverseKey === '-1') { | ||
order = -1 | ||
} else if (reverseKey.charAt(0) === '!') { | ||
reverseKey = reverseKey.slice(1) | ||
order = this.$get(reverseKey) ? 1 : -1 | ||
} else { | ||
order = this.$get(reverseKey) ? -1 : 1 | ||
} | ||
return function (e) { | ||
if (e.keyCode === code) { | ||
handler.call(this, e) | ||
} | ||
// sort on a copy to avoid mutating original array | ||
return arr.slice().sort(function (a, b) { | ||
a = get(a, key) | ||
b = get(b, key) | ||
return a === b ? 0 : a > b ? order : -order | ||
}) | ||
} | ||
filters.orderBy.computed = true | ||
// Array filter helpers ------------------------------------------------------- | ||
/** | ||
* String contain helper | ||
*/ | ||
function contains (val, search) { | ||
/* jshint eqeqeq: false */ | ||
if (utils.isObject(val)) { | ||
for (var key in val) { | ||
if (contains(val[key], search)) { | ||
return true | ||
} | ||
} | ||
} else if (val != null) { | ||
return val.toString().toLowerCase().indexOf(search) > -1 | ||
} | ||
} | ||
/** | ||
* Test whether a string is in quotes, | ||
* if yes return stripped string | ||
*/ | ||
function stripQuotes (str) { | ||
if (QUOTE_RE.test(str)) { | ||
return str.slice(1, -1) | ||
} | ||
} |
@@ -34,2 +34,4 @@ var config = require('./config'), | ||
value = utils.toConstructor(value) | ||
} else if (type === 'filter') { | ||
utils.checkFilter(value) | ||
} | ||
@@ -65,3 +67,4 @@ hash[id] = value | ||
} catch (e) { | ||
return utils.warn('Cannot find plugin: ' + plugin) | ||
utils.warn('Cannot find plugin: ' + plugin) | ||
return | ||
} | ||
@@ -100,2 +103,9 @@ } | ||
// extend data options need to be copied | ||
// on instantiation | ||
if (options.data) { | ||
options.defaultData = options.data | ||
delete options.data | ||
} | ||
// inherit options | ||
@@ -116,15 +126,2 @@ options = inheritOptions(options, ParentVM.options, true) | ||
// copy prototype props | ||
var methods = options.methods | ||
if (methods) { | ||
for (var key in methods) { | ||
if ( | ||
!(key in ViewModel.prototype) && | ||
typeof methods[key] === 'function' | ||
) { | ||
proto[key] = methods[key] | ||
} | ||
} | ||
} | ||
// allow extended VM to be further extended | ||
@@ -164,8 +161,6 @@ ExtendedVM.extend = extend | ||
for (var key in parent) { | ||
if (key === 'el' || key === 'methods') continue | ||
if (key === 'el') continue | ||
var val = child[key], | ||
parentVal = parent[key], | ||
type = utils.typeOf(val), | ||
parentType = utils.typeOf(parentVal) | ||
if (topLevel && type === 'Function' && parentVal) { | ||
parentVal = parent[key] | ||
if (topLevel && typeof val === 'function' && parentVal) { | ||
// merge hook functions into an array | ||
@@ -178,3 +173,7 @@ child[key] = [val] | ||
} | ||
} else if (topLevel && (type === 'Object' || parentType === 'Object')) { | ||
} else if ( | ||
topLevel && | ||
(utils.isTrueObject(val) || utils.isTrueObject(parentVal)) | ||
&& !(parentVal instanceof ViewModel) | ||
) { | ||
// merge toplevel object options | ||
@@ -181,0 +180,0 @@ child[key] = inheritOptions(val, parentVal) |
@@ -6,8 +6,8 @@ /* jshint proto:true */ | ||
// cache methods | ||
typeOf = utils.typeOf, | ||
def = utils.defProtected, | ||
isObject = utils.isObject, | ||
isArray = Array.isArray, | ||
hasOwn = ({}).hasOwnProperty, | ||
oDef = Object.defineProperty, | ||
slice = [].slice, | ||
// types | ||
OBJECT = 'Object', | ||
ARRAY = 'Array', | ||
// fix for IE + __proto__ problem | ||
@@ -17,5 +17,3 @@ // define methods as inenumerable if __proto__ is present, | ||
// attach to array instances | ||
hasProto = ({}).__proto__, | ||
// lazy load | ||
ViewModel | ||
hasProto = ({}).__proto__ | ||
@@ -40,6 +38,15 @@ // Array Mutation Handlers & Augmentations ------------------------------------ | ||
// Augment the ArrayProxy with convenience methods | ||
def(ArrayProxy, 'remove', removeElement, !hasProto) | ||
def(ArrayProxy, 'set', replaceElement, !hasProto) | ||
def(ArrayProxy, 'replace', replaceElement, !hasProto) | ||
def(ArrayProxy, '$set', function (index, data) { | ||
return this.splice(index, 1, data)[0] | ||
}, !hasProto) | ||
def(ArrayProxy, '$remove', function (index) { | ||
if (typeof index !== 'number') { | ||
index = this.indexOf(index) | ||
} | ||
if (index > -1) { | ||
return this.splice(index, 1)[0] | ||
} | ||
}, !hasProto) | ||
/** | ||
@@ -66,2 +73,3 @@ * Intercep a mutation event so we can emit the mutation info. | ||
} | ||
// link & unlink | ||
@@ -72,6 +80,8 @@ linkArrayElements(this, inserted) | ||
// emit the mutation event | ||
this.__emitter__.emit('mutate', null, this, { | ||
method: method, | ||
args: args, | ||
result: result | ||
this.__emitter__.emit('mutate', '', this, { | ||
method : method, | ||
args : args, | ||
result : result, | ||
inserted : inserted, | ||
removed : removed | ||
}) | ||
@@ -94,4 +104,8 @@ | ||
if (isWatchable(item)) { | ||
convert(item) | ||
watch(item) | ||
// if object is not converted for observing | ||
// convert it... | ||
if (!item.__emitter__) { | ||
convert(item) | ||
watch(item) | ||
} | ||
owners = item.__emitter__.owners | ||
@@ -122,52 +136,22 @@ if (owners.indexOf(arr) < 0) { | ||
/** | ||
* Convenience method to remove an element in an Array | ||
* This will be attached to observed Array instances | ||
*/ | ||
function removeElement (index) { | ||
if (typeof index === 'function') { | ||
var i = this.length, | ||
removed = [] | ||
while (i--) { | ||
if (index(this[i])) { | ||
removed.push(this.splice(i, 1)[0]) | ||
} | ||
} | ||
return removed.reverse() | ||
} else { | ||
if (typeof index !== 'number') { | ||
index = this.indexOf(index) | ||
} | ||
if (index > -1) { | ||
return this.splice(index, 1)[0] | ||
} | ||
} | ||
} | ||
// Object add/delete key augmentation ----------------------------------------- | ||
/** | ||
* Convenience method to replace an element in an Array | ||
* This will be attached to observed Array instances | ||
*/ | ||
function replaceElement (index, data) { | ||
if (typeof index === 'function') { | ||
var i = this.length, | ||
replaced = [], | ||
replacer | ||
while (i--) { | ||
replacer = index(this[i]) | ||
if (replacer !== undefined) { | ||
replaced.push(this.splice(i, 1, replacer)[0]) | ||
} | ||
} | ||
return replaced.reverse() | ||
} else { | ||
if (typeof index !== 'number') { | ||
index = this.indexOf(index) | ||
} | ||
if (index > -1) { | ||
return this.splice(index, 1, data)[0] | ||
} | ||
} | ||
} | ||
var ObjProxy = Object.create(Object.prototype) | ||
def(ObjProxy, '$add', function (key, val) { | ||
if (hasOwn.call(this, key)) return | ||
this[key] = val | ||
convertKey(this, key) | ||
// emit a propagating set event | ||
this.__emitter__.emit('set', key, val, true) | ||
}, !hasProto) | ||
def(ObjProxy, '$delete', function (key) { | ||
if (!(hasOwn.call(this, key))) return | ||
// trigger set events | ||
this[key] = undefined | ||
delete this[key] | ||
this.__emitter__.emit('delete', key) | ||
}, !hasProto) | ||
// Watch Helpers -------------------------------------------------------------- | ||
@@ -179,5 +163,3 @@ | ||
function isWatchable (obj) { | ||
ViewModel = ViewModel || require('./viewmodel') | ||
var type = typeOf(obj) | ||
return (type === OBJECT || type === ARRAY) && !(obj instanceof ViewModel) | ||
return typeof obj === 'object' && obj && !obj.$compiler | ||
} | ||
@@ -192,9 +174,9 @@ | ||
def(obj, '__emitter__', emitter) | ||
emitter.on('set', function () { | ||
var owners = obj.__emitter__.owners, | ||
i = owners.length | ||
while (i--) { | ||
owners[i].__emitter__.emit('set', '', '', true) | ||
} | ||
}) | ||
emitter | ||
.on('set', function (key, val, propagate) { | ||
if (propagate) propagateChange(obj) | ||
}) | ||
.on('mutate', function () { | ||
propagateChange(obj) | ||
}) | ||
emitter.values = utils.hash() | ||
@@ -206,10 +188,20 @@ emitter.owners = [] | ||
/** | ||
* Propagate an array element's change to its owner arrays | ||
*/ | ||
function propagateChange (obj) { | ||
var owners = obj.__emitter__.owners, | ||
i = owners.length | ||
while (i--) { | ||
owners[i].__emitter__.emit('set', '', '', true) | ||
} | ||
} | ||
/** | ||
* Watch target based on its type | ||
*/ | ||
function watch (obj) { | ||
var type = typeOf(obj) | ||
if (type === OBJECT) { | ||
if (isArray(obj)) { | ||
watchArray(obj) | ||
} else { | ||
watchObject(obj) | ||
} else if (type === ARRAY) { | ||
watchArray(obj) | ||
} | ||
@@ -219,5 +211,20 @@ } | ||
/** | ||
* Augment target objects with modified | ||
* methods | ||
*/ | ||
function augment (target, src) { | ||
if (hasProto) { | ||
target.__proto__ = src | ||
} else { | ||
for (var key in src) { | ||
def(target, key, src[key]) | ||
} | ||
} | ||
} | ||
/** | ||
* Watch an Object, recursive. | ||
*/ | ||
function watchObject (obj) { | ||
augment(obj, ObjProxy) | ||
for (var key in obj) { | ||
@@ -233,9 +240,3 @@ convertKey(obj, key) | ||
function watchArray (arr) { | ||
if (hasProto) { | ||
arr.__proto__ = ArrayProxy | ||
} else { | ||
for (var key in ArrayProxy) { | ||
def(arr, key, ArrayProxy[key]) | ||
} | ||
} | ||
augment(arr, ArrayProxy) | ||
linkArrayElements(arr, arr) | ||
@@ -262,7 +263,9 @@ } | ||
Object.defineProperty(obj, key, { | ||
oDef(obj, key, { | ||
enumerable: true, | ||
configurable: true, | ||
get: function () { | ||
var value = values[key] | ||
// only emit get on tip values | ||
if (pub.shouldGet && typeOf(value) !== OBJECT) { | ||
if (pub.shouldGet) { | ||
emitter.emit('get', key) | ||
@@ -285,4 +288,4 @@ } | ||
emitter.emit('set', key, val, propagate) | ||
if (Array.isArray(val)) { | ||
emitter.emit('set', key + '.length', val.length) | ||
if (isArray(val)) { | ||
emitter.emit('set', key + '.length', val.length, propagate) | ||
} | ||
@@ -300,7 +303,7 @@ observe(val, key, emitter) | ||
function emitSet (obj) { | ||
var type = typeOf(obj), | ||
emitter = obj && obj.__emitter__ | ||
if (type === ARRAY) { | ||
var emitter = obj && obj.__emitter__ | ||
if (!emitter) return | ||
if (isArray(obj)) { | ||
emitter.emit('set', 'length', obj.length) | ||
} else if (type === OBJECT) { | ||
} else { | ||
var key, val | ||
@@ -322,15 +325,14 @@ for (key in obj) { | ||
function copyPaths (newObj, oldObj) { | ||
if (typeOf(oldObj) !== OBJECT || typeOf(newObj) !== OBJECT) { | ||
if (!isObject(newObj) || !isObject(oldObj)) { | ||
return | ||
} | ||
var path, type, oldVal, newVal | ||
var path, oldVal, newVal | ||
for (path in oldObj) { | ||
if (!(path in newObj)) { | ||
if (!(hasOwn.call(newObj, path))) { | ||
oldVal = oldObj[path] | ||
type = typeOf(oldVal) | ||
if (type === OBJECT) { | ||
if (isArray(oldVal)) { | ||
newObj[path] = [] | ||
} else if (isObject(oldVal)) { | ||
newVal = newObj[path] = {} | ||
copyPaths(newVal, oldVal) | ||
} else if (type === ARRAY) { | ||
newObj[path] = [] | ||
} else { | ||
@@ -357,5 +359,5 @@ newObj[path] = undefined | ||
} | ||
if (typeOf(obj) === OBJECT) { | ||
if (isObject(obj)) { | ||
sec = path[i] | ||
if (!(sec in obj)) { | ||
if (!(hasOwn.call(obj, sec))) { | ||
obj[sec] = undefined | ||
@@ -362,0 +364,0 @@ if (obj.__emitter__) convertKey(obj, sec) |
@@ -1,10 +0,33 @@ | ||
var BINDING_RE = /{{{?([^{}]+?)}?}}/, | ||
TRIPLE_RE = /{{{[^{}]+}}}/ | ||
var openChar = '{', | ||
endChar = '}', | ||
ESCAPE_RE = /[-.*+?^${}()|[\]\/\\]/g, | ||
BINDING_RE = buildInterpolationRegex() | ||
/** | ||
function buildInterpolationRegex () { | ||
var open = escapeRegex(openChar), | ||
end = escapeRegex(endChar) | ||
return new RegExp(open + open + open + '?(.+?)' + end + '?' + end + end) | ||
} | ||
function escapeRegex (str) { | ||
return str.replace(ESCAPE_RE, '\\$&') | ||
} | ||
function setDelimiters (delimiters) { | ||
exports.delimiters = delimiters | ||
openChar = delimiters[0] | ||
endChar = delimiters[1] | ||
BINDING_RE = buildInterpolationRegex() | ||
} | ||
/** | ||
* Parse a piece of text, return an array of tokens | ||
* token types: | ||
* 1. plain string | ||
* 2. object with key = binding key | ||
* 3. object with key & html = true | ||
*/ | ||
function parse (text) { | ||
if (!BINDING_RE.test(text)) return null | ||
var m, i, token, tokens = [] | ||
var m, i, token, match, tokens = [] | ||
/* jshint boss: true */ | ||
@@ -15,3 +38,6 @@ while (m = text.match(BINDING_RE)) { | ||
token = { key: m[1].trim() } | ||
if (TRIPLE_RE.test(m[0])) token.html = true | ||
match = m[0] | ||
token.html = | ||
match.charAt(2) === openChar && | ||
match.charAt(match.length - 3) === endChar | ||
tokens.push(token) | ||
@@ -27,2 +53,4 @@ text = text.slice(i + m[0].length) | ||
* return a Directive-friendly expression | ||
* | ||
* e.g. a {{b}} c => "a " + b + " c" | ||
*/ | ||
@@ -32,6 +60,11 @@ function parseAttr (attr) { | ||
if (!tokens) return null | ||
if (tokens.length === 1) return tokens[0].key | ||
var res = [], token | ||
for (var i = 0, l = tokens.length; i < l; i++) { | ||
token = tokens[i] | ||
res.push(token.key || ('"' + token + '"')) | ||
res.push( | ||
token.key | ||
? ('(' + token.key + ')') | ||
: ('"' + token + '"') | ||
) | ||
} | ||
@@ -41,3 +74,5 @@ return res.join('+') | ||
exports.parse = parse | ||
exports.parseAttr = parseAttr | ||
exports.parse = parse | ||
exports.parseAttr = parseAttr | ||
exports.setDelimiters = setDelimiters | ||
exports.delimiters = [openChar, endChar] |
201
src/utils.js
var config = require('./config'), | ||
attrs = config.attrs, | ||
toString = ({}).toString, | ||
@@ -7,2 +6,5 @@ win = window, | ||
timeout = win.setTimeout, | ||
def = Object.defineProperty, | ||
THIS_RE = /[^\w]this[^\w]/, | ||
OBJECT = 'object', | ||
hasClassList = 'classList' in document.documentElement, | ||
@@ -14,2 +16,47 @@ ViewModel // late def | ||
/** | ||
* get a value from an object keypath | ||
*/ | ||
get: function (obj, key) { | ||
/* jshint eqeqeq: false */ | ||
if (key.indexOf('.') < 0) { | ||
return obj[key] | ||
} | ||
var path = key.split('.'), | ||
d = -1, l = path.length | ||
while (++d < l && obj != null) { | ||
obj = obj[path[d]] | ||
} | ||
return obj | ||
}, | ||
/** | ||
* set a value to an object keypath | ||
*/ | ||
set: function (obj, key, val) { | ||
/* jshint eqeqeq: false */ | ||
if (key.indexOf('.') < 0) { | ||
obj[key] = val | ||
return | ||
} | ||
var path = key.split('.'), | ||
d = -1, l = path.length - 1 | ||
while (++d < l) { | ||
if (obj[path[d]] == null) { | ||
obj[path[d]] = {} | ||
} | ||
obj = obj[path[d]] | ||
} | ||
obj[path[d]] = val | ||
}, | ||
/** | ||
* return the base segment of a keypath | ||
*/ | ||
baseKey: function (key) { | ||
return key.indexOf('.') > 0 | ||
? key.split('.')[0] | ||
: key | ||
}, | ||
/** | ||
* Create a prototype-less object | ||
@@ -26,5 +73,7 @@ * which is a better hash/map | ||
attr: function (el, type) { | ||
var attr = attrs[type], | ||
var attr = config.prefix + '-' + type, | ||
val = el.getAttribute(attr) | ||
if (val !== null) el.removeAttribute(attr) | ||
if (val !== null) { | ||
el.removeAttribute(attr) | ||
} | ||
return val | ||
@@ -38,7 +87,7 @@ }, | ||
*/ | ||
defProtected: function (obj, key, val, enumerable) { | ||
if (obj.hasOwnProperty(key)) return | ||
Object.defineProperty(obj, key, { | ||
defProtected: function (obj, key, val, enumerable, writable) { | ||
def(obj, key, { | ||
value : val, | ||
enumerable : !!enumerable, | ||
enumerable : enumerable, | ||
writable : writable, | ||
configurable : true | ||
@@ -49,10 +98,17 @@ }) | ||
/** | ||
* Accurate type check | ||
* internal use only, so no need to check for NaN | ||
* A less bullet-proof but more efficient type check | ||
* than Object.prototype.toString | ||
*/ | ||
typeOf: function (obj) { | ||
return toString.call(obj).slice(8, -1) | ||
isObject: function (obj) { | ||
return typeof obj === OBJECT && obj && !Array.isArray(obj) | ||
}, | ||
/** | ||
* A more accurate but less efficient type check | ||
*/ | ||
isTrueObject: function (obj) { | ||
return toString.call(obj) === '[object Object]' | ||
}, | ||
/** | ||
* Most simple bind | ||
@@ -68,24 +124,30 @@ * enough for the usecase and fast than native bind() | ||
/** | ||
* Make sure only strings, booleans, numbers and | ||
* objects are output to html. otherwise, ouput empty string. | ||
* Make sure null and undefined output empty string | ||
*/ | ||
toText: function (value) { | ||
/* jshint eqeqeq: false */ | ||
var type = typeof value | ||
return (type === 'string' || | ||
type === 'boolean' || | ||
(type === 'number' && value == value)) // deal with NaN | ||
? value | ||
: type === 'object' && value !== null | ||
? JSON.stringify(value) | ||
: '' | ||
guard: function (value) { | ||
/* jshint eqeqeq: false, eqnull: true */ | ||
return value == null | ||
? '' | ||
: (typeof value == 'object') | ||
? JSON.stringify(value) | ||
: value | ||
}, | ||
/** | ||
* When setting value on the VM, parse possible numbers | ||
*/ | ||
checkNumber: function (value) { | ||
return (isNaN(value) || value === null || typeof value === 'boolean') | ||
? value | ||
: Number(value) | ||
}, | ||
/** | ||
* simple extend | ||
*/ | ||
extend: function (obj, ext, protective) { | ||
extend: function (obj, ext) { | ||
for (var key in ext) { | ||
if (protective && obj[key]) continue | ||
obj[key] = ext[key] | ||
if (obj[key] !== ext[key]) { | ||
obj[key] = ext[key] | ||
} | ||
} | ||
@@ -121,2 +183,7 @@ return obj | ||
if (!templateNode) return | ||
// if its a template tag and the browser supports it, | ||
// its content is already a document fragment! | ||
if (templateNode.tagName === 'TEMPLATE' && templateNode.content) { | ||
return templateNode.content | ||
} | ||
template = templateNode.innerHTML | ||
@@ -143,3 +210,3 @@ } | ||
ViewModel = ViewModel || require('./viewmodel') | ||
return utils.typeOf(obj) === 'Object' | ||
return utils.isObject(obj) | ||
? ViewModel.extend(obj) | ||
@@ -152,2 +219,12 @@ : typeof obj === 'function' | ||
/** | ||
* Check if a filter function contains references to `this` | ||
* If yes, mark it as a computed filter. | ||
*/ | ||
checkFilter: function (filter) { | ||
if (THIS_RE.test(filter.toString())) { | ||
filter.computed = true | ||
} | ||
}, | ||
/** | ||
* convert certain option values to the desired format. | ||
@@ -159,2 +236,3 @@ */ | ||
template = options.template, | ||
filters = options.filters, | ||
key | ||
@@ -171,2 +249,7 @@ if (components) { | ||
} | ||
if (filters) { | ||
for (key in filters) { | ||
utils.checkFilter(filters[key]) | ||
} | ||
} | ||
if (template) { | ||
@@ -178,24 +261,2 @@ options.template = utils.toFragment(template) | ||
/** | ||
* log for debugging | ||
*/ | ||
log: function (msg) { | ||
if (config.debug && console) { | ||
console.log(msg) | ||
} | ||
}, | ||
/** | ||
* warnings, traces by default | ||
* can be suppressed by `silent` option. | ||
*/ | ||
warn: function (msg) { | ||
if (!config.silent && console) { | ||
console.warn(msg) | ||
if (config.debug && console.trace) { | ||
console.trace(msg) | ||
} | ||
} | ||
}, | ||
/** | ||
* used to defer batch updates | ||
@@ -236,3 +297,45 @@ */ | ||
} | ||
}, | ||
/** | ||
* Convert an object to Array | ||
* used in v-repeat and array filters | ||
*/ | ||
objectToArray: function (obj) { | ||
var res = [], val, data | ||
for (var key in obj) { | ||
val = obj[key] | ||
data = utils.isObject(val) | ||
? val | ||
: { $value: val } | ||
data.$key = key | ||
res.push(data) | ||
} | ||
return res | ||
} | ||
} | ||
enableDebug() | ||
function enableDebug () { | ||
/** | ||
* log for debugging | ||
*/ | ||
utils.log = function (msg) { | ||
if (config.debug && console) { | ||
console.log(msg) | ||
} | ||
} | ||
/** | ||
* warnings, traces by default | ||
* can be suppressed by `silent` option. | ||
*/ | ||
utils.warn = function (msg) { | ||
if (!config.silent && console) { | ||
console.warn(msg) | ||
if (config.debug && console.trace) { | ||
console.trace() | ||
} | ||
} | ||
} | ||
} |
@@ -28,2 +28,13 @@ var Compiler = require('./compiler'), | ||
/** | ||
* Convenience function to get a value from | ||
* a keypath | ||
*/ | ||
def(VMProto, '$get', function (key) { | ||
var val = utils.get(this, key) | ||
return val === undefined && this.$parent | ||
? this.$parent.$get(key) | ||
: val | ||
}) | ||
/** | ||
* Convenience function to set an actual nested value | ||
@@ -33,8 +44,3 @@ * from a flat key string. Used in directives. | ||
def(VMProto, '$set', function (key, value) { | ||
var path = key.split('.'), | ||
obj = this | ||
for (var d = 0, l = path.length - 1; d < l; d++) { | ||
obj = obj[path[d]] | ||
} | ||
obj[path[d]] = value | ||
utils.set(this, key, value) | ||
}) | ||
@@ -133,7 +139,7 @@ | ||
def(VMProto, '$remove', function (cb) { | ||
var el = this.$el, | ||
parent = el.parentNode | ||
if (!parent) return | ||
var el = this.$el | ||
transition(el, -1, function () { | ||
parent.removeChild(el) | ||
if (el.parentNode) { | ||
el.parentNode.removeChild(el) | ||
} | ||
if (cb) nextTick(cb) | ||
@@ -145,7 +151,5 @@ }, this.$compiler) | ||
target = query(target) | ||
var el = this.$el, | ||
parent = target.parentNode | ||
if (!parent) return | ||
var el = this.$el | ||
transition(el, 1, function () { | ||
parent.insertBefore(el, target) | ||
target.parentNode.insertBefore(el, target) | ||
if (cb) nextTick(cb) | ||
@@ -157,11 +161,8 @@ }, this.$compiler) | ||
target = query(target) | ||
var el = this.$el, | ||
parent = target.parentNode, | ||
next = target.nextSibling | ||
if (!parent) return | ||
var el = this.$el | ||
transition(el, 1, function () { | ||
if (next) { | ||
parent.insertBefore(el, next) | ||
if (target.nextSibling) { | ||
target.parentNode.insertBefore(el, target.nextSibling) | ||
} else { | ||
parent.appendChild(el) | ||
target.parentNode.appendChild(el) | ||
} | ||
@@ -168,0 +169,0 @@ if (cb) nextTick(cb) |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
282814
31
7841