3901*/3902function t_zeroForms__addResource(options) {3903const { id, path, type, recId, onError } = options || {};39043905const addedElement = document.getElementById(id);3906if (addedElement) {3907if (onError && addedElement.getAttribute('data-load-error') === 'true') {3908onError();3909} else if (onError) {3910addedElement.addEventListener('error', onError);3911}3912
return; } t_zeroForms__isInWhiteList(path); const allRecords = document.getElementById('allrecords'); const isExport = allRecords && allRecords.getAttribute('data-tilda-export') === 'yes'; const zeroFormScript = document.querySelector('script[src*="tilda-zero-forms"]'); const scriptSrc = zeroFormScript ? zeroFormScript.src : ''; let location = 'https://static.tildacdn.' + t_zeroForms__getRootZone(); if (!isExport && scriptSrc && scriptSrc.indexOf('https://') !== -1) { location = scriptSrc.split('/js/')[0]; } const element = document.createElement(type); element.id = id; if (type === 'script') { element.src = location + '/js/' + path; element.async = true; } else if (type === 'link') { element.href = location + '/css/' + path; element.rel = 'stylesheet'; } element.addEventListener('error', () => { t_zeroForms__onFuncLoad('t_fallback__reloadSRC', function () { t_fallback__reloadSRC(element); }); element.setAttribute('data-loaded', 'true'); element.setAttribute('data-load-error', 'true'); }); if (onError) element.addEventListener('error', onError); element.addEventListener('load', () => { element.setAttribute('data-loaded', 'true'); }); t_zeroForms__addResourceToQueue(recId, element); document.head.insertAdjacentElement('beforeend', element);}/** * Добавляет inline HTML элемент с переданным контентом. Используется для добавляения на страницу inline скрипта или стиля. * @param {{ id: string, content: string, zeroForm: HTMLElement | null, tag: 'script' | 'style' }} options */function t_zeroForms__addInlineTag(options) { const { id, content, zeroForm, tag } = options || {}; if (document.getElementById(id)) return; if (!content) return; const element = document.createElement(tag); element.id = id; element.textContent = content; const appendParent = zeroForm ? zeroForm.querySelector('.tn-atom') : document.head; appendParent.insertAdjacentElement('beforeend', element);}/** * Проверяет, был ли добавлен указанный файл в зависимости zero-form для экспорта страницы. * При добавлении нового скрипта или стиля необходимо добавить его упоминание в tpl_zero_form_export.tpl, чтобы он подключался на экспортированных сайтах. * * Такой подход – ограничение, связанное с логикой работы сервиса для экспорта. Сервис экспорта проверяет только html и не выполняет скрипты. * Чтобы все файлы появлялись при экспорте, необходимо добавить их явное упоминание в html (tpl). * @param {string} path */function t_zeroForms__isInWhiteList(path) { if (!path || !t_zeroForms__isTeam()) return; const isAllowed = [ 'tilda-zero-form-errorbox.min.css', 'tilda-zero-form-horizontal.min.css', 'tilda-phone-mask-1.1.min.js', 'tilda-date-picker-1.0.min.css', 'tilda-date-picker-1.0.min.js', 'tilda-calc-1.0.min.js', 'tilda-upwidget-1.1.min.js', 'uploadcare-3.x.full.min.js', 'uploadcare-3.x.min.js', 'tilda-range-1.0.min.js', 'tilda-range-1.0.min.css', 'tilda-img-select-1.0.min.js', 'tilda-img-select-1.0.min.css', 'tilda-conditional-form-1.0.min.js', 'tilda-contact-method-1.0.min.js', 'tilda-ratescale-1.0.min.js',