From a8df9590fd8b57d2e8ef7e63dddfbee6fec38d2a Mon Sep 17 00:00:00 2001 From: rirat-0 Date: Wed, 17 Jun 2026 15:38:59 +0200 Subject: [PATCH] updater sorter.js fuer client seite --- js/sorter.js | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/js/sorter.js b/js/sorter.js index 2d0d743..66f1a3e 100644 --- a/js/sorter.js +++ b/js/sorter.js @@ -1,26 +1,45 @@ -function initSorter() { - const form = document.getElementById('search-form-id'); +function initClientSorter() { + const listContainer = document.querySelector('.s-res-list'); const sortRadios = document.querySelectorAll('.sort-radio'); - if (!form) return; + // wenn keine liste vorhanden, abbrechen + if (!listContainer || sortRadios.length === 0) return; sortRadios.forEach(radio => { radio.addEventListener('change', function() { - - const pageInput = document.getElementById('s-res-page-input'); - if (pageInput) { - pageInput.value = '1'; - } - - form.submit(); + const cards = Array.from(listContainer.querySelectorAll('.s-res-item')); + const sortValue = this.value; + + cards.sort((a, b) => { + 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(); + return titleA.localeCompare(titleB); + } + else if (sortValue === 'newest' || sortValue === 'oldest') { + // hoehere ID wird als neuer gesehen + const urlA = a.querySelector('.s-res-link').getAttribute('href'); + const urlB = b.querySelector('.s-res-link').getAttribute('href'); + + const idA = parseInt(urlA.match(/id=(\d+)/)[1], 10); + const idB = parseInt(urlB.match(/id=(\d+)/)[1], 10); + + return sortValue === 'newest' ? idB - idA : idA - idB; + } + return 0; + }); + + listContainer.innerHTML = ''; + cards.forEach(card => listContainer.appendChild(card)); }); }); } // ist das DOM bereits vollständig aufgebaut? if (document.readyState === 'loading') { - document.addEventListener('DOMContentLoaded', initSorter); + document.addEventListener('DOMContentLoaded', initClientSorter); } else { - initSorter(); + initClientSorter(); } \ No newline at end of file