Skip to content

Commit 49c4fff

Browse files
committed
Implementing changes from 2factorauth#3491 for Acceptbitcoincash repo
1 parent 2ed84b8 commit 49c4fff

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

js/app.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ $(window).resize(function () {
179179
var isSearching = false;
180180
if(document.getElementById('bch-merchant-search') instanceof Object){
181181
var jets = new Jets({
182-
searchTag: '#bch-merchant-search',
182+
callSearchManually: true,
183183
contentTag: '.bch-merchant-content',
184184
didSearch: function (searchPhrase) {
185185
document.location.hash = '';
@@ -236,8 +236,40 @@ if(document.getElementById('bch-merchant-search') instanceof Object){
236236
return searchItems;
237237
}
238238
});
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+
239248
}
240249

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+
};
241273
/**
242274
* Ensure searching is conducted with regard to the user's viewport
243275
* after re-sizing the screen and close all categories after re-sizing

0 commit comments

Comments
 (0)