1
1
import { search } from './search'
2
2
3
3
let NO_DATA_TEXT = ''
4
+ let options
4
5
5
6
function style ( ) {
6
7
const code = `
@@ -86,12 +87,16 @@ function style() {
86
87
87
88
.search p.empty {
88
89
text-align: center;
90
+ }
91
+
92
+ .app-name.hide, .sidebar-nav.hide {
93
+ display: none;
89
94
}`
90
95
91
96
Docsify . dom . style ( code )
92
97
}
93
98
94
- function tpl ( opts , defaultValue = '' ) {
99
+ function tpl ( defaultValue = '' ) {
95
100
const html =
96
101
`<div class="input-wrap">
97
102
<input type="search" value="${ defaultValue } " />
@@ -116,11 +121,18 @@ function doSearch(value) {
116
121
const $search = Docsify . dom . find ( 'div.search' )
117
122
const $panel = Docsify . dom . find ( $search , '.results-panel' )
118
123
const $clearBtn = Docsify . dom . find ( $search , '.clear-button' )
124
+ const $sidebarNav = Docsify . dom . find ( '.sidebar-nav' )
125
+ const $appName = Docsify . dom . find ( '.app-name' )
119
126
120
127
if ( ! value ) {
121
128
$panel . classList . remove ( 'show' )
122
129
$clearBtn . classList . remove ( 'show' )
123
130
$panel . innerHTML = ''
131
+
132
+ if ( options . hideOtherSidebarContent ) {
133
+ $sidebarNav . classList . remove ( 'hide' )
134
+ $appName . classList . remove ( 'hide' )
135
+ }
124
136
return
125
137
}
126
138
const matchs = search ( value )
@@ -138,6 +150,10 @@ function doSearch(value) {
138
150
$panel . classList . add ( 'show' )
139
151
$clearBtn . classList . add ( 'show' )
140
152
$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
+ }
141
157
}
142
158
143
159
function bindEvents ( ) {
@@ -188,16 +204,22 @@ function updateNoData(text, path) {
188
204
}
189
205
}
190
206
207
+ function updateOptions ( opts ) {
208
+ options = opts
209
+ }
210
+
191
211
export function init ( opts , vm ) {
192
212
const keywords = vm . router . parse ( ) . query . s
193
213
214
+ updateOptions ( opts )
194
215
style ( )
195
- tpl ( opts , keywords )
216
+ tpl ( keywords )
196
217
bindEvents ( )
197
218
keywords && setTimeout ( _ => doSearch ( keywords ) , 500 )
198
219
}
199
220
200
221
export function update ( opts , vm ) {
222
+ updateOptions ( opts )
201
223
updatePlaceholder ( opts . placeholder , vm . route . path )
202
224
updateNoData ( opts . noData , vm . route . path )
203
225
}
0 commit comments