enhanced uploader
This commit is contained in:
@@ -13,6 +13,71 @@ htmx.on('htmx:configRequest', (event) => {
|
||||
event.detail.headers['X-CSRFToken'] = getCookie('csrftoken');
|
||||
});
|
||||
|
||||
function initialiseMobileNavigation() {
|
||||
const toggle = document.querySelector('[data-nav-toggle]');
|
||||
const closeButton = document.querySelector('[data-nav-close]');
|
||||
const nav = document.querySelector('#primary-navigation');
|
||||
const backdrop = document.querySelector('[data-nav-backdrop]');
|
||||
if (!toggle || !closeButton || !nav || !backdrop) return;
|
||||
|
||||
const mobile = window.matchMedia('(max-width: 700px)');
|
||||
document.body.classList.add('js-nav-ready');
|
||||
|
||||
function closeMenu(restoreFocus = true) {
|
||||
if (!document.body.classList.contains('mobile-nav-open')) return;
|
||||
document.body.classList.remove('mobile-nav-open');
|
||||
toggle.setAttribute('aria-expanded', 'false');
|
||||
toggle.setAttribute('aria-label', 'Open menu');
|
||||
backdrop.hidden = true;
|
||||
nav.inert = mobile.matches;
|
||||
if (restoreFocus) toggle.focus();
|
||||
}
|
||||
|
||||
function openMenu() {
|
||||
if (!mobile.matches) return;
|
||||
document.body.classList.add('mobile-nav-open');
|
||||
toggle.setAttribute('aria-expanded', 'true');
|
||||
toggle.setAttribute('aria-label', 'Close menu');
|
||||
backdrop.hidden = false;
|
||||
nav.inert = false;
|
||||
closeButton.focus();
|
||||
}
|
||||
|
||||
function syncViewport() {
|
||||
closeMenu(false);
|
||||
nav.inert = mobile.matches;
|
||||
}
|
||||
|
||||
toggle.addEventListener('click', () => {
|
||||
if (document.body.classList.contains('mobile-nav-open')) closeMenu();
|
||||
else openMenu();
|
||||
});
|
||||
closeButton.addEventListener('click', () => closeMenu());
|
||||
backdrop.addEventListener('click', () => closeMenu());
|
||||
document.addEventListener('keydown', (event) => {
|
||||
if (!document.body.classList.contains('mobile-nav-open')) return;
|
||||
if (event.key === 'Escape') {
|
||||
event.preventDefault();
|
||||
closeMenu();
|
||||
} else if (event.key === 'Tab') {
|
||||
const focusable = Array.from(nav.querySelectorAll('a, button:not([disabled])'));
|
||||
const first = focusable[0];
|
||||
const last = focusable[focusable.length - 1];
|
||||
if (event.shiftKey && document.activeElement === first) {
|
||||
event.preventDefault();
|
||||
last.focus();
|
||||
} else if (!event.shiftKey && document.activeElement === last) {
|
||||
event.preventDefault();
|
||||
first.focus();
|
||||
}
|
||||
}
|
||||
});
|
||||
mobile.addEventListener('change', syncViewport);
|
||||
syncViewport();
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', initialiseMobileNavigation);
|
||||
|
||||
|
||||
let fastingTimerInterval;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user