From 1e890cfa2e3c70227e021b6516da6baefa030ae3 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Wed, 8 Oct 2025 15:15:38 +0200 Subject: [PATCH] uncomment observers --- src/components/project/PdfViewer.vue | 69 +++++++++++++++------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/src/components/project/PdfViewer.vue b/src/components/project/PdfViewer.vue index 4acd480..0fd8f77 100644 --- a/src/components/project/PdfViewer.vue +++ b/src/components/project/PdfViewer.vue @@ -50,38 +50,43 @@ const currentPageIndex = ref(1); // Functions const onPdfLoaded = () => { - // const wrapper = document.querySelector('.vpv-pages-inner-container'); - // const observer = new IntersectionObserver( - // (entries) => { - // entries.forEach((entry, index) => { - // if (entry.intersectionRatio > 0.5) { - // currentPageIndex.value = parseInt( - // entry.target.getAttribute('aria-label').split(' ')[1] - // ); - // } - // }); - // }, - // { - // root: wrapper, - // threshold: [0.5], - // } - // ); - // const observePages = () => { - // const pages = document.querySelectorAll('.vpv-page-inner-container'); - // pages.forEach((page) => { - // if (!page.__observed__) { - // observer.observe(page); - // page.__observed__ = true; - // } - // }); - // }; - // const mutationObserver = new MutationObserver(() => { - // observePages(); - // }); - // if (wrapper) { - // mutationObserver.observe(wrapper, { childList: true, subtree: true }); - // } - // observePages(); + const wrapper = document.querySelector('.vpv-pages-inner-container'); + + const observer = new IntersectionObserver( + (entries) => { + entries.forEach((entry, index) => { + if (entry.intersectionRatio > 0.5) { + currentPageIndex.value = parseInt( + entry.target.getAttribute('aria-label').split(' ')[1] + ); + } + }); + }, + { + root: wrapper, + threshold: [0.5], + } + ); + + const observePages = () => { + const pages = document.querySelectorAll('.vpv-page-inner-container'); + pages.forEach((page) => { + if (!page.__observed__) { + observer.observe(page); + page.__observed__ = true; + } + }); + }; + + const mutationObserver = new MutationObserver(() => { + observePages(); + }); + + if (wrapper) { + mutationObserver.observe(wrapper, { childList: true, subtree: true }); + } + + observePages(); };