style: add some style 5 (modal form 2)
This commit is contained in:
51
index.html
51
index.html
@@ -820,27 +820,62 @@
|
||||
</style>
|
||||
|
||||
<script>
|
||||
// Открытие модального окна
|
||||
document.querySelectorAll('[href="#booking"], .btn[href="#booking"]').forEach(btn => {
|
||||
// === МОДАЛЬНОЕ ОКНО + ОТПРАВКА ===
|
||||
const popup = document.getElementById('booking-popup');
|
||||
const form = document.getElementById('popup-booking-form');
|
||||
|
||||
if (popup && form) {
|
||||
// Открытие окна
|
||||
document.querySelectorAll('a[href="#booking"], .btn[href="#booking"]').forEach(btn => {
|
||||
btn.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
document.getElementById('booking-popup').classList.add('modal--active');
|
||||
popup.classList.add('modal--active');
|
||||
});
|
||||
});
|
||||
|
||||
// Закрытие
|
||||
document.querySelectorAll('[data-modal-close]').forEach(el => {
|
||||
el.addEventListener('click', () => {
|
||||
document.getElementById('booking-popup').classList.remove('modal--active');
|
||||
popup.classList.remove('modal--active');
|
||||
});
|
||||
});
|
||||
|
||||
// Закрытие по Esc
|
||||
document.addEventListener('keydown', e => {
|
||||
if (e.key === "Escape") {
|
||||
document.getElementById('booking-popup').classList.remove('modal--active');
|
||||
// Отправка формы
|
||||
form.addEventListener('submit', async function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const submitBtn = form.querySelector('button[type="submit"]');
|
||||
const originalText = submitBtn.textContent;
|
||||
|
||||
submitBtn.textContent = 'Отправляем...';
|
||||
submitBtn.disabled = true;
|
||||
|
||||
const formData = new FormData(form);
|
||||
|
||||
try {
|
||||
const response = await fetch('send-form.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.status === "success") {
|
||||
alert("✅ Заявка успешно отправлена!\nМы свяжемся с вами в ближайшее время.");
|
||||
form.reset();
|
||||
popup.classList.remove('modal--active');
|
||||
} else {
|
||||
alert("❌ " + (result.message || "Ошибка при отправке. Попробуйте позже."));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
alert("❌ Ошибка соединения. Проверьте интернет и попробуйте снова.");
|
||||
}
|
||||
|
||||
submitBtn.textContent = originalText;
|
||||
submitBtn.disabled = false;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user