Skip to content

Commit 211dd74

Browse files
author
Kang Cheng
committed
Add hideOtherSidebarContent option
Allow user to configure whether or not to hide other sidebar content while showing searching results. Related issue: #535
1 parent 2cd4646 commit 211dd74

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

Diff for: docs/plugins.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ By default, the hyperlink on the current page is recognized and the content is s
3737
},
3838
3939
// Headline depth, 1 - 6
40-
depth: 2
40+
depth: 2,
41+
42+
hideOtherSidebarContent: false, // whether or not to hide other sidebar content
4143
}
4244
}
4345
</script>

Diff for: src/core/render/tpl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function main(config) {
3636
'</button>' +
3737
'<aside class="sidebar">' +
3838
(config.name ?
39-
`<h1><a class="app-name-link" data-nosearch>${
39+
`<h1 class="app-name"><a class="app-name-link" data-nosearch>${
4040
config.logo ?
4141
`<img alt=${config.name} src=${config.logo}>` :
4242
config.name

Diff for: src/plugins/search/component.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {search} from './search'
22

33
let NO_DATA_TEXT = ''
4+
let options
45

56
function style() {
67
const code = `
@@ -86,12 +87,16 @@ function style() {
8687
8788
.search p.empty {
8889
text-align: center;
90+
}
91+
92+
.app-name.hide, .sidebar-nav.hide {
93+
display: none;
8994
}`
9095

9196
Docsify.dom.style(code)
9297
}
9398

94-
function tpl(opts, defaultValue = '') {
99+
function tpl(defaultValue = '') {
95100
const html =
96101
`<div class="input-wrap">
97102
<input type="search" value="${defaultValue}" />
@@ -116,11 +121,18 @@ function doSearch(value) {
116121
const $search = Docsify.dom.find('div.search')
117122
const $panel = Docsify.dom.find($search, '.results-panel')
118123
const $clearBtn = Docsify.dom.find($search, '.clear-button')
124+
const $sidebarNav = Docsify.dom.find('.sidebar-nav')
125+
const $appName = Docsify.dom.find('.app-name')
119126

120127
if (!value) {
121128
$panel.classList.remove('show')
122129
$clearBtn.classList.remove('show')
123130
$panel.innerHTML = ''
131+
132+
if (options.hideOtherSidebarContent) {
133+
$sidebarNav.classList.remove('hide')
134+
$appName.classList.remove('hide')
135+
}
124136
return
125137
}
126138
const matchs = search(value)
@@ -138,6 +150,10 @@ function doSearch(value) {
138150
$panel.classList.add('show')
139151
$clearBtn.classList.add('show')
140152
$panel.innerHTML = html || `<p class="empty">${NO_DATA_TEXT}</p>`
153+
if (options.hideOtherSidebarContent) {
154+
$sidebarNav.classList.add('hide')
155+
$appName.classList.add('hide')
156+
}
141157
}
142158

143159
function bindEvents() {
@@ -188,16 +204,22 @@ function updateNoData(text, path) {
188204
}
189205
}
190206

207+
function updateOptions(opts) {
208+
options = opts
209+
}
210+
191211
export function init(opts, vm) {
192212
const keywords = vm.router.parse().query.s
193213

214+
updateOptions(opts)
194215
style()
195-
tpl(opts, keywords)
216+
tpl(keywords)
196217
bindEvents()
197218
keywords && setTimeout(_ => doSearch(keywords), 500)
198219
}
199220

200221
export function update(opts, vm) {
222+
updateOptions(opts)
201223
updatePlaceholder(opts.placeholder, vm.route.path)
202224
updateNoData(opts.noData, vm.route.path)
203225
}

Diff for: src/plugins/search/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const CONFIG = {
66
noData: 'No Results!',
77
paths: 'auto',
88
depth: 2,
9-
maxAge: 86400000 // 1 day
9+
maxAge: 86400000, // 1 day
10+
hideOtherSidebarContent: false
1011
}
1112

1213
const install = function (hook, vm) {
@@ -21,6 +22,7 @@ const install = function (hook, vm) {
2122
CONFIG.placeholder = opts.placeholder || CONFIG.placeholder
2223
CONFIG.noData = opts.noData || CONFIG.noData
2324
CONFIG.depth = opts.depth || CONFIG.depth
25+
CONFIG.hideOtherSidebarContent = opts.hideOtherSidebarContent || CONFIG.hideOtherSidebarContent
2426
}
2527

2628
const isAuto = CONFIG.paths === 'auto'

0 commit comments

Comments
 (0)