1
1
import { search } from './search'
2
2
3
- let dom
4
3
let NO_DATA_TEXT = ''
5
4
6
5
function style ( ) {
@@ -65,25 +64,25 @@ function style () {
65
64
.search p.empty {
66
65
text-align: center;
67
66
}`
68
- const style = dom . create ( 'style' , code )
69
- dom . appendTo ( dom . head , style )
67
+ const style = Docsify . dom . create ( 'style' , code )
68
+ Docsify . dom . appendTo ( Docsify . dom . head , style )
70
69
}
71
70
72
71
function tpl ( opts , defaultValue = '' ) {
73
72
const html =
74
73
`<input type="search" value="${ defaultValue } " />` +
75
74
'<div class="results-panel"></div>' +
76
75
'</div>'
77
- const el = dom . create ( 'div' , html )
78
- const aside = dom . find ( 'aside' )
76
+ const el = Docsify . dom . create ( 'div' , html )
77
+ const aside = Docsify . dom . find ( 'aside' )
79
78
80
- dom . toggleClass ( el , 'search' )
81
- dom . before ( aside , el )
79
+ Docsify . dom . toggleClass ( el , 'search' )
80
+ Docsify . dom . before ( aside , el )
82
81
}
83
82
84
83
function doSearch ( value ) {
85
- const $search = dom . find ( 'div.search' )
86
- const $panel = dom . find ( $search , '.results-panel' )
84
+ const $search = Docsify . dom . find ( 'div.search' )
85
+ const $panel = Docsify . dom . find ( $search , '.results-panel' )
87
86
88
87
if ( ! value ) {
89
88
$panel . classList . remove ( 'show' )
@@ -105,22 +104,23 @@ function doSearch (value) {
105
104
}
106
105
107
106
function bindEvents ( ) {
108
- const $search = dom . find ( 'div.search' )
109
- const $input = dom . find ( $search , 'input' )
107
+ const $search = Docsify . dom . find ( 'div.search' )
108
+ const $input = Docsify . dom . find ( $search , 'input' )
110
109
111
110
let timeId
112
111
// Prevent to Fold sidebar
113
- dom . on ( $search , 'click' ,
112
+ Docsify . dom . on ( $search , 'click' ,
114
113
e => e . target . tagName !== 'A' && e . stopPropagation ( ) )
115
- dom . on ( $input , 'input' , e => {
114
+ Docsify . dom . on ( $input , 'input' , e => {
116
115
clearTimeout ( timeId )
117
116
timeId = setTimeout ( _ => doSearch ( e . target . value . trim ( ) ) , 100 )
118
117
} )
119
118
}
120
119
121
120
function updatePlaceholder ( text , path ) {
122
- const $input = dom . getNode ( '.search input[type="search"]' )
121
+ const $input = Docsify . dom . getNode ( '.search input[type="search"]' )
123
122
123
+ if ( ! $input ) return
124
124
if ( typeof text === 'string' ) {
125
125
$input . placeholder = text
126
126
} else {
@@ -139,7 +139,6 @@ function updateNoData (text, path) {
139
139
}
140
140
141
141
export function init ( opts , vm ) {
142
- dom = Docsify . dom
143
142
const keywords = vm . router . parse ( ) . query . s
144
143
145
144
style ( )
0 commit comments