Добавление 2 новых услуг стоматология и лазерная эпиляция

This commit is contained in:
adlevin
2026-06-08 15:38:34 +03:00
parent cbee56e488
commit d22b2d913c
4 changed files with 420 additions and 45 deletions

View File

@@ -433,85 +433,154 @@ function initServiceModal() {
const modalTitle = modal.querySelector('.modal-title');
const modalDescription = modal.querySelector('.modal-description');
const modalProcedures = document.getElementById('modal-procedures');
const modalSubservices = document.getElementById('modal-subservices');
const proceduresTitle = modal.querySelector('.procedures-title');
const modalNote = document.getElementById('modal-note');
const modalBackButton = document.getElementById('modal-back');
let scrollPosition = 0;
let currentServiceData = null;
let parentServiceData = null;
// Открытие модального окна
serviceCards.forEach(card => {
card.addEventListener('click', function() {
const serviceKey = card.getAttribute('data-service');
const serviceData = servicesData[serviceKey];
if (serviceData) {
// Сохраняем текущую позицию скролла
scrollPosition = window.pageYOffset || document.documentElement.scrollTop;
// Заполняем данные модального окна
modalIcon.className = serviceData.icon;
modalTitle.textContent = serviceData.title;
modalDescription.textContent = serviceData.description;
// Очищаем и заполняем список процедур
modalProcedures.innerHTML = '';
openServiceModal(serviceData, serviceKey);
}
});
});
function openServiceModal(serviceData, serviceKey) {
// Сохраняем позицию скролла только если модальное окно еще не открыто
if (!modal.classList.contains('active')) {
scrollPosition = window.pageYOffset || document.documentElement.scrollTop;
}
currentServiceData = serviceData;
// Если это основная услуга (не подуслуга) - сбрасываем parentServiceData
// Подуслуги имеют id типа "dentistry-therapeutic", основные - "dentistry", "laboratory" и т.д.
if (serviceKey === 'dentistry' || !serviceKey.includes('-') || serviceKey.split('-').length === 1) {
parentServiceData = null;
}
// Заполняем данные модального окна
modalIcon.className = serviceData.icon;
modalTitle.textContent = serviceData.title;
modalDescription.textContent = serviceData.description;
// Проверяем, это ли родительская услуга со подуслугами
if (serviceData.isParent && serviceData.subservices) {
proceduresTitle.style.display = 'none';
modalProcedures.style.display = 'none';
modalBackButton.style.display = 'none';
// Очищаем и заполняем подуслуги
modalSubservices.innerHTML = '';
serviceData.subservices.forEach(subservice => {
const subCard = document.createElement('div');
subCard.className = 'subservice-card';
subCard.innerHTML = `
<div class="subservice-icon">
<i class="${subservice.icon}"></i>
</div>
<h4 class="subservice-title">${subservice.title}</h4>
<p class="subservice-description">${subservice.description}</p>
`;
subCard.addEventListener('click', function(e) {
e.stopPropagation();
parentServiceData = serviceData;
openServiceModal(subservice, subservice.id);
});
modalSubservices.appendChild(subCard);
});
modalSubservices.style.display = 'grid';
} else {
proceduresTitle.style.display = 'block';
modalProcedures.style.display = 'block';
modalSubservices.style.display = 'none';
// Показываем кнопку "Назад" если есть родительская услуга со подуслугами
if (parentServiceData && parentServiceData.isParent) {
modalBackButton.style.display = 'flex';
} else {
modalBackButton.style.display = 'none';
}
// Очищаем и заполняем список процедур
modalProcedures.innerHTML = '';
if (serviceData.procedures) {
serviceData.procedures.forEach(procedure => {
const li = document.createElement('li');
li.textContent = procedure;
modalProcedures.appendChild(li);
});
// Обрабатываем примечание
if (serviceData.note) {
modalNote.innerHTML = serviceData.note;
modalNote.style.display = 'block';
} else {
modalNote.style.display = 'none';
}
// Блокируем скролл страницы
document.body.style.position = 'fixed';
document.body.style.top = `-${scrollPosition}px`;
document.body.style.width = '100%';
// Показываем модальное окно
modal.classList.add('active');
}
});
});
}
// Обрабатываем примечание
if (serviceData.note) {
modalNote.innerHTML = serviceData.note;
modalNote.style.display = 'block';
} else {
modalNote.style.display = 'none';
}
// Блокируем скролл страницы
document.body.style.position = 'fixed';
document.body.style.top = `-${scrollPosition}px`;
document.body.style.width = '100%';
// Показываем модальное окно
modal.classList.add('active');
}
// Закрытие модального окна
function closeModal() {
// Сначала плавно скрываем модальное окно
modal.classList.remove('active');
// Через короткую задержку восстанавливаем скролл без эффектов
setTimeout(() => {
const currentScrollPosition = scrollPosition;
document.body.style.position = '';
document.body.style.top = '';
document.body.style.width = '';
// Отключаем smooth scroll временно
document.documentElement.style.scrollBehavior = 'auto';
window.scrollTo(0, currentScrollPosition);
// Возвращаем smooth scroll обратно
setTimeout(() => {
document.documentElement.style.scrollBehavior = 'smooth';
}, 50);
}, 100);
}
modalClose.addEventListener('click', closeModal);
modalOverlay.addEventListener('click', closeModal);
// Кнопка "Назад" для возврата к подуслугам
modalBackButton.addEventListener('click', function(e) {
e.stopPropagation();
if (parentServiceData) {
openServiceModal(parentServiceData, 'parent');
}
});
// Закрытие по Escape
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && modal.classList.contains('active')) {
closeModal();
}
});
// Предотвращение скролла при касании модального окна на мобильных
modal.addEventListener('touchmove', function(e) {
if (e.target === modal || e.target === modalOverlay) {