File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -134,7 +134,24 @@ var searchBar = document.getElementById('mocks-search');
134
134
var mocksList = document . getElementById ( 'mocks-list' ) ;
135
135
var plotArea = document . getElementById ( 'plots' ) ;
136
136
137
- searchBar . addEventListener ( 'keyup' , function ( e ) {
137
+ searchBar . addEventListener ( 'keyup' , debounce ( searchMocks , 250 ) ) ;
138
+
139
+ function debounce ( func , wait , immediate ) {
140
+ var timeout ;
141
+ return function ( ) {
142
+ var context = this , args = arguments ;
143
+ var later = function ( ) {
144
+ timeout = null ;
145
+ if ( ! immediate ) func . apply ( context , args ) ;
146
+ } ;
147
+ var callNow = immediate && ! timeout ;
148
+ clearTimeout ( timeout ) ;
149
+ timeout = setTimeout ( later , wait ) ;
150
+ if ( callNow ) func . apply ( context , args ) ;
151
+ } ;
152
+ }
153
+
154
+ function searchMocks ( e ) {
138
155
139
156
// Clear results.
140
157
while ( mocksList . firstChild ) {
@@ -162,4 +179,4 @@ searchBar.addEventListener('keyup', function(e) {
162
179
var plotAreaWidth = Math . floor ( window . innerWidth - listWidth ) ;
163
180
plotArea . setAttribute ( 'style' , 'width: ' + plotAreaWidth + 'px;' ) ;
164
181
} ) ;
165
- } ) ;
182
+ }
You can’t perform that action at this time.
0 commit comments