forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQRouteTab.js
More file actions
144 lines (125 loc) · 3.92 KB
/
QRouteTab.js
File metadata and controls
144 lines (125 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import Vue from 'vue'
import QTab from './QTab.js'
import RouterLinkMixin from '../../mixins/router-link.js'
import { isSameRoute, isIncludedRoute } from '../../utils/router.js'
import { stopAndPrevent, noop } from '../../utils/event.js'
export default Vue.extend({
name: 'QRouteTab',
mixins: [ QTab, RouterLinkMixin ],
inject: {
__activateRoute: {},
__recalculateScroll: {}
},
watch: {
$route () {
this.__checkActivation()
}
},
computed: {
routerTabLinkProps () {
return {
...this.linkProps.props,
custom: true
}
}
},
methods: {
__activate (e, keyboard) {
if (this.disable !== true) {
if (
e !== void 0 && (
e.ctrlKey === true ||
e.shiftKey === true ||
e.altKey === true ||
e.metaKey === true
)
) {
// if it has meta keys, let vue-router link
// handle this by its own
this.__checkActivation(true)
}
else if (this.hasRouterLink === true) {
// we use programatic navigation instead of letting vue-router handle it
// so we can check for activation when the navigation is complete
e !== void 0 && stopAndPrevent(e)
const go = (to = this.to, append = this.append, replace = this.replace) => {
const { route } = this.$router.resolve(to, this.$route, append)
const checkFn = to === this.to && append === this.append
? this.__checkActivation
: noop
// vue-router now throwing error if navigating
// to the same route that the user is currently at
// https://github.com/vuejs/vue-router/issues/2872
this.$router[replace === true ? 'replace' : 'push'](
route,
() => { checkFn(true) },
err => {
if (err && err.name === 'NavigationDuplicated') {
checkFn(true)
}
}
)
}
this.qListeners.click !== void 0 && this.$emit('click', e, go)
if (e === void 0 || e.navigate !== false) {
go()
}
}
}
if (keyboard === true) {
this.$el.focus({ preventScroll: true })
}
else if (this.$refs.blurTarget !== void 0) {
this.$refs.blurTarget.focus({ preventScroll: true })
}
},
__checkActivation (selected = false) {
if (this.hasRouterLink !== true) {
return
}
const
current = this.$route,
{ href, location, route } = this.$router.resolve(this.to, current, this.append),
redirected = route.redirectedFrom !== void 0,
isSameRouteCheck = isSameRoute(current, route),
checkFunction = this.exact === true ? isSameRoute : isIncludedRoute,
params = {
name: this.name,
selected,
exact: this.exact,
priorityMatched: route.matched.length,
priorityHref: href.length
}
if (isSameRouteCheck === true || (this.exact !== true && isIncludedRoute(current, route) === true)) {
this.__activateRoute({
...params,
redirected,
// if it's an exact match give higher priority
// even if the tab is not marked as exact
exact: this.exact === true || isSameRouteCheck === true
})
}
if (
redirected === true &&
checkFunction(current, {
path: route.redirectedFrom,
...location
}) === true
) {
this.__activateRoute(params)
}
this.isActive === true && this.__activateRoute()
}
},
mounted () {
this.__recalculateScroll()
this.$router !== void 0 && this.__checkActivation()
},
beforeDestroy () {
this.__recalculateScroll()
this.__activateRoute({ remove: true, name: this.name })
},
render (h) {
return this.__renderTab(h, this.linkTag)
}
})