Skip to content

Commit

Permalink
Fix(JS) Update modal code
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorSvertoka committed Jan 6, 2024
1 parent 3dee783 commit b66a6cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/js/06-modal-rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const btnIsClosed = document.querySelector('.rating-close-btn');

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

function onExercisesCardClick(event) {
if (!event.target.closest('.modal-exercises__btn-rating')) {
Expand Down
32 changes: 16 additions & 16 deletions src/js/07-modal-team.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,25 @@ const teamCloseBtn = document.querySelector('.team__modal-close-btn');
function onLinkClick(event) {
event.preventDefault();

teamBackdrop.classList.remove('is-hidden');
document.body.classList.add('modal-open');

openModalStaff();
addAllEventListeners();
}

function onEscClick(event) {
event.preventDefault();

if (event.code !== 'Escape') {
return;
if (event.code === 'Escape') {
closeAndRemoveListeners();
}

closingModalStaff();
}

function onBackdropClick(event) {
if (event.target.closest('.team__wrapper')) {
return;
if (!event.target.closest('.team__wrapper')) {
closeAndRemoveListeners();
}

closingModalStaff();
}

function onCloseBtnClick(event) {
event.preventDefault();

closingModalStaff();
closeAndRemoveListeners();
}

function addAllEventListeners() {
Expand All @@ -41,11 +32,20 @@ function addAllEventListeners() {
teamCloseBtn.addEventListener('click', onCloseBtnClick);
}

function closingModalStaff() {
function closeAndRemoveListeners() {
document.removeEventListener('keydown', onEscClick);
teamBackdrop.removeEventListener('click', onBackdropClick);
teamCloseBtn.removeEventListener('click', onCloseBtnClick);

closeModalStaff();
}

function openModalStaff() {
teamBackdrop.classList.remove('is-hidden');
document.body.classList.add('modal-open');
}

function closeModalStaff() {
teamBackdrop.classList.add('is-hidden');
document.body.classList.remove('modal-open');
}
Expand Down

0 comments on commit b66a6cd

Please sign in to comment.