2026-03-02 09:30:46 -05:00
|
|
|
import * as bootstrap from 'bootstrap';
|
|
|
|
|
window.bootstrap = bootstrap;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// trap browser back and close the modal if open
|
|
|
|
|
const cardModal = document.getElementById('cardModal');
|
2026-03-05 12:10:55 -05:00
|
|
|
const loadingMsg = cardModal.innerHTML;
|
2026-03-02 09:30:46 -05:00
|
|
|
// Push a new history state when the modal is shown
|
|
|
|
|
cardModal.addEventListener('shown.bs.modal', () => {
|
|
|
|
|
history.pushState({ modalOpen: true }, null, '#cardModal');
|
|
|
|
|
});
|
|
|
|
|
// Listen for the browser's back button (popstate event)
|
|
|
|
|
window.addEventListener('popstate', (e) => {
|
|
|
|
|
if (cardModal.classList.contains('show')) {
|
|
|
|
|
const modalInstance = bootstrap.Modal.getInstance(cardModal);
|
|
|
|
|
if (modalInstance) {
|
|
|
|
|
modalInstance.hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// Trigger a back navigation when the modal is closed via its native controls (X, backdrop click)
|
|
|
|
|
cardModal.addEventListener('hide.bs.modal', () => {
|
2026-03-05 12:10:55 -05:00
|
|
|
cardModal.innerHTML = loadingMsg;
|
2026-03-02 09:30:46 -05:00
|
|
|
if (history.state && history.state.modalOpen) {
|
|
|
|
|
history.back();
|
|
|
|
|
}
|
|
|
|
|
});
|