201const rootZone = t_form_phonemask_getRootZone();202xhr.open('GET', `https://geo.tildaapi.${rootZone}/geo/country/`, true);203xhr.onreadystatechange = function () {204if (xhr.readyState === 4) {205if (xhr.status >= 200 && xhr.status < 400) {206iso = xhr.responseText;207window.geoCountry = iso;208209var geoCountryLoaded = document.createEvent('Event');210geoCountryLoaded.initEvent('geoCountryLoaded', true, false);211document.dispatchEvent(geoCountryLoaded);212
initHandler(recId, lid, iso); } else { // Если не удалось получить страну, то используем страну проекта или первую из списка стран в этом скрипте const countriesKeys = Object.keys(t_form_phonemask__getCountriesList()); const projectCountryIso = t_form_phonemask__getProjectCountryIso()?.toLowerCase(); let fallbackIso; if (projectCountryIso && countriesKeys.includes(projectCountryIso)) { fallbackIso = projectCountryIso; } else { fallbackIso = countriesKeys[0]; } initHandler(recId, lid, fallbackIso); } } }; xhr.send(); window.geoCountryRequested = true; } else { document.addEventListener('geoCountryLoaded', function () { initHandler(recId, lid, window.geoCountry); }); }}/** * Возвращает ISO код страны проекта пользователя * @returns {string} */function t_form_phonemask__getProjectCountryIso() { const allrecords = document.getElementById('allrecords'); if (!allrecords) return ''; return allrecords.getAttribute('data-tilda-project-country') || '';}/** * Finds elements, replaces fields, init styles, adds handlers * * @param {number | string} recId - rec id block * @param {number | string} lid - id field * @param {string} originalIso - str country */function t_form_phonemask_initPhoneMaskForm(recId, lid, originalIso) { var rec = t_form_phonemask__getRec(recId); if (!rec) return; var inputGroup = t_form_phonemask__getInputGroup(rec, lid); if (!inputGroup) return; if (inputGroup.getAttribute('data-init-mask')) return; if (!document.getElementById('phone-mask-style')) { t_form_phonemask__addStyle(); } const countryConfig = t_form_phonemask__prepareISOandCountry(originalIso); t_form_phonemask__saveISOtoLocalStorage(countryConfig.iso); t_form_phonemask__prepareInputGroup({ rec, group: inputGroup, countryConfig, lid }); t_form_phonemask__triggerInitMask(inputGroup); t_form_phonemask__initResetListener(inputGroup, countryConfig);}/** * Finds elements, replaces fields, init styles, adds handlers * * @param {number | string} recId - rec id block * @param {number | string} lid - id field * @param {string} originalISO - str country */function t_form_phonemask__multiple__initPhoneMaskForm(recId, lid, originalISO = '') { var rec = t_form_phonemask__getRec(recId); if (!rec) return; var inputGroup = t_form_phonemask__getInputGroup(rec, lid); if (!inputGroup) return; if (inputGroup.getAttribute('data-init-mask')) return; if (!document.getElementById('phone-mask-style')) { t_form_phonemask__addStyle(); } const countryConfig = t_form_phonemask__prepareISOandCountry(originalISO); t_form_phonemask__saveISOtoLocalStorage(countryConfig.iso); const phoneMaskGroups = inputGroup.querySelectorAll('.t-phonemask-input-group');