(function(w, d, u, i, o, s, p) { if (d.getElementById(i)) return; w['MangoObject'] = o; w[o] = w[o] || function() {(w[o].q = w[o].q || []).push(arguments)}; w[o].u = u; w[o].t = 1 * new Date(); s = d.createElement('script'); s.async = 1; s.id = i; s.src = u; p = d.getElementsByTagName('script')[0]; p.parentNode.insertBefore(s, p); }(window, document, '//widgets.mango-office.ru/widgets/mango.js', 'mango-js', 'mgo')); /** * получает настройки для базовых кейсов использования * @param {number} _widgetId * @param {string} _domain * @param {{numberTextAr: [], selectorsAr: [], anchors: []}} _firstNumberParams - первичный номер * @param _numbersWithHash - дополнительный запрос за номерами с хешем */ mgo.baseCases = function baseCase(_widgetId, _domain, _firstNumberParams, _numbersWithHash) { function replaceAllAncorsByHref(href, bodyReplaceFlag, number, formattedNumber) { document.querySelectorAll(`[href="${href}"]`).forEach(_e => { if (bodyReplaceFlag) { _e.innerHTML = formattedNumber; } _e.setAttribute('href', 'tel:+' + number); }); } function getRegionByDomain(_domainsArRegionPairs, _defaultRegion) { const currentDomain = location.href.split('/')[2]; for (let [domainsAr, region] of _domainsArRegionPairs) { for (let domain of domainsAr) { if (domain === currentDomain) { return region; } } } return _defaultRegion; } const calltracking = { id: _widgetId, domain: _domain } _firstNumberParams = Object.assign({numberTextAr: [], selectorsAr: [], anchors: []}, _firstNumberParams); const elements = []; for (let el of _firstNumberParams.numberTextAr) { elements.push({numberText: el}); } for (let el of _firstNumberParams.selectorsAr) { elements.push({selector: el}) } if (elements.length) { calltracking.elements = elements; } if (_firstNumberParams.anchors.length) { calltracking.onReady = function({number, formattedNumber}) { for (let {href, bodyReplaceFlag} of _firstNumberParams.anchors) { replaceAllAncorsByHref(href, bodyReplaceFlag, number, formattedNumber); } } } if (Array.isArray(_firstNumberParams.regionByDomain)) { let region = getRegionByDomain(_firstNumberParams.regionByDomain, undefined); if (region) { calltracking.region = region.replace(/^RU-/, ''); } } mgo({calltracking}); //--- for (let {hash, region, selectorsAr=[], anchors=[], numberTemplate, regionByDomain, redirectNumber} of _numbersWithHash || []) { mgo(_mgo => { const numberFormater = new Mango.CallTracking.NumberFormatter; if (Array.isArray(regionByDomain)) { region = getRegionByDomain(regionByDomain, region); } region = region ? region.replace(/^RU-/, '') : region; _mgo.getNumber({hash, region, redirectNumber}, ({number, formattedNumber}) => { if (numberTemplate) { formattedNumber = numberFormater.format(number, numberTemplate); } for (let el of selectorsAr) { document.querySelectorAll(el).forEach(_e => _e.innerHTML = formattedNumber); } for (let {href, bodyReplaceFlag} of anchors) { replaceAllAncorsByHref(href, bodyReplaceFlag, number, formattedNumber); } }); }); } } mgo.baseCases(33849, undefined, {"numberTextAr":["78003331313"]}, undefined);