PageRenderTime 72ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/files/vue/0.12.4/vue.js

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