function togglePopup(popup) {
popup.classList.toggle('popup_active');
if (popup.classList.contains('popup_active')) {
document.addEventListener('keydown', closeEscape);
} else {
document.removeEventListener('keydown', closeEscape);
}
}
const closeEscape = (evt) => {
if (evt.key === "Escape") {
popup.classList.remove('popup_active');
}
}
function togglePopup(popup) {
popup.classList.toggle('popup_active');
if (popup.classList.contains('popup_opened')) {
document.addEventListener('keydown', closeEscape);
} else {
document.removeEventListener('keydown', closeEscape);
}
}
const closeEscape = (evt) => {
if (evt.key === 'Escape') {
const popupList = Array.from(document.querySelectorAll('.popup'));
popupList.forEach((popup) => {
if (popup.classList.contains('popup_active')) {
togglePopup(popup);
}
});
}
}