WebUI: implement debounce behavior for resize events

This commit is contained in:
Chocobo1
2024-08-09 17:48:03 +08:00
parent 0c580c3174
commit 29379232aa
6 changed files with 43 additions and 31 deletions

View File

@@ -32,6 +32,7 @@ window.qBittorrent ??= {};
window.qBittorrent.Misc ??= (() => {
const exports = () => {
return {
createDebounceHandler: createDebounceHandler,
friendlyUnit: friendlyUnit,
friendlyDuration: friendlyDuration,
friendlyPercentage: friendlyPercentage,
@@ -50,6 +51,18 @@ window.qBittorrent.Misc ??= (() => {
};
};
const createDebounceHandler = (delay, func) => {
let timer = -1;
return (...params) => {
clearTimeout(timer);
timer = setTimeout(() => {
func(...params);
timer = -1;
}, delay);
};
};
/*
* JS counterpart of the function in src/misc.cpp
*/