Skip to content

Commit

Permalink
Perf(JS) Changes to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorSvertoka committed Jun 23, 2024
1 parent bee3b1b commit 7cf22ba
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 162 deletions.
53 changes: 0 additions & 53 deletions src/js/modal-team.js

This file was deleted.

81 changes: 81 additions & 0 deletions src/js/modal-windows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
function setupModal(
linkSelector,
backdropSelector,
closeBtnSelector,
wrapperSelector
) {
const link = document.querySelector(linkSelector);
const backdrop = document.querySelector(backdropSelector);
const closeBtn = document.querySelector(closeBtnSelector);

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

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

addAllEventListeners();
}

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

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

closingModalStaff();
}

function onBackdropClick(event) {
if (event.target.closest(wrapperSelector)) {
return;
}

closingModalStaff();
}

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

closingModalStaff();
}

function addAllEventListeners() {
document.addEventListener('keydown', onEscClick);
backdrop.addEventListener('click', onBackdropClick);
closeBtn.addEventListener('click', onCloseBtnClick);
}

function closingModalStaff() {
document.removeEventListener('keydown', onEscClick);
backdrop.removeEventListener('click', onBackdropClick);
closeBtn.removeEventListener('click', onCloseBtnClick);

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

link.addEventListener('click', onLinkClick);
}

setupModal(
'.footer__link',
'.team__backdrop',
'.team__modal-close-btn',
'.team__wrapper'
);

setupModal(
'.footer__text--privacy',
'.privacy__backdrop',
'.privacy__modal-close-btn',
'.privacy__wrapper'
);

setupModal(
'.footer__text--terms',
'.terms__backdrop',
'.terms__modal-close-btn',
'.terms__wrapper'
);
53 changes: 0 additions & 53 deletions src/js/privacy-policy.js

This file was deleted.

53 changes: 0 additions & 53 deletions src/js/terms-of-service.js

This file was deleted.

4 changes: 1 addition & 3 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import './js/mobile-menu';
import './js/mobile-icon-open';
import './js/form';
import './js/modal-team';
import './js/modal-windows';
import './js/smooth-scroll';
import './js/scroll-top';
import './js/privacy-policy';
import './js/terms-of-service';

0 comments on commit 7cf22ba

Please sign in to comment.