uncomment observers

This commit is contained in:
isUnknown 2025-10-08 15:15:38 +02:00
parent 4223a9d522
commit 1e890cfa2e

View file

@ -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();
};
</script>