3801* @param {{ successUrl?: string, successCallback?: string }} options3802*/3803function t_forms__handleSuccess(form, options) {3804const { successUrl, successCallback = '' } = options || {};3805/**3806* eval() is needed to execute a user function. The jQuery check is left3807* for compatibility with older users whose code can work with the jQuery object.3808* An example of a custom function: https://help-ru.tilda.cc/tips/javascript#rec1153350343809*/38103811let callback = (successCallback || '').replace('window.', '');
if (callback && typeof window[callback] === 'function') { if (typeof jQuery !== 'undefined') { // eslint-disable-next-line no-eval eval(callback + '(jQuery(form))'); } else { // eslint-disable-next-line no-eval eval(callback + '(form)'); } } else if (successUrl) { const successBox = form.querySelector('.t-form__successbox'); t_forms__handleRedirect(form, successUrl, successBox); }}function t_forms__getRootZone() { const allrecords = document.getElementById('allrecords'); const rootZone = allrecords && allrecords.getAttribute('data-tilda-root-zone'); return rootZone || 'com';}function t_forms__isTesterPage() { const allRecords = document.getElementById('allrecords'); const isOwnerATester = allRecords && allRecords.getAttribute('data-tilda-ts') === 'y'; return isOwnerATester;}function t_forms__isTeam() { const allRecords = document.getElementById('allrecords'); return allRecords && allRecords.getAttribute('data-tilda-te') === 'y';}function t_forms__isQuiz(form) { return form && form.closest('.t-quiz');}function t_forms__isIOS() { return /iPhone|iPad|iPod/i.test(navigator.userAgent) && !window.MSStream;}function t_forms__isNewSuccessBox(form) { if (!form) return false; if (t_forms__isQuiz(form)) return false; const blocksWithOldSuccessBox = ['t396', 't447', 't651', 't653', 't706', 't708', 't945', 't1122']; const isOldVersion = blocksWithOldSuccessBox.some(block => form.closest(`.${block}`)); return !isOldVersion;}/** * Удаляет дубликаты из массива DOM-элементов с использованием Map * @param {Element[]} nodes * @return {Element[]} */function t_forms__removeDuplicateElements(nodes) { const uniqueMap = new Map(); nodes.forEach(node => uniqueMap.set(node, true)); return Array.from(uniqueMap.keys());}/** * * @param {Element} form * @returns {{ status: 'valid' | 'invalid', data: string, contentType: string }} */function t_forms__getFormData(form) { const JSON_FORMAT = 'text/plain'; const URLENCODED_FORMAT = 'application/x-www-form-urlencoded; charset=UTF-8'; try { const USE_JSON = t_forms__shouldEnableFormAsJSON(); // TODO BL-1184: Оставить только формат JSON после проверки на работоспособность if (USE_JSON) { const formData = t_forms__getFormDataJSON(form); const hasPaymentAndProducts = window.tildaForm.tildapayment && window.tildaForm.tildapayment.products; const hasMemberInfo = window.tildaForm.tildamember && Object.keys(window.tildaForm.tildamember).length > 0; if (!hasPaymentAndProducts && form.closest('.t706__orderform')) { return { status: 'invalid', data: '', contentType: '', }; }