diff --git a/src/js/05-modal-exercises.js b/src/js/05-modal-exercises.js index bf42be7..dce7250 100644 --- a/src/js/05-modal-exercises.js +++ b/src/js/05-modal-exercises.js @@ -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(); } diff --git a/src/js/06-modal-rating.js b/src/js/06-modal-rating.js index 775e829..6585196 100644 --- a/src/js/06-modal-rating.js +++ b/src/js/06-modal-rating.js @@ -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) { @@ -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(); } }