Skip to content

Commit

Permalink
Update 06-modal-rating.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorSvertoka committed Jan 6, 2024
1 parent b66a6cd commit 8ad540a
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/js/06-modal-rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ const modalIsOpen = document.querySelector('.modal-rating');
const btnIsClosed = document.querySelector('.rating-close-btn');

modalExercises.addEventListener('click', onExercisesCardClick);
btnIsClosed.addEventListener('click', closeModalExercises);
modalIsOpen.addEventListener('click', closeModalExercises);
btnIsClosed.addEventListener('click', closeModal);
modalIsOpen.addEventListener('click', closeOverlay);

document.addEventListener('keydown', onEscClick);

function onExercisesCardClick(event) {
if (!event.target.closest('.modal-exercises__btn-rating')) {
Expand All @@ -15,7 +17,21 @@ function onExercisesCardClick(event) {
modalExercises.classList.add('hidden');
}

function closeModalExercises() {
function closeModal() {
modalIsOpen.classList.add('is-hidden');
modalExercises.classList.remove('hidden');
}

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

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

0 comments on commit 8ad540a

Please sign in to comment.