1201closeBtnIcon.addEventListener('click', window.tildaForm.handleClosePopup);1202}12031204if (closeBtn) {1205closeBtn.addEventListener('click', window.tildaForm.handleClosePopup);1206}12071208if (!isRedirect) {1209body.addEventListener('keydown', handleKeydown);1210successPopup.addEventListener('click', handleOutsideClick);1211}1212
function handleKeydown(event) { if (event.key === 'Escape' || event.keyCode == 27) { window.tildaForm.handleClosePopup(); } } function handleOutsideClick(event) { if (event.target === successPopup) { window.tildaForm.handleClosePopup(); } }}/** * Success end form. The function call order is crucial. * First, we must handle success callbacks and then clear out the form data. * @param {Node} formNode - block form * @param {string} successUrl - link on successful submission * @param {string} successCallback - function on successful submission */window.tildaForm.successEnd = function (formNode, successUrl, successCallback) { const form = t_forms__getElement(formNode); t_addClass(form, 'js-send-form-success'); t_forms__updateAllSystemVariables(form); const popup = form.closest('.t-popup'); const isZeroPopup = form.closest('.t1093'); const isFormInPopup = t_forms__isNewSuccessBox(form) && popup && !isZeroPopup; const zeroWithSuccessPopup = form.getAttribute('data-success-popup') === 'y'; function callOnSuccess() { t_forms__handleSuccess(form, { successCallback, successUrl }); window.tildaForm.clearTCart(form); t_forms__clearFormInputs(form); t_forms__clearFormData(form); if (t_forms__isNewSuccessBox(form) || zeroWithSuccessPopup) { window.t_forms__clearForm(form); } } function showSuccessbox() { t_forms__showSuccessbox(form).finally(() => { callOnSuccess(); }); } if (isFormInPopup) { // вызываем сооющение успеха с небольшой задержкой, чтобы не было конфликта с закрытием попапа с формой const SUCCESS_POPUP_DELAY = 320; t_forms__processFormsInPopup(popup, form); setTimeout(showSuccessbox, SUCCESS_POPUP_DELAY); return; } showSuccessbox();};/* Clear data cart */window.tildaForm.clearTCart = function (formNode) { const form = t_forms__getElement(formNode); if (form.getAttribute('data-formcart') === 'y') { /* flag clear basket */ window.clearTCart = true; window.tcart = { amount: 0, currency: '', system: '', products: [], }; window.tcart.system = 'none'; if (typeof localStorage === 'object') { try { localStorage.removeItem('tcart'); } catch (error) { console.error('Your web browser does not support localStorage. Code status: ', error); } } try { delete window.tcart; window.tcart__loadLocalObj(); } catch (error) { /* */