forked from telepenin/cloudlinux-doc-theme
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathNavbar.vue
215 lines (188 loc) · 5.07 KB
/
Navbar.vue
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<template>
<header class="navbar">
<SidebarButton @toggle-sidebar="$emit('toggle-sidebar')"/>
<router-link
:to="homeUrl"
class="home-link"
>
<img
class="logo"
v-if="$site.themeConfig.logo"
:src="$withBase($site.themeConfig.logo)"
:alt="$siteTitle"
>
<span
ref="siteName"
class="site-name site-name--documentation"
v-if="$siteTitle"
:class="{ 'can-hide': $site.themeConfig.logo }"
>{{ $siteTitle }}</span>
</router-link>
<!-- <div class="line"></div> -->
<AlgoliaSearchBox
v-if="isAlgoliaSearch"
:options="algolia"
/>
<SearchBox v-else-if="$site.themeConfig.search !== false"/>
<div
class="links"
:style="{
'max-width': linksWrapMaxWidth + 'px'
}"
>
<a v-for="item in $themeLocaleConfig.navbarLinks"
:href="item.url"
target="_blank"
class="btn"
@click="onClick(item.event)">{{ item.text }}</a>
<NavLinks class="can-hide"/>
</div>
</header>
</template>
<script>
import SidebarButton from './SidebarButton.vue'
import AlgoliaSearchBox from './AlgoliaSearchBox'
import SearchBox from './SearchBox.vue'
import NavLinks from './NavLinks.vue'
export default {
components: { SidebarButton, NavLinks, SearchBox, AlgoliaSearchBox },
data () {
return {
linksWrapMaxWidth: null
}
},
mounted () {
const MOBILE_DESKTOP_BREAKPOINT = 719 // refer to config.styl
const NAVBAR_VERTICAL_PADDING = parseInt(css(this.$el, 'paddingLeft')) + parseInt(css(this.$el, 'paddingRight'))
const handleLinksWrapWidth = () => {
if (document.documentElement.clientWidth < MOBILE_DESKTOP_BREAKPOINT) {
this.linksWrapMaxWidth = null
} else {
this.linksWrapMaxWidth = this.$el.offsetWidth - NAVBAR_VERTICAL_PADDING -
(this.$refs.siteName && this.$refs.siteName.offsetWidth || 0)
}
}
handleLinksWrapWidth()
window.addEventListener('resize', handleLinksWrapWidth, false)
},
computed: {
algolia () {
return this.$themeLocaleConfig.algolia || this.$site.themeConfig.algolia || {}
},
isAlgoliaSearch () {
return this.algolia && this.algolia.apiKey && this.algolia.indexName
},
homeUrl() {
const defaultUrl = this.$localePath + this.$site.themeConfig.defaultURL;
// remove double slashes from path if any
return defaultUrl.replace(/\/+/g, '/');
},
submitRequestUrl() {
return this.$site.themeConfig.submitRequestURL || "https://cloudlinux.zendesk.com/hc/en-us/requests/new";
},
},
methods: {
onClick(event){
switch (event.type) {
case 'event':
var event = new CustomEvent(event.name);
document.dispatchEvent(event);
}
}
}
}
function css (el, property) {
// NOTE: Known bug, will return 'auto' if style value is 'auto'
const win = el.ownerDocument.defaultView
// null means not to return pseudo styles
return win.getComputedStyle(el, null)[property]
}
</script>
<style lang="stylus">
@import './styles/config.styl'
$navbar-vertical-padding = 0.7rem
$navbar-horizontal-padding = 1.5rem
.navbar
padding $navbar-vertical-padding $navbar-horizontal-padding
line-height $navbarHeight - 1.5rem
position relative
height: $navbarHeight - 3rem
box-shadow: 0 3px 7px 0 rgba(0, 0, 0, 0.23);
a, span, img
display inline-block
.logo
height $navbarHeight - 1.6rem
min-width $navbarHeight - 1.4rem
margin-right 1.5rem
vertical-align top
.site-name
font-size 1rem
font-weight 600
color $siteNameColor
position relative
.site-name--documentation
border-right: 1px solid $siteNameBorderColor;
padding-right: 1rem;
line-height: 1.2rem;
.links
box-sizing border-box
background-color $mainColor
white-space nowrap
font-size 0.9rem
position absolute
right $navbar-horizontal-padding
top 0
display flex
.search-box
flex: 0 0 auto
vertical-align top
.nav-links
flex 1
@media (max-width: $MQMobile)
.navbar
padding-left 4rem
.can-hide
display none
.links
padding-left 1.5rem
.btn
margin: 0.65rem 0 0 0
.btn
// -webkit-appearance: button;
// -moz-appearance: button;
// appearance: button;
padding 0.7rem 1.6rem;
position: relative;
background-color: $mainColor;
border: 2px solid $buttonBorderColor;
border-radius: 4px;
font-size: 0.88rem;
line-height: 1rem;
margin 0.65rem 1rem 0 0
color: $buttonTextColor;
text-align: center;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
text-decoration: none;
overflow: hidden;
cursor: pointer;
font-weight 600
.btn:hover
text-decoration underline
.btn:after
content: "";
background: #fff;
display: block;
position: absolute;
padding-top: 300%;
padding-left: 350%;
margin-left: -20px!important;
margin-top: -120%;
opacity: 0;
transition: all 0.8s
.btn:active:after
padding: 0;
margin: 0;
opacity: 1;
transition: 0s
</style>