Skip to content

Commit

Permalink
Feat(JS) Added close for Esc
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorSvertoka committed Jan 6, 2024
1 parent 8ad540a commit 04a3e01
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/js/05-modal-exercises.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ overlay.addEventListener('click', function (event) {
}
});

window.addEventListener('keydown', function (event) {
document.addEventListener('keydown', function (event) {
if (event.key === 'Escape' && !modalExercises.classList.contains('hidden')) {
closeModalExercises();
}
Expand Down
9 changes: 3 additions & 6 deletions src/js/06-modal-rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const btnIsClosed = document.querySelector('.rating-close-btn');
modalExercises.addEventListener('click', onExercisesCardClick);
btnIsClosed.addEventListener('click', closeModal);
modalIsOpen.addEventListener('click', closeOverlay);

document.addEventListener('keydown', onEscClick);

function onExercisesCardClick(event) {
Expand All @@ -24,14 +23,12 @@ function closeModal() {

function closeOverlay(event) {
if (event.target == modalIsOpen) {
modalIsOpen.classList.add('is-hidden');
modalExercises.classList.remove('hidden');
closeModal();
}
}

function onEscClick(event) {
if (event.code === 'Escape') {
modalIsOpen.classList.add('is-hidden');
modalExercises.classList.remove('hidden');
if (event.key === 'Escape') {
closeModal();
}
}

0 comments on commit 04a3e01

Please sign in to comment.