2019-04-15 10:35:40 +08:00
|
|
|
<template>
|
|
|
|
<header class="navbar">
|
|
|
|
<SidebarButton @toggle-sidebar="$emit('toggle-sidebar')"/>
|
|
|
|
|
|
|
|
<router-link
|
|
|
|
:to="$localePath"
|
|
|
|
class="home-link">
|
|
|
|
<img
|
|
|
|
class="logo"
|
2019-05-08 15:13:18 +08:00
|
|
|
v-if="$themeConfig.logo"
|
|
|
|
:src="$withBase($themeConfig.logo)"
|
2019-04-15 10:35:40 +08:00
|
|
|
:alt="$siteTitle">
|
|
|
|
<span
|
|
|
|
ref="siteName"
|
|
|
|
class="site-name"
|
|
|
|
v-if="$siteTitle">{{ $siteTitle }}</span>
|
|
|
|
</router-link>
|
|
|
|
|
|
|
|
<div
|
|
|
|
class="links"
|
|
|
|
:style="linksWrapMaxWidth ? {
|
|
|
|
'max-width': linksWrapMaxWidth + 'px'
|
|
|
|
} : {}">
|
2019-09-01 00:11:13 +08:00
|
|
|
|
2019-11-27 14:30:23 +08:00
|
|
|
<Mode />
|
2019-04-15 10:35:40 +08:00
|
|
|
<AlgoliaSearchBox
|
|
|
|
v-if="isAlgoliaSearch"
|
|
|
|
:options="algolia"/>
|
2019-07-20 19:00:36 +08:00
|
|
|
<SearchBox v-else-if="$themeConfig.search !== false && $frontmatter.search !== false"/>
|
2019-04-15 10:35:40 +08:00
|
|
|
<NavLinks class="can-hide"/>
|
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import AlgoliaSearchBox from '@AlgoliaSearchBox'
|
|
|
|
import SearchBox from '@SearchBox'
|
2019-12-06 00:11:16 +08:00
|
|
|
import SidebarButton from '@theme/components/SidebarButton'
|
|
|
|
import NavLinks from '@theme/components/NavLinks'
|
2019-11-27 14:30:23 +08:00
|
|
|
import Mode from '@theme/components/Mode'
|
2019-04-15 10:35:40 +08:00
|
|
|
|
|
|
|
export default {
|
2019-11-27 14:30:23 +08:00
|
|
|
components: { SidebarButton, NavLinks, SearchBox, AlgoliaSearchBox, Mode },
|
2019-04-15 10:35:40 +08:00
|
|
|
|
|
|
|
data () {
|
|
|
|
return {
|
2019-11-27 14:30:23 +08:00
|
|
|
linksWrapMaxWidth: null
|
2019-04-15 10:35:40 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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 {
|
2019-09-20 13:54:13 +08:00
|
|
|
this.linksWrapMaxWidth = this.$el.offsetWidth - NAVBAR_VERTICAL_PADDING -
|
|
|
|
(this.$refs.siteName && this.$refs.siteName.offsetWidth || 0)
|
2019-04-15 10:35:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
handleLinksWrapWidth()
|
|
|
|
window.addEventListener('resize', handleLinksWrapWidth, false)
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
algolia () {
|
2019-05-08 15:13:18 +08:00
|
|
|
return this.$themeLocaleConfig.algolia || this.$themeConfig.algolia || {}
|
2019-04-15 10:35:40 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
isAlgoliaSearch () {
|
|
|
|
return this.algolia && this.algolia.apiKey && this.algolia.indexName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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">
|
2019-11-28 11:49:03 +08:00
|
|
|
@require '../styles/mode.styl'
|
2019-10-17 14:28:37 +08:00
|
|
|
|
2019-04-15 10:35:40 +08:00
|
|
|
$navbar-vertical-padding = 0.7rem
|
|
|
|
$navbar-horizontal-padding = 1.5rem
|
|
|
|
|
|
|
|
.navbar
|
|
|
|
padding $navbar-vertical-padding $navbar-horizontal-padding
|
|
|
|
line-height $navbarHeight - 1.4rem
|
2019-11-27 20:03:10 +08:00
|
|
|
box-shadow var(--box-shadow)
|
2019-12-08 20:08:19 +08:00
|
|
|
background var(--background-color)
|
2019-04-15 10:35:40 +08:00
|
|
|
a, span, img
|
|
|
|
display inline-block
|
|
|
|
.logo
|
|
|
|
height $navbarHeight - 1.4rem
|
|
|
|
min-width $navbarHeight - 1.4rem
|
|
|
|
margin-right 0.8rem
|
|
|
|
vertical-align top
|
|
|
|
.site-name
|
|
|
|
font-size 1.2rem
|
|
|
|
font-weight 600
|
2019-11-27 20:03:10 +08:00
|
|
|
color var(--text-color)
|
2019-04-15 10:35:40 +08:00
|
|
|
position relative
|
2019-12-08 20:08:19 +08:00
|
|
|
background var(--background-color)
|
2019-04-15 10:35:40 +08:00
|
|
|
.links
|
|
|
|
padding-left 1.5rem
|
|
|
|
box-sizing border-box
|
|
|
|
white-space nowrap
|
|
|
|
font-size 0.9rem
|
|
|
|
position absolute
|
|
|
|
right $navbar-horizontal-padding
|
|
|
|
top $navbar-vertical-padding
|
|
|
|
display flex
|
2019-12-19 23:31:41 +08:00
|
|
|
background-color var(--background-color)
|
2019-04-15 10:35:40 +08:00
|
|
|
.search-box
|
|
|
|
flex: 0 0 auto
|
|
|
|
vertical-align top
|
|
|
|
|
|
|
|
@media (max-width: $MQMobile)
|
|
|
|
.navbar
|
|
|
|
padding-left 4rem
|
|
|
|
.can-hide
|
|
|
|
display none
|
|
|
|
.links
|
|
|
|
padding-left 1.5rem
|
|
|
|
</style>
|