Synced with mixtape upstream
This commit is contained in:
@@ -20,15 +20,21 @@ function buttonToggle(clickedButton) {
|
||||
}
|
||||
|
||||
function filterSongs() {
|
||||
const searchTerm = search.value.trim().toLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu, "");
|
||||
const searchTerm = sanitizeString(search.value);
|
||||
const songs = Array.from(songList.children);
|
||||
songs.forEach(song => {
|
||||
const title = song.dataset.title.toLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu, "");
|
||||
const matching = title.includes(searchTerm) && (!selectedCategory || song.dataset.category === selectedCategory);
|
||||
const matching = (
|
||||
(song.dataset.title.includes(searchTerm) || (song.dataset.artist && song.dataset.artist.includes(searchTerm))) &&
|
||||
(!selectedCategory || song.dataset.category === selectedCategory)
|
||||
);
|
||||
song.classList.toggle("hidden", !matching);
|
||||
});
|
||||
}
|
||||
|
||||
function sanitizeString(string) {
|
||||
return string.trim().toLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu, "")
|
||||
}
|
||||
|
||||
// Event listeners
|
||||
search.addEventListener("input", filterSongs);
|
||||
// Filtering happens before the reset itself without this timeout
|
||||
@@ -37,8 +43,12 @@ buttons.forEach(button => button.addEventListener("click", () => buttonToggle(bu
|
||||
|
||||
// Normalize song titles
|
||||
Array.from(songList.children).forEach(song => {
|
||||
song.dataset.title = song.dataset.title.toLowerCase().normalize("NFD").replace(/\p{Diacritic}/gu, "");
|
||||
song.dataset.title = sanitizeString(song.dataset.title);
|
||||
if (song.dataset.artist) {
|
||||
song.dataset.artist = sanitizeString(song.dataset.artist);
|
||||
}
|
||||
});
|
||||
|
||||
// Display the filter section on JS-enabled browsers
|
||||
window.addEventListener("load", () => filters.classList.remove = "hidden");
|
||||
|
||||
|
Reference in New Issue
Block a user