This commit is contained in:
2026-09-29 04:35:35 +02:00
parent 73c0659d4a
commit 6c813143eb
51 changed files with 3708 additions and 743 deletions
+49 -4
View File
@@ -7,10 +7,47 @@
const dragModalClose = document.getElementById('drag-modal-close');
const dragForm = dragModal ? dragModal.querySelector('.upload-form') : null;
const navUploadLink = document.getElementById('nav-upload-link');
// Dropdown placement: right under the navbar "Upload" link, left-aligned with it and kept inside the
// window. Without a visible link (phone: it sits in the collapsed menu) it drops from the navbar.
const positionModal = () => {
if (!dragModal || !dragModal.classList.contains('show')) return;
const content = dragModal.querySelector('.modal-content');
if (!content) return;
const vw = document.documentElement.clientWidth;
const linkRect = navUploadLink ? navUploadLink.getBoundingClientRect() : null;
const useLink = !!(linkRect && linkRect.width > 0 && linkRect.height > 0);
const nav = document.querySelector('body > nav.navbar, nav.navbar');
const top = Math.round((useLink ? linkRect.bottom : (nav ? nav.getBoundingClientRect().bottom : 0)) + 6);
content.style.top = top + 'px';
content.style.maxHeight = Math.max(200, window.innerHeight - top - 12) + 'px';
const w = content.offsetWidth;
let left = useLink ? linkRect.left : (vw - w) / 2;
left = Math.max(8, Math.min(left, vw - w - 8));
content.style.left = Math.round(left) + 'px';
};
window.addEventListener('resize', positionModal, { passive: true });
// The navbar link shows when the dropdown is open. Watched on the modal itself because it gets closed
// from several places (close button, Escape, toggle, finished upload, hideAllModals).
if (dragModal && navUploadLink) {
const syncLink = () => {
const open = dragModal.classList.contains('show');
navUploadLink.classList.toggle('is-active', open);
navUploadLink.setAttribute('aria-expanded', open ? 'true' : 'false');
};
new MutationObserver(syncLink).observe(dragModal, { attributes: true, attributeFilter: ['class'] });
syncLink();
}
const navEl = document.querySelector('body > nav.navbar, nav.navbar');
if (navEl && window.ResizeObserver) new ResizeObserver(positionModal).observe(navEl);
const showModal = () => {
if (!dragModal) return;
dragModal.classList.add('show');
dragModal.classList.add('show', 'is-dropdown');
document.body.classList.add('modal-open');
positionModal();
// Reset scroll position so it always starts at the top
dragModal.scrollTop = 0;
const modalContent = dragModal.querySelector('.modal-content');
@@ -19,14 +56,22 @@
if (modalBody) modalBody.scrollTop = 0;
};
// Hide without resetting: a picked file / typed tags survive, reopening continues there.
// (The close button and Escape still close + reset, see below.)
const hideModal = () => {
if (!dragModal) return;
dragModal.classList.remove('show');
document.body.classList.remove('modal-open');
};
// Navbar upload link — always attached so it works even if drag-drop can't init.
// Opens the modal when available; falls back to /upload navigation otherwise.
const navUploadLink = document.getElementById('nav-upload-link');
// Toggles the dropdown when available; falls back to /upload navigation otherwise.
if (navUploadLink) {
navUploadLink.addEventListener('click', (e) => {
if (!dragModal) return; // no modal → fall back to href navigation
e.preventDefault();
showModal();
if (dragModal.classList.contains('show')) hideModal();
else showModal();
});
}