Fixed search showing duplicates when typing fast

Fixed search input showing duplicates when typing fast.

Function from: //https://stackoverflow.com/a/1909508
This commit is contained in:
cp6 2021-01-24 00:38:37 +11:00
parent 40db8d4361
commit a5bf2c5f07

View File

@ -364,7 +364,16 @@ function yabsModalView(hostname, id) {
});
}
$('#searchInput').keyup(function() {
//https://stackoverflow.com/a/1909508
function delay(fn, ms) {
let timer = 0
return function(...args) {
clearTimeout(timer)
timer = setTimeout(fn.bind(this, ...args), ms || 0)
}
}
$('#searchInput').keyup(delay(function (e) {
var search_term = this.value;
$('#searchDivBody').empty();
$.ajax({
@ -375,4 +384,4 @@ $('#searchInput').keyup(function() {
$('#searchDivBody').append(result);
}
});
});
}, 500));