Refactor modal reopening logic to streamline URL parameter handling and improve code clarity

This commit is contained in:
Ross
2026-03-23 10:35:07 +00:00
parent 077bd3ed87
commit b17774aa7c
+11 -19
View File
@@ -1333,34 +1333,26 @@
window.history.replaceState({}, '', url.toString()); window.history.replaceState({}, '', url.toString());
} }
// On load: reopen modals if URL params present // On load: reopen modals if URL params present — call loader functions directly
(function reopenModalsFromUrl() { (function reopenModalsFromUrl() {
const params = new URL(window.location.href).searchParams; const params = new URL(window.location.href).searchParams;
const dsId = params.get('displayset'); const dsId = params.get('displayset');
const dsFull = params.get('displayset_full'); const dsFull = params.get('displayset_full');
const findingId = params.get('finding'); const findingId = params.get('finding');
if (dsId) { if (dsId) {
// try to find a button for this displayset and click it // prefer to use existing button url if present, otherwise construct endpoint
const btn = document.querySelector(`.view-displayset-modal[data-ds-id="${dsId}"]`); const btn = document.querySelector(`.view-displayset-modal[data-ds-id="${dsId}"]`);
if (btn) { const url = btn ? btn.dataset.url : null;
// open fullscreen if requested if (dsFull) {
if (dsFull) { loadDisplaysetFullscreen(url, dsId);
// ensure the modal content is loaded then trigger fullscreen } else {
btn.click(); loadDisplaysetModal(url, dsId);
// wait for content then trigger fullscreen button
setTimeout(function () {
const fs = document.querySelector('.displayset-fullscreen-btn');
if (fs) fs.click();
}, 800);
} else {
btn.click();
}
return;
} }
} } else if (findingId) {
if (findingId) { // open finding modal
const fbtn = document.querySelector(`.view-finding-modal[data-finding-id="${findingId}"]`); const fbtn = document.querySelector(`.view-finding-modal[data-finding-id="${findingId}"]`);
if (fbtn) fbtn.click(); const url = fbtn ? fbtn.getAttribute('data-url') : null;
loadFindingModal(findingId, url);
} }
})(); })();