Files
crank/apps/ui/js/page-transitions.js
github-ops 5f8149d0d1
Deploy / deploy (push) Failing after 1m43s
CI / Rust Checks (push) Successful in 5m54s
CI / UI Checks (push) Successful in 4s
CI / Deployment Manifests (push) Successful in 3s
CI / Frontend E2E (push) Successful in 4m24s
Fix workspace selection and secret modal layout
2026-06-22 18:30:56 +00:00

55 lines
1.7 KiB
JavaScript

(function() {
'use strict';
var transitionMs = 120;
function prefersReducedMotion() {
return window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
}
function isInternalNavigation(link) {
if (!link || !link.href || link.target || link.hasAttribute('download')) return false;
var targetUrl;
try {
targetUrl = new URL(link.href, window.location.href);
} catch (_error) {
return false;
}
if (targetUrl.origin !== window.location.origin) return false;
if (targetUrl.pathname === window.location.pathname && targetUrl.search === window.location.search) {
return targetUrl.hash && targetUrl.hash !== window.location.hash;
}
return true;
}
function initPageTransitions() {
if (prefersReducedMotion()) return;
document.addEventListener('click', function(event) {
if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
return;
}
var link = event.target.closest ? event.target.closest('a[href]') : null;
if (!isInternalNavigation(link)) return;
var targetUrl = new URL(link.href, window.location.href);
if (targetUrl.pathname === window.location.pathname && targetUrl.search === window.location.search) return;
event.preventDefault();
document.body.classList.add('page-leaving');
window.setTimeout(function() {
window.location.href = targetUrl.href;
}, transitionMs);
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initPageTransitions, { once: true });
} else {
initPageTransitions();
}
})();