/home/bdqbpbxa/demo-subdomains/uvitme.goodface.com.ua/wp-content/themes/uvitme/js/script.js
// Маска телефона
$('.phone-mask').inputmask('mask', {
'mask': '+389 99 999 9999',
showMaskOnHover: false
});
// Ввод только чисел
$('.num').bind("change keyup input click", function () {
if (this.value.match(/[^0-9]/g)) {
this.value = this.value.replace(/[^0-9]/g, '');
}
});
// Блокировка скроллинга Body
function blockBody() {
if ($('body').hasClass('no-scroll')) {
let scrollTop = $('body').attr('data-scroll');
$('body').removeClass('no-scroll');
$('body').attr('style', '');
$(document).scrollTop(scrollTop);
} else {
let scrollTop = $(document).scrollTop();
$('body').addClass('no-scroll');
$('body').css({
top: '-' + scrollTop + 'px'
});
$('body').attr('data-scroll', scrollTop);
}
}
// header hide
// var scrollPos = 0;
// $(window).on('load', function () {
// var scroll = $(this).scrollTop();
// $('.header').removeClass('hide');
// })
// $(window).scroll(function () {
// var scroll = $(this).scrollTop();
// if (scrollPos < scroll) {
// $('.header').addClass('hide');
// } else {
// $('.header').removeClass('hide');
// }
// scrollPos = scroll;
// });
// main block header animation
$(window).on('load', function () {
$('.main-section__header').each(function () {
var maxWordsBoxWidth = Math.ceil(Math.max.apply(Math, $(this).find('.change-words div').map(function () {
return $(this).width();
}).get()));
$(this).find('.change-words').attr('style', 'width: ' + maxWordsBoxWidth + 'px;');
setInterval(() => {
var getEl = $(this).find('.change-words div');
var activeEl = $(this).find('.change-words div.active')
var activeElIndex = activeEl.index();
activeEl.removeClass('active').addClass('top').clone().appendTo($(this).find('.change-words'));
getEl.eq(activeElIndex + 1).addClass('active');
setTimeout(() => {
$(this).find('.change-words div').removeClass('top');
$(this).find('.change-words div').first().remove();
}, 700)
}, 3000)
})
});
// header anchor
$(document).ready(function () {
$('.header__nav').on("click", "a", function (event) {
event.preventDefault();
var id = $(this).attr('href');
var top = $(id).offset().top - 100;
$('body,html').animate({
scrollTop: top
}, 1500);
});
});
// header fill
$(window).scroll(function () {
var scroll = $(this).scrollTop();
if (scroll > 0) {
$('.header').addClass('fill');
} else {
$('.header').removeClass('fill');
}
});
// validation
// $('input[type="submit"]').on('click', function (e) {
// e.preventDefault();
// $(this).closest('form').find('.input-box input').each(function () {
// if (this.value.trim().length < 1 || $(this).val().trim().split('').includes('_')) {
// $(this).addClass('wpcf7-not-valid');
// }
// });
// if ($(this).closest('form').find('.input-box textarea').length) {
// $(this).closest('form').find('.input-box textarea').each(function () {
// if (this.value.length < 1) {
// $(this).addClass('wpcf7-not-valid');
// }
// });
// }
// });
$('.input-box input').on('input', function () {
$(this).removeClass('wpcf7-not-valid');
});
$('.input-box textarea').on('input', function () {
$(this).removeClass('wpcf7-not-valid');
});
$('.checkbox label').on('click', function () {
var inputSubmit = $(this).closest('form').find('input[type="submit"]');
var inputBtnBox = $(this).closest('form').find('.input');
if (inputSubmit.is('[disabled]')) {
inputBtnBox.removeClass('disabled');
} else {
inputBtnBox.addClass('disabled');
}
});
// scroll for modal
var scrollWidth;
function getScrollBarWidth() {
let $divs = $('<div class="div1" style="width: 100vw; overflow-y: scroll;"><div class="div2" style="width: 100%;"></div></div>');
$('body').append($divs);
let width1 = $('.div1').width(),
width2 = $('.div2').width();
scrollWidth = width1 - width2;
$divs.remove();
}
getScrollBarWidth();
function bodyScroll() {
$('body').css('padding-right', scrollWidth + 'px');
$('.header').css('right', scrollWidth + 'px');
}
// pop-up
$('.open-pop-up').on('click', function () {
$('.pop-up-container').addClass('active').find('.js-form-wrapper').attr('data-triggered', $(this).data('event') + '_' + $(this).data('label'));
bodyScroll($('.pop-up-container'));
blockBody();
});
$(document).on('wpcf7mailsent', function (e) {
// if (($(this).closest('form').find('input').hasClass('wpcf7-not-valid')) || ($(this).closest('form').find('textarea').hasClass('wpcf7-not-valid'))) {
// return;
// }
if ($('.pop-up-wrapper.active').length) {
$('.pop-up-wrapper.active').removeClass('active');
$('.pop-up-thanks').addClass('active');
} else {
$('.pop-up-thanks').addClass('active');
blockBody();
}
/**
* GTM/GA events
*/
var ev = $(e.detail.apiResponse.into).closest('.js-form-wrapper').attr('data-triggered');
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'formSubmission_' + ev
});
bodyScroll($('.pop-up-thanks'));
});
$('.open-pop-up-question').on('click', function () {
$('.pop-up-container-question').addClass('active').find('.js-form-wrapper').attr('data-triggered', $(this).data('event') + '_' + $(this).data('label'));
bodyScroll($('.pop-up-container-question'));
blockBody();
});
$('.pop-up-wrapper').on('click', function (e) {
if ($(e.target).closest('.pop-up-content').length == 0) {
$(this).find('.close-pop-up').click();
}
});
$('.close-pop-up').on('click', function () {
$(this).closest('.pop-up-wrapper').removeClass('active');
$('body').removeClass('scroll');
$('body').css('padding-right', 0 + 'px');
$('.header').css('right', 0 + 'px');
blockBody();
if ($(this).closest('.pop-up-video').length) {
$(this).closest('.pop-up-video').find('#video').get(0).pause();
}
})
// video pop-up
$('.open-video').on('click', function () {
blockBody();
bodyScroll($('.pop-up-video'));
$('.pop-up-video').addClass('active');
$('#video').get(0).play();
});
// video
var lastWindowWidth = 0;
function changeVideo() {
if (window.innerWidth == lastWindowWidth) return;
lastWindowWidth = window.innerWidth;
var mainVideo = $('#the-video');
var medQualVersionSrc = mainVideo.attr('data-video-mob');
var highQualVersionSrc = mainVideo.attr('data-video');
var activeVideoSRC = mainVideo.attr('src');
var newVideoSRC = false;
if (window.matchMedia('screen and (max-width: 812px)').matches) {
newVideoSRC = medQualVersionSrc;
} else {
newVideoSRC = highQualVersionSrc;
}
if (newVideoSRC != activeVideoSRC) {
mainVideo.attr('src', newVideoSRC);
}
}
changeVideo();
// approach section -- accordion
$('.approach-box__more-btn').on('click', function () {
var getHiddenText = $(this).closest('.approach-block__box').find('.approach-box__text');
var getHiddenTextBlockHeight = getHiddenText.find('p').height();
getHiddenText.addClass('active');
getHiddenText.css({
'height': getHiddenTextBlockHeight + 'px'
});
$(this).slideToggle(400);
});
// questions section -- accordion
var openAnswerAnimation = false;
$('.questions-box__question').on('click', function () {
if (!openAnswerAnimation) {
var getQuestionContainer = $(this).closest('.questions-section__box');
getQuestionContainer.toggleClass('active');
getQuestionContainer.find('.questions-box__answer').slideToggle(200);
openAnswerAnimation = true;
setTimeout(function () {
openAnswerAnimation = false;
}, 200)
}
});
// button "more questions"
if (!$('.questions-block__hidden-questions').length) {
$('.open-more-questions').remove();
}
$('.open-more-questions').on('click', function () {
$('.questions-block__hidden-questions').slideDown(700);
$(this).slideUp(400);
});
// Количество отзывов
$(window).ready(function() {
if (!$('.reviews-menu-item').length) {
return;
}
const reviewsSlideCount = $('.slider').find('.slide').length;
$('.reviews-menu-item').each(function() {
const html = $(this).append('<span></span>');
const span = $(this).find('span');
if (reviewsSlideCount > 10) {
span.html('10+')
} else {
span.html(reviewsSlideCount)
}
});
});
// slider
$(window).on('load', function () {
if (!$('.slider').length) {
return
}
var slideNumber = $('.slider').find('.slide').length;
if (slideNumber > 4) {
$('.slider__dots-number').html('+' + (slideNumber - 4))
} else if (slideNumber <= 4) {
$('.slider__dots-number').remove();
}
$('.slider').slick({
infinite: true,
arrows: true,
dots: false,
autoplay: true,
autoplaySpeed: 4500,
variableWidth: true,
pauseOnFocus: true,
pauseOnHover: true,
pauseOnDotsHover: false,
slidesToShow: 1,
slidesToScroll: 1,
cssEase: 'ease',
speed: 700,
draggable: true,
edgeFriction: 15,
touchThreshold: 125,
swipeToSlide: true,
swipe: true,
prevArrow: $('.prev-arrow'),
nextArrow: $('.next-arrow'),
asNavFor: '.dots-slider',
responsive: [
{
breakpoint: 750,
settings: {
arrows: false,
touchThreshold: 225
}
}
]
});
$('.dots-slider').slick({
infinite: true,
arrows: true,
dots: false,
autoplay: true,
autoplaySpeed: 4500,
variableWidth: true,
pauseOnFocus: true,
pauseOnHover: true,
pauseOnDotsHover: false,
slidesToShow: 1,
slidesToScroll: 1,
cssEase: 'ease',
speed: 700,
swipeToSlide: false,
swipe: false,
prevArrow: $('.prev-arrow'),
nextArrow: $('.next-arrow'),
asNavFor: '.slider',
zIndex: 1,
responsive: [
{
breakpoint: 750,
settings: {
arrows: false
}
}
]
});
$('.dots-slider').find('.slick-current').addClass('circle');
$('.dots-slider').on('beforeChange', function (event, slick, currentSlide, nextSlide) {
$(this).find('.slick-current').addClass('hide');
});
$('.dots-slider').on('afterChange', function (event, slick, currentSlide, nextSlide) {
$('.dots-slide').removeClass('circle hide');
$(this).find('.slick-current').addClass('circle');
});
})
// back to top btn
$('.btn-to-top').on('click', function (e) {
e.preventDefault();
$('html, body').animate({
scrollTop: '0px'
}, 1500);
});
// scroll animation
function animation(scrollTop) {
$('.animation').not('.animated').each(function () {
var offsetTop = $(this).offset().top;
var windowHeight = window.innerHeight;
if ((scrollTop + windowHeight) > offsetTop) {
$(this).addClass('animated');
}
});
}
// function hover
// function hover(ths, parent) {
// $(ths).closest(parent).find('.hover').addClass('on');
// $(ths).removeClass('on');
// }
// $('.hover').mouseenter(function () {
// if ($(this).closest('.header').length) {
// hover(this, '.header');
// } else if ($(this).closest('.footer').length) {
// hover(this, '.footer');
// }
// })
// $('.hover').mouseleave(function () {
// $('.hover').removeClass('on');
// })
// resize texarea
$('textarea').on('input', function (e) {
this.style.height = '1px';
this.style.height = (this.scrollHeight + 1) + 'px';
if ($(this).closest('.pop-up-wrapper').find('.pop-up').outerHeight(true) > $(window).height()) {
$('body').removeClass('scroll padding');
$('body').addClass('padding');
} else {
$('body').removeClass('scroll padding');
$('body').addClass('scroll');
}
});
// ios viewport
$(window).ready(function() {
let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
});
$(window).scroll(function () {
var scrollTop = $(this).scrollTop();
// Анимации подплываний
animation(scrollTop);
});
$(window).on('load', function () {
setTimeout(function () {
$('.pop-up-wrapper').removeClass('hide');
}, 400);
$(window).scroll();
});
// Change main video on resize
var changeVideoTimer = false;
$(window).on('resize', function () {
clearTimeout(changeVideoTimer);
changeVideoTimer = setTimeout(changeVideo, 100);
});
$('.anchor').on('click', function(event) {
event.preventDefault();
let anchor = $(this).attr('href');
$('html, body').animate({
scrollTop: $(anchor).offset().top - $('.header').outerHeight()
}, 500);
});
$('.expand').on('click', function() {
let $content = $(this).siblings('.content');
let $this = $(this);
$content.css('max-height', $content.attr('data-height') + 'px').attr('data-click', 1);
$content.removeClass('gradient-show').addClass('content-offset');
$this.addClass('expand-disappear');
});
$('.choices-nav').find('li').on('click', function() {
let currentChoice = $(this).attr('data-choice');
$(this).siblings().removeClass('current-choice');
$(this).addClass('current-choice');
$('.choices-content').find('li').removeClass('hidden');
$('.choices-content').find('li').filter('[class="'+ currentChoice +'"]').addClass('hidden');
});
$('.tabs-nav').find('li').on('click', function() {
let currentTab = $(this).attr('data-tab');
$(this).siblings().removeClass('current-tab');
$(this).addClass('current-tab');
$('.tabs-content').children().removeClass('current-content');
$('.tabs-content').children().filter('[data-content="'+ currentTab +'"]').addClass('current-content');
$('.tabs-content').css('height', $('.tabs-content').children().filter('[data-content="'+ currentTab +'"]').outerHeight(true) + 'px');
});
$(window).on('load', function() {
$('body').removeClass('loading');
$('.preloader').addClass('preloader-hide').delay(250).queue(function() {
$('.preloader').remove();
});
checkContentHeight();
});
function checkContentHeight() {
$('.fourth-section').find('.row').each(function() {
let totalHeight = 0;
let $this = $(this).find('.content');
$this.children().each(function() {
totalHeight += $(this).outerHeight(true);
});
$this.attr('data-height', totalHeight);
if (totalHeight > parseInt($this.css('max-height'))) {
$this.siblings('.expand').removeClass('expand-hide');
$this.addClass('gradient-show');
} else {
$this.siblings('.expand').addClass('expand-hide');
$this.removeClass('gradient-show');
}
});
}
$('.seventh-section .image img, .header__logo img').on('load', function() {
$(this).css({width: '50%'});
$(this).outerWidth();
$(this).attr('style', '');
});
/**
* GTM/GA Events
*/
$(document).on('click', '.js-gtm', function (e) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'click_' + $(this).data('event') + '_' + $(this).data('label')
});
});
$(window).on('load', function () {
if (window.innerWidth <= 750) {
const windowHeight = $(window).innerHeight();
$('section.main-section').attr('style', `max-height: ${windowHeight}px`);
}
});