
Element.prototype.matches || (Element.prototype.matches = Element.prototype.matchesSelector || Element.prototype.webkitMatchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.msMatchesSelector), Element.prototype.closest || (Element.prototype.closest = function (e) { for (var t = this; t;) { if (t.matches(e)) return t; t = t.parentElement } return null });
var ct_get_val = function (form, selector) { if (!!form.querySelector(selector)) { return form.querySelector(selector).value; } else { return ''; } }
var calltouch_sender = function (form, is_zero_block) {
console.log(form);
var fio = ct_get_val(form, 'input[data-tilda-rule="name"]'); if (!fio) { fio = ct_get_val(form, 'input[name="name"],input[name="Name"]'); }
var phone = ct_get_val(form, 'input[data-tilda-rule="phone"]'); if (!phone) { phone = ct_get_val(form, 'input[name="phone"],input[name="Phone"]'); }
var email = ct_get_val(form, 'input[data-tilda-rule="email"]'); if (!email) { email = ct_get_val(form, 'input[name="email"],input[name="Email"]'); }
var sub = 'Заявка с ' + location.hostname;
var ct_data = {
fio: fio,
phoneNumber: phone,
email: email,
subject: sub,
requestUrl: location.href,
sessionId: window.ct('calltracking_params','tbx4j410').sessionId
};
var post_data = Object.keys(ct_data).reduce(function (a, k) { if (!!ct_data[k]) { a.push(k + '=' + encodeURIComponent(ct_data[k])); } return a }, []).join('&');
var ct_site_id = window.ct('calltracking_params','tbx4j410').siteId;
var ct_valid = !!phone || !!email;
console.log(ct_data, ct_valid);
if (ct_valid && !window.ct_snd_flag) {
window.ct_snd_flag = 1; setTimeout(function () { window.ct_snd_flag = 0; }, 20000);
calltouch_send_request(post_data, ct_site_id);
}
if (is_zero_block) { var su = form.getAttribute('data-success-url'); if (su) { console.log('ct_start_timeout'); setTimeout(function () { console.log('ct_end_timeout'); window.location.href = su; }, 1000); } }
}
var set_calltouch_listener = function (form, is_zero_block) {
form.addEventListener('tildaform:aftersuccess', function (e) { calltouch_sender(form, is_zero_block); });
if (!is_zero_block) {
var success_callback = form.getAttribute('data-success-callback'); var formsended_callback = form.getAttribute('data-formsended-callback');
if (!!success_callback) {
if (success_callback == 't702_onSuccess') { window.t702_onSuccess_def = success_callback; form.setAttribute('data-success-callback', 't702_onSuccess_ct_fix'); }
if (success_callback == 't396_onSuccess') { window.t396_onSuccess_def = success_callback; form.setAttribute('data-success-callback', 't396_onSuccess_ct_fix'); }
if (success_callback == 't678_onSuccess') { window.t678_onSuccess_def = success_callback; form.setAttribute('data-success-callback', 't678_onSuccess_ct_fix'); }
}
if (!!formsended_callback) {
if (formsended_callback == 't706_onSuccessCallback') { window.t706_onSuccessCallback_def = form.getAttribute('data-formsended-callback'); form.setAttribute('data-formsended-callback', 't706_onSuccessCallback_ct_fix'); }
}
}
}
var calltouch_send_request = function (post_data, ct_site_id) { var ct_url = 'https://api.calltouch.ru/calls-service/RestAPI/requests/' + ct_site_id + '/register/'; if (window.jQuery) { jQuery.ajax({ url: ct_url, dataType: 'json', type: 'POST', data: post_data, async: false }); } else { var request = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(); request.open('POST', ct_url, true); request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); request.send(post_data); } }
if (document.readyState !== 'loading') {
[].forEach.call(document.querySelectorAll('form'), function (el) { set_calltouch_listener(el, false); });
} else {
document.addEventListener('DOMContentLoaded', function () {
[].forEach.call(document.querySelectorAll('form'), function (el) { set_calltouch_listener(el, false); });
});
}
window.t396_onSuccess = function (form) { if (!form) return; if (!form.id) { calltouch_sender(form[0], true); } else { calltouch_sender(form, true); } }
window.t702_onSuccess_ct_fix = function (form) { console.log('ct_start_timeout'); setTimeout(function () { console.log('ct_end_timeout'); window[window.t702_onSuccess_def](form); }, 1000); }
window.t396_onSuccess_ct_fix = function (form) { console.log('ct_start_timeout'); setTimeout(function () { console.log('ct_end_timeout'); window[window.t396_onSuccess_def](form); }, 1000); }
window.t678_onSuccess_ct_fix = function (form) { console.log('ct_start_timeout'); setTimeout(function () { console.log('ct_end_timeout'); window[window.t678_onSuccess_def](form); }, 1000); }
window.t706_onSuccessCallback_ct_fix = function (form) { console.log('ct_start_timeout'); setTimeout(function () { console.log('ct_end_timeout'); window[window.t706_onSuccessCallback_def](form); }, 1000); }