Files
xbcr/static/js/ui-motion.js
T

38 lines
1.3 KiB
JavaScript

(function () {
'use strict';
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
window.uiNavigate = function (url) {
if (reduceMotion) {
window.location.href = url;
return;
}
document.body.classList.add('ui-page-leaving');
window.setTimeout(function () { window.location.href = url; }, 170);
};
window.uiCloseWindow = function () {
if (reduceMotion) {
window.close();
return;
}
document.body.classList.add('ui-page-leaving');
window.setTimeout(function () { window.close(); }, 170);
};
document.addEventListener('click', function (event) {
const link = event.target.closest('a[href]');
if (!link || event.defaultPrevented || event.button !== 0 || event.metaKey ||
event.ctrlKey || event.shiftKey || event.altKey || link.target === '_blank' ||
link.hasAttribute('download')) return;
const destination = new URL(link.href, window.location.href);
if (destination.origin !== window.location.origin ||
(destination.pathname === window.location.pathname && destination.hash)) return;
event.preventDefault();
window.uiNavigate(destination.href);
});
})();