timeout search as you type

This commit is contained in:
simon 2022-05-30 15:29:52 +07:00
parent a9b8d34b5a
commit c6d696a91b
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4

View File

@ -785,21 +785,25 @@ function setProgressBar(videoId, currentTime, duration) {
}
// multi search form
let searchTimeout = null;
function searchMulti(query) {
if (query.length > 1) {
var payload = JSON.stringify({'multi_search': query});
var http = new XMLHttpRequest();
http.onreadystatechange = function() {
if (http.readyState === 4) {
allResults = JSON.parse(http.response).results;
populateMultiSearchResults(allResults);
}
};
http.open("POST", "/process/", true);
http.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
http.setRequestHeader("Content-type", "application/json");
http.send(payload);
}
clearTimeout(searchTimeout);
searchTimeout = setTimeout(function () {
if (query.length > 1) {
var payload = JSON.stringify({'multi_search': query});
var http = new XMLHttpRequest();
http.onreadystatechange = function() {
if (http.readyState === 4) {
allResults = JSON.parse(http.response).results;
populateMultiSearchResults(allResults);
}
};
http.open("POST", "/process/", true);
http.setRequestHeader("X-CSRFToken", getCookie("csrftoken"));
http.setRequestHeader("Content-type", "application/json");
http.send(payload);
}
}, 500);
}
function getViewDefaults(view) {