var callTrapRunTest = false; function callTrapInit(){ if(typeof(jQuery) == 'undefined'){ if(!callTrapRunTest){ callTrapRunTest = true; document.write(''); //document.write(''); } setTimeout('callTrapInit()', 50); } else { // Input mask !function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a("object"==typeof exports?require("jquery"):jQuery)}(function(a){var b,c=navigator.userAgent,d=/iphone/i.test(c),e=/chrome/i.test(c),f=/android/i.test(c);a.mask={definitions:{b:"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"},autoclear:!0,dataName:"rawMaskFn",placeholder:"_"},a.fn.extend({caret:function(a,b){var c;if(0!==this.length&&!this.is(":hidden"))return"number"==typeof a?(b="number"==typeof b?b:a,this.each(function(){this.setSelectionRange?this.setSelectionRange(a,b):this.createTextRange&&(c=this.createTextRange(),c.collapse(!0),c.moveEnd("character",b),c.moveStart("character",a),c.select())})):(this[0].setSelectionRange?(a=this[0].selectionStart,b=this[0].selectionEnd):document.selection&&document.selection.createRange&&(c=document.selection.createRange(),a=0-c.duplicate().moveStart("character",-1e5),b=a+c.text.length),{begin:a,end:b})},unmask:function(){return this.trigger("unmask")},mask:function(c,g){var h,i,j,k,l,m,n,o;if(!c&&this.length>0){h=a(this[0]);var p=h.data(a.mask.dataName);return p?p():void 0}return g=a.extend({autoclear:a.mask.autoclear,placeholder:a.mask.placeholder,completed:null},g),i=a.mask.definitions,j=[],k=n=c.length,l=null,a.each(c.split(""),function(a,b){"?"==b?(n--,k=a):i[b]?(j.push(new RegExp(i[b])),null===l&&(l=j.length-1),k>a&&(m=j.length-1)):j.push(null)}),this.trigger("unmask").each(function(){function h(){if(g.completed){for(var a=l;m>=a;a++)if(j[a]&&C[a]===p(a))return;g.completed.call(B)}}function p(a){return g.placeholder.charAt(a=0&&!j[a];);return a}function s(a,b){var c,d;if(!(0>a)){for(c=a,d=q(b);n>c;c++)if(j[c]){if(!(n>d&&j[c].test(C[d])))break;C[c]=C[d],C[d]=p(d),d=q(d)}z(),B.caret(Math.max(l,a))}}function t(a){var b,c,d,e;for(b=a,c=p(a);n>b;b++)if(j[b]){if(d=q(b),e=C[b],C[b]=c,!(n>d&&j[d].test(e)))break;c=e}}function u(){var a=B.val(),b=B.caret();if(a.length0&&!j[b.begin-1];)b.begin--;if(0===b.begin)for(;b.beging)&&g&&13!==g){if(i.end-i.begin!==0&&(y(i.begin,i.end),s(i.begin,i.end-1)),c=q(i.begin-1),n>c&&(d=String.fromCharCode(g),j[c].test(d))){if(t(c),C[c]=d,z(),e=q(c),f){var k=function(){a.proxy(a.fn.caret,B,e)()};setTimeout(k,0)}else B.caret(e);i.begin<=m&&h()}b.preventDefault()}}}function y(a,b){var c;for(c=a;b>c&&n>c;c++)j[c]&&(C[c]=p(c))}function z(){B.val(C.join(""))}function A(a){var b,c,d,e=B.val(),f=-1;for(b=0,d=0;n>b;b++)if(j[b]){for(C[b]=p(b);d++e.length){y(b+1,n);break}}else C[b]===e.charAt(d)&&d++,k>b&&(f=b);return a?z():k>f+1?g.autoclear||C.join("")===D?(B.val()&&B.val(""),y(0,n)):z():(z(),B.val(B.val().substring(0,f+1))),k?b:l}var B=a(this),C=a.map(c.split(""),function(a,b){return"?"!=a?i[a]?p(b):a:void 0}),D=C.join(""),E=B.val();B.data(a.mask.dataName,function(){return a.map(C,function(a,b){return j[b]&&a!=p(b)?a:null}).join("")}),B.one("unmask",function(){B.off(".mask").removeData(a.mask.dataName)}).on("focus.mask",function(){if(!B.prop("readonly")){clearTimeout(b);var a;E=B.val(),a=A(),b=setTimeout(function(){z(),a==c.replace("?","").length?B.caret(0,a):B.caret(a)},10)}}).on("blur.mask",v).on("keydown.mask",w).on("keypress.mask",x).on("input.mask paste.mask",function(){B.prop("readonly")||setTimeout(function(){var a=A(!0);B.caret(a),h()},0)}),e&&f&&B.off("input.mask").on("input.mask",u),A()})}})}); var calltrap_overlay = '#calltrap-overlay'; var calltrap_btn = '#calltrap-btn'; var calltrap_form = '#calltrap-form'; var calltrap_close = '#calltrap-close'; var calltrap_success = '#calltrap-success'; $ = jQuery; $(document).ready(function(){ jQuery.support.cors = true; $.ajax({ url: '//kved.in.ua/trap/calltrap.php?trap=get_form&form_id=1', method: 'get', dataType: 'json', crossDomain: true, success: function(data){ if(data.html){ $('body').append(data.html); $('#calltrap-form input[name="client_phone"]').mask('+38 (bbb) bbb-bb-bb',{placeholder:"_"}); } } }); }); $(document).on('click', calltrap_btn, function(){ $(calltrap_form).show(); $(calltrap_success).hide(); $(calltrap_overlay).fadeIn(500, function(){ $('input[type="text"]', calltrap_form).eq(0).val('+').focus(); $(calltrap_btn).hide(); }); return false; }); $(document).on('click', calltrap_close, function(){ $(calltrap_overlay).fadeOut(500, function(){ $(calltrap_btn).fadeIn(500); }); return false; }); $(document).on('submit', calltrap_form, function(){ $form = $(this); data = $form.serializeArray($form); data.push({name: 'location', value: window.location.href}); $.ajax({ url: '//kved.in.ua/trap/calltrap.php?trap=get_request&form_id=1', method: 'post', dataType: 'json', data: data, crossDomain: true, beforeSend: function(){ $('input, button, textarea', $form).prop('disabled', true); }, success: function(response){ if(response.error){ $input = $('input', $form).eq(0); calltrap_phone = response.phone || null; $input.val(response.error).toggleClass('error'); setTimeout(function(){ $input.val(calltrap_phone).toggleClass('error').focus(); }, 1000); } else { $(calltrap_form).hide(); $(calltrap_success).show(); $form[0].reset(); } }, complete: function(){ $('input, button, textarea', $form).prop('disabled', false); } }); return false; }); } } callTrapInit();