Skip to content

Commit 2da7340

Browse files
committed
Timetable modal now closes when clicking outside
1 parent 979ca9d commit 2da7340

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

script.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,15 @@ function openTimetableModal(stopCode) {
124124
}
125125

126126
function closeTimetableModal(stopCode) {
127+
// Close on clicking outside modal
128+
document.addEventListener("click", (event) => {
129+
if (event.target.id !== `modal-${stopCode}`) {
130+
return;
131+
}
132+
});
133+
127134
const modal = document.getElementById(`modal-${stopCode}`);
135+
128136
if (modal) {
129137
modal.classList.add('hidden');
130138
document.body.style.overflow = '';
@@ -434,8 +442,9 @@ async function createStationCard(stopPoint) {
434442
const modal = document.createElement('div');
435443
modal.className = 'timetable-modal hidden';
436444
modal.id = `modal-${stopPoint.code}`;
445+
modal.onclick = () => closeTimetableModal(stopPoint.code);
437446
modal.innerHTML = `
438-
<div class="modal-content">
447+
<div class="modal-content" onclick="event.stopPropagation()">
439448
<div class="modal-header" >
440449
<h3>First/Last Trains</h3>
441450
<button class="modal-close" onclick="closeTimetableModal('${stopPoint.code}')">&times;</button>

0 commit comments

Comments
 (0)