Новые измнения в коде
This commit is contained in:
parent
beeec4740e
commit
4b9735118b
4 changed files with 251 additions and 21 deletions
|
|
@ -69,6 +69,7 @@ const title = 'Бесплатная консультация';
|
|||
modal.classList.add('active');
|
||||
modal.setAttribute('aria-hidden', 'false');
|
||||
document.body.style.overflow = 'hidden';
|
||||
startAutoCloseTimer();
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
|
|
@ -76,6 +77,24 @@ const title = 'Бесплатная консультация';
|
|||
modal.classList.remove('active');
|
||||
modal.setAttribute('aria-hidden', 'true');
|
||||
document.body.style.overflow = '';
|
||||
resetAutoCloseTimer();
|
||||
}
|
||||
|
||||
// Таймер для автозакрытия
|
||||
let autoCloseTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
function startAutoCloseTimer() {
|
||||
if (autoCloseTimer) clearTimeout(autoCloseTimer);
|
||||
autoCloseTimer = setTimeout(() => {
|
||||
closeModal();
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
function resetAutoCloseTimer() {
|
||||
if (autoCloseTimer) {
|
||||
clearTimeout(autoCloseTimer);
|
||||
autoCloseTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
// Открытие по кастомному событию
|
||||
|
|
@ -119,7 +138,7 @@ const title = 'Бесплатная консультация';
|
|||
const phone = formData.get('phone');
|
||||
|
||||
if (!name || !phone) {
|
||||
alert('Пожалуйста, заполните имя и телефон');
|
||||
(window as any).toast?.show('Пожалуйста, заполните имя и телефон', 'error', 3000);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -133,18 +152,22 @@ const title = 'Бесплатная консультация';
|
|||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
alert('Спасибо! Мы свяжемся с вами в течение 15 минут.');
|
||||
(window as any).toast?.show('Спасибо! Мы свяжемся с вами в течение 15 минут.', 'success', 4000);
|
||||
form.reset();
|
||||
closeModal();
|
||||
} else {
|
||||
alert('Ошибка: ' + result.error);
|
||||
(window as any).toast?.show(result.error || 'Ошибка отправки', 'error', 4000);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
alert('Ошибка отправки. Попробуйте позже.');
|
||||
(window as any).toast?.show('Ошибка отправки. Попробуйте позже.', 'error', 4000);
|
||||
}
|
||||
});
|
||||
|
||||
// Сброс таймера при активности пользователя
|
||||
modal?.addEventListener('mousemove', resetAutoCloseTimer);
|
||||
modal?.addEventListener('click', resetAutoCloseTimer);
|
||||
|
||||
// Для Astro View Transitions
|
||||
document.addEventListener('astro:page-load', () => {
|
||||
// Переинициализация при навигации
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue