Files
smartsoltech_site/smartsoltech/static/assets/js/modal-init.js

79 lines
3.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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();
}
});
});