From a5bf2c5f07a2291cd7bd6e5473d5920da73857b8 Mon Sep 17 00:00:00 2001 From: cp6 Date: Sun, 24 Jan 2021 00:38:37 +1100 Subject: [PATCH] Fixed search showing duplicates when typing fast Fixed search input showing duplicates when typing fast. Function from: //https://stackoverflow.com/a/1909508 --- assets/js/scripts.min.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/assets/js/scripts.min.js b/assets/js/scripts.min.js index 9437b85..709400f 100644 --- a/assets/js/scripts.min.js +++ b/assets/js/scripts.min.js @@ -364,7 +364,16 @@ function yabsModalView(hostname, id) { }); } -$('#searchInput').keyup(function() { +//https://stackoverflow.com/a/1909508 +function delay(fn, ms) { + let timer = 0 + return function(...args) { + clearTimeout(timer) + timer = setTimeout(fn.bind(this, ...args), ms || 0) + } +} + +$('#searchInput').keyup(delay(function (e) { var search_term = this.value; $('#searchDivBody').empty(); $.ajax({ @@ -375,4 +384,4 @@ $('#searchInput').keyup(function() { $('#searchDivBody').append(result); } }); -}); \ No newline at end of file +}, 500)); \ No newline at end of file