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
1 changed files with 18 additions and 14 deletions

View File

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