PageRenderTime 30ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/files/vue/0.12.6/vue.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 2202 lines | 1172 code | 269 blank | 761 comment | 208 complexity | a5baba801995bd480cee2383ac343706 MD5 | raw file
  1. /**
  2. * Vue.js v0.12.6
  3. * (c) 2015 Evan You
  4. * Released under the MIT License.
  5. */
  6. (function webpackUniversalModuleDefinition(root, factory) {
  7. if(typeof exports === 'object' && typeof module === 'object')
  8. module.exports = factory();
  9. else if(typeof define === 'function' && define.amd)
  10. define(factory);
  11. else if(typeof exports === 'object')
  12. exports["Vue"] = factory();
  13. else
  14. root["Vue"] = factory();
  15. })(this, function() {
  16. return /******/ (function(modules) { // webpackBootstrap
  17. /******/ // The module cache
  18. /******/ var installedModules = {};
  19. /******/ // The require function
  20. /******/ function __webpack_require__(moduleId) {
  21. /******/ // Check if module is in cache
  22. /******/ if(installedModules[moduleId])
  23. /******/ return installedModules[moduleId].exports;
  24. /******/ // Create a new module (and put it into the cache)
  25. /******/ var module = installedModules[moduleId] = {
  26. /******/ exports: {},
  27. /******/ id: moduleId,
  28. /******/ loaded: false
  29. /******/ };
  30. /******/ // Execute the module function
  31. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  32. /******/ // Flag the module as loaded
  33. /******/ module.loaded = true;
  34. /******/ // Return the exports of the module
  35. /******/ return module.exports;
  36. /******/ }
  37. /******/ // expose the modules object (__webpack_modules__)
  38. /******/ __webpack_require__.m = modules;
  39. /******/ // expose the module cache
  40. /******/ __webpack_require__.c = installedModules;
  41. /******/ // __webpack_public_path__
  42. /******/ __webpack_require__.p = "";
  43. /******/ // Load entry module and return exports
  44. /******/ return __webpack_require__(0);
  45. /******/ })
  46. /************************************************************************/
  47. /******/ ([
  48. /* 0 */
  49. /***/ function(module, exports, __webpack_require__) {
  50. var _ = __webpack_require__(1)
  51. var extend = _.extend
  52. /**
  53. * The exposed Vue constructor.
  54. *
  55. * API conventions:
  56. * - public API methods/properties are prefiexed with `$`
  57. * - internal methods/properties are prefixed with `_`
  58. * - non-prefixed properties are assumed to be proxied user
  59. * data.
  60. *
  61. * @constructor
  62. * @param {Object} [options]
  63. * @public
  64. */
  65. function Vue (options) {
  66. this._init(options)
  67. }
  68. /**
  69. * Mixin global API
  70. */
  71. extend(Vue, __webpack_require__(9))
  72. /**
  73. * Vue and every constructor that extends Vue has an
  74. * associated options object, which can be accessed during
  75. * compilation steps as `this.constructor.options`.
  76. *
  77. * These can be seen as the default options of every
  78. * Vue instance.
  79. */
  80. Vue.options = {
  81. replace: true,
  82. directives: __webpack_require__(28),
  83. elementDirectives: __webpack_require__(50),
  84. filters: __webpack_require__(53),
  85. transitions: {},
  86. components: {},
  87. partials: {}
  88. }
  89. /**
  90. * Build up the prototype
  91. */
  92. var p = Vue.prototype
  93. /**
  94. * $data has a setter which does a bunch of
  95. * teardown/setup work
  96. */
  97. Object.defineProperty(p, '$data', {
  98. get: function () {
  99. return this._data
  100. },
  101. set: function (newData) {
  102. if (newData !== this._data) {
  103. this._setData(newData)
  104. }
  105. }
  106. })
  107. /**
  108. * Mixin internal instance methods
  109. */
  110. extend(p, __webpack_require__(55))
  111. extend(p, __webpack_require__(56))
  112. extend(p, __webpack_require__(57))
  113. extend(p, __webpack_require__(58))
  114. extend(p, __webpack_require__(60))
  115. /**
  116. * Mixin public API methods
  117. */
  118. extend(p, __webpack_require__(61))
  119. extend(p, __webpack_require__(62))
  120. extend(p, __webpack_require__(63))
  121. extend(p, __webpack_require__(64))
  122. extend(p, __webpack_require__(65))
  123. module.exports = _.Vue = Vue
  124. /***/ },
  125. /* 1 */
  126. /***/ function(module, exports, __webpack_require__) {
  127. var lang = __webpack_require__(4)
  128. var extend = lang.extend
  129. extend(exports, lang)
  130. extend(exports, __webpack_require__(5))
  131. extend(exports, __webpack_require__(6))
  132. extend(exports, __webpack_require__(2))
  133. extend(exports, __webpack_require__(7))
  134. extend(exports, __webpack_require__(8))
  135. /***/ },
  136. /* 2 */
  137. /***/ function(module, exports, __webpack_require__) {
  138. var _ = __webpack_require__(1)
  139. var config = __webpack_require__(3)
  140. /**
  141. * Assert whether a prop is valid.
  142. *
  143. * @param {Object} prop
  144. * @param {*} value
  145. */
  146. exports.assertProp = function (prop, value) {
  147. var options = prop.options
  148. var type = options.type
  149. var valid = true
  150. var expectedType
  151. if (type) {
  152. if (type === String) {
  153. expectedType = 'string'
  154. valid = typeof value === expectedType
  155. } else if (type === Number) {
  156. expectedType = 'number'
  157. valid = typeof value === 'number'
  158. } else if (type === Boolean) {
  159. expectedType = 'boolean'
  160. valid = typeof value === 'boolean'
  161. } else if (type === Function) {
  162. expectedType = 'function'
  163. valid = typeof value === 'function'
  164. } else if (type === Object) {
  165. expectedType = 'object'
  166. valid = _.isPlainObject(value)
  167. } else if (type === Array) {
  168. expectedType = 'array'
  169. valid = _.isArray(value)
  170. } else {
  171. valid = value instanceof type
  172. }
  173. }
  174. if (!valid) {
  175. _.warn(
  176. 'Invalid prop: type check failed for ' +
  177. prop.path + '="' + prop.raw + '".' +
  178. ' Expected ' + formatType(expectedType) +
  179. ', got ' + formatValue(value) + '.'
  180. )
  181. return false
  182. }
  183. var validator = options.validator
  184. if (validator) {
  185. if (!validator.call(null, value)) {
  186. _.warn(
  187. 'Invalid prop: custom validator check failed for ' +
  188. prop.path + '="' + prop.raw + '"'
  189. )
  190. return false
  191. }
  192. }
  193. return true
  194. }
  195. function formatType (val) {
  196. return val
  197. ? val.charAt(0).toUpperCase() + val.slice(1)
  198. : 'custom type'
  199. }
  200. function formatValue (val) {
  201. return Object.prototype.toString.call(val).slice(8, -1)
  202. }
  203. /**
  204. * Check if an element is a component, if yes return its
  205. * component id.
  206. *
  207. * @param {Element} el
  208. * @param {Object} options
  209. * @return {String|undefined}
  210. */
  211. exports.commonTagRE = /^(div|p|span|img|a|br|ul|ol|li|h1|h2|h3|h4|h5|code|pre)$/
  212. exports.checkComponent = function (el, options) {
  213. var tag = el.tagName.toLowerCase()
  214. if (tag === 'component') {
  215. // dynamic syntax
  216. var exp = el.getAttribute('is')
  217. el.removeAttribute('is')
  218. return exp
  219. } else if (
  220. !exports.commonTagRE.test(tag) &&
  221. _.resolveAsset(options, 'components', tag)
  222. ) {
  223. return tag
  224. /* eslint-disable no-cond-assign */
  225. } else if (tag = _.attr(el, 'component')) {
  226. /* eslint-enable no-cond-assign */
  227. return tag
  228. }
  229. }
  230. /**
  231. * Create an "anchor" for performing dom insertion/removals.
  232. * This is used in a number of scenarios:
  233. * - block instance
  234. * - v-html
  235. * - v-if
  236. * - component
  237. * - repeat
  238. *
  239. * @param {String} content
  240. * @param {Boolean} persist - IE trashes empty textNodes on
  241. * cloneNode(true), so in certain
  242. * cases the anchor needs to be
  243. * non-empty to be persisted in
  244. * templates.
  245. * @return {Comment|Text}
  246. */
  247. exports.createAnchor = function (content, persist) {
  248. return config.debug
  249. ? document.createComment(content)
  250. : document.createTextNode(persist ? ' ' : '')
  251. }
  252. /***/ },
  253. /* 3 */
  254. /***/ function(module, exports, __webpack_require__) {
  255. module.exports = {
  256. /**
  257. * The prefix to look for when parsing directives.
  258. *
  259. * @type {String}
  260. */
  261. prefix: 'v-',
  262. /**
  263. * Whether to print debug messages.
  264. * Also enables stack trace for warnings.
  265. *
  266. * @type {Boolean}
  267. */
  268. debug: false,
  269. /**
  270. * Whether to suppress warnings.
  271. *
  272. * @type {Boolean}
  273. */
  274. silent: false,
  275. /**
  276. * Whether allow observer to alter data objects'
  277. * __proto__.
  278. *
  279. * @type {Boolean}
  280. */
  281. proto: true,
  282. /**
  283. * Whether to parse mustache tags in templates.
  284. *
  285. * @type {Boolean}
  286. */
  287. interpolate: true,
  288. /**
  289. * Whether to use async rendering.
  290. */
  291. async: true,
  292. /**
  293. * Whether to warn against errors caught when evaluating
  294. * expressions.
  295. */
  296. warnExpressionErrors: true,
  297. /**
  298. * Internal flag to indicate the delimiters have been
  299. * changed.
  300. *
  301. * @type {Boolean}
  302. */
  303. _delimitersChanged: true,
  304. /**
  305. * List of asset types that a component can own.
  306. *
  307. * @type {Array}
  308. */
  309. _assetTypes: [
  310. 'component',
  311. 'directive',
  312. 'elementDirective',
  313. 'filter',
  314. 'transition',
  315. 'partial'
  316. ],
  317. /**
  318. * prop binding modes
  319. */
  320. _propBindingModes: {
  321. ONE_WAY: 0,
  322. TWO_WAY: 1,
  323. ONE_TIME: 2
  324. },
  325. /**
  326. * Max circular updates allowed in a batcher flush cycle.
  327. */
  328. _maxUpdateCount: 100
  329. }
  330. /**
  331. * Interpolation delimiters.
  332. * We need to mark the changed flag so that the text parser
  333. * knows it needs to recompile the regex.
  334. *
  335. * @type {Array<String>}
  336. */
  337. var delimiters = ['{{', '}}']
  338. Object.defineProperty(module.exports, 'delimiters', {
  339. get: function () {
  340. return delimiters
  341. },
  342. set: function (val) {
  343. delimiters = val
  344. this._delimitersChanged = true
  345. }
  346. })
  347. /***/ },
  348. /* 4 */
  349. /***/ function(module, exports, __webpack_require__) {
  350. /**
  351. * Check is a string starts with $ or _
  352. *
  353. * @param {String} str
  354. * @return {Boolean}
  355. */
  356. exports.isReserved = function (str) {
  357. var c = (str + '').charCodeAt(0)
  358. return c === 0x24 || c === 0x5F
  359. }
  360. /**
  361. * Guard text output, make sure undefined outputs
  362. * empty string
  363. *
  364. * @param {*} value
  365. * @return {String}
  366. */
  367. exports.toString = function (value) {
  368. return value == null
  369. ? ''
  370. : value.toString()
  371. }
  372. /**
  373. * Check and convert possible numeric numbers before
  374. * setting back to data
  375. *
  376. * @param {*} value
  377. * @return {*|Number}
  378. */
  379. exports.toNumber = function (value) {
  380. return (
  381. isNaN(value) ||
  382. value === null ||
  383. typeof value === 'boolean'
  384. ) ? value
  385. : Number(value)
  386. }
  387. /**
  388. * Convert string boolean literals into real booleans.
  389. *
  390. * @param {*} value
  391. * @return {*|Boolean}
  392. */
  393. exports.toBoolean = function (value) {
  394. return value === 'true'
  395. ? true
  396. : value === 'false'
  397. ? false
  398. : value
  399. }
  400. /**
  401. * Strip quotes from a string
  402. *
  403. * @param {String} str
  404. * @return {String | false}
  405. */
  406. exports.stripQuotes = function (str) {
  407. var a = str.charCodeAt(0)
  408. var b = str.charCodeAt(str.length - 1)
  409. return a === b && (a === 0x22 || a === 0x27)
  410. ? str.slice(1, -1)
  411. : false
  412. }
  413. /**
  414. * Camelize a hyphen-delmited string.
  415. *
  416. * @param {String} str
  417. * @return {String}
  418. */
  419. exports.camelize = function (str) {
  420. return str.replace(/-(\w)/g, toUpper)
  421. }
  422. function toUpper (_, c) {
  423. return c ? c.toUpperCase() : ''
  424. }
  425. /**
  426. * Hyphenate a camelCase string.
  427. *
  428. * @param {String} str
  429. * @return {String}
  430. */
  431. exports.hyphenate = function (str) {
  432. return str
  433. .replace(/([a-z\d])([A-Z])/g, '$1-$2')
  434. .toLowerCase()
  435. }
  436. /**
  437. * Converts hyphen/underscore/slash delimitered names into
  438. * camelized classNames.
  439. *
  440. * e.g. my-component => MyComponent
  441. * some_else => SomeElse
  442. * some/comp => SomeComp
  443. *
  444. * @param {String} str
  445. * @return {String}
  446. */
  447. var classifyRE = /(?:^|[-_\/])(\w)/g
  448. exports.classify = function (str) {
  449. return str.replace(classifyRE, toUpper)
  450. }
  451. /**
  452. * Simple bind, faster than native
  453. *
  454. * @param {Function} fn
  455. * @param {Object} ctx
  456. * @return {Function}
  457. */
  458. exports.bind = function (fn, ctx) {
  459. return function (a) {
  460. var l = arguments.length
  461. return l
  462. ? l > 1
  463. ? fn.apply(ctx, arguments)
  464. : fn.call(ctx, a)
  465. : fn.call(ctx)
  466. }
  467. }
  468. /**
  469. * Convert an Array-like object to a real Array.
  470. *
  471. * @param {Array-like} list
  472. * @param {Number} [start] - start index
  473. * @return {Array}
  474. */
  475. exports.toArray = function (list, start) {
  476. start = start || 0
  477. var i = list.length - start
  478. var ret = new Array(i)
  479. while (i--) {
  480. ret[i] = list[i + start]
  481. }
  482. return ret
  483. }
  484. /**
  485. * Mix properties into target object.
  486. *
  487. * @param {Object} to
  488. * @param {Object} from
  489. */
  490. exports.extend = function (to, from) {
  491. for (var key in from) {
  492. to[key] = from[key]
  493. }
  494. return to
  495. }
  496. /**
  497. * Quick object check - this is primarily used to tell
  498. * Objects from primitive values when we know the value
  499. * is a JSON-compliant type.
  500. *
  501. * @param {*} obj
  502. * @return {Boolean}
  503. */
  504. exports.isObject = function (obj) {
  505. return obj !== null && typeof obj === 'object'
  506. }
  507. /**
  508. * Strict object type check. Only returns true
  509. * for plain JavaScript objects.
  510. *
  511. * @param {*} obj
  512. * @return {Boolean}
  513. */
  514. var toString = Object.prototype.toString
  515. exports.isPlainObject = function (obj) {
  516. return toString.call(obj) === '[object Object]'
  517. }
  518. /**
  519. * Array type check.
  520. *
  521. * @param {*} obj
  522. * @return {Boolean}
  523. */
  524. exports.isArray = Array.isArray
  525. /**
  526. * Define a non-enumerable property
  527. *
  528. * @param {Object} obj
  529. * @param {String} key
  530. * @param {*} val
  531. * @param {Boolean} [enumerable]
  532. */
  533. exports.define = function (obj, key, val, enumerable) {
  534. Object.defineProperty(obj, key, {
  535. value: val,
  536. enumerable: !!enumerable,
  537. writable: true,
  538. configurable: true
  539. })
  540. }
  541. /**
  542. * Debounce a function so it only gets called after the
  543. * input stops arriving after the given wait period.
  544. *
  545. * @param {Function} func
  546. * @param {Number} wait
  547. * @return {Function} - the debounced function
  548. */
  549. exports.debounce = function (func, wait) {
  550. var timeout, args, context, timestamp, result
  551. var later = function () {
  552. var last = Date.now() - timestamp
  553. if (last < wait && last >= 0) {
  554. timeout = setTimeout(later, wait - last)
  555. } else {
  556. timeout = null
  557. result = func.apply(context, args)
  558. if (!timeout) context = args = null
  559. }
  560. }
  561. return function () {
  562. context = this
  563. args = arguments
  564. timestamp = Date.now()
  565. if (!timeout) {
  566. timeout = setTimeout(later, wait)
  567. }
  568. return result
  569. }
  570. }
  571. /**
  572. * Manual indexOf because it's slightly faster than
  573. * native.
  574. *
  575. * @param {Array} arr
  576. * @param {*} obj
  577. */
  578. exports.indexOf = function (arr, obj) {
  579. for (var i = 0, l = arr.length; i < l; i++) {
  580. if (arr[i] === obj) return i
  581. }
  582. return -1
  583. }
  584. /**
  585. * Make a cancellable version of an async callback.
  586. *
  587. * @param {Function} fn
  588. * @return {Function}
  589. */
  590. exports.cancellable = function (fn) {
  591. var cb = function () {
  592. if (!cb.cancelled) {
  593. return fn.apply(this, arguments)
  594. }
  595. }
  596. cb.cancel = function () {
  597. cb.cancelled = true
  598. }
  599. return cb
  600. }
  601. /***/ },
  602. /* 5 */
  603. /***/ function(module, exports, __webpack_require__) {
  604. // can we use __proto__?
  605. exports.hasProto = '__proto__' in {}
  606. // Browser environment sniffing
  607. var inBrowser = exports.inBrowser =
  608. typeof window !== 'undefined' &&
  609. Object.prototype.toString.call(window) !== '[object Object]'
  610. exports.isIE9 =
  611. inBrowser &&
  612. navigator.userAgent.toLowerCase().indexOf('msie 9.0') > 0
  613. exports.isAndroid =
  614. inBrowser &&
  615. navigator.userAgent.toLowerCase().indexOf('android') > 0
  616. // Transition property/event sniffing
  617. if (inBrowser && !exports.isIE9) {
  618. var isWebkitTrans =
  619. window.ontransitionend === undefined &&
  620. window.onwebkittransitionend !== undefined
  621. var isWebkitAnim =
  622. window.onanimationend === undefined &&
  623. window.onwebkitanimationend !== undefined
  624. exports.transitionProp = isWebkitTrans
  625. ? 'WebkitTransition'
  626. : 'transition'
  627. exports.transitionEndEvent = isWebkitTrans
  628. ? 'webkitTransitionEnd'
  629. : 'transitionend'
  630. exports.animationProp = isWebkitAnim
  631. ? 'WebkitAnimation'
  632. : 'animation'
  633. exports.animationEndEvent = isWebkitAnim
  634. ? 'webkitAnimationEnd'
  635. : 'animationend'
  636. }
  637. /**
  638. * Defer a task to execute it asynchronously. Ideally this
  639. * should be executed as a microtask, so we leverage
  640. * MutationObserver if it's available, and fallback to
  641. * setTimeout(0).
  642. *
  643. * @param {Function} cb
  644. * @param {Object} ctx
  645. */
  646. exports.nextTick = (function () {
  647. var callbacks = []
  648. var pending = false
  649. var timerFunc
  650. function handle () {
  651. pending = false
  652. var copies = callbacks.slice(0)
  653. callbacks = []
  654. for (var i = 0; i < copies.length; i++) {
  655. copies[i]()
  656. }
  657. }
  658. /* istanbul ignore if */
  659. if (typeof MutationObserver !== 'undefined') {
  660. var counter = 1
  661. var observer = new MutationObserver(handle)
  662. var textNode = document.createTextNode(counter)
  663. observer.observe(textNode, {
  664. characterData: true
  665. })
  666. timerFunc = function () {
  667. counter = (counter + 1) % 2
  668. textNode.data = counter
  669. }
  670. } else {
  671. timerFunc = setTimeout
  672. }
  673. return function (cb, ctx) {
  674. var func = ctx
  675. ? function () { cb.call(ctx) }
  676. : cb
  677. callbacks.push(func)
  678. if (pending) return
  679. pending = true
  680. timerFunc(handle, 0)
  681. }
  682. })()
  683. /***/ },
  684. /* 6 */
  685. /***/ function(module, exports, __webpack_require__) {
  686. var _ = __webpack_require__(1)
  687. var config = __webpack_require__(3)
  688. /**
  689. * Query an element selector if it's not an element already.
  690. *
  691. * @param {String|Element} el
  692. * @return {Element}
  693. */
  694. exports.query = function (el) {
  695. if (typeof el === 'string') {
  696. var selector = el
  697. el = document.querySelector(el)
  698. if (!el) {
  699. _.warn('Cannot find element: ' + selector)
  700. }
  701. }
  702. return el
  703. }
  704. /**
  705. * Check if a node is in the document.
  706. * Note: document.documentElement.contains should work here
  707. * but always returns false for comment nodes in phantomjs,
  708. * making unit tests difficult. This is fixed byy doing the
  709. * contains() check on the node's parentNode instead of
  710. * the node itself.
  711. *
  712. * @param {Node} node
  713. * @return {Boolean}
  714. */
  715. exports.inDoc = function (node) {
  716. var doc = document.documentElement
  717. var parent = node && node.parentNode
  718. return doc === node ||
  719. doc === parent ||
  720. !!(parent && parent.nodeType === 1 && (doc.contains(parent)))
  721. }
  722. /**
  723. * Extract an attribute from a node.
  724. *
  725. * @param {Node} node
  726. * @param {String} attr
  727. */
  728. exports.attr = function (node, attr) {
  729. attr = config.prefix + attr
  730. var val = node.getAttribute(attr)
  731. if (val !== null) {
  732. node.removeAttribute(attr)
  733. }
  734. return val
  735. }
  736. /**
  737. * Insert el before target
  738. *
  739. * @param {Element} el
  740. * @param {Element} target
  741. */
  742. exports.before = function (el, target) {
  743. target.parentNode.insertBefore(el, target)
  744. }
  745. /**
  746. * Insert el after target
  747. *
  748. * @param {Element} el
  749. * @param {Element} target
  750. */
  751. exports.after = function (el, target) {
  752. if (target.nextSibling) {
  753. exports.before(el, target.nextSibling)
  754. } else {
  755. target.parentNode.appendChild(el)
  756. }
  757. }
  758. /**
  759. * Remove el from DOM
  760. *
  761. * @param {Element} el
  762. */
  763. exports.remove = function (el) {
  764. el.parentNode.removeChild(el)
  765. }
  766. /**
  767. * Prepend el to target
  768. *
  769. * @param {Element} el
  770. * @param {Element} target
  771. */
  772. exports.prepend = function (el, target) {
  773. if (target.firstChild) {
  774. exports.before(el, target.firstChild)
  775. } else {
  776. target.appendChild(el)
  777. }
  778. }
  779. /**
  780. * Replace target with el
  781. *
  782. * @param {Element} target
  783. * @param {Element} el
  784. */
  785. exports.replace = function (target, el) {
  786. var parent = target.parentNode
  787. if (parent) {
  788. parent.replaceChild(el, target)
  789. }
  790. }
  791. /**
  792. * Add event listener shorthand.
  793. *
  794. * @param {Element} el
  795. * @param {String} event
  796. * @param {Function} cb
  797. */
  798. exports.on = function (el, event, cb) {
  799. el.addEventListener(event, cb)
  800. }
  801. /**
  802. * Remove event listener shorthand.
  803. *
  804. * @param {Element} el
  805. * @param {String} event
  806. * @param {Function} cb
  807. */
  808. exports.off = function (el, event, cb) {
  809. el.removeEventListener(event, cb)
  810. }
  811. /**
  812. * Add class with compatibility for IE & SVG
  813. *
  814. * @param {Element} el
  815. * @param {Strong} cls
  816. */
  817. exports.addClass = function (el, cls) {
  818. if (el.classList) {
  819. el.classList.add(cls)
  820. } else {
  821. var cur = ' ' + (el.getAttribute('class') || '') + ' '
  822. if (cur.indexOf(' ' + cls + ' ') < 0) {
  823. el.setAttribute('class', (cur + cls).trim())
  824. }
  825. }
  826. }
  827. /**
  828. * Remove class with compatibility for IE & SVG
  829. *
  830. * @param {Element} el
  831. * @param {Strong} cls
  832. */
  833. exports.removeClass = function (el, cls) {
  834. if (el.classList) {
  835. el.classList.remove(cls)
  836. } else {
  837. var cur = ' ' + (el.getAttribute('class') || '') + ' '
  838. var tar = ' ' + cls + ' '
  839. while (cur.indexOf(tar) >= 0) {
  840. cur = cur.replace(tar, ' ')
  841. }
  842. el.setAttribute('class', cur.trim())
  843. }
  844. }
  845. /**
  846. * Extract raw content inside an element into a temporary
  847. * container div
  848. *
  849. * @param {Element} el
  850. * @param {Boolean} asFragment
  851. * @return {Element}
  852. */
  853. exports.extractContent = function (el, asFragment) {
  854. var child
  855. var rawContent
  856. /* istanbul ignore if */
  857. if (
  858. exports.isTemplate(el) &&
  859. el.content instanceof DocumentFragment
  860. ) {
  861. el = el.content
  862. }
  863. if (el.hasChildNodes()) {
  864. trim(el, el.firstChild)
  865. trim(el, el.lastChild)
  866. rawContent = asFragment
  867. ? document.createDocumentFragment()
  868. : document.createElement('div')
  869. /* eslint-disable no-cond-assign */
  870. while (child = el.firstChild) {
  871. /* eslint-enable no-cond-assign */
  872. rawContent.appendChild(child)
  873. }
  874. }
  875. return rawContent
  876. }
  877. function trim (content, node) {
  878. if (node && node.nodeType === 3 && !node.data.trim()) {
  879. content.removeChild(node)
  880. }
  881. }
  882. /**
  883. * Check if an element is a template tag.
  884. * Note if the template appears inside an SVG its tagName
  885. * will be in lowercase.
  886. *
  887. * @param {Element} el
  888. */
  889. exports.isTemplate = function (el) {
  890. return el.tagName &&
  891. el.tagName.toLowerCase() === 'template'
  892. }
  893. /***/ },
  894. /* 7 */
  895. /***/ function(module, exports, __webpack_require__) {
  896. var config = __webpack_require__(3)
  897. /**
  898. * Enable debug utilities. The enableDebug() function and
  899. * all _.log() & _.warn() calls will be dropped in the
  900. * minified production build.
  901. */
  902. enableDebug()
  903. function enableDebug () {
  904. var hasConsole = typeof console !== 'undefined'
  905. /**
  906. * Log a message.
  907. *
  908. * @param {String} msg
  909. */
  910. exports.log = function (msg) {
  911. if (hasConsole && config.debug) {
  912. console.log('[Vue info]: ' + msg)
  913. }
  914. }
  915. /**
  916. * We've got a problem here.
  917. *
  918. * @param {String} msg
  919. */
  920. exports.warn = function (msg, e) {
  921. if (hasConsole && (!config.silent || config.debug)) {
  922. console.warn('[Vue warn]: ' + msg)
  923. /* istanbul ignore if */
  924. if (config.debug) {
  925. console.warn((e || new Error('Warning Stack Trace')).stack)
  926. }
  927. }
  928. }
  929. /**
  930. * Assert asset exists
  931. */
  932. exports.assertAsset = function (val, type, id) {
  933. /* istanbul ignore if */
  934. if (type === 'directive') {
  935. if (id === 'with') {
  936. exports.warn(
  937. 'v-with has been deprecated in ^0.12.0. ' +
  938. 'Use props instead.'
  939. )
  940. return
  941. }
  942. if (id === 'events') {
  943. exports.warn(
  944. 'v-events has been deprecated in ^0.12.0. ' +
  945. 'Pass down methods as callback props instead.'
  946. )
  947. return
  948. }
  949. }
  950. if (!val) {
  951. exports.warn('Failed to resolve ' + type + ': ' + id)
  952. }
  953. }
  954. }
  955. /***/ },
  956. /* 8 */
  957. /***/ function(module, exports, __webpack_require__) {
  958. var _ = __webpack_require__(1)
  959. var extend = _.extend
  960. /**
  961. * Option overwriting strategies are functions that handle
  962. * how to merge a parent option value and a child option
  963. * value into the final value.
  964. *
  965. * All strategy functions follow the same signature:
  966. *
  967. * @param {*} parentVal
  968. * @param {*} childVal
  969. * @param {Vue} [vm]
  970. */
  971. var strats = Object.create(null)
  972. /**
  973. * Helper that recursively merges two data objects together.
  974. */
  975. function mergeData (to, from) {
  976. var key, toVal, fromVal
  977. for (key in from) {
  978. toVal = to[key]
  979. fromVal = from[key]
  980. if (!to.hasOwnProperty(key)) {
  981. to.$add(key, fromVal)
  982. } else if (_.isObject(toVal) && _.isObject(fromVal)) {
  983. mergeData(toVal, fromVal)
  984. }
  985. }
  986. return to
  987. }
  988. /**
  989. * Data
  990. */
  991. strats.data = function (parentVal, childVal, vm) {
  992. if (!vm) {
  993. // in a Vue.extend merge, both should be functions
  994. if (!childVal) {
  995. return parentVal
  996. }
  997. if (typeof childVal !== 'function') {
  998. _.warn(
  999. 'The "data" option should be a function ' +
  1000. 'that returns a per-instance value in component ' +
  1001. 'definitions.'
  1002. )
  1003. return parentVal
  1004. }
  1005. if (!parentVal) {
  1006. return childVal
  1007. }
  1008. // when parentVal & childVal are both present,
  1009. // we need to return a function that returns the
  1010. // merged result of both functions... no need to
  1011. // check if parentVal is a function here because
  1012. // it has to be a function to pass previous merges.
  1013. return function mergedDataFn () {
  1014. return mergeData(
  1015. childVal.call(this),
  1016. parentVal.call(this)
  1017. )
  1018. }
  1019. } else if (parentVal || childVal) {
  1020. return function mergedInstanceDataFn () {
  1021. // instance merge
  1022. var instanceData = typeof childVal === 'function'
  1023. ? childVal.call(vm)
  1024. : childVal
  1025. var defaultData = typeof parentVal === 'function'
  1026. ? parentVal.call(vm)
  1027. : undefined
  1028. if (instanceData) {
  1029. return mergeData(instanceData, defaultData)
  1030. } else {
  1031. return defaultData
  1032. }
  1033. }
  1034. }
  1035. }
  1036. /**
  1037. * El
  1038. */
  1039. strats.el = function (parentVal, childVal, vm) {
  1040. if (!vm && childVal && typeof childVal !== 'function') {
  1041. _.warn(
  1042. 'The "el" option should be a function ' +
  1043. 'that returns a per-instance value in component ' +
  1044. 'definitions.'
  1045. )
  1046. return
  1047. }
  1048. var ret = childVal || parentVal
  1049. // invoke the element factory if this is instance merge
  1050. return vm && typeof ret === 'function'
  1051. ? ret.call(vm)
  1052. : ret
  1053. }
  1054. /**
  1055. * Hooks and param attributes are merged as arrays.
  1056. */
  1057. strats.created =
  1058. strats.ready =
  1059. strats.attached =
  1060. strats.detached =
  1061. strats.beforeCompile =
  1062. strats.compiled =
  1063. strats.beforeDestroy =
  1064. strats.destroyed =
  1065. strats.props = function (parentVal, childVal) {
  1066. return childVal
  1067. ? parentVal
  1068. ? parentVal.concat(childVal)
  1069. : _.isArray(childVal)
  1070. ? childVal
  1071. : [childVal]
  1072. : parentVal
  1073. }
  1074. /**
  1075. * 0.11 deprecation warning
  1076. */
  1077. strats.paramAttributes = function () {
  1078. /* istanbul ignore next */
  1079. _.warn(
  1080. '"paramAttributes" option has been deprecated in 0.12. ' +
  1081. 'Use "props" instead.'
  1082. )
  1083. }
  1084. /**
  1085. * Assets
  1086. *
  1087. * When a vm is present (instance creation), we need to do
  1088. * a three-way merge between constructor options, instance
  1089. * options and parent options.
  1090. */
  1091. strats.directives =
  1092. strats.filters =
  1093. strats.transitions =
  1094. strats.components =
  1095. strats.partials =
  1096. strats.elementDirectives = function (parentVal, childVal) {
  1097. var res = Object.create(parentVal)
  1098. return childVal
  1099. ? extend(res, childVal)
  1100. : res
  1101. }
  1102. /**
  1103. * Events & Watchers.
  1104. *
  1105. * Events & watchers hashes should not overwrite one
  1106. * another, so we merge them as arrays.
  1107. */
  1108. strats.watch =
  1109. strats.events = function (parentVal, childVal) {
  1110. if (!childVal) return parentVal
  1111. if (!parentVal) return childVal
  1112. var ret = {}
  1113. extend(ret, parentVal)
  1114. for (var key in childVal) {
  1115. var parent = ret[key]
  1116. var child = childVal[key]
  1117. if (parent && !_.isArray(parent)) {
  1118. parent = [parent]
  1119. }
  1120. ret[key] = parent
  1121. ? parent.concat(child)
  1122. : [child]
  1123. }
  1124. return ret
  1125. }
  1126. /**
  1127. * Other object hashes.
  1128. */
  1129. strats.methods =
  1130. strats.computed = function (parentVal, childVal) {
  1131. if (!childVal) return parentVal
  1132. if (!parentVal) return childVal
  1133. var ret = Object.create(parentVal)
  1134. extend(ret, childVal)
  1135. return ret
  1136. }
  1137. /**
  1138. * Default strategy.
  1139. */
  1140. var defaultStrat = function (parentVal, childVal) {
  1141. return childVal === undefined
  1142. ? parentVal
  1143. : childVal
  1144. }
  1145. /**
  1146. * Make sure component options get converted to actual
  1147. * constructors.
  1148. *
  1149. * @param {Object} components
  1150. */
  1151. function guardComponents (components) {
  1152. if (components) {
  1153. var def
  1154. for (var key in components) {
  1155. if (_.commonTagRE.test(key)) {
  1156. _.warn(
  1157. 'Do not use built-in HTML elements as component ' +
  1158. 'name: ' + key
  1159. )
  1160. }
  1161. def = components[key]
  1162. if (_.isPlainObject(def)) {
  1163. def.name = key
  1164. components[key] = _.Vue.extend(def)
  1165. }
  1166. }
  1167. }
  1168. }
  1169. /**
  1170. * Ensure all props option syntax are normalized into the
  1171. * Object-based format.
  1172. *
  1173. * @param {Object} options
  1174. */
  1175. function guardProps (options) {
  1176. var props = options.props
  1177. if (_.isPlainObject(props)) {
  1178. options.props = Object.keys(props).map(function (key) {
  1179. var val = props[key]
  1180. if (!_.isPlainObject(val)) {
  1181. val = { type: val }
  1182. }
  1183. val.name = key
  1184. return val
  1185. })
  1186. } else if (_.isArray(props)) {
  1187. options.props = props.map(function (prop) {
  1188. return typeof prop === 'string'
  1189. ? { name: prop }
  1190. : prop
  1191. })
  1192. }
  1193. }
  1194. /**
  1195. * Merge two option objects into a new one.
  1196. * Core utility used in both instantiation and inheritance.
  1197. *
  1198. * @param {Object} parent
  1199. * @param {Object} child
  1200. * @param {Vue} [vm] - if vm is present, indicates this is
  1201. * an instantiation merge.
  1202. */
  1203. exports.mergeOptions = function merge (parent, child, vm) {
  1204. guardComponents(child.components)
  1205. guardProps(child)
  1206. var options = {}
  1207. var key
  1208. if (child.mixins) {
  1209. for (var i = 0, l = child.mixins.length; i < l; i++) {
  1210. parent = merge(parent, child.mixins[i], vm)
  1211. }
  1212. }
  1213. for (key in parent) {
  1214. mergeField(key)
  1215. }
  1216. for (key in child) {
  1217. if (!(parent.hasOwnProperty(key))) {
  1218. mergeField(key)
  1219. }
  1220. }
  1221. function mergeField (key) {
  1222. var strat = strats[key] || defaultStrat
  1223. options[key] = strat(parent[key], child[key], vm, key)
  1224. }
  1225. return options
  1226. }
  1227. /**
  1228. * Resolve an asset.
  1229. * This function is used because child instances need access
  1230. * to assets defined in its ancestor chain.
  1231. *
  1232. * @param {Object} options
  1233. * @param {String} type
  1234. * @param {String} id
  1235. * @return {Object|Function}
  1236. */
  1237. exports.resolveAsset = function resolve (options, type, id) {
  1238. var asset = options[type][id]
  1239. while (!asset && options._parent) {
  1240. options = options._parent.$options
  1241. asset = options[type][id]
  1242. }
  1243. return asset
  1244. }
  1245. /***/ },
  1246. /* 9 */
  1247. /***/ function(module, exports, __webpack_require__) {
  1248. var _ = __webpack_require__(1)
  1249. var config = __webpack_require__(3)
  1250. /**
  1251. * Expose useful internals
  1252. */
  1253. exports.util = _
  1254. exports.nextTick = _.nextTick
  1255. exports.config = __webpack_require__(3)
  1256. exports.compiler = __webpack_require__(10)
  1257. exports.parsers = {
  1258. path: __webpack_require__(23),
  1259. text: __webpack_require__(13),
  1260. template: __webpack_require__(25),
  1261. directive: __webpack_require__(15),
  1262. expression: __webpack_require__(22)
  1263. }
  1264. /**
  1265. * Each instance constructor, including Vue, has a unique
  1266. * cid. This enables us to create wrapped "child
  1267. * constructors" for prototypal inheritance and cache them.
  1268. */
  1269. exports.cid = 0
  1270. var cid = 1
  1271. /**
  1272. * Class inehritance
  1273. *
  1274. * @param {Object} extendOptions
  1275. */
  1276. exports.extend = function (extendOptions) {
  1277. extendOptions = extendOptions || {}
  1278. var Super = this
  1279. var Sub = createClass(
  1280. extendOptions.name ||
  1281. Super.options.name ||
  1282. 'VueComponent'
  1283. )
  1284. Sub.prototype = Object.create(Super.prototype)
  1285. Sub.prototype.constructor = Sub
  1286. Sub.cid = cid++
  1287. Sub.options = _.mergeOptions(
  1288. Super.options,
  1289. extendOptions
  1290. )
  1291. Sub['super'] = Super
  1292. // allow further extension
  1293. Sub.extend = Super.extend
  1294. // create asset registers, so extended classes
  1295. // can have their private assets too.
  1296. config._assetTypes.forEach(function (type) {
  1297. Sub[type] = Super[type]
  1298. })
  1299. return Sub
  1300. }
  1301. /**
  1302. * A function that returns a sub-class constructor with the
  1303. * given name. This gives us much nicer output when
  1304. * logging instances in the console.
  1305. *
  1306. * @param {String} name
  1307. * @return {Function}
  1308. */
  1309. function createClass (name) {
  1310. return new Function(
  1311. 'return function ' + _.classify(name) +
  1312. ' (options) { this._init(options) }'
  1313. )()
  1314. }
  1315. /**
  1316. * Plugin system
  1317. *
  1318. * @param {Object} plugin
  1319. */
  1320. exports.use = function (plugin) {
  1321. // additional parameters
  1322. var args = _.toArray(arguments, 1)
  1323. args.unshift(this)
  1324. if (typeof plugin.install === 'function') {
  1325. plugin.install.apply(plugin, args)
  1326. } else {
  1327. plugin.apply(null, args)
  1328. }
  1329. return this
  1330. }
  1331. /**
  1332. * Create asset registration methods with the following
  1333. * signature:
  1334. *
  1335. * @param {String} id
  1336. * @param {*} definition
  1337. */
  1338. config._assetTypes.forEach(function (type) {
  1339. exports[type] = function (id, definition) {
  1340. if (!definition) {
  1341. return this.options[type + 's'][id]
  1342. } else {
  1343. if (
  1344. type === 'component' &&
  1345. _.isPlainObject(definition)
  1346. ) {
  1347. definition.name = id
  1348. definition = _.Vue.extend(definition)
  1349. }
  1350. this.options[type + 's'][id] = definition
  1351. }
  1352. }
  1353. })
  1354. /***/ },
  1355. /* 10 */
  1356. /***/ function(module, exports, __webpack_require__) {
  1357. var _ = __webpack_require__(1)
  1358. _.extend(exports, __webpack_require__(11))
  1359. _.extend(exports, __webpack_require__(27))
  1360. /***/ },
  1361. /* 11 */
  1362. /***/ function(module, exports, __webpack_require__) {
  1363. var _ = __webpack_require__(1)
  1364. var compileProps = __webpack_require__(12)
  1365. var config = __webpack_require__(3)
  1366. var textParser = __webpack_require__(13)
  1367. var dirParser = __webpack_require__(15)
  1368. var templateParser = __webpack_require__(25)
  1369. var resolveAsset = _.resolveAsset
  1370. var componentDef = __webpack_require__(26)
  1371. // terminal directives
  1372. var terminalDirectives = [
  1373. 'repeat',
  1374. 'if'
  1375. ]
  1376. /**
  1377. * Compile a template and return a reusable composite link
  1378. * function, which recursively contains more link functions
  1379. * inside. This top level compile function would normally
  1380. * be called on instance root nodes, but can also be used
  1381. * for partial compilation if the partial argument is true.
  1382. *
  1383. * The returned composite link function, when called, will
  1384. * return an unlink function that tearsdown all directives
  1385. * created during the linking phase.
  1386. *
  1387. * @param {Element|DocumentFragment} el
  1388. * @param {Object} options
  1389. * @param {Boolean} partial
  1390. * @param {Vue} [host] - host vm of transcluded content
  1391. * @return {Function}
  1392. */
  1393. exports.compile = function (el, options, partial, host) {
  1394. // link function for the node itself.
  1395. var nodeLinkFn = partial || !options._asComponent
  1396. ? compileNode(el, options)
  1397. : null
  1398. // link function for the childNodes
  1399. var childLinkFn =
  1400. !(nodeLinkFn && nodeLinkFn.terminal) &&
  1401. el.tagName !== 'SCRIPT' &&
  1402. el.hasChildNodes()
  1403. ? compileNodeList(el.childNodes, options)
  1404. : null
  1405. /**
  1406. * A composite linker function to be called on a already
  1407. * compiled piece of DOM, which instantiates all directive
  1408. * instances.
  1409. *
  1410. * @param {Vue} vm
  1411. * @param {Element|DocumentFragment} el
  1412. * @return {Function|undefined}
  1413. */
  1414. return function compositeLinkFn (vm, el) {
  1415. // cache childNodes before linking parent, fix #657
  1416. var childNodes = _.toArray(el.childNodes)
  1417. // link
  1418. var dirs = linkAndCapture(function () {
  1419. if (nodeLinkFn) nodeLinkFn(vm, el, host)
  1420. if (childLinkFn) childLinkFn(vm, childNodes, host)
  1421. }, vm)
  1422. return makeUnlinkFn(vm, dirs)
  1423. }
  1424. }
  1425. /**
  1426. * Apply a linker to a vm/element pair and capture the
  1427. * directives created during the process.
  1428. *
  1429. * @param {Function} linker
  1430. * @param {Vue} vm
  1431. */
  1432. function linkAndCapture (linker, vm) {
  1433. var originalDirCount = vm._directives.length
  1434. linker()
  1435. return vm._directives.slice(originalDirCount)
  1436. }
  1437. /**
  1438. * Linker functions return an unlink function that
  1439. * tearsdown all directives instances generated during
  1440. * the process.
  1441. *
  1442. * We create unlink functions with only the necessary
  1443. * information to avoid retaining additional closures.
  1444. *
  1445. * @param {Vue} vm
  1446. * @param {Array} dirs
  1447. * @param {Vue} [context]
  1448. * @param {Array} [contextDirs]
  1449. * @return {Function}
  1450. */
  1451. function makeUnlinkFn (vm, dirs, context, contextDirs) {
  1452. return function unlink (destroying) {
  1453. teardownDirs(vm, dirs, destroying)
  1454. if (context && contextDirs) {
  1455. teardownDirs(context, contextDirs)
  1456. }
  1457. }
  1458. }
  1459. /**
  1460. * Teardown partial linked directives.
  1461. *
  1462. * @param {Vue} vm
  1463. * @param {Array} dirs
  1464. * @param {Boolean} destroying
  1465. */
  1466. function teardownDirs (vm, dirs, destroying) {
  1467. var i = dirs.length
  1468. while (i--) {
  1469. dirs[i]._teardown()
  1470. if (!destroying) {
  1471. vm._directives.$remove(dirs[i])
  1472. }
  1473. }
  1474. }
  1475. /**
  1476. * Compile link props on an instance.
  1477. *
  1478. * @param {Vue} vm
  1479. * @param {Element} el
  1480. * @param {Object} options
  1481. * @return {Function}
  1482. */
  1483. exports.compileAndLinkProps = function (vm, el, props) {
  1484. var propsLinkFn = compileProps(el, props)
  1485. var propDirs = linkAndCapture(function () {
  1486. propsLinkFn(vm, null)
  1487. }, vm)
  1488. return makeUnlinkFn(vm, propDirs)
  1489. }
  1490. /**
  1491. * Compile the root element of an instance.
  1492. *
  1493. * 1. attrs on context container (context scope)
  1494. * 2. attrs on the component template root node, if
  1495. * replace:true (child scope)
  1496. *
  1497. * If this is a block instance, we only need to compile 1.
  1498. *
  1499. * This function does compile and link at the same time,
  1500. * since root linkers can not be reused. It returns the
  1501. * unlink function for potential context directives on the
  1502. * container.
  1503. *
  1504. * @param {Vue} vm
  1505. * @param {Element} el
  1506. * @param {Object} options
  1507. * @return {Function}
  1508. */
  1509. exports.compileAndLinkRoot = function (vm, el, options) {
  1510. var containerAttrs = options._containerAttrs
  1511. var replacerAttrs = options._replacerAttrs
  1512. var contextLinkFn, replacerLinkFn
  1513. // only need to compile other attributes for
  1514. // non-block instances
  1515. if (el.nodeType !== 11) {
  1516. // for components, container and replacer need to be
  1517. // compiled separately and linked in different scopes.
  1518. if (options._asComponent) {
  1519. // 2. container attributes
  1520. if (containerAttrs) {
  1521. contextLinkFn = compileDirectives(containerAttrs, options)
  1522. }
  1523. if (replacerAttrs) {
  1524. // 3. replacer attributes
  1525. replacerLinkFn = compileDirectives(replacerAttrs, options)
  1526. }
  1527. } else {
  1528. // non-component, just compile as a normal element.
  1529. replacerLinkFn = compileDirectives(el, options)
  1530. }
  1531. }
  1532. // link context scope dirs
  1533. var context = vm._context
  1534. var contextDirs
  1535. if (context && contextLinkFn) {
  1536. contextDirs = linkAndCapture(function () {
  1537. contextLinkFn(context, el)
  1538. }, context)
  1539. }
  1540. // link self
  1541. var selfDirs = linkAndCapture(function () {
  1542. if (replacerLinkFn) replacerLinkFn(vm, el)
  1543. }, vm)
  1544. // return the unlink function that tearsdown context
  1545. // container directives.
  1546. return makeUnlinkFn(vm, selfDirs, context, contextDirs)
  1547. }
  1548. /**
  1549. * Compile a node and return a nodeLinkFn based on the
  1550. * node type.
  1551. *
  1552. * @param {Node} node
  1553. * @param {Object} options
  1554. * @return {Function|null}
  1555. */
  1556. function compileNode (node, options) {
  1557. var type = node.nodeType
  1558. if (type === 1 && node.tagName !== 'SCRIPT') {
  1559. return compileElement(node, options)
  1560. } else if (type === 3 && config.interpolate && node.data.trim()) {
  1561. return compileTextNode(node, options)
  1562. } else {
  1563. return null
  1564. }
  1565. }
  1566. /**
  1567. * Compile an element and return a nodeLinkFn.
  1568. *
  1569. * @param {Element} el
  1570. * @param {Object} options
  1571. * @return {Function|null}
  1572. */
  1573. function compileElement (el, options) {
  1574. var linkFn
  1575. var hasAttrs = el.hasAttributes()
  1576. // check terminal directives (repeat & if)
  1577. if (hasAttrs) {
  1578. linkFn = checkTerminalDirectives(el, options)
  1579. }
  1580. // check element directives
  1581. if (!linkFn) {
  1582. linkFn = checkElementDirectives(el, options)
  1583. }
  1584. // check component
  1585. if (!linkFn) {
  1586. linkFn = checkComponent(el, options)
  1587. }
  1588. // normal directives
  1589. if (!linkFn && hasAttrs) {
  1590. linkFn = compileDirectives(el, options)
  1591. }
  1592. // if the element is a textarea, we need to interpolate
  1593. // its content on initial render.
  1594. if (el.tagName === 'TEXTAREA') {
  1595. var realLinkFn = linkFn
  1596. linkFn = function (vm, el) {
  1597. el.value = vm.$interpolate(el.value)
  1598. if (realLinkFn) realLinkFn(vm, el)
  1599. }
  1600. linkFn.terminal = true
  1601. }
  1602. return linkFn
  1603. }
  1604. /**
  1605. * Compile a textNode and return a nodeLinkFn.
  1606. *
  1607. * @param {TextNode} node
  1608. * @param {Object} options
  1609. * @return {Function|null} textNodeLinkFn
  1610. */
  1611. function compileTextNode (node, options) {
  1612. var tokens = textParser.parse(node.data)
  1613. if (!tokens) {
  1614. return null
  1615. }
  1616. var frag = document.createDocumentFragment()
  1617. var el, token
  1618. for (var i = 0, l = tokens.length; i < l; i++) {
  1619. token = tokens[i]
  1620. el = token.tag
  1621. ? processTextToken(token, options)
  1622. : document.createTextNode(token.value)
  1623. frag.appendChild(el)
  1624. }
  1625. return makeTextNodeLinkFn(tokens, frag, options)
  1626. }
  1627. /**
  1628. * Process a single text token.
  1629. *
  1630. * @param {Object} token
  1631. * @param {Object} options
  1632. * @return {Node}
  1633. */
  1634. function processTextToken (token, options) {
  1635. var el
  1636. if (token.oneTime) {
  1637. el = document.createTextNode(token.value)
  1638. } else {
  1639. if (token.html) {
  1640. el = document.createComment('v-html')
  1641. setTokenType('html')
  1642. } else {
  1643. // IE will clean up empty textNodes during
  1644. // frag.cloneNode(true), so we have to give it
  1645. // something here...
  1646. el = document.createTextNode(' ')
  1647. setTokenType('text')
  1648. }
  1649. }
  1650. function setTokenType (type) {
  1651. token.type = type
  1652. token.def = resolveAsset(options, 'directives', type)
  1653. token.descriptor = dirParser.parse(token.value)[0]
  1654. }
  1655. return el
  1656. }
  1657. /**
  1658. * Build a function that processes a textNode.
  1659. *
  1660. * @param {Array<Object>} tokens
  1661. * @param {DocumentFragment} frag
  1662. */
  1663. function makeTextNodeLinkFn (tokens, frag) {
  1664. return function textNodeLinkFn (vm, el) {
  1665. var fragClone = frag.cloneNode(true)
  1666. var childNodes = _.toArray(fragClone.childNodes)
  1667. var token, value, node
  1668. for (var i = 0, l = tokens.length; i < l; i++) {
  1669. token = tokens[i]
  1670. value = token.value
  1671. if (token.tag) {
  1672. node = childNodes[i]
  1673. if (token.oneTime) {
  1674. value = vm.$eval(value)
  1675. if (token.html) {
  1676. _.replace(node, templateParser.parse(value, true))
  1677. } else {
  1678. node.data = value
  1679. }
  1680. } else {
  1681. vm._bindDir(token.type, node,
  1682. token.descriptor, token.def)
  1683. }
  1684. }
  1685. }
  1686. _.replace(el, fragClone)
  1687. }
  1688. }
  1689. /**
  1690. * Compile a node list and return a childLinkFn.
  1691. *
  1692. * @param {NodeList} nodeList
  1693. * @param {Object} options
  1694. * @return {Function|undefined}
  1695. */
  1696. function compileNodeList (nodeList, options) {
  1697. var linkFns = []
  1698. var nodeLinkFn, childLinkFn, node
  1699. for (var i = 0, l = nodeList.length; i < l; i++) {
  1700. node = nodeList[i]
  1701. nodeLinkFn = compileNode(node, options)
  1702. childLinkFn =
  1703. !(nodeLinkFn && nodeLinkFn.terminal) &&
  1704. node.tagName !== 'SCRIPT' &&
  1705. node.hasChildNodes()
  1706. ? compileNodeList(node.childNodes, options)
  1707. : null
  1708. linkFns.push(nodeLinkFn, childLinkFn)
  1709. }
  1710. return linkFns.length
  1711. ? makeChildLinkFn(linkFns)
  1712. : null
  1713. }
  1714. /**
  1715. * Make a child link function for a node's childNodes.
  1716. *
  1717. * @param {Array<Function>} linkFns
  1718. * @return {Function} childLinkFn
  1719. */
  1720. function makeChildLinkFn (linkFns) {
  1721. return function childLinkFn (vm, nodes, host) {
  1722. var node, nodeLinkFn, childrenLinkFn
  1723. for (var i = 0, n = 0, l = linkFns.length; i < l; n++) {
  1724. node = nodes[n]
  1725. nodeLinkFn = linkFns[i++]
  1726. childrenLinkFn = linkFns[i++]
  1727. // cache childNodes before linking parent, fix #657
  1728. var childNodes = _.toArray(node.childNodes)
  1729. if (nodeLinkFn) {
  1730. nodeLinkFn(vm, node, host)
  1731. }
  1732. if (childrenLinkFn) {
  1733. childrenLinkFn(vm, childNodes, host)
  1734. }
  1735. }
  1736. }
  1737. }
  1738. /**
  1739. * Check for element directives (custom elements that should
  1740. * be resovled as terminal directives).
  1741. *
  1742. * @param {Element} el
  1743. * @param {Object} options
  1744. */
  1745. function checkElementDirectives (el, options) {
  1746. var tag = el.tagName.toLowerCase()
  1747. if (_.commonTagRE.test(tag)) return
  1748. var def = resolveAsset(options, 'elementDirectives', tag)
  1749. if (def) {
  1750. return makeTerminalNodeLinkFn(el, tag, '', options, def)
  1751. }
  1752. }
  1753. /**
  1754. * Check if an element is a component. If yes, return
  1755. * a component link function.
  1756. *
  1757. * @param {Element} el
  1758. * @param {Object} options
  1759. * @param {Boolean} hasAttrs
  1760. * @return {Function|undefined}
  1761. */
  1762. function checkComponent (el, options, hasAttrs) {
  1763. var componentId = _.checkComponent(el, options, hasAttrs)
  1764. if (componentId) {
  1765. var componentLinkFn = function (vm, el, host) {
  1766. vm._bindDir('component', el, {
  1767. expression: componentId
  1768. }, componentDef, host)
  1769. }
  1770. componentLinkFn.terminal = true
  1771. return componentLinkFn
  1772. }
  1773. }
  1774. /**
  1775. * Check an element for terminal directives in fixed order.
  1776. * If it finds one, return a terminal link function.
  1777. *
  1778. * @param {Element} el
  1779. * @param {Object} options
  1780. * @return {Function} terminalLinkFn
  1781. */
  1782. function checkTerminalDirectives (el, options) {
  1783. if (_.attr(el, 'pre') !== null) {
  1784. return skip
  1785. }
  1786. var value, dirName
  1787. for (var i = 0, l = terminalDirectives.length; i < l; i++) {
  1788. dirName = terminalDirectives[i]
  1789. if ((value = _.attr(el, dirName)) !== null) {
  1790. return makeTerminalNodeLinkFn(el, dirName, value, options)
  1791. }
  1792. }
  1793. }
  1794. function skip () {}
  1795. skip.terminal = true
  1796. /**
  1797. * Build a node link function for a terminal directive.
  1798. * A terminal link function terminates the current
  1799. * compilation recursion and handles compilation of the
  1800. * subtree in the directive.
  1801. *
  1802. * @param {Element} el
  1803. * @param {String} dirName
  1804. * @param {String} value
  1805. * @param {Object} options
  1806. * @param {Object} [def]
  1807. * @return {Function} terminalLinkFn
  1808. */
  1809. function makeTerminalNodeLinkFn (el, dirName, value, options, def) {
  1810. var descriptor = dirParser.parse(value)[0]
  1811. // no need to call resolveAsset since terminal directives
  1812. // are always internal
  1813. def = def || options.directives[dirName]
  1814. var fn = function terminalNodeLinkFn (vm, el, host) {
  1815. vm._bindDir(dirName, el, descriptor, def, host)
  1816. }
  1817. fn.terminal = true
  1818. return fn
  1819. }
  1820. /**
  1821. * Compile the directives on an element and return a linker.
  1822. *
  1823. * @param {Element|Object} elOrAttrs
  1824. * - could be an object of already-extracted
  1825. * container attributes.
  1826. * @param {Object} options
  1827. * @return {Function}
  1828. */
  1829. function compileDirectives (elOrAttrs, options) {
  1830. var attrs = _.isPlainObject(elOrAttrs)
  1831. ? mapToList(elOrAttrs)
  1832. : elOrAttrs.attributes
  1833. var i = attrs.length
  1834. var dirs = []
  1835. var attr, name, value, dir, dirName, dirDef
  1836. while (i--) {
  1837. attr = attrs[i]
  1838. name = attr.name
  1839. value = attr.value
  1840. if (name.indexOf(config.prefix) === 0) {
  1841. dirName = name.slice(config.prefix.length)
  1842. dirDef = resolveAsset(options, 'directives', dirName)
  1843. _.assertAsset(dirDef, 'directive', dirName)
  1844. if (dirDef) {
  1845. dirs.push({
  1846. name: dirName,
  1847. descriptors: dirParser.parse(value),
  1848. def: dirDef
  1849. })
  1850. }
  1851. } else if (config.interpolate) {
  1852. dir = collectAttrDirective(name, value, options)
  1853. if (dir) {
  1854. dirs.push(dir)
  1855. }
  1856. }
  1857. }
  1858. // sort by priority, LOW to HIGH
  1859. if (dirs.length) {
  1860. dirs.sort(directiveComparator)
  1861. return makeNodeLinkFn(dirs)
  1862. }
  1863. }
  1864. /**
  1865. * Convert a map (Object) of attributes to an Array.
  1866. *
  1867. * @param {Object} map
  1868. * @return {Array}
  1869. */
  1870. function mapToList (map) {
  1871. var list = []
  1872. for (var key in map) {
  1873. list.push({
  1874. name: key,
  1875. value: map[key]
  1876. })
  1877. }
  1878. return list
  1879. }
  1880. /**
  1881. * Build a link function for all directives on a single node.
  1882. *
  1883. * @param {Array} directives
  1884. * @return {Function} directivesLinkFn
  1885. */
  1886. function makeNodeLinkFn (directives) {
  1887. return function nodeLinkFn (vm, el, host) {
  1888. // reverse apply because it's sorted low to high
  1889. var i = directives.length
  1890. var dir, j, k
  1891. while (i--) {
  1892. dir = directives[i]
  1893. if (dir._link) {
  1894. // custom link fn
  1895. dir._link(vm, el)
  1896. } else {
  1897. k = dir.descriptors.length
  1898. for (j = 0; j < k; j++) {
  1899. vm._bindDir(dir.name, el,
  1900. dir.descriptors[j], dir.def, host)
  1901. }
  1902. }
  1903. }
  1904. }
  1905. }
  1906. /**
  1907. * Check an attribute for potential dynamic bindings,
  1908. * and return a directive object.
  1909. *
  1910. * @param {String} name
  1911. * @param {String} value
  1912. * @param {Object} options
  1913. * @return {Object}
  1914. */
  1915. function collectAttrDirective (name, value, options) {
  1916. var tokens = textParser.parse(value)
  1917. if (tokens) {
  1918. var def = options.directives.attr
  1919. var i = tokens.length
  1920. var allOneTime = true
  1921. while (i--) {
  1922. var token = tokens[i]
  1923. if (token.tag && !token.oneTime) {
  1924. allOneTime = false
  1925. }
  1926. }
  1927. return {
  1928. def: def,
  1929. _link: allOneTime
  1930. ? function (vm, el) {
  1931. el.setAttribute(name, vm.$interpolate(value))
  1932. }
  1933. : function (vm, el) {