Skip to content

Commit

Permalink
filter case insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
junsan1 committed Jul 7, 2024
1 parent 3aa7023 commit 326c70e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions _layouts/catalog_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ <h2>{{ item.name }}</h2>

function applyFilters() {
catalogItems.forEach(item => {
const itemFilters = item.dataset.filters.split(',');
if (activeFilters.size === 0 || Array.from(activeFilters).every(filter => itemFilters.includes(filter))) {
const itemFilters = item.dataset.filters.toLowerCase().split(',');
if (activeFilters.size === 0 || Array.from(activeFilters).every(filter =>
itemFilters.includes(filter.toLowerCase())
)) {
item.style.display = 'block';
} else {
item.style.display = 'none';
Expand Down Expand Up @@ -94,10 +96,13 @@ <h2>{{ item.name }}</h2>
const urlFilters = urlParams.getAll('filter');
if (urlFilters.length > 0) {
urlFilters.forEach(filter => {
const button = document.querySelector(`.filter-btn[data-filter="${filter}"]`);
const lowercaseFilter = filter.toLowerCase();
const button = Array.from(filterButtons).find(btn =>
btn.dataset.filter.toLowerCase() === lowercaseFilter
);
if (button) {
button.classList.add('active');
activeFilters.add(filter);
activeFilters.add(button.dataset.filter);
}
});
applyFilters();
Expand All @@ -109,7 +114,7 @@ <h2>{{ item.name }}</h2>
const urlFilters = urlParams.getAll('filter');

filterButtons.forEach(button => {
if (urlFilters.includes(button.dataset.filter)) {
if (urlFilters.some(filter => filter.toLowerCase() === button.dataset.filter.toLowerCase())) {
button.classList.add('active');
activeFilters.add(button.dataset.filter);
} else {
Expand Down

0 comments on commit 326c70e

Please sign in to comment.