mirror of
https://github.com/go-gitea/gitea.git
synced 2026-01-24 06:25:54 +01:00
refactor: enhance TOC position updates with ResizeObserver and IntersectionObserver
- Replace window resize and scroll event listeners with a ResizeObserver to monitor changes in the document body. - Implement an IntersectionObserver for the file header to trigger TOC position updates based on its visibility. - This improves performance and responsiveness of the TOC sidebar in file views.
This commit is contained in:
parent
2d7b11e365
commit
e7fb9af3cb
@ -142,8 +142,22 @@ function initTocToggle(elFileView: HTMLElement): void {
|
||||
}
|
||||
|
||||
// Update TOC position on resize/scroll to keep aligned with file content
|
||||
window.addEventListener('resize', updatePosition);
|
||||
window.addEventListener('scroll', updatePosition);
|
||||
const resizeObserver = new ResizeObserver(() => {
|
||||
updatePosition();
|
||||
});
|
||||
resizeObserver.observe(document.body);
|
||||
|
||||
const fileHeader = elFileView.querySelector('.file-header');
|
||||
if (fileHeader) {
|
||||
const intersectionObserver = new IntersectionObserver(() => {
|
||||
updatePosition();
|
||||
}, {
|
||||
root: null,
|
||||
rootMargin: '0px',
|
||||
threshold: [0, 0.25, 0.5, 0.75, 1.0],
|
||||
});
|
||||
intersectionObserver.observe(fileHeader);
|
||||
}
|
||||
|
||||
toggleBtn.addEventListener('click', () => {
|
||||
const isCurrentlyVisible = !tocSidebar.classList.contains('toc-panel-hidden');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user