This commit is contained in:
2026-09-13 18:13:12 +02:00
parent 54ee89e63c
commit ffd32a6b63
3 changed files with 81 additions and 42 deletions
+26 -9
View File
@@ -1638,6 +1638,9 @@ window.cancelAnimFrame = (function () {
}
modal._isClosing = false;
document.body.classList.add('onara-modal-open');
if (document.querySelector('.index-container') && window.scrollY !== 0) {
window.scrollTo(0, 0);
}
modal.style.display = 'flex';
modal.setAttribute('aria-hidden', 'false');
modal.classList.remove('onara-fade-out');
@@ -1647,6 +1650,27 @@ window.cancelAnimFrame = (function () {
};
window.openOnaraModal = openOnaraModal;
const scrollOnaraThumbIntoView = (thumb, forceCenter = false) => {
if (!thumb) return;
const container = thumb.closest('.index-container');
if (container) {
const cRect = container.getBoundingClientRect();
const tRect = thumb.getBoundingClientRect();
const navbarH = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--navbar-h')) || 50;
const vh = window.innerHeight || document.documentElement.clientHeight;
const isVisible = tRect.bottom > navbarH && tRect.top < vh;
if (!isVisible || forceCenter) {
const targetScrollTop = container.scrollTop + (tRect.top - cRect.top) - (container.clientHeight / 2) + (tRect.height / 2);
container.scrollTop = Math.max(0, targetScrollTop);
}
} else {
thumb.scrollIntoView({ block: 'center', inline: 'nearest', behavior: 'instant' });
}
if (document.querySelector('.index-container') && window.scrollY !== 0) {
window.scrollTo(0, 0);
}
};
const updateOnaraActiveItem = (itemid, url, forceScroll = false, slug = null) => {
if (!isOnaraActive()) return null;
// Clear onara-active from any and all elements to guarantee only 1 item is selected
@@ -1673,14 +1697,7 @@ window.cancelAnimFrame = (function () {
if (targetThumb) {
targetThumb.classList.add('onara-active');
const rect = targetThumb.getBoundingClientRect();
const navbarH = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--navbar-h')) || 50;
const vh = window.innerHeight || document.documentElement.clientHeight;
// If any part of the thumbnail is already visible in the viewport, do not scroll
const isVisible = rect.bottom > navbarH && rect.top < vh;
if (!isVisible || forceScroll) {
targetThumb.scrollIntoView({ block: 'center', inline: 'nearest', behavior: 'instant' });
}
scrollOnaraThumbIntoView(targetThumb, forceScroll);
}
return targetThumb;
};
@@ -1804,7 +1821,7 @@ window.cancelAnimFrame = (function () {
synthThumb.innerHTML = '<div class="thumb-indicators"></div><p></p>';
oldPosts.prepend(synthThumb);
if (typeof window.initLazyLoading === 'function') window.initLazyLoading();
synthThumb.scrollIntoView({ block: 'center', inline: 'nearest', behavior: 'instant' });
scrollOnaraThumbIntoView(synthThumb, true);
}
} catch (err) {
console.error('[ONARA] Failed to sync background grid:', err);