Browse Source

search tags javascript fixes

current_wdka_release
crunk 3 years ago
parent
commit
6a475024d3
  1. 18
      verse/static/js/dropdown.js

18
verse/static/js/dropdown.js

@ -60,18 +60,21 @@ let timeout = null;
searchInput.addEventListener('keyup', function (e) { searchInput.addEventListener('keyup', function (e) {
// Clear the timeout if it has already been set. // Clear the timeout if it has already been set.
clearTimeout(timeout); clearTimeout(timeout);
// Make a new timeout set to go off in 1000ms (1 second) // Make a new timeout set to go off in 1000ms (1 second)
timeout = setTimeout(function () { timeout = setTimeout(function () {
console.log('Input Value:', searchInput.value); console.log('Input Value:', searchInput.value);
searchTags(searchInput.value); if (searchInput.value.length > 2) {
searchTags(searchInput.value);
} else {
clearSearchTags();
}
}, 1000); }, 1000);
}); });
function searchTags(searchInput) { function searchTags(searchInput) {
var tag_ele = document.getElementsByClassName('tags'); let tag_ele = document.getElementsByClassName('tags');
for (var i = 0; i < tag_ele.length; ++i) { for (var i = 0; i < tag_ele.length; ++i) {
let searchText = searchInput.toLowerCase(); let searchText = searchInput.toLowerCase().trim();
let tagtext = tag_ele[i].innerText.toLowerCase(); let tagtext = tag_ele[i].innerText.toLowerCase();
if(searchText.includes(tagtext) || tagtext.includes(searchText)) { if(searchText.includes(tagtext) || tagtext.includes(searchText)) {
addClass(tag_ele[i], "searched"); addClass(tag_ele[i], "searched");
@ -81,3 +84,10 @@ function searchTags(searchInput) {
} }
} }
} }
function clearSearchTags() {
let tag_ele = document.getElementsByClassName('tags');
for (var i = 0; i < tag_ele.length; ++i) {
removeClass(tag_ele[i], "searched");
}
}

Loading…
Cancel
Save