farling42 / fvtt-pdf-pager

PDF Pager for Foundry
MIT License
6 stars 4 forks source link

Scroll TOC when PDF view scrolled #75

Open farling42 opened 9 months ago

farling42 commented 9 months ago

Ensure that the visible part of the TOC mirrors the visible part of the PDF when the PDF view is changed.

farling42 commented 9 months ago

Things to look at: IntersectionObserver JournalSheet._onPageScroll JournalSheet._observeHeadings JournalSheet.synchroniseSidebar _activatePagesInView

farling42 commented 5 months ago

The <ol class="directory-list scrollable"> has the scrollTop property that varies when the TOC is scrolled up and down.

farling42 commented 5 months ago

JournalSheet._observeHeadings looks for all the h1-h6 headings in the journal page, and then sets up the InteractionObserver.

    const headings = Array.fromRange(6, 1).map(n => `h${n}`).join(",");
    element.querySelectorAll(`.journal-entry-page :is(${headings})`).forEach(el => headingObserver.observe(el));

This would need to include the headings in the PDF iframe as well as the normal pages.

farling42 commented 5 days ago

Simply call scrollIIntoView() on the entry in the TOC which matches the page/header.