+
diff --git a/js/sorter.js b/js/sorter.js
index 66f1a3e..5a1ee59 100644
--- a/js/sorter.js
+++ b/js/sorter.js
@@ -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();
}
\ No newline at end of file