Navigation (history) from modal boxes fixed.
This commit is contained in:
parent
da0bd681e1
commit
ff4ac844d0
1 changed files with 13 additions and 22 deletions
|
|
@ -1407,7 +1407,6 @@ function confirmAction(message, btnText = "Confirm") {
|
||||||
const okBtn = document.getElementById('confirm-btn-ok');
|
const okBtn = document.getElementById('confirm-btn-ok');
|
||||||
const cancelBtn = document.getElementById('confirm-btn-cancel');
|
const cancelBtn = document.getElementById('confirm-btn-cancel');
|
||||||
const closeBtn = modal.querySelector('.close-btn');
|
const closeBtn = modal.querySelector('.close-btn');
|
||||||
const modalContext = 'confirmation-modal';
|
|
||||||
|
|
||||||
msgEl.innerText = message;
|
msgEl.innerText = message;
|
||||||
okBtn.innerText = btnText;
|
okBtn.innerText = btnText;
|
||||||
|
|
@ -1416,24 +1415,24 @@ function confirmAction(message, btnText = "Confirm") {
|
||||||
|
|
||||||
// 1. Cleanup & Resolve
|
// 1. Cleanup & Resolve
|
||||||
const close = () => {
|
const close = () => {
|
||||||
window.removeEventListener('popstate', onPopState);
|
window.removeEventListener('keydown', onKeyDown, true);
|
||||||
modal.style.display = 'none';
|
modal.style.display = 'none';
|
||||||
resolve(resultToResolve);
|
resolve(resultToResolve);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 2. Handle History Changes (Back Button / Escape)
|
// 2. Escape Key Listener (Capturing phase to intercept before NavManager)
|
||||||
const onPopState = () => {
|
const onKeyDown = (e) => {
|
||||||
close();
|
if (e.key === 'Escape') {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
commit(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 3. Handle UI Actions (OK / Cancel)
|
// 3. Handle UI Actions (OK / Cancel)
|
||||||
const commit = (res) => {
|
const commit = (res) => {
|
||||||
resultToResolve = res;
|
resultToResolve = res;
|
||||||
if (history.state && history.state.context === modalContext) {
|
close();
|
||||||
history.back(); // This triggers onPopState -> close()
|
|
||||||
} else {
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 4. Setup DOM (Clone to cleanly remove old listeners)
|
// 4. Setup DOM (Clone to cleanly remove old listeners)
|
||||||
|
|
@ -1446,12 +1445,8 @@ function confirmAction(message, btnText = "Confirm") {
|
||||||
newCancel.onclick = (e) => { e.stopPropagation(); commit(false); };
|
newCancel.onclick = (e) => { e.stopPropagation(); commit(false); };
|
||||||
closeBtn.onclick = (e) => { e.stopPropagation(); e.preventDefault(); commit(false); };
|
closeBtn.onclick = (e) => { e.stopPropagation(); e.preventDefault(); commit(false); };
|
||||||
|
|
||||||
// 5. Open & Push State
|
// 5. Setup Listeners and Display
|
||||||
if (!history.state || history.state.context !== modalContext) {
|
window.addEventListener('keydown', onKeyDown, true);
|
||||||
history.pushState({ context: modalContext }, "", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener('popstate', onPopState);
|
|
||||||
modal.style.display = 'flex';
|
modal.style.display = 'flex';
|
||||||
newCancel.focus(); // Default focus on Cancel
|
newCancel.focus(); // Default focus on Cancel
|
||||||
});
|
});
|
||||||
|
|
@ -2634,12 +2629,8 @@ const NavManager = {
|
||||||
if (typeof iframe !== 'undefined') { iframe.style.display = 'none'; iframe.src = 'about:blank'; }
|
if (typeof iframe !== 'undefined') { iframe.style.display = 'none'; iframe.src = 'about:blank'; }
|
||||||
|
|
||||||
// 2. Restore View
|
// 2. Restore View
|
||||||
if (ctx === 'map') {
|
if (ctx && document.getElementById('view-' + ctx)) {
|
||||||
switchView('map', true); // Pass true to skip pushState
|
switchView(ctx, true);
|
||||||
} else if (ctx === 'nets') {
|
|
||||||
switchView('nets', true);
|
|
||||||
} else if (ctx === 'inspect') {
|
|
||||||
switchView('inspect', true);
|
|
||||||
} else {
|
} else {
|
||||||
// Default to List
|
// Default to List
|
||||||
switchView('list', true);
|
switchView('list', true);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue