search tags javascript fixes
This commit is contained in:
parent
f8560eddd9
commit
6a475024d3
@ -60,18 +60,21 @@ let timeout = null;
|
||||
searchInput.addEventListener('keyup', function (e) {
|
||||
// Clear the timeout if it has already been set.
|
||||
clearTimeout(timeout);
|
||||
|
||||
// Make a new timeout set to go off in 1000ms (1 second)
|
||||
timeout = setTimeout(function () {
|
||||
console.log('Input Value:', searchInput.value);
|
||||
searchTags(searchInput.value);
|
||||
if (searchInput.value.length > 2) {
|
||||
searchTags(searchInput.value);
|
||||
} else {
|
||||
clearSearchTags();
|
||||
}
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
function searchTags(searchInput) {
|
||||
var tag_ele = document.getElementsByClassName('tags');
|
||||
let tag_ele = document.getElementsByClassName('tags');
|
||||
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();
|
||||
if(searchText.includes(tagtext) || tagtext.includes(searchText)) {
|
||||
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…
Reference in New Issue
Block a user