Widget:JumpToSegment: Difference between revisions

From Bodhicitta
No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 1: Line 1:
<script>
<script>
(function() {
function tryScroll(hash, attemptsLeft) {
var hash = decodeURIComponent(window.location.hash.slice(1));
if (!hash) return;
if (!hash) return;
function tryScroll(attemptsLeft) {
var el = document.getElementById(hash);
var el = document.getElementById(hash);
if (el) {
if (el) {
el.scrollIntoView({behavior: 'instant', block: 'start'});
el.scrollIntoView({behavior: 'instant', block: 'start'});
return;
return;
}
if (attemptsLeft > 0) {
setTimeout(function() { tryScroll(attemptsLeft - 1); }, 200);
}
}
}
tryScroll(10);
if (attemptsLeft > 0) {
})();
setTimeout(function() { tryScroll(hash, attemptsLeft - 1); }, 200);
}
}
 
// Run once immediately, in case the widget script itself loads after the page is ready
tryScroll(decodeURIComponent(window.location.hash.slice(1)), 10);
 
// Also run any time the URL hash changes, in case navigation happens via JS rather than a full page reload
window.addEventListener('hashchange', function() {
tryScroll(decodeURIComponent(window.location.hash.slice(1)), 10);
});
</script>
</script>

Revision as of 20:51, 14 August 2026

<script> function tryScroll(hash, attemptsLeft) { if (!hash) return; var el = document.getElementById(hash); if (el) { el.scrollIntoView({behavior: 'instant', block: 'start'}); return; } if (attemptsLeft > 0) { setTimeout(function() { tryScroll(hash, attemptsLeft - 1); }, 200); } }

// Run once immediately, in case the widget script itself loads after the page is ready tryScroll(decodeURIComponent(window.location.hash.slice(1)), 10);

// Also run any time the URL hash changes, in case navigation happens via JS rather than a full page reload window.addEventListener('hashchange', function() { tryScroll(decodeURIComponent(window.location.hash.slice(1)), 10); }); </script>