@@ -81,13 +81,7 @@ function bindEvents () {
81
81
const $search = dom . find ( 'div.search' )
82
82
const $input = dom . find ( $search , 'input' )
83
83
const $panel = dom . find ( $search , '.results-panel' )
84
-
85
- // Prevent to Fold sidebar
86
- dom . on ( $search , 'click' ,
87
- e => e . target . tagName !== 'A' && e . stopPropagation ( ) )
88
-
89
- dom . on ( $input , 'input' , e => {
90
- const value = e . target . value . trim ( )
84
+ const doSearch = function ( value ) {
91
85
if ( ! value ) {
92
86
$panel . classList . remove ( 'show' )
93
87
$panel . innerHTML = ''
@@ -96,7 +90,6 @@ function bindEvents () {
96
90
const matchs = search ( value )
97
91
98
92
let html = ''
99
-
100
93
matchs . forEach ( post => {
101
94
html += `<div class="matching-post">
102
95
<h2><a href="${ post . url } ">${ post . title } </a></h2>
@@ -106,6 +99,15 @@ function bindEvents () {
106
99
107
100
$panel . classList . add ( 'show' )
108
101
$panel . innerHTML = html || '<p class="empty">No Results!</p>'
102
+ }
103
+
104
+ let timeId
105
+ // Prevent to Fold sidebar
106
+ dom . on ( $search , 'click' ,
107
+ e => e . target . tagName !== 'A' && e . stopPropagation ( ) )
108
+ dom . on ( $input , 'input' , e => {
109
+ clearTimeout ( timeId )
110
+ timeId = setTimeout ( _ => doSearch ( e . target . value . trim ( ) ) , 200 )
109
111
} )
110
112
}
111
113
0 commit comments