Advertisement
Guest User

functions.js

a guest
Aug 28th, 2019
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var woodmartThemeModule;
  2. var wooFile = false;
  3.  
  4. (function ($) {
  5.     "use strict";
  6.  
  7.     woodmartThemeModule = (function () {
  8.  
  9.         var woodmartTheme = {
  10.             popupEffect: 'mfp-move-horizontal',
  11.             bootstrapTooltips: '.woodmart-tooltip, .product-actions-btns > a, .wrapp-buttons .woodmart-buttons > div:not(.woodmart-add-btn) a, .wrapp-buttons .woodmart-buttons .woodmart-add-btn, body:not(.catalog-mode-on):not(.login-see-prices) .woodmart-hover-base:not(.product-in-carousel) .woodmart-buttons > div:not(.woodmart-add-btn) a, body:not(.catalog-mode-on):not(.login-see-prices) .woodmart-hover-base.hover-width-small:not(.product-in-carousel) .woodmart-add-btn, body:not(.catalog-mode-on):not(.login-see-prices) .woodmart-hover-base.add-small-button:not(.product-in-carousel) .woodmart-add-btn, .woodmart-hover-base .product-compare-button a',
  12.         };
  13.  
  14.         return {
  15.  
  16.             init: function () {
  17.                 // Disable nanoscroller option
  18.                 woodmartTheme.disableNanoScrollerWebkit = woodmart_settings.disable_nanoscroller == 'webkit' && (jscd.browser == 'Chrome' || jscd.browser == 'Opera' || jscd.browser == 'Safari');
  19.  
  20.                 this.headerBanner();
  21.  
  22.                 this.headerBuilder()
  23.  
  24.                 this.visibleElements();
  25.  
  26.                 this.bannersHover();
  27.  
  28.                 this.portfolioEffects();
  29.  
  30.                 this.parallax();
  31.  
  32.                 this.googleMap();
  33.  
  34.                 this.scrollTop();
  35.  
  36.                 this.sidebarMenu();
  37.  
  38.                 this.widgetsHidable();
  39.  
  40.                 this.stickyColumn();
  41.  
  42.                 this.mfpPopup();
  43.  
  44.                 this.blogMasonry();
  45.  
  46.                 this.blogLoadMore();
  47.  
  48.                 this.portfolioLoadMore();
  49.  
  50.                 this.equalizeColumns();
  51.  
  52.                 this.menuSetUp();
  53.  
  54.                 this.menuOffsets();
  55.  
  56.                 this.onePageMenu();
  57.  
  58.                 this.mobileNavigation();
  59.  
  60.                 this.simpleDropdown();
  61.  
  62.                 this.promoPopup();
  63.  
  64.                 this.contentPopup();
  65.  
  66.                 this.cookiesPopup();
  67.  
  68.                 this.btnsToolTips();
  69.  
  70.                 this.stickyFooter();
  71.  
  72.                 this.countDownTimer();
  73.  
  74.                 this.nanoScroller();
  75.  
  76.                 this.gradientShift();
  77.  
  78.                 this.videoPoster();
  79.  
  80.                 this.mobileSearchIcon();
  81.  
  82.                 this.fullScreenMenu();
  83.  
  84.                 this.searchFullScreen();
  85.  
  86.                 this.wooInit();
  87.  
  88.                 this.lazyLoading();
  89.  
  90.                 this.ajaxSearch();
  91.  
  92.                 this.photoswipeImages();
  93.  
  94.                 this.stickySocialButtons();
  95.  
  96.                 this.animationsOffset();
  97.  
  98.                 this.hiddenSidebar();
  99.  
  100.                 this.imageHotspot();
  101.  
  102.                 this.woodSliderLazyLoad();
  103.  
  104.                 this.owlCarouselInit();
  105.  
  106.                 this.portfolioPhotoSwipe();
  107.  
  108.                 this.woocommerceNotices();
  109.  
  110.                 this.menuDropdownsAJAX();
  111.  
  112.                 this.instagramAjaxQuery();
  113.  
  114.                 this.footerWidgetsAccordion();
  115.  
  116.                 this.googleMapInit();
  117.  
  118.                 $(window).resize();
  119.  
  120.             },
  121.  
  122.             /**
  123.              *-------------------------------------------------------------------------------------------------------------------------------------------
  124.              * WooCommerce init
  125.              *-------------------------------------------------------------------------------------------------------------------------------------------
  126.              */
  127.  
  128.             wooInit: function () {
  129.                 if (!woodmart_settings.woo_installed) return;
  130.  
  131.                 this.loginDropdown();
  132.  
  133.                 this.loginSidebar();
  134.  
  135.                 this.productLoaderPosition();
  136.  
  137.                 this.initZoom();
  138.  
  139.                 this.woocommerceWrappTable();
  140.  
  141.                 this.woocommerceComments();
  142.  
  143.                 this.onRemoveFromCart();
  144.  
  145.                 this.woocommerceQuantity();
  146.  
  147.                 this.cartWidget();
  148.  
  149.                 this.ajaxFilters();
  150.  
  151.                 this.shopPageInit();
  152.  
  153.                 this.filtersArea();
  154.  
  155.                 this.categoriesMenu();
  156.  
  157.                 this.headerCategoriesMenu();
  158.  
  159.                 this.loginTabs();
  160.  
  161.                 this.productVideo();
  162.  
  163.                 this.product360Button();
  164.  
  165.                 this.wishList();
  166.  
  167.                 this.compare();
  168.  
  169.                 this.woodmartCompare();
  170.  
  171.                 this.productsLoadMore();
  172.  
  173.                 this.productsTabs();
  174.  
  175.                 this.swatchesVariations();
  176.  
  177.                 this.swatchesOnGrid();
  178.  
  179.                 this.quickViewInit();
  180.  
  181.                 this.quickShop();
  182.  
  183.                 this.addToCart();
  184.  
  185.                 this.productAccordion();
  186.  
  187.                 this.productImagesGallery();
  188.  
  189.                 this.productImages();
  190.  
  191.                 this.stickyDetails();
  192.  
  193.                 this.stickyAddToCart();
  194.  
  195.                 this.stickySidebarBtn();
  196.  
  197.                 this.productMoreDescription();
  198.  
  199.                 this.variationsPrice();
  200.  
  201.                 this.wishlist();
  202.             },
  203.  
  204.             googleMapInit: function () {
  205.                 $('.google-map-container').each(function () {
  206.                     var $map = $(this);
  207.                     var data = $map.data('map-args');
  208.  
  209.                     var config = {
  210.                         locations: [{
  211.                             lat: data.latitude,
  212.                             lon: data.longitude,
  213.                             icon: data.marker_icon,
  214.                             animation: google.maps.Animation.DROP
  215.                         }],
  216.                         controls_on_map: false,
  217.                         map_div: '#' + data.selector,
  218.                         start: 1,
  219.                         map_options: {
  220.                             zoom: parseInt( data.zoom ),
  221.                             scrollwheel: 'yes' === data.mouse_zoom ? true : false,
  222.                         },
  223.                     };
  224.  
  225.                     if (data.json_style) {
  226.                         config.styles = {};
  227.                         config.styles[woodmart_settings.google_map_style_text] = $.parseJSON(data.json_style);
  228.                     }
  229.  
  230.                     if ('yes' === data.marker_text_needed) {
  231.                         config.locations[0].html = data.marker_text;
  232.                     }
  233.  
  234.                     if ('button' === data.init_type) {
  235.                         $map.find('.woodmart-init-map').on('click', function(e){
  236.                             e.preventDefault();
  237.                            
  238.                             if ($map.hasClass('woodmart-map-inited')) {
  239.                                 return;
  240.                             }
  241.  
  242.                             $map.addClass('woodmart-map-inited');
  243.                             new Maplace(config).Load();
  244.                         });
  245.                     } else if ('scroll' === data.init_type) {
  246.                         $(window).scroll(function () {
  247.                             if (window.innerHeight + $(window).scrollTop() + parseInt(data.init_offset) > $map.offset().top) {
  248.                                 if ($map.hasClass('woodmart-map-inited')) {
  249.                                     return;
  250.                                 }
  251.  
  252.                                 $map.addClass('woodmart-map-inited');
  253.                                 new Maplace(config).Load();
  254.                             }
  255.                         });
  256.  
  257.                         $(window).scroll();
  258.                     } else {
  259.                         new Maplace(config).Load();
  260.                     }
  261.                 });
  262.             },
  263.  
  264.             footerWidgetsAccordion: function () {
  265.                 if ($(window).width() > 576) {
  266.                     return;
  267.                 }
  268.  
  269.                 $('.footer-widget-collapse .widget-title').on('click', function () {
  270.                     var $title = $(this);
  271.                     var $widget = $title.parent();
  272.                     var $content = $widget.find('> *:not(.widget-title)');
  273.  
  274.                     if ($widget.hasClass('footer-widget-opened')) {
  275.                         $widget.removeClass('footer-widget-opened');
  276.                         $content.stop().slideUp(200);
  277.                     } else {
  278.                         $widget.addClass('footer-widget-opened');
  279.                         $content.stop().slideDown(200);
  280.                     }
  281.                 });
  282.  
  283.             },
  284.  
  285.             instagramAjaxQuery: function () {
  286.                 $('.instagram-widget').each(function () {
  287.                     var $instagram = $(this);
  288.                     if (!$instagram.hasClass('instagram-with-error')) {
  289.                         return;
  290.                     }
  291.  
  292.                     var username = $instagram.data('username');
  293.                     var atts = $instagram.data('atts');
  294.                     var request_param = username.indexOf('#') > -1 ? 'explore/tags/' + username.substr(1) : username;
  295.  
  296.                     var url = 'https://www.instagram.com/' + request_param + '/';
  297.  
  298.                     $instagram.addClass('loading');
  299.  
  300.                     $.ajax({
  301.                         url: url,
  302.                         success: function (response) {
  303.                             $.ajax({
  304.                                 url: woodmart_settings.ajaxurl,
  305.                                 data: {
  306.                                     action: 'woodmart_instagram_ajax_query',
  307.                                     body: response,
  308.                                     atts: atts,
  309.                                 },
  310.                                 dataType: 'json',
  311.                                 method: 'POST',
  312.                                 success: function (response) {
  313.                                     $instagram.parent().html(response);
  314.                                     woodmartThemeModule.owlCarouselInit();
  315.                                 },
  316.                                 error: function (data) {
  317.                                     console.log('instagram ajax error');
  318.                                 },
  319.                             });
  320.                         },
  321.                         error: function (data) {
  322.                             console.log('instagram ajax error');
  323.                         },
  324.                     });
  325.  
  326.                 });
  327.             },
  328.  
  329.             /**
  330.              *-------------------------------------------------------------------------------------------------------------------------------------------
  331.              * Menu dropdowns AJAX
  332.              *-------------------------------------------------------------------------------------------------------------------------------------------
  333.              */
  334.  
  335.             menuDropdownsAJAX: function () {
  336.                 var $menus = jQuery('.menu').has('.dropdown-load-ajax');
  337.  
  338.                 jQuery('body').on('mousemove', checkMenuProximity);
  339.  
  340.                 function checkMenuProximity(event) {
  341.  
  342.                     $menus.each(function () {
  343.                         var $menu = jQuery(this);
  344.  
  345.                         if ($menu.hasClass('dropdowns-loading') || $menu.hasClass('dropdowns-loaded')) return;
  346.  
  347.                         if (!isNear($menu, 50, event)) return;
  348.  
  349.                         loadDropdowns($menu);
  350.  
  351.                     });
  352.                 }
  353.  
  354.                 function loadDropdowns($menu) {
  355.                     $menu.addClass('dropdowns-loading');
  356.  
  357.                     var $items = $menu.find('.dropdown-load-ajax'),
  358.                         ids = [];
  359.  
  360.                     $items.each(function () {
  361.                         ids.push(jQuery(this).find('.dropdown-html-placeholder').data('id'));
  362.                     });
  363.  
  364.                     jQuery.ajax({
  365.                         url: woodmart_settings.ajaxurl,
  366.                         data: {
  367.                             action: 'woodmart_load_html_dropdowns',
  368.                             ids: ids,
  369.                         },
  370.                         dataType: 'json',
  371.                         method: 'POST',
  372.                         success: function (response) {
  373.  
  374.                             if (response.status == 'success') {
  375.                                 Object.keys(response.data).forEach(function (id) {
  376.                                     var html = response.data[id];
  377.                                     $menu.find('[data-id="' + id + '"]').replaceWith(html);
  378.                                 });
  379.  
  380.                                 // Initialize OWL Carousels
  381.                                 woodmartThemeModule.owlCarouselInit();
  382.  
  383.                             } else {
  384.                                 console.log('loading html dropdowns returns wrong data - ', response.message);
  385.                             }
  386.                         },
  387.                         error: function (data) {
  388.                             console.log('loading html dropdowns ajax error');
  389.                         },
  390.                         complete: function () {
  391.                             $menu.removeClass('dropdowns-loading').addClass('dropdowns-loaded');
  392.                         },
  393.                     });
  394.                 }
  395.  
  396.                 function isNear($element, distance, event) {
  397.  
  398.                     var left = $element.offset().left - distance,
  399.                         top = $element.offset().top - distance,
  400.                         right = left + $element.width() + (2 * distance),
  401.                         bottom = top + $element.height() + (2 * distance),
  402.                         x = event.pageX,
  403.                         y = event.pageY;
  404.  
  405.                     return (x > left && x < right && y > top && y < bottom);
  406.  
  407.                 };
  408.             },
  409.  
  410.             /**
  411.              *-------------------------------------------------------------------------------------------------------------------------------------------
  412.              * WooCommerce pretty notices
  413.              *-------------------------------------------------------------------------------------------------------------------------------------------
  414.              */
  415.  
  416.             woocommerceNotices: function () {
  417.                 var notices = '.woocommerce-error, .woocommerce-info, .woocommerce-message, div.wpcf7-response-output, #yith-wcwl-popup-message, .mc4wp-alert, .dokan-store-contact .alert-success, .yith_ywraq_add_item_product_message';
  418.  
  419.                 $('body').on('click', notices, function () {
  420.                     var $msg = $(this);
  421.                     hideMessage($msg);
  422.                 });
  423.  
  424.                 var showAllMessages = function () {
  425.                     $notices.addClass('shown-notice');
  426.                 };
  427.  
  428.                 var hideAllMessages = function () {
  429.                     hideMessage($notices);
  430.                 };
  431.  
  432.                 var hideMessage = function ($msg) {
  433.                     $msg.removeClass('shown-notice').addClass('hidden-notice');
  434.                 };
  435.             },
  436.  
  437.             /**
  438.              *-------------------------------------------------------------------------------------------------------------------------------------------
  439.              * Portfolio photo swipe
  440.              *-------------------------------------------------------------------------------------------------------------------------------------------
  441.              */
  442.  
  443.             portfolioPhotoSwipe: function () {
  444.                 $(document).on('click', '.portfolio-enlarge', function (e) {
  445.                     e.preventDefault();
  446.                     var $parent = $(this).parents('.owl-item');
  447.                     if ($parent.length == 0) {
  448.                         $parent = $(this).parents('.portfolio-entry');
  449.                     }
  450.                     var index = $parent.index();
  451.                     var items = getPortfolioImages();
  452.                     woodmartThemeModule.callPhotoSwipe(index, items);
  453.                 });
  454.  
  455.                 var getPortfolioImages = function () {
  456.                     var items = [];
  457.                     $('.portfolio-entry').find('figure a img').each(function () {
  458.                         items.push({
  459.                             src: $(this).attr('src'),
  460.                             w: $(this).attr('width'),
  461.                             h: $(this).attr('height')
  462.                         });
  463.                     });
  464.                     return items;
  465.                 };
  466.             },
  467.  
  468.             /**
  469.              *-------------------------------------------------------------------------------------------------------------------------------------------
  470.              * Owl carousel init function
  471.              *-------------------------------------------------------------------------------------------------------------------------------------------
  472.              */
  473.  
  474.             owlCarouselInit: function () {
  475.                 $(document).on('FrontendEditorCarouselInit', function (event, $element) {
  476.                     owlInit($element);
  477.                 });
  478.  
  479.                 $('div[data-owl-carousel]:not(.scroll-init)').each(function () {
  480.                     owlInit($(this));
  481.                 });
  482.  
  483.                 if (typeof ($.fn.waypoint) != 'undefined') {
  484.                     $('div[data-owl-carousel].scroll-init').waypoint(function () {
  485.                         owlInit($(this));
  486.                     }, {
  487.                             offset: '100%'
  488.                         });
  489.                 }
  490.  
  491.                 function owlInit($this) {
  492.                     var $owl = $this.find('.owl-carousel');
  493.  
  494.                     if ($(window).width() <= 1024 && $this.hasClass('disable-owl-mobile') || $owl.hasClass('owl-loaded')) {
  495.                         return;
  496.                     }
  497.  
  498.                     var options = {
  499.                         rtl: $('body').hasClass('rtl'),
  500.                         items: $this.data('desktop') ? $this.data('desktop') : 1,
  501.                         responsive: {
  502.                             1025: {
  503.                                 items: $this.data('desktop') ? $this.data('desktop') : 1
  504.                             },
  505.                             769: {
  506.                                 items: $this.data('tablet_landscape') ? $this.data('tablet_landscape') : 1
  507.                             },
  508.                             577: {
  509.                                 items: $this.data('tablet') ? $this.data('tablet') : 1
  510.                             },
  511.                             0: {
  512.                                 items: $this.data('mobile') ? $this.data('mobile') : 1
  513.                             }
  514.                         },
  515.                         autoplay: $this.data('autoplay') == 'yes' ? true : false,
  516.                         autoplayHoverPause: $this.data('autoplay') == 'yes' ? true : false,
  517.                         autoplayTimeout: $this.data('speed') ? $this.data('speed') : 5000,
  518.                         dots: $this.data('hide_pagination_control') == 'yes' ? false : true,
  519.                         nav: $this.data('hide_prev_next_buttons') == 'yes' ? false : true,
  520.                         autoHeight: $this.data('autoheight') == 'yes' ? true : false,
  521.                         slideBy: $this.data('scroll_per_page') == 'no' ? 1 : 'page',
  522.                         navText: false,
  523.                         center: $this.data('center_mode') == 'yes' ? true : false,
  524.                         loop: $this.data('wrap') == 'yes' ? true : false,
  525.                         dragEndSpeed: $this.data('dragendspeed') ? $this.data('dragendspeed') : 200,
  526.                         onRefreshed: function () {
  527.                             $(window).resize();
  528.                         }
  529.                     };
  530.  
  531.                     if ($this.data('sliding_speed')) {
  532.                         options.smartSpeed = $this.data('sliding_speed');
  533.                         options.dragEndSpeed = $this.data('sliding_speed');
  534.                     }
  535.  
  536.                     if ($this.data('animation')) {
  537.                         options.animateOut = $this.data('animation');
  538.                         options.mouseDrag = false;
  539.                     }
  540.  
  541.                     function determinePseudoActive() {
  542.                         var id = $owl.find('.owl-item.active').find('.woodmart-slide').attr('id');
  543.                         $owl.find('.owl-item.pseudo-active').removeClass('pseudo-active');
  544.                         var $els = $owl.find('[id="' + id + '"]');
  545.                         $els.each(function () {
  546.                             if (!$(this).parent().hasClass('active')) {
  547.                                 $(this).parent().addClass('pseudo-active');
  548.                             }
  549.                         });
  550.                     }
  551.  
  552.                     if ($this.data('content_animation')) {
  553.                         determinePseudoActive();
  554.                         options.onTranslated = function () {
  555.                             determinePseudoActive();
  556.                         };
  557.                     }
  558.  
  559.                     $(window).on('vc_js', function () {
  560.                         $owl.trigger('refresh.owl.carousel');
  561.                     });
  562.  
  563.                     $owl.owlCarousel(options);
  564.  
  565.                     if ($this.data('autoheight') == 'yes') {
  566.                         $owl.imagesLoaded(function () {
  567.                             $owl.trigger('refresh.owl.carousel');
  568.                         });
  569.                     }
  570.                 }
  571.             },
  572.  
  573.             /**
  574.              *-------------------------------------------------------------------------------------------------------------------------------------------
  575.              * Woodmart slider lazyload
  576.              *-------------------------------------------------------------------------------------------------------------------------------------------
  577.              */
  578.  
  579.             woodSliderLazyLoad: function () {
  580.                 $('.woodmart-slider').on('changed.owl.carousel', function (event) {
  581.                     var $this = $(this);
  582.                     var active = $this.find('.owl-item').eq(event.item.index);
  583.                     var id = active.find('.woodmart-slide').attr('id');
  584.                     var $els = $this.find('[id="' + id + '"]');
  585.  
  586.                     active.find('.woodmart-slide').addClass('woodmart-loaded');
  587.                     $els.each(function () {
  588.                         $(this).addClass('woodmart-loaded');
  589.                     });
  590.                 });
  591.             },
  592.  
  593.             /**
  594.              *-------------------------------------------------------------------------------------------------------------------------------------------
  595.              * Image hotspot
  596.              *-------------------------------------------------------------------------------------------------------------------------------------------
  597.              */
  598.  
  599.             imageHotspot: function () {
  600.                 //Hotspot action
  601.                 $('.woodmart-image-hotspot').each(function () {
  602.                     var _this = $(this);
  603.                     var btn = _this.find('.hotspot-btn');
  604.                     // var content = _this.find('.hotspot-content');
  605.                     var parentWrapper = _this.parents('.woodmart-image-hotspot-wrapper');
  606.  
  607.                     if (!parentWrapper.hasClass('hotspot-action-click') && $(window).width() > 1024) return;
  608.  
  609.                     btn.on('click', function () {
  610.                         if (_this.hasClass('hotspot-opened')) {
  611.                             _this.removeClass('hotspot-opened');
  612.                         } else {
  613.                             _this.addClass('hotspot-opened');
  614.                             _this.siblings().removeClass('hotspot-opened');
  615.                         }
  616.                         $(document).trigger('wood-images-loaded');
  617.                         return false;
  618.                     });
  619.  
  620.                     $(document).on('click', function (e) {
  621.                         var target = e.target;
  622.                         if (_this.hasClass('hotspot-opened') && !$(target).is('.woodmart-image-hotspot') && !$(target).parents().is('.woodmart-image-hotspot')) {
  623.                             _this.removeClass('hotspot-opened');
  624.                             return false;
  625.                         }
  626.                     });
  627.                 });
  628.  
  629.                 //Image loaded
  630.                 $('.woodmart-image-hotspot-wrapper').each(function () {
  631.                     var _this = $(this);
  632.                     _this.imagesLoaded(function () {
  633.                         _this.addClass('loaded');
  634.                     });
  635.                 });
  636.  
  637.                 //Content position
  638.                 $('.woodmart-image-hotspot .hotspot-content').each(function () {
  639.                     var content = $(this);
  640.                     var offsetLeft = content.offset().left;
  641.                     var offsetRight = $(window).width() - (offsetLeft + content.outerWidth());
  642.  
  643.                     if ($(window).width() > 768) {
  644.                         if (offsetLeft <= 0) content.addClass('hotspot-overflow-right');
  645.                         if (offsetRight <= 0) content.addClass('hotspot-overflow-left');
  646.                     }
  647.  
  648.                     if ($(window).width() <= 768) {
  649.                         if (offsetLeft <= 0) content.css('marginLeft', Math.abs(offsetLeft - 15) + 'px');
  650.                         if (offsetRight <= 0) content.css('marginLeft', offsetRight - 15 + 'px');
  651.                     }
  652.                 });
  653.             },
  654.  
  655.             /**
  656.              *-------------------------------------------------------------------------------------------------------------------------------------------
  657.              * Hidden sidebar button
  658.              *-------------------------------------------------------------------------------------------------------------------------------------------
  659.              */
  660.  
  661.             hiddenSidebar: function () {
  662.                 $('body').on('click', '.woodmart-show-sidebar-btn, .woodmart-sticky-sidebar-opener', function (e) {
  663.                     e.preventDefault();
  664.                     if ($('.sidebar-container').hasClass('show-hidden-sidebar')) {
  665.                         woodmartThemeModule.hideShopSidebar();
  666.                     } else {
  667.                         showSidebar();
  668.                     }
  669.                 });
  670.  
  671.                 $('body').on("click touchstart", ".woodmart-close-side, .close-side-widget", function () {
  672.                     woodmartThemeModule.hideShopSidebar();
  673.                 });
  674.  
  675.                 var showSidebar = function () {
  676.                     $('.sidebar-container').addClass('show-hidden-sidebar');
  677.                     $('.woodmart-close-side').addClass('woodmart-close-side-opened');
  678.                     $('.woodmart-show-sidebar-btn').addClass('btn-clicked');
  679.  
  680.                     if ($(window).width() >= 1024 && (!woodmartTheme.disableNanoScrollerWebkit && woodmart_settings.disable_nanoscroller != 'disable')) {
  681.                         $(".sidebar-inner.woodmart-sidebar-scroll").nanoScroller({
  682.                             paneClass: 'woodmart-scroll-pane',
  683.                             sliderClass: 'woodmart-scroll-slider',
  684.                             contentClass: 'woodmart-sidebar-content',
  685.                             preventPageScrolling: false
  686.                         });
  687.                     }
  688.                 };
  689.             },
  690.  
  691.             hideShopSidebar: function () {
  692.                 $('.woodmart-show-sidebar-btn').removeClass('btn-clicked');
  693.                 $('.sidebar-container').removeClass('show-hidden-sidebar');
  694.                 $('.woodmart-close-side').removeClass('woodmart-close-side-opened');
  695.                 if (!woodmartTheme.disableNanoScrollerWebkit && woodmart_settings.disable_nanoscroller != 'disable') {
  696.                     $('.sidebar-inner.woodmart-scroll').nanoScroller({ destroy: true });
  697.                 }
  698.             },
  699.  
  700.             /**
  701.              *-------------------------------------------------------------------------------------------------------------------------------------------
  702.              * Css animations offset
  703.              *-------------------------------------------------------------------------------------------------------------------------------------------
  704.              */
  705.  
  706.             animationsOffset: function () {
  707.                 if (typeof ($.fn.waypoint) == 'undefined') return;
  708.  
  709.                 $('.wpb_animate_when_almost_visible:not(.wpb_start_animation)').waypoint(function () {
  710.                     $(this).addClass('wpb_start_animation animated')
  711.                 }, {
  712.                         offset: '100%'
  713.                     });
  714.             },
  715.  
  716.             /**
  717.              *-------------------------------------------------------------------------------------------------------------------------------------------
  718.              * Social buttons class on load
  719.              *-------------------------------------------------------------------------------------------------------------------------------------------
  720.              */
  721.  
  722.             stickySocialButtons: function () {
  723.                 $('.woodmart-sticky-social').addClass('buttons-loaded');
  724.             },
  725.  
  726.             /**
  727.              *-------------------------------------------------------------------------------------------------------------------------------------------
  728.              * Photoswipe gallery
  729.              *-------------------------------------------------------------------------------------------------------------------------------------------
  730.              */
  731.  
  732.             photoswipeImages: function () {
  733.                 $('.photoswipe-images').each(function () {
  734.                     var $this = $(this);
  735.                     $this.on('click', 'a', function (e) {
  736.                         e.preventDefault();
  737.                         var index = $(e.currentTarget).data('index') - 1;
  738.                         var items = getGalleryItems($this, []);
  739.                         woodmartThemeModule.callPhotoSwipe(index, items);
  740.                     });
  741.                 });
  742.  
  743.                 var getGalleryItems = function ($gallery, items) {
  744.                     var src, width, height, title;
  745.  
  746.                     $gallery.find('a').each(function () {
  747.                         src = $(this).attr('href');
  748.                         width = $(this).data('width');
  749.                         height = $(this).data('height');
  750.                         title = $(this).attr('title');
  751.                         if (!isItemInArray(items, src)) {
  752.                             items.push({
  753.                                 src: src,
  754.                                 w: width,
  755.                                 h: height,
  756.                                 title: title
  757.                             });
  758.                         }
  759.                     });
  760.  
  761.                     return items;
  762.                 };
  763.  
  764.                 var isItemInArray = function (items, src) {
  765.                     var i;
  766.                     for (i = 0; i < items.length; i++) {
  767.                         if (items[i].src == src) {
  768.                             return true;
  769.                         }
  770.                     }
  771.  
  772.                     return false;
  773.                 };
  774.             },
  775.  
  776.             callPhotoSwipe: function (index, items) {
  777.                 var pswpElement = document.querySelectorAll('.pswp')[0];
  778.  
  779.                 if ($('body').hasClass('rtl')) {
  780.                     index = items.length - index - 1;
  781.                     items = items.reverse();
  782.                 }
  783.  
  784.                 // define options (if needed)
  785.                 var options = {
  786.                     // optionName: 'option value'
  787.                     // for example:
  788.                     index: index, // start at first slide
  789.                     shareButtons: [
  790.                         { id: 'facebook', label: woodmart_settings.share_fb, url: 'https://www.facebook.com/sharer/sharer.php?u={{url}}' },
  791.                         { id: 'twitter', label: woodmart_settings.tweet, url: 'https://twitter.com/intent/tweet?text={{text}}&url={{url}}' },
  792.                         {
  793.                             id: 'pinterest', label: woodmart_settings.pin_it, url: 'http://www.pinterest.com/pin/create/button/' +
  794.                                 '?url={{url}}&media={{image_url}}&description={{text}}'
  795.                         },
  796.                         { id: 'download', label: woodmart_settings.download_image, url: '{{raw_image_url}}', download: true }
  797.                     ],
  798.                     // getThumbBoundsFn: function(index) {
  799.  
  800.                     //     // get window scroll Y
  801.                     //     var pageYScroll = window.pageYOffset || document.documentElement.scrollTop;
  802.                     //     // optionally get horizontal scroll
  803.  
  804.                     //     // get position of element relative to viewport
  805.                     //     var rect = $target.offset();
  806.  
  807.                     //     // w = width
  808.                     //     return {x:rect.left, y:rect.top + pageYScroll, w:rect.width};
  809.  
  810.  
  811.                     // }
  812.                 };
  813.  
  814.                 // Initializes and opens PhotoSwipe
  815.                 var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
  816.                 gallery.init();
  817.             },
  818.  
  819.             /**
  820.              *-------------------------------------------------------------------------------------------------------------------------------------------
  821.              * Header banner
  822.              *-------------------------------------------------------------------------------------------------------------------------------------------
  823.              */
  824.  
  825.             headerBanner: function () {
  826.                 var banner_version = woodmart_settings.header_banner_version,
  827.                     banner_btn = woodmart_settings.header_banner_close_btn,
  828.                     banner_enabled = woodmart_settings.header_banner_enabled;
  829.                 if (Cookies.get('woodmart_tb_banner_' + banner_version) == 'closed' || banner_btn == false || banner_enabled == false) return;
  830.                 var banner = $('.header-banner');
  831.  
  832.                 if (!$('body').hasClass('page-template-maintenance')) {
  833.                     $('body').addClass('header-banner-display');
  834.                 }
  835.  
  836.                 banner.on('click', '.close-header-banner', function (e) {
  837.                     e.preventDefault();
  838.                     closeBanner();
  839.                 })
  840.  
  841.                 var closeBanner = function () {
  842.                     $('body').removeClass('header-banner-display').addClass('header-banner-hide');
  843.                     Cookies.set('woodmart_tb_banner_' + banner_version, 'closed', { expires: 60, path: '/' });
  844.                 };
  845.  
  846.             },
  847.  
  848.             /**
  849.              *-------------------------------------------------------------------------------------------------------------------------------------------
  850.              * Full screen menu
  851.              *-------------------------------------------------------------------------------------------------------------------------------------------
  852.              */
  853.  
  854.             fullScreenMenu: function () {
  855.                 $('.full-screen-burger-icon').on('click', function () {
  856.                     $('body').toggleClass('full-screen-menu-open');
  857.                 });
  858.  
  859.                 $(document).keyup(function (e) {
  860.                     if (e.keyCode === 27) $('.full-screen-close-icon').click();
  861.                 });
  862.  
  863.                 $('.full-screen-close-icon').on('click', function () {
  864.                     $('body').removeClass('full-screen-menu-open');
  865.                     setTimeout(function () {
  866.                         $('.full-screen-nav .menu-item-has-children').removeClass('sub-menu-open');
  867.                         $('.full-screen-nav .menu-item-has-children .icon-sub-fs').removeClass('up-icon');
  868.                     }, 200)
  869.                 });
  870.  
  871.                 $('.full-screen-nav .menu > .menu-item.menu-item-has-children, .full-screen-nav .menu-item-design-default.menu-item-has-children .menu-item-has-children').append('<span class="icon-sub-fs"></span>');
  872.  
  873.                 $('.full-screen-nav').on('click', '.icon-sub-fs', function (e) {
  874.                     var $icon = $(this),
  875.                         $parentItem = $icon.parent();
  876.  
  877.                     e.preventDefault();
  878.                     if ($parentItem.hasClass('sub-menu-open')) {
  879.                         $parentItem.removeClass('sub-menu-open');
  880.                         $icon.removeClass('up-icon');
  881.                     } else {
  882.                         $parentItem.siblings('.sub-menu-open').find('.icon-sub-fs').removeClass('up-icon');
  883.                         $parentItem.siblings('.sub-menu-open').removeClass('sub-menu-open');
  884.                         $parentItem.addClass('sub-menu-open');
  885.                         $icon.addClass('up-icon');
  886.                     }
  887.                 });
  888.             },
  889.  
  890.  
  891.             /**
  892.              *-------------------------------------------------------------------------------------------------------------------------------------------
  893.              * Mobile search icon
  894.              *-------------------------------------------------------------------------------------------------------------------------------------------
  895.              */
  896.  
  897.             mobileSearchIcon: function () {
  898.                 $('.mobile-search-icon.search-button').on('click', function (e) {
  899.                     e.preventDefault();
  900.                     if (!$('.mobile-nav').hasClass('act-mobile-menu')) {
  901.                         $('.mobile-nav').addClass('act-mobile-menu');
  902.                         $('.woodmart-close-side').addClass('woodmart-close-side-opened');
  903.                         $('.mobile-nav .searchform').find('input[type="text"]').focus();
  904.                     }
  905.                 });
  906.  
  907.             },
  908.  
  909.             /**
  910.              *-------------------------------------------------------------------------------------------------------------------------------------------
  911.              * Video Poster
  912.              *-------------------------------------------------------------------------------------------------------------------------------------------
  913.              */
  914.  
  915.             videoPoster: function () {
  916.                 $('.woodmart-video-poster-wrapper').on('click', function () {
  917.                     var videoWrapper = $(this),
  918.                         video = videoWrapper.parent().find('iframe'),
  919.                         videoScr = video.attr('src'),
  920.                         videoNewSrc = videoScr + '&autoplay=1';
  921.  
  922.                     if (videoScr.indexOf('vimeo.com') + 1) {
  923.                         videoNewSrc = videoScr + '?autoplay=1';
  924.                     }
  925.                     video.attr('src', videoNewSrc);
  926.                     videoWrapper.addClass('hidden-poster');
  927.                 })
  928.             },
  929.  
  930.             /**
  931.              *-------------------------------------------------------------------------------------------------------------------------------------------
  932.              * Header builder scripts for sticky header
  933.              *-------------------------------------------------------------------------------------------------------------------------------------------
  934.              */
  935.  
  936.             headerBuilder: function () {
  937.                 var $header = $('.whb-header'),
  938.                     $stickyElements = $('.whb-sticky-row'),
  939.                     $firstSticky = '',
  940.                     headerHeight = $header.find('.whb-main-header').outerHeight(),
  941.                     $window = $(window),
  942.                     isSticked = false,
  943.                     adminBarHeight = $('#wpadminbar').outerHeight(),
  944.                     stickAfter = 300,
  945.                     cloneHTML = '',
  946.                     isHideOnScroll = $header.hasClass('whb-hide-on-scroll');
  947.  
  948.                 $stickyElements.each(function () {
  949.                     if ($(this).outerHeight() > 10) {
  950.                         $firstSticky = $(this);
  951.                         return false;
  952.                     }
  953.                 });
  954.  
  955.  
  956.                 // Real header sticky option
  957.                 if ($header.hasClass('whb-sticky-real')) {
  958.  
  959.                     // if no sticky rows
  960.                     if ($firstSticky.length == 0 || $firstSticky.outerHeight() < 10) return;
  961.  
  962.                     $header.addClass('whb-sticky-prepared').css({
  963.                         paddingTop: headerHeight
  964.                     })
  965.  
  966.                     stickAfter = $firstSticky.offset().top - adminBarHeight
  967.                 }
  968.  
  969.  
  970.                 // Sticky header clone
  971.  
  972.                 if ($header.hasClass('whb-sticky-clone')) {
  973.                     var data = []
  974.                     data['cloneClass'] = $header.find('.whb-general-header').attr('class')
  975.  
  976.                     if (isHideOnScroll) {
  977.                         data['wrapperClasses'] = 'whb-hide-on-scroll';
  978.                     }
  979.  
  980.                     cloneHTML = woodmart_settings.whb_header_clone
  981.  
  982.                     cloneHTML = cloneHTML.replace(/<%([^%>]+)?%>/g, function (replacement) {
  983.                         var selector = replacement.slice(2, -2)
  984.  
  985.                         return $header.find(selector).length
  986.                             ? $('<div>')
  987.                                 .append($header.find(selector).first().clone())
  988.                                 .html()
  989.                             : (data[selector] !== undefined) ? data[selector] : ''
  990.                     })
  991.  
  992.                     $header.after(cloneHTML)
  993.                     $header = $header.parent().find('.whb-clone')
  994.  
  995.                     $header.find('.whb-row').removeClass('whb-flex-equal-sides').addClass('whb-flex-flex-middle');
  996.                 }
  997.  
  998.                 if ($('.whb-header').hasClass('whb-scroll-slide')) {
  999.                     stickAfter = headerHeight + adminBarHeight
  1000.                 }
  1001.  
  1002.                 var previousScroll;
  1003.  
  1004.                 $window.on('scroll', function () {
  1005.                     var after = stickAfter;
  1006.                     var currentScroll = $(window).scrollTop();
  1007.                     var windowHeight = $(window).height();
  1008.                     var documentHeight = $(document).height();
  1009.                     if ($('.header-banner').length > 0 && $('body').hasClass('header-banner-display')) {
  1010.                         after += $('.header-banner').outerHeight();
  1011.                     }
  1012.  
  1013.                     if (!$('.close-header-banner').length && $header.hasClass('whb-scroll-stick')) {
  1014.                         after = stickAfter
  1015.                     }
  1016.  
  1017.                     if (currentScroll > after) {
  1018.                         stickHeader();
  1019.                     } else {
  1020.                         unstickHeader();
  1021.                     }
  1022.  
  1023.                     var startAfter = 100;
  1024.  
  1025.                     if ($header.hasClass('whb-scroll-stick')) {
  1026.                         startAfter = 500;
  1027.                     }
  1028.  
  1029.                     if (isHideOnScroll) {
  1030.                         if (previousScroll - currentScroll > 0 && currentScroll > after ) {
  1031.                             $header.addClass('whb-scroll-up');
  1032.                             $header.removeClass('whb-scroll-down');
  1033.                         } else if (currentScroll - previousScroll > 0 && currentScroll + windowHeight != documentHeight && currentScroll > (after + startAfter)) {
  1034.                             $header.addClass('whb-scroll-down');
  1035.                             $header.removeClass('whb-scroll-up');
  1036.                         } else if (currentScroll <= after) {
  1037.                             $header.removeClass('whb-scroll-down');
  1038.                             $header.removeClass('whb-scroll-up');
  1039.                         } else if (currentScroll + windowHeight >= documentHeight - 5) {
  1040.                             $header.addClass('whb-scroll-up');
  1041.                             $header.removeClass('whb-scroll-down');
  1042.                         }
  1043.                     }
  1044.  
  1045.                     previousScroll = currentScroll;
  1046.                 });
  1047.  
  1048.                 function stickHeader() {
  1049.                     if (isSticked) return
  1050.                     isSticked = true
  1051.                     $header.addClass('whb-sticked')
  1052.                 }
  1053.  
  1054.                 function unstickHeader() {
  1055.                     if (!isSticked) return
  1056.  
  1057.                     isSticked = false
  1058.                     $header.removeClass('whb-sticked')
  1059.                 }
  1060.             },
  1061.  
  1062.  
  1063.             /**
  1064.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1065.              * Counter shortcode method
  1066.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1067.              */
  1068.             counterShortcode: function (counter) {
  1069.                 if (counter.attr('data-state') == 'done' || counter.text() != counter.data('final')) {
  1070.                     return;
  1071.                 }
  1072.                 counter.prop('Counter', 0).animate({
  1073.                     Counter: counter.text()
  1074.                 }, {
  1075.                         duration: 3000,
  1076.                         easing: 'swing',
  1077.                         step: function (now) {
  1078.                             if (now >= counter.data('final')) {
  1079.                                 counter.attr('data-state', 'done');
  1080.                             }
  1081.                             counter.text(Math.ceil(now));
  1082.                         }
  1083.                     });
  1084.             },
  1085.  
  1086.             /**
  1087.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1088.              * Activate methods in viewport
  1089.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1090.              */
  1091.             visibleElements: function () {
  1092.  
  1093.                 $('.woodmart-counter .counter-value').each(function () {
  1094.                     $(this).waypoint(function () {
  1095.                         woodmartThemeModule.counterShortcode($(this));
  1096.                     }, { offset: '100%' });
  1097.                 });
  1098.  
  1099.             },
  1100.  
  1101.  
  1102.             /**
  1103.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1104.              * Banner hover effect with jquery panr
  1105.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1106.              */
  1107.             bannersHover: function () {
  1108.                 if (typeof ($.fn.panr) == 'undefined') return;
  1109.                 $('.promo-banner.banner-hover-parallax').panr({
  1110.                     sensitivity: 20,
  1111.                     scale: false,
  1112.                     scaleOnHover: true,
  1113.                     scaleTo: 1.15,
  1114.                     scaleDuration: .34,
  1115.                     panY: true,
  1116.                     panX: true,
  1117.                     panDuration: 0.5,
  1118.                     resetPanOnMouseLeave: true
  1119.                 });
  1120.             },
  1121.  
  1122.  
  1123.             /**
  1124.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1125.              * Portfolio hover effects
  1126.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1127.              */
  1128.             portfolioEffects: function () {
  1129.                 if (typeof ($.fn.panr) == 'undefined') return;
  1130.                 $('.woodmart-portfolio-holder .portfolio-parallax').panr({
  1131.                     sensitivity: 15,
  1132.                     scale: false,
  1133.                     scaleOnHover: true,
  1134.                     scaleTo: 1.12,
  1135.                     scaleDuration: 0.45,
  1136.                     panY: true,
  1137.                     panX: true,
  1138.                     panDuration: 1.5,
  1139.                     resetPanOnMouseLeave: true
  1140.                 });
  1141.             },
  1142.  
  1143.             /**
  1144.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1145.              * Promo popup
  1146.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1147.              */
  1148.  
  1149.             promoPopup: function () {
  1150.                 var promo_version = woodmart_settings.promo_version;
  1151.  
  1152.                 if ($('body').hasClass('page-template-maintenance') || woodmart_settings.enable_popup != 'yes' || (woodmart_settings.promo_popup_hide_mobile == 'yes' && $(window).width() < 768)) return;
  1153.  
  1154.                 var popup = $('.woodmart-promo-popup'),
  1155.                     shown = false,
  1156.                     pages = Cookies.get('woodmart_shown_pages');
  1157.  
  1158.                 var showPopup = function () {
  1159.                     $.magnificPopup.open({
  1160.                         items: {
  1161.                             src: '.woodmart-promo-popup'
  1162.                         },
  1163.                         type: 'inline',
  1164.                         removalDelay: 500, //delay removal by X to allow out-animation
  1165.                         tClose: woodmart_settings.close,
  1166.                         tLoading: woodmart_settings.loading,
  1167.                         callbacks: {
  1168.                             beforeOpen: function () {
  1169.                                 this.st.mainClass = woodmartTheme.popupEffect + ' promo-popup-wrapper';
  1170.                             },
  1171.                             open: function () {
  1172.                                 // Will fire when this exact popup is opened
  1173.                                 // this - is Magnific Popup object
  1174.                             },
  1175.                             close: function () {
  1176.                                 Cookies.set('woodmart_popup_' + promo_version, 'shown', { expires: 7, path: '/' });
  1177.                             }
  1178.                             // e.t.c.
  1179.                         }
  1180.                     });
  1181.                     $(document).trigger('wood-images-loaded');
  1182.                 };
  1183.  
  1184.                 $('.woodmart-open-newsletter').on('click', function (e) {
  1185.                     e.preventDefault();
  1186.                     showPopup();
  1187.                 })
  1188.  
  1189.                 if (!pages) pages = 0;
  1190.  
  1191.                 if (pages < woodmart_settings.popup_pages) {
  1192.                     pages++;
  1193.                     Cookies.set('woodmart_shown_pages', pages, { expires: 7, path: '/' });
  1194.                     return false;
  1195.                 }
  1196.  
  1197.                 if (Cookies.get('woodmart_popup_' + promo_version) != 'shown') {
  1198.                     if (woodmart_settings.popup_event == 'scroll') {
  1199.                         $(window).scroll(function () {
  1200.                             if (shown) return false;
  1201.                             if ($(document).scrollTop() >= woodmart_settings.popup_scroll) {
  1202.                                 showPopup();
  1203.                                 shown = true;
  1204.                             }
  1205.                         });
  1206.                     } else {
  1207.                         setTimeout(function () {
  1208.                             showPopup();
  1209.                         }, woodmart_settings.popup_delay);
  1210.                     }
  1211.                 }
  1212.  
  1213.  
  1214.             },
  1215.  
  1216.             /**
  1217.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1218.              * Content in popup element
  1219.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1220.              */
  1221.  
  1222.             contentPopup: function () {
  1223.                 var popup = $('.woodmart-open-popup');
  1224.  
  1225.                 popup.magnificPopup({
  1226.                     type: 'inline',
  1227.                     removalDelay: 500, //delay removal by X to allow out-animation
  1228.                     tClose: woodmart_settings.close,
  1229.                     tLoading: woodmart_settings.loading,
  1230.                     callbacks: {
  1231.                         beforeOpen: function () {
  1232.                             this.st.mainClass = woodmartTheme.popupEffect + ' content-popup-wrapper';
  1233.                         },
  1234.  
  1235.                         open: function () {
  1236.                             $(document).trigger('wood-images-loaded');
  1237.                         }
  1238.                     }
  1239.                 });
  1240.  
  1241.             },
  1242.  
  1243.             /**
  1244.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1245.              * Cookies law
  1246.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1247.              */
  1248.  
  1249.             cookiesPopup: function () {
  1250.                 var cookies_version = woodmart_settings.cookies_version;
  1251.                 if (Cookies.get('woodmart_cookies_' + cookies_version) == 'accepted') return;
  1252.                 var popup = $('.woodmart-cookies-popup');
  1253.  
  1254.                 setTimeout(function () {
  1255.                     popup.addClass('popup-display');
  1256.                     popup.on('click', '.cookies-accept-btn', function (e) {
  1257.                         e.preventDefault();
  1258.                         acceptCookies();
  1259.                     })
  1260.                 }, 2500);
  1261.  
  1262.                 var acceptCookies = function () {
  1263.                     popup.removeClass('popup-display').addClass('popup-hide');
  1264.                     Cookies.set('woodmart_cookies_' + cookies_version, 'accepted', { expires: 60, path: '/' });
  1265.                 };
  1266.             },
  1267.  
  1268.             /**
  1269.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1270.              * Google map
  1271.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1272.              */
  1273.  
  1274.             googleMap: function () {
  1275.                 var gmap = $(".google-map-container-with-content");
  1276.  
  1277.                 $(window).resize(function () {
  1278.                     gmap.css({
  1279.                         'height': gmap.find('.woodmart-google-map.with-content').outerHeight()
  1280.                     })
  1281.                 });
  1282.  
  1283.             },
  1284.  
  1285.             /**
  1286.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1287.              * Menu preparation
  1288.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1289.              */
  1290.  
  1291.             menuSetUp: function () {
  1292.                 var hasChildClass = 'menu-item-has-children',
  1293.                     mainMenu = $('.woodmart-navigation').find('ul.menu'),
  1294.                     lis = mainMenu.find(' > li'),
  1295.                     openedClass = 'item-menu-opened';
  1296.  
  1297.                 $('.mobile-nav').find('ul.site-mobile-menu').find(' > li').has('.sub-menu-dropdown').addClass(hasChildClass);
  1298.  
  1299.                 mainMenu.on('click', ' > .item-event-click > a', function (e) {
  1300.                     e.preventDefault();
  1301.                     if (!$(this).parent().hasClass(openedClass)) {
  1302.                         $('.' + openedClass).removeClass(openedClass);
  1303.                     }
  1304.                     $(this).parent().toggleClass(openedClass);
  1305.                 });
  1306.  
  1307.                 $(document).on('click', function (e) {
  1308.                     var target = e.target;
  1309.                     if ($('.' + openedClass).length > 0 && !$(target).is('.item-event-hover') && !$(target).parents().is('.item-event-hover') && !$(target).parents().is('.' + openedClass + '')) {
  1310.                         mainMenu.find('.' + openedClass + '').removeClass(openedClass);
  1311.                         return false;
  1312.                     }
  1313.                 });
  1314.  
  1315.                 var menuForIPad = function () {
  1316.                     if ($(window).width() <= 1024) {
  1317.                         mainMenu.find(' > .menu-item-has-children.item-event-hover').each(function () {
  1318.                             $(this).data('original-event', 'hover').removeClass('item-event-hover').addClass('item-event-click');
  1319.                         });
  1320.                     } else {
  1321.                         mainMenu.find(' > .item-event-click').each(function () {
  1322.                             if ($(this).data('original-event') == 'hover') {
  1323.                                 $(this).removeClass('item-event-click').addClass('item-event-hover');
  1324.                             }
  1325.                         });
  1326.                     }
  1327.                 };
  1328.  
  1329.                 $(window).on('resize', menuForIPad);
  1330.             },
  1331.             /**
  1332.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1333.              * Keep navigation dropdowns in the screen
  1334.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1335.              */
  1336.  
  1337.             menuOffsets: function () {
  1338.  
  1339.                 var mainMenu = $('.main-nav, .whb-secondary-menu').find('ul.menu'),
  1340.                     lis = mainMenu.find(' > li.menu-item-design-sized, li.menu-item-design-full-width');
  1341.  
  1342.  
  1343.                 mainMenu.on('hover', ' > li.menu-item-design-sized, li.menu-item-design-full-width', function (e) {
  1344.                     setOffset($(this));
  1345.                 });
  1346.  
  1347.                 var setOffset = function (li) {
  1348.  
  1349.                     var dropdown = li.find(' > .sub-menu-dropdown'),
  1350.                         styleID = 'arrow-offset',
  1351.                         siteWrapper = $('.website-wrapper');
  1352.  
  1353.                     dropdown.attr('style', '');
  1354.  
  1355.                     var dropdownWidth = dropdown.outerWidth(),
  1356.                         dropdownOffset = dropdown.offset(),
  1357.                         screenWidth = $(window).width(),
  1358.                         bodyRight = siteWrapper.outerWidth() + siteWrapper.offset().left,
  1359.                         viewportWidth = $('body').hasClass('wrapper-boxed') || $('body').hasClass('wrapper-boxed-2') ? bodyRight : screenWidth,
  1360.                         extraSpace = (li.hasClass('menu-item-design-full-width')) ? 0 : 10;
  1361.  
  1362.                     if (!dropdownWidth || !dropdownOffset) return;
  1363.  
  1364.                     var dropdownOffsetRight = screenWidth - dropdownOffset.left - dropdownWidth;
  1365.  
  1366.                     if ($('body').hasClass('rtl') && dropdownOffsetRight + dropdownWidth >= viewportWidth && (li.hasClass('menu-item-design-sized') || li.hasClass('menu-item-design-full-width'))) {
  1367.                         // If right point is not in the viewport
  1368.                         var toLeft = dropdownOffsetRight + dropdownWidth - viewportWidth;
  1369.  
  1370.                         dropdown.css({
  1371.                             right: - toLeft - extraSpace
  1372.                         });
  1373.  
  1374.                     } else if (dropdownOffset.left + dropdownWidth >= viewportWidth && (li.hasClass('menu-item-design-sized') || li.hasClass('menu-item-design-full-width'))) {
  1375.                         // If right point is not in the viewport
  1376.                         var toRight = dropdownOffset.left + dropdownWidth - viewportWidth;
  1377.  
  1378.                         dropdown.css({
  1379.                             left: - toRight - extraSpace
  1380.                         });
  1381.                     }
  1382.  
  1383.                 };
  1384.  
  1385.                 lis.each(function () {
  1386.                     setOffset($(this));
  1387.                     $(this).addClass('with-offsets');
  1388.                 });
  1389.             },
  1390.  
  1391.  
  1392.             /**
  1393.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1394.              * One page menu
  1395.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1396.              */
  1397.  
  1398.             onePageMenu: function () {
  1399.  
  1400.                 var scrollToRow = function (hash) {
  1401.                     var row = $('#' + hash);
  1402.  
  1403.                     if (row.length < 1) return;
  1404.  
  1405.                     var position = row.offset().top;
  1406.  
  1407.                     $('html, body').animate({
  1408.                         scrollTop: position - woodmart_settings.one_page_menu_offset
  1409.                     }, 800);
  1410.  
  1411.                     setTimeout(function () {
  1412.                         activeMenuItem(hash);
  1413.                     }, 800);
  1414.                 };
  1415.  
  1416.                 var activeMenuItem = function (hash) {
  1417.                     var itemHash;
  1418.                     $('.onepage-link').each(function () {
  1419.                         itemHash = $(this).find('> a').attr('href').split('#')[1];
  1420.  
  1421.                         if (itemHash == hash) {
  1422.                             $('.onepage-link').removeClass('current-menu-item');
  1423.                             $(this).addClass('current-menu-item');
  1424.                         }
  1425.  
  1426.                     });
  1427.                 };
  1428.  
  1429.                 $('body').on('click', '.onepage-link > a', function (e) {
  1430.                     var $this = $(this),
  1431.                         hash = $this.attr('href').split('#')[1];
  1432.  
  1433.                     if ($('#' + hash).length < 1) return;
  1434.  
  1435.                     e.preventDefault();
  1436.  
  1437.                     scrollToRow(hash);
  1438.  
  1439.                     // close mobile menu
  1440.                     $('.woodmart-close-side').trigger('click');
  1441.                 });
  1442.  
  1443.                 if ($('.onepage-link').length > 0) {
  1444.                     $('.entry-content > .vc_section, .entry-content > .vc_row').waypoint(function () {
  1445.                         var hash = $(this).attr('id');
  1446.                         activeMenuItem(hash);
  1447.                     }, { offset: 150 });
  1448.  
  1449.                     // $('.onepage-link').removeClass('current-menu-item');
  1450.  
  1451.                     // URL contains hash
  1452.                     var locationHash = window.location.hash.split('#')[1];
  1453.  
  1454.                     if (window.location.hash.length > 1) {
  1455.                         setTimeout(function () {
  1456.                             scrollToRow(locationHash);
  1457.                         }, 500);
  1458.                     }
  1459.  
  1460.                 }
  1461.             },
  1462.  
  1463.  
  1464.             /**
  1465.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1466.              * mobile responsive navigation
  1467.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1468.              */
  1469.  
  1470.             mobileNavigation: function () {
  1471.  
  1472.                 var body = $("body"),
  1473.                     mobileNav = $(".mobile-nav"),
  1474.                     wrapperSite = $(".website-wrapper"),
  1475.                     dropDownCat = $(".mobile-nav .site-mobile-menu .menu-item-has-children"),
  1476.                     elementIcon = '<span class="icon-sub-menu"></span>',
  1477.                     butOpener = $(".icon-sub-menu");
  1478.  
  1479.                 var closeSide = $('.woodmart-close-side');
  1480.  
  1481.                 dropDownCat.append(elementIcon);
  1482.  
  1483.                 mobileNav.on("click", ".icon-sub-menu", function (e) {
  1484.                     e.preventDefault();
  1485.  
  1486.                     if ($(this).parent().hasClass("opener-page")) {
  1487.                         $(this).parent().removeClass("opener-page").find("> ul").slideUp(200);
  1488.                         $(this).parent().removeClass("opener-page").find(".sub-menu-dropdown .container > ul, .sub-menu-dropdown > ul").slideUp(200);
  1489.                         $(this).parent().find('> .icon-sub-menu').removeClass("up-icon");
  1490.                     } else {
  1491.                         $(this).parent().addClass("opener-page").find("> ul").slideDown(200);
  1492.                         $(this).parent().addClass("opener-page").find(".sub-menu-dropdown .container > ul, .sub-menu-dropdown > ul").slideDown(200);
  1493.                         $(this).parent().find('> .icon-sub-menu').addClass("up-icon");
  1494.                     }
  1495.                 });
  1496.  
  1497.                 mobileNav.on('click', '.mobile-nav-tabs li', function () {
  1498.                     if ($(this).hasClass('active')) return;
  1499.                     var menuName = $(this).data('menu');
  1500.                     $(this).parent().find('.active').removeClass('active');
  1501.                     $(this).addClass('active');
  1502.                     $('.mobile-menu-tab').removeClass('active');
  1503.                     $('.mobile-' + menuName + '-menu').addClass('active');
  1504.                 });
  1505.  
  1506.                 body.on("click", ".mobile-nav-icon", function () {
  1507.  
  1508.                     if (mobileNav.hasClass("act-mobile-menu")) {
  1509.                         closeMenu();
  1510.                     } else {
  1511.                         openMenu();
  1512.                     }
  1513.  
  1514.                 });
  1515.  
  1516.                 body.on("click touchstart", ".woodmart-close-side", function () {
  1517.                     closeMenu();
  1518.                 });
  1519.  
  1520.                 body.on('click', '.mobile-nav .login-side-opener', function () {
  1521.                     closeMenu();
  1522.                 });
  1523.  
  1524.                 function openMenu() {
  1525.                     mobileNav.addClass("act-mobile-menu");
  1526.                     closeSide.addClass('woodmart-close-side-opened');
  1527.                 }
  1528.  
  1529.                 function closeMenu() {
  1530.                     mobileNav.removeClass("act-mobile-menu");
  1531.                     closeSide.removeClass('woodmart-close-side-opened');
  1532.                     $('.mobile-nav .searchform input[type=text]').blur();
  1533.                 }
  1534.             },
  1535.  
  1536.             /**
  1537.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1538.              * Simple dropdown for category select on search form
  1539.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1540.              */
  1541.             simpleDropdown: function () {
  1542.  
  1543.                 $('.input-dropdown-inner').each(function () {
  1544.                     var dd = $(this);
  1545.                     var btn = dd.find('> a');
  1546.                     var input = dd.find('> input');
  1547.                     var list = dd.find('> .list-wrapper');
  1548.  
  1549.                     inputPadding();
  1550.  
  1551.                     $(document).on('click', function (e) {
  1552.                         var target = e.target;
  1553.                         if (dd.hasClass('dd-shown') && !$(target).is('.input-dropdown-inner') && !$(target).parents().is('.input-dropdown-inner')) {
  1554.                             hideList();
  1555.                             return false;
  1556.                         }
  1557.                     });
  1558.  
  1559.                     btn.on('click', function (e) {
  1560.                         e.preventDefault();
  1561.  
  1562.                         if (dd.hasClass('dd-shown')) {
  1563.                             hideList();
  1564.                         } else {
  1565.                             showList();
  1566.                         }
  1567.                         return false;
  1568.                     });
  1569.  
  1570.                     list.on('click', 'a', function (e) {
  1571.                         e.preventDefault();
  1572.                         var value = $(this).data('val');
  1573.                         var label = $(this).text();
  1574.                         list.find('.current-item').removeClass('current-item');
  1575.                         $(this).parent().addClass('current-item');
  1576.                         if (value != 0) {
  1577.                             list.find('ul:not(.children) > li:first-child').show();
  1578.                         } else if (value == 0) {
  1579.                             list.find('ul:not(.children) > li:first-child').hide();
  1580.                         }
  1581.                         btn.text(label);
  1582.                         input.val(value).trigger('cat_selected');
  1583.                         hideList();
  1584.                         inputPadding();
  1585.                     });
  1586.  
  1587.  
  1588.                     function showList() {
  1589.                         dd.addClass('dd-shown');
  1590.                         list.slideDown(100);
  1591.                         if (typeof ($.fn.devbridgeAutocomplete) != 'undefined') {
  1592.                             dd.parent().siblings('[type="text"]').devbridgeAutocomplete('hide');
  1593.                         }
  1594.                         setTimeout(function () {
  1595.                             woodmartThemeModule.nanoScroller();
  1596.                         }, 300);
  1597.                     }
  1598.  
  1599.                     function hideList() {
  1600.                         dd.removeClass('dd-shown');
  1601.                         list.slideUp(100);
  1602.                     }
  1603.  
  1604.                     function inputPadding() {
  1605.                         if ($(window).width() <= 768) return;
  1606.                         var paddingValue = dd.innerWidth() + dd.parent().siblings('.searchsubmit').innerWidth() + 17,
  1607.                             padding = 'padding-right';
  1608.                         if ($('body').hasClass('rtl')) padding = 'padding-left';
  1609.  
  1610.                         dd.parent().parent().find('.s').css(padding, paddingValue);
  1611.                     }
  1612.                 });
  1613.  
  1614.             },
  1615.  
  1616.             /**
  1617.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1618.              * Function to make columns the same height
  1619.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1620.              */
  1621.             equalizeColumns: function () {
  1622.  
  1623.                 $.fn.woodmart_equlize = function (options) {
  1624.  
  1625.                     var settings = $.extend({
  1626.                         child: "",
  1627.                     }, options);
  1628.  
  1629.                     var that = this;
  1630.  
  1631.                     if (settings.child != '') {
  1632.                         that = this.find(settings.child);
  1633.                     }
  1634.  
  1635.                     var resize = function () {
  1636.  
  1637.                         var maxHeight = 0;
  1638.                         var height;
  1639.                         that.each(function () {
  1640.                             $(this).attr('style', '');
  1641.                             if ($(window).width() > 767 && $(this).outerHeight() > maxHeight)
  1642.                                 maxHeight = $(this).outerHeight();
  1643.                         });
  1644.  
  1645.                         that.each(function () {
  1646.                             $(this).css({
  1647.                                 minHeight: maxHeight
  1648.                             });
  1649.                         });
  1650.  
  1651.                     }
  1652.  
  1653.                     $(window).on('resize', function () {
  1654.                         resize();
  1655.                     });
  1656.                     setTimeout(function () {
  1657.                         resize();
  1658.                     }, 200);
  1659.                     setTimeout(function () {
  1660.                         resize();
  1661.                     }, 500);
  1662.                     setTimeout(function () {
  1663.                         resize();
  1664.                     }, 800);
  1665.                 }
  1666.  
  1667.                 $('.equal-columns').each(function () {
  1668.                     $(this).woodmart_equlize({
  1669.                         child: '> [class*=col-]'
  1670.                     });
  1671.                 });
  1672.             },
  1673.  
  1674.  
  1675.             /**
  1676.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1677.              * Enable masonry grid for blog
  1678.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1679.              */
  1680.             blogMasonry: function () {
  1681.                 if (typeof ($.fn.isotope) == 'undefined' || typeof ($.fn.imagesLoaded) == 'undefined') return;
  1682.                 var $container = $('.masonry-container');
  1683.  
  1684.                 // initialize Masonry after all images have loaded
  1685.                 $container.imagesLoaded(function () {
  1686.                     $container.isotope({
  1687.                         gutter: 0,
  1688.                         isOriginLeft: !$('body').hasClass('rtl'),
  1689.                         itemSelector: '.blog-design-masonry, .blog-design-mask, .masonry-item'
  1690.                     });
  1691.                 });
  1692.  
  1693.  
  1694.                 //Portfolio filters
  1695.                 $('.masonry-filter').on('click', 'a', function (e) {
  1696.                     e.preventDefault();
  1697.                     setTimeout(function () {
  1698.                         jQuery(document).trigger('wood-images-loaded');
  1699.                     }, 300);
  1700.  
  1701.                     $('.masonry-filter').find('.filter-active').removeClass('filter-active');
  1702.                     $(this).addClass('filter-active');
  1703.                     var filterValue = $(this).attr('data-filter');
  1704.                     $(this).parents('.portfolio-filter').next('.masonry-container.woodmart-portfolio-holder').isotope({
  1705.                         filter: filterValue
  1706.                     });
  1707.                 });
  1708.  
  1709.             },
  1710.  
  1711.             /**
  1712.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1713.              * Helper function that make btn click when you scroll page to it
  1714.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1715.              */
  1716.             clickOnScrollButton: function (btnClass, destroy, offset) {
  1717.                 if (typeof $.waypoints != 'function') return;
  1718.  
  1719.                 var $btn = $(btnClass);
  1720.                 if (destroy) {
  1721.                     $btn.waypoint('destroy');
  1722.                 }
  1723.  
  1724.                 if (!offset) {
  1725.                     offset = 0;
  1726.                 }
  1727.  
  1728.                 $btn.waypoint(function () {
  1729.                     $btn.trigger('click');
  1730.                 }, {
  1731.                         offset: function () {
  1732.                             return $(window).outerHeight() + parseInt(offset);
  1733.                         }
  1734.                     });
  1735.             },
  1736.  
  1737.             /**
  1738.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1739.              * Load more button for blog shortcode
  1740.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1741.              */
  1742.             blogLoadMore: function () {
  1743.                 var btnClass = '.woodmart-blog-load-more.load-on-scroll',
  1744.                     process = false;
  1745.  
  1746.                 woodmartThemeModule.clickOnScrollButton(btnClass, false, false);
  1747.  
  1748.                 $('.woodmart-blog-load-more').on('click', function (e) {
  1749.                     e.preventDefault();
  1750.  
  1751.                     if (process || $(this).hasClass('no-more-posts')) return;
  1752.  
  1753.                     process = true;
  1754.  
  1755.                     var $this = $(this),
  1756.                         holder = $this.parent().siblings('.woodmart-blog-holder'),
  1757.                         source = holder.data('source'),
  1758.                         action = 'woodmart_get_blog_' + source,
  1759.                         ajaxurl = woodmart_settings.ajaxurl,
  1760.                         dataType = 'json',
  1761.                         method = 'POST',
  1762.                         atts = holder.data('atts'),
  1763.                         paged = holder.data('paged');
  1764.  
  1765.                     $this.addClass('loading');
  1766.  
  1767.                     var data = {
  1768.                         atts: atts,
  1769.                         paged: paged,
  1770.                         action: action,
  1771.                     };
  1772.  
  1773.                     if (source == 'main_loop') {
  1774.                         ajaxurl = $(this).attr('href');
  1775.                         method = 'GET';
  1776.                         data = {};
  1777.                     }
  1778.  
  1779.                     $.ajax({
  1780.                         url: ajaxurl,
  1781.                         data: data,
  1782.                         dataType: dataType,
  1783.                         method: method,
  1784.                         success: function (data) {
  1785.  
  1786.                             var items = $(data.items);
  1787.  
  1788.                             if (items) {
  1789.                                 if (holder.hasClass('masonry-container')) {
  1790.                                     // initialize Masonry after all images have loaded  
  1791.                                     holder.append(items).isotope('appended', items);
  1792.                                     holder.imagesLoaded().progress(function () {
  1793.                                         holder.isotope('layout');
  1794.                                         woodmartThemeModule.clickOnScrollButton(btnClass, true, false);
  1795.                                     });
  1796.                                 } else {
  1797.                                     holder.append(items);
  1798.                                     woodmartThemeModule.clickOnScrollButton(btnClass, true, false);
  1799.                                 }
  1800.  
  1801.                                 holder.data('paged', paged + 1);
  1802.  
  1803.                                 if (source == 'main_loop') {
  1804.                                     $this.attr('href', data.nextPage);
  1805.                                     if (data.status == 'no-more-posts') {
  1806.                                         $this.hide().remove();
  1807.                                     }
  1808.                                 }
  1809.                             }
  1810.  
  1811.                             if (data.status == 'no-more-posts') {
  1812.                                 $this.addClass('no-more-posts');
  1813.                                 $this.hide();
  1814.                             }
  1815.  
  1816.                         },
  1817.                         error: function (data) {
  1818.                             console.log('ajax error');
  1819.                         },
  1820.                         complete: function () {
  1821.                             $this.removeClass('loading');
  1822.                             process = false;
  1823.                         },
  1824.                     });
  1825.  
  1826.                 });
  1827.  
  1828.             },
  1829.  
  1830.  
  1831.             /**
  1832.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1833.              * Load more button for portfolio shortcode
  1834.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1835.              */
  1836.             portfolioLoadMore: function () {
  1837.  
  1838.                 if (typeof $.waypoints != 'function') return;
  1839.  
  1840.                 var waypoint = $('.woodmart-portfolio-load-more.load-on-scroll').waypoint(function () {
  1841.                     $('.woodmart-portfolio-load-more.load-on-scroll').trigger('click');
  1842.                 }, { offset: '100%' }),
  1843.                     process = false;
  1844.  
  1845.                 $('.woodmart-portfolio-load-more').on('click', function (e) {
  1846.                     e.preventDefault();
  1847.  
  1848.                     if (process || $(this).hasClass('no-more-posts')) return;
  1849.  
  1850.                     process = true;
  1851.  
  1852.                     var $this = $(this),
  1853.                         holder = $this.parent().parent().find('.woodmart-portfolio-holder'),
  1854.                         source = holder.data('source'),
  1855.                         action = 'woodmart_get_portfolio_' + source,
  1856.                         ajaxurl = woodmart_settings.ajaxurl,
  1857.                         dataType = 'json',
  1858.                         method = 'POST',
  1859.                         timeout,
  1860.                         atts = holder.data('atts'),
  1861.                         paged = holder.data('paged');
  1862.  
  1863.                     $this.addClass('loading');
  1864.  
  1865.                     var data = {
  1866.                         atts: atts,
  1867.                         paged: paged,
  1868.                         action: action,
  1869.                     };
  1870.  
  1871.                     if (source == 'main_loop') {
  1872.                         ajaxurl = $(this).attr('href');
  1873.                         method = 'GET';
  1874.                         data = {};
  1875.                     }
  1876.  
  1877.                     $.ajax({
  1878.                         url: ajaxurl,
  1879.                         data: data,
  1880.                         dataType: dataType,
  1881.                         method: method,
  1882.                         success: function (data) {
  1883.  
  1884.                             var items = $(data.items);
  1885.  
  1886.                             if (items) {
  1887.                                 if (holder.hasClass('masonry-container')) {
  1888.                                     // initialize Masonry after all images have loaded
  1889.                                     holder.append(items).isotope('appended', items);
  1890.                                     holder.imagesLoaded().progress(function () {
  1891.                                         holder.isotope('layout');
  1892.  
  1893.                                         clearTimeout(timeout);
  1894.  
  1895.                                         timeout = setTimeout(function () {
  1896.                                             $('.woodmart-portfolio-load-more.load-on-scroll').waypoint('destroy');
  1897.                                             waypoint = $('.woodmart-portfolio-load-more.load-on-scroll').waypoint(function () {
  1898.                                                 $('.woodmart-portfolio-load-more.load-on-scroll').trigger('click');
  1899.                                             }, { offset: '100%' });
  1900.                                         }, 1000);
  1901.                                     });
  1902.                                 } else {
  1903.                                     holder.append(items);
  1904.                                 }
  1905.  
  1906.                                 holder.data('paged', paged + 1);
  1907.  
  1908.                                 $this.attr('href', data.nextPage);
  1909.                             }
  1910.  
  1911.                             woodmartThemeModule.mfpPopup();
  1912.                             woodmartThemeModule.portfolioEffects();
  1913.  
  1914.                             if (data.status == 'no-more-posts') {
  1915.                                 $this.addClass('no-more-posts');
  1916.                                 $this.hide();
  1917.                             }
  1918.  
  1919.                         },
  1920.                         error: function (data) {
  1921.                             console.log('ajax error');
  1922.                         },
  1923.                         complete: function () {
  1924.                             $this.removeClass('loading');
  1925.                             process = false;
  1926.                         },
  1927.                     });
  1928.  
  1929.                 });
  1930.  
  1931.             },
  1932.  
  1933.             /**
  1934.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1935.              * MEGA MENU
  1936.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1937.              */
  1938.             sidebarMenu: function () {
  1939.                 var heightMegaMenu = $(".widget_nav_mega_menu #menu-categories").height();
  1940.                 var heightMegaNavigation = $(".categories-menu-dropdown").height();
  1941.                 var subMenuHeight = $(".widget_nav_mega_menu ul > li.menu-item-design-sized > .sub-menu-dropdown, .widget_nav_mega_menu ul > li.menu-item-design-full-width > .sub-menu-dropdown");
  1942.                 var megaNavigationHeight = $(".categories-menu-dropdown ul > li.menu-item-design-sized > .sub-menu-dropdown, .categories-menu-dropdown ul > li.menu-item-design-full-width > .sub-menu-dropdown");
  1943.                 subMenuHeight.css(
  1944.                     "min-height", heightMegaMenu + "px"
  1945.                 );
  1946.  
  1947.                 megaNavigationHeight.css(
  1948.                     "min-height", heightMegaNavigation + "px"
  1949.                 );
  1950.             },
  1951.  
  1952.  
  1953.             /**
  1954.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1955.              * Hide widget on title click
  1956.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1957.              */
  1958.             widgetsHidable: function () {
  1959.  
  1960.                 $(document).on('click', '.widget-hidable .widget-title', function () {
  1961.                     var content = $(this).siblings('ul, div, form, label, select');
  1962.                     $(this).parent().toggleClass('widget-hidden');
  1963.                     content.stop().slideToggle(200);
  1964.                 });
  1965.  
  1966.             },
  1967.  
  1968.             /**
  1969.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1970.              * Sticky column for portfolio items
  1971.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1972.              */
  1973.             stickyColumn: function () {
  1974.                 var details = $('.woodmart-sticky-column');
  1975.  
  1976.                 details.each(function () {
  1977.                     var $column = $(this),
  1978.                         offset = 0;
  1979.  
  1980.                     if ($('body').hasClass('enable-sticky-header') || $('.whb-sticky-row').length > 0 || $('.whb-sticky-header').length > 0) {
  1981.                         offset = 150;
  1982.                     }
  1983.  
  1984.                     $column.find(' > .vc_column-inner > .wpb_wrapper').stick_in_parent({
  1985.                         offset_top: offset
  1986.                     });
  1987.                 })
  1988.  
  1989.             },
  1990.  
  1991.  
  1992.             /**
  1993.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1994.              * Use magnific popup for images
  1995.              *-------------------------------------------------------------------------------------------------------------------------------------------
  1996.              */
  1997.             mfpPopup: function () {
  1998.  
  1999.                 $('.gallery').magnificPopup({
  2000.                     delegate: ' > a',
  2001.                     type: 'image',
  2002.                     removalDelay: 500, //delay removal by X to allow out-animation
  2003.                     tClose: woodmart_settings.close,
  2004.                     tLoading: woodmart_settings.loading,
  2005.                     callbacks: {
  2006.                         beforeOpen: function () {
  2007.                             this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim');
  2008.                             this.st.mainClass = woodmartTheme.popupEffect;
  2009.                         }
  2010.                     },
  2011.                     image: {
  2012.                         verticalFit: true
  2013.                     },
  2014.                     gallery: {
  2015.                         enabled: true,
  2016.                         navigateByImgClick: true
  2017.                     },
  2018.                 });
  2019.  
  2020.                 $('[data-rel="mfp"]').magnificPopup({
  2021.                     type: 'image',
  2022.                     removalDelay: 500, //delay removal by X to allow out-animation
  2023.                     tClose: woodmart_settings.close,
  2024.                     tLoading: woodmart_settings.loading,
  2025.                     callbacks: {
  2026.                         beforeOpen: function () {
  2027.                             this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim');
  2028.                             this.st.mainClass = woodmartTheme.popupEffect;
  2029.                         }
  2030.                     },
  2031.                     image: {
  2032.                         verticalFit: true
  2033.                     },
  2034.                     gallery: {
  2035.                         enabled: false,
  2036.                         navigateByImgClick: false
  2037.                     },
  2038.                 });
  2039.  
  2040.                 $(document).on('click', '.mfp-img', function () {
  2041.                     var mfp = jQuery.magnificPopup.instance; // get instance
  2042.                     mfp.st.image.verticalFit = !mfp.st.image.verticalFit; // toggle verticalFit on and off
  2043.                     mfp.currItem.img.removeAttr('style'); // remove style attribute, to remove max-width if it was applied
  2044.                     mfp.updateSize(); // force update of size
  2045.                 });
  2046.             },
  2047.  
  2048.             /**
  2049.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2050.              * Parallax effect
  2051.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2052.              */
  2053.             parallax: function () {
  2054.                 if ($(window).width() <= 1024) return;
  2055.  
  2056.                 $('.parallax-yes').each(function () {
  2057.                     var $bgobj = $(this);
  2058.                     $(window).scroll(function () {
  2059.                         var yPos = -($(window).scrollTop() / $bgobj.data('speed'));
  2060.                         var coords = 'center ' + yPos + 'px';
  2061.                         $bgobj.css({
  2062.                             backgroundPosition: coords
  2063.                         });
  2064.                     });
  2065.                 });
  2066.  
  2067.                 $('.woodmart-parallax').each(function () {
  2068.                     var $this = $(this);
  2069.                     if ($this.hasClass('wpb_column')) {
  2070.                         $this.find('> .vc_column-inner').parallax("50%", 0.3);
  2071.                     } else {
  2072.                         $this.parallax("50%", 0.3);
  2073.                     }
  2074.                 });
  2075.  
  2076.             },
  2077.  
  2078.  
  2079.             /**
  2080.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2081.              * Scroll top button
  2082.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2083.              */
  2084.             scrollTop: function () {
  2085.                 //Check to see if the window is top if not then display button
  2086.                 $(window).scroll(function () {
  2087.                     if ($(this).scrollTop() > 100) {
  2088.                         $('.scrollToTop').addClass('button-show');
  2089.                     } else {
  2090.                         $('.scrollToTop').removeClass('button-show');
  2091.                     }
  2092.                 });
  2093.  
  2094.                 //Click event to scroll to top
  2095.                 $('.scrollToTop').on('click', function () {
  2096.                     $('html, body').animate({
  2097.                         scrollTop: 0
  2098.                     }, 800);
  2099.                     return false;
  2100.                 });
  2101.             },
  2102.  
  2103.             /**
  2104.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2105.              * ToolTips titles
  2106.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2107.              */
  2108.             btnsToolTips: function () {
  2109.  
  2110.                 if ($(window).width() <= 1024) return;
  2111.  
  2112.                 var $tooltips = $('.woodmart-css-tooltip, .product-grid-item:not(.woodmart-hover-base):not(.woodmart-hover-icons) .woodmart-buttons > div a, .woodmart-hover-base.product-in-carousel .woodmart-buttons > div a'),
  2113.                     $bootstrapTooltips = $(woodmartTheme.bootstrapTooltips);
  2114.  
  2115.                 // .product-grid-item .add_to_cart_button
  2116.  
  2117.  
  2118.                 $tooltips.each(function () {
  2119.                     $(this).find('.woodmart-tooltip-label').remove();
  2120.                     $(this).addClass('woodmart-tltp').prepend('<span class="woodmart-tooltip-label">' + $(this).text() + '</span>');
  2121.                     $(this).find('.woodmart-tooltip-label').trigger('mouseover');
  2122.                 })
  2123.  
  2124.                     .off('mouseover.tooltips')
  2125.  
  2126.                     .on('mouseover.tooltips', function () {
  2127.                         var $label = $(this).find('.woodmart-tooltip-label'),
  2128.                             width = $label.outerWidth();
  2129.  
  2130.                         if ($('body').hasClass('rtl')) {
  2131.                             $label.css({
  2132.                                 marginRight: - parseInt(width / 2)
  2133.                             })
  2134.                         } else {
  2135.                             $label.css({
  2136.                                 marginLeft: - parseInt(width / 2)
  2137.                             })
  2138.                         }
  2139.                     });
  2140.  
  2141.                 // Bootstrap tooltips
  2142.  
  2143.                 $bootstrapTooltips.tooltip({
  2144.                     animation: false,
  2145.                     container: 'body',
  2146.                     trigger: 'hover',
  2147.                     title: function () {
  2148.                         if ($(this).find('.added_to_cart').length > 0) return $(this).find('.add_to_cart_button').text();
  2149.                         return $(this).text();
  2150.                     }
  2151.                 });
  2152.  
  2153.             },
  2154.  
  2155.             /**
  2156.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2157.              * Sticky footer: margin bottom for main wrapper
  2158.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2159.              */
  2160.             stickyFooter: function () {
  2161.  
  2162.                 if (!$('body').hasClass('sticky-footer-on') || $(window).width() <= 1024) return;
  2163.  
  2164.                 var $footer = $('.footer-container'),
  2165.                     $page = $('.main-page-wrapper'),
  2166.                     $window = $(window);
  2167.  
  2168.                 if ($('.woodmart-prefooter').length > 0) {
  2169.                     $page = $('.woodmart-prefooter');
  2170.                 }
  2171.  
  2172.                 var footerOffset = function () {
  2173.                     $page.css({
  2174.                         marginBottom: $footer.outerHeight()
  2175.                     })
  2176.                 };
  2177.  
  2178.                 $window.on('resize', footerOffset);
  2179.  
  2180.                 $footer.imagesLoaded(function () {
  2181.                     footerOffset();
  2182.                 });
  2183.  
  2184.                 //Safari fix
  2185.                 var footerSafariFix = function () {
  2186.                     if (!$('html').hasClass('browser-Safari')) return;
  2187.                     var windowScroll = $window.scrollTop();
  2188.                     var footerOffsetTop = $(document).outerHeight() - $footer.outerHeight();
  2189.  
  2190.                     if (footerOffsetTop < windowScroll + $footer.outerHeight() + $window.outerHeight()) {
  2191.                         $footer.addClass('visible-footer');
  2192.                     } else {
  2193.                         $footer.removeClass('visible-footer');
  2194.                     }
  2195.                 };
  2196.  
  2197.                 footerSafariFix();
  2198.                 $window.on('scroll', footerSafariFix);
  2199.  
  2200.             },
  2201.  
  2202.             /**
  2203.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2204.              * Back in history
  2205.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2206.              */
  2207.             backHistory: function () {
  2208.                 history.go(-1);
  2209.  
  2210.                 setTimeout(function () {
  2211.                     $('.filters-area').removeClass('filters-opened').stop().hide();
  2212.                     $('.open-filters').removeClass('btn-opened');
  2213.                     if ($(window).width() <= 1024) {
  2214.                         $('.woodmart-product-categories').removeClass('categories-opened').stop().hide();
  2215.                         $('.woodmart-show-categories').removeClass('button-open');
  2216.                     }
  2217.  
  2218.                     woodmartThemeModule.btnsToolTips();
  2219.                     woodmartThemeModule.categoriesAccordion();
  2220.                     woodmartThemeModule.woocommercePriceSlider();
  2221.                 }, 20);
  2222.  
  2223.  
  2224.             },
  2225.  
  2226.             /**
  2227.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2228.              * Ajax Search for products
  2229.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2230.              */
  2231.             ajaxSearch: function () {
  2232.                 if (typeof ($.fn.devbridgeAutocomplete) == 'undefined') return;
  2233.  
  2234.                 var escapeRegExChars = function (value) {
  2235.                     return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
  2236.                 };
  2237.  
  2238.                 $('form.woodmart-ajax-search').each(function () {
  2239.                     var $this = $(this),
  2240.                         number = parseInt($this.data('count')),
  2241.                         thumbnail = parseInt($this.data('thumbnail')),
  2242.                         symbols_count = parseInt($this.data('symbols_count')),
  2243.                         productCat = $this.find('[name="product_cat"]'),
  2244.                         $results = $this.parent().find('.woodmart-search-results'),
  2245.                         postType = $this.data('post_type'),
  2246.                         url = woodmart_settings.ajaxurl + '?action=woodmart_ajax_search',
  2247.                         price = parseInt($this.data('price'));
  2248.  
  2249.                     if (number > 0) url += '&number=' + number;
  2250.                     url += '&post_type=' + postType;
  2251.  
  2252.                     $results.on('click', '.view-all-results', function () {
  2253.                         $this.submit();
  2254.                     });
  2255.  
  2256.                     if (productCat.length && productCat.val() !== '') {
  2257.                         url += '&product_cat=' + productCat.val();
  2258.                     }
  2259.  
  2260.                     $this.find('[type="text"]').devbridgeAutocomplete({
  2261.                         serviceUrl: url,
  2262.                         appendTo: $results,
  2263.                         minChars: symbols_count,
  2264.  
  2265.                         onSelect: function (suggestion) {
  2266.                             if (suggestion.permalink.length > 0)
  2267.                                 window.location.href = suggestion.permalink;
  2268.                         },
  2269.                         onSearchStart: function (query) {
  2270.                             $this.addClass('search-loading');
  2271.                         },
  2272.                         beforeRender: function (container) {
  2273.  
  2274.                             if (container[0].childElementCount > 2)
  2275.                                 $(container).append('<div class="view-all-results"><span>' + woodmart_settings.all_results + '</span></div>');
  2276.  
  2277.                         },
  2278.                         onSearchComplete: function (query, suggestions) {
  2279.                             $this.removeClass('search-loading');
  2280.  
  2281.                             if ($(window).width() >= 1024 && (!woodmartTheme.disableNanoScrollerWebkit && woodmart_settings.disable_nanoscroller != 'disable')) {
  2282.                                 $(".woodmart-scroll").nanoScroller({
  2283.                                     paneClass: 'woodmart-scroll-pane',
  2284.                                     sliderClass: 'woodmart-scroll-slider',
  2285.                                     contentClass: 'woodmart-scroll-content',
  2286.                                     preventPageScrolling: false
  2287.                                 });
  2288.                             }
  2289.  
  2290.                             $(document).trigger('wood-images-loaded');
  2291.  
  2292.                         },
  2293.                         formatResult: function (suggestion, currentValue) {
  2294.                             if (currentValue == '&') currentValue = "&#038;";
  2295.                             var pattern = '(' + escapeRegExChars(currentValue) + ')',
  2296.                                 returnValue = '';
  2297.  
  2298.                             if (thumbnail && suggestion.thumbnail) {
  2299.                                 returnValue += ' <div class="suggestion-thumb">' + suggestion.thumbnail + '</div>';
  2300.                             }
  2301.  
  2302.                             returnValue += '<h4 class="suggestion-title result-title">' + suggestion.value
  2303.                                 .replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>')
  2304.                                 // .replace(/&/g, '&amp;')
  2305.                                 .replace(/</g, '&lt;')
  2306.                                 .replace(/>/g, '&gt;')
  2307.                                 .replace(/"/g, '&quot;')
  2308.                                 .replace(/&lt;(\/?strong)&gt;/g, '<$1>') + '</h4>';
  2309.  
  2310.                             if (suggestion.no_found) returnValue = '<div class="suggestion-title no-found-msg">' + suggestion.value + '</div>';
  2311.  
  2312.                             if (price && suggestion.price) {
  2313.                                 returnValue += ' <div class="suggestion-price price">' + suggestion.price + '</div>';
  2314.                             }
  2315.  
  2316.                             return returnValue;
  2317.                         }
  2318.                     });
  2319.  
  2320.                     if (productCat.length) {
  2321.  
  2322.                         var searchForm = $this.find('[type="text"]').devbridgeAutocomplete(),
  2323.                             serviceUrl = woodmart_settings.ajaxurl + '?action=woodmart_ajax_search';
  2324.  
  2325.                         if (number > 0) serviceUrl += '&number=' + number;
  2326.                         serviceUrl += '&post_type=' + postType;
  2327.  
  2328.                         productCat.on('cat_selected', function () {
  2329.                             if (productCat.val() != '') {
  2330.                                 searchForm.setOptions({
  2331.                                     serviceUrl: serviceUrl + '&product_cat=' + productCat.val()
  2332.                                 });
  2333.                             } else {
  2334.                                 searchForm.setOptions({
  2335.                                     serviceUrl: serviceUrl
  2336.                                 });
  2337.                             }
  2338.  
  2339.                             searchForm.hide();
  2340.                             searchForm.onValueChange();
  2341.                         });
  2342.                     }
  2343.  
  2344.                     $('body').on('click', function () {
  2345.                         $this.find('[type="text"]').devbridgeAutocomplete('hide');
  2346.                     });
  2347.  
  2348.                     $('.woodmart-search-results').on('click', function (e) {
  2349.                         e.stopPropagation();
  2350.                     });
  2351.  
  2352.                 });
  2353.  
  2354.             },
  2355.  
  2356.  
  2357.             /**
  2358.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2359.              * Search full screen
  2360.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2361.              */
  2362.             searchFullScreen: function () {
  2363.  
  2364.                 var body = $('body'),
  2365.                     searchWrapper = $('.woodmart-search-full-screen'),
  2366.                     offset = 0;
  2367.  
  2368.  
  2369.                 body.on('click', '.search-button:not(.mobile-search-icon) > a', function (e) {
  2370.  
  2371.                     e.preventDefault();
  2372.  
  2373.                     if ($(this).parent().find('.woodmart-search-dropdown').length > 0) return; // if dropdown search on header builder
  2374.  
  2375.                     if (body.hasClass('global-search-dropdown') || $(window).width() < 1024) return;
  2376.  
  2377.                     if (isOpened()) {
  2378.                         closeWidget();
  2379.                     } else {
  2380.                         setTimeout(function () {
  2381.                             openWidget();
  2382.                         }, 10);
  2383.                     }
  2384.                 })
  2385.  
  2386.  
  2387.                 body.on("click", ".woodmart-close-search, .main-page-wrapper, .header-banner", function (event) {
  2388.  
  2389.                     if (!$(event.target).is('.woodmart-close-search') && $(event.target).closest(".woodmart-search-full-screen").length) return;
  2390.  
  2391.                     if (isOpened()) {
  2392.                         closeWidget();
  2393.                     }
  2394.                 });
  2395.  
  2396.  
  2397.                 var closeByEsc = function (e) {
  2398.                     if (e.keyCode === 27) {
  2399.                         closeWidget();
  2400.                         body.unbind('keyup', closeByEsc);
  2401.                     }
  2402.                 };
  2403.  
  2404.  
  2405.                 var closeWidget = function () {
  2406.                     $('body').removeClass('woodmart-search-opened');
  2407.                     searchWrapper.removeClass('search-overlap');
  2408.                 };
  2409.  
  2410.                 var openWidget = function () {
  2411.                     var bar = $('#wpadminbar').outerHeight();
  2412.  
  2413.                     var offset = 0;
  2414.  
  2415.                     if ($('.whb-sticked').length > 0) {
  2416.                         if ($('.whb-clone').length > 0)
  2417.                             offset = $('.whb-sticked').outerHeight() + bar;
  2418.                         else
  2419.                             offset = $('.whb-main-header').outerHeight() + bar;
  2420.                     } else {
  2421.                         offset = $('.whb-main-header').outerHeight() + bar;
  2422.                         if ($('body').hasClass('header-banner-display')) {
  2423.                             offset += $('.header-banner').outerHeight();
  2424.                         }
  2425.                     }
  2426.  
  2427.                     searchWrapper.css('top', offset);
  2428.  
  2429.                     // Close by esc
  2430.                     body.on('keyup', closeByEsc);
  2431.  
  2432.                     $('body').addClass('woodmart-search-opened');
  2433.                     searchWrapper.addClass('search-overlap');
  2434.                     setTimeout(function () {
  2435.                         searchWrapper.find('input[type="text"]').focus();
  2436.                         $(window).one('scroll', function () {
  2437.                             if (isOpened()) {
  2438.                                 closeWidget();
  2439.                             }
  2440.                         });
  2441.                     }, 300);
  2442.                 };
  2443.  
  2444.                 var isOpened = function () {
  2445.                     return $('body').hasClass('woodmart-search-opened');
  2446.                 };
  2447.             },
  2448.  
  2449.  
  2450.             /**
  2451.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2452.              * Sale final date countdown
  2453.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2454.              */
  2455.             countDownTimer: function () {
  2456.  
  2457.                 $('.woodmart-timer').each(function () {
  2458.                     var time = moment.tz($(this).data('end-date'), $(this).data('timezone'));
  2459.                     $(this).countdown(time.toDate(), function (event) {
  2460.                         $(this).html(event.strftime(''
  2461.                             + '<span class="countdown-days">%-D <span>' + woodmart_settings.countdown_days + '</span></span> '
  2462.                             + '<span class="countdown-hours">%H <span>' + woodmart_settings.countdown_hours + '</span></span> '
  2463.                             + '<span class="countdown-min">%M <span>' + woodmart_settings.countdown_mins + '</span></span> '
  2464.                             + '<span class="countdown-sec">%S <span>' + woodmart_settings.countdown_sec + '</span></span>'));
  2465.                     });
  2466.                 });
  2467.  
  2468.             },
  2469.  
  2470.  
  2471.             /**
  2472.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2473.              * Init nanoscroller
  2474.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2475.              */
  2476.             nanoScroller: function () {
  2477.  
  2478.                 if ($(window).width() < 1024 || (woodmart_settings.disable_nanoscroller == 'webkit' && (jscd.browser == 'Chrome' || jscd.browser == 'Opera' || jscd.browser == 'Safari')) || woodmart_settings.disable_nanoscroller == 'disable') return;
  2479.  
  2480.                 $(".woodmart-scroll").nanoScroller({
  2481.                     paneClass: 'woodmart-scroll-pane',
  2482.                     sliderClass: 'woodmart-scroll-slider',
  2483.                     contentClass: 'woodmart-scroll-content',
  2484.                     preventPageScrolling: false
  2485.                 });
  2486.  
  2487.                 $('body').on('wc_fragments_refreshed wc_fragments_loaded added_to_cart', function () {
  2488.                     $(".widget_shopping_cart .woodmart-scroll").nanoScroller({
  2489.                         paneClass: 'woodmart-scroll-pane',
  2490.                         sliderClass: 'woodmart-scroll-slider',
  2491.                         contentClass: 'woodmart-scroll-content',
  2492.                         preventPageScrolling: false
  2493.                     });
  2494.                     $(".widget_shopping_cart .woodmart-scroll-content").scroll(function () {
  2495.                         $(document).trigger('wood-images-loaded');
  2496.                     })
  2497.                 });
  2498.             },
  2499.  
  2500.             /**
  2501.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2502.              * WoodMart gradient
  2503.              *-------------------------------------------------------------------------------------------------------------------------------------------
  2504.              */
  2505.             gradientShift: function () {
  2506.                 $('.woodmart_gradient').each(function () {
  2507.                     var selector = $(this);
  2508.                     var parent = selector.prev();
  2509.                     parent.css('position', 'relative');
  2510.                     parent.prepend(selector);
  2511.                 });
  2512.             },
  2513.  
  2514.             /**
  2515.             *-------------------------------------------------------------------------------------------------------------------------------------------
  2516.             * Lazy loading
  2517.             *-------------------------------------------------------------------------------------------------------------------------------------------
  2518.             */
  2519.             lazyLoading: function () {
  2520.                 if (!window.addEventListener || !window.requestAnimationFrame || !document.getElementsByClassName) return;
  2521.  
  2522.                 // start
  2523.                 var pItem = document.getElementsByClassName('woodmart-lazy-load'), pCount, timer;
  2524.  
  2525.                 $(document).on('wood-images-loaded added_to_cart', function () {
  2526.                     inView();
  2527.                 })
  2528.  
  2529.                 $('.woodmart-scroll-content, .woodmart-sidebar-content').scroll(function () {
  2530.                     $(document).trigger('wood-images-loaded');
  2531.                 })
  2532.                 // $(document).on( 'scroll', '.woodmart-scroll-content', function() {
  2533.                 //     $(document).trigger('wood-images-loaded');
  2534.                 // })
  2535.  
  2536.                 // WooCommerce tabs fix
  2537.                 $('.wc-tabs > li').on('click', function () {
  2538.                     $(document).trigger('wood-images-loaded');
  2539.                 });
  2540.  
  2541.                 // scroll and resize events
  2542.                 window.addEventListener('scroll', scroller, false);
  2543.                 window.addEventListener('resize', scroller, false);
  2544.  
  2545.                 // DOM mutation observer
  2546.                 if (MutationObserver) {
  2547.  
  2548.                     var observer = new MutationObserver(function () {
  2549.                         // console.log('mutated', pItem.length, pCount)
  2550.                         if (pItem.length !== pCount) inView();
  2551.                     });
  2552.  
  2553.                     observer.observe(document.body, { subtree: true, childList: true, attributes: true, characterData: true });
  2554.  
  2555.                 }
  2556.  
  2557.                 // initial check
  2558.                 inView();
  2559.  
  2560.                 // throttled scroll/resize
  2561.                 function scroller() {
  2562.  
  2563.                     timer = timer || setTimeout(function () {
  2564.                         timer = null;
  2565.                         inView();
  2566.                     }, 100);
  2567.  
  2568.                 }
  2569.  
  2570.  
  2571.                 // image in view?
  2572.                 function inView() {
  2573.  
  2574.                     if (pItem.length) requestAnimationFrame(function () {
  2575.                         var offset = parseInt(woodmart_settings.lazy_loading_offset);
  2576.                         var wT = window.pageYOffset, wB = wT + window.innerHeight + offset, cRect, pT, pB, p = 0;
  2577.  
  2578.                         while (p < pItem.length) {
  2579.  
  2580.                             cRect = pItem[p].getBoundingClientRect();
  2581.                             pT = wT + cRect.top;
  2582.                             pB = pT + cRect.height;
  2583.  
  2584.                             if (wT < pB && wB > pT && !pItem[p].loaded) {
  2585.                                 loadFullImage(pItem[p], p);
  2586.                             }
  2587.                             else p++;
  2588.  
  2589.                         }
  2590.  
  2591.                         pCount = pItem.length;
  2592.  
  2593.                     });
  2594.  
  2595.                 }
  2596.  
  2597.  
  2598.                 // replace with full image
  2599.                 function loadFullImage(item, i) {
  2600.  
  2601.                     item.onload = addedImg;
  2602.  
  2603.                     item.src = item.dataset.woodSrc;
  2604.                     if (typeof (item.dataset.srcset) != 'undefined') {
  2605.                         item.srcset = item.dataset.srcset;
  2606.                     }
  2607.  
  2608.                     item.loaded = true
  2609.  
  2610.                     // replace image
  2611.                     function addedImg() {
  2612.  
  2613.                         requestAnimationFrame(function () {
  2614.                             item.classList.add('woodmart-loaded')
  2615.  
  2616.                             var $masonry = jQuery(item).parents('.view-masonry .gallery-images, .grid-masonry, .masonry-container');
  2617.                             if ($masonry.length > 0) {
  2618.                                 $masonry.isotope('layout');
  2619.                             }
  2620.                             var $categories = jQuery(item).parents('.categories-masonry');
  2621.                             if ($categories.length > 0) {
  2622.                                 $categories.packery();
  2623.                             }
  2624.  
  2625.                             // var $owl = jQuery(item).parents('.owl-carousel');
  2626.                             // if ($owl.length > 0) {
  2627.                             //     $owl.trigger('refresh.owl.carousel');
  2628.                             // }
  2629.  
  2630.                         });
  2631.  
  2632.                     }
  2633.  
  2634.                 }
  2635.  
  2636.             },
  2637.         }
  2638.     }());
  2639.  
  2640. })(jQuery);
  2641.  
  2642.  
  2643. jQuery(document).ready(function () {
  2644.     if (!wooFile) {
  2645.         woodmartThemeModule.init();
  2646.     }
  2647. });
  2648.  
  2649.  
  2650. var wooFile = true;
  2651. //Functions WOO
  2652.  
  2653. (function ($) {
  2654.     "use strict";
  2655.  
  2656.     var woodmartTheme = {
  2657.         popupEffect: 'mfp-move-horizontal',
  2658.         supports_html5_storage: false,
  2659.         shopLoadMoreBtn: '.woodmart-products-load-more.load-on-scroll',
  2660.         ajaxLinks: '.woodmart-product-categories a, .widget_product_categories a, .widget_layered_nav_filters a, .woocommerce-widget-layered-nav a, .filters-area:not(.custom-content) a, body.post-type-archive-product:not(.woocommerce-account) .woocommerce-pagination a, body.tax-product_cat:not(.woocommerce-account) .woocommerce-pagination a, .woodmart-shop-tools a, .woodmart-woocommerce-layered-nav a, .woodmart-price-filter a, .woodmart-clear-filters-wrapp a, .woodmart-woocommerce-sort-by a',
  2661.         mainCarouselArg: {
  2662.             rtl: $('body').hasClass('rtl'),
  2663.             items: woodmart_settings.product_gallery.thumbs_slider.position == 'centered' ? 2 : 1,
  2664.             autoplay: woodmart_settings.product_slider_autoplay,
  2665.             autoplayTimeout: 3000,
  2666.             loop: woodmart_settings.product_slider_autoplay,
  2667.             center: woodmart_settings.product_gallery.thumbs_slider.position == 'centered',
  2668.             startPosition: woodmart_settings.product_gallery.thumbs_slider.position == 'centered' ? woodmart_settings.centered_gallery_start : 0,
  2669.             dots: false,
  2670.             nav: true,
  2671.             autoHeight: woodmart_settings.product_slider_auto_height == 'yes',
  2672.             navText: false,
  2673.             onRefreshed: function () {
  2674.                 $(window).resize();
  2675.             }
  2676.         }
  2677.     };
  2678.  
  2679.     /* Storage Handling */
  2680.     try {
  2681.         woodmartTheme.supports_html5_storage = ('sessionStorage' in window && window.sessionStorage !== null);
  2682.  
  2683.         window.sessionStorage.setItem('woodmart', 'test');
  2684.         window.sessionStorage.removeItem('woodmart');
  2685.     } catch (err) {
  2686.         woodmartTheme.supports_html5_storage = false;
  2687.     }
  2688.  
  2689.     /**
  2690.     *-------------------------------------------------------------------------------------------------------------------------------------------
  2691.     * Wishlist
  2692.     *-------------------------------------------------------------------------------------------------------------------------------------------
  2693.     */
  2694.     woodmartThemeModule.wishlist = function () {
  2695.         var cookiesName = 'woodmart_wishlist_count';
  2696.  
  2697.         if ($('body').hasClass('logged-in')) {
  2698.             cookiesName += '_logged';
  2699.         }
  2700.  
  2701.         if (woodmart_settings.is_multisite) {
  2702.             cookiesName += '_' + woodmart_settings.current_blog_id;
  2703.         }
  2704.  
  2705.         var $widget = $('.woodmart-wishlist-info-widget');
  2706.         var cookie = Cookies.get(cookiesName);
  2707.  
  2708.         if ($widget.length > 0) {
  2709.             try {
  2710.                 var count = JSON.parse(cookie);
  2711.                 $widget.find('.wishlist-count').text(count);
  2712.             }
  2713.             catch (e) {
  2714.                 console.log('cant parse cookies json');
  2715.             }
  2716.         }
  2717.  
  2718.         // Add to wishlist action
  2719.         $('body').on('click', '.woodmart-wishlist-btn a', function (e) {
  2720.             var $this = $(this);
  2721.             var productId = $this.data('product-id');
  2722.             var addedText = $this.data('added-text');
  2723.             var key = $this.data('key');
  2724.  
  2725.             if ($this.hasClass('added')) {
  2726.                 return true;
  2727.             }
  2728.  
  2729.             e.preventDefault();
  2730.  
  2731.             $this.addClass('loading');
  2732.  
  2733.             $.ajax({
  2734.                 url: woodmart_settings.ajaxurl,
  2735.                 data: {
  2736.                     action: 'woodmart_add_to_wishlist',
  2737.                     product_id: productId,
  2738.                     key: key,
  2739.                 },
  2740.                 dataType: 'json',
  2741.                 method: 'GET',
  2742.                 success: function (response) {
  2743.                     if (response) {
  2744.                         $this.addClass('added');
  2745.                         $(document).trigger('added_to_wishlist');
  2746.  
  2747.                         if (response.wishlist_content) {
  2748.                             updateWishlist(response);
  2749.                         }
  2750.  
  2751.                         if ($this.find('span').length > 0) {
  2752.                             $this.find('span').text(addedText);
  2753.                         }
  2754.                         else {
  2755.                             $this.text(addedText);
  2756.                         }
  2757.                     }
  2758.                     else {
  2759.                         console.log('something wrong loading wishlist data ',
  2760.                             response);
  2761.                     }
  2762.                 },
  2763.                 error: function (data) {
  2764.                     console.log(
  2765.                         'We cant add to wishlist. Something wrong with AJAX response. Probably some PHP conflict.');
  2766.                 },
  2767.                 complete: function () {
  2768.                     $this.removeClass('loading');
  2769.                 },
  2770.             });
  2771.  
  2772.         });
  2773.  
  2774.         $('body').on('click', '.woodmart-wishlist-remove', function (e) {
  2775.             var $this = $(this);
  2776.             var productId = $this.data('product-id');
  2777.             var key = $this.data('key');
  2778.  
  2779.             if ($this.hasClass('added')) {
  2780.                 return true;
  2781.             }
  2782.  
  2783.             e.preventDefault();
  2784.  
  2785.             $this.addClass('loading');
  2786.  
  2787.             $.ajax({
  2788.                 url: woodmart_settings.ajaxurl,
  2789.                 data: {
  2790.                     action: 'woodmart_remove_from_wishlist',
  2791.                     product_id: productId,
  2792.                     key: key,
  2793.                 },
  2794.                 dataType: 'json',
  2795.                 method: 'GET',
  2796.                 success: function (response) {
  2797.                     if (response.wishlist_content) {
  2798.                         updateWishlist(response);
  2799.                     }
  2800.                     else {
  2801.                         console.log('something wrong loading wishlist data ',
  2802.                             response);
  2803.                     }
  2804.                 },
  2805.                 error: function (data) {
  2806.                     console.log(
  2807.                         'We cant remove from wishlist. Something wrong with AJAX response. Probably some PHP conflict.');
  2808.                 },
  2809.                 complete: function () {
  2810.                     $this.removeClass('loading');
  2811.                 },
  2812.             });
  2813.  
  2814.         });
  2815.  
  2816.         // Elements update after ajax
  2817.         function updateWishlist(data) {
  2818.             if ($widget.length > 0) {
  2819.                 $widget.find('.wishlist-count').text(data.count);
  2820.             }
  2821.  
  2822.             if ($('.woodmart-wishlist-content').length > 0 && !$('.woodmart-wishlist-content').hasClass('woodmart-wishlist-preview')) {
  2823.                 $('.woodmart-wishlist-content').replaceWith(data.wishlist_content);
  2824.             }
  2825.  
  2826.             woodmartThemeModule.swatchesVariations();
  2827.             woodmartThemeModule.btnsToolTips();
  2828.             woodmartThemeModule.productHover();
  2829.             woodmartThemeModule.countDownTimer();
  2830.         }
  2831.  
  2832.     };
  2833.  
  2834.     /**
  2835.     *-------------------------------------------------------------------------------------------------------------------------------------------
  2836.     * Variations price
  2837.     *-------------------------------------------------------------------------------------------------------------------------------------------
  2838.     */
  2839.  
  2840.     woodmartThemeModule.variationsPrice = function () {
  2841.         if ('no' === woodmart_settings.single_product_variations_price) {
  2842.             return;
  2843.         }
  2844.  
  2845.         $('.variations_form').each(function () {
  2846.             var $form = $(this);
  2847.             var $price = $form.parent().find('> .price').first();
  2848.             var priceOriginalHtml = $price.html();
  2849.  
  2850.             $form.on('show_variation', function (e, variation, purchasable) {
  2851.                 if (variation.price_html.length > 1) {
  2852.                     $price.html(variation.price_html);
  2853.                 }
  2854.             });
  2855.  
  2856.             $form.on('hide_variation', function () {
  2857.                 $price.html(priceOriginalHtml);
  2858.             });
  2859.         });
  2860.     };
  2861.  
  2862.     /**
  2863.     *-------------------------------------------------------------------------------------------------------------------------------------------
  2864.     * Product filters
  2865.     *-------------------------------------------------------------------------------------------------------------------------------------------
  2866.     */
  2867.  
  2868.     woodmartThemeModule.productFilters = function () {
  2869.         //Select checkboxes value
  2870.         var removeValue = function ($mainInput, currentVal) {
  2871.             if ($mainInput.length == 0) return;
  2872.             var mainInputVal = $mainInput.val();
  2873.             if (mainInputVal.indexOf(',') > 0) {
  2874.                 $mainInput.val(mainInputVal.replace(',' + currentVal, '').replace(currentVal + ',', ''));
  2875.             } else {
  2876.                 $mainInput.val(mainInputVal.replace(currentVal, ''));
  2877.             }
  2878.         }
  2879.  
  2880.         $('.woodmart-pf-checkboxes li > .pf-value').on('click', function (e) {
  2881.             e.preventDefault();
  2882.             var $this = $(this);
  2883.             var $li = $this.parent();
  2884.             var $widget = $this.parents('.woodmart-pf-checkboxes');
  2885.             var $mainInput = $widget.find('.result-input');
  2886.             var $results = $widget.find('.woodmart-pf-results');
  2887.  
  2888.             var multiSelect = $widget.hasClass('multi_select');
  2889.             var mainInputVal = $mainInput.val();
  2890.             var currentText = $this.data('title');
  2891.             var currentVal = $this.data('val');
  2892.  
  2893.             if (multiSelect) {
  2894.                 if (!$li.hasClass('pf-active')) {
  2895.                     if (mainInputVal == '') {
  2896.                         $mainInput.val(currentVal);
  2897.                     } else {
  2898.                         $mainInput.val(mainInputVal + ',' + currentVal);
  2899.                     }
  2900.                     $results.prepend('<li class="selected-value" data-title="' + currentVal + '">' + currentText + '</li>');
  2901.                     $li.addClass('pf-active');
  2902.                 } else {
  2903.                     removeValue($mainInput, currentVal);
  2904.                     $results.find('li[data-title="' + currentVal + '"]').remove();
  2905.                     $li.removeClass('pf-active');
  2906.                 }
  2907.             } else {
  2908.                 if (!$li.hasClass('pf-active')) {
  2909.                     $mainInput.val(currentVal);
  2910.                     $results.find('.selected-value').remove();
  2911.                     $results.prepend('<li class="selected-value" data-title="' + currentVal + '">' + currentText + '</li>');
  2912.                     $li.parents('.woodmart-scroll-content').find('.pf-active').removeClass('pf-active');
  2913.                     $li.addClass('pf-active');
  2914.                 } else {
  2915.                     $mainInput.val('');
  2916.                     $results.find('.selected-value').remove();
  2917.                     $li.removeClass('pf-active');
  2918.                 }
  2919.             }
  2920.         });
  2921.  
  2922.         //Label clear
  2923.         $('.woodmart-pf-checkboxes').on('click', '.selected-value', function () {
  2924.             var $this = $(this);
  2925.             var $widget = $this.parents('.woodmart-pf-checkboxes');
  2926.             var $mainInput = $widget.find('.result-input');
  2927.             var currentVal = $this.data('title');
  2928.  
  2929.             //Price filter clear
  2930.             if (currentVal == 'price-filter') {
  2931.                 var min = $this.data('min');
  2932.                 var max = $this.data('max');
  2933.                 var $slider = $widget.find('.price_slider_widget');
  2934.                 $slider.slider('values', 0, min);
  2935.                 $slider.slider('values', 1, max);
  2936.                 $widget.find('.min_price').val('');
  2937.                 $widget.find('.max_price').val('');
  2938.                 $(document.body).trigger('filter_price_slider_slide', [min, max, min, max, $slider]);
  2939.                 return;
  2940.             }
  2941.  
  2942.             removeValue($mainInput, currentVal);
  2943.             $widget.find('.pf-value[data-val="' + currentVal + '"]').parent().removeClass('pf-active');
  2944.             $this.remove();
  2945.         });
  2946.  
  2947.         //Checkboxes value dropdown
  2948.         $('.woodmart-pf-checkboxes').each(function () {
  2949.             var $this = $(this);
  2950.             var $btn = $this.find('.woodmart-pf-title');
  2951.             var $list = $btn.siblings('.woodmart-pf-dropdown');
  2952.             var multiSelect = $this.hasClass('multi_select');
  2953.  
  2954.             $btn.on('click', function (e) {
  2955.                 var target = e.target;
  2956.                 if ($(target).is($btn.find('.selected-value'))) return;
  2957.  
  2958.                 if (!$this.hasClass('opened')) {
  2959.                     $this.addClass('opened');
  2960.                     $list.slideDown(100);
  2961.                     setTimeout(function () {
  2962.                         woodmartThemeModule.nanoScroller();
  2963.                     }, 300);
  2964.                 } else {
  2965.                     close();
  2966.                 }
  2967.             });
  2968.  
  2969.             $(document).on('click', function (e) {
  2970.                 var target = e.target;
  2971.                 if ($this.hasClass('opened') && (multiSelect && !$(target).is($this) && !$(target).parents().is($this)) || (!multiSelect && !$(target).is($btn) && !$(target).parents().is($btn))) {
  2972.                     close();
  2973.                 }
  2974.             });
  2975.  
  2976.             var close = function () {
  2977.                 $this.removeClass('opened');
  2978.                 $list.slideUp(100);
  2979.             }
  2980.         });
  2981.  
  2982.         var removeEmptyValues = function ($selector) {
  2983.             $selector.find('.woodmart-pf-checkboxes').each(function () {
  2984.                 if (!$(this).find('input[type="hidden"]').val()) {
  2985.                     $(this).find('input[type="hidden"]').remove();
  2986.                 }
  2987.             });
  2988.         }
  2989.  
  2990.         var changeFormAction = function ($form) {
  2991.             var activeCat = $form.find('.woodmart-pf-categories .pf-active .pf-value');
  2992.             if (activeCat.length > 0) {
  2993.                 $form.attr('action', activeCat.attr('href'));
  2994.             }
  2995.         }
  2996.  
  2997.         //Price slider init
  2998.         $(document.body).on('filter_price_slider_create filter_price_slider_slide', function (event, min, max, minPrice, maxPrice, $slider) {
  2999.             var minHtml = accounting.formatMoney(min, {
  3000.                 symbol: woocommerce_price_slider_params.currency_format_symbol,
  3001.                 decimal: woocommerce_price_slider_params.currency_format_decimal_sep,
  3002.                 thousand: woocommerce_price_slider_params.currency_format_thousand_sep,
  3003.                 precision: woocommerce_price_slider_params.currency_format_num_decimals,
  3004.                 format: woocommerce_price_slider_params.currency_format
  3005.             });
  3006.  
  3007.             var maxHtml = accounting.formatMoney(max, {
  3008.                 symbol: woocommerce_price_slider_params.currency_format_symbol,
  3009.                 decimal: woocommerce_price_slider_params.currency_format_decimal_sep,
  3010.                 thousand: woocommerce_price_slider_params.currency_format_thousand_sep,
  3011.                 precision: woocommerce_price_slider_params.currency_format_num_decimals,
  3012.                 format: woocommerce_price_slider_params.currency_format
  3013.             });
  3014.  
  3015.             $slider.siblings('.filter_price_slider_amount').find('span.from').html(minHtml);
  3016.             $slider.siblings('.filter_price_slider_amount').find('span.to').html(maxHtml);
  3017.  
  3018.             var $results = $slider.parents('.woodmart-pf-checkboxes').find('.woodmart-pf-results');
  3019.             var value = $results.find('.selected-value');
  3020.             if (min == minPrice && max == maxPrice) {
  3021.                 value.remove();
  3022.             } else {
  3023.                 if (value.length == 0) {
  3024.                     $results.prepend('<li class="selected-value" data-title="price-filter" data-min="' + minPrice + '" data-max="' + maxPrice + '">' + minHtml + ' - ' + maxHtml + '</li>');
  3025.                 } else {
  3026.                     value.html(minHtml + ' - ' + maxHtml);
  3027.                 }
  3028.             }
  3029.  
  3030.             $(document.body).trigger('price_slider_updated', [min, max]);
  3031.         });
  3032.  
  3033.         $('.woodmart-pf-price-range .price_slider_widget').each(function () {
  3034.             var $this = $(this);
  3035.             var $minInput = $this.siblings('.filter_price_slider_amount').find('.min_price');
  3036.             var $maxInput = $this.siblings('.filter_price_slider_amount').find('.max_price');
  3037.             var minPrice = parseInt($minInput.data('min'));
  3038.             var maxPrice = parseInt($maxInput.data('max'));
  3039.             var currentMinPrice = parseInt($minInput.val());
  3040.             var currentMaxPrice = parseInt($maxInput.val());
  3041.  
  3042.             $('.price_slider_widget, .price_label').show();
  3043.  
  3044.             $this.slider({
  3045.                 range: true,
  3046.                 animate: true,
  3047.                 min: minPrice,
  3048.                 max: maxPrice,
  3049.                 values: [currentMinPrice, currentMaxPrice],
  3050.                 create: function () {
  3051.                     if (currentMinPrice == minPrice && currentMaxPrice == maxPrice) {
  3052.                         $minInput.val('');
  3053.                         $maxInput.val('');
  3054.                     }
  3055.                     $(document.body).trigger('filter_price_slider_create', [currentMinPrice, currentMaxPrice, minPrice, maxPrice, $this]);
  3056.                 },
  3057.                 slide: function (event, ui) {
  3058.                     if (ui.values[0] == minPrice && ui.values[1] == maxPrice) {
  3059.                         $minInput.val('');
  3060.                         $maxInput.val('');
  3061.                     } else {
  3062.                         $minInput.val(ui.values[0]);
  3063.                         $maxInput.val(ui.values[1]);
  3064.                     }
  3065.                     $(document.body).trigger('filter_price_slider_slide', [ui.values[0], ui.values[1], minPrice, maxPrice, $this]);
  3066.                 },
  3067.                 change: function (event, ui) {
  3068.                     $(document.body).trigger('price_slider_change', [ui.values[0], ui.values[1]]);
  3069.                 }
  3070.             });
  3071.         });
  3072.  
  3073.         //Submit filter form
  3074.         $('.woodmart-product-filters').one('click', '.woodmart-pf-btn button', function (e) {
  3075.             var $form = $(this).parents('.woodmart-product-filters');
  3076.             removeEmptyValues($form);
  3077.             changeFormAction($form);
  3078.  
  3079.             if (!$('body').hasClass('woodmart-ajax-shop-on') || typeof ($.fn.pjax) == 'undefined' || !$form.hasClass('with-ajax')) return;
  3080.             $.pjax({
  3081.                 container: '.main-page-wrapper',
  3082.                 timeout: woodmart_settings.pjax_timeout,
  3083.                 url: $form.attr('action'),
  3084.                 data: $form.serialize(),
  3085.                 scrollTo: false
  3086.             });
  3087.             $(this).prop('disabled', true);
  3088.         });
  3089.  
  3090.         //Create labels after ajax
  3091.         $('.woodmart-pf-checkboxes .pf-active > .pf-value').each(function () {
  3092.             var resultsWrapper = $(this).parents('.woodmart-pf-checkboxes').find('.woodmart-pf-results');
  3093.             resultsWrapper.prepend('<li class="selected-value" data-title="' + $(this).data('val') + '">' + $(this).data('title') + '</li>');
  3094.         });
  3095.  
  3096.     };
  3097.  
  3098.     /**
  3099.     *-------------------------------------------------------------------------------------------------------------------------------------------
  3100.     * Sticky sidebar button
  3101.     *-------------------------------------------------------------------------------------------------------------------------------------------
  3102.     */
  3103.  
  3104.     woodmartThemeModule.stickySidebarBtn = function () {
  3105.         var $trigger = $('.woodmart-show-sidebar-btn');
  3106.         var $stickyBtn = $('.shop-sidebar-opener:not(.toolbar)');
  3107.  
  3108.         if ($stickyBtn.length <= 0 || $trigger.length <= 0 || $(window).width() >= 1024) return;
  3109.  
  3110.         var stickySidebarBtnToggle = function () {
  3111.             var btnOffset = $trigger.offset().top + $trigger.outerHeight();
  3112.             var windowScroll = $(window).scrollTop();
  3113.  
  3114.             if (btnOffset < windowScroll) {
  3115.                 $stickyBtn.addClass('woodmart-sidebar-btn-shown');
  3116.             } else {
  3117.                 $stickyBtn.removeClass('woodmart-sidebar-btn-shown');
  3118.             }
  3119.         };
  3120.  
  3121.         stickySidebarBtnToggle();
  3122.  
  3123.         $(window).scroll(stickySidebarBtnToggle);
  3124.         $(window).resize(stickySidebarBtnToggle);
  3125.     };
  3126.  
  3127.     /**
  3128.     *-------------------------------------------------------------------------------------------------------------------------------------------
  3129.     * Product thumbnail images & photo swipe gallery
  3130.     *-------------------------------------------------------------------------------------------------------------------------------------------
  3131.     */
  3132.  
  3133.     woodmartThemeModule.productImages = function () {
  3134.         // Init photoswipe
  3135.  
  3136.         var currentImage,
  3137.             $productGallery = $('.woocommerce-product-gallery'),
  3138.             $mainImages = $('.woocommerce-product-gallery__wrapper'),
  3139.             $thumbs = $productGallery.find('.thumbnails'),
  3140.             currentClass = 'current-image',
  3141.             PhotoSwipeTrigger = '.woodmart-show-product-gallery';
  3142.  
  3143.         $thumbs.addClass('thumbnails-ready');
  3144.  
  3145.         if ($productGallery.hasClass('image-action-popup')) {
  3146.             PhotoSwipeTrigger += ', .woocommerce-product-gallery__image a';
  3147.         }
  3148.  
  3149.         $productGallery.on('click', '.woocommerce-product-gallery__image a', function (e) {
  3150.             e.preventDefault();
  3151.         });
  3152.  
  3153.         $productGallery.on('click', PhotoSwipeTrigger, function (e) {
  3154.             e.preventDefault();
  3155.  
  3156.             currentImage = $(this).attr('href');
  3157.  
  3158.             // build items array
  3159.             var items = getProductItems();
  3160.  
  3161.             woodmartThemeModule.callPhotoSwipe(getCurrentGalleryIndex(e), items);
  3162.  
  3163.         });
  3164.  
  3165.         $thumbs.on('click', '.image-link', function (e) {
  3166.             e.preventDefault();
  3167.  
  3168.             // if( $thumbs.hasClass('thumbnails-large') ) {
  3169.             //     var index = $(e.currentTarget).index() + 1;
  3170.             //     var items = getProductItems();
  3171.             //     callPhotoSwipe(index, items);
  3172.             //     return;
  3173.             // }
  3174.  
  3175.             // var href = $(this).attr('href'),
  3176.             //     src  = $(this).attr('data-single-image'),
  3177.             //     width = $(this).attr('data-width'),
  3178.             //     height = $(this).attr('data-height'),
  3179.             //     title = $(this).attr('title');
  3180.  
  3181.             // $thumbs.find('.' + currentClass).removeClass(currentClass);
  3182.             // $(this).addClass(currentClass);
  3183.  
  3184.             // if( $mainImages.find('img').attr('src') == src ) return;
  3185.  
  3186.             // $mainImages.addClass('loading-image').attr('href', href).find('img').attr('src', src).attr('srcset', src).one('load', function() {
  3187.             //     $mainImages.removeClass('loading-image').data('width', width).data('height', height).attr('title', title);
  3188.             // });
  3189.  
  3190.         });
  3191.  
  3192.         var getCurrentGalleryIndex = function (e) {
  3193.             if ($mainImages.hasClass('owl-carousel'))
  3194.                 return $mainImages.find('.owl-item.active').index();
  3195.             else return $(e.currentTarget).parent().parent().index();
  3196.         };
  3197.  
  3198.         var getProductItems = function () {
  3199.             var items = [];
  3200.  
  3201.             $mainImages.find('figure a img').each(function () {
  3202.                 var src = $(this).attr('data-large_image'),
  3203.                     width = $(this).attr('data-large_image_width'),
  3204.                     height = $(this).attr('data-large_image_height'),
  3205.                     caption = $(this).data('caption');
  3206.  
  3207.                 items.push({
  3208.                     src: src,
  3209.                     w: width,
  3210.                     h: height,
  3211.                     title: (woodmart_settings.product_images_captions == 'yes') ? caption : false
  3212.                 });
  3213.  
  3214.             });
  3215.  
  3216.             return items;
  3217.         };
  3218.  
  3219.         /* Fix zoom for first item firstly */
  3220.  
  3221.         if ($productGallery.hasClass('image-action-zoom')) {
  3222.             var zoom_target = $('.woocommerce-product-gallery__image');
  3223.             var image_to_zoom = zoom_target.find('img');
  3224.  
  3225.             // But only zoom if the img is larger than its container.
  3226.             if (image_to_zoom.attr('width') > $('.woocommerce-product-gallery').width()) {
  3227.                 zoom_target.trigger('zoom.destroy');
  3228.                 zoom_target.zoom({
  3229.                     touch: false
  3230.                 });
  3231.             }
  3232.         }
  3233.     };
  3234.  
  3235.     /**
  3236.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3237.      * Sticky add to cart
  3238.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3239.      */
  3240.  
  3241.     woodmartThemeModule.stickyAddToCart = function () {
  3242.         var $trigger = $('.summary-inner .cart');
  3243.         var $stickyBtn = $('.woodmart-sticky-btn');
  3244.  
  3245.         if ($stickyBtn.length <= 0 || $trigger.length <= 0 || ($(window).width() <= 768 && $stickyBtn.hasClass('mobile-off'))) return;
  3246.  
  3247.         var summaryOffset = $trigger.offset().top + $trigger.outerHeight();
  3248.         var $scrollToTop = $('.scrollToTop');
  3249.  
  3250.         var stickyAddToCartToggle = function () {
  3251.             var windowScroll = $(window).scrollTop();
  3252.             var windowHeight = $(window).height();
  3253.             var documentHeight = $(document).height();
  3254.  
  3255.             if (summaryOffset < windowScroll && windowScroll + windowHeight != documentHeight) {
  3256.                 $stickyBtn.addClass('woodmart-sticky-btn-shown');
  3257.                 $scrollToTop.addClass('woodmart-sticky-btn-shown');
  3258.  
  3259.             } else if (windowScroll + windowHeight == documentHeight || summaryOffset > windowScroll) {
  3260.                 $stickyBtn.removeClass('woodmart-sticky-btn-shown');
  3261.                 $scrollToTop.removeClass('woodmart-sticky-btn-shown');
  3262.             }
  3263.         };
  3264.  
  3265.         stickyAddToCartToggle();
  3266.  
  3267.         $(window).scroll(stickyAddToCartToggle);
  3268.  
  3269.         $('.woodmart-sticky-add-to-cart').on('click', function (e) {
  3270.             e.preventDefault();
  3271.             $('html, body').animate({
  3272.                 scrollTop: $('.summary-inner').offset().top
  3273.             }, 800);
  3274.         });
  3275.  
  3276.         // Wishlist.
  3277.         $('.woodmart-sticky-btn .woodmart-wishlist-btn a').on('click', function (e) {
  3278.             if (!$(this).hasClass('added')) {
  3279.                 e.preventDefault();
  3280.             }
  3281.  
  3282.             $('.summary-inner > .woodmart-wishlist-btn a').trigger('click');
  3283.         });
  3284.  
  3285.         $(document).on('added_to_wishlist', function () {
  3286.             $('.woodmart-sticky-btn .woodmart-wishlist-btn a').addClass('added');
  3287.         });
  3288.  
  3289.         // Compare.
  3290.         $('.woodmart-sticky-btn .woodmart-compare-btn a').on('click', function (e) {
  3291.             if (!$(this).hasClass('added')){
  3292.                 e.preventDefault();
  3293.             }
  3294.  
  3295.             $('.summary-inner > .woodmart-compare-btn a').trigger('click');
  3296.         });
  3297.  
  3298.         $(document).on('added_to_compare', function () {
  3299.             $('.woodmart-sticky-btn .woodmart-compare-btn a').addClass('added');
  3300.         });
  3301.     };
  3302.  
  3303.     /**
  3304.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3305.      * Login dropdown
  3306.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3307.      */
  3308.  
  3309.     woodmartThemeModule.loginDropdown = function () {
  3310.         if ($(window).width() <= 1024) return;
  3311.  
  3312.         $('.menu-item-register:not(.login-side-opener)').on('mouseover', function () {
  3313.             $(this).addClass('opened');
  3314.         }).on('mouseout', function (event) {
  3315.             if (!$(event.target).is('input')) {
  3316.                 $(this).removeClass('opened');
  3317.             }
  3318.         }).on('mouseleave', function () {
  3319.             var $this = $(this);
  3320.             setTimeout(function () {
  3321.                 $this.removeClass('opened');
  3322.             }, 300);
  3323.         });
  3324.     };
  3325.  
  3326.     /**
  3327.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3328.      * Login sidebar
  3329.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3330.      */
  3331.  
  3332.     woodmartThemeModule.loginSidebar = function () {
  3333.         var body = $('body');
  3334.         var loginFormSide = $('.login-form-side');
  3335.         var closeSide = $('.woodmart-close-side');
  3336.  
  3337.         $('.login-side-opener').on('click', function (e) {
  3338.             e.preventDefault();
  3339.             if (isOpened()) {
  3340.                 closeWidget();
  3341.             } else {
  3342.                 setTimeout(function () {
  3343.                     openWidget();
  3344.                 }, 10);
  3345.             }
  3346.         });
  3347.  
  3348.         body.on('click touchstart', '.woodmart-close-side', function () {
  3349.             if (isOpened()) closeWidget();
  3350.         });
  3351.  
  3352.         body.on('click', '.close-side-widget', function (e) {
  3353.             e.preventDefault();
  3354.             if (isOpened()) closeWidget();
  3355.         });
  3356.  
  3357.         $(document).keyup(function (e) {
  3358.             if (e.keyCode === 27 && isOpened()) closeWidget();
  3359.         });
  3360.  
  3361.         var closeWidget = function () {
  3362.             loginFormSide.removeClass('woodmart-login-side-opened');
  3363.             closeSide.removeClass('woodmart-close-side-opened');
  3364.         };
  3365.  
  3366.         var openWidget = function () {
  3367.             loginFormSide.addClass('woodmart-login-side-opened');
  3368.             closeSide.addClass('woodmart-close-side-opened');
  3369.         };
  3370.  
  3371.         var isOpened = function () {
  3372.             return loginFormSide.hasClass('woodmart-login-side-opened');
  3373.         };
  3374.     };
  3375.  
  3376.     /**
  3377.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3378.      * Shop loader position
  3379.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3380.      */
  3381.  
  3382.     woodmartThemeModule.shopLoader = function () {
  3383.         var loaderClass = '.woodmart-shop-loader',
  3384.             contentClass = '.products[data-source="main_loop"]',
  3385.             sidebarClass = '.area-sidebar-shop',
  3386.             sidebarLeftClass = 'sidebar-left',
  3387.             hiddenClass = 'hidden-loader',
  3388.             hiddenTopClass = 'hidden-from-top',
  3389.             hiddenBottomClass = 'hidden-from-bottom';
  3390.  
  3391.         var loaderVerticalPosition = function () {
  3392.             var $products = $(contentClass),
  3393.                 $loader = $products.parent().find(loaderClass);
  3394.  
  3395.             if ($products.length < 1) return;
  3396.  
  3397.             var offset = $(window).height() / 2,
  3398.                 scrollTop = $(window).scrollTop(),
  3399.                 holderTop = $products.offset().top - offset,
  3400.                 holderHeight = $products.height(),
  3401.                 holderBottom = holderTop + holderHeight - 130;
  3402.  
  3403.             if (scrollTop < holderTop) {
  3404.                 $loader.addClass(hiddenClass + ' ' + hiddenTopClass);
  3405.             } else if (scrollTop > holderBottom) {
  3406.                 $loader.addClass(hiddenClass + ' ' + hiddenBottomClass);
  3407.             } else {
  3408.                 $loader.removeClass(hiddenClass + ' ' + hiddenTopClass + ' ' + hiddenBottomClass);
  3409.             }
  3410.         };
  3411.  
  3412.         var loaderHorizontalPosition = function () {
  3413.             var $products = $(contentClass),
  3414.                 $sidebar = $(sidebarClass),
  3415.                 $loader = $products.parent().find(loaderClass),
  3416.                 sidebarWidth = $sidebar.outerWidth();
  3417.  
  3418.             if ($products.length < 1) return;
  3419.  
  3420.             if (sidebarWidth > 0 && $sidebar.hasClass(sidebarLeftClass)) {
  3421.                 if ($('body').hasClass('rtl')) {
  3422.                     $loader.css({
  3423.                         'marginLeft': - sidebarWidth / 2 - 15
  3424.                     })
  3425.                 } else {
  3426.                     $loader.css({
  3427.                         'marginLeft': sidebarWidth / 2 - 15
  3428.                     })
  3429.                 }
  3430.             } else if (sidebarWidth > 0) {
  3431.                 if ($('body').hasClass('rtl')) {
  3432.                     $loader.css({
  3433.                         'marginLeft': sidebarWidth / 2 - 15
  3434.                     })
  3435.                 } else {
  3436.                     $loader.css({
  3437.                         'marginLeft': - sidebarWidth / 2 - 15
  3438.                     })
  3439.                 }
  3440.             }
  3441.  
  3442.         };
  3443.  
  3444.         $(window).off('scroll.loaderVerticalPosition');
  3445.         $(window).off('loaderHorizontalPosition');
  3446.  
  3447.         $(window).on('scroll.loaderVerticalPosition', loaderVerticalPosition);
  3448.         $(window).on('resize.loaderHorizontalPosition', loaderHorizontalPosition);
  3449.  
  3450.         loaderVerticalPosition();
  3451.         loaderHorizontalPosition();
  3452.     };
  3453.  
  3454.     /**
  3455.     *-------------------------------------------------------------------------------------------------------------------------------------------
  3456.     * "Sort by" widget reinit
  3457.     *-------------------------------------------------------------------------------------------------------------------------------------------
  3458.     */
  3459.     woodmartThemeModule.sortByWidget = function () {
  3460.         if (!$('body').hasClass('woodmart-ajax-shop-on') || typeof ($.fn.pjax) == 'undefined') return;
  3461.  
  3462.         $('.woocommerce-ordering').on('change', 'select.orderby', function () {
  3463.             var $form = $(this).closest('form');
  3464.  
  3465.             $form.find('[name="_pjax"]').remove();
  3466.  
  3467.             $.pjax({
  3468.                 container: '.main-page-wrapper',
  3469.                 timeout: woodmart_settings.pjax_timeout,
  3470.                 url: '?' + $form.serialize(),
  3471.                 scrollTo: false
  3472.             });
  3473.         });
  3474.  
  3475.         $('.woocommerce-ordering').submit(function (e) {
  3476.             e.preventDefault(e);
  3477.         });
  3478.     };
  3479.  
  3480.     /**
  3481.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3482.      * Add filters dropdowns compatibility
  3483.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3484.      */
  3485.  
  3486.     woodmartThemeModule.filterDropdowns = function () {
  3487.         // Init
  3488.         $('.woodmart-widget-layered-nav-dropdown-form').each(function () {
  3489.             var $form = $(this);
  3490.             var $select = $form.find('select');
  3491.             var slug = $select.data('slug');
  3492.  
  3493.             $select.change(function () {
  3494.                 var val = $(this).val();
  3495.                 $('input[name=filter_' + slug + ']').val(val);
  3496.             });
  3497.  
  3498.             if ($().selectWoo) {
  3499.                 $select.selectWoo({
  3500.                     placeholder: $select.data('placeholder'),
  3501.                     minimumResultsForSearch: 5,
  3502.                     width: '100%',
  3503.                     allowClear: $select.attr('multiple') ? false : true,
  3504.                     language: {
  3505.                         noResults: function () {
  3506.                             return $select.data('noResults');
  3507.                         }
  3508.                     }
  3509.                 }).on('select2:unselecting', function () {
  3510.                     $(this).data('unselecting', true);
  3511.                 }).on('select2:opening', function (e) {
  3512.                     if ($(this).data('unselecting')) {
  3513.                         $(this).removeData('unselecting');
  3514.                         e.preventDefault();
  3515.                     }
  3516.                 });
  3517.             }
  3518.         });
  3519.  
  3520.         function ajaxAction($element) {
  3521.             var $form = $element.parent('.woodmart-widget-layered-nav-dropdown-form');
  3522.             if (!$('body').hasClass('woodmart-ajax-shop-on') || typeof ($.fn.pjax) == 'undefined') {
  3523.                 return;
  3524.             }
  3525.  
  3526.             $.pjax({
  3527.                 container: '.main-page-wrapper',
  3528.                 timeout: woodmart_settings.pjax_timeout,
  3529.                 url: $form.attr('action'),
  3530.                 data: $form.serialize(),
  3531.                 scrollTo: false
  3532.             });
  3533.         }
  3534.  
  3535.         $('.woodmart-widget-layered-nav-dropdown__submit').on('click', function (e) {
  3536.             if (!$(this).siblings('select').attr('multiple') || !$('body').hasClass('woodmart-ajax-shop-on')) {
  3537.                 return;
  3538.             }
  3539.  
  3540.             ajaxAction($(this));
  3541.  
  3542.             $(this).prop('disabled', true);
  3543.         });
  3544.  
  3545.         $('.woodmart-widget-layered-nav-dropdown-form select').on('change', function (e) {
  3546.             if (!$('body').hasClass('woodmart-ajax-shop-on')) {
  3547.                 $(this).parent().submit();
  3548.                 return;
  3549.             }
  3550.  
  3551.             if ($(this).attr('multiple')) {
  3552.                 return;
  3553.             }
  3554.  
  3555.             ajaxAction($(this));
  3556.         });
  3557.  
  3558.     };
  3559.  
  3560.     /**
  3561.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3562.      * Sticky details block for special product type
  3563.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3564.      */
  3565.  
  3566.     woodmartThemeModule.stickyDetails = function () {
  3567.         if (
  3568.             !$('body').hasClass('woodmart-product-sticky-on')
  3569.             || $(window).width() <= 1024
  3570.         ) return;
  3571.  
  3572.         var details = $('.entry-summary');
  3573.  
  3574.  
  3575.         details.each(function () {
  3576.             var $column = $(this),
  3577.                 offset = 40,
  3578.                 $inner = $column.find('.summary-inner'),
  3579.                 $images = $column.parent().find('.product-images-inner');
  3580.  
  3581.             if ($('body').hasClass('enable-sticky-header') || $('.whb-sticky-row').length > 0 || $('.whb-sticky-header').length > 0) {
  3582.                 offset = 150;
  3583.             }
  3584.  
  3585.             $images.imagesLoaded(function () {
  3586.                 var diff = $inner.outerHeight() - $images.outerHeight();
  3587.  
  3588.                 if (diff < -100) {
  3589.                     $inner.stick_in_parent({
  3590.                         offset_top: offset
  3591.                     });
  3592.                 } else if (diff > 100) {
  3593.                     $images.stick_in_parent({
  3594.                         offset_top: offset
  3595.                     });
  3596.                 }
  3597.  
  3598.                 $(window).resize(function () {
  3599.  
  3600.                     if ($(window).width() <= 1024) {
  3601.                         $inner.trigger('sticky_kit:detach');
  3602.                         $images.trigger('sticky_kit:detach');
  3603.                     } else if ($inner.outerHeight() < $images.outerHeight()) {
  3604.                         $inner.stick_in_parent({
  3605.                             offset_top: offset
  3606.                         });
  3607.                     } else {
  3608.                         $images.stick_in_parent({
  3609.                             offset_top: offset
  3610.                         });
  3611.                     }
  3612.  
  3613.                 });
  3614.             });
  3615.  
  3616.         });
  3617.     };
  3618.  
  3619.     /**
  3620.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3621.      * Product accordion
  3622.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3623.      */
  3624.  
  3625.     woodmartThemeModule.productAccordion = function () {
  3626.         var $accordion = $('.wc-tabs-wrapper');
  3627.  
  3628.         var time = 300;
  3629.  
  3630.         var hash = window.location.hash;
  3631.         var url = window.location.href;
  3632.  
  3633.         if (hash.toLowerCase().indexOf('comment-') >= 0 || hash === '#reviews' || hash === '#tab-reviews') {
  3634.             $accordion.find('.tab-title-reviews').addClass('active');
  3635.         } else if (url.indexOf('comment-page-') > 0 || url.indexOf('cpage=') > 0) {
  3636.             $accordion.find('.tab-title-reviews').addClass('active');
  3637.         } else {
  3638.             $accordion.find('.woodmart-accordion-title').first().addClass('active');
  3639.         }
  3640.  
  3641.         $accordion.on('click', '.woodmart-accordion-title', function (e) {
  3642.             e.preventDefault();
  3643.  
  3644.             var $this = $(this),
  3645.                 $panel = $this.siblings('.woocommerce-Tabs-panel');
  3646.  
  3647.             var curentIndex = $this.parent().index();
  3648.             var oldIndex = $this.parent().siblings().find('.active').parent('.woodmart-tab-wrapper').index();
  3649.  
  3650.             if ($this.hasClass('active')) {
  3651.                 oldIndex = curentIndex;
  3652.                 $this.removeClass('active');
  3653.                 $panel.stop().slideUp(time);
  3654.             } else {
  3655.                 $accordion.find('.woodmart-accordion-title').removeClass('active');
  3656.                 $accordion.find('.woocommerce-Tabs-panel').slideUp();
  3657.                 $this.addClass('active');
  3658.                 $panel.stop().slideDown(time);
  3659.             }
  3660.  
  3661.             if (oldIndex == -1) oldIndex = curentIndex;
  3662.  
  3663.             $(window).resize();
  3664.  
  3665.             setTimeout(function () {
  3666.                 $(window).resize();
  3667.                 if ($(window).width() < 1024 && curentIndex > oldIndex) {
  3668.                     $('html, body').animate({
  3669.                         scrollTop: $this.offset().top - $this.outerHeight() - $('.sticky-header').outerHeight() - 50
  3670.                     }, 500);
  3671.                 }
  3672.             }, time);
  3673.  
  3674.         });
  3675.     };
  3676.  
  3677.     /**
  3678.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3679.      * Product thumbnail images & photo swipe gallery
  3680.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3681.      */
  3682.  
  3683.     woodmartThemeModule.productImagesGallery = function () {
  3684.         var $mainGallery = $('.woocommerce-product-gallery__wrapper:not(.quick-view-gallery)');
  3685.         var $thumbs = $('.images .thumbnails');
  3686.         var $mainOwl = $('.woocommerce-product-gallery__wrapper');
  3687.         var thumbs_position = woodmart_settings.product_gallery.thumbs_slider.position;
  3688.  
  3689.         // if (woodmart_settings.product_gallery.thumbs_slider.position == 'centered' && $mainOwl.find('.product-image-wrap').length > 1) {
  3690.         //     var moveblock = $mainOwl.find('.product-image-wrap:eq(0)');
  3691.         //     moveblock.remove();
  3692.         //     $mainOwl.find('.product-image-wrap:eq(0)').after(moveblock);
  3693.         // }
  3694.  
  3695.         if (woodmart_settings.product_gallery.images_slider) {
  3696.             if (woodmart_settings.product_slider_auto_height == 'yes') {
  3697.                 $('.product-images').imagesLoaded(function () {
  3698.                     initMainGallery();
  3699.                 });
  3700.             } else {
  3701.                 initMainGallery();
  3702.             }
  3703.         } else if (jQuery(window).width() <= 1024 && (thumbs_position == 'bottom_combined' || thumbs_position == 'bottom_column' || thumbs_position == 'bottom_grid')) {
  3704.             initMainGallery();
  3705.         }
  3706.  
  3707.         if (woodmart_settings.product_gallery.thumbs_slider.enabled && woodmart_settings.product_gallery.images_slider) {
  3708.             initThumbnailsMarkup();
  3709.             if (woodmart_settings.product_gallery.thumbs_slider.position == 'left' && jQuery(window).width() > 1024 && typeof ($.fn.slick) != 'undefined') {
  3710.                 initThumbnailsVertical();
  3711.             } else {
  3712.                 initThumbnailsHorizontal();
  3713.             }
  3714.         }
  3715.  
  3716.         function initMainGallery() {
  3717.             $mainGallery.trigger('destroy.owl.carousel');
  3718.             $mainGallery.addClass('owl-carousel').owlCarousel(woodmartTheme.mainCarouselArg);
  3719.             $(document).trigger('wood-images-loaded');
  3720.         };
  3721.  
  3722.         function initThumbnailsMarkup() {
  3723.             var markup = '';
  3724.  
  3725.             $mainGallery.find('.woocommerce-product-gallery__image').each(function () {
  3726.                 var image = $(this).data('thumb'),
  3727.                     alt = $(this).find('a > img').attr('alt'),
  3728.                     title = $(this).find('a > img').attr('title');
  3729.  
  3730.                 markup += '<div class="product-image-thumbnail"><img alt="' + alt + '" title="' + title + '" src="' + image + '" /></div>';
  3731.             });
  3732.  
  3733.             if ($thumbs.hasClass('slick-slider')) {
  3734.                 $thumbs.slick('unslick');
  3735.             } else if ($thumbs.hasClass('owl-carousel')) {
  3736.                 $thumbs.trigger('destroy.owl.carousel');
  3737.             }
  3738.  
  3739.             $thumbs.empty();
  3740.             $thumbs.append(markup);
  3741.         };
  3742.  
  3743.         function initThumbnailsVertical() {
  3744.             $thumbs.slick({
  3745.                 slidesToShow: woodmart_settings.product_gallery.thumbs_slider.items.vertical_items,
  3746.                 slidesToScroll: woodmart_settings.product_gallery.thumbs_slider.items.vertical_items,
  3747.                 vertical: true,
  3748.                 verticalSwiping: true,
  3749.                 infinite: false,
  3750.             });
  3751.  
  3752.             $thumbs.on('click', '.product-image-thumbnail', function (e) {
  3753.                 var i = $(this).index();
  3754.                 $mainOwl.trigger('to.owl.carousel', i);
  3755.             });
  3756.  
  3757.             $mainOwl.on('changed.owl.carousel', function (e) {
  3758.                 var i = e.item.index;
  3759.                 $thumbs.slick('slickGoTo', i);
  3760.                 $thumbs.find('.active-thumb').removeClass('active-thumb');
  3761.                 $thumbs.find('.product-image-thumbnail').eq(i).addClass('active-thumb');
  3762.             });
  3763.  
  3764.             $thumbs.find('.product-image-thumbnail').eq(0).addClass('active-thumb');
  3765.         };
  3766.  
  3767.         function initThumbnailsHorizontal() {
  3768.             $thumbs.addClass('owl-carousel').owlCarousel({
  3769.                 rtl: $('body').hasClass('rtl'),
  3770.                 items: woodmart_settings.product_gallery.thumbs_slider.items.desktop,
  3771.                 responsive: {
  3772.                     1025: {
  3773.                         items: woodmart_settings.product_gallery.thumbs_slider.items.desktop
  3774.                     },
  3775.                     769: {
  3776.                         items: woodmart_settings.product_gallery.thumbs_slider.items.tablet_landscape
  3777.                     },
  3778.                     577: {
  3779.                         items: woodmart_settings.product_gallery.thumbs_slider.items.tablet
  3780.                     },
  3781.                     0: {
  3782.                         items: woodmart_settings.product_gallery.thumbs_slider.items.mobile
  3783.                     }
  3784.                 },
  3785.                 dots: false,
  3786.                 nav: true,
  3787.                 // mouseDrag: false,
  3788.                 navText: false,
  3789.             });
  3790.  
  3791.             var $thumbsOwl = $thumbs.owlCarousel();
  3792.  
  3793.             $thumbs.on('click', '.owl-item', function (e) {
  3794.                 var i = $(this).index();
  3795.                 $thumbsOwl.trigger('to.owl.carousel', i);
  3796.                 $mainOwl.trigger('to.owl.carousel', i);
  3797.             });
  3798.  
  3799.             $mainOwl.on('changed.owl.carousel', function (e) {
  3800.                 var i = e.item.index;
  3801.                 $thumbsOwl.trigger('to.owl.carousel', i);
  3802.                 $thumbs.find('.active-thumb').removeClass('active-thumb');
  3803.                 $thumbs.find('.product-image-thumbnail').eq(i).addClass('active-thumb');
  3804.             });
  3805.  
  3806.             $thumbs.find('.product-image-thumbnail').eq(0).addClass('active-thumb');
  3807.         };
  3808.  
  3809.         // Update first thumbnail on variation change
  3810.     };
  3811.  
  3812.     /**
  3813.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3814.      * WooCommerce adding to cart
  3815.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3816.      */
  3817.  
  3818.     woodmartThemeModule.addToCart = function () {
  3819.         var that = this;
  3820.         var timeoutNumber = 0;
  3821.         var timeout;
  3822.  
  3823.         that.addToCartAllTypes();
  3824.  
  3825.         $('body').on('added_to_cart', function (event, fragments, cart_hash) {
  3826.  
  3827.             if (woodmart_settings.add_to_cart_action == 'popup') {
  3828.  
  3829.                 var html = [
  3830.                     '<div class="added-to-cart">',
  3831.                     '<h4>' + woodmart_settings.added_to_cart + '</h4>',
  3832.                     '<a href="#" class="btn btn-style-link btn-color-default close-popup">' + woodmart_settings.continue_shopping + '</a>',
  3833.                     '<a href="' + woodmart_settings.cart_url + '" class="btn btn-color-primary view-cart">' + woodmart_settings.view_cart + '</a>',
  3834.                     '</div>',
  3835.                 ].join("");
  3836.  
  3837.                 $.magnificPopup.open({
  3838.                     removalDelay: 500, //delay removal by X to allow out-animation
  3839.                     tClose: woodmart_settings.close,
  3840.                     tLoading: woodmart_settings.loading,
  3841.                     callbacks: {
  3842.                         beforeOpen: function () {
  3843.                             this.st.mainClass = woodmartTheme.popupEffect + '  cart-popup-wrapper';
  3844.                         },
  3845.                     },
  3846.                     items: {
  3847.                         src: '<div class="mfp-with-anim white-popup popup-added_to_cart">' + html + '</div>',
  3848.                         type: 'inline'
  3849.                     }
  3850.                 });
  3851.  
  3852.                 $('.white-popup').on('click', '.close-popup', function (e) {
  3853.                     e.preventDefault();
  3854.                     $.magnificPopup.close();
  3855.                 });
  3856.  
  3857.                 closeAfterTimeout();
  3858.             } else if (woodmart_settings.add_to_cart_action == 'widget') {
  3859.  
  3860.                 clearTimeout(timeoutNumber);
  3861.  
  3862.                 if ($('.act-scroll .woodmart-shopping-cart, .whb-sticked .woodmart-shopping-cart').length > 0) {
  3863.                     $('.act-scroll .woodmart-shopping-cart, .whb-sticked .woodmart-shopping-cart').addClass('display-widget');
  3864.                 } else {
  3865.                     $('.whb-header .woodmart-shopping-cart').addClass('display-widget');
  3866.                 }
  3867.  
  3868.                 if ($('.cart-widget-opener').length > 0) {
  3869.                     $('.cart-widget-opener').trigger('click');
  3870.                 }
  3871.  
  3872.                 timeoutNumber = setTimeout(function () {
  3873.                     $('.display-widget').removeClass('display-widget');
  3874.                 }, 3500);
  3875.  
  3876.  
  3877.                 closeAfterTimeout();
  3878.             }
  3879.  
  3880.             that.btnsToolTips();
  3881.  
  3882.         });
  3883.  
  3884.         var closeAfterTimeout = function () {
  3885.             if ('yes' !== woodmart_settings.add_to_cart_action_timeout) {
  3886.                 return false;
  3887.             }
  3888.  
  3889.             clearTimeout(timeout);
  3890.  
  3891.             timeout = setTimeout(function () {
  3892.                 $('.woodmart-close-side').trigger('click');
  3893.                 $.magnificPopup.close();
  3894.             }, parseInt(woodmart_settings.add_to_cart_action_timeout_number) * 1000);
  3895.         };
  3896.     },
  3897.  
  3898.     woodmartThemeModule.addToCartAllTypes = function () {
  3899.         if (woodmart_settings.ajax_add_to_cart == false) return;
  3900.         // AJAX add to cart for all types of products
  3901.  
  3902.         $('body').on('submit', 'form.cart', function (e) {
  3903.             var $productWrapper = $(this).parents('.single-product-page');
  3904.             if ($productWrapper.hasClass('product-type-external') || $productWrapper.hasClass('product-type-zakeke')) return;
  3905.  
  3906.             e.preventDefault();
  3907.  
  3908.             var $form = $(this),
  3909.                 $thisbutton = $form.find('.single_add_to_cart_button'),
  3910.                 data = $form.serialize();
  3911.  
  3912.             data += '&action=woodmart_ajax_add_to_cart';
  3913.  
  3914.             if ($thisbutton.val()) {
  3915.                 data += '&add-to-cart=' + $thisbutton.val();
  3916.             }
  3917.  
  3918.             $thisbutton.removeClass('added not-added');
  3919.             $thisbutton.addClass('loading');
  3920.  
  3921.             // Trigger event
  3922.             $(document.body).trigger('adding_to_cart', [$thisbutton, data]);
  3923.  
  3924.             $.ajax({
  3925.                 url: woodmart_settings.ajaxurl,
  3926.                 data: data,
  3927.                 method: 'POST',
  3928.                 success: function (response) {
  3929.                     if (!response) {
  3930.                         return;
  3931.                     }
  3932.  
  3933.                     var this_page = window.location.toString();
  3934.  
  3935.                     this_page = this_page.replace('add-to-cart', 'added-to-cart');
  3936.  
  3937.                     if (response.error && response.product_url) {
  3938.                         window.location = response.product_url;
  3939.                         return;
  3940.                     }
  3941.  
  3942.                     // Redirect to cart option
  3943.                     if (wc_add_to_cart_params.cart_redirect_after_add === 'yes') {
  3944.  
  3945.                         window.location = wc_add_to_cart_params.cart_url;
  3946.                         return;
  3947.  
  3948.                     } else {
  3949.  
  3950.                         $thisbutton.removeClass('loading');
  3951.  
  3952.                         var fragments = response.fragments;
  3953.                         var cart_hash = response.cart_hash;
  3954.  
  3955.  
  3956.                         // Block fragments class
  3957.                         if (fragments) {
  3958.                             $.each(fragments, function (key) {
  3959.                                 $(key).addClass('updating');
  3960.                             });
  3961.                         }
  3962.  
  3963.                         // Replace fragments
  3964.                         if (fragments) {
  3965.                             $.each(fragments, function (key, value) {
  3966.                                 $(key).replaceWith(value);
  3967.                             });
  3968.                         }
  3969.  
  3970.                         // Show notices
  3971.                         if (response.notices.indexOf('error') > 0) {
  3972.                             $('body').append(response.notices);
  3973.                             $thisbutton.addClass('not-added');
  3974.                         } else {
  3975.                             if (woodmart_settings.add_to_cart_action == 'widget')
  3976.                                 $.magnificPopup.close();
  3977.  
  3978.                             // Changes button classes
  3979.                             $thisbutton.addClass('added');
  3980.                             // Trigger event so themes can refresh other areas
  3981.                             $(document.body).trigger('added_to_cart', [fragments, cart_hash, $thisbutton]);
  3982.                         }
  3983.  
  3984.                     }
  3985.                 },
  3986.                 error: function () {
  3987.                     console.log('ajax adding to cart error');
  3988.                 },
  3989.                 complete: function () { },
  3990.             });
  3991.  
  3992.         });
  3993.     };
  3994.  
  3995.     /**
  3996.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3997.      * Quick Shop
  3998.      *-------------------------------------------------------------------------------------------------------------------------------------------
  3999.      */
  4000.  
  4001.     woodmartThemeModule.quickShop = function () {
  4002.         var btnSelector = '.quick-shop-on.product-type-variable .add_to_cart_button';
  4003.  
  4004.         $(document).on('click', btnSelector, function (e) {
  4005.             e.preventDefault();
  4006.  
  4007.             var $this = $(this),
  4008.                 $product = $this.parents('.product').first(),
  4009.                 $content = $product.find('.quick-shop-form'),
  4010.                 id = $product.data('id'),
  4011.                 loadingClass = 'btn-loading';
  4012.  
  4013.             if ($this.hasClass(loadingClass)) return;
  4014.  
  4015.  
  4016.             // Simply show quick shop form if it is already loaded with AJAX previously
  4017.             if ($product.hasClass('quick-shop-loaded')) {
  4018.                 $product.addClass('quick-shop-shown');
  4019.                 return;
  4020.             }
  4021.  
  4022.             $this.addClass(loadingClass);
  4023.             $product.addClass('loading-quick-shop');
  4024.  
  4025.             $.ajax({
  4026.                 url: woodmart_settings.ajaxurl,
  4027.                 data: {
  4028.                     action: 'woodmart_quick_shop',
  4029.                     id: id,
  4030.                 },
  4031.                 method: 'get',
  4032.                 success: function (data) {
  4033.  
  4034.                     // insert variations form
  4035.                     $content.append(data);
  4036.  
  4037.                     initVariationForm($product);
  4038.                     $('body').trigger('woodmart-quick-view-displayed');
  4039.                     woodmartThemeModule.swatchesVariations();
  4040.                     woodmartThemeModule.btnsToolTips();
  4041.  
  4042.                 },
  4043.                 complete: function () {
  4044.                     setTimeout(function () {
  4045.                         $this.removeClass(loadingClass);
  4046.                         $product.removeClass('loading-quick-shop');
  4047.                         $product.addClass('quick-shop-shown quick-shop-loaded');
  4048.                     }, 100);
  4049.                 },
  4050.                 error: function () {
  4051.                 },
  4052.             });
  4053.  
  4054.         })
  4055.  
  4056.             .on('click', '.quick-shop-close', function () {
  4057.                 var $this = $(this),
  4058.                     $product = $this.parents('.product');
  4059.  
  4060.                 $product.removeClass('quick-shop-shown');
  4061.             });
  4062.  
  4063.         $(document.body).on('added_to_cart', function () {
  4064.             $('.product').removeClass('quick-shop-shown');
  4065.         });
  4066.  
  4067.         function initVariationForm($product) {
  4068.             $product.find('.variations_form').wc_variation_form().find('.variations select:eq(0)').change();
  4069.             $product.find('.variations_form').trigger('wc_variation_form');
  4070.         }
  4071.     };
  4072.  
  4073.     /**
  4074.      *-------------------------------------------------------------------------------------------------------------------------------------------
  4075.      * Quick View
  4076.      *-------------------------------------------------------------------------------------------------------------------------------------------
  4077.      */
  4078.  
  4079.     woodmartThemeModule.quickViewInit = function () {
  4080.         // Open popup with product info when click on Quick View button
  4081.         $(document).on('click', '.open-quick-view', function (e) {
  4082.  
  4083.             e.preventDefault();
  4084.  
  4085.             if ($('.open-quick-view').hasClass('loading')) {
  4086.                 return true;
  4087.             }
  4088.  
  4089.             var productId = $(this).data('id'),
  4090.                 loopName = $(this).data('loop-name'),
  4091.                 closeText = woodmart_settings.close,
  4092.                 loadingText = woodmart_settings.loading,
  4093.                 loop = $(this).data('loop'),
  4094.                 prev = '',
  4095.                 next = '',
  4096.                 loopBtns = $('.quick-view').find('[data-loop-name="' + loopName + '"]'),
  4097.                 btn = $(this);
  4098.  
  4099.             btn.addClass('loading');
  4100.  
  4101.             if (typeof loopBtns[loop - 1] != 'undefined') {
  4102.                 prev = loopBtns.eq(loop - 1).addClass('quick-view-prev');
  4103.                 prev = $('<div>').append(prev.clone()).html();
  4104.             }
  4105.  
  4106.             if (typeof loopBtns[loop + 1] != 'undefined') {
  4107.                 next = loopBtns.eq(loop + 1).addClass('quick-view-next');
  4108.                 next = $('<div>').append(next.clone()).html();
  4109.             }
  4110.  
  4111.             woodmartThemeModule.quickViewLoad(productId, btn, prev, next);
  4112.  
  4113.         });
  4114.     };
  4115.  
  4116.     woodmartThemeModule.quickViewCarousel = function () {
  4117.         $('.product-quick-view .woocommerce-product-gallery__wrapper').trigger('destroy.owl.carousel');
  4118.         $('.product-quick-view .woocommerce-product-gallery__wrapper').addClass('owl-carousel').owlCarousel({
  4119.             rtl: $('body').hasClass('rtl'),
  4120.             items: 1,
  4121.             dots: false,
  4122.             nav: true,
  4123.             navText: false
  4124.         });
  4125.     };
  4126.  
  4127.     woodmartThemeModule.quickViewLoad = function (id, btn, prev, next) {
  4128.         var data = {
  4129.             id: id,
  4130.             action: "woodmart_quick_view",
  4131.         };
  4132.  
  4133.         var initPopup = function (data) {
  4134.             $.magnificPopup.open({
  4135.                 items: {
  4136.                     src: '<div class="mfp-with-anim popup-quick-view">' + data + '</div>', // can be a HTML string, jQuery object, or CSS selector
  4137.                     type: 'inline'
  4138.                 },
  4139.                 tClose: woodmart_settings.close,
  4140.                 tLoading: woodmart_settings.loading,
  4141.                 removalDelay: 500, //delay removal by X to allow out-animation
  4142.                 callbacks: {
  4143.                     beforeOpen: function () {
  4144.                         this.st.mainClass = woodmartTheme.popupEffect + ' quick-view-wrapper';
  4145.                     },
  4146.                     open: function () {
  4147.                         $('.variations_form').each(function () {
  4148.                             $(this).wc_variation_form().find('.variations select:eq(0)').change();
  4149.                         });
  4150.                         $('.variations_form').trigger('wc_variation_form');
  4151.                         $('body').trigger('woodmart-quick-view-displayed');
  4152.                         woodmartThemeModule.swatchesVariations();
  4153.  
  4154.                         woodmartThemeModule.btnsToolTips();
  4155.                         setTimeout(function () {
  4156.                             woodmartThemeModule.nanoScroller();
  4157.                         }, 300);
  4158.                         woodmartThemeModule.quickViewCarousel();
  4159.                     }
  4160.                 },
  4161.             });
  4162.         }
  4163.  
  4164.         $.ajax({
  4165.             url: woodmart_settings.ajaxurl,
  4166.             data: data,
  4167.             method: 'get',
  4168.             success: function (data) {
  4169.                 if (woodmart_settings.quickview_in_popup_fix) {
  4170.                     $.magnificPopup.close();
  4171.                     setTimeout(function () {
  4172.                         initPopup(data);
  4173.                     }, 500);
  4174.                 } else {
  4175.                     initPopup(data);
  4176.                 }
  4177.             },
  4178.             complete: function () {
  4179.                 btn.removeClass('loading');
  4180.             },
  4181.             error: function () {
  4182.             },
  4183.         });
  4184.     };
  4185.  
  4186.     /**
  4187.      *-------------------------------------------------------------------------------------------------------------------------------------------
  4188.      * Swatches variations
  4189.      *-------------------------------------------------------------------------------------------------------------------------------------------
  4190.      */
  4191.  
  4192.     woodmartThemeModule.swatchesVariations = function () {
  4193.         var $variation_forms = $('.variations_form');
  4194.         var variationGalleryReplace = false;
  4195.  
  4196.         // Firefox mobile fix
  4197.         $('.variations_form .label').on('click', function (e) {
  4198.             if ($(this).siblings('.value').hasClass('with-swatches')) {
  4199.                 e.preventDefault();
  4200.             }
  4201.         });
  4202.  
  4203.         $variation_forms.each(function () {
  4204.             var $variation_form = $(this);
  4205.  
  4206.             if ($variation_form.data('swatches')) return;
  4207.             $variation_form.data('swatches', true);
  4208.  
  4209.             // If AJX
  4210.             if (!$variation_form.data('product_variations')) {
  4211.                 $variation_form.find('.swatches-select').find('> div').addClass('swatch-enabled');
  4212.             }
  4213.  
  4214.             if ($('.swatches-select > div').hasClass('active-swatch')) {
  4215.                 $variation_form.addClass('variation-swatch-selected');
  4216.             }
  4217.  
  4218.             $variation_form.on('click', '.swatches-select > div', function () {
  4219.                 var value = $(this).data('value');
  4220.                 var id = $(this).parent().data('id');
  4221.  
  4222.                 $variation_form.trigger('check_variations', ['attribute_' + id, true]);
  4223.                 resetSwatches($variation_form);
  4224.  
  4225.                 //$variation_form.find('select#' + id).val('').trigger('change');
  4226.                 //$variation_form.trigger('check_variations');
  4227.  
  4228.                 if ($(this).hasClass('active-swatch')) {
  4229.                     // Removed since 2.9 version as not necessary
  4230.                     // $variation_form.find( '.variations select' ).val( '' ).change();
  4231.                     // $variation_form.trigger( 'reset_data' );
  4232.                     // $(this).removeClass('active-swatch')
  4233.                     return;
  4234.                 }
  4235.  
  4236.                 if ($(this).hasClass('swatch-disabled')) return;
  4237.                 $variation_form.find('select#' + id).val(value).trigger('change');
  4238.                 $(this).parent().find('.active-swatch').removeClass('active-swatch');
  4239.                 $(this).addClass('active-swatch');
  4240.                 resetSwatches($variation_form);
  4241.             })
  4242.  
  4243.  
  4244.                 // On clicking the reset variation button
  4245.                 .on('click', '.reset_variations', function (event) {
  4246.                     $variation_form.find('.active-swatch').removeClass('active-swatch');
  4247.                 })
  4248.  
  4249.                 .on('reset_data', function () {
  4250.                     var all_attributes_chosen = true;
  4251.                     var some_attributes_chosen = false;
  4252.  
  4253.                     $variation_form.find('.variations select').each(function () {
  4254.                         var attribute_name = $(this).data('attribute_name') || $(this).attr('name');
  4255.                         var value = $(this).val() || '';
  4256.  
  4257.                         if (value.length === 0) {
  4258.                             all_attributes_chosen = false;
  4259.                         } else {
  4260.                             some_attributes_chosen = true;
  4261.                         }
  4262.  
  4263.                     });
  4264.  
  4265.                     if (all_attributes_chosen) {
  4266.                         $(this).parent().find('.active-swatch').removeClass('active-swatch');
  4267.                     }
  4268.  
  4269.                     $variation_form.removeClass('variation-swatch-selected');
  4270.  
  4271.                     var $mainOwl = $('.woocommerce-product-gallery__wrapper.owl-carousel');
  4272.  
  4273.                     resetSwatches($variation_form);
  4274.  
  4275.                     if (!$mainOwl.hasClass('owl-carousel')) return;
  4276.  
  4277.                     if (woodmart_settings.product_slider_auto_height == 'yes') {
  4278.                         if (!isQuickView() && isVariationGallery('default') && variationGalleryReplace) {
  4279.                             $mainOwl.trigger('destroy.owl.carousel');
  4280.                         }
  4281.                         $('.product-images').imagesLoaded(function () {
  4282.                             $mainOwl = $mainOwl.owlCarousel(woodmartTheme.mainCarouselArg);
  4283.                             $mainOwl.trigger('refresh.owl.carousel');
  4284.                         });
  4285.                     } else {
  4286.                         $mainOwl = $mainOwl.owlCarousel(woodmartTheme.mainCarouselArg);
  4287.                         $mainOwl.trigger('refresh.owl.carousel');
  4288.                     }
  4289.  
  4290.                     var slide_go_to = woodmart_settings.product_gallery.thumbs_slider.position == 'centered' ? woodmart_settings.centered_gallery_start : 0;
  4291.                     if (isQuickView()) slide_go_to = 0;
  4292.                     $mainOwl.trigger('to.owl.carousel', slide_go_to);
  4293.  
  4294.                     replaceMainGallery('default', $variation_form);
  4295.                 })
  4296.  
  4297.  
  4298.                 // Update first tumbnail
  4299.                 .on('reset_image', function () {
  4300.                     var $thumb = $('.thumbnails .product-image-thumbnail img').first();
  4301.                     if (!isQuickView() && !isQuickShop($variation_form)) {
  4302.                         $thumb.wc_reset_variation_attr('src');
  4303.                     }
  4304.                 })
  4305.                 .on('show_variation', function (e, variation, purchasable) {
  4306.  
  4307.                     if (!variation.image.src) {
  4308.                         return;
  4309.                     }
  4310.  
  4311.                     // See if the gallery has an image with the same original src as the image we want to switch to.
  4312.                     var galleryHasImage = $variation_form.parents('.single-product-content').find('.thumbnails .product-image-thumbnail img[data-o_src="' + variation.image.thumb_src + '"]').length > 0;
  4313.                     var $firstThumb = $variation_form.parents('.single-product-content').find('.thumbnails .product-image-thumbnail img').first();
  4314.  
  4315.                     // If the gallery has the image, reset the images. We'll scroll to the correct one.
  4316.                     if (galleryHasImage) {
  4317.                         $firstThumb.wc_reset_variation_attr('src');
  4318.                     }
  4319.  
  4320.                     if (!isQuickShop($variation_form) && !replaceMainGallery(variation.variation_id, $variation_form)) {
  4321.                         if ($firstThumb.attr('src') != variation.image.thumb_src) {
  4322.                             $firstThumb.wc_set_variation_attr('src', variation.image.src);
  4323.                         }
  4324.                         woodmartThemeModule.initZoom();
  4325.                     }
  4326.  
  4327.                     $variation_form.addClass('variation-swatch-selected');
  4328.  
  4329.                     if (!isQuickShop($variation_form) && !isQuickView()) {
  4330.                         scrollToTop();
  4331.                     }
  4332.  
  4333.                     var $mainOwl = $('.woocommerce-product-gallery__wrapper.owl-carousel');
  4334.  
  4335.                     if (!$mainOwl.hasClass('owl-carousel')) return;
  4336.  
  4337.                     if (woodmart_settings.product_slider_auto_height == 'yes') {
  4338.                         if (!isQuickView() && isVariationGallery(variation.variation_id) && variationGalleryReplace) {
  4339.                             $mainOwl.trigger('destroy.owl.carousel');
  4340.                         }
  4341.                         $('.product-images').imagesLoaded(function () {
  4342.                             $mainOwl = $mainOwl.owlCarousel(woodmartTheme.mainCarouselArg);
  4343.                             $mainOwl.trigger('refresh.owl.carousel');
  4344.                         });
  4345.                     } else {
  4346.                         $mainOwl = $mainOwl.owlCarousel(woodmartTheme.mainCarouselArg);
  4347.                         $mainOwl.trigger('refresh.owl.carousel');
  4348.                     }
  4349.  
  4350.                     var $thumbs = $('.images .thumbnails');
  4351.  
  4352.                     $mainOwl.trigger('to.owl.carousel', 0);
  4353.  
  4354.                     if ($thumbs.hasClass('owl-carousel')) {
  4355.                         $thumbs.owlCarousel().trigger('to.owl.carousel', 0);
  4356.                         $thumbs.find('.active-thumb').removeClass('active-thumb');
  4357.                         $thumbs.find('.product-image-thumbnail').eq(0).addClass('active-thumb');
  4358.                     } else if ($thumbs.hasClass('slick-slider')) {
  4359.                         $thumbs.slick('slickGoTo', 0);
  4360.                         if (!$thumbs.find('.product-image-thumbnail').eq(0).hasClass('active-thumb')) {
  4361.                             $thumbs.find('.active-thumb').removeClass('active-thumb');
  4362.                             $thumbs.find('.product-image-thumbnail').eq(0).addClass('active-thumb');
  4363.                         }
  4364.                     }
  4365.  
  4366.                 });
  4367.         })
  4368.  
  4369.         var resetSwatches = function ($variation_form) {
  4370.  
  4371.             // If using AJAX
  4372.             if (!$variation_form.data('product_variations')) return;
  4373.  
  4374.             $variation_form.find('.variations select').each(function () {
  4375.  
  4376.                 var select = $(this);
  4377.                 var swatch = select.parent().find('.swatches-select');
  4378.                 var options = select.html();
  4379.                 // var options = select.data('attribute_html');
  4380.                 options = $(options);
  4381.  
  4382.                 swatch.find('> div').removeClass('swatch-enabled').addClass('swatch-disabled');
  4383.  
  4384.                 options.each(function (el) {
  4385.                     var value = $(this).val();
  4386.  
  4387.                     if ($(this).hasClass('enabled')) {
  4388.                         // if( ! el.disabled ) {
  4389.                         swatch.find('div[data-value="' + value + '"]').removeClass('swatch-disabled').addClass('swatch-enabled');
  4390.                     } else {
  4391.                         swatch.find('div[data-value="' + value + '"]').addClass('swatch-disabled').removeClass('swatch-enabled');
  4392.                     }
  4393.  
  4394.                 });
  4395.  
  4396.             });
  4397.         };
  4398.  
  4399.         var isQuickView = function () {
  4400.             return $('.single-product-content').hasClass('product-quick-view');
  4401.         };
  4402.  
  4403.         var isQuickShop = function ($form) {
  4404.             return $form.parent().hasClass('quick-shop-form');
  4405.         };
  4406.  
  4407.         var isVariationGallery = function (key) {
  4408.             if (typeof woodmart_variation_gallery_data === 'undefined' && typeof woodmart_qv_variation_gallery_data === 'undefined' ) {
  4409.                 return;
  4410.             }
  4411.  
  4412.             var variation_gallery_data = isQuickView() ? woodmart_qv_variation_gallery_data : woodmart_variation_gallery_data;
  4413.  
  4414.             return typeof variation_gallery_data !== 'undefined' && variation_gallery_data && variation_gallery_data[key];
  4415.         };
  4416.  
  4417.         var scrollToTop = function () {
  4418.             if ((woodmart_settings.swatches_scroll_top_desktop == 1 && $(window).width() >= 1024) || (woodmart_settings.swatches_scroll_top_mobile == 1 && $(window).width() <= 1024)) {
  4419.                 var $page = $('html, body');
  4420.  
  4421.                 $page.stop(true);
  4422.                 $(window).on('mousedown wheel DOMMouseScroll mousewheel keyup touchmove', function () {
  4423.                     $page.stop(true);
  4424.                 });
  4425.                 $page.animate({
  4426.                     scrollTop: $('.product-image-summary').offset().top - 150
  4427.                 }, 800);
  4428.                 $('.woodmart-swatch').tooltip('hide');
  4429.             }
  4430.         }
  4431.  
  4432.         var replaceMainGallery = function (key, $variationForm) {
  4433.             if (!isVariationGallery(key) || isQuickShop($variationForm) || ('default' === key && !variationGalleryReplace)) {
  4434.                 return false;
  4435.             }
  4436.  
  4437.             var variation_gallery_data = isQuickView() ? woodmart_qv_variation_gallery_data : woodmart_variation_gallery_data;
  4438.  
  4439.             var imagesData = variation_gallery_data[key];
  4440.             var $mainGallery = $variationForm.parents('.single-product-content').find('.woocommerce-product-gallery__wrapper');
  4441.  
  4442.             $mainGallery.empty();
  4443.  
  4444.             for (var index = 0; index < imagesData.length; index++) {
  4445.                 var $html = '<div class="product-image-wrap"><figure data-thumb="' + imagesData[index].data_thumb + '" class="woocommerce-product-gallery__image">';
  4446.  
  4447.                 if (!isQuickView()) {
  4448.                     $html += '<a href="' + imagesData[index].href + '">';
  4449.                 }
  4450.  
  4451.                 $html += imagesData[index].image;
  4452.  
  4453.                 if (!isQuickView()) {
  4454.                     $html += '</a>';
  4455.                 }
  4456.  
  4457.                 $html += '</figure></div>';
  4458.  
  4459.                 $mainGallery.append($html);
  4460.             }
  4461.  
  4462.             woodmartThemeModule.productImagesGallery();
  4463.             woodmartThemeModule.quickViewCarousel();
  4464.             $('.woocommerce-product-gallery__image').trigger('zoom.destroy');
  4465.             if (!isQuickView()) {
  4466.                 woodmartThemeModule.initZoom();
  4467.             }
  4468.  
  4469.             if ('default' === key) {
  4470.                 variationGalleryReplace = false;
  4471.             } else {
  4472.                 variationGalleryReplace = true;
  4473.             }
  4474.  
  4475.             return true;
  4476.         }
  4477.     };
  4478.  
  4479.     woodmartThemeModule.swatchesOnGrid = function () {
  4480.         $('body').on('click', '.swatch-on-grid', function () {
  4481.  
  4482.             var src, srcset, image_sizes;
  4483.  
  4484.             var imageSrc = $(this).data('image-src'),
  4485.                 imageSrcset = $(this).data('image-srcset'),
  4486.                 imageSizes = $(this).data('image-sizes');
  4487.  
  4488.             if (typeof imageSrc == 'undefined' || '' === imageSrc) {
  4489.                 return;
  4490.             }
  4491.  
  4492.             var product = $(this).parents('.product-grid-item'),
  4493.                 image = product.find('.product-image-link > img'),
  4494.                 srcOrig = image.data('original-src'),
  4495.                 srcsetOrig = image.data('original-srcset'),
  4496.                 sizesOrig = image.data('original-sizes');
  4497.  
  4498.             if (typeof srcOrig == 'undefined') {
  4499.                 image.data('original-src', image.attr('src'));
  4500.             }
  4501.  
  4502.             if (typeof srcsetOrig == 'undefined') {
  4503.                 image.data('original-srcset', image.attr('srcset'));
  4504.             }
  4505.  
  4506.             if (typeof sizesOrig == 'undefined') {
  4507.                 image.data('original-sizes', image.attr('sizes'));
  4508.             }
  4509.  
  4510.  
  4511.             if ($(this).hasClass('current-swatch')) {
  4512.                 src = srcOrig;
  4513.                 srcset = srcsetOrig;
  4514.                 image_sizes = sizesOrig;
  4515.                 $(this).removeClass('current-swatch');
  4516.                 product.removeClass('product-swatched');
  4517.             } else {
  4518.                 $(this).parent().find('.current-swatch').removeClass('current-swatch');
  4519.                 $(this).addClass('current-swatch');
  4520.                 product.addClass('product-swatched');
  4521.                 src = imageSrc;
  4522.                 srcset = imageSrcset;
  4523.                 image_sizes = imageSizes;
  4524.             }
  4525.  
  4526.             if (image.attr('src') == src) return;
  4527.  
  4528.             product.addClass('loading-image');
  4529.  
  4530.             image.attr('src', src).attr('srcset', srcset).attr('image_sizes', image_sizes).one('load', function () {
  4531.                 product.removeClass('loading-image');
  4532.             });
  4533.  
  4534.         });
  4535.     };
  4536.  
  4537.     /**
  4538.      *-------------------------------------------------------------------------------------------------------------------------------------------
  4539.      * Products tabs element AJAX loading
  4540.      *-------------------------------------------------------------------------------------------------------------------------------------------
  4541.      */
  4542.  
  4543.     woodmartThemeModule.productsTabs = function () {
  4544.         var process = false;
  4545.  
  4546.         $('.woodmart-products-tabs').each(function () {
  4547.             var $this = $(this),
  4548.                 $inner = $this.find('.woodmart-tab-content'),
  4549.                 cache = [];
  4550.  
  4551.             if ($inner.find('.owl-carousel').length < 1) {
  4552.                 cache[0] = {
  4553.                     html: $inner.html()
  4554.                 };
  4555.             }
  4556.  
  4557.             $this.find('.products-tabs-title li').on('click', function (e) {
  4558.                 e.preventDefault();
  4559.  
  4560.                 var $this = $(this),
  4561.                     atts = $this.data('atts'),
  4562.                     index = $this.index();
  4563.  
  4564.                 if (process || $this.hasClass('active-tab-title')) return; process = true;
  4565.  
  4566.                 loadTab(atts, index, $inner, $this, cache, function (data) {
  4567.                     if (data.html) {
  4568.                         $inner.html(data.html);
  4569.  
  4570.                         $(document).trigger('wood-images-loaded');
  4571.  
  4572.                         woodmartThemeModule.productHover();
  4573.                         woodmartThemeModule.btnsToolTips();
  4574.                         woodmartThemeModule.shopMasonry();
  4575.                         woodmartThemeModule.countDownTimer();
  4576.                         woodmartThemeModule.productLoaderPosition();
  4577.                         woodmartThemeModule.productsLoadMore();
  4578.                     }
  4579.                 });
  4580.  
  4581.             });
  4582.  
  4583.             var $nav = $this.find('.tabs-navigation-wrapper'),
  4584.                 $subList = $nav.find('ul'),
  4585.                 time = 300;
  4586.  
  4587.             $nav.on('click', '.open-title-menu', function () {
  4588.                 var $btn = $(this);
  4589.  
  4590.                 if ($subList.hasClass('list-shown')) {
  4591.                     $btn.removeClass('toggle-active');
  4592.                     $subList.stop().slideUp(time).removeClass('list-shown');
  4593.                 } else {
  4594.                     $btn.addClass('toggle-active');
  4595.                     $subList.addClass('list-shown');
  4596.                     setTimeout(function () {
  4597.                         $('body').one('click', function (e) {
  4598.                             var target = e.target;
  4599.                             if (!$(target).is('.tabs-navigation-wrapper') && !$(target).parents().is('.tabs-navigation-wrapper')) {
  4600.                                 $btn.removeClass('toggle-active');
  4601.                                 $subList.removeClass('list-shown');
  4602.                                 return false;
  4603.                             }
  4604.                         });
  4605.                     }, 10);
  4606.                 }
  4607.  
  4608.             })
  4609.                 .on('click', 'li', function () {
  4610.                     var $btn = $nav.find('.open-title-menu'),
  4611.                         text = $(this).text();
  4612.  
  4613.                     if ($subList.hasClass('list-shown')) {
  4614.                         $btn.removeClass('toggle-active').text(text);
  4615.                         $subList.removeClass('list-shown');
  4616.                     }
  4617.                 });
  4618.  
  4619.         });
  4620.  
  4621.         var loadTab = function (atts, index, holder, btn, cache, callback) {
  4622.  
  4623.             btn.parent().find('.active-tab-title').removeClass('active-tab-title');
  4624.             btn.addClass('active-tab-title')
  4625.  
  4626.             if (cache[index]) {
  4627.                 holder.addClass('loading');
  4628.                 setTimeout(function () {
  4629.                     callback(cache[index]);
  4630.                     holder.removeClass('loading');
  4631.                     process = false;
  4632.                 }, 300);
  4633.                 return;
  4634.             }
  4635.  
  4636.             holder.addClass('loading').parent().addClass('element-loading');
  4637.  
  4638.             btn.addClass('loading');
  4639.  
  4640.             $.ajax({
  4641.                 url: woodmart_settings.ajaxurl,
  4642.                 data: {
  4643.                     atts: atts,
  4644.                     action: 'woodmart_get_products_tab_shortcode',
  4645.                 },
  4646.                 dataType: 'json',
  4647.                 method: 'POST',
  4648.                 success: function (data) {
  4649.                     cache[index] = data;
  4650.                     callback(data);
  4651.                 },
  4652.                 error: function (data) {
  4653.                     console.log('ajax error');
  4654.                 },
  4655.                 complete: function () {
  4656.                     holder.removeClass('loading').parent().removeClass('element-loading');
  4657.                     btn.removeClass('loading');
  4658.                     process = false;
  4659.                     woodmartThemeModule.compare();
  4660.                 },
  4661.             });
  4662.         };
  4663.     };
  4664.  
  4665.     /**
  4666.      *-------------------------------------------------------------------------------------------------------------------------------------------
  4667.      * Load more button for products shortcode
  4668.      *-------------------------------------------------------------------------------------------------------------------------------------------
  4669.      */
  4670.  
  4671.     woodmartThemeModule.productsLoadMore = function () {
  4672.         var process = false,
  4673.             intervalID;
  4674.  
  4675.         $('.woodmart-products-element').each(function () {
  4676.             var $this = $(this),
  4677.                 cache = [],
  4678.                 inner = $this.find('.woodmart-products-holder');
  4679.  
  4680.             if (!inner.hasClass('pagination-arrows')) return;
  4681.  
  4682.             cache[1] = {
  4683.                 items: inner.html(),
  4684.                 status: 'have-posts'
  4685.             };
  4686.  
  4687.             $this.on('recalc', function () {
  4688.                 calc();
  4689.             });
  4690.  
  4691.             $(window).resize(function () {
  4692.                 calc();
  4693.             });
  4694.  
  4695.             var calc = function () {
  4696.                 var height = inner.outerHeight();
  4697.                 $this.stop().css({ minHeight: height });
  4698.             };
  4699.  
  4700.  
  4701.             // sticky buttons
  4702.  
  4703.             var body = $('body'),
  4704.                 btnWrap = $this.find('.products-footer'),
  4705.                 btnLeft = btnWrap.find('.woodmart-products-load-prev'),
  4706.                 btnRight = btnWrap.find('.woodmart-products-load-next'),
  4707.                 loadWrapp = $this.find('.woodmart-products-loader'),
  4708.                 scrollTop,
  4709.                 holderTop,
  4710.                 btnLeftOffset,
  4711.                 btnRightOffset,
  4712.                 holderBottom,
  4713.                 holderHeight,
  4714.                 holderWidth,
  4715.                 btnsHeight,
  4716.                 offsetArrow = 50,
  4717.                 offset,
  4718.                 windowWidth;
  4719.  
  4720.             if (body.hasClass('rtl')) {
  4721.                 btnLeft = btnRight;
  4722.                 btnRight = btnWrap.find('.woodmart-products-load-prev');
  4723.             }
  4724.  
  4725.             $(window).scroll(function () {
  4726.                 buttonsPos();
  4727.             });
  4728.  
  4729.             setTimeout(function () {
  4730.                 buttonsPos();
  4731.             }, 500);
  4732.  
  4733.             function buttonsPos() {
  4734.  
  4735.                 offset = $(window).height() / 2;
  4736.  
  4737.                 windowWidth = $(window).outerWidth(true);
  4738.  
  4739.                 holderWidth = $this.outerWidth(true);
  4740.  
  4741.                 scrollTop = $(window).scrollTop();
  4742.  
  4743.                 holderTop = $this.offset().top - offset;
  4744.  
  4745.                 btnLeftOffset = $this.offset().left - offsetArrow;
  4746.  
  4747.                 btnRightOffset = holderWidth + $this.offset().left + offsetArrow - btnRight.outerWidth();
  4748.  
  4749.                 btnsHeight = btnLeft.outerHeight();
  4750.  
  4751.                 holderHeight = $this.height() - btnsHeight;
  4752.  
  4753.                 holderBottom = holderTop + holderHeight;
  4754.  
  4755.                 if ($(window).width() <= 1024) {
  4756.                     btnLeftOffset = btnLeftOffset + 35;
  4757.                     btnRightOffset = btnRightOffset - 35;
  4758.                 }
  4759.  
  4760.                 btnLeft.css({
  4761.                     'left': btnLeftOffset + 'px'
  4762.                 });
  4763.  
  4764.                 btnRight.css({
  4765.                     'left': btnRightOffset + 'px'
  4766.                 });
  4767.  
  4768.                 if (scrollTop < holderTop || scrollTop > holderBottom) {
  4769.                     btnWrap.removeClass('show-arrow');
  4770.                     loadWrapp.addClass('hidden-loader');
  4771.                 } else {
  4772.                     btnWrap.addClass('show-arrow');
  4773.                     loadWrapp.removeClass('hidden-loader');
  4774.                 }
  4775.  
  4776.             };
  4777.  
  4778.             $this.find('.woodmart-products-load-prev, .woodmart-products-load-next').off('click').on('click', function (e) {
  4779.  
  4780.                 e.preventDefault();
  4781.  
  4782.                 if (process || $(this).hasClass('disabled')) return; process = true;
  4783.  
  4784.                 clearInterval(intervalID);
  4785.  
  4786.                 var $this = $(this),
  4787.                     holder = $this.parent().parent().prev(),
  4788.                     next = $this.parent().find('.woodmart-products-load-next'),
  4789.                     prev = $this.parent().find('.woodmart-products-load-prev'),
  4790.                     atts = holder.data('atts'),
  4791.                     action = 'woodmart_get_products_shortcode',
  4792.                     ajaxurl = woodmart_settings.ajaxurl,
  4793.                     dataType = 'json',
  4794.                     method = 'POST',
  4795.                     paged = holder.attr('data-paged');
  4796.  
  4797.                 paged++;
  4798.  
  4799.                 if ($this.hasClass('woodmart-products-load-prev')) {
  4800.                     if (paged < 2) return;
  4801.                     paged = paged - 2;
  4802.                 }
  4803.  
  4804.                 loadProducts('arrows', atts, ajaxurl, action, dataType, method, paged, holder, $this, cache, function (data) {
  4805.                     var isBorderedGrid = holder.hasClass('products-bordered-grid');
  4806.  
  4807.                     if (!isBorderedGrid) {
  4808.                         holder.addClass('woodmart-animated-products');
  4809.                     }
  4810.  
  4811.                     if (data.items) {
  4812.                         holder.html(data.items).attr('data-paged', paged);
  4813.                         holder.imagesLoaded().progress(function () {
  4814.                             holder.parent().trigger('recalc');
  4815.                         });
  4816.  
  4817.                         $(document).trigger('wood-images-loaded');
  4818.  
  4819.                         woodmartThemeModule.productHover();
  4820.                         woodmartThemeModule.btnsToolTips();
  4821.                     }
  4822.  
  4823.                     if ($(window).width() < 768) {
  4824.                         $('html, body').stop().animate({
  4825.                             scrollTop: holder.offset().top - 150
  4826.                         }, 400);
  4827.                     }
  4828.  
  4829.                     if (!isBorderedGrid) {
  4830.                         var iter = 0;
  4831.                         intervalID = setInterval(function () {
  4832.                             holder.find('.product-grid-item').eq(iter).addClass('woodmart-animated');
  4833.                             iter++;
  4834.                         }, 100);
  4835.                     }
  4836.  
  4837.                     if (paged > 1) {
  4838.                         prev.removeClass('disabled');
  4839.                     } else {
  4840.                         prev.addClass('disabled');
  4841.                     }
  4842.  
  4843.                     if (data.status == 'no-more-posts') {
  4844.                         next.addClass('disabled');
  4845.                     } else {
  4846.                         next.removeClass('disabled');
  4847.                     }
  4848.                 });
  4849.  
  4850.             });
  4851.         });
  4852.  
  4853.  
  4854.         woodmartThemeModule.clickOnScrollButton(woodmartTheme.shopLoadMoreBtn, false, woodmart_settings.infinit_scroll_offset);
  4855.  
  4856.         $(document).off('click', '.woodmart-products-load-more').on('click', '.woodmart-products-load-more', function (e) {
  4857.             e.preventDefault();
  4858.  
  4859.             if (process) return; process = true;
  4860.  
  4861.             var $this = $(this),
  4862.                 holder = $this.parent().siblings('.woodmart-products-holder'),
  4863.                 source = holder.data('source'),
  4864.                 action = 'woodmart_get_products_' + source,
  4865.                 ajaxurl = woodmart_settings.ajaxurl,
  4866.                 dataType = 'json',
  4867.                 method = 'POST',
  4868.                 atts = holder.data('atts'),
  4869.                 paged = holder.data('paged');
  4870.  
  4871.             paged++;
  4872.  
  4873.             if (source == 'main_loop') {
  4874.                 ajaxurl = $(this).attr('href');
  4875.                 method = 'GET';
  4876.             }
  4877.  
  4878.             loadProducts('load-more', atts, ajaxurl, action, dataType, method, paged, holder, $this, [], function (data) {
  4879.                 if (data.items) {
  4880.                     if (holder.hasClass('grid-masonry')) {
  4881.                         isotopeAppend(holder, data.items);
  4882.                     } else {
  4883.                         holder.append(data.items);
  4884.                     }
  4885.  
  4886.                     holder.imagesLoaded().progress(function () {
  4887.                         woodmartThemeModule.clickOnScrollButton(woodmartTheme.shopLoadMoreBtn, true, woodmart_settings.infinit_scroll_offset);
  4888.                     });
  4889.  
  4890.                     $(document).trigger('wood-images-loaded');
  4891.  
  4892.                     holder.data('paged', paged);
  4893.  
  4894.                     woodmartThemeModule.productHover();
  4895.                     woodmartThemeModule.btnsToolTips();
  4896.                 }
  4897.  
  4898.                 if (source == 'main_loop') {
  4899.                     $this.attr('href', data.nextPage);
  4900.                     if (data.status == 'no-more-posts') {
  4901.                         $this.hide().remove();
  4902.                     }
  4903.                 }
  4904.  
  4905.                 if (data.status == 'no-more-posts') {
  4906.                     $this.hide();
  4907.                 }
  4908.             });
  4909.  
  4910.         });
  4911.  
  4912.         var loadProducts = function (btnType, atts, ajaxurl, action, dataType, method, paged, holder, btn, cache, callback) {
  4913.             var data = {
  4914.                 atts: atts,
  4915.                 paged: paged,
  4916.                 action: action,
  4917.                 woo_ajax: 1,
  4918.             };
  4919.  
  4920.             if (cache[paged]) {
  4921.                 holder.addClass('loading');
  4922.                 setTimeout(function () {
  4923.                     callback(cache[paged]);
  4924.                     holder.removeClass('loading');
  4925.                     process = false;
  4926.                 }, 300);
  4927.                 return;
  4928.             }
  4929.  
  4930.             if (btnType == 'arrows') holder.addClass('loading').parent().addClass('element-loading');
  4931.  
  4932.             btn.addClass('loading');
  4933.  
  4934.             if (action == 'woodmart_get_products_main_loop') {
  4935.                 var loop = holder.find('.product').last().data('loop');
  4936.                 data = {
  4937.                     loop: loop,
  4938.                     woo_ajax: 1
  4939.                 };
  4940.             }
  4941.  
  4942.             $.ajax({
  4943.                 url: ajaxurl,
  4944.                 data: data,
  4945.                 dataType: dataType,
  4946.                 method: method,
  4947.                 success: function (data) {
  4948.                     cache[paged] = data;
  4949.                     callback(data);
  4950.                 },
  4951.                 error: function (data) {
  4952.                     console.log('ajax error');
  4953.                 },
  4954.                 complete: function () {
  4955.                     if (btnType == 'arrows') holder.removeClass('loading').parent().removeClass('element-loading');
  4956.                     btn.removeClass('loading');
  4957.                     process = false;
  4958.                     woodmartThemeModule.compare();
  4959.                     woodmartThemeModule.productHover();
  4960.                     woodmartThemeModule.countDownTimer();
  4961.                 },
  4962.             });
  4963.         };
  4964.  
  4965.         var isotopeAppend = function (el, items) {
  4966.             // initialize Masonry after all images have loaded
  4967.             var items = $(items);
  4968.             el.append(items).isotope('appended', items);
  4969.             el.imagesLoaded().progress(function () {
  4970.                 el.isotope('layout');
  4971.             });
  4972.         };
  4973.     };
  4974.  
  4975.     /**
  4976.      *-------------------------------------------------------------------------------------------------------------------------------------------
  4977.      * Compare button
  4978.      *-------------------------------------------------------------------------------------------------------------------------------------------
  4979.      */
  4980.  
  4981.     woodmartThemeModule.compare = function () {
  4982.         var body = $("body"),
  4983.             button = $("a.compare");
  4984.  
  4985.         body.on("click", "a.compare", function () {
  4986.             $(this).addClass("loading");
  4987.         });
  4988.  
  4989.         body.on("yith_woocompare_open_popup", function () {
  4990.             button.removeClass("loading");
  4991.             body.addClass("compare-opened");
  4992.         });
  4993.  
  4994.         body.on('click', '#cboxClose, #cboxOverlay', function () {
  4995.             body.removeClass("compare-opened");
  4996.         });
  4997.     };
  4998.  
  4999.     /**
  5000.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5001.      * WoodMart compare functions
  5002.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5003.      */
  5004.  
  5005.     woodmartThemeModule.woodmartCompare = function () {
  5006.         var cookiesName = 'woodmart_compare_list';
  5007.  
  5008.         if (woodmart_settings.is_multisite) {
  5009.             cookiesName += '_' + woodmart_settings.current_blog_id;
  5010.         }
  5011.  
  5012.         var $body = $("body"),
  5013.             $widget = $('.woodmart-compare-info-widget'),
  5014.             compareCookie = Cookies.get(cookiesName);
  5015.  
  5016.         if ($widget.length > 0) {
  5017.             try {
  5018.                 var ids = JSON.parse(compareCookie);
  5019.                 $widget.find('.compare-count').text(ids.length);
  5020.             } catch (e) {
  5021.                 console.log('cant parse cookies json');
  5022.             }
  5023.         }
  5024.         // Add to compare action
  5025.  
  5026.         $body.on('click', '.woodmart-compare-btn a', function (e) {
  5027.             var $this = $(this),
  5028.                 id = $this.data('id'),
  5029.                 addedText = $this.data('added-text');
  5030.  
  5031.             if ($this.hasClass('added')) return true;
  5032.  
  5033.             e.preventDefault();
  5034.  
  5035.             $this.addClass('loading');
  5036.  
  5037.             jQuery.ajax({
  5038.                 url: woodmart_settings.ajaxurl,
  5039.                 data: {
  5040.                     action: 'woodmart_add_to_compare',
  5041.                     id: id,
  5042.                 },
  5043.                 dataType: 'json',
  5044.                 method: 'GET',
  5045.                 success: function (response) {
  5046.                     if (response.table) {
  5047.                         updateCompare(response);
  5048.                         $(document).trigger('added_to_compare');
  5049.                     } else {
  5050.                         console.log('something wrong loading compare data ', response);
  5051.                     }
  5052.                 },
  5053.                 error: function (data) {
  5054.                     console.log('We cant add to compare. Something wrong with AJAX response. Probably some PHP conflict.');
  5055.                 },
  5056.                 complete: function () {
  5057.                     $this.removeClass('loading').addClass('added');
  5058.  
  5059.                     if ($this.find('span').length > 0) {
  5060.                         $this.find('span').text(addedText);
  5061.                     } else {
  5062.                         $this.text(addedText);
  5063.                     }
  5064.                 },
  5065.             });
  5066.  
  5067.         });
  5068.  
  5069.         // Remove from compare action
  5070.  
  5071.         $body.on('click', '.woodmart-compare-remove', function (e) {
  5072.             var $table = $('.woodmart-compare-table');
  5073.  
  5074.             e.preventDefault();
  5075.             var $this = $(this),
  5076.                 id = $this.data('id');
  5077.  
  5078.             $table.addClass('loading');
  5079.             $this.addClass('loading');
  5080.  
  5081.             jQuery.ajax({
  5082.                 url: woodmart_settings.ajaxurl,
  5083.                 data: {
  5084.                     action: 'woodmart_remove_from_compare',
  5085.                     id: id,
  5086.                 },
  5087.                 dataType: 'json',
  5088.                 method: 'GET',
  5089.                 success: function (response) {
  5090.                     if (response.table) {
  5091.                         updateCompare(response);
  5092.                     } else {
  5093.                         console.log('something wrong loading compare data ', response);
  5094.                     }
  5095.                 },
  5096.                 error: function (data) {
  5097.                     console.log('We cant remove product compare. Something wrong with AJAX response. Probably some PHP conflict.');
  5098.                 },
  5099.                 complete: function () {
  5100.                     $table.removeClass('loading');
  5101.                     $this.addClass('loading');
  5102.                 },
  5103.             });
  5104.  
  5105.         });
  5106.  
  5107.         // Elements update after ajax
  5108.  
  5109.         function updateCompare(data) {
  5110.             if ($widget.length > 0) {
  5111.                 $widget.find('.compare-count').text(data.count);
  5112.             }
  5113.  
  5114.             if ($('.woodmart-compare-table').length > 0) {
  5115.                 $('.woodmart-compare-table').replaceWith(data.table);
  5116.             }
  5117.  
  5118.         }
  5119.  
  5120.     };
  5121.  
  5122.     /**
  5123.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5124.      * Add class in wishlist
  5125.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5126.      */
  5127.  
  5128.     woodmartThemeModule.wishList = function () {
  5129.         var body = $("body");
  5130.  
  5131.         body.on("click", ".add_to_wishlist", function () {
  5132.  
  5133.             $(this).parent().addClass("feid-in");
  5134.  
  5135.         });
  5136.     };
  5137.  
  5138.     /**
  5139.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5140.      * Product 360 button
  5141.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5142.      */
  5143.  
  5144.     woodmartThemeModule.product360Button = function () {
  5145.         $('.product-360-button a').magnificPopup({
  5146.             type: 'inline',
  5147.             mainClass: 'mfp-fade',
  5148.             // removalDelay: 500, //delay removal by X to allow out-animation
  5149.             // callbacks: {
  5150.             //     beforeOpen: function() {
  5151.             //         this.st.mainClass = woodmartTheme.popupEffect;
  5152.             //     }
  5153.             // },
  5154.             preloader: false,
  5155.             tClose: woodmart_settings.close,
  5156.             tLoading: woodmart_settings.loading,
  5157.             fixedContentPos: false,
  5158.             callbacks: {
  5159.                 open: function () {
  5160.                     $(window).resize()
  5161.                 },
  5162.             },
  5163.         });
  5164.     };
  5165.  
  5166.     /**
  5167.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5168.      * Product video button
  5169.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5170.      */
  5171.  
  5172.     woodmartThemeModule.productVideo = function () {
  5173.         $('.product-video-button a').magnificPopup({
  5174.             tClose: woodmart_settings.close,
  5175.             tLoading: woodmart_settings.loading,
  5176.             type: 'iframe',
  5177.             iframe: {
  5178.                 patterns: {
  5179.                     youtube: {
  5180.                         index: 'youtube.com/',
  5181.                         id: 'v=',
  5182.                         src: '//www.youtube.com/embed/%id%?rel=0&autoplay=1'
  5183.                     }
  5184.                 }
  5185.             },
  5186.             preloader: false,
  5187.             fixedContentPos: false
  5188.         });
  5189.     };
  5190.  
  5191.     /**
  5192.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5193.      * Login tabs for my account page
  5194.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5195.      */
  5196.  
  5197.     woodmartThemeModule.loginTabs = function () {
  5198.         var tabs = $('.woodmart-register-tabs'),
  5199.             btn = tabs.find('.woodmart-switch-to-register'),
  5200.             title = $('.col-register-text h2'),
  5201.             login = tabs.find('.col-login'),
  5202.             loginText = tabs.find('.login-info'),
  5203.             register = tabs.find('.col-register'),
  5204.             classOpened = 'active-register',
  5205.             loginLabel = btn.data('login'),
  5206.             registerLabel = btn.data('register'),
  5207.             loginTitleLabel = btn.data('login-title'),
  5208.             registerTitleLabel = btn.data('reg-title');
  5209.  
  5210.         btn.on('click', function (e) {
  5211.             e.preventDefault();
  5212.  
  5213.             if (isShown()) {
  5214.                 hideRegister();
  5215.             } else {
  5216.                 showRegister();
  5217.             }
  5218.  
  5219.             var scrollTo = $('.main-page-wrapper').offset().top - 100;
  5220.  
  5221.             if ($(window).width() < 768) {
  5222.                 $('html, body').stop().animate({
  5223.                     scrollTop: tabs.offset().top - 90
  5224.                 }, 400);
  5225.             }
  5226.         });
  5227.  
  5228.         var showRegister = function () {
  5229.             tabs.addClass(classOpened);
  5230.             btn.text(loginLabel);
  5231.             if (loginText.length > 0) {
  5232.                 title.text(loginTitleLabel);
  5233.             }
  5234.         };
  5235.  
  5236.         var hideRegister = function () {
  5237.             tabs.removeClass(classOpened);
  5238.             btn.text(registerLabel);
  5239.             if (loginText.length > 0) {
  5240.                 title.text(registerTitleLabel);
  5241.             }
  5242.         };
  5243.  
  5244.         var isShown = function () {
  5245.             return tabs.hasClass(classOpened);
  5246.         };
  5247.     };
  5248.  
  5249.     /**
  5250.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5251.      * Header Categories menu for mobile
  5252.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5253.      */
  5254.  
  5255.     woodmartThemeModule.headerCategoriesMenu = function () {
  5256.         if ($(window).width() > 1024) return;
  5257.  
  5258.         var categories = $('.header-categories-nav'),
  5259.             catsUl = categories.find('.categories-menu-dropdown'),
  5260.             subCategories = categories.find('.menu-item-has-children'),
  5261.             button = categories.find('.menu-opener'),
  5262.             time = 200,
  5263.             iconDropdown = '<span class="drop-category"></span>';
  5264.  
  5265.         subCategories.find('> a').before(iconDropdown);
  5266.  
  5267.         catsUl.on('click', '.drop-category', function () {
  5268.             var sublist = $(this).parent().find('> .sub-menu-dropdown, >.sub-sub-menu');
  5269.             if (sublist.hasClass('child-open')) {
  5270.                 $(this).removeClass("act-icon");
  5271.                 sublist.slideUp(time).removeClass('child-open');
  5272.             } else {
  5273.                 $(this).addClass("act-icon");
  5274.                 sublist.slideDown(time).addClass('child-open');
  5275.             }
  5276.         });
  5277.  
  5278.         categories.on('click', '.menu-opener', function (e) {
  5279.             e.preventDefault();
  5280.  
  5281.             if (isOpened()) {
  5282.                 closeCats();
  5283.             } else {
  5284.                 //setTimeout(function() {
  5285.                 openCats();
  5286.                 //}, 50);
  5287.             }
  5288.         });
  5289.  
  5290.         catsUl.on('click', 'a', function (e) {
  5291.             closeCats();
  5292.             catsUl.stop().attr('style', '');
  5293.         });
  5294.  
  5295.         var isOpened = function () {
  5296.             return catsUl.hasClass('categories-opened');
  5297.         };
  5298.  
  5299.         var openCats = function () {
  5300.             catsUl.addClass('categories-opened').stop().slideDown(time);
  5301.             button.addClass('button-open');
  5302.  
  5303.         };
  5304.  
  5305.         var closeCats = function () {
  5306.             catsUl.removeClass('categories-opened').stop().slideUp(time);
  5307.             button.removeClass('button-open');
  5308.         };
  5309.     };
  5310.  
  5311.     /**
  5312.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5313.      * Categories menu for mobile
  5314.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5315.      */
  5316.  
  5317.     woodmartThemeModule.categoriesMenu = function () {
  5318.         if ($(window).width() > 1024) return;
  5319.  
  5320.         var categories = $('.woodmart-product-categories'),
  5321.             subCategories = categories.find('li > ul'),
  5322.             button = $('.woodmart-show-categories'),
  5323.             time = 200;
  5324.  
  5325.         //this.categoriesMenuBtns();
  5326.  
  5327.         $('body').on('click', '.icon-drop-category', function () {
  5328.             if ($(this).closest('.has-sub').find('> ul').hasClass('child-open')) {
  5329.                 $(this).removeClass("woodmart-act-icon").closest('.has-sub').find('> ul').slideUp(time).removeClass('child-open');
  5330.             } else {
  5331.                 $(this).addClass("woodmart-act-icon").closest('.has-sub').find('> ul').slideDown(time).addClass('child-open');
  5332.             }
  5333.         });
  5334.  
  5335.         $('body').on('click', '.woodmart-show-categories', function (e) {
  5336.             e.preventDefault();
  5337.  
  5338.             if (isOpened()) {
  5339.                 closeCats();
  5340.             } else {
  5341.                 //setTimeout(function() {
  5342.                 openCats();
  5343.                 //}, 50);
  5344.             }
  5345.         });
  5346.  
  5347.         $('body').on('click', '.woodmart-product-categories a', function (e) {
  5348.             closeCats();
  5349.             categories.stop().attr('style', '');
  5350.         });
  5351.  
  5352.         var isOpened = function () {
  5353.             return $('.woodmart-product-categories').hasClass('categories-opened');
  5354.         };
  5355.  
  5356.         var openCats = function () {
  5357.             $('.woodmart-product-categories').addClass('categories-opened').stop().slideDown(time);
  5358.             $('.woodmart-show-categories').addClass('button-open');
  5359.  
  5360.         };
  5361.  
  5362.         var closeCats = function () {
  5363.             $('.woodmart-product-categories').removeClass('categories-opened').stop().slideUp(time);
  5364.             $('.woodmart-show-categories').removeClass('button-open');
  5365.         };
  5366.     };
  5367.  
  5368.     woodmartThemeModule.categoriesMenuBtns = function () {
  5369.         if ($(window).width() > 1024) return;
  5370.  
  5371.         var categories = $('.woodmart-product-categories'),
  5372.             subCategories = categories.find('li > ul'),
  5373.             iconDropdown = '<span class="icon-drop-category"></span>';
  5374.  
  5375.         categories.addClass('responsive-cateogires');
  5376.         subCategories.parent().addClass('has-sub').find('> .category-nav-link').prepend(iconDropdown);
  5377.     };
  5378.  
  5379.     /**
  5380.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5381.      * Filters area
  5382.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5383.      */
  5384.  
  5385.     woodmartThemeModule.filtersArea = function () {
  5386.         var filters = $('.filters-area'),
  5387.             btn = $('.open-filters'),
  5388.             time = 200;
  5389.  
  5390.         $('body').on('click', '.open-filters', function (e) {
  5391.             e.preventDefault();
  5392.  
  5393.             if (isOpened()) {
  5394.                 closeFilters();
  5395.             } else {
  5396.                 woodmartThemeModule.openFilters(time);
  5397.                 setTimeout(function () {
  5398.                     woodmartThemeModule.shopLoader();
  5399.                 }, time);
  5400.             }
  5401.  
  5402.         });
  5403.  
  5404.         if (woodmart_settings.shop_filters_close == 'no') {
  5405.             $('body').on('click', woodmartTheme.ajaxLinks, function () {
  5406.                 if (isOpened()) {
  5407.                     closeFilters();
  5408.                 }
  5409.             });
  5410.         }
  5411.  
  5412.         var isOpened = function () {
  5413.             filters = $('.filters-area')
  5414.             return filters.hasClass('filters-opened');
  5415.         };
  5416.  
  5417.         var closeFilters = function () {
  5418.             filters = $('.filters-area')
  5419.             filters.removeClass('filters-opened');
  5420.             filters.stop().slideUp(time);
  5421.             $('.open-filters').removeClass('btn-opened');
  5422.         };
  5423.     };
  5424.  
  5425.     woodmartThemeModule.openFilters = function (time) {
  5426.         var filters = $('.filters-area')
  5427.         filters.stop().slideDown(time);
  5428.         $('.open-filters').addClass('btn-opened');
  5429.         setTimeout(function () {
  5430.             filters.addClass('filters-opened');
  5431.             $('body').removeClass('body-filters-opened');
  5432.             woodmartThemeModule.nanoScroller();
  5433.             $(document).trigger('wood-images-loaded');
  5434.         }, time);
  5435.     };
  5436.  
  5437.     /**
  5438.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5439.      * Init shop page JS functions
  5440.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5441.      */
  5442.  
  5443.     woodmartThemeModule.shopPageInit = function () {
  5444.         woodmartThemeModule.shopMasonry();
  5445.         woodmartThemeModule.ajaxSearch();
  5446.         woodmartThemeModule.productHover();
  5447.         woodmartThemeModule.btnsToolTips();
  5448.         woodmartThemeModule.compare();
  5449.         woodmartThemeModule.filterDropdowns();
  5450.         woodmartThemeModule.sortByWidget();
  5451.         woodmartThemeModule.categoriesMenuBtns();
  5452.         woodmartThemeModule.categoriesAccordion();
  5453.         woodmartThemeModule.woocommercePriceSlider();
  5454.         woodmartThemeModule.countDownTimer();
  5455.         woodmartThemeModule.nanoScroller();
  5456.         woodmartThemeModule.shopLoader();
  5457.         woodmartThemeModule.stickySidebarBtn();
  5458.         woodmartThemeModule.productFilters();
  5459.  
  5460.         woodmartThemeModule.clickOnScrollButton(woodmartTheme.shopLoadMoreBtn, false, woodmart_settings.infinit_scroll_offset);
  5461.  
  5462.         // Bootstrap tooltips reset
  5463.  
  5464.         $('body > .tooltip').remove();
  5465.  
  5466.         $(document.body).on('updated_wc_div', function () {
  5467.             $(document).trigger('wood-images-loaded');
  5468.         });
  5469.  
  5470.         $(document).trigger('resize.vcRowBehaviour');
  5471.     };
  5472.  
  5473.     /**
  5474.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5475.      * Ajax filters
  5476.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5477.      */
  5478.  
  5479.     woodmartThemeModule.ajaxFilters = function () {
  5480.         if (!$('body').hasClass('woodmart-ajax-shop-on') || typeof ($.fn.pjax) == 'undefined' || $('body').hasClass('single-product')) {
  5481.             return;
  5482.         }
  5483.        
  5484.         var that = this,
  5485.             filtersState = false,
  5486.             products = $('.products');
  5487.  
  5488.         $('body').on('click', '.post-type-archive-product .products-footer .woocommerce-pagination a', function (e) {
  5489.             scrollToTop(true);
  5490.         });
  5491.  
  5492.         $(document).pjax(woodmartTheme.ajaxLinks, '.main-page-wrapper', {
  5493.             timeout: woodmart_settings.pjax_timeout,
  5494.             scrollTo: false
  5495.         });
  5496.  
  5497.         if (woodmart_settings.price_filter_action == 'click') {
  5498.             $(document).on('click', '.widget_price_filter form .button', function () {
  5499.                 var form = $('.widget_price_filter form');
  5500.                 $.pjax({
  5501.                     container: '.main-page-wrapper',
  5502.                     timeout: woodmart_settings.pjax_timeout,
  5503.                     url: form.attr('action'),
  5504.                     data: form.serialize(),
  5505.                     scrollTo: false
  5506.                 });
  5507.  
  5508.                 return false;
  5509.             });
  5510.         } else if (woodmart_settings.price_filter_action == 'submit') {
  5511.             $(document).on('submit', '.widget_price_filter form', function (event) {
  5512.                 var container = $('.main-page-wrapper');
  5513.                 $.pjax.submit(event, container);
  5514.             });
  5515.         }
  5516.  
  5517.         $(document).on('pjax:error', function (xhr, textStatus, error, options) {
  5518.             console.log('pjax error ' + error);
  5519.         });
  5520.  
  5521.         $(document).on('pjax:start', function (xhr, options) {
  5522.             $('.site-content').removeClass('ajax-loaded');
  5523.             $('.site-content').addClass('ajax-loading');
  5524.             woodmartThemeModule.hideShopSidebar();
  5525.         });
  5526.  
  5527.         $(document).on('pjax:complete', function (xhr, textStatus, options) {
  5528.  
  5529.             that.shopPageInit();
  5530.             scrollToTop(false);
  5531.  
  5532.             $(document).trigger('wood-images-loaded');
  5533.  
  5534.             $('.woodmart-sidebar-content').scroll(function () {
  5535.                 $(document).trigger('wood-images-loaded');
  5536.             })
  5537.  
  5538.             $('.site-content').removeClass('ajax-loading');
  5539.         });
  5540.  
  5541.         $(document).on('pjax:beforeReplace', function (contents, options) {
  5542.             if ($('.filters-area').hasClass('filters-opened') && woodmart_settings.shop_filters_close == 'yes') {
  5543.                 filtersState = true;
  5544.                 $('body').addClass('body-filters-opened');
  5545.             }
  5546.         });
  5547.  
  5548.         $(document).on('pjax:end', function (xhr, textStatus, options) {
  5549.             if (filtersState) {
  5550.                 $('.filters-area').css('display', 'block');
  5551.                 woodmartThemeModule.openFilters(200);
  5552.                 filtersState = false;
  5553.             }
  5554.             $('.site-content').removeClass('ajax-loading');
  5555.             $('.site-content').addClass('ajax-loaded');
  5556.         });
  5557.  
  5558.         var scrollToTop = function (type) {
  5559.             if (woodmart_settings.ajax_scroll == 'no' && type == false) return false;
  5560.  
  5561.             var $scrollTo = $(woodmart_settings.ajax_scroll_class),
  5562.                 scrollTo = $scrollTo.offset().top - woodmart_settings.ajax_scroll_offset;
  5563.  
  5564.             $('html, body').stop().animate({
  5565.                 scrollTop: scrollTo
  5566.             }, 400);
  5567.         };
  5568.     };
  5569.  
  5570.     /**
  5571.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5572.      * Side shopping cart widget
  5573.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5574.      */
  5575.  
  5576.     woodmartThemeModule.cartWidget = function () {
  5577.         var widget = $('.cart-widget-opener'),
  5578.             btn = widget.find('a'),
  5579.             body = $('body');
  5580.  
  5581.         var cartWidgetSide = $('.cart-widget-side');
  5582.         var closeSide = $('.woodmart-close-side');
  5583.  
  5584.         widget.on('click', function (e) {
  5585.             if (!isCart() && !isCheckout()) e.preventDefault();
  5586.  
  5587.             if (isOpened()) {
  5588.                 closeWidget();
  5589.             } else {
  5590.                 setTimeout(function () {
  5591.                     openWidget();
  5592.                 }, 10);
  5593.             }
  5594.  
  5595.         });
  5596.  
  5597.         body.on("click touchstart", ".woodmart-close-side", function () {
  5598.             if (isOpened()) {
  5599.                 closeWidget();
  5600.             }
  5601.         });
  5602.  
  5603.         body.on("click", ".close-side-widget", function (e) {
  5604.             e.preventDefault();
  5605.             if (isOpened()) {
  5606.                 closeWidget();
  5607.             }
  5608.         });
  5609.  
  5610.         $(document).keyup(function (e) {
  5611.             if (e.keyCode === 27 && isOpened()) closeWidget();
  5612.         });
  5613.  
  5614.         var closeWidget = function () {
  5615.             cartWidgetSide.removeClass('woodmart-cart-opened');
  5616.             closeSide.removeClass('woodmart-close-side-opened');
  5617.         };
  5618.  
  5619.         var openWidget = function () {
  5620.             if (isCart() || isCheckout()) return false;
  5621.             cartWidgetSide.addClass('woodmart-cart-opened');
  5622.             closeSide.addClass('woodmart-close-side-opened');
  5623.         };
  5624.  
  5625.         var isOpened = function () {
  5626.             return cartWidgetSide.hasClass('woodmart-cart-opened');
  5627.         };
  5628.  
  5629.         var isCart = function () {
  5630.             return $('body').hasClass('woocommerce-cart');
  5631.         };
  5632.  
  5633.         var isCheckout = function () {
  5634.             return $('body').hasClass('woocommerce-checkout');
  5635.         };
  5636.     };
  5637.  
  5638.     /**
  5639.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5640.      * Quantityt +/-
  5641.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5642.      */
  5643.  
  5644.     woodmartThemeModule.woocommerceQuantity = function () {
  5645.         if (!String.prototype.getDecimals) {
  5646.             String.prototype.getDecimals = function () {
  5647.                 var num = this,
  5648.                     match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
  5649.                 if (!match) {
  5650.                     return 0;
  5651.                 }
  5652.                 return Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0));
  5653.             }
  5654.         }
  5655.  
  5656.         $(document).on('click', '.plus, .minus', function () {
  5657.             // Get values
  5658.             var $qty = $(this).closest('.quantity').find('.qty'),
  5659.                 currentVal = parseFloat($qty.val()),
  5660.                 max = parseFloat($qty.attr('max')),
  5661.                 min = parseFloat($qty.attr('min')),
  5662.                 step = $qty.attr('step');
  5663.  
  5664.             // Format values
  5665.             if (!currentVal || currentVal === '' || currentVal === 'NaN') currentVal = 0;
  5666.             if (max === '' || max === 'NaN') max = '';
  5667.             if (min === '' || min === 'NaN') min = 0;
  5668.             if (step === 'any' || step === '' || step === undefined || parseFloat(step) === 'NaN') step = '1';
  5669.  
  5670.             // Change the value
  5671.             if ($(this).is('.plus')) {
  5672.                 if (max && (currentVal >= max)) {
  5673.                     $qty.val(max);
  5674.                 } else {
  5675.                     $qty.val((currentVal + parseFloat(step)).toFixed(step.getDecimals()));
  5676.                 }
  5677.             } else {
  5678.                 if (min && (currentVal <= min)) {
  5679.                     $qty.val(min);
  5680.                 } else if (currentVal > 0) {
  5681.                     $qty.val((currentVal - parseFloat(step)).toFixed(step.getDecimals()));
  5682.                 }
  5683.             }
  5684.  
  5685.             // Trigger change event
  5686.             $qty.trigger('change');
  5687.         });
  5688.     };
  5689.  
  5690.     /**
  5691.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5692.      * On remove from cart widget
  5693.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5694.      */
  5695.  
  5696.     woodmartThemeModule.onRemoveFromCart = function () {
  5697.         $(document).on('click', '.widget_shopping_cart .remove', function (e) {
  5698.             e.preventDefault();
  5699.             $(this).parent().addClass('removing-process');
  5700.         });
  5701.     };
  5702.  
  5703.     /**
  5704.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5705.      * Fix comments
  5706.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5707.      */
  5708.  
  5709.     woodmartThemeModule.woocommerceComments = function () {
  5710.         var hash = window.location.hash;
  5711.         var url = window.location.href;
  5712.  
  5713.         if (hash.toLowerCase().indexOf('comment-') >= 0 || hash === '#reviews' || hash === '#tab-reviews' || url.indexOf('comment-page-') > 0 || url.indexOf('cpage=') > 0) {
  5714.  
  5715.             setTimeout(function () {
  5716.                 window.scrollTo(0, 0);
  5717.             }, 1);
  5718.  
  5719.             setTimeout(function () {
  5720.                 if ($(hash).length > 0) {
  5721.                     $('html, body').stop().animate({
  5722.                         scrollTop: $(hash).offset().top - 100
  5723.                     }, 400);
  5724.                 }
  5725.             }, 10);
  5726.  
  5727.         }
  5728.     };
  5729.  
  5730.     /**
  5731.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5732.      * Mobile responsive navigation
  5733.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5734.      */
  5735.  
  5736.     woodmartThemeModule.woocommerceWrappTable = function () {
  5737.         var wooTable = $(".shop_table:not(.shop_table_responsive):not(.woocommerce-checkout-review-order-table)").wrap("<div class='responsive-table'></div>");
  5738.     };
  5739.  
  5740.     /**
  5741.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5742.      * Product loder position
  5743.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5744.      */
  5745.  
  5746.     woodmartThemeModule.productLoaderPosition = function () {
  5747.         var recalc = function () {
  5748.             $('.woodmart-products-loader').each(function () {
  5749.                 var $loader = $(this),
  5750.                     $loaderWrap = $loader.parent();
  5751.  
  5752.                 if ($loader.length == 0) return;
  5753.  
  5754.                 $loader.css('left', $loaderWrap.offset().left + $loaderWrap.outerWidth() / 2);
  5755.             });
  5756.         };
  5757.  
  5758.         $(window).on('resize', recalc);
  5759.  
  5760.         recalc();
  5761.     };
  5762.  
  5763.     /**
  5764.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5765.      * Init Zoom
  5766.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5767.      */
  5768.  
  5769.     woodmartThemeModule.initZoom = function () {
  5770.         var $mainGallery = $('.woocommerce-product-gallery__wrapper:not(.quick-view-gallery)');
  5771.  
  5772.         if (woodmart_settings.zoom_enable != 'yes') {
  5773.             return false;
  5774.         }
  5775.  
  5776.         $mainGallery.find('.product-image-wrap').each(function () {
  5777.             var $wrapper = $(this).find('.woocommerce-product-gallery__image');
  5778.             var image = $wrapper.find('img');
  5779.             var zoomOptions = {
  5780.                 touch: false
  5781.             };
  5782.  
  5783.             if ('ontouchstart' in window) {
  5784.                 zoomOptions.on = 'click';
  5785.             }
  5786.  
  5787.             // But only zoom if the img is larger than its container.
  5788.             if (image.data('large_image_width') > $(this).width()) {
  5789.                 $wrapper.trigger('zoom.destroy');
  5790.                 $wrapper.zoom(zoomOptions);
  5791.             }
  5792.         });
  5793.     };
  5794.  
  5795.     /**
  5796.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5797.      * Product Hover
  5798.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5799.      */
  5800.     woodmartThemeModule.productMoreDescription = function ()  {
  5801.         $('.woodmart-more-desc').each(function () {
  5802.             var btnHTML = '<a href="#" class="woodmart-more-desc-btn"><span>' + 'more' + '</span></a>';
  5803.             var $content = $(this);
  5804.             var $inner = $content.find('.woodmart-more-desc-inner');
  5805.             var contentHeight = $content.outerHeight();
  5806.             var innerHeight = $inner.outerHeight();
  5807.             var delta = innerHeight - contentHeight;
  5808.  
  5809.             if ($content.hasClass('woodmart-more-desc-active')) {
  5810.                 return;
  5811.             }
  5812.  
  5813.             if (delta > 30) {
  5814.                 $content.addClass('woodmart-more-desc-active');
  5815.                 $content.append(btnHTML);
  5816.             } else if (delta > 0) {
  5817.                 $content.css('height', contentHeight + delta);
  5818.             }
  5819.         });
  5820.  
  5821.         $('body').on('click', '.woodmart-more-desc-btn', function (e) {
  5822.             e.preventDefault();
  5823.             $(this).parent().addClass('woodmart-more-desc-full');
  5824.  
  5825.             woodmartThemeModule.productHoverRecalc($(this).parents('.woodmart-hover-base'));
  5826.         });
  5827.     };
  5828.  
  5829.     woodmartThemeModule.productHoverRecalc = function ($el) {
  5830.         if ($el.hasClass('product-in-carousel')) {
  5831.             return;
  5832.         }
  5833.  
  5834.         var heightHideInfo = $el.find('.fade-in-block').outerHeight();
  5835.  
  5836.         $el.find('.content-product-imagin').css({
  5837.             marginBottom: -heightHideInfo
  5838.         });
  5839.  
  5840.         $el.addClass('hover-ready');
  5841.     };
  5842.  
  5843.     woodmartThemeModule.productHover = function () {
  5844.         $('.woodmart-hover-base').each(function () {
  5845.             var $product = $(this);
  5846.  
  5847.             $product.imagesLoaded(function () {
  5848.                 woodmartThemeModule.productHoverRecalc($product);
  5849.             });
  5850.         });
  5851.  
  5852.         if ($(window).width() <= 1024) {
  5853.             $('.woodmart-hover-base').on('click', function (e) {
  5854.                 var hoverClass = 'state-hover';
  5855.                 if (!$(this).hasClass(hoverClass) && woodmart_settings.base_hover_mobile_click == 'no') {
  5856.                     e.preventDefault();
  5857.                     $('.' + hoverClass).removeClass(hoverClass);
  5858.                     $(this).addClass(hoverClass);
  5859.                 }
  5860.             });
  5861.             $(document).on('click touchstart', function (e) {
  5862.                 if ($(e.target).closest('.state-hover').length == 0) {
  5863.                     $('.state-hover').removeClass('state-hover');
  5864.                 }
  5865.             });
  5866.         }
  5867.  
  5868.         $('.product-grid-item').each(function () {
  5869.             var $el = $(this),
  5870.                 widthHiddenInfo = $el.outerWidth();
  5871.  
  5872.             if ($(window).width() <= 1024 && $el.hasClass('woodmart-hover-icons') || !woodmart_settings.hover_width_small) return;
  5873.  
  5874.             if (widthHiddenInfo < 255 || $(window).width() <= 1024) {
  5875.                 $el.removeClass('hover-width-big').addClass('hover-width-small');
  5876.             } else {
  5877.                 $el.removeClass('hover-width-small').addClass('hover-width-big');
  5878.             }
  5879.         })
  5880.  
  5881.     };
  5882.     /**
  5883.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5884.      * Enable masonry grid for shop isotope type
  5885.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5886.      */
  5887.     woodmartThemeModule.shopMasonry = function () {
  5888.  
  5889.         if (typeof ($.fn.isotope) == 'undefined' || typeof ($.fn.imagesLoaded) == 'undefined') return;
  5890.         var $container = $('.elements-grid.grid-masonry');
  5891.         // initialize Masonry after all images have loaded
  5892.         $container.imagesLoaded(function () {
  5893.             $container.isotope({
  5894.                 isOriginLeft: !$('body').hasClass('rtl'),
  5895.                 itemSelector: '.category-grid-item, .product-grid-item',
  5896.             });
  5897.         });
  5898.  
  5899.         // Categories masonry
  5900.         $(window).resize(function () {
  5901.             var $catsContainer = $('.categories-masonry');
  5902.             var colWidth = ($catsContainer.hasClass('categories-style-masonry')) ? '.category-grid-item' : '.col-lg-3.category-grid-item';
  5903.             $catsContainer.imagesLoaded(function () {
  5904.                 $catsContainer.packery({
  5905.                     resizable: false,
  5906.                     isOriginLeft: !$('body').hasClass('rtl'),
  5907.                     // layoutMode: 'packery',
  5908.                     packery: {
  5909.                         gutter: 0,
  5910.                         columnWidth: colWidth
  5911.                     },
  5912.                     itemSelector: '.category-grid-item',
  5913.                     // masonry: {
  5914.                     // gutter: 0
  5915.                     // }
  5916.                 });
  5917.             });
  5918.         });
  5919.  
  5920.     };
  5921.  
  5922.     /**
  5923.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5924.      * Categories toggle accordion
  5925.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5926.      */
  5927.     woodmartThemeModule.categoriesAccordion = function () {
  5928.  
  5929.         if (woodmart_settings.categories_toggle == 'no') return;
  5930.  
  5931.         var $widget = $('.widget_product_categories'),
  5932.             $list = $widget.find('.product-categories'),
  5933.             time = 300;
  5934.  
  5935.         $list.find('.cat-parent').each(function () {
  5936.             if ($(this).find(' > .woodmart-cats-toggle').length > 0) return;
  5937.             if ($(this).find(' > .children').length == 0) return;
  5938.             $(this).append('<div class="woodmart-cats-toggle"></div>');
  5939.         });
  5940.  
  5941.         $list.on('click', '.woodmart-cats-toggle', function () {
  5942.             var $btn = $(this),
  5943.                 $subList = $btn.prev();
  5944.  
  5945.             if ($subList.hasClass('list-shown')) {
  5946.                 $btn.removeClass('toggle-active');
  5947.                 $subList.stop().slideUp(time).removeClass('list-shown');
  5948.             } else {
  5949.                 $subList.parent().parent().find('> li > .list-shown').slideUp().removeClass('list-shown');
  5950.                 $subList.parent().parent().find('> li > .toggle-active').removeClass('toggle-active');
  5951.                 $btn.addClass('toggle-active');
  5952.                 $subList.stop().slideDown(time).addClass('list-shown');
  5953.             }
  5954.         });
  5955.  
  5956.         if ($list.find('li.current-cat.cat-parent, li.current-cat-parent').length > 0) {
  5957.             $list.find('li.current-cat.cat-parent, li.current-cat-parent').find('> .woodmart-cats-toggle').click();
  5958.         }
  5959.  
  5960.     };
  5961.  
  5962.     /**
  5963.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5964.      * WooCommerce price filter slider with ajax
  5965.      *-------------------------------------------------------------------------------------------------------------------------------------------
  5966.      */
  5967.  
  5968.     woodmartThemeModule.woocommercePriceSlider = function () {
  5969.  
  5970.         // woocommerce_price_slider_params is required to continue, ensure the object exists
  5971.         if (typeof woocommerce_price_slider_params === 'undefined' || $('.price_slider_amount #min_price').length < 1 || !$.fn.slider) {
  5972.             return false;
  5973.         }
  5974.  
  5975.         var $slider = $('.price_slider');
  5976.  
  5977.         if ($slider.slider('instance') !== undefined) return;
  5978.  
  5979.         // Get markup ready for slider
  5980.         $('input#min_price, input#max_price').hide();
  5981.         $('.price_slider, .price_label').show();
  5982.  
  5983.         // Price slider uses $ ui
  5984.         var min_price = $('.price_slider_amount #min_price').data('min'),
  5985.             max_price = $('.price_slider_amount #max_price').data('max'),
  5986.             current_min_price = parseInt(min_price, 10),
  5987.             current_max_price = parseInt(max_price, 10);
  5988.  
  5989.         if ($('.products').attr('data-min_price') && $('.products').attr('data-min_price').length > 0) {
  5990.             current_min_price = parseInt($('.products').attr('data-min_price'), 10);
  5991.         }
  5992.         if ($('.products').attr('data-max_price') && $('.products').attr('data-max_price').length > 0) {
  5993.             current_max_price = parseInt($('.products').attr('data-max_price'), 10);
  5994.         }
  5995.  
  5996.         $slider.slider({
  5997.             range: true,
  5998.             animate: true,
  5999.             min: min_price,
  6000.             max: max_price,
  6001.             values: [current_min_price, current_max_price],
  6002.             create: function () {
  6003.  
  6004.                 $('.price_slider_amount #min_price').val(current_min_price);
  6005.                 $('.price_slider_amount #max_price').val(current_max_price);
  6006.  
  6007.                 $(document.body).trigger('price_slider_create', [current_min_price, current_max_price]);
  6008.             },
  6009.             slide: function (event, ui) {
  6010.  
  6011.                 $('input#min_price').val(ui.values[0]);
  6012.                 $('input#max_price').val(ui.values[1]);
  6013.  
  6014.                 $(document.body).trigger('price_slider_slide', [ui.values[0], ui.values[1]]);
  6015.             },
  6016.             change: function (event, ui) {
  6017.  
  6018.                 $(document.body).trigger('price_slider_change', [ui.values[0], ui.values[1]]);
  6019.             }
  6020.         });
  6021.  
  6022.         setTimeout(function () {
  6023.             $(document.body).trigger('price_slider_create', [current_min_price, current_max_price]);
  6024.             if ($slider.find('.ui-slider-range').length > 1) $slider.find('.ui-slider-range').first().remove();
  6025.         }, 10);
  6026.     };
  6027.  
  6028. })(jQuery);
  6029.  
  6030. jQuery(document).ready(function () {
  6031.     woodmartThemeModule.init();
  6032. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement