// // script.js // webpage-profy // // Created by Alexander Zahn on 05/02/2018. // Copyright (c) 2018 Alexander Zahn // http://zanstudio.ru // $(function () { 'use strict'; var user = { name : '', lastname : '', phone : '', email : '', mess: '', }; var windowWidth = $(window).width(); var windowHeight = $(window).height(); window.addEventListener('resize', function () { windowWidth = $(window).width(); console.log("resize to " + windowWidth); if(windowHeight <= 1024) { $(".header__wrap-block--isSticky").unstick(); } else { $(".header__wrap-block--isSticky").sticky({topSpacing:0}); } if(!/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)) { portfolioListRefresh(); mainbannerRefresh(); } }); $('.project__content').css('minHeight',$('.project__content-adaptiveimage').height()); //Верхнее меню if(windowWidth > 768) { $(".header__wrap-block--isSticky").sticky({topSpacing:0}); } $('.scroll_to_top__button').fadeOut(); $(window).scroll(function () { if ($(this).scrollTop() > 800) { $('.scroll_to_top__button').fadeIn(); } else { $('.scroll_to_top__button').fadeOut(); } }); $('.scroll_to_top__button').click(function () { $('body,html').animate({ scrollTop: 0 }, 400); return false; }); //Главный баннер mainbannerInit(); //Портфолио $('.portfolio__list').each(function() { var items = $(this).data("items"); var id = $(this).attr('id'); portfolioListInit(items, id); }); $('.header__menu-button').click(function() { $('.menu').toggleClass('menu--active'); }); $('.menu__close').click(function() { menuToggle(); }); $('.popup__close').click(function() { popupClose(); }); $('.thx__close').click(function() { thxClose(); }); faqInit(); projectGalleryInit(); $('.news__otherlist-item').click(function() { var title = $(this).data('title'); var text = $(this).data('text'); var url = $(this).data('url'); var date = $(this).data('date'); $('.news__otherlist-item').each(function() { $(this).removeClass('news__otherlist-item--active'); }); $(this).addClass('news__otherlist-item--active'); newsChange(title,text, date, url); }); $('.js-popup-init').click(function() { var formname = $(this).data('title'); popupInit(formname); }); for(var i = 0; i <= $('.services__item').length; i++) { $('.services__item:nth-child('+i+') .services__item-num span').html('0'+i); } $('.js-separated-value').each(function() { var value = $(this).html(); var new_value = thousandSeparator(value); $(this).html(new_value); }); $('.popup__form').validate({ errorElement: "em", rules: { popup_name: { minlength: 1, required: true }, popup_phone: { minlength: 18, required: true } }, submitHandler: function(form) { user.name = $('#popup_name').val(); user.phone = $('#popup_phone').val(); var formname = $('#popup_formname').val(); console.log(user); grecaptcha.ready(function () { grecaptcha.execute('6Ld79LElAAAAAHw3lRYYatC8JP14zos9pKHcDGfq', { action: 'submit' }).then(function (token) { $.ajax({ type: "POST", url: '/local/php/contact.php', data: 'name=' + user.name + '&phone=' + user.phone + '&formname=' + formname + '&captcha=' + token, timeout: 30000 }) .done(function() { thx(); $('#popup_name').val(''); $('#popup_phone').val(''); $('#popup_formname').val(''); }); })}); } }); jQuery.validator.addMethod("emailExt", function(value, element, param) { return value.match(/^[a-zA-Z0-9_\.%\+\-]+@[a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,}$/); },'Введеный email некорректен'); $('#mess_form').validate({ errorElement: "em", rules: { mess_name: { minlength: 1, required: true }, mess_email: { required: true, //email: true, //emailExt: true // accept:"[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}" } }, submitHandler: function(form) { user.name = $('#mess_name').val(); user.email = $('#mess_email').val(); user.mess = $('#mess_text').val(); var formname = $('#mess_formname').val(); console.log(user); grecaptcha.ready(function () { grecaptcha.execute('6Ld79LElAAAAAHw3lRYYatC8JP14zos9pKHcDGfq', { action: 'submit' }).then(function (token) { $.ajax({ type: "POST", url: '/local/php/contact1.php', data: 'name=' + user.name + '&email=' + user.email + '&mess=' + user.mess + '&formname=' + formname + '&captcha=' + token, timeout: 30000 }) .done(function() { thx(); $('#mess_name').val(''); $('#mess_email').val(''); $('#mess_text').val(''); $('#mess_formname').val(''); }); }); }); } }); $('.article__cta-form').validate({ errorElement: "em", rules: { cta_name: { minlength: 1, required: true }, cta_phone: { minlength: 18, required: true }, cta_email: { email: true, required: true } }, submitHandler: function(form) { user.name = $('#cta_name').val(); user.phone = $('#cta_phone').val(); user.email = $('#cta_email').val(); var formname = $('#cta_formname').val(); console.log(user); grecaptcha.ready(function () { grecaptcha.execute('6Ld79LElAAAAAHw3lRYYatC8JP14zos9pKHcDGfq', { action: 'submit' }).then(function (token) { $.ajax({ type: "POST", url: '/local/php/contact.php', data: 'name=' + user.name + '&phone=' + user.phone + '&email=' + user.email + '&formname=' + formname + '&captcha=' + token, timeout: 30000 }) .done(function() { thx(); $('#cta_name').val(''); $('#cta_phone').val(''); $('#cta_email').val(''); }); })}); } }); $('.phone__input--masked').mask('+7 (000) 000-00-00'); }); function menuToggle() { 'use strict'; $('.menu').toggleClass('menu--active'); } function popupClose() { 'use strict'; $('.popup').removeClass('popup--active'); } function popupInit(formname) { 'use strict'; $('#popup_formname').val(formname); $('.popup').addClass('popup--active'); } function thx() { 'use strict'; $('.popup').removeClass('popup--active'); $('.thx').addClass('thx--active'); } function thxClose() { 'use strict'; $('.thx').removeClass('thx--active'); } function portfolioListInit(itemsInRow, portfolioID) { 'use strict'; $('#'+portfolioID).cubeportfolio({ layoutMode: 'multiple-grids', sortByDimension: true, mediaQueries: [{ width: 800, cols: itemsInRow, }, { width: 480, cols: 1, options: { caption: '', gapHorizontal: 20, gapVertical: 0, } }], defaultFilter: '*', animationType: 'quicksand', gapHorizontal: 20, gapVertical: 20, gridAdjustment: 'responsive', caption: 'zoom', displayType: 'sequentially', displayTypeSpeed: 100, // lightbox lightboxDelegate: '.cbp-lightbox', lightboxGallery: true, lightboxTitleSrc: 'data-title', lightboxCounter: '