Skip to content

Commit

Permalink
feat: Add keyboard navigation for image gallery modal
Browse files Browse the repository at this point in the history
  • Loading branch information
drikusroor committed Oct 11, 2024
1 parent 7f4c63d commit 982e811
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/blog/templates/blog/includes/image-modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
modal.style.display = "none";
}
})

// Function triggerd by pressing the next button, to see the next picture in the gallery
next.addEventListener('click', () => {
const nextIndex = currentImageID == openModals.length - 1 ? 0 : currentImageID + 1;
Expand All @@ -60,6 +60,17 @@
setCurrentImageID(modalinfo);
})

// Add event listeners for the arrow keys to navigate through the gallery
document.addEventListener('keydown', (e) => {
if (e.key === 'ArrowRight') {
next.click();
} else if (e.key === 'ArrowLeft') {
prev.click();
} else if (e.key === 'Escape') {
modal.style.display = "none";
}
})

// Return the item from an array with the correct class
function searchForClass (array, className) {
var classItem;
Expand Down

0 comments on commit 982e811

Please sign in to comment.