Skip to content

Commit f4fbb3d

Browse files
authored
Website Update
1 parent 3934860 commit f4fbb3d

2 files changed

Lines changed: 21 additions & 55 deletions

File tree

docs/assets/js/shell.js

Lines changed: 20 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,7 @@
672672
if (!target) return;
673673

674674
event.preventDefault();
675-
const destination = scrollToTarget(hash);
676-
window.dispatchEvent(new CustomEvent('modelized:navautoscroll', {
677-
detail: { hash, destination }
678-
}));
675+
scrollToTarget(hash);
679676

680677
const nav = document.querySelector('.nav');
681678
if (nav?.classList.contains('nav--open')){
@@ -798,54 +795,27 @@
798795

799796
const homeSection = document.querySelector("#hero");
800797
let lockedHash = "";
801-
let lockedDestination = null;
802-
let lockFrame = 0;
803798
let lockTimer = 0;
804799

805800
const clearScrollLock = () => {
806-
if (lockFrame) {
807-
cancelAnimationFrame(lockFrame);
808-
lockFrame = 0;
809-
}
810801
if (lockTimer) {
811802
clearTimeout(lockTimer);
812803
lockTimer = 0;
813804
}
814805
lockedHash = "";
815-
lockedDestination = null;
816806
};
817807

818808
const releaseScrollLock = () => {
819809
clearScrollLock();
820810
syncFromViewport();
821811
};
822812

823-
const watchScrollLock = () => {
813+
const scheduleScrollLockRelease = (delay = 140) => {
824814
if (!lockedHash) return;
825-
826-
let lastY = getScrollTop();
827-
let stillFrames = 0;
828-
829-
const tick = () => {
830-
lockFrame = 0;
831-
if (!lockedHash) return;
832-
833-
const currentY = getScrollTop();
834-
const delta = Math.abs(currentY - lastY);
835-
const nearDestination = lockedDestination !== null && Math.abs(currentY - lockedDestination) <= 2;
836-
837-
lastY = currentY;
838-
stillFrames = (nearDestination || delta < 0.5) ? (stillFrames + 1) : 0;
839-
840-
if (stillFrames >= 3) {
841-
releaseScrollLock();
842-
return;
843-
}
844-
845-
lockFrame = requestAnimationFrame(tick);
846-
};
847-
848-
lockFrame = requestAnimationFrame(tick);
815+
if (lockTimer) {
816+
clearTimeout(lockTimer);
817+
}
818+
lockTimer = window.setTimeout(releaseScrollLock, delay);
849819
};
850820

851821
setActiveByHash(location.hash);
@@ -912,28 +882,24 @@
912882
map.forEach((_link, section) => observer.observe(section));
913883
requestAnimationFrame(syncFromViewport);
914884

915-
window.addEventListener('modelized:navautoscroll', (event) => {
916-
const nextHash = event.detail?.hash;
917-
if (!nextHash) return;
918-
919-
clearScrollLock();
920-
lockedHash = nextHash;
921-
lockedDestination = typeof event.detail?.destination === 'number' ? event.detail.destination : null;
922-
setActiveByHash(lockedHash);
923-
924-
if (prefersReducedMotion) {
925-
lockTimer = window.setTimeout(releaseScrollLock, 0);
926-
return;
927-
}
885+
links.forEach((link) => {
886+
link.addEventListener('click', () => {
887+
const nextHash = link.getAttribute('href');
888+
if (!nextHash || !nextHash.startsWith('#')) return;
928889

929-
lockTimer = window.setTimeout(watchScrollLock, 120);
890+
clearScrollLock();
891+
lockedHash = nextHash;
892+
setActiveByHash(lockedHash);
893+
scheduleScrollLockRelease(prefersReducedMotion ? 0 : 180);
894+
});
930895
});
931896

897+
window.addEventListener('scroll', () => {
898+
scheduleScrollLockRelease(140);
899+
}, { passive: true });
900+
932901
window.addEventListener('orientationchange', clearScrollLock);
933-
window.addEventListener('resize', () => {
934-
if (!lockedHash) return;
935-
lockTimer = window.setTimeout(releaseScrollLock, 0);
936-
});
902+
window.addEventListener('resize', releaseScrollLock);
937903
}
938904

939905
function initSectionDepth() {

docs/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,6 @@ <h2>Live Modules</h2>
133133

134134
<div id="footer-slot"></div>
135135

136-
<script src="assets/js/shell.js?v=20260321j" defer></script>
136+
<script src="assets/js/shell.js?v=20260321k" defer></script>
137137
</body>
138138
</html>

0 commit comments

Comments
 (0)