mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Apply multiple tags filter
This commit is contained in:
@@ -14,6 +14,7 @@ export {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const random_id = () => Math.round(Date.now() * Math.random()).toString();
|
const random_id = () => Math.round(Date.now() * Math.random()).toString();
|
||||||
|
const TAG_LOGIC_AND = true;
|
||||||
|
|
||||||
const DEFAULT_TAGS = [
|
const DEFAULT_TAGS = [
|
||||||
{ id: random_id(), name: "Plain Text" },
|
{ id: random_id(), name: "Plain Text" },
|
||||||
@@ -175,27 +176,32 @@ function appendTagToList(listElement, tag, { removable, editable, selectable })
|
|||||||
removable ? removeButton.show() : removeButton.hide();
|
removable ? removeButton.show() : removeButton.hide();
|
||||||
|
|
||||||
if (selectable) {
|
if (selectable) {
|
||||||
tagElement.on('click', onTagFilterClick);
|
tagElement.on('click', () => onTagFilterClick.bind(tagElement)(listElement));
|
||||||
}
|
}
|
||||||
|
|
||||||
$(listElement).append(tagElement);
|
$(listElement).append(tagElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTagFilterClick() {
|
function onTagFilterClick(listElement) {
|
||||||
const wasSelected = $(this).hasClass('selected');
|
const wasSelected = $(this).hasClass('selected');
|
||||||
clearTagsFilter();
|
$('#rm_print_characters_block > div').removeClass('hiddenByTag');
|
||||||
|
|
||||||
if (wasSelected) {
|
$(this).toggleClass('selected', !wasSelected);
|
||||||
|
|
||||||
|
const tagIds = [...($(listElement).find(".tag.selected").map((_, el) => $(el).attr("id")))];
|
||||||
|
$('#rm_print_characters_block > div').each((_, element) => applyFilterToElement(tagIds, element));
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyFilterToElement(tagIds, element) {
|
||||||
|
if (tagIds.length === 0) {
|
||||||
|
$(element).removeClass('hiddenByTag');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tagId = $(this).attr('id');
|
const tagFlags = tagIds.map(tagId => isElementTagged(element, tagId));
|
||||||
$(this).addClass('selected');
|
const trueFlags = tagFlags.filter(x => x);
|
||||||
$('#rm_print_characters_block > div').each((_, element) => applyFilterToElement(tagId, element));
|
const isTagged = TAG_LOGIC_AND ? tagFlags.length === trueFlags.length : trueFlags.length > 0;
|
||||||
}
|
|
||||||
|
|
||||||
function applyFilterToElement(tagId, element) {
|
|
||||||
const isTagged = isElementTagged(element, tagId);
|
|
||||||
$(element).toggleClass('hiddenByTag', !isTagged);
|
$(element).toggleClass('hiddenByTag', !isTagged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user