Changeset 230e446 in Klonkt for src/assets/js/audio-player.js


Ignore:
Timestamp:
06/20/2026 01:38:16 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
fa08981
Parents:
d188736
Message:

feat(player): mini-player jumps to post AND scrolls to the track (desktop)

Track embed gets id="track-<id>" (anchor) + id in the track JSON. goToPost
now carries the track id: after the htmx swap to the post it scrolls to the
track embed (block:center, smooth) with a brief highlight, instead of
scrolling to the top. Busters: audio-player.js?v=17, style.css?v=16.

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/assets/js/audio-player.js

    rd188736 r230e446  
    566566  //    via htmx zodat de audio blijft spelen. Geen post bekend → val terug op de sheet.
    567567  //  - MOBIEL: altijd de uitgebreide speler-sheet openen (huidig gedrag).
    568   function goToPost(url) {
     568  function scrollToTrack(trackId) {
     569    if (!trackId) { window.scrollTo(0, 0); return; }
     570    const el = document.getElementById('track-' + trackId);
     571    if (!el) { window.scrollTo(0, 0); return; }
     572    el.scrollIntoView({ block: 'center', behavior: 'smooth' });
     573    el.classList.add('pat-flash');
     574    setTimeout(() => el.classList.remove('pat-flash'), 1600);
     575  }
     576  function goToPost(url, trackId) {
     577    const hash = trackId ? ('#track-' + trackId) : '';
    569578    if (window.htmx && url.charAt(0) === '/') {
    570579      try {
    571         window.htmx.ajax('GET', url, { target: '#pcms-main', swap: 'innerHTML' });
    572         history.pushState({}, '', url);
    573         window.scrollTo(0, 0);
     580        const p = window.htmx.ajax('GET', url, { target: '#pcms-main', swap: 'innerHTML' });
     581        history.pushState({}, '', url + hash);
     582        // Na de swap naar de track scrollen (klein uitstel zodat de globale
     583        // afterSwap-top-scroll eerst is geweest); val terug op top als niet gevonden.
     584        const go = () => setTimeout(() => scrollToTrack(trackId), 60);
     585        if (p && typeof p.then === 'function') p.then(go); else setTimeout(go, 150);
    574586        return;
    575587      } catch (e) { /* val terug op volledige navigatie */ }
    576588    }
    577     location.href = url;
     589    location.href = url + hash;
    578590  }
    579591  expandTrigger.addEventListener('click', () => {
    580592    const t = queue[currentIndex];
    581593    const isDesktop = window.matchMedia && window.matchMedia('(min-width: 768px)').matches;
    582     if (isDesktop && t && t.postUrl) { goToPost(t.postUrl); return; }
     594    if (isDesktop && t && t.postUrl) { goToPost(t.postUrl, t.id); return; }
    583595    openSheet();
    584596  });
Note: See TracChangeset for help on using the changeset viewer.