From b93171da401f6b64fb387860973c2012600183f8 Mon Sep 17 00:00:00 2001 From: nuintun Date: Fri, 18 Mar 2016 17:00:14 +0800 Subject: [PATCH] update files --- static/js/vue/vue.js | 4776 ++++++++++++++++++++++-------------------- 1 file changed, 2478 insertions(+), 2298 deletions(-) diff --git a/static/js/vue/vue.js b/static/js/vue/vue.js index faf04d5..14d2359 100644 --- a/static/js/vue/vue.js +++ b/static/js/vue/vue.js @@ -1,12 +1,12 @@ /*! - * Vue.js v1.0.14 + * Vue.js v1.0.18 * (c) 2016 Evan You * Released under the MIT License. */ (function (global, factory){ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : - global.Vue = factory(); + (global.Vue = factory()); }(this, function (){ 'use strict'; @@ -85,7 +85,7 @@ * @return {Boolean} */ - var literalValueRE = /^\s?(true|false|[\d\.]+|'[^']*'|"[^"]*")\s?$/; + var literalValueRE = /^\s?(true|false|-?[\d\.]+|'[^']*'|"[^"]*")\s?$/; function isLiteral(exp){ return literalValueRE.test(exp); @@ -212,7 +212,7 @@ * @return {Function} */ - function bind$1(fn, ctx){ + function bind(fn, ctx){ return function (a){ var l = arguments.length; return l ? l > 1 ? fn.apply(ctx, arguments) : fn.call(ctx, a) : fn.call(ctx); @@ -291,7 +291,7 @@ var isArray = Array.isArray; /** - * Define a non-enumerable property + * Define a property. * * @param {Object} obj * @param {String} key @@ -395,9 +395,13 @@ // Browser environment sniffing var inBrowser = typeof window !== 'undefined' && Object.prototype.toString.call(window) !== '[object Object]'; - var isIE9 = inBrowser && navigator.userAgent.toLowerCase().indexOf('msie 9.0') > 0; + // detect devtools + var devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__; - var isAndroid = inBrowser && navigator.userAgent.toLowerCase().indexOf('android') > 0; + // UA sniffing for working around browser-specific quirks + var UA = inBrowser && window.navigator.userAgent.toLowerCase(); + var isIE9 = UA && UA.indexOf('msie 9.0') > 0; + var isAndroid = UA && UA.indexOf('android') > 0; var transitionProp = undefined; var transitionEndEvent = undefined; @@ -451,7 +455,11 @@ textNode.data = counter; }; } else { - timerFunc = setTimeout; + // webpack attempts to inject a shim for setImmediate + // if it is used as a global, so we have to work around that to + // avoid bundling unnecessary code. + var context = inBrowser ? window : typeof global !== 'undefined' ? global : {}; + timerFunc = context.setImmediate || setTimeout; } return function (cb, ctx){ var func = ctx ? function (){ @@ -485,23 +493,29 @@ */ p.put = function (key, value){ - var entry = { - key: key, - value: value - }; - this._keymap[key] = entry; - if (this.tail) { - this.tail.newer = entry; - entry.older = this.tail; - } else { - this.head = entry; - } - this.tail = entry; + var removed; if (this.size === this.limit) { - return this.shift(); - } else { + removed = this.shift(); + } + + var entry = this.get(key, true); + if (!entry) { + entry = { + key: key + }; + this._keymap[key] = entry; + if (this.tail) { + this.tail.newer = entry; + entry.older = this.tail; + } else { + this.head = entry; + } + this.tail = entry; this.size++; } + entry.value = value; + + return removed; }; /** @@ -517,6 +531,7 @@ this.head.older = undefined; entry.newer = entry.older = undefined; this._keymap[entry.key] = undefined; + this.size--; } return entry; }; @@ -642,7 +657,6 @@ */ function parseDirective(s){ - var hit = cache$1.get(s); if (hit) { return hit; @@ -850,10 +864,10 @@ * @return {String} */ - var filterRE$1 = /[^|]\|[^|]/; + var filterRE = /[^|]\|[^|]/; function inlineFilters(exp, single){ - if (!filterRE$1.test(exp)) { + if (!filterRE.test(exp)) { return single ? exp : '(' + exp + ')'; } else { var dir = parseDirective(exp); @@ -868,7 +882,7 @@ } } - var text$1 = Object.freeze({ + var text = Object.freeze({ compileRegex: compileRegex, parseText: parseText, tokensToExp: tokensToExp @@ -910,12 +924,11 @@ warnExpressionErrors: true, /** - * Whether or not to handle fully object properties which - * are already backed by getters and seters. Depending on - * use case and environment, this might introduce non-neglible - * performance penalties. + * Whether to allow devtools inspection. + * Disabled by default in production builds. */ - convertAllProperties: false, + + devtools: 'development' !== 'production', /** * Internal flag to indicate the delimiters have been @@ -1062,14 +1075,14 @@ function applyTransition(el, direction, op, vm, cb){ var transition = el.__v_trans; if (!transition || - // skip if there are no js hooks and CSS transition is - // not supported + // skip if there are no js hooks and CSS transition is + // not supported !transition.hooks && !transitionEndEvent || - // skip transitions for initial compile + // skip transitions for initial compile !vm._isCompiled || - // if the vm is being manipulated by a parent directive - // during the parent's compilation phase, skip the - // animation. + // if the vm is being manipulated by a parent directive + // during the parent's compilation phase, skip the + // animation. vm.$parent && !vm.$parent._isCompiled) { op(); if (cb) cb(); @@ -1079,6 +1092,13 @@ transition[action](op, cb); } + var transition = Object.freeze({ + appendWithTransition: appendWithTransition, + beforeWithTransition: beforeWithTransition, + removeWithTransition: removeWithTransition, + applyTransition: applyTransition + }); + /** * Query an element selector if it's not an element already. * @@ -1229,10 +1249,11 @@ * @param {Element} el * @param {String} event * @param {Function} cb + * @param {Boolean} [useCapture] */ - function on$1(el, event, cb){ - el.addEventListener(event, cb); + function on(el, event, cb, useCapture){ + el.addEventListener(event, cb, useCapture); } /** @@ -1259,7 +1280,7 @@ function setClass(el, cls){ /* istanbul ignore if */ - if (isIE9 && !(el instanceof SVGElement)) { + if (isIE9 && !/svg$/.test(el.namespaceURI)) { el.className = cls; } else { el.setAttribute('class', cls); @@ -1313,14 +1334,14 @@ * * @param {Element} el * @param {Boolean} asFragment - * @return {Element} + * @return {Element|DocumentFragment} */ function extractContent(el, asFragment){ var child; var rawContent; /* istanbul ignore if */ - if (isTemplate(el) && el.content instanceof DocumentFragment) { + if (isTemplate(el) && isFragment(el.content)) { el = el.content; } if (el.hasChildNodes()) { @@ -1336,20 +1357,26 @@ } /** - * Trim possible empty head/tail textNodes inside a parent. + * Trim possible empty head/tail text and comment + * nodes inside a parent. * * @param {Node} node */ function trimNode(node){ - trim(node, node.firstChild); - trim(node, node.lastChild); + var child; + /* eslint-disable no-sequences */ + while ((child = node.firstChild, isTrimmable(child))) { + node.removeChild(child); + } + while ((child = node.lastChild, isTrimmable(child))) { + node.removeChild(child); + } + /* eslint-enable no-sequences */ } - function trim(parent, node){ - if (node && node.nodeType === 3 && !node.data.trim()) { - parent.removeChild(node); - } + function isTrimmable(node){ + return node && (node.nodeType === 3 && !node.data.trim() || node.nodeType === 8); } /** @@ -1384,7 +1411,7 @@ function createAnchor(content, persist){ var anchor = config.debug ? document.createComment(content) : document.createTextNode(persist ? ' ' : ''); - anchor.__vue_anchor = true; + anchor.__v_anchor = true; return anchor; } @@ -1459,8 +1486,392 @@ } } - var commonTagRE = /^(div|p|span|img|a|b|i|br|ul|ol|li|h1|h2|h3|h4|h5|h6|code|pre|table|th|td|tr|form|label|input|select|option|nav|article|section|header|footer)$/; - var reservedTagRE = /^(slot|partial|component)$/; + /** + * Check if a node is a DocumentFragment. + * + * @param {Node} node + * @return {Boolean} + */ + + function isFragment(node){ + return node && node.nodeType === 11; + } + + /** + * Get outerHTML of elements, taking care + * of SVG elements in IE as well. + * + * @param {Element} el + * @return {String} + */ + + function getOuterHTML(el){ + if (el.outerHTML) { + return el.outerHTML; + } else { + var container = document.createElement('div'); + container.appendChild(el.cloneNode(true)); + return container.innerHTML; + } + } + + var uid$1 = 0; + + /** + * A dep is an observable that can have multiple + * directives subscribing to it. + * + * @constructor + */ + function Dep(){ + this.id = uid$1++; + this.subs = []; + } + + // the current target watcher being evaluated. + // this is globally unique because there could be only one + // watcher being evaluated at any time. + Dep.target = null; + + /** + * Add a directive subscriber. + * + * @param {Directive} sub + */ + + Dep.prototype.addSub = function (sub){ + this.subs.push(sub); + }; + + /** + * Remove a directive subscriber. + * + * @param {Directive} sub + */ + + Dep.prototype.removeSub = function (sub){ + this.subs.$remove(sub); + }; + + /** + * Add self as a dependency to the target watcher. + */ + + Dep.prototype.depend = function (){ + Dep.target.addDep(this); + }; + + /** + * Notify all subscribers of a new value. + */ + + Dep.prototype.notify = function (){ + // stablize the subscriber list first + var subs = toArray(this.subs); + for (var i = 0, l = subs.length; i < l; i++) { + subs[i].update(); + } + }; + + var arrayProto = Array.prototype; + var arrayMethods = Object.create(arrayProto) + + /** + * Intercept mutating methods and emit events + */ + + ; + ['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse'].forEach(function (method){ + // cache original method + var original = arrayProto[method]; + def(arrayMethods, method, function mutator(){ + // avoid leaking arguments: + // http://jsperf.com/closure-with-arguments + var i = arguments.length; + var args = new Array(i); + while (i--) { + args[i] = arguments[i]; + } + var result = original.apply(this, args); + var ob = this.__ob__; + var inserted; + switch (method) { + case 'push': + inserted = args; + break; + case 'unshift': + inserted = args; + break; + case 'splice': + inserted = args.slice(2); + break; + } + if (inserted) ob.observeArray(inserted); + // notify change + ob.dep.notify(); + return result; + }); + }); + + /** + * Swap the element at the given index with a new value + * and emits corresponding event. + * + * @param {Number} index + * @param {*} val + * @return {*} - replaced element + */ + + def(arrayProto, '$set', function $set(index, val){ + if (index >= this.length) { + this.length = Number(index) + 1; + } + return this.splice(index, 1, val)[0]; + }); + + /** + * Convenience method to remove the element at given index. + * + * @param {Number} index + * @param {*} val + */ + + def(arrayProto, '$remove', function $remove(item){ + /* istanbul ignore if */ + if (!this.length) return; + var index = indexOf(this, item); + if (index > -1) { + return this.splice(index, 1); + } + }); + + var arrayKeys = Object.getOwnPropertyNames(arrayMethods); + + /** + * Observer class that are attached to each observed + * object. Once attached, the observer converts target + * object's property keys into getter/setters that + * collect dependencies and dispatches updates. + * + * @param {Array|Object} value + * @constructor + */ + + function Observer(value){ + this.value = value; + this.dep = new Dep(); + def(value, '__ob__', this); + if (isArray(value)) { + var augment = hasProto ? protoAugment : copyAugment; + augment(value, arrayMethods, arrayKeys); + this.observeArray(value); + } else { + this.walk(value); + } + } + + // Instance methods + + /** + * Walk through each property and convert them into + * getter/setters. This method should only be called when + * value type is Object. + * + * @param {Object} obj + */ + + Observer.prototype.walk = function (obj){ + var keys = Object.keys(obj); + for (var i = 0, l = keys.length; i < l; i++) { + this.convert(keys[i], obj[keys[i]]); + } + }; + + /** + * Observe a list of Array items. + * + * @param {Array} items + */ + + Observer.prototype.observeArray = function (items){ + for (var i = 0, l = items.length; i < l; i++) { + observe(items[i]); + } + }; + + /** + * Convert a property into getter/setter so we can emit + * the events when the property is accessed/changed. + * + * @param {String} key + * @param {*} val + */ + + Observer.prototype.convert = function (key, val){ + defineReactive(this.value, key, val); + }; + + /** + * Add an owner vm, so that when $set/$delete mutations + * happen we can notify owner vms to proxy the keys and + * digest the watchers. This is only called when the object + * is observed as an instance's root $data. + * + * @param {Vue} vm + */ + + Observer.prototype.addVm = function (vm){ + (this.vms || (this.vms = [])).push(vm); + }; + + /** + * Remove an owner vm. This is called when the object is + * swapped out as an instance's $data object. + * + * @param {Vue} vm + */ + + Observer.prototype.removeVm = function (vm){ + this.vms.$remove(vm); + }; + + // helpers + + /** + * Augment an target Object or Array by intercepting + * the prototype chain using __proto__ + * + * @param {Object|Array} target + * @param {Object} proto + */ + + function protoAugment(target, src){ + /* eslint-disable no-proto */ + target.__proto__ = src; + /* eslint-enable no-proto */ + } + + /** + * Augment an target Object or Array by defining + * hidden properties. + * + * @param {Object|Array} target + * @param {Object} proto + */ + + function copyAugment(target, src, keys){ + for (var i = 0, l = keys.length; i < l; i++) { + var key = keys[i]; + def(target, key, src[key]); + } + } + + /** + * Attempt to create an observer instance for a value, + * returns the new observer if successfully observed, + * or the existing observer if the value already has one. + * + * @param {*} value + * @param {Vue} [vm] + * @return {Observer|undefined} + * @static + */ + + function observe(value, vm){ + if (!value || typeof value !== 'object') { + return; + } + var ob; + if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) { + ob = value.__ob__; + } else if ((isArray(value) || isPlainObject(value)) && Object.isExtensible(value) && !value._isVue) { + ob = new Observer(value); + } + if (ob && vm) { + ob.addVm(vm); + } + return ob; + } + + /** + * Define a reactive property on an Object. + * + * @param {Object} obj + * @param {String} key + * @param {*} val + * @param {Boolean} doNotObserve + */ + + function defineReactive(obj, key, val, doNotObserve){ + var dep = new Dep(); + + var property = Object.getOwnPropertyDescriptor(obj, key); + if (property && property.configurable === false) { + return; + } + + // cater for pre-defined getter/setters + var getter = property && property.get; + var setter = property && property.set; + + // if doNotObserve is true, only use the child value observer + // if it already exists, and do not attempt to create it. + // this allows freezing a large object from the root and + // avoid unnecessary observation inside v-for fragments. + var childOb = doNotObserve ? isObject(val) && val.__ob__ : observe(val); + Object.defineProperty(obj, key, { + enumerable: true, + configurable: true, + get: function reactiveGetter(){ + var value = getter ? getter.call(obj) : val; + if (Dep.target) { + dep.depend(); + if (childOb) { + childOb.dep.depend(); + } + if (isArray(value)) { + for (var e, i = 0, l = value.length; i < l; i++) { + e = value[i]; + e && e.__ob__ && e.__ob__.dep.depend(); + } + } + } + return value; + }, + set: function reactiveSetter(newVal){ + var value = getter ? getter.call(obj) : val; + if (newVal === value) { + return; + } + if (setter) { + setter.call(obj, newVal); + } else { + val = newVal; + } + childOb = doNotObserve ? isObject(newVal) && newVal.__ob__ : observe(newVal); + dep.notify(); + } + }); + } + + var commonTagRE = /^(div|p|span|img|a|b|i|br|ul|ol|li|h1|h2|h3|h4|h5|h6|code|pre|table|th|td|tr|form|label|input|select|option|nav|article|section|header|footer)$/i; + var reservedTagRE = /^(slot|partial|component)$/i; + + var isUnknownElement = undefined; + if ('development' !== 'production') { + isUnknownElement = function (el, tag){ + if (tag.indexOf('-') > -1) { + // http://stackoverflow.com/a/28210364/1070244 + return el.constructor === window.HTMLUnknownElement || el.constructor === window.HTMLElement; + } else { + return (/HTMLUnknownElement/.test(el.toString()) && + // Chrome returns unknown for several HTML5 elements. + // https://code.google.com/p/chromium/issues/detail?id=540526 + !/^(data|time|rtc|rb)$/.test(tag) + ); + } + }; + } /** * Check if an element is a component, if yes return its @@ -1482,11 +1893,11 @@ if (is) { return is; } else if ('development' !== 'production') { - if (tag.indexOf('-') > -1 || /HTMLUnknownElement/.test(el.toString()) && - // Chrome returns unknown for several HTML5 elements. - // https://code.google.com/p/chromium/issues/detail?id=540526 - !/^(data|time|rtc|rb)$/.test(tag)) { - warn('Unknown custom element: <' + tag + '> - did you ' + 'register the component correctly?'); + var expectedTag = options._componentNameMap && options._componentNameMap[tag]; + if (expectedTag) { + warn('Unknown custom element: <' + tag + '> - ' + 'did you mean <' + expectedTag + '>? ' + 'HTML is case-insensitive, remember to use kebab-case in templates.'); + } else if (isUnknownElement(el, tag)) { + warn('Unknown custom element: <' + tag + '> - did you ' + 'register the component correctly? For recursive components, ' + 'make sure to provide the "name" option.'); } } } @@ -1526,7 +1937,35 @@ function initProp(vm, prop, value){ var key = prop.path; value = coerceProp(prop, value); - vm[key] = vm._data[key] = assertProp(prop, value) ? value : undefined; + if (value === undefined) { + value = getPropDefaultValue(vm, prop.options); + } + if (assertProp(prop, value)) { + defineReactive(vm, key, value, true /* doNotObserve */); + } + } + + /** + * Get the default value of a prop. + * + * @param {Vue} vm + * @param {Object} options + * @return {*} + */ + + function getPropDefaultValue(vm, options){ + // no default, return undefined + if (!hasOwn(options, 'default')) { + // absent boolean value defaults to false + return options.type === Boolean ? false : undefined; + } + var def = options['default']; + // warn against non-factory defaults for Object & Array + if (isObject(def)) { + 'development' !== 'production' && warn('Object/Array as default prop values will be shared ' + 'across multiple instances. Use a factory function ' + 'to return the default value instead.'); + } + // call factory function for non-Function types + return typeof def === 'function' && options.type !== Function ? def.call(vm) : def; } /** @@ -1537,9 +1976,10 @@ */ function assertProp(prop, value){ - // if a prop is not provided and is not required, - // skip the check. - if (prop.raw === null && !prop.required) { + if (!prop.options.required && ( // non-required + prop.raw === null || // abscent + value == null) // null or undefined + ) { return true; } var options = prop.options; @@ -1575,7 +2015,7 @@ } var validator = options.validator; if (validator) { - if (!validator.call(null, value)) { + if (!validator(value)) { 'development' !== 'production' && warn('Invalid prop: custom validator check failed for ' + prop.path + '="' + prop.raw + '"'); return false; } @@ -1697,7 +2137,7 @@ * Hooks and param attributes are merged as arrays. */ - strats.init = strats.created = strats.ready = strats.attached = strats.detached = strats.beforeCompile = strats.compiled = strats.beforeDestroy = strats.destroyed = function (parentVal, childVal){ + strats.init = strats.created = strats.ready = strats.attached = strats.detached = strats.beforeCompile = strats.compiled = strats.beforeDestroy = strats.destroyed = strats.activate = function (parentVal, childVal){ return childVal ? parentVal ? parentVal.concat(childVal) : isArray(childVal) ? childVal : [childVal] : parentVal; }; @@ -1781,14 +2221,22 @@ function guardComponents(options){ if (options.components) { var components = options.components = guardArrayAssets(options.components); - var def; var ids = Object.keys(components); + var def; + if ('development' !== 'production') { + var map = options._componentNameMap = {}; + } for (var i = 0, l = ids.length; i < l; i++) { var key = ids[i]; if (commonTagRE.test(key) || reservedTagRE.test(key)) { 'development' !== 'production' && warn('Do not use built-in or reserved HTML elements as component ' + 'id: ' + key); continue; } + // record a all lowercase <-> kebab-case mapping for + // possible custom element case error warning + if ('development' !== 'production') { + map[key.replace(/-/g, '').toLowerCase()] = hyphenate(key); + } def = components[key]; if (isPlainObject(def)) { components[key] = Vue.extend(def); @@ -1905,12 +2353,16 @@ */ function resolveAsset(options, type, id){ + /* istanbul ignore if */ + if (typeof id !== 'string') { + return; + } var assets = options[type]; var camelizedId; return assets[id] || - // camelCase ID + // camelCase ID assets[camelizedId = camelize(id)] || - // Pascal Case ID + // Pascal Case ID assets[camelizedId.charAt(0).toUpperCase() + camelizedId.slice(1)]; } @@ -1924,340 +2376,6 @@ } } - var arrayProto = Array.prototype; - var arrayMethods = Object.create(arrayProto) - - /** - * Intercept mutating methods and emit events - */ - - ; - ['push', 'pop', 'shift', 'unshift', 'splice', 'sort', 'reverse'].forEach(function (method){ - // cache original method - var original = arrayProto[method]; - def(arrayMethods, method, function mutator(){ - // avoid leaking arguments: - // http://jsperf.com/closure-with-arguments - var i = arguments.length; - var args = new Array(i); - while (i--) { - args[i] = arguments[i]; - } - var result = original.apply(this, args); - var ob = this.__ob__; - var inserted; - switch (method) { - case 'push': - inserted = args; - break; - case 'unshift': - inserted = args; - break; - case 'splice': - inserted = args.slice(2); - break; - } - if (inserted) ob.observeArray(inserted); - // notify change - ob.dep.notify(); - return result; - }); - }); - - /** - * Swap the element at the given index with a new value - * and emits corresponding event. - * - * @param {Number} index - * @param {*} val - * @return {*} - replaced element - */ - - def(arrayProto, '$set', function $set(index, val){ - if (index >= this.length) { - this.length = Number(index) + 1; - } - return this.splice(index, 1, val)[0]; - }); - - /** - * Convenience method to remove the element at given index. - * - * @param {Number} index - * @param {*} val - */ - - def(arrayProto, '$remove', function $remove(item){ - /* istanbul ignore if */ - if (!this.length) return; - var index = indexOf(this, item); - if (index > -1) { - return this.splice(index, 1); - } - }); - - var uid$3 = 0; - - /** - * A dep is an observable that can have multiple - * directives subscribing to it. - * - * @constructor - */ - function Dep(){ - this.id = uid$3++; - this.subs = []; - } - - // the current target watcher being evaluated. - // this is globally unique because there could be only one - // watcher being evaluated at any time. - Dep.target = null; - - /** - * Add a directive subscriber. - * - * @param {Directive} sub - */ - - Dep.prototype.addSub = function (sub){ - this.subs.push(sub); - }; - - /** - * Remove a directive subscriber. - * - * @param {Directive} sub - */ - - Dep.prototype.removeSub = function (sub){ - this.subs.$remove(sub); - }; - - /** - * Add self as a dependency to the target watcher. - */ - - Dep.prototype.depend = function (){ - Dep.target.addDep(this); - }; - - /** - * Notify all subscribers of a new value. - */ - - Dep.prototype.notify = function (){ - // stablize the subscriber list first - var subs = toArray(this.subs); - for (var i = 0, l = subs.length; i < l; i++) { - subs[i].update(); - } - }; - - var arrayKeys = Object.getOwnPropertyNames(arrayMethods); - - /** - * Observer class that are attached to each observed - * object. Once attached, the observer converts target - * object's property keys into getter/setters that - * collect dependencies and dispatches updates. - * - * @param {Array|Object} value - * @constructor - */ - - function Observer(value){ - this.value = value; - this.dep = new Dep(); - def(value, '__ob__', this); - if (isArray(value)) { - var augment = hasProto ? protoAugment : copyAugment; - augment(value, arrayMethods, arrayKeys); - this.observeArray(value); - } else { - this.walk(value); - } - } - - // Instance methods - - /** - * Walk through each property and convert them into - * getter/setters. This method should only be called when - * value type is Object. - * - * @param {Object} obj - */ - - Observer.prototype.walk = function (obj){ - var keys = Object.keys(obj); - for (var i = 0, l = keys.length; i < l; i++) { - this.convert(keys[i], obj[keys[i]]); - } - }; - - /** - * Observe a list of Array items. - * - * @param {Array} items - */ - - Observer.prototype.observeArray = function (items){ - for (var i = 0, l = items.length; i < l; i++) { - observe(items[i]); - } - }; - - /** - * Convert a property into getter/setter so we can emit - * the events when the property is accessed/changed. - * - * @param {String} key - * @param {*} val - */ - - Observer.prototype.convert = function (key, val){ - defineReactive(this.value, key, val); - }; - - /** - * Add an owner vm, so that when $set/$delete mutations - * happen we can notify owner vms to proxy the keys and - * digest the watchers. This is only called when the object - * is observed as an instance's root $data. - * - * @param {Vue} vm - */ - - Observer.prototype.addVm = function (vm){ - (this.vms || (this.vms = [])).push(vm); - }; - - /** - * Remove an owner vm. This is called when the object is - * swapped out as an instance's $data object. - * - * @param {Vue} vm - */ - - Observer.prototype.removeVm = function (vm){ - this.vms.$remove(vm); - }; - - // helpers - - /** - * Augment an target Object or Array by intercepting - * the prototype chain using __proto__ - * - * @param {Object|Array} target - * @param {Object} proto - */ - - function protoAugment(target, src){ - target.__proto__ = src; - } - - /** - * Augment an target Object or Array by defining - * hidden properties. - * - * @param {Object|Array} target - * @param {Object} proto - */ - - function copyAugment(target, src, keys){ - for (var i = 0, l = keys.length; i < l; i++) { - var key = keys[i]; - def(target, key, src[key]); - } - } - - /** - * Attempt to create an observer instance for a value, - * returns the new observer if successfully observed, - * or the existing observer if the value already has one. - * - * @param {*} value - * @param {Vue} [vm] - * @return {Observer|undefined} - * @static - */ - - function observe(value, vm){ - if (!value || typeof value !== 'object') { - return; - } - var ob; - if (hasOwn(value, '__ob__') && value.__ob__ instanceof Observer) { - ob = value.__ob__; - } else if ((isArray(value) || isPlainObject(value)) && Object.isExtensible(value) && !value._isVue) { - ob = new Observer(value); - } - if (ob && vm) { - ob.addVm(vm); - } - return ob; - } - - /** - * Define a reactive property on an Object. - * - * @param {Object} obj - * @param {String} key - * @param {*} val - */ - - function defineReactive(obj, key, val){ - var dep = new Dep(); - - // cater for pre-defined getter/setters - var getter, setter; - if (config.convertAllProperties) { - var property = Object.getOwnPropertyDescriptor(obj, key); - if (property && property.configurable === false) { - return; - } - getter = property && property.get; - setter = property && property.set; - } - - var childOb = observe(val); - Object.defineProperty(obj, key, { - enumerable: true, - configurable: true, - get: function reactiveGetter(){ - var value = getter ? getter.call(obj) : val; - if (Dep.target) { - dep.depend(); - if (childOb) { - childOb.dep.depend(); - } - if (isArray(value)) { - for (var e, i = 0, l = value.length; i < l; i++) { - e = value[i]; - e && e.__ob__ && e.__ob__.dep.depend(); - } - } - } - return value; - }, - set: function reactiveSetter(newVal){ - var value = getter ? getter.call(obj) : val; - if (newVal === value) { - return; - } - if (setter) { - setter.call(obj, newVal); - } else { - val = newVal; - } - childOb = observe(newVal); - dep.notify(); - } - }); - } - var util = Object.freeze({ defineReactive: defineReactive, set: set, @@ -2272,7 +2390,7 @@ camelize: camelize, hyphenate: hyphenate, classify: classify, - bind: bind$1, + bind: bind, toArray: toArray, extend: extend, isObject: isObject, @@ -2285,6 +2403,7 @@ isArray: isArray, hasProto: hasProto, inBrowser: inBrowser, + devtools: devtools, isIE9: isIE9, isAndroid: isAndroid, get transitionProp(){ return transitionProp; }, @@ -2302,7 +2421,7 @@ remove: remove, prepend: prepend, replace: replace, - on: on$1, + on: on, off: off, setClass: setClass, addClass: addClass, @@ -2314,6 +2433,8 @@ findRef: findRef, mapNodeRange: mapNodeRange, removeNodeRange: removeNodeRange, + isFragment: isFragment, + getOuterHTML: getOuterHTML, mergeOptions: mergeOptions, resolveAsset: resolveAsset, assertAsset: assertAsset, @@ -2329,7 +2450,6 @@ var uid = 0; function initMixin(Vue){ - /** * The main init sequence. This is called for every * instance, including ones that are created from extended @@ -2342,7 +2462,6 @@ */ Vue.prototype._init = function (options){ - options = options || {}; this.$el = null; @@ -2371,7 +2490,7 @@ this._fragmentEnd = null; // @type {Text|Comment} // lifecycle state - this._isCompiled = this._isDestroyed = this._isReady = this._isAttached = this._isBeingDestroyed = false; + this._isCompiled = this._isDestroyed = this._isReady = this._isAttached = this._isBeingDestroyed = this._vForRemoving = false; this._unlinkFn = null; // context: @@ -2411,6 +2530,11 @@ // it will be filled up in _initScope(). this._data = {}; + // save raw constructor data before merge + // so that we know which properties are provided at + // instantiation. + this._runtimeData = options.data; + // call init hook this._callHook('init'); @@ -2768,12 +2892,12 @@ var allowedKeywordsRE = new RegExp('^(' + allowedKeywords.replace(/,/g, '\\b|') + '\\b)'); // keywords that don't make sense inside expressions - var improperKeywords = 'break,case,class,catch,const,continue,debugger,default,' + 'delete,do,else,export,extends,finally,for,function,if,' + 'import,in,instanceof,let,return,super,switch,throw,try,' + 'var,while,with,yield,enum,await,implements,package,' + 'proctected,static,interface,private,public'; + var improperKeywords = 'break,case,class,catch,const,continue,debugger,default,' + 'delete,do,else,export,extends,finally,for,function,if,' + 'import,in,instanceof,let,return,super,switch,throw,try,' + 'var,while,with,yield,enum,await,implements,package,' + 'protected,static,interface,private,public'; var improperKeywordsRE = new RegExp('^(' + improperKeywords.replace(/,/g, '\\b|') + '\\b)'); var wsRE = /\s/g; var newlineRE = /\n/g; - var saveRE = /[\{,]\s*[\w\$_]+\s*:|('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*")|new |typeof |void /g; + var saveRE = /[\{,]\s*[\w\$_]+\s*:|('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`)|new |typeof |void /g; var restoreRE = /"(\d+)"/g; var pathTestRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\]|\[\d+\]|\[[A-Za-z_$][\w$]*\])*$/; var identRE = /[^\w$\.](?:[A-Za-z_$][\w$]*)/g; @@ -2876,7 +3000,9 @@ function makeGetterFn(body){ try { + /* eslint-disable no-new-func */ return new Function('scope', 'return ' + body + ';'); + /* eslint-enable no-new-func */ } catch (e) { 'development' !== 'production' && warn('Invalid expression. ' + 'Generated function body: ' + body); } @@ -2940,9 +3066,9 @@ function isSimplePath(exp){ return pathTestRE.test(exp) && - // don't treat true/false as paths + // don't treat true/false as paths !booleanLiteralRE.test(exp) && - // Math constants e.g. Math.PI, Math.E etc. + // Math constants e.g. Math.PI, Math.E etc. exp.slice(0, 5) !== 'Math.'; } @@ -2957,6 +3083,8 @@ // before user watchers so that when user watchers are // triggered, the DOM would have already been in updated // state. + + var queueIndex; var queue = []; var userQueue = []; var has = {}; @@ -2986,10 +3114,8 @@ runBatcherQueue(userQueue); // dev tool hook /* istanbul ignore if */ - if ('development' !== 'production') { - if (inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__) { - window.__VUE_DEVTOOLS_GLOBAL_HOOK__.emit('flush'); - } + if (devtools && config.devtools) { + devtools.emit('flush'); } resetBatcherState(); } @@ -3003,8 +3129,8 @@ function runBatcherQueue(queue){ // do not cache length because more watchers might be pushed // as we run existing watchers - for (var i = 0; i < queue.length; i++) { - var watcher = queue[i]; + for (queueIndex = 0; queueIndex < queue.length; queueIndex++) { + var watcher = queue[queueIndex]; var id = watcher.id; has[id] = null; watcher.run(); @@ -3033,20 +3159,20 @@ function pushWatcher(watcher){ var id = watcher.id; if (has[id] == null) { - // if an internal watcher is pushed, but the internal - // queue is already depleted, we run it immediately. if (internalQueueDepleted && !watcher.user) { - watcher.run(); - return; - } - // push watcher into appropriate queue - var q = watcher.user ? userQueue : queue; - has[id] = q.length; - q.push(watcher); - // queue the flush - if (!waiting) { - waiting = true; - nextTick(flushBatcherQueue); + // an internal watcher triggered by a user watcher... + // let's run it immediately after current user watcher is done. + userQueue.splice(queueIndex + 1, 0, watcher); + } else { + // push watcher into appropriate queue + var q = watcher.user ? userQueue : queue; + has[id] = q.length; + q.push(watcher); + // queue the flush + if (!waiting) { + waiting = true; + nextTick(flushBatcherQueue); + } } } } @@ -3080,13 +3206,15 @@ var isFn = typeof expOrFn === 'function'; this.vm = vm; vm._watchers.push(this); - this.expression = isFn ? expOrFn.toString() : expOrFn; + this.expression = expOrFn; this.cb = cb; this.id = ++uid$2; // uid for batching this.active = true; this.dirty = this.lazy; // for lazy watchers - this.deps = Object.create(null); - this.newDeps = null; + this.deps = []; + this.newDeps = []; + this.depIds = Object.create(null); + this.newDepIds = null; this.prevError = null; // for async error stacks // parse expression for getter/setter if (isFn) { @@ -3103,23 +3231,6 @@ this.queued = this.shallow = false; } - /** - * Add a dependency to this directive. - * - * @param {Dep} dep - */ - - Watcher.prototype.addDep = function (dep){ - var id = dep.id; - if (!this.newDeps[id]) { - this.newDeps[id] = dep; - if (!this.deps[id]) { - this.deps[id] = dep; - dep.addSub(this); - } - } - }; - /** * Evaluate the getter, and re-collect dependencies. */ @@ -3195,7 +3306,25 @@ Watcher.prototype.beforeGet = function (){ Dep.target = this; - this.newDeps = Object.create(null); + this.newDepIds = Object.create(null); + this.newDeps.length = 0; + }; + + /** + * Add a dependency to this directive. + * + * @param {Dep} dep + */ + + Watcher.prototype.addDep = function (dep){ + var id = dep.id; + if (!this.newDepIds[id]) { + this.newDepIds[id] = true; + this.newDeps.push(dep); + if (!this.depIds[id]) { + dep.addSub(this); + } + } }; /** @@ -3204,15 +3333,17 @@ Watcher.prototype.afterGet = function (){ Dep.target = null; - var ids = Object.keys(this.deps); - var i = ids.length; + var i = this.deps.length; while (i--) { - var id = ids[i]; - if (!this.newDeps[id]) { - this.deps[id].removeSub(this); + var dep = this.deps[i]; + if (!this.newDepIds[dep.id]) { + dep.removeSub(this); } } + this.depIds = this.newDepIds; + var tmp = this.deps; this.deps = this.newDeps; + this.newDeps = tmp; }; /** @@ -3250,10 +3381,10 @@ if (this.active) { var value = this.get(); if (value !== this.value || - // Deep watchers and watchers on Object/Arrays should fire even - // when the value is the same, because the value may - // have mutated; but only do so if this is a - // non-shallow update (caused by a vm digest). + // Deep watchers and watchers on Object/Arrays should fire even + // when the value is the same, because the value may + // have mutated; but only do so if this is a + // non-shallow update (caused by a vm digest). (isObject(value) || this.deep) && !this.shallow) { // set new value var oldValue = this.value; @@ -3300,10 +3431,9 @@ */ Watcher.prototype.depend = function (){ - var depIds = Object.keys(this.deps); - var i = depIds.length; + var i = this.deps.length; while (i--) { - this.deps[depIds[i]].depend(); + this.deps[i].depend(); } }; @@ -3314,15 +3444,15 @@ Watcher.prototype.teardown = function (){ if (this.active) { // remove self from vm's watcher list - // we can skip this if the vm if being destroyed - // which can improve teardown performance. - if (!this.vm._isBeingDestroyed) { + // this is a somewhat expensive operation so we skip it + // if the vm is being destroyed or is performing a v-for + // re-render (the watcher list is then filtered by v-for). + if (!this.vm._isBeingDestroyed && !this.vm._vForRemoving) { this.vm._watchers.$remove(this); } - var depIds = Object.keys(this.deps); - var i = depIds.length; + var i = this.deps.length; while (i--) { - this.deps[depIds[i]].removeSub(this); + this.deps[i].removeSub(this); } this.active = false; this.vm = this.cb = this.value = null; @@ -3349,817 +3479,14 @@ } } - var cloak = { - bind: function bind(){ - var el = this.el; - this.vm.$once('pre-hook:compiled', function (){ - el.removeAttribute('v-cloak'); - }); - } - }; - - var ref = { - bind: function bind(){ - 'development' !== 'production' && warn('v-ref:' + this.arg + ' must be used on a child ' + 'component. Found on <' + this.el.tagName.toLowerCase() + '>.'); - } - }; - - var ON = 700; - var MODEL = 800; - var BIND = 850; - var TRANSITION = 1100; - var EL = 1500; - var COMPONENT = 1500; - var PARTIAL = 1750; - var SLOT = 1750; - var FOR = 2000; - var IF = 2000; - - var el = { - - priority: EL, + var text$1 = { bind: function bind(){ - /* istanbul ignore if */ - if (!this.arg) { - return; - } - var id = this.id = camelize(this.arg); - var refs = (this._scope || this.vm).$els; - if (hasOwn(refs, id)) { - refs[id] = this.el; - } else { - defineReactive(refs, id, this.el); - } - }, - - unbind: function unbind(){ - var refs = (this._scope || this.vm).$els; - if (refs[this.id] === this.el) { - refs[this.id] = null; - } - } - }; - - var prefixes = ['-webkit-', '-moz-', '-ms-']; - var camelPrefixes = ['Webkit', 'Moz', 'ms']; - var importantRE = /!important;?$/; - var propCache = Object.create(null); - - var testEl = null; - - var style = { - - deep: true, - - update: function update(value){ - if (typeof value === 'string') { - this.el.style.cssText = value; - } else if (isArray(value)) { - this.handleObject(value.reduce(extend, {})); - } else { - this.handleObject(value || {}); - } - }, - - handleObject: function handleObject(value){ - // cache object styles so that only changed props - // are actually updated. - var cache = this.cache || (this.cache = {}); - var name, val; - for (name in cache) { - if (!(name in value)) { - this.handleSingle(name, null); - delete cache[name]; - } - } - for (name in value) { - val = value[name]; - if (val !== cache[name]) { - cache[name] = val; - this.handleSingle(name, val); - } - } - }, - - handleSingle: function handleSingle(prop, value){ - prop = normalize(prop); - if (!prop) return; // unsupported prop - // cast possible numbers/booleans into strings - if (value != null) value += ''; - if (value) { - var isImportant = importantRE.test(value) ? 'important' : ''; - if (isImportant) { - value = value.replace(importantRE, '').trim(); - } - this.el.style.setProperty(prop, value, isImportant); - } else { - this.el.style.removeProperty(prop); - } - } - - }; - - /** - * Normalize a CSS property name. - * - cache result - * - auto prefix - * - camelCase -> dash-case - * - * @param {String} prop - * @return {String} - */ - - function normalize(prop){ - if (propCache[prop]) { - return propCache[prop]; - } - var res = prefix(prop); - propCache[prop] = propCache[res] = res; - return res; - } - - /** - * Auto detect the appropriate prefix for a CSS property. - * https://gist.github.com/paulirish/523692 - * - * @param {String} prop - * @return {String} - */ - - function prefix(prop){ - prop = hyphenate(prop); - var camel = camelize(prop); - var upper = camel.charAt(0).toUpperCase() + camel.slice(1); - if (!testEl) { - testEl = document.createElement('div'); - } - if (camel in testEl.style) { - return prop; - } - var i = prefixes.length; - var prefixed; - while (i--) { - prefixed = camelPrefixes[i] + upper; - if (prefixed in testEl.style) { - return prefixes[i] + prop; - } - } - } - - // xlink - var xlinkNS = 'http://www.w3.org/1999/xlink'; - var xlinkRE = /^xlink:/; - - // check for attributes that prohibit interpolations - var disallowedInterpAttrRE = /^v-|^:|^@|^(is|transition|transition-mode|debounce|track-by|stagger|enter-stagger|leave-stagger)$/; - - // these attributes should also set their corresponding properties - // because they only affect the initial state of the element - var attrWithPropsRE = /^(value|checked|selected|muted)$/; - - // these attributes should set a hidden property for - // binding v-model to object values - var modelProps = { - value: '_value', - 'true-value': '_trueValue', - 'false-value': '_falseValue' - }; - - var bind = { - - priority: BIND, - - bind: function bind(){ - var attr = this.arg; - var tag = this.el.tagName; - // should be deep watch on object mode - if (!attr) { - this.deep = true; - } - // handle interpolation bindings - var descriptor = this.descriptor; - var tokens = descriptor.interp; - if (tokens) { - // handle interpolations with one-time tokens - if (descriptor.hasOneTime) { - this.expression = tokensToExp(tokens, this._scope || this.vm); - } - - // only allow binding on native attributes - if (disallowedInterpAttrRE.test(attr) || attr === 'name' && (tag === 'PARTIAL' || tag === 'SLOT')) { - 'development' !== 'production' && warn(attr + '="' + descriptor.raw + '": ' + 'attribute interpolation is not allowed in Vue.js ' + 'directives and special attributes.'); - this.el.removeAttribute(attr); - this.invalid = true; - } - - /* istanbul ignore if */ - if ('development' !== 'production') { - var raw = attr + '="' + descriptor.raw + '": '; - // warn src - if (attr === 'src') { - warn(raw + 'interpolation in "src" attribute will cause ' + 'a 404 request. Use v-bind:src instead.'); - } - - // warn style - if (attr === 'style') { - warn(raw + 'interpolation in "style" attribute will cause ' + 'the attribute to be discarded in Internet Explorer. ' + 'Use v-bind:style instead.'); - } - } - } + this.attr = this.el.nodeType === 3 ? 'data' : 'textContent'; }, update: function update(value){ - if (this.invalid) { - return; - } - var attr = this.arg; - if (this.arg) { - this.handleSingle(attr, value); - } else { - this.handleObject(value || {}); - } - }, - - // share object handler with v-bind:class - handleObject: style.handleObject, - - handleSingle: function handleSingle(attr, value){ - var el = this.el; - var interp = this.descriptor.interp; - if (!interp && attrWithPropsRE.test(attr) && attr in el) { - el[attr] = attr === 'value' ? value == null // IE9 will set input.value to "null" for null... - ? '' : value : value; - } - // set model props - var modelProp = modelProps[attr]; - if (!interp && modelProp) { - el[modelProp] = value; - // update v-model if present - var model = el.__v_model; - if (model) { - model.listener(); - } - } - // do not set value attribute for textarea - if (attr === 'value' && el.tagName === 'TEXTAREA') { - el.removeAttribute(attr); - return; - } - // update attribute - if (value != null && value !== false) { - if (attr === 'class') { - // handle edge case #1960: - // class interpolation should not overwrite Vue transition class - if (el.__v_trans) { - value += ' ' + el.__v_trans.id + '-transition'; - } - setClass(el, value); - } else if (xlinkRE.test(attr)) { - el.setAttributeNS(xlinkNS, attr, value); - } else { - el.setAttribute(attr, value); - } - } else { - el.removeAttribute(attr); - } - } - }; - - // keyCode aliases - var keyCodes = { - esc: 27, - tab: 9, - enter: 13, - space: 32, - 'delete': 46, - up: 38, - left: 37, - right: 39, - down: 40 - }; - - function keyFilter(handler, keys){ - var codes = keys.map(function (key){ - var charCode = key.charCodeAt(0); - if (charCode > 47 && charCode < 58) { - return parseInt(key, 10); - } - if (key.length === 1) { - charCode = key.toUpperCase().charCodeAt(0); - if (charCode > 64 && charCode < 91) { - return charCode; - } - } - return keyCodes[key]; - }); - return function keyHandler(e){ - if (codes.indexOf(e.keyCode) > -1) { - return handler.call(this, e); - } - }; - } - - function stopFilter(handler){ - return function stopHandler(e){ - e.stopPropagation(); - return handler.call(this, e); - }; - } - - function preventFilter(handler){ - return function preventHandler(e){ - e.preventDefault(); - return handler.call(this, e); - }; - } - - var on = { - - acceptStatement: true, - priority: ON, - - bind: function bind(){ - // deal with iframes - if (this.el.tagName === 'IFRAME' && this.arg !== 'load') { - var self = this; - this.iframeBind = function (){ - on$1(self.el.contentWindow, self.arg, self.handler); - }; - this.on('load', this.iframeBind); - } - }, - - update: function update(handler){ - // stub a noop for v-on with no value, - // e.g. @mousedown.prevent - if (!this.descriptor.raw) { - handler = function (){}; - } - - if (typeof handler !== 'function') { - 'development' !== 'production' && warn('v-on:' + this.arg + '="' + this.expression + '" expects a function value, ' + 'got ' + handler); - return; - } - - // apply modifiers - if (this.modifiers.stop) { - handler = stopFilter(handler); - } - if (this.modifiers.prevent) { - handler = preventFilter(handler); - } - // key filter - var keys = Object.keys(this.modifiers).filter(function (key){ - return key !== 'stop' && key !== 'prevent'; - }); - if (keys.length) { - handler = keyFilter(handler, keys); - } - - this.reset(); - this.handler = handler; - - if (this.iframeBind) { - this.iframeBind(); - } else { - on$1(this.el, this.arg, this.handler); - } - }, - - reset: function reset(){ - var el = this.iframeBind ? this.el.contentWindow : this.el; - if (this.handler) { - off(el, this.arg, this.handler); - } - }, - - unbind: function unbind(){ - this.reset(); - } - }; - - var checkbox = { - - bind: function bind(){ - var self = this; - var el = this.el; - - this.getValue = function (){ - return el.hasOwnProperty('_value') ? el._value : self.params.number ? toNumber(el.value) : el.value; - }; - - function getBooleanValue(){ - var val = el.checked; - if (val && el.hasOwnProperty('_trueValue')) { - return el._trueValue; - } - if (!val && el.hasOwnProperty('_falseValue')) { - return el._falseValue; - } - return val; - } - - this.listener = function (){ - var model = self._watcher.value; - if (isArray(model)) { - var val = self.getValue(); - if (el.checked) { - if (indexOf(model, val) < 0) { - model.push(val); - } - } else { - model.$remove(val); - } - } else { - self.set(getBooleanValue()); - } - }; - - this.on('change', this.listener); - if (el.hasAttribute('checked')) { - this.afterBind = this.listener; - } - }, - - update: function update(value){ - var el = this.el; - if (isArray(value)) { - el.checked = indexOf(value, this.getValue()) > -1; - } else { - if (el.hasOwnProperty('_trueValue')) { - el.checked = looseEqual(value, el._trueValue); - } else { - el.checked = !!value; - } - } - } - }; - - var select = { - - bind: function bind(){ - var self = this; - var el = this.el; - - // method to force update DOM using latest value. - this.forceUpdate = function (){ - if (self._watcher) { - self.update(self._watcher.get()); - } - }; - - // check if this is a multiple select - var multiple = this.multiple = el.hasAttribute('multiple'); - - // attach listener - this.listener = function (){ - var value = getValue(el, multiple); - value = self.params.number ? isArray(value) ? value.map(toNumber) : toNumber(value) : value; - self.set(value); - }; - this.on('change', this.listener); - - // if has initial value, set afterBind - var initValue = getValue(el, multiple, true); - if (multiple && initValue.length || !multiple && initValue !== null) { - this.afterBind = this.listener; - } - - // All major browsers except Firefox resets - // selectedIndex with value -1 to 0 when the element - // is appended to a new parent, therefore we have to - // force a DOM update whenever that happens... - this.vm.$on('hook:attached', this.forceUpdate); - }, - - update: function update(value){ - var el = this.el; - el.selectedIndex = -1; - var multi = this.multiple && isArray(value); - var options = el.options; - var i = options.length; - var op, val; - while (i--) { - op = options[i]; - val = op.hasOwnProperty('_value') ? op._value : op.value; - /* eslint-disable eqeqeq */ - op.selected = multi ? indexOf$1(value, val) > -1 : looseEqual(value, val); - /* eslint-enable eqeqeq */ - } - }, - - unbind: function unbind(){ - /* istanbul ignore next */ - this.vm.$off('hook:attached', this.forceUpdate); - } - }; - - /** - * Get select value - * - * @param {SelectElement} el - * @param {Boolean} multi - * @param {Boolean} init - * @return {Array|*} - */ - - function getValue(el, multi, init){ - var res = multi ? [] : null; - var op, val, selected; - for (var i = 0, l = el.options.length; i < l; i++) { - op = el.options[i]; - selected = init ? op.hasAttribute('selected') : op.selected; - if (selected) { - val = op.hasOwnProperty('_value') ? op._value : op.value; - if (multi) { - res.push(val); - } else { - return val; - } - } - } - return res; - } - - /** - * Native Array.indexOf uses strict equal, but in this - * case we need to match string/numbers with custom equal. - * - * @param {Array} arr - * @param {*} val - */ - - function indexOf$1(arr, val){ - var i = arr.length; - while (i--) { - if (looseEqual(arr[i], val)) { - return i; - } - } - return -1; - } - - var radio = { - - bind: function bind(){ - var self = this; - var el = this.el; - - this.getValue = function (){ - // value overwrite via v-bind:value - if (el.hasOwnProperty('_value')) { - return el._value; - } - var val = el.value; - if (self.params.number) { - val = toNumber(val); - } - return val; - }; - - this.listener = function (){ - self.set(self.getValue()); - }; - this.on('change', this.listener); - - if (el.hasAttribute('checked')) { - this.afterBind = this.listener; - } - }, - - update: function update(value){ - this.el.checked = looseEqual(value, this.getValue()); - } - }; - - var text$2 = { - - bind: function bind(){ - var self = this; - var el = this.el; - var isRange = el.type === 'range'; - var lazy = this.params.lazy; - var number = this.params.number; - var debounce = this.params.debounce; - - // handle composition events. - // http://blog.evanyou.me/2014/01/03/composition-event/ - // skip this for Android because it handles composition - // events quite differently. Android doesn't trigger - // composition events for language input methods e.g. - // Chinese, but instead triggers them for spelling - // suggestions... (see Discussion/#162) - var composing = false; - if (!isAndroid && !isRange) { - this.on('compositionstart', function (){ - composing = true; - }); - this.on('compositionend', function (){ - composing = false; - // in IE11 the "compositionend" event fires AFTER - // the "input" event, so the input handler is blocked - // at the end... have to call it here. - // - // #1327: in lazy mode this is unecessary. - if (!lazy) { - self.listener(); - } - }); - } - - // prevent messing with the input when user is typing, - // and force update on blur. - this.focused = false; - if (!isRange && !lazy) { - this.on('focus', function (){ - self.focused = true; - }); - this.on('blur', function (){ - self.focused = false; - // do not sync value after fragment removal (#2017) - if (!self._frag || self._frag.inserted) { - self.rawListener(); - } - }); - } - - // Now attach the main listener - this.listener = this.rawListener = function (){ - if (composing || !self._bound) { - return; - } - var val = number || isRange ? toNumber(el.value) : el.value; - self.set(val); - // force update on next tick to avoid lock & same value - // also only update when user is not typing - nextTick(function (){ - if (self._bound && !self.focused) { - self.update(self._watcher.value); - } - }); - }; - - // apply debounce - if (debounce) { - this.listener = _debounce(this.listener, debounce); - } - - // Support jQuery events, since jQuery.trigger() doesn't - // trigger native events in some cases and some plugins - // rely on $.trigger() - // - // We want to make sure if a listener is attached using - // jQuery, it is also removed with jQuery, that's why - // we do the check for each directive instance and - // store that check result on itself. This also allows - // easier test coverage control by unsetting the global - // jQuery variable in tests. - this.hasjQuery = typeof jQuery === 'function'; - if (this.hasjQuery) { - jQuery(el).on('change', this.listener); - if (!lazy) { - jQuery(el).on('input', this.listener); - } - } else { - this.on('change', this.listener); - if (!lazy) { - this.on('input', this.listener); - } - } - - // IE9 doesn't fire input event on backspace/del/cut - if (!lazy && isIE9) { - this.on('cut', function (){ - nextTick(self.listener); - }); - this.on('keyup', function (e){ - if (e.keyCode === 46 || e.keyCode === 8) { - self.listener(); - } - }); - } - - // set initial value if present - if (el.hasAttribute('value') || el.tagName === 'TEXTAREA' && el.value.trim()) { - this.afterBind = this.listener; - } - }, - - update: function update(value){ - this.el.value = _toString(value); - }, - - unbind: function unbind(){ - var el = this.el; - if (this.hasjQuery) { - jQuery(el).off('change', this.listener); - jQuery(el).off('input', this.listener); - } - } - }; - - var handlers = { - text: text$2, - radio: radio, - select: select, - checkbox: checkbox - }; - - var model = { - - priority: MODEL, - twoWay: true, - handlers: handlers, - params: ['lazy', 'number', 'debounce'], - - /** - * Possible elements: - *