fix: improve forum reply anchor scroll — wait for full page load
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions

Use window 'load' event and scrollRestoration=manual to ensure scroll
happens after all content is rendered, overriding browser's native
anchor scroll which fires too early.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-04-09 21:55:16 +02:00
parent 150af432bf
commit 6ba5910c26

View File

@ -1504,23 +1504,27 @@
{% block extra_js %}
// Scroll to reply anchor (e.g. from notification link #reply-55)
(function() {
function scrollToReplyAnchor() {
var hash = window.location.hash;
if (hash && hash.startsWith('#reply-')) {
var target = document.getElementById(hash.substring(1));
if (target) {
var headerH = document.querySelector('header');
var offset = headerH ? headerH.offsetHeight + 16 : 80;
setTimeout(function() {
var top = target.getBoundingClientRect().top + window.pageYOffset - offset;
window.scrollTo({ top: top, behavior: 'smooth' });
target.style.transition = 'box-shadow 0.3s ease';
target.style.boxShadow = '0 0 0 3px var(--primary-light, #4a6999)';
setTimeout(function() { target.style.boxShadow = ''; }, 3000);
}, 200);
}
}
})();
if (!hash || !hash.startsWith('#reply-')) return;
var target = document.getElementById(hash.substring(1));
if (!target) return;
// Disable native browser scroll-to-anchor
if ('scrollRestoration' in history) history.scrollRestoration = 'manual';
window.scrollTo(0, 0);
var headerH = document.querySelector('header');
var offset = headerH ? headerH.offsetHeight + 16 : 80;
var top = target.getBoundingClientRect().top + window.pageYOffset - offset;
window.scrollTo({ top: top, behavior: 'smooth' });
target.style.transition = 'box-shadow 0.3s ease';
target.style.boxShadow = '0 0 0 3px var(--primary-light, #4a6999)';
setTimeout(function() { target.style.boxShadow = ''; }, 3000);
}
if (document.readyState === 'complete') {
setTimeout(scrollToReplyAnchor, 100);
} else {
window.addEventListener('load', function() { setTimeout(scrollToReplyAnchor, 100); });
}
function showToast(message, type = 'info', duration = 4000) {
const container = document.getElementById('toastContainer');