Simplify search logic with css classes

This commit is contained in:
SillyLossy
2023-04-29 17:54:51 +03:00
parent 26e10c2d9a
commit a881ed32c5
2 changed files with 7 additions and 30 deletions

View File

@ -1250,15 +1250,14 @@ function applyFavFilter(enabled) {
const selector = ['#rm_print_characters_block .character_select', '#rm_print_characters_block .group_select'].join(',');
if (enabled) {
$(selector).each(function () {
if ($(this).children(".flex-container").children(".ch_fav").length !== 0) {
$(this).children(".flex-container").children(".ch_fav").val().toLowerCase().includes(true)
? $(this).show()
: $(this).hide();
if ($(this).find(".ch_fav").length !== 0) {
const shouldBeDisplayed = $(this).find(".ch_fav").val().toLowerCase().includes(true);
$(this).toggleClass('hiddenByFav', !shouldBeDisplayed);
}
});
}
else {
$(selector).show();
$(selector).removeClass('hiddenByFav');
}
}
@ -3939,17 +3938,9 @@ $(document).ready(function () {
$("#character_search_bar").on("input", function () {
const selector = ['#rm_print_characters_block .character_select', '#rm_print_characters_block .group_select'].join(',');
const searchValue = $(this).val().trim().toLowerCase();
const selectedTagId = $('#rm_tag_filter .tag.selected').attr('id');
if (!searchValue) {
$(selector).each(function () {
if (selectedTagId && !isElementTagged(this, selectedTagId)) {
$(this).hide();
}
else {
$(this).show();
}
})
$(selector).removeClass('hiddenBySearch');
} else {
$(selector).each(function () {
const isValidSearch = $(this)
@ -3958,23 +3949,9 @@ $(document).ready(function () {
.toLowerCase()
.includes(searchValue);
if (isValidSearch) {
if (selectedTagId && !isElementTagged(this, selectedTagId)) {
$(this).hide();
}
else {
$(this).show();
}
}
else {
$(this).hide();
}
$(this).toggleClass('hiddenBySearch', !isValidSearch);
});
}
if (selectedTagId) {
applyFilterToList(selectedTagId)
}
});
$("#filter_by_fav").click(function () {