sortieren nach likes nun moeglich

This commit is contained in:
rirat-0
2026-06-17 17:58:40 +02:00
parent e1102eb7db
commit de4d2fe5c0
2 changed files with 18 additions and 5 deletions
+9 -4
View File
@@ -1,5 +1,5 @@
function initClientSorter() {
function initSorter() {
const listContainer = document.querySelector('.s-res-list');
const sortRadios = document.querySelectorAll('.sort-radio');
@@ -12,7 +12,12 @@ function initClientSorter() {
const sortValue = this.value;
cards.sort((a, b) => {
if (sortValue === 'alphabet') {
if (sortValue === 'likes') {
const likesA = parseInt(a.getAttribute('data-likes') || '0', 10);
const likesB = parseInt(b.getAttribute('data-likes') || '0', 10);
return likesB - likesA;
}
else if (sortValue === 'alphabet') {
// alphabetische sortierung
const titleA = a.querySelector('.s-res-link').textContent.trim().toLowerCase();
const titleB = b.querySelector('.s-res-link').textContent.trim().toLowerCase();
@@ -39,7 +44,7 @@ function initClientSorter() {
// ist das DOM bereits vollständig aufgebaut?
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initClientSorter);
document.addEventListener('DOMContentLoaded', initSorter);
} else {
initClientSorter();
initSorter();
}