File: /var/www/html/wp-content/themes/polygant_2023/inc/js/common.js
(function ($) {
var target, //current clicked item
langTraget, //btn to open the language list
langsBox, //dropdown list of languages
phones, //phone elements
maxPhoneWidth, //largest width
mqXS, mqHS, mqSM, mqMD, mqLG, mqPortrait, mqLandscape, //media query vars
toggleBtn, //mobile toggle button
hiddenBox, //mobile menu hidden box
mobileMnu, //general wrap for mobile header menu
itemsWrapId, //interval id
toggleShowPages, showPages,
ajaxRequest;
mqXS = window.matchMedia("(max-width: 479px)");
mqHS = window.matchMedia("(min-width: 480px) and (max-width: 767px)");
mqSM = window.matchMedia("(min-width: 768px) and (max-width: 991px)");
mqMD = window.matchMedia("(min-width: 992px) and (max-width: 1199px)");
mqLG = window.matchMedia("(min-width: 1200px)");
mqPortrait = window.matchMedia("screen and (orientation:portrait)");
mqLandscape = window.matchMedia("screen and (orientation:landscape)");
langTraget = $("#langTarget");
langsBox = $("#langsBox");
phones = $(".phone");
toggleBtn = $("#toggleBtn");
hiddenBox = $("#hiddenBox");
mobileMnu = $("#mobileMnu");
toggleShowPages = $("#toggleShowPages");
showPages = $("#showPages");
ajaxRequest = $(".ajaxRequest");
/**
* Ajax
*/
/**
* Show/hide sidebar
*/
toggleShowPages.on("click", function (event) {
event.preventDefault();
var th = $(this);
th.toggleClass("is_on");
showPages.stop(true, true).fadeToggle();
$(document).on("click", function (event) {
target = $(event.target);
if (!target.closest("#toggleShowPages").length && !target.closest("#showPages").length) {
th.removeClass("is_on");
showPages.stop(true, true).fadeOut();
}
});
});
/**
* Success popup
*/
function simplePopup(element, closeBtn, contentArea, timeOut) {
var el, elClose, elContent, timeOutNeed;
el = $(element);
elClose = $(closeBtn);
elContent = contentArea ? $(contentArea) : false;
timeOutNeed = timeOut ? timeOut : false;
el.stop(true, true).fadeIn();
elClose.on("click", function (event) {
event.preventDefault();
el.stop(true, true).fadeOut();
$("body").removeClass("is_popupForm");
});
if (timeOutNeed) {
setTimeout(function () {
el.stop(true, true).fadeOut();
$("body").removeClass("is_popupForm");
}, 3000);
}
}
/**
* Form popup
*/
$(".formPopup").on("click", function (event) {
event.preventDefault();
simplePopup("#simplePopupForm", "#simplePopupFormClose", "#contentArea");
$("body").addClass("is_popupForm");
});
$(".devHire-link").on("click", function (event) {
event.preventDefault();
$('.popDev__title').html($('h1.entry-title').html());
$('input[name=dev_name]').val($(this).closest('.developer').find('.devTitle').html());
simplePopup("#simplePopupForm_dev", "#simplePopupFormClose_dev", "#contentArea_dev");
$("body").addClass("is_popupForm");
});
/**
* Lang show/hide
*/
langTraget.on("click", function (event) {
event.preventDefault();
langsBox.stop(true, true).slideToggle();
});
/**
* Request call show/hide popup
*/
$.fn.customPopup = function (popup) {
if (popup) {
var th, thId;
th = $(this);
thId = $(this).attr("id");
th.on("click", function (event) {
event.preventDefault();
th.toggleClass("is_on");
$(popup).stop(true, true).fadeToggle();
});
$(document).on("click", function (event) {
var target = $(event.target);
if (target.attr("id") == thId || target.closest(popup).length) {
return;
} else {
$(popup).stop(true, true).fadeOut();
th.removeClass("is_on");
}
});
}
};
/**
* Init plugin customPopup for request call in header
*/
$("#requestCallBtn").customPopup("#requestCallPopup");
/**
* Mobile popup
* Init plugin customPopup for request call in header
*/
$("#requestCallBtnMobile").customPopup("#requestCallPopupMobile");
/**
* Toggle mobile menu
*/
toggleBtn.on("click", function (event) {
event.preventDefault();
$(this).toggleClass("is_on");
mobileMnu.toggleClass("is_on");
hiddenBox.stop(true, true).fadeToggle();
});
/**
* Area: page sidebar
* Action: sticky sidebar
*/
function stickySideBar() {
var init,
elOffTop, elHeight,
content, contentOffTop, contentHeight,
menu, menuHeight,
perfectPaddingTop, scrollTop;
elOffTop = showPages.length ? showPages.offset().top : false;
elHeight = showPages.length ? showPages.outerHeight() : false;
content = $(".theContent");
contentOffTop = content.length ? content.offset().top : false;
contentHeight = content.length ? content.outerHeight() : false;
menu = $(".headerScrolled");
menuHeight = menu.outerHeight();
perfectPaddingTop = 30; //px
scrollTop = $(window).scrollTop();
init = function () {
contentHeight = content.length ? content.outerHeight() : false;
if (mqLG.matches || mqMD.matches) {
if (menu.length && content.length) {
if (elHeight < contentHeight) {
if (scrollTop >= elOffTop && (scrollTop + elHeight) <= (contentOffTop + contentHeight)) {
showPages.css("transform", "translateY(" + (scrollTop - menuHeight - perfectPaddingTop) + "px)");
} else {
if (scrollTop < elOffTop) {
showPages.removeAttr("style");
}
if (scrollTop >= (contentOffTop + contentHeight - elHeight - menuHeight - perfectPaddingTop)) {
showPages.css("transform", "translateY(" + (contentOffTop + contentHeight - elHeight - menuHeight - perfectPaddingTop) + "px)");
}
}
}
}
}
};
$(window).scroll(function () {
scrollTop = $(this).scrollTop();
init();
});
$(window).resize(function () {
elOffTop = showPages.length ? showPages.offset().top : false;
elHeight = showPages.length ? showPages.outerHeight() : false;
contentOffTop = content.length ? content.offset().top : false;
contentHeight = content.length ? content.outerHeight() : false;
menuHeight = menu.outerHeight();
scrollTop = $(this).scrollTop();
init();
})
}
/**
* Area: all pages
* Action: scrolltop button
*/
window.onscroll = function () {
scrollFunction();
};
function scrollFunction() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
document.getElementById("scrollUpBtn").style.display = "block";
} else {
document.getElementById("scrollUpBtn").style.display = "none";
}
}
document.getElementById("scrollUpBtn").addEventListener("click", function () {
jQuery('html, body').animate({scrollTop: 0}, 1000);
}, false);
/**
* Area: phone number in header
* Action: set phone largest width
*/
function setLargestWidth() {
maxPhoneWidth = 0;
phones.each(function (i, e) {
var width;
width = $(this).width();
if (maxPhoneWidth < width) {
maxPhoneWidth = width;
}
});
//set all phones maxPhoneWidth
phones.css("width", maxPhoneWidth + 1 + "px");
}
/**
* First load media query
*/
if (mqMD.matches) {
//set phone largest width
setLargestWidth();
}
/**
* Resize
*/
$(window).resize(function () {
if (mqSM.matches) {
//fix media query at width phones
phones.removeAttr("style");
}
if (mqMD.matches) {
//set phone largest width
setLargestWidth();
//show sidebar
showPages.css("display", "");
}
if (mqLG.matches) {
//fix media query at width phones
phones.removeAttr("style");
//show sidebar
showPages.css("display", "");
}
});
/**
* Document click triks
*/
$(document).on("click", function (event) {
target = $(event.target);
if (!target.closest(".langSelect").length) {
langsBox.stop(true, true).slideUp();
}
if (!target.closest("#mobileMnu").length) {
toggleBtn.removeClass("is_on");
mobileMnu.removeClass("is_on");
hiddenBox.stop(true, true).fadeOut();
}
if (!target.closest("#contentArea").length && !target.closest(".formPopup").length && !target.closest("#contentArea_dev").length && !target.closest(".devHire-link").length) {
$("#simplePopupForm, #simplePopupForm_dev").stop(true, true).fadeOut();
$("body").removeClass("is_popupForm");
}
});
$(function () {
if ($(window).width() < 1200) {
$('.header-menu > ul > li > a').click(function (e) {
if ($(this).hasClass('blog') == false) {
e.preventDefault();
}
if ($(this).parent().hasClass('active') == true) {
$('.header-menu > ul > li').removeClass('active');
return;
}
$('.header-menu > ul > li').removeClass('active');
$(this).parent().addClass('active');
})
}
var owl = $('.owl-carousel.devSlider'),
owlOptions = {
loop: true,
dots: true,
nav: false,
responsive: {
0: {
items: 1
}
}
};
if ($(window).width() < 767) {
var owlActive = owl.owlCarousel(owlOptions);
} else {
owl.addClass('off');
}
$(window).resize(function () {
if ($(window).width() < 767) {
if ($('.owl-carousel').hasClass('off')) {
var owlActive = owl.owlCarousel(owlOptions);
owl.removeClass('off');
}
} else {
if (!$('.owl-carousel').hasClass('off')) {
owl.addClass('off').trigger('destroy.owl.carousel');
owl.find('.owl-stage-outer').children(':eq(0)').unwrap();
}
}
});
});
})(jQuery);