79 lines
3.1 KiB
JavaScript
79 lines
3.1 KiB
JavaScript
document.addEventListener("DOMContentLoaded", function () {
|
||
// Функция для закрытия всех модальных окон
|
||
function closeAllModals() {
|
||
document.querySelectorAll('.modal').forEach(modal => {
|
||
modal.classList.remove('show');
|
||
modal.style.display = 'none';
|
||
});
|
||
document.body.classList.remove('modal-open');
|
||
document.body.style.overflow = '';
|
||
}
|
||
|
||
// Закрыть все модальные окна при загрузке страницы
|
||
closeAllModals();
|
||
|
||
// Работа с модальным окном заявки (Bootstrap modal)
|
||
var modalElement = document.getElementById('orderModal');
|
||
if (modalElement) {
|
||
var modal = new bootstrap.Modal(modalElement);
|
||
|
||
// Инициализация модального окна
|
||
modalElement.addEventListener('show.bs.modal', function () {
|
||
console.log("Модальное окно открыто");
|
||
});
|
||
|
||
modalElement.addEventListener('hide.bs.modal', function () {
|
||
console.log("Модальное окно закрыто");
|
||
});
|
||
}
|
||
|
||
// Открытие кастомного модального окна для заявки на услугу
|
||
const openModalBtn = document.getElementById('openModalBtn');
|
||
const serviceModal = document.getElementById('serviceModal');
|
||
const generateQrButton = document.getElementById('generateQrButton');
|
||
|
||
if (openModalBtn && serviceModal) {
|
||
openModalBtn.addEventListener('click', function (event) {
|
||
event.preventDefault();
|
||
const serviceId = openModalBtn.getAttribute('data-service-id');
|
||
console.log("Service ID при открытии модального окна:", serviceId);
|
||
|
||
if (!serviceId) {
|
||
alert("Идентификатор услуги не найден. Обновите страницу и попробуйте снова.");
|
||
return;
|
||
}
|
||
|
||
if (generateQrButton) {
|
||
generateQrButton.dataset.serviceId = serviceId;
|
||
}
|
||
|
||
serviceModal.classList.add('show');
|
||
serviceModal.style.display = 'block';
|
||
document.body.classList.add('modal-open');
|
||
document.body.style.overflow = 'hidden';
|
||
});
|
||
}
|
||
|
||
// Закрытие кастомного модального окна
|
||
const closeButtons = document.querySelectorAll('.close');
|
||
closeButtons.forEach(closeBtn => {
|
||
closeBtn.addEventListener('click', function () {
|
||
closeAllModals();
|
||
});
|
||
});
|
||
|
||
// Закрытие модального окна при клике вне его
|
||
window.addEventListener('click', function (event) {
|
||
if (event.target.classList.contains('modal') && event.target.classList.contains('show')) {
|
||
closeAllModals();
|
||
}
|
||
});
|
||
|
||
// Закрытие по нажатию Escape
|
||
document.addEventListener('keydown', function(event) {
|
||
if (event.key === 'Escape') {
|
||
closeAllModals();
|
||
}
|
||
});
|
||
});
|