File: /home/salamatk/takarzan.ir/wp-content/themes/xts-luman/js/scripts/menuOffsets.js
/* global xts_settings */
(function($) {
XTSThemeModule.xtsElementorAddAction('frontend/element_ready/xts_mega_menu.default', function() {
XTSThemeModule.menuOffsets();
XTSThemeModule.menuDropdownAside();
});
XTSThemeModule.menuOffsets = function() {
var setOffset = function(li) {
var $dropdown = li.find(' > .xts-dropdown-menu');
if ( $dropdown.parents().hasClass('xts-style-aside') ) {
return;
}
var dropdownWidth = $dropdown.outerWidth();
var dropdownOffset = $dropdown.offset();
var toRight;
var viewportWidth = XTSThemeModule.$window.width();
var dropdownOffsetRight;
var dropdownOffsetLeft;
var containerOffset;
var menu_animation_offset = parseInt(xts_settings.menu_animation_offset || 0);
$dropdown.attr('style', '');
if (!dropdownWidth || !dropdownOffset) {
return;
}
if ($dropdown.is('.xts-style-default, .xts-style-full, .xts-style-container, .xts-style-aside')) {
dropdownOffsetRight = viewportWidth - dropdownOffset.left - dropdownWidth;
if (XTSThemeModule.$body.hasClass('rtl')) {
if (dropdownOffsetRight + dropdownWidth + menu_animation_offset >= viewportWidth) {
toRight = dropdownOffsetRight + dropdownWidth - viewportWidth + menu_animation_offset;
$dropdown.css({
right: -toRight
});
} else if (dropdownOffset.left + dropdownWidth >= viewportWidth) {
toRight = dropdownOffset.left + dropdownWidth - viewportWidth + menu_animation_offset;
$dropdown.css({
left: -toRight
});
}
} else if (dropdownOffset.left + dropdownWidth + menu_animation_offset >= viewportWidth) {
toRight = dropdownOffset.left + dropdownWidth - viewportWidth + menu_animation_offset;
$dropdown.css({
left: -toRight
});
}
} else if ($dropdown.is('.xts-style-sized')) {
var extraSpace = 0;
var $stickyCat = $('.xts-sticky-cats');
if ( ! XTSThemeModule.$body.hasClass('xts-layout-boxed')) {
extraSpace = 15;
if (XTSThemeModule.$body.hasClass('xts-sticky-cats-enabled') && $stickyCat.length) {
extraSpace -= $stickyCat.width() / 2;
}
}
viewportWidth = xts_settings.site_width;
if (XTSThemeModule.$window.width() < viewportWidth || ! viewportWidth || $('.xts-header').hasClass('xts-full-width')) {
viewportWidth = XTSThemeModule.$window.width();
}
containerOffset = (XTSThemeModule.$window.width() - viewportWidth) / 2;
dropdownOffsetRight = viewportWidth - dropdownOffset.left - dropdownWidth;
if (XTSThemeModule.$body.hasClass('rtl')) {
dropdownOffsetLeft = containerOffset + dropdownOffsetRight + menu_animation_offset;
if (dropdownOffsetLeft + dropdownWidth >= viewportWidth) {
toRight = dropdownOffsetLeft + dropdownWidth - viewportWidth;
$dropdown.css({
right: -toRight - extraSpace
});
}
} else {
dropdownOffsetLeft = dropdownOffset.left - containerOffset + menu_animation_offset;
if (dropdownOffsetLeft + dropdownWidth >= viewportWidth) {
toRight = dropdownOffsetLeft + dropdownWidth - viewportWidth;
$dropdown.css({
left: -toRight - extraSpace
});
}
}
}
};
$('.xts-nav-main, .xts-nav-main > li, .xts-nav-secondary, .xts-nav-secondary > li, .xts-nav-mega.xts-direction-h, .xts-nav-mega.xts-direction-h > li').each(function() {
var $menu = $(this);
if ($('html').hasClass('platform-iOS') && $menu.hasClass('xts-event-hover') && $menu.hasClass('menu-item-has-children')) {
$menu.removeClass('xts-event-hover').addClass('xts-event-click');
}
if ($menu.hasClass('menu-item')) {
$menu = $(this).parent();
}
$menu.on('mouseenter mousemove', function() {
if ($menu.hasClass('xts-offsets-calculated') || $menu.parents('.xts-style-aside').length) {
return;
}
$menu.find(' > .menu-item-has-children').each(function() {
setOffset($(this));
});
$menu.addClass('xts-offsets-calculated');
});
if ('yes' === xts_settings.clear_menu_offsets_on_resize) {
setTimeout(function () {
XTSThemeModule.$window.on('resize', XTSThemeModule.debounce(function () {
$menu.removeClass('xts-offsets-calculated');
$menu.find(' > .menu-item-has-children > .xts-dropdown-menu').attr('style', '');
}, 300));
}, 2000);
}
});
};
XTSThemeModule.menuDropdownAside = function() {
$('.xts-nav .xts-style-aside').each( function () {
var $links = $(this).find('.menu-item');
if (!$links.length) {
return;
}
var $firstLink = $links.first();
if (!$firstLink.hasClass('menu-item-has-children')) {
$firstLink.parents('.xts-sub-menu-wrapp').addClass('xts-empty-item');
}
$firstLink.addClass('xts-opened').find('.xts-dropdown').addClass('xts-opened');
$links.on('mouseover', function () {
var $this = $(this);
var $wrap = $this.parents('.xts-sub-menu-wrapp');
if ($this.hasClass('xts-opened')) {
return;
}
if ( $this.hasClass('item-level-1') ) {
if (!$this.hasClass('menu-item-has-children')) {
$wrap.addClass('xts-empty-item');
} else {
$wrap.removeClass('xts-empty-item');
}
}
if ( $this.parents().hasClass('sub-sub-menu') ) {
return;
}
$this.siblings().removeClass('xts-opened').find('.xts-dropdown').removeClass('xts-opened');
$this.addClass('xts-opened').find('.xts-dropdown').addClass('xts-opened');
});
});
}
$(document).ready(function() {
setTimeout(function () {
XTSThemeModule.menuOffsets();
XTSThemeModule.menuDropdownAside();
}, 100);
});
})(jQuery);