'use strict'; class StickyHeader { constructor() { let _this = this; this.$tbayHeader = jQuery('.tbay_header-template'); this.$tbayHeaderMain = jQuery('.tbay_header-template .header-main'); if (this.$tbayHeader.hasClass('main-sticky-header') && this.$tbayHeaderMain.length > 0) { this._initStickyHeader(); } jQuery('.search-min-wrapper .btn-search-min').click(this._onClickSeachMin); jQuery('.tbay-search-form .overlay-box').click(this._onClickOverLayBox); this._intSearchOffcanvas; let sticky_header = jQuery('.element-sticky-header'); if (sticky_header.length > 0) { _this._initELementStickyheader(sticky_header); } } _initStickyHeader() { var _this = this; var tbay_width = jQuery(window).width(); var header_height = _this.$tbayHeader.outerHeight(); var headerMain_height = _this.$tbayHeaderMain.outerHeight(); var admin_height = jQuery('#wpadminbar').length > 0 ? jQuery('#wpadminbar').outerHeight() : 0; var sticky = _this.$tbayHeaderMain.offset().top; if (tbay_width >= 1024) { if (sticky == 0 || sticky == admin_height) { if (_this.$tbayHeader.hasClass('sticky-header')) return; _this._stickyHeaderOnDesktop(headerMain_height, sticky, admin_height); _this.$tbayHeaderMain.addClass('sticky-1'); jQuery(window).scroll(function () { if (jQuery(this).scrollTop() > header_height) { _this.$tbayHeaderMain.addClass('sticky-box'); } else { _this.$tbayHeaderMain.removeClass('sticky-box'); } }); } else { jQuery(window).scroll(function () { if (!_this.$tbayHeader.hasClass('main-sticky-header')) return; if (jQuery(this).scrollTop() > sticky - admin_height) { if (_this.$tbayHeader.hasClass('sticky-header')) return; _this._stickyHeaderOnDesktop(headerMain_height, sticky, admin_height); } else { _this.$tbayHeaderMain.css("top", 0).css("position", "relative").removeClass('sticky-header').parent().css('padding-top', 0); _this.$tbayHeaderMain.prev().css('margin-bottom', 0); } }); } } } _stickyHeaderOnDesktop(headerMain_height, sticky, admin_height) { this.$tbayHeaderMain.addClass('sticky-header').css("top", admin_height).css("position", "fixed"); if (sticky == 0 || sticky == admin_height) { this.$tbayHeaderMain.parent().css('padding-top', headerMain_height); } else { this.$tbayHeaderMain.prev().css('margin-bottom', headerMain_height); } } _onClickSeachMin() { jQuery('.tbay-search-form.tbay-search-min form').toggleClass('show'); jQuery(this).toggleClass('active'); } _onClickOverLayBox() { jQuery('.search-min-wrapper .btn-search-min').removeClass('active'); jQuery('.tbay-search-form.tbay-search-min form').removeClass('show'); } _intSearchOffcanvas() { if (jQuery('#tbay-offcanvas-main').length === 0) return; jQuery('[data-toggle="offcanvas-main-search"]').off().on('click', function () { jQuery('#wrapper-container').toggleClass('show'); jQuery('#tbay-offcanvas-main').toggleClass('show'); }); var $box_totop = jQuery('#tbay-offcanvas-main, .search'); jQuery(window).on("click.Bst", function (event) { if ($box_totop.has(event.target).length == 0 && !$box_totop.is(event.target)) { jQuery('#wrapper-container').removeClass('show'); jQuery('#tbay-offcanvas-main').removeClass('show'); } }); } _initELementStickyheader(elements) { var el = elements.first(); let _this = this; var scroll = false, sum = 0, prev_sum = 0; if (el.parents('.tbay_header-template').length === 0) return; var adminbar = jQuery('#wpadminbar').length > 0 ? jQuery('#wpadminbar').outerHeight() : 0, sticky_load = el.offset().top - jQuery(window).scrollTop() - adminbar, sticky = sticky_load; el.prevAll().each(function () { prev_sum += jQuery(this).outerHeight(); }); elements.each(function () { if (jQuery(this).parents('.element-sticky-header').length > 0) return; sum += jQuery(this).outerHeight(); }); _this._initELementStickyheaderContent(sticky_load, sticky, sum, prev_sum, elements, el, adminbar, scroll); jQuery(window).scroll(function () { scroll = true; if (jQuery(window).scrollTop() === 0) sticky = 0; _this._initELementStickyheaderContent(sticky_load, sticky, sum, prev_sum, elements, el, adminbar, scroll); }); } _initELementStickyheaderContent(sticky_load, sticky, sum, prev_sum, elements, el, adminbar, scroll) { if (jQuery(window).scrollTop() < prev_sum && scroll || jQuery(window).scrollTop() === 0 && scroll) { if (el.parent().children().first().hasClass('element-sticky-header')) return; el.css('top', ''); if (sticky === sticky_load || sticky === 0) { elements.last().next().css('padding-top', ''); } else { el.prev().css('margin-bottom', ''); } el.parent().css('padding-top', ''); elements.each(function () { jQuery(this).removeClass("sticky"); if (jQuery(this).prev('.element-sticky-header').length > 0) { jQuery(this).css('top', ''); } }); } else { if (jQuery(window).scrollTop() < prev_sum && !scroll) return; elements.each(function () { if (jQuery(this).parents('.element-sticky-header').length > 0) return; jQuery(this).addClass("sticky"); if (jQuery(this).prevAll('.element-sticky-header').length > 0) { let total = 0; jQuery(this).prevAll('.element-sticky-header').each(function () { total += jQuery(this).outerHeight(); }); jQuery(this).css('top', total + adminbar); } }); el.css('top', adminbar); if (sticky === sticky_load || sticky === 0) { el.addClass("sticky"); el.parent().css('padding-top', sum); } else { el.prev().css('margin-bottom', sum); } } } } const TREE_VIEW_OPTION_MEGA_MENU = { animated: 300, collapsed: true, unique: true, persist: "location" }; const TREE_VIEW_OPTION_MOBILE_MENU = { animated: 300, collapsed: true, unique: true, hover: false }; class Mobile { constructor() { this._mobileMenu(); this._Select_change_form(); this._FooterMobileAccordion(); this._topBarDevice(); jQuery(window).scroll(() => { this._topBarDevice(); }); } _topBarDevice() { var scroll = jQuery(window).scrollTop(); var objectSelect = jQuery('#wpadminbar').length > 0 ? jQuery('#wpadminbar').outerHeight() : 0; var scrollmobile = jQuery(window).scrollTop(); jQuery(".topbar-device-mobile").toggleClass("active", scroll <= objectSelect); jQuery("#tbay-mobile-menu").toggleClass("offsetop", scrollmobile == 0); } _mobileMenu() { jQuery('[data-toggle="offcanvas"], .btn-offcanvas').click(function () { jQuery('#wrapper-container').toggleClass('active'); jQuery('#tbay-mobile-menu').toggleClass('active'); }); jQuery("#main-mobile-menu .caret").click(function () { jQuery("#main-mobile-menu .dropdown").removeClass('open'); jQuery(event.target).parent().addClass('open'); }); } _Select_change_form() { jQuery('.topbar-device-mobile > form select').on('change', function () { this.form.submit(); }); } _FooterMobileAccordion() { if (jQuery(window).width() >= 768) return; jQuery('.footer-mobile-collapse .heading-tbay-title').off().on('click', function () { var $title = jQuery(this); var $widget = $title.parent(); var $content = $widget.find('> *:not(.heading-tbay-title)'); if ($widget.hasClass('opened-collapse')) { $widget.removeClass('opened-collapse'); $content.stop().slideUp(200); } else { $widget.addClass('opened-collapse'); $content.stop().slideDown(200); } }); } } class AccountMenu { constructor() { this._slideToggleAccountMenu(".tbay-login"); this._slideToggleAccountMenu(".topbar-mobile"); this._tbayClickNotMyAccountMenu(); } _tbayClickNotMyAccountMenu() { var $win_my_account = jQuery(window); var $box_my_account = jQuery('.tbay-login .dropdown .account-menu,.topbar-mobile .dropdown .account-menu,.tbay-login .dropdown .account-button,.topbar-mobile .dropdown .account-button'); $win_my_account.on("click.Bst", function (event) { if ($box_my_account.has(event.target).length == 0 && !$box_my_account.is(event.target)) { jQuery(".tbay-login .dropdown .account-menu").slideUp(500); jQuery(".topbar-mobile .dropdown .account-menu").slideUp(500); } }); } _slideToggleAccountMenu(parentSelector) { jQuery(parentSelector).find(".dropdown .account-button").click(function () { jQuery(parentSelector).find(".dropdown .account-menu").slideToggle(500); }); } } class BackToTop { constructor() { this._init(); } _init() { jQuery(window).scroll(function () { var isActive = jQuery(this).scrollTop() > 400; jQuery('.tbay-to-top').toggleClass('active', isActive); jQuery('.tbay-category-fixed').toggleClass('active', isActive); }); jQuery('#back-to-top-mobile, #back-to-top').click(this._onClickBackToTop); } _onClickBackToTop() { jQuery('html, body').animate({ scrollTop: '0px' }, 0); } } class FuncCommon { constructor() { this._progressAnimation(); this._createWrapStart(); jQuery('.mod-heading .widget-title > span').wrapStart(); this._tbayActiveAdminBar(); this._tbayResizeMegamenu(); this._initHeaderCoverBG(); this._initCanvasSearch(); this._initTreeviewMenu(); this._categoryMenu(); jQuery(window).scroll(() => { this._tbayActiveAdminBar(); }); jQuery(window).on("resize", () => { this._tbayResizeMegamenu(); }); this._moveFormLogin(); this._moveFormCoupon(); this._moveNoticesLogin(); } _tbayActiveAdminBar() { var objectSelect = jQuery("#wpadminbar"); if (objectSelect.length > 0) { jQuery("body").addClass("active-admin-bar"); } } _createWrapStart() { jQuery.fn.wrapStart = function () { return this.each(function () { var $this = jQuery(this); var node = $this.contents().filter(function () { return this.nodeType == 3; }).first(), text = node.text().trim(), first = text.split(' ', 1).join(" "); if (!node.length) return; node[0].nodeValue = text.slice(first.length); node.before('' + first + ''); }); }; } _progressAnimation() { jQuery("[data-progress-animation]").each(function () { var $this = jQuery(this); $this.appear(function () { var delay = $this.attr("data-appear-animation-delay") ? $this.attr("data-appear-animation-delay") : 1; if (delay > 1) $this.css("animation-delay", delay + "ms"); setTimeout(function () { $this.animate({ width: $this.attr("data-progress-animation") }, 800); }, delay); }, { accX: 0, accY: -50 }); }); } _tbayResizeMegamenu() { var window_size = jQuery('body').innerWidth(); if (jQuery('.tbay_custom_menu').length > 0 && jQuery('.tbay_custom_menu').hasClass('tbay-vertical-menu')) { if (window_size > 767) { this._resizeMegaMenuOnDesktop(); } else { this._initTreeViewForMegaMenuOnMobile(); } } if (jQuery('.tbay-megamenu').length > 0 && jQuery('.tbay-megamenu,.tbay-offcanvas-main').hasClass('verticle-menu') && window_size > 767) { this._resizeMegaMenuVertical(); } } _resizeMegaMenuVertical() { var full_width = parseInt(jQuery('#main-container.container').innerWidth()); var menu_width = parseInt(jQuery('.verticle-menu').innerWidth()); var w = full_width - menu_width; jQuery('.verticle-menu').find('.aligned-fullwidth').children('.dropdown-menu').css({ "max-width": w, "width": full_width - 30 }); } _resizeMegaMenuOnDesktop() { let maxWidth = jQuery('#main-container.container').innerWidth() - jQuery('.tbay-vertical-menu').innerWidth(); let width = jQuery('#main-container.container').innerWidth() - 30; jQuery('.tbay-vertical-menu').find('.aligned-fullwidth').children('.dropdown-menu').css({ 'max-width': maxWidth, "width": width }); } _initTreeViewForMegaMenuOnMobile() { if (typeof jQuery.fn.treeview === "undefined") return; jQuery(".tbay-vertical-menu > .widget_nav_menu >.nav > ul").each(function () { if (jQuery(this).hasClass('treeview')) return; jQuery(this).treeview(TREE_VIEW_OPTION_MEGA_MENU); }); } _moveFormLogin() { if (jQuery('.woocommerce-form-login-toggle').length === 0) return; jQuery('.woocommerce-form-login-toggle').parent().find('.woocommerce-form-login').insertAfter(jQuery(".woocommerce-form-login-toggle .woocommerce-info")); } _moveNoticesLogin() { if (jQuery('.woocommerce-form-login-toggle').length === 0) return; jQuery('.woocommerce > .woocommerce-notices-wrapper').insertAfter(jQuery(".woocommerce-form-login-toggle .woocommerce-form-login ")); } _moveFormCoupon() { if (jQuery('.woocommerce-form-coupon-toggle').length === 0) return; jQuery('.woocommerce-form-coupon-toggle').parent().find('.woocommerce-form-coupon').insertAfter(jQuery(".woocommerce-form-coupon-toggle .woocommerce-info")); } _initHeaderCoverBG() { let menu = jQuery('.tbay-horizontal .navbar-nav > li,.tbay-horizontal-default .navbar-nav > li, .tbay_header-template .product-recently-viewed-header'), search = jQuery('.tbay-search-form .tbay-search'), btn_category = jQuery('.category-inside .category-inside-title'), cart_click = jQuery('.cart-popup'); menu.mouseenter(function () { if (jQuery(this).parents('#tbay-header').length === 0) return; if (jQuery(this).children('.dropdown-menu, ul, .content-view').length == 0) return; jQuery('.tbay_header-template').addClass('nav-cover-active-1'); }).mouseleave(function () { if (jQuery(this).closest('.dropdown-menu').length) return; jQuery('.tbay_header-template').removeClass('nav-cover-active-1'); }); search.focusin(function () { if (jQuery(this).closest('.dropdown-menu').length) return; if (search.parents('.sidebar-canvas-search').length > 0 || jQuery(this).closest('.tbay_header-template').length === 0) return; jQuery('.tbay_header-template').addClass('nav-cover-active-2'); }).focusout(function () { jQuery('.tbay_header-template').removeClass('nav-cover-active-2'); }); cart_click.on('shown.bs.dropdown', function (event) { jQuery(event.target).closest('.tbay_header-template').addClass('nav-cover-active-3'); }).on('hidden.bs.dropdown', function (event) { jQuery(event.target).closest('.tbay_header-template').removeClass('nav-cover-active-3'); }); if (btn_category.parents('.tbay_header-template')) { jQuery(document.body).on('tbay_category_inside_open', () => { jQuery('.tbay_header-template').addClass('nav-cover-active-4'); }); jQuery(document.body).on('tbay_category_inside_close', () => { jQuery('.tbay_header-template').removeClass('nav-cover-active-4'); }); } } _initCanvasSearch() { let input_search = jQuery('#tbay-search-form-canvas .sidebar-canvas-search .sidebar-content .tbay-search'); input_search.focusin(function () { input_search.parent().addClass('search_cv_active'); }).focusout(function () { input_search.parent().removeClass('search_cv_active'); }); } _initTreeviewMenu() { if (typeof jQuery.fn.treeview === "undefined") return; jQuery("#category-menu").addClass('treeview'); jQuery(".treeview-menu .menu, #category-menu").treeview(TREE_VIEW_OPTION_MEGA_MENU); jQuery("#main-mobile-menu, #main-mobile-menu-xlg").treeview(TREE_VIEW_OPTION_MOBILE_MENU); } _categoryMenu() { jQuery(".category-inside .category-inside-title").click(function () { jQuery(event.target).parents('.category-inside').toggleClass("open"); if (jQuery(event.target).parents('.category-inside').hasClass('setting-open')) return; if (jQuery(event.target).parents('.category-inside').hasClass('open')) { jQuery(document.body).trigger('tbay_category_inside_open'); } else { jQuery(document.body).trigger('tbay_category_inside_close'); } }); let $win = jQuery(window); $win.on("click.Bst,click touchstart tap", function (event) { let $box = jQuery('.category-inside .category-inside-title, .category-inside-content'); if (!jQuery('.category-inside').hasClass('open') && !jQuery('.tbay_header-template').hasClass('nav-cover-active-4')) return; if ($box.has(event.target).length == 0 && !$box.is(event.target)) { let insides = jQuery('.category-inside'); jQuery.each(insides, function (key, inside) { if (!jQuery(inside).hasClass('setting-open')) { jQuery(inside).removeClass('open'); jQuery('.tbay_header-template').removeClass('nav-cover-active-4'); } }); } }); } } class NewsLetter { constructor() { this._init(); } _init() { let btnRemove = jQuery('#popupNewsletterModal .popupnewsletter-close, #popupNewsletterModal .btn-text-close'); setTimeout(function () { if (Cookies.get('newsletter_remove') == "" || typeof Cookies.get('newsletter_remove') === "undefined") { jQuery('#popupNewsletterModal').modal('show'); } }, 3000); btnRemove.off().on('click', function (event) { jQuery(this).parents('#newsletter-popup').slideUp("slow"); Cookies.set('newsletter_remove', 'hidden', { expires: 0.1, path: '/' }); event.preventDefault(); }); } } class Search { constructor() { this._init(); } _init() { this._tbaySearchMobile(); this._searchToTop(); this._searchCanvasForm(); this._searchCanvasFormV3(); jQuery('.button-show-search').click(() => jQuery('.tbay-search-form').addClass('active')); jQuery('.button-hidden-search').click(() => jQuery('.tbay-search-form').removeClass('active')); } _tbaySearchMobile() { jQuery('#search-mobile-nav-cover').on("click", function () { jQuery(this).parent().find('form').removeClass('open'); }); } _searchToTop() { jQuery('.search-totop-wrapper .btn-search-totop').click(function () { jQuery('.search-totop-content').toggleClass('active'); jQuery(this).toggleClass('active'); }); var $box_totop = jQuery('.search-totop-wrapper .btn-search-totop, .search-totop-content'); jQuery(window).on("click.Bst", function (event) { if ($box_totop.has(event.target).length == 0 && !$box_totop.is(event.target)) { jQuery('.search-totop-wrapper .btn-search-totop').removeClass('active'); jQuery('.search-totop-content').removeClass('active'); } }); } _searchCanvasForm() { let searchform = jQuery('#tbay-search-form-canvas'); if (searchform.length === 0) return; searchform.find('button.search-open').click(function () { jQuery(event.target).parents('#tbay-search-form-canvas').toggleClass("open"); jQuery('body').toggleClass("active-search-canvas"); }); let window_searchcanvas = jQuery(window); let forcussidebar = jQuery('#tbay-search-form-canvas .search-open, #tbay-search-form-canvas .sidebar-content'); window_searchcanvas.on("click.Bst", function (event) { if (!searchform.hasClass('open')) return; if (forcussidebar.has(event.target).length == 0 && !forcussidebar.is(event.target)) { searchform.removeClass("open"); jQuery('body').removeClass("active-search-canvas"); } }); searchform.find('button.btn-search-close').click(function () { if (!searchform.hasClass('open')) return; searchform.removeClass("open"); jQuery('body').removeClass("active-search-canvas"); }); } _searchCanvasFormV3() { let searchform = jQuery('#tbay-search-form-canvas-v3'); if (searchform.length === 0) return; searchform.find('button.search-open').click(function () { jQuery(event.target).parents('#tbay-search-form-canvas-v3').toggleClass("open"); jQuery('body').toggleClass("active-search-canvas"); }); let window_searchcanvas = jQuery(window); let forcussidebar = jQuery('#tbay-search-form-canvas-v3 .search-open, #tbay-search-form-canvas-v3 .sidebar-content'); window_searchcanvas.on("click.Bst", function (event) { if (!searchform.hasClass('open')) return; if (forcussidebar.has(event.target).length == 0 && !forcussidebar.is(event.target)) { searchform.removeClass("open"); jQuery('body').removeClass("active-search-canvas"); } }); searchform.find('button.btn-search-close').click(function () { if (!searchform.hasClass('open')) return; searchform.removeClass("open"); jQuery('body').removeClass("active-search-canvas"); }); } } class TreeView { constructor() { this._tbayTreeViewMenu(); } _tbayTreeViewMenu() { if (typeof jQuery.fn.treeview === "undefined" || typeof jQuery('.tbay-treeview') === "undefined") return; jQuery(".tbay-treeview").each(function () { if (jQuery(this).find('> ul').hasClass('treeview')) return; jQuery(this).find('> ul').treeview({ animated: 400, collapsed: true, unique: true, persist: "location" }); }); } } class Section { constructor() { this._tbayMegaMenu(); this._tbayRecentlyView(); } _tbayMegaMenu() { let menu = jQuery('.elementor-widget-tbay-nav-menu'); if (menu.length === 0) return; menu.find('.tbay-element-nav-menu').each(function () { if (jQuery(this).data('wrapper').layout !== "horizontal") return; if (!jQuery(this).closest('.elementor-top-column').hasClass('tbay-column-static')) { jQuery(this).closest('.elementor-top-column').addClass('tbay-column-static'); } if (!jQuery(this).closest('section').hasClass('tbay-section-static')) { jQuery(this).closest('section').addClass('tbay-section-static'); } }); } _tbayRecentlyView() { let recently = jQuery('.tbay-element-product-recently-viewed'); if (recently.length === 0) return; recently.each(function () { if (jQuery(this).data('wrapper').layout !== "header") return; if (!jQuery(this).closest('.elementor-top-column').hasClass('tbay-column-static')) { jQuery(this).closest('.elementor-top-column').addClass('tbay-column-static'); } if (!jQuery(this).closest('.elementor-top-column').hasClass('tbay-column-recentlyviewed')) { jQuery(this).closest('.elementor-top-column').addClass('tbay-column-recentlyviewed'); } if (!jQuery(this).closest('section').hasClass('tbay-section-recentlyviewed')) { jQuery(this).closest('section').addClass('tbay-section-recentlyviewed'); } if (!jQuery(this).closest('section').hasClass('tbay-section-static')) { jQuery(this).closest('section').addClass('tbay-section-static'); } }); } } class Preload { constructor() { this._init(); } _init() { if (jQuery.fn.jpreLoader) { var $preloader = jQuery('.js-preloader'); $preloader.jpreLoader({}, function () { $preloader.addClass('preloader-done'); jQuery('body').trigger('preloader-done'); jQuery(window).trigger('resize'); }); } jQuery('.tbay-page-loader').delay(100).fadeOut(400, function () { jQuery('body').removeClass('tbay-body-loading'); jQuery(this).remove(); }); if (jQuery(document.body).hasClass('tbay-body-loader')) { setTimeout(function () { jQuery(document.body).removeClass('tbay-body-loader'); jQuery('.tbay-page-loader').fadeOut(250); }, 300); } } } class Accordion { constructor() { this._init(); } _init() { if (jQuery('.single-product').length === 0) return; jQuery('#woocommerce-accordion').on('shown.bs.collapse', function (e) { var offset = jQuery(this).find('.collapse.show').prev('.tabs-title'); if (offset) { jQuery('html,body').animate({ scrollTop: jQuery(offset).offset().top - 150 }, 500); } }); } } class CustomFonts { constructor() { this._init(); } _init() { if (jQuery('.list-tbay-custom-fonts-body').length === 0) return; jQuery('.code-preview').hide(); jQuery('.show-code').off().on('click', function (e) { jQuery(this).children('.name').toggle(); jQuery(this).children('.code-preview').toggleClass('show'); e.stopPropagation(); return false; }); jQuery("#quick-search").keyup(function () { var srch = jQuery(this).val().trim().toLowerCase(); jQuery(".icon-preview-box").hide().filter(function () { return jQuery(this).html().trim().toLowerCase().indexOf(srch) != -1; }).show(); }); jQuery(".font-size-changer a").click(function (e) { e.preventDefault(); jQuery(".font-size-changer .active").removeClass("active"); jQuery(".icon-preview-box").removeClass("small-icons medium-icons large-icons").addClass(jQuery(this).attr("class")); jQuery(this).addClass("active"); }); } } class MenuDropdownsAJAX { constructor() { this._initmenuDropdownsAJAX(); } _initmenuDropdownsAJAX() { var _this = this; jQuery('body').on('mousemove', function () { jQuery('.menu').has('.dropdown-load-ajax').each(function () { var $menu = jQuery(this); if ($menu.hasClass('dropdowns-loading') || $menu.hasClass('dropdowns-loaded')) { return; } if (!_this.isNear($menu, 50, event)) { return; } _this.loadDropdowns($menu); }); }); } loadDropdowns($menu) { var _this = this; $menu.addClass('dropdowns-loading'); var storageKey = '', unparsedData = '', menu_mobile_id = ''; if ($menu.closest('nav').attr('id') === 'tbay-mobile-menu-navbar') { if (jQuery('#main-mobile-menu-mmenu-wrapper').length > 0) { menu_mobile_id += '_' + jQuery('#main-mobile-menu-mmenu-wrapper').data('id'); } storageKey = maia_settings.storage_key + '_megamenu_' + menu_mobile_id; } else { storageKey = maia_settings.storage_key + '_megamenu_' + $menu.closest('nav').data('id'); } unparsedData = localStorage.getItem(storageKey); var storedData = false; var $items = $menu.find('.dropdown-load-ajax'), ids = []; $items.each(function () { ids.push(jQuery(this).find('.dropdown-html-placeholder').data('id')); }); var unparsedData = localStorage.getItem(storageKey); try { storedData = JSON.parse(unparsedData); } catch (e) { console.log('cant parse Json', e); } if (storedData) { _this.renderResults(storedData, $menu); if ($menu.attr('id') !== 'tbay-mobile-menu-navbar') { $menu.removeClass('dropdowns-loading').addClass('dropdowns-loaded'); } } else { jQuery.ajax({ url: maia_settings.ajaxurl, data: { action: 'maia_load_html_dropdowns', ids: ids, security: maia_settings.wp_megamenunonce }, dataType: 'json', method: 'POST', success: function (response) { if (response.status === 'success') { _this.renderResults(response.data, $menu); localStorage.setItem(storageKey, JSON.stringify(response.data)); } else { console.log('loading html dropdowns returns wrong data - ', response.message); } }, error: function () { console.log('loading html dropdowns ajax error'); } }); } } renderResults(data, $menu) { var _this = this; Object.keys(data).forEach(function (id) { _this.removeDuplicatedStylesFromHTML(data[id], function (html) { let html2 = html; const regex1 = ']*>]*href=["]' + window.location.href + '["]>.*?<\/a><\/li>'; let content = html.match(regex1); if (content !== null) { let $url = content[0]; let $class = $url.match(/(?:class)=(?:["']\W+\s*(?:\w+)\()?["']([^'"]+)['"]/g)[0].split('"')[1]; let $class_new = $class + ' active'; let $url_new = $url.replace($class, $class_new); html2 = html2.replace($url, $url_new); } $menu.find('[data-id="' + id + '"]').replaceWith(html2); if ($menu.attr('id') !== 'tbay-mobile-menu-navbar') { $menu.addClass('dropdowns-loaded'); setTimeout(function () { $menu.removeClass('dropdowns-loading'); }, 1000); } }); }); } isNear($element, distance, event) { var left = $element.offset().left - distance, top = $element.offset().top - distance, right = left + $element.width() + 2 * distance, bottom = top + $element.height() + 2 * distance, x = event.pageX, y = event.pageY; return x > left && x < right && y > top && y < bottom; } removeDuplicatedStylesFromHTML(html, callback) { if (maia_settings.combined_css) { callback(html); return; } else { const regex = /