Do a new getContents if the search field is cleared

This commit is contained in:
Junior 2024-12-16 11:19:39 -05:00
parent 851b5156d7
commit 7b7f866582

View File

@ -2,6 +2,7 @@
var kindlemail = ""; var kindlemail = "";
var currentpath = ""; var currentpath = "";
var searchTimeout = null; var searchTimeout = null;
var lastSearch = "";
$(document).ready(function() { $(document).ready(function() {
getContents(); getContents();
@ -35,6 +36,10 @@ $(document).ready(function() {
$("#search").on("change keyup", function() { $("#search").on("change keyup", function() {
if ( searchTimeout ) clearTimeout(searchTimeout); if ( searchTimeout ) clearTimeout(searchTimeout);
if ( $("#search").val().length > 2 ) searchTimeout = setTimeout(getContents, 500); if ( $("#search").val().length > 2 ) searchTimeout = setTimeout(getContents, 500);
if ( ($("#search").val() == "") && (lastSearch != "") ) {
lastSearch = "";
getContents();
}
}); });
}); });
@ -50,7 +55,10 @@ function redirectToLogin() {
function getContents() { function getContents() {
if ( searchTimeout ) clearTimeout(searchTimeout); if ( searchTimeout ) clearTimeout(searchTimeout);
var data = {}; var data = {};
if ( $("#search").val() != "" ) data.search = $("#search").val(); if ( $("#search").val() != "" ) {
data.search = $("#search").val();
lastSearch = data.search;
}
$.ajax({ $.ajax({
url : 'ajax/getcontents.php', url : 'ajax/getcontents.php',
data : data, data : data,