mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-11-26 18:37:12 +00:00
Improve entry search with a debouncer
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
parent
df3bb71357
commit
9628560d64
@ -63,7 +63,12 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
refreshBalance();
|
refreshBalance();
|
||||||
}
|
}
|
||||||
|
|
||||||
alias_obj.keyup(reloadTable);
|
alias_obj.keyup(function(event) {
|
||||||
|
let code = event.originalEvent.keyCode
|
||||||
|
if (65 <= code <= 122 || code === 13) {
|
||||||
|
debounce(reloadTable)()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$(document).ready(init);
|
$(document).ready(init);
|
||||||
|
|
||||||
|
@ -381,11 +381,11 @@ function de_validate (id, validated, resourcetype) {
|
|||||||
* @param callback Function to call
|
* @param callback Function to call
|
||||||
* @param wait Debounced milliseconds
|
* @param wait Debounced milliseconds
|
||||||
*/
|
*/
|
||||||
function debounce (callback, wait) {
|
let debounce_timeout
|
||||||
let timeout
|
function debounce (callback, wait=500) {
|
||||||
return (...args) => {
|
return (...args) => {
|
||||||
const context = this
|
const context = this
|
||||||
clearTimeout(timeout)
|
clearTimeout(debounce_timeout)
|
||||||
timeout = setTimeout(() => callback.apply(context, args), wait)
|
debounce_timeout = setTimeout(() => callback.apply(context, args), wait)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user