fix: Improve modal event binding and close button functionality
- Remove inline onclick attribute from close button - Add ID-based event listener binding in DOMContentLoaded - Add preventDefault and stopPropagation to close handler - Add console logging for debugging - Add null checks for modal elements
This commit is contained in:
@@ -207,22 +207,37 @@ function closeDetailModal() {
|
|||||||
modal.classList.remove('active');
|
modal.classList.remove('active');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close modal when clicking outside
|
// Initialize modal event listeners
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
const modal = document.getElementById('detail-modal');
|
const modal = document.getElementById('detail-modal');
|
||||||
|
const closeBtn = document.getElementById('modal-close-btn');
|
||||||
|
|
||||||
|
// Close button click
|
||||||
|
if (closeBtn) {
|
||||||
|
closeBtn.addEventListener('click', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
closeDetailModal();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Click outside modal
|
||||||
|
if (modal) {
|
||||||
modal.addEventListener('click', (e) => {
|
modal.addEventListener('click', (e) => {
|
||||||
if (e.target === modal) {
|
if (e.target === modal) {
|
||||||
closeDetailModal();
|
closeDetailModal();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Close on escape key
|
// Escape key
|
||||||
document.addEventListener('keydown', (e) => {
|
document.addEventListener('keydown', (e) => {
|
||||||
if (e.key === 'Escape' && modal.classList.contains('active')) {
|
if (e.key === 'Escape' && modal && modal.classList.contains('active')) {
|
||||||
closeDetailModal();
|
closeDetailModal();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('Detail modal initialized');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Export for use in other modules
|
// Export for use in other modules
|
||||||
|
|||||||
@@ -261,7 +261,7 @@
|
|||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h2>Capture Details</h2>
|
<h2>Capture Details</h2>
|
||||||
<button class="modal-close" onclick="closeDetailModal()">×</button>
|
<button id="modal-close-btn" class="modal-close">×</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body" id="modal-body-content">
|
<div class="modal-body" id="modal-body-content">
|
||||||
<!-- Content loaded dynamically -->
|
<!-- Content loaded dynamically -->
|
||||||
|
|||||||
Reference in New Issue
Block a user