diff --git a/themes/intotheeast/templates/trip.html.twig b/themes/intotheeast/templates/trip.html.twig index 83dc042..06b2bd1 100644 --- a/themes/intotheeast/templates/trip.html.twig +++ b/themes/intotheeast/templates/trip.html.twig @@ -132,6 +132,7 @@ {% if has_gpx %} {% endif %} + @@ -327,6 +328,23 @@ setTimeout(function () { tripMap.resize(); }, 100); }); })(); +(function() { + var sortBtn = document.getElementById('trip-sort-toggle'); + if (!sortBtn) return; + var feed = document.querySelector('.feed'); + var emptyMsg = document.getElementById('feed-filter-empty'); + var ascending = true; + + sortBtn.addEventListener('click', function() { + ascending = !ascending; + var entries = Array.from(feed.querySelectorAll('[data-type]')); + entries.reverse().forEach(function(el) { feed.insertBefore(el, emptyMsg); }); + sortBtn.textContent = ascending ? '↑ Oldest first' : '↓ Newest first'; + sortBtn.setAttribute('aria-label', ascending ? 'Sort: oldest first' : 'Sort: newest first'); + sortBtn.classList.toggle('is-active', !ascending); + }); +})(); + var STATS_GPS = {{ gps_points|json_encode|raw }}; var HAS_GPX = {{ has_gpx ? 'true' : 'false' }};