@@ -179,7 +179,7 @@ $(window).resize(function () {
179
179
var isSearching = false ;
180
180
if ( document . getElementById ( 'bch-merchant-search' ) instanceof Object ) {
181
181
var jets = new Jets ( {
182
- searchTag : '#bch-merchant-search' ,
182
+ callSearchManually : true ,
183
183
contentTag : '.bch-merchant-content' ,
184
184
didSearch : function ( searchPhrase ) {
185
185
document . location . hash = '' ;
@@ -236,8 +236,40 @@ if(document.getElementById('bch-merchant-search') instanceof Object){
236
236
return searchItems ;
237
237
}
238
238
} ) ;
239
+
240
+ // Wrap the jets.search function with a debounced function
241
+ var debouncedSearch = debounce ( function ( e ) {
242
+ jets . search ( e . target . value ) ;
243
+ } , 350 ) ;
244
+
245
+ // Attach a keyup event listener to the input
246
+ $ ( '#bch-merchant-search' ) . keyup ( debouncedSearch ) ;
247
+
239
248
}
240
249
250
+ /**
251
+ * Returns a function, that, as long as it continues to be invoked, will not
252
+ * be triggered. The function will be called after it stops being called for
253
+ * N milliseconds.
254
+ *
255
+ * @param func The function to be debounced
256
+ * @param wait The time in ms to debounce
257
+ */
258
+ function debounce ( func , wait ) {
259
+ var timeout ;
260
+
261
+ return function ( ) {
262
+ var context = this , args = arguments ;
263
+ var later = function ( ) {
264
+ timeout = null ;
265
+ func . apply ( context , args ) ;
266
+ } ;
267
+
268
+ clearTimeout ( timeout ) ;
269
+ timeout = setTimeout ( later , wait ) ;
270
+ if ( ! timeout ) func . apply ( context , args ) ;
271
+ } ;
272
+ } ;
241
273
/**
242
274
* Ensure searching is conducted with regard to the user's viewport
243
275
* after re-sizing the screen and close all categories after re-sizing
0 commit comments