mirror of
https://github.com/krateng/maloja.git
synced 2025-04-12 07:00:02 +03:00
Add debounce timer to search, GH-370
This commit is contained in:
parent
1462883ab5
commit
26f26f36cb
@ -1,17 +1,23 @@
|
||||
var searches = []
|
||||
var debounceTimer;
|
||||
|
||||
function search(searchfield) {
|
||||
txt = searchfield.value;
|
||||
if (txt == "") {
|
||||
reallyclear()
|
||||
}
|
||||
else {
|
||||
xhttp = new XMLHttpRequest();
|
||||
searches.push(xhttp)
|
||||
xhttp.onreadystatechange = searchresult
|
||||
xhttp.open("GET","/api/search?max=5&query=" + encodeURIComponent(txt), true);
|
||||
xhttp.send();
|
||||
}
|
||||
clearTimeout(debounceTimer);
|
||||
debounceTimer = setTimeout(() => {
|
||||
const txt = searchfield.value;
|
||||
if (txt == "") {
|
||||
reallyclear();
|
||||
}
|
||||
else {
|
||||
const xhttp = new XMLHttpRequest();
|
||||
searches.push(xhttp);
|
||||
xhttp.onreadystatechange = searchresult
|
||||
xhttp.open("GET","/api/search?max=5&query=" + encodeURIComponent(txt), true);
|
||||
xhttp.send();
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user