Task_12281 (#1)

Co-authored-by: User A0264400 <a0264400@jarl.from.sh>
Reviewed-on: #1
Co-authored-by: Anton.AE <ab.an.ev@yandex.ru>
Co-committed-by: Anton.AE <ab.an.ev@yandex.ru>
This commit is contained in:
2026-07-05 16:07:04 +03:00
committed by Антон
parent 50f3a8e626
commit 3e42863ef5
2878 changed files with 59059 additions and 181273 deletions

View File

@@ -138,6 +138,55 @@ const mobileToggle = document.getElementById('mobileToggle')
})
}
const submitLeadForm = (formElement, successElement, formType, onSuccess) => {
if (!formElement || !successElement) {
return
}
formElement.addEventListener('submit', async event => {
event.preventDefault()
const leadFormConfig = window.test1LeadForm || null
if (!leadFormConfig?.ajaxUrl || !leadFormConfig?.action || !leadFormConfig?.nonce) {
window.alert('Форма временно недоступна. Обновите страницу и попробуйте снова.')
return
}
const formData = new window.FormData(formElement)
formData.append('action', leadFormConfig.action)
formData.append('nonce', leadFormConfig.nonce)
formData.append('form_type', formType)
formData.append('page_url', window.location.href)
try {
const response = await window.fetch(leadFormConfig.ajaxUrl, {
method: 'POST',
credentials: 'same-origin',
body: formData,
})
const payload = await response.json().catch(() => null)
if (!response.ok || !payload?.success) {
throw new Error('submit_failed')
}
successElement.classList.add('visible')
if (typeof onSuccess === 'function') {
onSuccess()
}
setTimeout(() => {
formElement.reset()
successElement.classList.remove('visible')
}, 2200)
} catch (error) {
window.alert('Не удалось отправить заявку. Попробуйте еще раз.')
}
})
}
mobileToggle.addEventListener('click', () => {
const isOpen = mobilePanel.classList.contains('active')
if (isOpen) {
@@ -272,26 +321,15 @@ const mobileToggle = document.getElementById('mobileToggle')
})
})
orderForm.addEventListener('submit', event => {
event.preventDefault()
orderSuccess.classList.add('visible')
submitLeadForm(orderForm, orderSuccess, 'landing_order', () => {
cart = []
renderCart()
setTimeout(() => {
closeModal()
orderForm.reset()
orderSuccess.classList.remove('visible')
}, 1800)
}, 700)
})
contactForm.addEventListener('submit', event => {
event.preventDefault()
contactSuccess.classList.add('visible')
setTimeout(() => {
contactForm.reset()
contactSuccess.classList.remove('visible')
}, 2200)
})
submitLeadForm(contactForm, contactSuccess, 'landing_contacts')
document.addEventListener('keydown', event => {
if (event.key !== 'Escape') {