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');
134134var mocksList = document . getElementById ( 'mocks-list' ) ;
135135var plotArea = document . getElementById ( 'plots' ) ;
136136
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 ) {
138155
139156 // Clear results.
140157 while ( mocksList . firstChild ) {
@@ -162,4 +179,4 @@ searchBar.addEventListener('keyup', function(e) {
162179 var plotAreaWidth = Math . floor ( window . innerWidth - listWidth ) ;
163180 plotArea . setAttribute ( 'style' , 'width: ' + plotAreaWidth + 'px;' ) ;
164181 } ) ;
165- } ) ;
182+ }
You can’t perform that action at this time.
0 commit comments