$( function() { phoneMask('input[name="Feedback[phone]"]'); /** * Modal form submit code */ $(document) .on( 'beforeSubmit', '#calculate-form, #feedback-form', function(e) { var f = this; var form = $(this); var formData = form.serialize(); $.ajax( { url: form.attr("action"), type: form.attr("method"), data: formData, success: function(data) { f.reset(); $('#feedback-modal,#calculate-modal') .modal('hide'); form.data('yiiActiveForm').validated = false; $('#success-modal') .modal('show'); }, error: function() { $('#feedback-modal') .modal('hide'); } } ); } ) .on( 'submit', '#calculate-form, #feedback-form', function(e) { e.preventDefault(); } ); /** * Contact form submitting */ $(document) .on( 'beforeSubmit', '#contact-form', function(e) { var f = this; var form = $(this); var formData = form.serialize(); $.ajax( { url: form.attr("action"), type: form.attr("method"), data: formData, success: function(data) { f.reset(); form.replaceWith(data.alert) }, error: function() { } } ); } ) .on( 'submit', '#contact-form', function(e) { e.preventDefault(); } ); /** * Button UP code */ if ($('#back-to-top').length) { var scrollTrigger = 100, // px backToTop = function() { var scrollTop = $(window) .scrollTop(); if (scrollTop > scrollTrigger) { $('#back-to-top') .addClass('show'); } else { $('#back-to-top') .removeClass('show'); } }; backToTop(); $(window) .on( 'scroll', function() { backToTop(); } ); $('#back-to-top') .on( 'click', function(e) { e.preventDefault(); $('html,body') .animate( { scrollTop: 0 }, 700 ); } ); } $(".active a") .on( 'click', function(){ $("#back-to-top").click(); return false; } ); /* нужно для гугл аналитики */ $(".close, .modal.fade").on('click', function(){ // $("#feedback-form")['0'].reset(); $(".send-form").removeAttr("id") }); $(".press-consultation").on('click',function(){ // $("#feedback-form")['0'].reset(); $(".send-form").attr('id', 'consultation'); }); $(".press-specialist").on('click',function(){ // $("#feedback-form")['0'].reset(); $(".send-form").attr('id', 'specialist'); }); $(".press-calculate").on('click',function(){ // $("#feedback-form")['0'].reset(); $(".send-form").attr('id', 'calculate'); }); $(".press-order").on('click',function(){ // $("#feedback-form")['0'].reset(); $(".send-form").attr('id', 'order'); }); $(".press-call").on('click',function(){ // $("#feedback-form")['0'].reset(); $(".send-form").attr('id', 'call'); }); $(".press-callback").on('click',function(){ // $("#feedback-form")['0'].reset(); $(".send-form").attr('id', 'callback'); }); function phoneMask(maskCssSelector) { var phoneInput = maskCssSelector; if($('body').find(phoneInput).length>0){ $(phoneInput).mask('+38(000)000-00-00',{placeholder:'+38(000)000-00-00'}); $(phoneInput).focus(function () { if(($(this).val())== '') {$(this).val('+38(0')} }); $(phoneInput).focusout(function () { var phoneVal = $(this).val() //if(phoneVal == '+38(0' || phoneVal == '+38(' || phoneVal == '+38' || phoneVal == '+3' || phoneVal == '+') {$(this).val('')} if(phoneVal.length <17) {$(this).val('')} }); } } /** * Блокирую кнопку сабмита после нажатия на 5 сек */ $('button[type="Submit"]').on('click',function () { var $this = $(this); $this.attr('disabled', true); setTimeout(function() { $this.attr('disabled', false); }, 5000); }); } );