(function ($) {
'use strict';
function login_dropdown() {
$('.site-header-account').on('mouseenter', function () {
$('.account-dropdown', this).append($('.account-wrap'));
});
// var $account_side = $('.site-header-account a');
// var $account_active = $('.site-header-account .account-dropdown');
// $account_side.on('click', function (e) {
// e.preventDefault();
// e.stopPropagation();
// $account_active.toggleClass('active');
// });
}
function handleWindow() {
var body = document.querySelector('body');
if (window.innerWidth > body.clientWidth + 5) {
body.classList.add('has-scrollbar');
body.setAttribute('style', '--scroll-bar: ' + (window.innerWidth - body.clientWidth) + 'px');
} else {
body.classList.remove('has-scrollbar');
}
}
function minHeight() {
var $body = $('body'),
bodyHeight = $(window).outerHeight(),
headerHeight = $('header.header-1').outerHeight(),
footerHeight = $('footer.site-footer').outerHeight(),
$adminBar = $('#wpadminbar');
if ($adminBar.length > 0) {
headerHeight += $adminBar.height();
}
if ($body.find('header.header-1').length) {
$('.site-content').css({
'min-height': bodyHeight - headerHeight - footerHeight - 90
});
}
}
function setPositionLvN($item) {
var sub = $item.children('.sub-menu'),
offset = $item.offset(),
width = $item.outerWidth(),
screen_width = $(window).width(),
sub_width = sub.outerWidth();
var align_delta = offset.left + width + sub_width - screen_width;
if (align_delta > 0) {
if ($item.parents('.menu-item-has-children').length) {
sub.css({left: 'auto', right: '100%'});
} else {
sub.css({left: 'auto', right: '0'});
}
} else {
sub.css({left: '', right: ''});
}
}
function initSubmenuHover() {
$('.site-header .primary-navigation .menu-item-has-children').on('hover', function (event) {
var $item = $(event.currentTarget);
setPositionLvN($item);
});
}
function _makeStickyKit() {
var top_sticky = 20,
$adminBar = $('#wpadminbar'),
$secondary = $('#secondary');
if ($adminBar.length > 0) {
top_sticky += $adminBar.height();
}
if ($secondary.length > 0) {
if (window.innerWidth < 992) {
$('#secondary').trigger('sticky_kit:detach');
} else {
$('#secondary').stick_in_parent({
offset_top: top_sticky
});
}
}
}
$(window).on("scroll", function () {
if ($(this).scrollTop() > 200) {
$('.scrollup').fadeIn().addClass('activate');
} else {
$('.scrollup').fadeOut().removeClass('activate');
}
});
$('.scrollup').on('click', function () {
$("html, body").animate({scrollTop: 0}, 600);
return false;
});
_makeStickyKit();
initSubmenuHover();
minHeight();
handleWindow();
login_dropdown();
})(jQuery);