├── assets
└── js
│ ├── vue-router.js
│ └── vue.js
├── footer.php
├── functions.php
├── header.php
├── index.php
└── style.css
/assets/js/vue-router.js:
--------------------------------------------------------------------------------
1 | /**
2 | * vue-router v2.1.1
3 | * (c) 2016 Evan You
4 | * @license MIT
5 | */
6 | (function (global, factory) {
7 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
8 | typeof define === 'function' && define.amd ? define(factory) :
9 | (global.VueRouter = factory());
10 | }(this, (function () { 'use strict';
11 |
12 | var View = {
13 | name: 'router-view',
14 | functional: true,
15 | props: {
16 | name: {
17 | type: String,
18 | default: 'default'
19 | }
20 | },
21 | render: function render (h, ref) {
22 | var props = ref.props;
23 | var children = ref.children;
24 | var parent = ref.parent;
25 | var data = ref.data;
26 |
27 | data.routerView = true
28 |
29 | var route = parent.$route
30 | var cache = parent._routerViewCache || (parent._routerViewCache = {})
31 | var depth = 0
32 | var inactive = false
33 |
34 | while (parent) {
35 | if (parent.$vnode && parent.$vnode.data.routerView) {
36 | depth++
37 | }
38 | if (parent._inactive) {
39 | inactive = true
40 | }
41 | parent = parent.$parent
42 | }
43 |
44 | data.routerViewDepth = depth
45 | var matched = route.matched[depth]
46 | if (!matched) {
47 | return h()
48 | }
49 |
50 | var name = props.name
51 | var component = inactive
52 | ? cache[name]
53 | : (cache[name] = matched.components[name])
54 |
55 | if (!inactive) {
56 | var hooks = data.hook || (data.hook = {})
57 | hooks.init = function (vnode) {
58 | matched.instances[name] = vnode.child
59 | }
60 | hooks.prepatch = function (oldVnode, vnode) {
61 | matched.instances[name] = vnode.child
62 | }
63 | hooks.destroy = function (vnode) {
64 | if (matched.instances[name] === vnode.child) {
65 | matched.instances[name] = undefined
66 | }
67 | }
68 | }
69 |
70 | return h(component, data, children)
71 | }
72 | }
73 |
74 | /* */
75 |
76 | function assert (condition, message) {
77 | if (!condition) {
78 | throw new Error(("[vue-router] " + message))
79 | }
80 | }
81 |
82 | function warn (condition, message) {
83 | if (!condition) {
84 | typeof console !== 'undefined' && console.warn(("[vue-router] " + message))
85 | }
86 | }
87 |
88 | /* */
89 |
90 | var encode = encodeURIComponent
91 | var decode = decodeURIComponent
92 |
93 | function resolveQuery (
94 | query,
95 | extraQuery
96 | ) {
97 | if ( extraQuery === void 0 ) extraQuery = {};
98 |
99 | if (query) {
100 | var parsedQuery
101 | try {
102 | parsedQuery = parseQuery(query)
103 | } catch (e) {
104 | "development" !== 'production' && warn(false, e.message)
105 | parsedQuery = {}
106 | }
107 | for (var key in extraQuery) {
108 | parsedQuery[key] = extraQuery[key]
109 | }
110 | return parsedQuery
111 | } else {
112 | return extraQuery
113 | }
114 | }
115 |
116 | function parseQuery (query) {
117 | var res = {}
118 |
119 | query = query.trim().replace(/^(\?|#|&)/, '')
120 |
121 | if (!query) {
122 | return res
123 | }
124 |
125 | query.split('&').forEach(function (param) {
126 | var parts = param.replace(/\+/g, ' ').split('=')
127 | var key = decode(parts.shift())
128 | var val = parts.length > 0
129 | ? decode(parts.join('='))
130 | : null
131 |
132 | if (res[key] === undefined) {
133 | res[key] = val
134 | } else if (Array.isArray(res[key])) {
135 | res[key].push(val)
136 | } else {
137 | res[key] = [res[key], val]
138 | }
139 | })
140 |
141 | return res
142 | }
143 |
144 | function stringifyQuery (obj) {
145 | var res = obj ? Object.keys(obj).map(function (key) {
146 | var val = obj[key]
147 |
148 | if (val === undefined) {
149 | return ''
150 | }
151 |
152 | if (val === null) {
153 | return encode(key)
154 | }
155 |
156 | if (Array.isArray(val)) {
157 | var result = []
158 | val.slice().forEach(function (val2) {
159 | if (val2 === undefined) {
160 | return
161 | }
162 | if (val2 === null) {
163 | result.push(encode(key))
164 | } else {
165 | result.push(encode(key) + '=' + encode(val2))
166 | }
167 | })
168 | return result.join('&')
169 | }
170 |
171 | return encode(key) + '=' + encode(val)
172 | }).filter(function (x) { return x.length > 0; }).join('&') : null
173 | return res ? ("?" + res) : ''
174 | }
175 |
176 | /* */
177 |
178 | function createRoute (
179 | record,
180 | location,
181 | redirectedFrom
182 | ) {
183 | var route = {
184 | name: location.name || (record && record.name),
185 | meta: (record && record.meta) || {},
186 | path: location.path || '/',
187 | hash: location.hash || '',
188 | query: location.query || {},
189 | params: location.params || {},
190 | fullPath: getFullPath(location),
191 | matched: record ? formatMatch(record) : []
192 | }
193 | if (redirectedFrom) {
194 | route.redirectedFrom = getFullPath(redirectedFrom)
195 | }
196 | return Object.freeze(route)
197 | }
198 |
199 | // the starting route that represents the initial state
200 | var START = createRoute(null, {
201 | path: '/'
202 | })
203 |
204 | function formatMatch (record) {
205 | var res = []
206 | while (record) {
207 | res.unshift(record)
208 | record = record.parent
209 | }
210 | return res
211 | }
212 |
213 | function getFullPath (ref) {
214 | var path = ref.path;
215 | var query = ref.query; if ( query === void 0 ) query = {};
216 | var hash = ref.hash; if ( hash === void 0 ) hash = '';
217 |
218 | return (path || '/') + stringifyQuery(query) + hash
219 | }
220 |
221 | var trailingSlashRE = /\/$/
222 | function isSameRoute (a, b) {
223 | if (b === START) {
224 | return a === b
225 | } else if (!b) {
226 | return false
227 | } else if (a.path && b.path) {
228 | return (
229 | a.path.replace(trailingSlashRE, '') === b.path.replace(trailingSlashRE, '') &&
230 | a.hash === b.hash &&
231 | isObjectEqual(a.query, b.query)
232 | )
233 | } else if (a.name && b.name) {
234 | return (
235 | a.name === b.name &&
236 | a.hash === b.hash &&
237 | isObjectEqual(a.query, b.query) &&
238 | isObjectEqual(a.params, b.params)
239 | )
240 | } else {
241 | return false
242 | }
243 | }
244 |
245 | function isObjectEqual (a, b) {
246 | if ( a === void 0 ) a = {};
247 | if ( b === void 0 ) b = {};
248 |
249 | var aKeys = Object.keys(a)
250 | var bKeys = Object.keys(b)
251 | if (aKeys.length !== bKeys.length) {
252 | return false
253 | }
254 | return aKeys.every(function (key) { return String(a[key]) === String(b[key]); })
255 | }
256 |
257 | function isIncludedRoute (current, target) {
258 | return (
259 | current.path.indexOf(target.path.replace(/\/$/, '')) === 0 &&
260 | (!target.hash || current.hash === target.hash) &&
261 | queryIncludes(current.query, target.query)
262 | )
263 | }
264 |
265 | function queryIncludes (current, target) {
266 | for (var key in target) {
267 | if (!(key in current)) {
268 | return false
269 | }
270 | }
271 | return true
272 | }
273 |
274 | /* */
275 |
276 | // work around weird flow bug
277 | var toTypes = [String, Object]
278 |
279 | var Link = {
280 | name: 'router-link',
281 | props: {
282 | to: {
283 | type: toTypes,
284 | required: true
285 | },
286 | tag: {
287 | type: String,
288 | default: 'a'
289 | },
290 | exact: Boolean,
291 | append: Boolean,
292 | replace: Boolean,
293 | activeClass: String,
294 | event: {
295 | type: [String, Array],
296 | default: 'click'
297 | }
298 | },
299 | render: function render (h) {
300 | var this$1 = this;
301 |
302 | var router = this.$router
303 | var current = this.$route
304 | var ref = router.resolve(this.to, current, this.append);
305 | var normalizedTo = ref.normalizedTo;
306 | var resolved = ref.resolved;
307 | var href = ref.href;
308 | var classes = {}
309 | var activeClass = this.activeClass || router.options.linkActiveClass || 'router-link-active'
310 | var compareTarget = normalizedTo.path ? createRoute(null, normalizedTo) : resolved
311 | classes[activeClass] = this.exact
312 | ? isSameRoute(current, compareTarget)
313 | : isIncludedRoute(current, compareTarget)
314 |
315 | var handler = function (e) {
316 | if (guardEvent(e)) {
317 | if (this$1.replace) {
318 | router.replace(normalizedTo)
319 | } else {
320 | router.push(normalizedTo)
321 | }
322 | }
323 | }
324 |
325 | var on = { click: guardEvent }
326 | if (Array.isArray(this.event)) {
327 | this.event.forEach(function (e) { on[e] = handler })
328 | } else {
329 | on[this.event] = handler
330 | }
331 |
332 | var data = {
333 | class: classes
334 | }
335 |
336 | if (this.tag === 'a') {
337 | data.on = on
338 | data.attrs = { href: href }
339 | } else {
340 | // find the first child and apply listener and href
341 | var a = findAnchor(this.$slots.default)
342 | if (a) {
343 | // in case the is a static node
344 | a.isStatic = false
345 | var extend = _Vue.util.extend
346 | var aData = a.data = extend({}, a.data)
347 | aData.on = on
348 | var aAttrs = a.data.attrs = extend({}, a.data.attrs)
349 | aAttrs.href = href
350 | } else {
351 | // doesn't have child, apply listener to self
352 | data.on = on
353 | }
354 | }
355 |
356 | return h(this.tag, data, this.$slots.default)
357 | }
358 | }
359 |
360 | function guardEvent (e) {
361 | // don't redirect with control keys
362 | /* istanbul ignore if */
363 | if (e.metaKey || e.ctrlKey || e.shiftKey) { return }
364 | // don't redirect when preventDefault called
365 | /* istanbul ignore if */
366 | if (e.defaultPrevented) { return }
367 | // don't redirect on right click
368 | /* istanbul ignore if */
369 | if (e.button !== 0) { return }
370 | // don't redirect if `target="_blank"`
371 | /* istanbul ignore if */
372 | var target = e.target.getAttribute('target')
373 | if (/\b_blank\b/i.test(target)) { return }
374 |
375 | e.preventDefault()
376 | return true
377 | }
378 |
379 | function findAnchor (children) {
380 | if (children) {
381 | var child
382 | for (var i = 0; i < children.length; i++) {
383 | child = children[i]
384 | if (child.tag === 'a') {
385 | return child
386 | }
387 | if (child.children && (child = findAnchor(child.children))) {
388 | return child
389 | }
390 | }
391 | }
392 | }
393 |
394 | var _Vue
395 |
396 | function install (Vue) {
397 | if (install.installed) { return }
398 | install.installed = true
399 |
400 | _Vue = Vue
401 |
402 | Object.defineProperty(Vue.prototype, '$router', {
403 | get: function get () { return this.$root._router }
404 | })
405 |
406 | Object.defineProperty(Vue.prototype, '$route', {
407 | get: function get$1 () { return this.$root._route }
408 | })
409 |
410 | Vue.mixin({
411 | beforeCreate: function beforeCreate () {
412 | if (this.$options.router) {
413 | this._router = this.$options.router
414 | this._router.init(this)
415 | Vue.util.defineReactive(this, '_route', this._router.history.current)
416 | }
417 | }
418 | })
419 |
420 | Vue.component('router-view', View)
421 | Vue.component('router-link', Link)
422 |
423 | var strats = Vue.config.optionMergeStrategies
424 | // use the same hook merging strategy for route hooks
425 | strats.beforeRouteEnter = strats.beforeRouteLeave = strats.created
426 | }
427 |
428 | /* */
429 |
430 | function resolvePath (
431 | relative,
432 | base,
433 | append
434 | ) {
435 | if (relative.charAt(0) === '/') {
436 | return relative
437 | }
438 |
439 | if (relative.charAt(0) === '?' || relative.charAt(0) === '#') {
440 | return base + relative
441 | }
442 |
443 | var stack = base.split('/')
444 |
445 | // remove trailing segment if:
446 | // - not appending
447 | // - appending to trailing slash (last segment is empty)
448 | if (!append || !stack[stack.length - 1]) {
449 | stack.pop()
450 | }
451 |
452 | // resolve relative path
453 | var segments = relative.replace(/^\//, '').split('/')
454 | for (var i = 0; i < segments.length; i++) {
455 | var segment = segments[i]
456 | if (segment === '.') {
457 | continue
458 | } else if (segment === '..') {
459 | stack.pop()
460 | } else {
461 | stack.push(segment)
462 | }
463 | }
464 |
465 | // ensure leading slash
466 | if (stack[0] !== '') {
467 | stack.unshift('')
468 | }
469 |
470 | return stack.join('/')
471 | }
472 |
473 | function parsePath (path) {
474 | var hash = ''
475 | var query = ''
476 |
477 | var hashIndex = path.indexOf('#')
478 | if (hashIndex >= 0) {
479 | hash = path.slice(hashIndex)
480 | path = path.slice(0, hashIndex)
481 | }
482 |
483 | var queryIndex = path.indexOf('?')
484 | if (queryIndex >= 0) {
485 | query = path.slice(queryIndex + 1)
486 | path = path.slice(0, queryIndex)
487 | }
488 |
489 | return {
490 | path: path,
491 | query: query,
492 | hash: hash
493 | }
494 | }
495 |
496 | function cleanPath (path) {
497 | return path.replace(/\/\//g, '/')
498 | }
499 |
500 | /* */
501 |
502 | function createRouteMap (routes) {
503 | var pathMap = Object.create(null)
504 | var nameMap = Object.create(null)
505 |
506 | routes.forEach(function (route) {
507 | addRouteRecord(pathMap, nameMap, route)
508 | })
509 |
510 | return {
511 | pathMap: pathMap,
512 | nameMap: nameMap
513 | }
514 | }
515 |
516 | function addRouteRecord (
517 | pathMap,
518 | nameMap,
519 | route,
520 | parent,
521 | matchAs
522 | ) {
523 | var path = route.path;
524 | var name = route.name;
525 | if ("development" !== 'production') {
526 | assert(path != null, "\"path\" is required in a route configuration.")
527 | assert(
528 | typeof route.component !== 'string',
529 | "route config \"component\" for path: " + (String(path || name)) + " cannot be a " +
530 | "string id. Use an actual component instead."
531 | )
532 | }
533 |
534 | var record = {
535 | path: normalizePath(path, parent),
536 | components: route.components || { default: route.component },
537 | instances: {},
538 | name: name,
539 | parent: parent,
540 | matchAs: matchAs,
541 | redirect: route.redirect,
542 | beforeEnter: route.beforeEnter,
543 | meta: route.meta || {}
544 | }
545 |
546 | if (route.children) {
547 | // Warn if route is named and has a default child route.
548 | // If users navigate to this route by name, the default child will
549 | // not be rendered (GH Issue #629)
550 | if ("development" !== 'production') {
551 | if (route.name && route.children.some(function (child) { return /^\/?$/.test(child.path); })) {
552 | warn(false, ("Named Route '" + (route.name) + "' has a default child route.\n When navigating to this named route (:to=\"{name: '" + (route.name) + "'\"), the default child route will not be rendered.\n Remove the name from this route and use the name of the default child route for named links instead.")
553 | )
554 | }
555 | }
556 | route.children.forEach(function (child) {
557 | addRouteRecord(pathMap, nameMap, child, record)
558 | })
559 | }
560 |
561 | if (route.alias !== undefined) {
562 | if (Array.isArray(route.alias)) {
563 | route.alias.forEach(function (alias) {
564 | addRouteRecord(pathMap, nameMap, { path: alias }, parent, record.path)
565 | })
566 | } else {
567 | addRouteRecord(pathMap, nameMap, { path: route.alias }, parent, record.path)
568 | }
569 | }
570 |
571 | if (!pathMap[record.path]) {
572 | pathMap[record.path] = record
573 | }
574 | if (name) {
575 | if (!nameMap[name]) {
576 | nameMap[name] = record
577 | } else if ("development" !== 'production') {
578 | warn(false, ("Duplicate named routes definition: { name: \"" + name + "\", path: \"" + (record.path) + "\" }"))
579 | }
580 | }
581 | }
582 |
583 | function normalizePath (path, parent) {
584 | path = path.replace(/\/$/, '')
585 | if (path[0] === '/') { return path }
586 | if (parent == null) { return path }
587 | return cleanPath(((parent.path) + "/" + path))
588 | }
589 |
590 | var __moduleExports = Array.isArray || function (arr) {
591 | return Object.prototype.toString.call(arr) == '[object Array]';
592 | };
593 |
594 | var isarray = __moduleExports
595 |
596 | /**
597 | * Expose `pathToRegexp`.
598 | */
599 | var index = pathToRegexp
600 | var parse_1 = parse
601 | var compile_1 = compile
602 | var tokensToFunction_1 = tokensToFunction
603 | var tokensToRegExp_1 = tokensToRegExp
604 |
605 | /**
606 | * The main path matching regexp utility.
607 | *
608 | * @type {RegExp}
609 | */
610 | var PATH_REGEXP = new RegExp([
611 | // Match escaped characters that would otherwise appear in future matches.
612 | // This allows the user to escape special characters that won't transform.
613 | '(\\\\.)',
614 | // Match Express-style parameters and un-named parameters with a prefix
615 | // and optional suffixes. Matches appear as:
616 | //
617 | // "/:test(\\d+)?" => ["/", "test", "\d+", undefined, "?", undefined]
618 | // "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined, undefined]
619 | // "/*" => ["/", undefined, undefined, undefined, undefined, "*"]
620 | '([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))'
621 | ].join('|'), 'g')
622 |
623 | /**
624 | * Parse a string for the raw tokens.
625 | *
626 | * @param {string} str
627 | * @param {Object=} options
628 | * @return {!Array}
629 | */
630 | function parse (str, options) {
631 | var tokens = []
632 | var key = 0
633 | var index = 0
634 | var path = ''
635 | var defaultDelimiter = options && options.delimiter || '/'
636 | var res
637 |
638 | while ((res = PATH_REGEXP.exec(str)) != null) {
639 | var m = res[0]
640 | var escaped = res[1]
641 | var offset = res.index
642 | path += str.slice(index, offset)
643 | index = offset + m.length
644 |
645 | // Ignore already escaped sequences.
646 | if (escaped) {
647 | path += escaped[1]
648 | continue
649 | }
650 |
651 | var next = str[index]
652 | var prefix = res[2]
653 | var name = res[3]
654 | var capture = res[4]
655 | var group = res[5]
656 | var modifier = res[6]
657 | var asterisk = res[7]
658 |
659 | // Push the current path onto the tokens.
660 | if (path) {
661 | tokens.push(path)
662 | path = ''
663 | }
664 |
665 | var partial = prefix != null && next != null && next !== prefix
666 | var repeat = modifier === '+' || modifier === '*'
667 | var optional = modifier === '?' || modifier === '*'
668 | var delimiter = res[2] || defaultDelimiter
669 | var pattern = capture || group
670 |
671 | tokens.push({
672 | name: name || key++,
673 | prefix: prefix || '',
674 | delimiter: delimiter,
675 | optional: optional,
676 | repeat: repeat,
677 | partial: partial,
678 | asterisk: !!asterisk,
679 | pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?')
680 | })
681 | }
682 |
683 | // Match any characters still remaining.
684 | if (index < str.length) {
685 | path += str.substr(index)
686 | }
687 |
688 | // If the path exists, push it onto the end.
689 | if (path) {
690 | tokens.push(path)
691 | }
692 |
693 | return tokens
694 | }
695 |
696 | /**
697 | * Compile a string to a template function for the path.
698 | *
699 | * @param {string} str
700 | * @param {Object=} options
701 | * @return {!function(Object=, Object=)}
702 | */
703 | function compile (str, options) {
704 | return tokensToFunction(parse(str, options))
705 | }
706 |
707 | /**
708 | * Prettier encoding of URI path segments.
709 | *
710 | * @param {string}
711 | * @return {string}
712 | */
713 | function encodeURIComponentPretty (str) {
714 | return encodeURI(str).replace(/[\/?#]/g, function (c) {
715 | return '%' + c.charCodeAt(0).toString(16).toUpperCase()
716 | })
717 | }
718 |
719 | /**
720 | * Encode the asterisk parameter. Similar to `pretty`, but allows slashes.
721 | *
722 | * @param {string}
723 | * @return {string}
724 | */
725 | function encodeAsterisk (str) {
726 | return encodeURI(str).replace(/[?#]/g, function (c) {
727 | return '%' + c.charCodeAt(0).toString(16).toUpperCase()
728 | })
729 | }
730 |
731 | /**
732 | * Expose a method for transforming tokens into the path function.
733 | */
734 | function tokensToFunction (tokens) {
735 | // Compile all the tokens into regexps.
736 | var matches = new Array(tokens.length)
737 |
738 | // Compile all the patterns before compilation.
739 | for (var i = 0; i < tokens.length; i++) {
740 | if (typeof tokens[i] === 'object') {
741 | matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$')
742 | }
743 | }
744 |
745 | return function (obj, opts) {
746 | var path = ''
747 | var data = obj || {}
748 | var options = opts || {}
749 | var encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent
750 |
751 | for (var i = 0; i < tokens.length; i++) {
752 | var token = tokens[i]
753 |
754 | if (typeof token === 'string') {
755 | path += token
756 |
757 | continue
758 | }
759 |
760 | var value = data[token.name]
761 | var segment
762 |
763 | if (value == null) {
764 | if (token.optional) {
765 | // Prepend partial segment prefixes.
766 | if (token.partial) {
767 | path += token.prefix
768 | }
769 |
770 | continue
771 | } else {
772 | throw new TypeError('Expected "' + token.name + '" to be defined')
773 | }
774 | }
775 |
776 | if (isarray(value)) {
777 | if (!token.repeat) {
778 | throw new TypeError('Expected "' + token.name + '" to not repeat, but received `' + JSON.stringify(value) + '`')
779 | }
780 |
781 | if (value.length === 0) {
782 | if (token.optional) {
783 | continue
784 | } else {
785 | throw new TypeError('Expected "' + token.name + '" to not be empty')
786 | }
787 | }
788 |
789 | for (var j = 0; j < value.length; j++) {
790 | segment = encode(value[j])
791 |
792 | if (!matches[i].test(segment)) {
793 | throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '", but received `' + JSON.stringify(segment) + '`')
794 | }
795 |
796 | path += (j === 0 ? token.prefix : token.delimiter) + segment
797 | }
798 |
799 | continue
800 | }
801 |
802 | segment = token.asterisk ? encodeAsterisk(value) : encode(value)
803 |
804 | if (!matches[i].test(segment)) {
805 | throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but received "' + segment + '"')
806 | }
807 |
808 | path += token.prefix + segment
809 | }
810 |
811 | return path
812 | }
813 | }
814 |
815 | /**
816 | * Escape a regular expression string.
817 | *
818 | * @param {string} str
819 | * @return {string}
820 | */
821 | function escapeString (str) {
822 | return str.replace(/([.+*?=^!:${}()[\]|\/\\])/g, '\\$1')
823 | }
824 |
825 | /**
826 | * Escape the capturing group by escaping special characters and meaning.
827 | *
828 | * @param {string} group
829 | * @return {string}
830 | */
831 | function escapeGroup (group) {
832 | return group.replace(/([=!:$\/()])/g, '\\$1')
833 | }
834 |
835 | /**
836 | * Attach the keys as a property of the regexp.
837 | *
838 | * @param {!RegExp} re
839 | * @param {Array} keys
840 | * @return {!RegExp}
841 | */
842 | function attachKeys (re, keys) {
843 | re.keys = keys
844 | return re
845 | }
846 |
847 | /**
848 | * Get the flags for a regexp from the options.
849 | *
850 | * @param {Object} options
851 | * @return {string}
852 | */
853 | function flags (options) {
854 | return options.sensitive ? '' : 'i'
855 | }
856 |
857 | /**
858 | * Pull out keys from a regexp.
859 | *
860 | * @param {!RegExp} path
861 | * @param {!Array} keys
862 | * @return {!RegExp}
863 | */
864 | function regexpToRegexp (path, keys) {
865 | // Use a negative lookahead to match only capturing groups.
866 | var groups = path.source.match(/\((?!\?)/g)
867 |
868 | if (groups) {
869 | for (var i = 0; i < groups.length; i++) {
870 | keys.push({
871 | name: i,
872 | prefix: null,
873 | delimiter: null,
874 | optional: false,
875 | repeat: false,
876 | partial: false,
877 | asterisk: false,
878 | pattern: null
879 | })
880 | }
881 | }
882 |
883 | return attachKeys(path, keys)
884 | }
885 |
886 | /**
887 | * Transform an array into a regexp.
888 | *
889 | * @param {!Array} path
890 | * @param {Array} keys
891 | * @param {!Object} options
892 | * @return {!RegExp}
893 | */
894 | function arrayToRegexp (path, keys, options) {
895 | var parts = []
896 |
897 | for (var i = 0; i < path.length; i++) {
898 | parts.push(pathToRegexp(path[i], keys, options).source)
899 | }
900 |
901 | var regexp = new RegExp('(?:' + parts.join('|') + ')', flags(options))
902 |
903 | return attachKeys(regexp, keys)
904 | }
905 |
906 | /**
907 | * Create a path regexp from string input.
908 | *
909 | * @param {string} path
910 | * @param {!Array} keys
911 | * @param {!Object} options
912 | * @return {!RegExp}
913 | */
914 | function stringToRegexp (path, keys, options) {
915 | return tokensToRegExp(parse(path, options), keys, options)
916 | }
917 |
918 | /**
919 | * Expose a function for taking tokens and returning a RegExp.
920 | *
921 | * @param {!Array} tokens
922 | * @param {(Array|Object)=} keys
923 | * @param {Object=} options
924 | * @return {!RegExp}
925 | */
926 | function tokensToRegExp (tokens, keys, options) {
927 | if (!isarray(keys)) {
928 | options = /** @type {!Object} */ (keys || options)
929 | keys = []
930 | }
931 |
932 | options = options || {}
933 |
934 | var strict = options.strict
935 | var end = options.end !== false
936 | var route = ''
937 |
938 | // Iterate over the tokens and create our regexp string.
939 | for (var i = 0; i < tokens.length; i++) {
940 | var token = tokens[i]
941 |
942 | if (typeof token === 'string') {
943 | route += escapeString(token)
944 | } else {
945 | var prefix = escapeString(token.prefix)
946 | var capture = '(?:' + token.pattern + ')'
947 |
948 | keys.push(token)
949 |
950 | if (token.repeat) {
951 | capture += '(?:' + prefix + capture + ')*'
952 | }
953 |
954 | if (token.optional) {
955 | if (!token.partial) {
956 | capture = '(?:' + prefix + '(' + capture + '))?'
957 | } else {
958 | capture = prefix + '(' + capture + ')?'
959 | }
960 | } else {
961 | capture = prefix + '(' + capture + ')'
962 | }
963 |
964 | route += capture
965 | }
966 | }
967 |
968 | var delimiter = escapeString(options.delimiter || '/')
969 | var endsWithDelimiter = route.slice(-delimiter.length) === delimiter
970 |
971 | // In non-strict mode we allow a slash at the end of match. If the path to
972 | // match already ends with a slash, we remove it for consistency. The slash
973 | // is valid at the end of a path match, not in the middle. This is important
974 | // in non-ending mode, where "/test/" shouldn't match "/test//route".
975 | if (!strict) {
976 | route = (endsWithDelimiter ? route.slice(0, -delimiter.length) : route) + '(?:' + delimiter + '(?=$))?'
977 | }
978 |
979 | if (end) {
980 | route += '$'
981 | } else {
982 | // In non-ending mode, we need the capturing groups to match as much as
983 | // possible by using a positive lookahead to the end or next path segment.
984 | route += strict && endsWithDelimiter ? '' : '(?=' + delimiter + '|$)'
985 | }
986 |
987 | return attachKeys(new RegExp('^' + route, flags(options)), keys)
988 | }
989 |
990 | /**
991 | * Normalize the given path string, returning a regular expression.
992 | *
993 | * An empty array can be passed in for the keys, which will hold the
994 | * placeholder key descriptions. For example, using `/user/:id`, `keys` will
995 | * contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.
996 | *
997 | * @param {(string|RegExp|Array)} path
998 | * @param {(Array|Object)=} keys
999 | * @param {Object=} options
1000 | * @return {!RegExp}
1001 | */
1002 | function pathToRegexp (path, keys, options) {
1003 | if (!isarray(keys)) {
1004 | options = /** @type {!Object} */ (keys || options)
1005 | keys = []
1006 | }
1007 |
1008 | options = options || {}
1009 |
1010 | if (path instanceof RegExp) {
1011 | return regexpToRegexp(path, /** @type {!Array} */ (keys))
1012 | }
1013 |
1014 | if (isarray(path)) {
1015 | return arrayToRegexp(/** @type {!Array} */ (path), /** @type {!Array} */ (keys), options)
1016 | }
1017 |
1018 | return stringToRegexp(/** @type {string} */ (path), /** @type {!Array} */ (keys), options)
1019 | }
1020 |
1021 | index.parse = parse_1;
1022 | index.compile = compile_1;
1023 | index.tokensToFunction = tokensToFunction_1;
1024 | index.tokensToRegExp = tokensToRegExp_1;
1025 |
1026 | /* */
1027 |
1028 | var regexpCache = Object.create(null)
1029 |
1030 | function getRouteRegex (path) {
1031 | var hit = regexpCache[path]
1032 | var keys, regexp
1033 |
1034 | if (hit) {
1035 | keys = hit.keys
1036 | regexp = hit.regexp
1037 | } else {
1038 | keys = []
1039 | regexp = index(path, keys)
1040 | regexpCache[path] = { keys: keys, regexp: regexp }
1041 | }
1042 |
1043 | return { keys: keys, regexp: regexp }
1044 | }
1045 |
1046 | var regexpCompileCache = Object.create(null)
1047 |
1048 | function fillParams (
1049 | path,
1050 | params,
1051 | routeMsg
1052 | ) {
1053 | try {
1054 | var filler =
1055 | regexpCompileCache[path] ||
1056 | (regexpCompileCache[path] = index.compile(path))
1057 | return filler(params || {}, { pretty: true })
1058 | } catch (e) {
1059 | if ("development" !== 'production') {
1060 | warn(false, ("missing param for " + routeMsg + ": " + (e.message)))
1061 | }
1062 | return ''
1063 | }
1064 | }
1065 |
1066 | /* */
1067 |
1068 | function normalizeLocation (
1069 | raw,
1070 | current,
1071 | append
1072 | ) {
1073 | var next = typeof raw === 'string' ? { path: raw } : raw
1074 | // named target
1075 | if (next.name || next._normalized) {
1076 | return next
1077 | }
1078 |
1079 | // relative params
1080 | if (!next.path && next.params && current) {
1081 | next = assign({}, next)
1082 | next._normalized = true
1083 | var params = assign(assign({}, current.params), next.params)
1084 | if (current.name) {
1085 | next.name = current.name
1086 | next.params = params
1087 | } else if (current.matched) {
1088 | var rawPath = current.matched[current.matched.length - 1].path
1089 | next.path = fillParams(rawPath, params, ("path " + (current.path)))
1090 | } else if ("development" !== 'production') {
1091 | warn(false, "relative params navigation requires a current route.")
1092 | }
1093 | return next
1094 | }
1095 |
1096 | var parsedPath = parsePath(next.path || '')
1097 | var basePath = (current && current.path) || '/'
1098 | var path = parsedPath.path
1099 | ? resolvePath(parsedPath.path, basePath, append || next.append)
1100 | : (current && current.path) || '/'
1101 | var query = resolveQuery(parsedPath.query, next.query)
1102 | var hash = next.hash || parsedPath.hash
1103 | if (hash && hash.charAt(0) !== '#') {
1104 | hash = "#" + hash
1105 | }
1106 |
1107 | return {
1108 | _normalized: true,
1109 | path: path,
1110 | query: query,
1111 | hash: hash
1112 | }
1113 | }
1114 |
1115 | function assign (a, b) {
1116 | for (var key in b) {
1117 | a[key] = b[key]
1118 | }
1119 | return a
1120 | }
1121 |
1122 | /* */
1123 |
1124 | function createMatcher (routes) {
1125 | var ref = createRouteMap(routes);
1126 | var pathMap = ref.pathMap;
1127 | var nameMap = ref.nameMap;
1128 |
1129 | function match (
1130 | raw,
1131 | currentRoute,
1132 | redirectedFrom
1133 | ) {
1134 | var location = normalizeLocation(raw, currentRoute)
1135 | var name = location.name;
1136 |
1137 | if (name) {
1138 | var record = nameMap[name]
1139 | var paramNames = getRouteRegex(record.path).keys
1140 | .filter(function (key) { return !key.optional; })
1141 | .map(function (key) { return key.name; })
1142 |
1143 | if (typeof location.params !== 'object') {
1144 | location.params = {}
1145 | }
1146 |
1147 | if (currentRoute && typeof currentRoute.params === 'object') {
1148 | for (var key in currentRoute.params) {
1149 | if (!(key in location.params) && paramNames.indexOf(key) > -1) {
1150 | location.params[key] = currentRoute.params[key]
1151 | }
1152 | }
1153 | }
1154 |
1155 | if (record) {
1156 | location.path = fillParams(record.path, location.params, ("named route \"" + name + "\""))
1157 | return _createRoute(record, location, redirectedFrom)
1158 | }
1159 | } else if (location.path) {
1160 | location.params = {}
1161 | for (var path in pathMap) {
1162 | if (matchRoute(path, location.params, location.path)) {
1163 | return _createRoute(pathMap[path], location, redirectedFrom)
1164 | }
1165 | }
1166 | }
1167 | // no match
1168 | return _createRoute(null, location)
1169 | }
1170 |
1171 | function redirect (
1172 | record,
1173 | location
1174 | ) {
1175 | var originalRedirect = record.redirect
1176 | var redirect = typeof originalRedirect === 'function'
1177 | ? originalRedirect(createRoute(record, location))
1178 | : originalRedirect
1179 |
1180 | if (typeof redirect === 'string') {
1181 | redirect = { path: redirect }
1182 | }
1183 |
1184 | if (!redirect || typeof redirect !== 'object') {
1185 | "development" !== 'production' && warn(
1186 | false, ("invalid redirect option: " + (JSON.stringify(redirect)))
1187 | )
1188 | return _createRoute(null, location)
1189 | }
1190 |
1191 | var re = redirect
1192 | var name = re.name;
1193 | var path = re.path;
1194 | var query = location.query;
1195 | var hash = location.hash;
1196 | var params = location.params;
1197 | query = re.hasOwnProperty('query') ? re.query : query
1198 | hash = re.hasOwnProperty('hash') ? re.hash : hash
1199 | params = re.hasOwnProperty('params') ? re.params : params
1200 |
1201 | if (name) {
1202 | // resolved named direct
1203 | var targetRecord = nameMap[name]
1204 | if ("development" !== 'production') {
1205 | assert(targetRecord, ("redirect failed: named route \"" + name + "\" not found."))
1206 | }
1207 | return match({
1208 | _normalized: true,
1209 | name: name,
1210 | query: query,
1211 | hash: hash,
1212 | params: params
1213 | }, undefined, location)
1214 | } else if (path) {
1215 | // 1. resolve relative redirect
1216 | var rawPath = resolveRecordPath(path, record)
1217 | // 2. resolve params
1218 | var resolvedPath = fillParams(rawPath, params, ("redirect route with path \"" + rawPath + "\""))
1219 | // 3. rematch with existing query and hash
1220 | return match({
1221 | _normalized: true,
1222 | path: resolvedPath,
1223 | query: query,
1224 | hash: hash
1225 | }, undefined, location)
1226 | } else {
1227 | warn(false, ("invalid redirect option: " + (JSON.stringify(redirect))))
1228 | return _createRoute(null, location)
1229 | }
1230 | }
1231 |
1232 | function alias (
1233 | record,
1234 | location,
1235 | matchAs
1236 | ) {
1237 | var aliasedPath = fillParams(matchAs, location.params, ("aliased route with path \"" + matchAs + "\""))
1238 | var aliasedMatch = match({
1239 | _normalized: true,
1240 | path: aliasedPath
1241 | })
1242 | if (aliasedMatch) {
1243 | var matched = aliasedMatch.matched
1244 | var aliasedRecord = matched[matched.length - 1]
1245 | location.params = aliasedMatch.params
1246 | return _createRoute(aliasedRecord, location)
1247 | }
1248 | return _createRoute(null, location)
1249 | }
1250 |
1251 | function _createRoute (
1252 | record,
1253 | location,
1254 | redirectedFrom
1255 | ) {
1256 | if (record && record.redirect) {
1257 | return redirect(record, redirectedFrom || location)
1258 | }
1259 | if (record && record.matchAs) {
1260 | return alias(record, location, record.matchAs)
1261 | }
1262 | return createRoute(record, location, redirectedFrom)
1263 | }
1264 |
1265 | return match
1266 | }
1267 |
1268 | function matchRoute (
1269 | path,
1270 | params,
1271 | pathname
1272 | ) {
1273 | var ref = getRouteRegex(path);
1274 | var regexp = ref.regexp;
1275 | var keys = ref.keys;
1276 | var m = pathname.match(regexp)
1277 |
1278 | if (!m) {
1279 | return false
1280 | } else if (!params) {
1281 | return true
1282 | }
1283 |
1284 | for (var i = 1, len = m.length; i < len; ++i) {
1285 | var key = keys[i - 1]
1286 | var val = typeof m[i] === 'string' ? decodeURIComponent(m[i]) : m[i]
1287 | if (key) { params[key.name] = val }
1288 | }
1289 |
1290 | return true
1291 | }
1292 |
1293 | function resolveRecordPath (path, record) {
1294 | return resolvePath(path, record.parent ? record.parent.path : '/', true)
1295 | }
1296 |
1297 | /* */
1298 |
1299 | var inBrowser = typeof window !== 'undefined'
1300 |
1301 | var supportsHistory = inBrowser && (function () {
1302 | var ua = window.navigator.userAgent
1303 |
1304 | if (
1305 | (ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) &&
1306 | ua.indexOf('Mobile Safari') !== -1 &&
1307 | ua.indexOf('Chrome') === -1 &&
1308 | ua.indexOf('Windows Phone') === -1
1309 | ) {
1310 | return false
1311 | }
1312 |
1313 | return window.history && 'pushState' in window.history
1314 | })()
1315 |
1316 | /* */
1317 |
1318 | function runQueue (queue, fn, cb) {
1319 | var step = function (index) {
1320 | if (index >= queue.length) {
1321 | cb()
1322 | } else {
1323 | if (queue[index]) {
1324 | fn(queue[index], function () {
1325 | step(index + 1)
1326 | })
1327 | } else {
1328 | step(index + 1)
1329 | }
1330 | }
1331 | }
1332 | step(0)
1333 | }
1334 |
1335 | /* */
1336 |
1337 |
1338 | var History = function History (router, base) {
1339 | this.router = router
1340 | this.base = normalizeBase(base)
1341 | // start with a route object that stands for "nowhere"
1342 | this.current = START
1343 | this.pending = null
1344 | };
1345 |
1346 | History.prototype.listen = function listen (cb) {
1347 | this.cb = cb
1348 | };
1349 |
1350 | History.prototype.transitionTo = function transitionTo (location, onComplete, onAbort) {
1351 | var this$1 = this;
1352 |
1353 | var route = this.router.match(location, this.current)
1354 | this.confirmTransition(route, function () {
1355 | this$1.updateRoute(route)
1356 | onComplete && onComplete(route)
1357 | this$1.ensureURL()
1358 | }, onAbort)
1359 | };
1360 |
1361 | History.prototype.confirmTransition = function confirmTransition (route, onComplete, onAbort) {
1362 | var this$1 = this;
1363 |
1364 | var current = this.current
1365 | var abort = function () { onAbort && onAbort() }
1366 | if (isSameRoute(route, current)) {
1367 | this.ensureURL()
1368 | return abort()
1369 | }
1370 |
1371 | var ref = resolveQueue(this.current.matched, route.matched);
1372 | var deactivated = ref.deactivated;
1373 | var activated = ref.activated;
1374 |
1375 | var queue = [].concat(
1376 | // in-component leave guards
1377 | extractLeaveGuards(deactivated),
1378 | // global before hooks
1379 | this.router.beforeHooks,
1380 | // enter guards
1381 | activated.map(function (m) { return m.beforeEnter; }),
1382 | // async components
1383 | resolveAsyncComponents(activated)
1384 | )
1385 |
1386 | this.pending = route
1387 | var iterator = function (hook, next) {
1388 | if (this$1.pending !== route) {
1389 | return abort()
1390 | }
1391 | hook(route, current, function (to) {
1392 | if (to === false) {
1393 | // next(false) -> abort navigation, ensure current URL
1394 | this$1.ensureURL(true)
1395 | abort()
1396 | } else if (typeof to === 'string' || typeof to === 'object') {
1397 | // next('/') or next({ path: '/' }) -> redirect
1398 | (typeof to === 'object' && to.replace) ? this$1.replace(to) : this$1.push(to)
1399 | abort()
1400 | } else {
1401 | // confirm transition and pass on the value
1402 | next(to)
1403 | }
1404 | })
1405 | }
1406 |
1407 | runQueue(queue, iterator, function () {
1408 | var postEnterCbs = []
1409 | var enterGuards = extractEnterGuards(activated, postEnterCbs, function () {
1410 | return this$1.current === route
1411 | })
1412 | // wait until async components are resolved before
1413 | // extracting in-component enter guards
1414 | runQueue(enterGuards, iterator, function () {
1415 | if (this$1.pending !== route) {
1416 | return abort()
1417 | }
1418 | this$1.pending = null
1419 | onComplete(route)
1420 | if (this$1.router.app) {
1421 | this$1.router.app.$nextTick(function () {
1422 | postEnterCbs.forEach(function (cb) { return cb(); })
1423 | })
1424 | }
1425 | })
1426 | })
1427 | };
1428 |
1429 | History.prototype.updateRoute = function updateRoute (route) {
1430 | var prev = this.current
1431 | this.current = route
1432 | this.cb && this.cb(route)
1433 | this.router.afterHooks.forEach(function (hook) {
1434 | hook && hook(route, prev)
1435 | })
1436 | };
1437 |
1438 | function normalizeBase (base) {
1439 | if (!base) {
1440 | if (inBrowser) {
1441 | // respect tag
1442 | var baseEl = document.querySelector('base')
1443 | base = baseEl ? baseEl.getAttribute('href') : '/'
1444 | } else {
1445 | base = '/'
1446 | }
1447 | }
1448 | // make sure there's the starting slash
1449 | if (base.charAt(0) !== '/') {
1450 | base = '/' + base
1451 | }
1452 | // remove trailing slash
1453 | return base.replace(/\/$/, '')
1454 | }
1455 |
1456 | function resolveQueue (
1457 | current,
1458 | next
1459 | ) {
1460 | var i
1461 | var max = Math.max(current.length, next.length)
1462 | for (i = 0; i < max; i++) {
1463 | if (current[i] !== next[i]) {
1464 | break
1465 | }
1466 | }
1467 | return {
1468 | activated: next.slice(i),
1469 | deactivated: current.slice(i)
1470 | }
1471 | }
1472 |
1473 | function extractGuard (
1474 | def,
1475 | key
1476 | ) {
1477 | if (typeof def !== 'function') {
1478 | // extend now so that global mixins are applied.
1479 | def = _Vue.extend(def)
1480 | }
1481 | return def.options[key]
1482 | }
1483 |
1484 | function extractLeaveGuards (matched) {
1485 | return flatten(flatMapComponents(matched, function (def, instance) {
1486 | var guard = extractGuard(def, 'beforeRouteLeave')
1487 | if (guard) {
1488 | return Array.isArray(guard)
1489 | ? guard.map(function (guard) { return wrapLeaveGuard(guard, instance); })
1490 | : wrapLeaveGuard(guard, instance)
1491 | }
1492 | }).reverse())
1493 | }
1494 |
1495 | function wrapLeaveGuard (
1496 | guard,
1497 | instance
1498 | ) {
1499 | return function routeLeaveGuard () {
1500 | return guard.apply(instance, arguments)
1501 | }
1502 | }
1503 |
1504 | function extractEnterGuards (
1505 | matched,
1506 | cbs,
1507 | isValid
1508 | ) {
1509 | return flatten(flatMapComponents(matched, function (def, _, match, key) {
1510 | var guard = extractGuard(def, 'beforeRouteEnter')
1511 | if (guard) {
1512 | return Array.isArray(guard)
1513 | ? guard.map(function (guard) { return wrapEnterGuard(guard, cbs, match, key, isValid); })
1514 | : wrapEnterGuard(guard, cbs, match, key, isValid)
1515 | }
1516 | }))
1517 | }
1518 |
1519 | function wrapEnterGuard (
1520 | guard,
1521 | cbs,
1522 | match,
1523 | key,
1524 | isValid
1525 | ) {
1526 | return function routeEnterGuard (to, from, next) {
1527 | return guard(to, from, function (cb) {
1528 | next(cb)
1529 | if (typeof cb === 'function') {
1530 | cbs.push(function () {
1531 | // #750
1532 | // if a router-view is wrapped with an out-in transition,
1533 | // the instance may not have been registered at this time.
1534 | // we will need to poll for registration until current route
1535 | // is no longer valid.
1536 | poll(cb, match.instances, key, isValid)
1537 | })
1538 | }
1539 | })
1540 | }
1541 | }
1542 |
1543 | function poll (
1544 | cb, // somehow flow cannot infer this is a function
1545 | instances,
1546 | key,
1547 | isValid
1548 | ) {
1549 | if (instances[key]) {
1550 | cb(instances[key])
1551 | } else if (isValid()) {
1552 | setTimeout(function () {
1553 | poll(cb, instances, key, isValid)
1554 | }, 16)
1555 | }
1556 | }
1557 |
1558 | function resolveAsyncComponents (matched) {
1559 | return flatMapComponents(matched, function (def, _, match, key) {
1560 | // if it's a function and doesn't have Vue options attached,
1561 | // assume it's an async component resolve function.
1562 | // we are not using Vue's default async resolving mechanism because
1563 | // we want to halt the navigation until the incoming component has been
1564 | // resolved.
1565 | if (typeof def === 'function' && !def.options) {
1566 | return function (to, from, next) {
1567 | var resolve = function (resolvedDef) {
1568 | match.components[key] = resolvedDef
1569 | next()
1570 | }
1571 |
1572 | var reject = function (reason) {
1573 | warn(false, ("Failed to resolve async component " + key + ": " + reason))
1574 | next(false)
1575 | }
1576 |
1577 | var res = def(resolve, reject)
1578 | if (res && typeof res.then === 'function') {
1579 | res.then(resolve, reject)
1580 | }
1581 | }
1582 | }
1583 | })
1584 | }
1585 |
1586 | function flatMapComponents (
1587 | matched,
1588 | fn
1589 | ) {
1590 | return flatten(matched.map(function (m) {
1591 | return Object.keys(m.components).map(function (key) { return fn(
1592 | m.components[key],
1593 | m.instances[key],
1594 | m, key
1595 | ); })
1596 | }))
1597 | }
1598 |
1599 | function flatten (arr) {
1600 | return Array.prototype.concat.apply([], arr)
1601 | }
1602 |
1603 | /* */
1604 |
1605 | var positionStore = Object.create(null)
1606 |
1607 | function saveScrollPosition (key) {
1608 | if (!key) { return }
1609 | positionStore[key] = {
1610 | x: window.pageXOffset,
1611 | y: window.pageYOffset
1612 | }
1613 | }
1614 |
1615 | function getScrollPosition (key) {
1616 | if (!key) { return }
1617 | return positionStore[key]
1618 | }
1619 |
1620 | function getElementPosition (el) {
1621 | var docRect = document.documentElement.getBoundingClientRect()
1622 | var elRect = el.getBoundingClientRect()
1623 | return {
1624 | x: elRect.left - docRect.left,
1625 | y: elRect.top - docRect.top
1626 | }
1627 | }
1628 |
1629 | function isValidPosition (obj) {
1630 | return isNumber(obj.x) || isNumber(obj.y)
1631 | }
1632 |
1633 | function normalizePosition (obj) {
1634 | return {
1635 | x: isNumber(obj.x) ? obj.x : window.pageXOffset,
1636 | y: isNumber(obj.y) ? obj.y : window.pageYOffset
1637 | }
1638 | }
1639 |
1640 | function isNumber (v) {
1641 | return typeof v === 'number'
1642 | }
1643 |
1644 | /* */
1645 |
1646 |
1647 | var genKey = function () { return String(Date.now()); }
1648 | var _key = genKey()
1649 |
1650 | var HTML5History = (function (History) {
1651 | function HTML5History (router, base) {
1652 | var this$1 = this;
1653 |
1654 | History.call(this, router, base)
1655 |
1656 | var expectScroll = router.options.scrollBehavior
1657 | window.addEventListener('popstate', function (e) {
1658 | _key = e.state && e.state.key
1659 | var current = this$1.current
1660 | this$1.transitionTo(getLocation(this$1.base), function (next) {
1661 | if (expectScroll) {
1662 | this$1.handleScroll(next, current, true)
1663 | }
1664 | })
1665 | })
1666 |
1667 | if (expectScroll) {
1668 | window.addEventListener('scroll', function () {
1669 | saveScrollPosition(_key)
1670 | })
1671 | }
1672 | }
1673 |
1674 | if ( History ) HTML5History.__proto__ = History;
1675 | HTML5History.prototype = Object.create( History && History.prototype );
1676 | HTML5History.prototype.constructor = HTML5History;
1677 |
1678 | HTML5History.prototype.go = function go (n) {
1679 | window.history.go(n)
1680 | };
1681 |
1682 | HTML5History.prototype.push = function push (location) {
1683 | var this$1 = this;
1684 |
1685 | var current = this.current
1686 | this.transitionTo(location, function (route) {
1687 | pushState(cleanPath(this$1.base + route.fullPath))
1688 | this$1.handleScroll(route, current, false)
1689 | })
1690 | };
1691 |
1692 | HTML5History.prototype.replace = function replace (location) {
1693 | var this$1 = this;
1694 |
1695 | var current = this.current
1696 | this.transitionTo(location, function (route) {
1697 | replaceState(cleanPath(this$1.base + route.fullPath))
1698 | this$1.handleScroll(route, current, false)
1699 | })
1700 | };
1701 |
1702 | HTML5History.prototype.ensureURL = function ensureURL (push) {
1703 | if (getLocation(this.base) !== this.current.fullPath) {
1704 | var current = cleanPath(this.base + this.current.fullPath)
1705 | push ? pushState(current) : replaceState(current)
1706 | }
1707 | };
1708 |
1709 | HTML5History.prototype.handleScroll = function handleScroll (to, from, isPop) {
1710 | var router = this.router
1711 | if (!router.app) {
1712 | return
1713 | }
1714 |
1715 | var behavior = router.options.scrollBehavior
1716 | if (!behavior) {
1717 | return
1718 | }
1719 | if ("development" !== 'production') {
1720 | assert(typeof behavior === 'function', "scrollBehavior must be a function")
1721 | }
1722 |
1723 | // wait until re-render finishes before scrolling
1724 | router.app.$nextTick(function () {
1725 | var position = getScrollPosition(_key)
1726 | var shouldScroll = behavior(to, from, isPop ? position : null)
1727 | if (!shouldScroll) {
1728 | return
1729 | }
1730 | var isObject = typeof shouldScroll === 'object'
1731 | if (isObject && typeof shouldScroll.selector === 'string') {
1732 | var el = document.querySelector(shouldScroll.selector)
1733 | if (el) {
1734 | position = getElementPosition(el)
1735 | } else if (isValidPosition(shouldScroll)) {
1736 | position = normalizePosition(shouldScroll)
1737 | }
1738 | } else if (isObject && isValidPosition(shouldScroll)) {
1739 | position = normalizePosition(shouldScroll)
1740 | }
1741 |
1742 | if (position) {
1743 | window.scrollTo(position.x, position.y)
1744 | }
1745 | })
1746 | };
1747 |
1748 | return HTML5History;
1749 | }(History));
1750 |
1751 | function getLocation (base) {
1752 | var path = window.location.pathname
1753 | if (base && path.indexOf(base) === 0) {
1754 | path = path.slice(base.length)
1755 | }
1756 | return (path || '/') + window.location.search + window.location.hash
1757 | }
1758 |
1759 | function pushState (url, replace) {
1760 | // try...catch the pushState call to get around Safari
1761 | // DOM Exception 18 where it limits to 100 pushState calls
1762 | var history = window.history
1763 | try {
1764 | if (replace) {
1765 | history.replaceState({ key: _key }, '', url)
1766 | } else {
1767 | _key = genKey()
1768 | history.pushState({ key: _key }, '', url)
1769 | }
1770 | saveScrollPosition(_key)
1771 | } catch (e) {
1772 | window.location[replace ? 'assign' : 'replace'](url)
1773 | }
1774 | }
1775 |
1776 | function replaceState (url) {
1777 | pushState(url, true)
1778 | }
1779 |
1780 | /* */
1781 |
1782 |
1783 | var HashHistory = (function (History) {
1784 | function HashHistory (router, base, fallback) {
1785 | History.call(this, router, base)
1786 | // check history fallback deeplinking
1787 | if (fallback && this.checkFallback()) {
1788 | return
1789 | }
1790 | ensureSlash()
1791 | }
1792 |
1793 | if ( History ) HashHistory.__proto__ = History;
1794 | HashHistory.prototype = Object.create( History && History.prototype );
1795 | HashHistory.prototype.constructor = HashHistory;
1796 |
1797 | HashHistory.prototype.checkFallback = function checkFallback () {
1798 | var location = getLocation(this.base)
1799 | if (!/^\/#/.test(location)) {
1800 | window.location.replace(
1801 | cleanPath(this.base + '/#' + location)
1802 | )
1803 | return true
1804 | }
1805 | };
1806 |
1807 | HashHistory.prototype.onHashChange = function onHashChange () {
1808 | if (!ensureSlash()) {
1809 | return
1810 | }
1811 | this.transitionTo(getHash(), function (route) {
1812 | replaceHash(route.fullPath)
1813 | })
1814 | };
1815 |
1816 | HashHistory.prototype.push = function push (location) {
1817 | this.transitionTo(location, function (route) {
1818 | pushHash(route.fullPath)
1819 | })
1820 | };
1821 |
1822 | HashHistory.prototype.replace = function replace (location) {
1823 | this.transitionTo(location, function (route) {
1824 | replaceHash(route.fullPath)
1825 | })
1826 | };
1827 |
1828 | HashHistory.prototype.go = function go (n) {
1829 | window.history.go(n)
1830 | };
1831 |
1832 | HashHistory.prototype.ensureURL = function ensureURL (push) {
1833 | var current = this.current.fullPath
1834 | if (getHash() !== current) {
1835 | push ? pushHash(current) : replaceHash(current)
1836 | }
1837 | };
1838 |
1839 | return HashHistory;
1840 | }(History));
1841 |
1842 | function ensureSlash () {
1843 | var path = getHash()
1844 | if (path.charAt(0) === '/') {
1845 | return true
1846 | }
1847 | replaceHash('/' + path)
1848 | return false
1849 | }
1850 |
1851 | function getHash () {
1852 | // We can't use window.location.hash here because it's not
1853 | // consistent across browsers - Firefox will pre-decode it!
1854 | var href = window.location.href
1855 | var index = href.indexOf('#')
1856 | return index === -1 ? '' : href.slice(index + 1)
1857 | }
1858 |
1859 | function pushHash (path) {
1860 | window.location.hash = path
1861 | }
1862 |
1863 | function replaceHash (path) {
1864 | var i = window.location.href.indexOf('#')
1865 | window.location.replace(
1866 | window.location.href.slice(0, i >= 0 ? i : 0) + '#' + path
1867 | )
1868 | }
1869 |
1870 | /* */
1871 |
1872 |
1873 | var AbstractHistory = (function (History) {
1874 | function AbstractHistory (router) {
1875 | History.call(this, router)
1876 | this.stack = []
1877 | this.index = -1
1878 | }
1879 |
1880 | if ( History ) AbstractHistory.__proto__ = History;
1881 | AbstractHistory.prototype = Object.create( History && History.prototype );
1882 | AbstractHistory.prototype.constructor = AbstractHistory;
1883 |
1884 | AbstractHistory.prototype.push = function push (location) {
1885 | var this$1 = this;
1886 |
1887 | this.transitionTo(location, function (route) {
1888 | this$1.stack = this$1.stack.slice(0, this$1.index + 1).concat(route)
1889 | this$1.index++
1890 | })
1891 | };
1892 |
1893 | AbstractHistory.prototype.replace = function replace (location) {
1894 | var this$1 = this;
1895 |
1896 | this.transitionTo(location, function (route) {
1897 | this$1.stack = this$1.stack.slice(0, this$1.index).concat(route)
1898 | })
1899 | };
1900 |
1901 | AbstractHistory.prototype.go = function go (n) {
1902 | var this$1 = this;
1903 |
1904 | var targetIndex = this.index + n
1905 | if (targetIndex < 0 || targetIndex >= this.stack.length) {
1906 | return
1907 | }
1908 | var route = this.stack[targetIndex]
1909 | this.confirmTransition(route, function () {
1910 | this$1.index = targetIndex
1911 | this$1.updateRoute(route)
1912 | })
1913 | };
1914 |
1915 | AbstractHistory.prototype.ensureURL = function ensureURL () {
1916 | // noop
1917 | };
1918 |
1919 | return AbstractHistory;
1920 | }(History));
1921 |
1922 | /* */
1923 |
1924 | var VueRouter = function VueRouter (options) {
1925 | if ( options === void 0 ) options = {};
1926 |
1927 | this.app = null
1928 | this.options = options
1929 | this.beforeHooks = []
1930 | this.afterHooks = []
1931 | this.match = createMatcher(options.routes || [])
1932 |
1933 | var mode = options.mode || 'hash'
1934 | this.fallback = mode === 'history' && !supportsHistory
1935 | if (this.fallback) {
1936 | mode = 'hash'
1937 | }
1938 | if (!inBrowser) {
1939 | mode = 'abstract'
1940 | }
1941 | this.mode = mode
1942 |
1943 | switch (mode) {
1944 | case 'history':
1945 | this.history = new HTML5History(this, options.base)
1946 | break
1947 | case 'hash':
1948 | this.history = new HashHistory(this, options.base, this.fallback)
1949 | break
1950 | case 'abstract':
1951 | this.history = new AbstractHistory(this)
1952 | break
1953 | default:
1954 | "development" !== 'production' && assert(false, ("invalid mode: " + mode))
1955 | }
1956 | };
1957 |
1958 | var prototypeAccessors = { currentRoute: {} };
1959 |
1960 | prototypeAccessors.currentRoute.get = function () {
1961 | return this.history && this.history.current
1962 | };
1963 |
1964 | VueRouter.prototype.init = function init (app /* Vue component instance */) {
1965 | var this$1 = this;
1966 |
1967 | "development" !== 'production' && assert(
1968 | install.installed,
1969 | "not installed. Make sure to call `Vue.use(VueRouter)` " +
1970 | "before creating root instance."
1971 | )
1972 |
1973 | this.app = app
1974 |
1975 | var history = this.history
1976 |
1977 | if (history instanceof HTML5History) {
1978 | history.transitionTo(getLocation(history.base))
1979 | } else if (history instanceof HashHistory) {
1980 | var setupHashListener = function () {
1981 | window.addEventListener('hashchange', function () {
1982 | history.onHashChange()
1983 | })
1984 | }
1985 | history.transitionTo(getHash(), setupHashListener, setupHashListener)
1986 | }
1987 |
1988 | history.listen(function (route) {
1989 | this$1.app._route = route
1990 | })
1991 | };
1992 |
1993 | VueRouter.prototype.beforeEach = function beforeEach (fn) {
1994 | this.beforeHooks.push(fn)
1995 | };
1996 |
1997 | VueRouter.prototype.afterEach = function afterEach (fn) {
1998 | this.afterHooks.push(fn)
1999 | };
2000 |
2001 | VueRouter.prototype.push = function push (location) {
2002 | this.history.push(location)
2003 | };
2004 |
2005 | VueRouter.prototype.replace = function replace (location) {
2006 | this.history.replace(location)
2007 | };
2008 |
2009 | VueRouter.prototype.go = function go (n) {
2010 | this.history.go(n)
2011 | };
2012 |
2013 | VueRouter.prototype.back = function back () {
2014 | this.go(-1)
2015 | };
2016 |
2017 | VueRouter.prototype.forward = function forward () {
2018 | this.go(1)
2019 | };
2020 |
2021 | VueRouter.prototype.getMatchedComponents = function getMatchedComponents (to) {
2022 | var route = to
2023 | ? this.resolve(to).resolved
2024 | : this.currentRoute
2025 | if (!route) {
2026 | return []
2027 | }
2028 | return [].concat.apply([], route.matched.map(function (m) {
2029 | return Object.keys(m.components).map(function (key) {
2030 | return m.components[key]
2031 | })
2032 | }))
2033 | };
2034 |
2035 | VueRouter.prototype.resolve = function resolve (
2036 | to,
2037 | current,
2038 | append
2039 | ) {
2040 | var normalizedTo = normalizeLocation(to, current || this.history.current, append)
2041 | var resolved = this.match(normalizedTo, current)
2042 | var fullPath = resolved.redirectedFrom || resolved.fullPath
2043 | var base = this.history.base
2044 | var href = createHref(base, fullPath, this.mode)
2045 | return {
2046 | normalizedTo: normalizedTo,
2047 | resolved: resolved,
2048 | href: href
2049 | }
2050 | };
2051 |
2052 | Object.defineProperties( VueRouter.prototype, prototypeAccessors );
2053 |
2054 | function createHref (base, fullPath, mode) {
2055 | var path = mode === 'hash' ? '#' + fullPath : fullPath
2056 | return base ? cleanPath(base + '/' + path) : path
2057 | }
2058 |
2059 | VueRouter.install = install
2060 |
2061 | if (inBrowser && window.Vue) {
2062 | window.Vue.use(VueRouter)
2063 | }
2064 |
2065 | return VueRouter;
2066 |
2067 | })));
--------------------------------------------------------------------------------
/footer.php:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |