PageRenderTime 24ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/files/vue/0.12.13/vue.js

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