valeraplusplus

construction-equipment-store 01.09

Sep 1st, 2025
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function ($, myObject) {
  2.  
  3.     var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),
  4.         isApple = /iPod|iPad|iPhone/i.test(navigator.userAgent),
  5.         $doc = $(document),
  6.         $win = $(window),
  7.         $html = $(document.documentElement);
  8.  
  9.  
  10.     shop2.search.getParams = function (folder_id, func) {
  11.         var gr_filter_max_count = shop2.my.gr_filter_max_count;
  12.         var url;
  13.  
  14.         shop2.trigger('beforeGetFolderCustomFields');
  15.  
  16.         if (folder_id > 0) {
  17.             if (shop2.my.gr_search_fields_new) {
  18.                 $.getJSON('/-/x-api/v1/public/?method=shop2/getFolderCustomFields', {
  19.                     param: {
  20.                         folder_id: folder_id,
  21.                         html: 1
  22.                     },
  23.                     gr_filter_max_count: gr_filter_max_count,
  24.                     gr_search_fields_new: 1
  25.                 }, function (d, status) {
  26.                     shop2.fire('afterGetFolderCustomFields', func, d.result, status);
  27.                     shop2.trigger('afterGetFolderCustomFields', d.result, status);
  28.                 });
  29.             } else {
  30.                 $.getJSON('/-/x-api/v1/public/?method=shop2/getFolderCustomFields', {
  31.                     param: {
  32.                         folder_id: folder_id,
  33.                         html: 1
  34.                     },
  35.                     gr_filter_max_count: gr_filter_max_count
  36.                 }, function (d, status) {
  37.                     shop2.fire('afterGetFolderCustomFields', func, d.result, status);
  38.                     shop2.trigger('afterGetFolderCustomFields', d.result, status);
  39.                 });
  40.             }
  41.         }
  42.     };
  43.  
  44.  
  45.     shop2.queue.search = function () {
  46.         var custom = $('#shop2_search_custom_fields'),
  47.             global = $('#shop2_search_global_fields');
  48.  
  49.         shop2.on('afterGetFolderCustomFields', function (d, status) {
  50.             custom.html(d.data);
  51.             global.find('input, select').prop('disabled', true);
  52.             global.hide();
  53.         });
  54.  
  55.         if ($('.site__wrapper').hasClass('gr-inner-pages')) {
  56.  
  57.             $('#s\\[folder_id\\]').on('change', function () {
  58.                 var $this = $(this),
  59.                     folder_id = $this.val();
  60.  
  61.                 if (folder_id) {
  62.  
  63.                     shop2.search.getParams(folder_id);
  64.  
  65.                 } else {
  66.  
  67.                     custom.html('');
  68.  
  69.                     global.find('input, select').prop('disabled', false);
  70.  
  71.                     global.show();
  72.  
  73.                 }
  74.             }).trigger('change');
  75.  
  76.         } else {
  77.  
  78.             $('#s\\[folder_id\\]').on('change', function () {
  79.                 var $this = $(this),
  80.                     folder_id = $this.val();
  81.  
  82.                 if (folder_id) {
  83.  
  84.                     shop2.search.getParams(folder_id);
  85.  
  86.                 } else {
  87.  
  88.                     custom.html('');
  89.  
  90.                     global.find('input, select').prop('disabled', false);
  91.  
  92.                     global.show();
  93.  
  94.                 }
  95.             }).trigger('change');
  96.  
  97.             /*$('#s\\[folder_id\\] input[type="radio"]').on('click', function() {
  98.             var $this = $(this),
  99.                 folder_id =  $this.is(':checked') ? $this.val() : undefined;
  100.    
  101.             if (folder_id) {
  102.                
  103.                 shop2.search.getParams(folder_id);
  104.            
  105.             } else {
  106.                
  107.                 custom.html('');
  108.                
  109.                 global.find('input, select').prop('disabled', false);
  110.                
  111.                 global.show();
  112.                
  113.             }
  114.         });*/
  115.  
  116.         }
  117.  
  118.         if (shop2.facets.enabled) {
  119.             shop2.facets.searchSetup();
  120.         }
  121.  
  122.     };
  123.  
  124.  
  125.  
  126. shop2.queue.compare = function() {
  127.     var popup_data;
  128.     var compare_arrow = '<i><svg class="gr-svg-icon"><use xlink:href="#icon_shop_notify_arr"></use></svg></i>';
  129.     if (shop2.my.gr_popup_compare) {
  130.         popup_data = ' data-remodal-target="compare-preview-popup"';
  131.     };
  132.    
  133.     let $document = $(document);
  134.     if ($('html').attr('lang') == 'ru') {
  135.         var compareBtn = '<a href="' + shop2.uri + '/compare" class="go-to-compare-btn"'+popup_data+' target="_blank">к сравнению'+compare_arrow+'</a>';
  136.         var compareBtn2 = '<a href="' + shop2.uri + '/compare" class="go-to-compare-btn"'+popup_data+' target="_blank">Перейти к сравнению'+compare_arrow+'</a>';
  137.     } else {
  138.         var compareBtn = '<a href="' + shop2.uri + '/compare" class="go-to-compare-btn"'+popup_data+' target="_blank">сompare'+compare_arrow+'</a>';
  139.         var compareBtn2 = '<a href="' + shop2.uri + '/compare" class="go-to-compare-btn"'+popup_data+' target="_blank">Compare'+compare_arrow+'</a>';
  140.     };
  141.  
  142.     function update(el, res) {
  143.  
  144.         $('input[type=checkbox][value=' + el.val() + ']').closest('.product-compare').replaceWith(res.data);
  145.         $('.product-compare-added a span').html(res.count);
  146.         $('.gr-compare-btn .gr-compare-btn-amount').html(res.count);
  147.        
  148.         var $compare_favorit_amount = $('.compare_favorit_amount')
  149.         if( $compare_favorit_amount.length ){
  150.             $compare_favorit_amount.text( +res.count + +$( '.site-header .favorite-count').text() );
  151.         }
  152.        
  153.         $('.keys-compare-amount').html(res.count);
  154.         $('.sheet-compare-btn__amount').html(res.count);
  155.        
  156.         if (+$('.gr-compare-btn .gr-compare-btn-amount').text() == '0') {
  157.             $('.gr-compare-btn').removeClass('active');
  158.             $('.keys-panel__compare').removeClass('opened');
  159.             $('.sheet-compare-btn').removeClass('opened');
  160.            
  161.             $('.login_amount').removeClass('vis_amount');
  162.            
  163.         } else {
  164.             $('.gr-compare-btn').addClass('active');
  165.             $('.keys-panel__compare').addClass('opened');
  166.             $('.sheet-compare-btn').addClass('opened');
  167.            
  168.             $('.login_amount').addClass('vis_amount');
  169.         };
  170.        
  171.         if (!$('.compare-remodal').hasClass('remodal-is-opened')) {
  172.             if ($('html').attr('lang') == 'ru') {
  173.                 shop2.msg('<span class="go-to-compare-count">'+res.count+'</span>' + 'Товар добавлен ' + compareBtn, $('body'));
  174.             } else {
  175.                 shop2.msg('<span class="go-to-compare-count">'+res.count+'</span>' + 'Added to ' + compareBtn, $('body'));
  176.             };
  177.         };
  178.  
  179.         if (res.panel) {
  180.             $('#shop2-panel').replaceWith(res.panel);
  181.         };
  182.  
  183.     }
  184.  
  185.     $document.on('click', '.product-compare input:checkbox', function() {
  186.         let $this = $(this),
  187.             action = $this.attr('checked') ? 'del' : 'add';
  188.            
  189.         shop2.compare.action(action, $this.val(), function(res, status) {
  190.             if (status == 'success') {
  191.                
  192.  
  193.                 if (res.errstr) {
  194.                     if (!$('.compare-remodal').hasClass('remodal-is-opened')) {
  195.                         shop2.msg(res.errstr + '<div class="go-to-compare-error">'+compareBtn2+'</div>', $('body'));
  196.                     }
  197.                     $this.prop('checked', false);
  198.                 } else {
  199.                     update($this, res);
  200.                    
  201.                     if (action == 'del' && !$('.compare-remodal').hasClass('remodal-is-opened')) {
  202.                         if ($('html').attr('lang') == 'ru') {
  203.                             shop2.msg('Товар удален из сравнения', $('body'));
  204.                         } else {
  205.                             shop2.msg('Product removed from comparison', $('body'));
  206.                         };
  207.                     }
  208.                 }
  209.                
  210.             }
  211.         });
  212.     });
  213. };
  214.  
  215.  
  216.     var shop2_gr = {
  217.         queue: {},
  218.         methods: {},
  219.         init: function () {
  220.  
  221.             $(function () {
  222.  
  223.                 let queue = shop2_gr.queue;
  224.  
  225.                 if (isMobile) $html.addClass('mobile');
  226.  
  227.                 for (key in queue) {
  228.                     let f = queue[key];
  229.                     if (typeof f === 'function') {
  230.                         setTimeout(function () {
  231.                             f();
  232.                         });
  233.                     };
  234.                 }
  235.  
  236.             });
  237.  
  238.         }
  239.     };
  240.  
  241.     shop2_gr.queue = {
  242.         ajaxRequestsComplete: function () {
  243.  
  244.             $.ajaxSetup({
  245.                 complete: function () {
  246.                     setTimeout(function () {
  247.                         shop2_gr.methods.changeFlagsColor();
  248.                     });
  249.                 }
  250.             });
  251.  
  252.             shop2.on('afterProductReloaded', function () {
  253.  
  254.                 setTimeout(function () {
  255.                     shop2_gr.methods.viewLots();
  256.                     shop2_gr.methods.amountInit();
  257.                     shop2_gr.methods.changeFlagsColor();
  258.  
  259.                     $('.shop2-product-item .buy-one-click').attr('data-api-url', $('.product-list').data('popup-form'));
  260.                     $('.shop2-product-item .buy-one-click.product_info_form').attr('data-api-url', $('.product-list').data('info-popup-form'));
  261.  
  262.                     $('.product-list .gr_images_lazy_load').each(function () {
  263.                         $(this).attr('src', $(this).attr('data-src'));
  264.                     });
  265.  
  266.                     if (!isMobile) {
  267.                         $('.quick-view-trigger').elemToolTip({
  268.                             text: 'Быстрый просмотр',
  269.                             margin: 12
  270.                         });
  271.                     };
  272.  
  273.                     $('#shop2-tooltip').hide();
  274.  
  275.                     if ($('.product-item-wrap').length) {
  276.                         $('.main-products').eq(gr_reloaded_wrap_index).find('.product-item-wrap').eq(gr_reloaded_product_index).find('.shop2-product-item').addClass('active');
  277.                     } else {
  278.                         $('.shop2-product-item').eq(gr_reloaded_product_index).addClass('active');
  279.                     }
  280.  
  281.                     setTimeout(function () {
  282.                         var hideText = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
  283.  
  284.                         $('.shop2-product-item.active .gr-options-more__btn').addClass('active');
  285.                         $('.shop2-product-item.active .gr-options-more__btn ins').text(hideText);
  286.                         $('.shop2-product-item.active .gr-options-container').show();
  287.                         $('.shop2-product-item').removeClass('active');
  288.  
  289.                         $('.product-list.thumbs .product-price').matchHeight('remove');
  290.                         $('.product-list.thumbs .product-price').matchHeight();
  291.                     });
  292.                 });
  293.             });
  294.  
  295.             shop2.on('afterProductsLazyLoaded', function () {
  296.                 $('.product-list .gr_images_lazy_load').each(function () {
  297.                     $(this).attr('src', $(this).attr('data-src'));
  298.                 });
  299.  
  300.                 $('.quick-view-trigger').elemToolTip({
  301.                     text: 'Быстрый просмотр',
  302.                     margin: 12
  303.                 });
  304.  
  305.                 //$('.product-list.thumbs .product-item__bottom-left').matchHeight('remove');
  306.                 $('.product-list.thumbs .product-item__bottom-right').matchHeight('remove');
  307.                 $('.product-list.thumbs .product-price').matchHeight('remove');
  308.                 //$('.product-list.thumbs .product-item__bottom').matchHeight('remove');
  309.  
  310.                 $('.product-list.thumbs .product-item__bottom-right').matchHeight();
  311.                 $('.product-list.thumbs .product-price').matchHeight();
  312.                 //$('.product-list.thumbs .product-item__bottom-left').matchHeight();
  313.                 //$('.product-list.thumbs .product-item__bottom').matchHeight();
  314.  
  315.                 shop2_gr.methods.viewLots();
  316.                 shop2_gr.methods.amountInit();
  317.             });
  318.  
  319.         },
  320.         /*Обновление скриптов при аякс-запросах*/
  321.  
  322.         ajaxCompare: function () {
  323.             // if (shop2.mode=="") {
  324.             //  var url = document.location.origin;
  325.             //  $.ajax({
  326.             //      url: url,
  327.             //          success: function(data){
  328.             //          var compare_btn = $(data).find('.gr-compare-btn');
  329.             //          var cart_btn = $(data).find('.gr-cart-popup-btn');
  330.             //          $('.gr-compare-btn').replaceWith(compare_btn);
  331.             //          $('.gr-cart-popup-btn').replaceWith(cart_btn);
  332.             //      }
  333.             //  });
  334.             // }
  335.         },
  336.         /*Сравнение на страницах "не магазина"*/
  337.  
  338.         checkboxes: function () {
  339.             $('#orderForm input[name="personal_data"]').parents('label').next('a').appendTo($('#orderForm input[name="personal_data"]').parents('label'));
  340.  
  341.             $('.shop2-order-form input[type="checkbox"]:not(.gr-fixed-checkbox), .shop2-order-form input[type="radio"], .comments-block .tpl-field.checkbox input, .tpl-field-reg input, .gr-authorization-checkbox, .shop2-order-options.shop2-payment-options .payment_methods-column input[type="radio"], #orderForm input[name="personal_data"]').mgStyler();
  342.  
  343.             $('#orderForm .mg-styler-label--checkbox a').on('click', function (e) {
  344.                 var $label = $(this).parent();
  345.                 var $input = $(this).parents('label').find('input');
  346.                 var href = $(this).attr('href');
  347.                 window.open(href, '_blank');
  348.  
  349.                 if ($('.mg-styler-label--checkbox input').is(':checked')) {
  350.                     setTimeout(function () {
  351.                         $input.prop('checked', true);
  352.                         $label.addClass('checked');
  353.                     }, 10);
  354.                 } else {
  355.                     setTimeout(function () {
  356.                         $input.prop('checked', false);
  357.                         $label.removeClass('checked');
  358.                     }, 10);
  359.                 }
  360.             });
  361.  
  362.             $(document).on('click', '.shop2-edost-variant > label', function () {
  363.                 if ($('.shop2-edost-variant > label > .shop2-edost-control input[type="radio"]:checked')) {
  364.                     $('.shop2-edost-variant > label > .shop2-edost-control').removeClass("active");
  365.                     $('.shop2-edost-variant > label > .shop2-edost-control input[type="radio"]:checked').parent().addClass('active');
  366.                 }
  367.  
  368.                 if ($('.shop2-edost-office > label > .shop2-edost-control input[type="radio"]:checked')) {
  369.                     $('.shop2-edost-office > label > .shop2-edost-control').removeClass("active");
  370.                     $('.shop2-edost-office > label > .shop2-edost-control input[type="radio"]:checked').parent().addClass('active');
  371.                 }
  372.             });
  373.  
  374.             $(document).on("click", ".shop2-edost-office > label", function () {
  375.                 if ($('.shop2-edost-office > label > .shop2-edost-control input[type="radio"]:checked')) {
  376.                     $('.shop2-edost-office > label > .shop2-edost-control').removeClass("active");
  377.                     $('.shop2-edost-office > label > .shop2-edost-control input[type="radio"]:checked').parent().addClass('active');
  378.                 }
  379.             });
  380.         },
  381.         /*Чекбоксы*/
  382.  
  383.         facetSelect: function () {
  384.             $(document).on('click', '.shop-search-color-select li', function () {
  385.                 var $input = $(this).find('input');
  386.                 var value = $(this).data('value');
  387.  
  388.                 if ($(this).hasClass('shop2-color-ext-selected')) {
  389.                     $input.val("");
  390.                     $(this).removeClass('shop2-color-ext-selected');
  391.                 } else {
  392.                     $(this).addClass('shop2-color-ext-selected');
  393.                     $input.val(value);
  394.                 }
  395.  
  396.                 if (shop2.facets.enabled) {
  397.                     var url = '/-/x-api/v1/public/?method=shop2/getSearchMatches';
  398.  
  399.                     var formData = $(shop2.facets.search.wrapper).serialize();
  400.  
  401.                     shop2.facets.getDataSearch(url, formData);
  402.                 };
  403.             });
  404.  
  405.             $(document).on('click', '.type-checkbox [data-name]', function () {
  406.                 if (shop2.facets.enabled) {
  407.                     var url = '/-/x-api/v1/public/?method=shop2/getSearchMatches';
  408.  
  409.                     var formData = $(shop2.facets.search.wrapper).serialize();
  410.  
  411.                     shop2.facets.getDataSearch(url, formData);
  412.                 };
  413.             });
  414.         },
  415.         /*Допполя в фасетном поиске*/
  416.  
  417.         headerBlock: function () {
  418.  
  419.  
  420.             /* Меню сайта */
  421.             if (window.matchMedia("(min-width: 1261px)").matches) {
  422.  
  423.                 setTimeout(function () {
  424.                     let siteMenu = $('.site-menu');
  425.  
  426.                     let menuList = siteMenu.find('.top-menu');
  427.                     menuList.rowMenu({
  428.                         "moreText": menuList.data('site_more_menu'),
  429.                         "moreWidth": 100
  430.                     });
  431.  
  432.  
  433.                     if (isMobile) {
  434.  
  435.                         $(document).on('click', '.row-menu-btn', function () {
  436.                             $('.top-menu > .has > a').removeClass('active').removeClass('active_mobile');
  437.                         });
  438.  
  439.                         $(document).on('click', '.top-menu .has > a', function (e) {
  440.                             if (!$(this).hasClass('active_mobile') && !$(this).parents().find('>a').hasClass('active_mobile')) {
  441.                                 $('.top-menu .has a').removeClass('active').removeClass('active_mobile');
  442.                                 $('.top-menu .has ul').hide();
  443.                             };
  444.  
  445.                             if (!$(this).hasClass('active_mobile')) {
  446.                                 e.preventDefault();
  447.                             };
  448.  
  449.                             var $ul = $(this).parent().parent('ul');
  450.  
  451.                             $ul.find('>li > a').removeClass('active').removeClass('active_mobile');
  452.                             $ul.find('>li > ul').hide();
  453.  
  454.                             $(this).addClass('active').addClass('active_mobile');
  455.                             $(this).parent().find('>ul').show();
  456.  
  457.                             if ($(document).outerWidth() > $(window).outerWidth()) {
  458.                                 $(this).parent().find('>ul').addClass('right_level');
  459.                             } else {
  460.                                 $(this).parent().find('>ul').removeClass('right_level');
  461.                             };
  462.                         });
  463.  
  464.                         $(document).on('click', function (e) {
  465.                             if (!$(e.target).closest('.top-menu').length) {
  466.                                 $('.top-menu li a').removeClass('active').removeClass('active_mobile');
  467.                                 $('.top-menu .row-menu-container').hide();
  468.                                 $('.top-menu .has ul').hide();
  469.                             };
  470.                         });
  471.                     };
  472.  
  473.                     if (!isMobile) {
  474.                         $('.top-menu ul').parent().each(function () {
  475.                             var o = $(this);
  476.                             var s = o.find('>ul');
  477.                             var l = o.parents('ul').length;
  478.                             var k = false;
  479.                             o.hover(
  480.                                 function () {
  481.                                     o.find('>a').addClass('active').removeClass('normal');
  482.                                     for (i = $('.top-menu ul').length; i >= 0; i--) {
  483.                                         o.parent().find('>li').not(o).find('ul').eq(i).hide();
  484.                                     }
  485.                                     k = true;
  486.  
  487.                                     s.show();
  488.  
  489.                                     if ($(document).outerWidth() > $(window).outerWidth()) {
  490.                                         o.find('>ul').addClass('right_level');
  491.                                     };
  492.                                 },
  493.                                 function () {
  494.                                     o.find('>a').removeClass('active').addClass('normal');
  495.                                     k = false;
  496.                                     window.setTimeout(function () {
  497.                                         if (!k) {
  498.                                             s.hide()
  499.                                             o.find('>ul').removeClass('right_level');
  500.                                         };
  501.                                     }, 1000);
  502.                                 }
  503.                             );
  504.                         });
  505.                     };
  506.  
  507.                     siteMenu.removeClass('hideOverflow');
  508.  
  509.                 }, 250);
  510.             };
  511.  
  512.             let rowTimeOut;
  513.  
  514.             $(window).on('resize.rowTimeOutResize', function () {
  515.                 if (window.matchMedia("(min-width: 1261px)").matches) {
  516.                     if (rowTimeOut) {
  517.                         clearTimeout(rowTimeOut);
  518.                     };
  519.                     rowTimeOut = setTimeout(function () {
  520.                         if (!$('.top-menu').hasClass('row-menu-init')) {
  521.                             let menuList = $('.top-menu');
  522.                             menuList.rowMenu({
  523.                                 "moreText": menuList.data('site_more_menu'),
  524.                                 "moreWidth": 100
  525.                             });
  526.  
  527.                         };
  528.                     }, 250);
  529.                 };
  530.                 if ($('.row-menu-init').length) {
  531.                     $(window).off('resize.rowTimeOutResize');
  532.                 };
  533.             });
  534.  
  535.         },
  536.         /*Шапка*/
  537.         siteSlider: function () {
  538.             var slider = document.querySelector('.js__main_slider');
  539.  
  540.             if (!!slider) {
  541.                 var sliderAutoplay = +slider.getAttribute('data-autoplay');
  542.  
  543.                 var mslider = tns({
  544.                     loop: true,
  545.                     container: slider,
  546.                     autoHeight: true,
  547.                     slideBy: 1,
  548.                     items: 1,
  549.                     swipeAngle: true,
  550.                     speed: 500,
  551.                     autoplayHoverPause: true,
  552.                     autoplay: sliderAutoplay,
  553.                     autoplayButtonOutput: false,
  554.                     controlsText: shop2_gr.settings.sliderControls,
  555.                     preventActionWhenRunning: false,
  556.                     controls: true,
  557.                     lazyload: true,
  558.                     navPosition: 'bottom',
  559.                     controlsPosition: 'bottom',
  560.                     controlsContainer: document.querySelector('.slider-controls'),
  561.                     navContainer: document.querySelector('.slide-counter__del'),
  562.  
  563.                     responsive: {
  564.                         0: {
  565.                             controls: true,
  566.                             nav: true,
  567.                             gutter: 20
  568.                         }
  569.                     }
  570.                 });
  571.  
  572.                 var info = mslider.getInfo(),
  573.                     current = document.querySelector('.slide-counter__num'),
  574.                     total = document.querySelector('.slide-counter__all');
  575.  
  576.                 current.textContent = mslider.getInfo().displayIndex;
  577.                 total.textContent = info.slideCount;
  578.  
  579.                 mslider.events.on("indexChanged", function () {
  580.                     current.textContent = mslider.getInfo().displayIndex;
  581.                     total.textContent = info.slideCount;
  582.                 });
  583.             };
  584.         },
  585.         /* Слайдер на главной */
  586.         folderPanel: function () {
  587.  
  588.             const btnClose = $('.folde-bl-close');
  589.             const btnOpne = $('.folder-bl-open');
  590.             const folderPanelWrap = $('.folder-panel__wrap');
  591.  
  592.             btnOpne.on('click', function () {
  593.                 folderPanelWrap.addClass('openFolder');
  594.                 setTimeout(() => {
  595.                     folderPanelWrap.addClass('openFolderAndClose')
  596.                 }, 300);
  597.             });
  598.             btnClose.on('click', function (e) {
  599.                 e.stopPropagation();
  600.                 folderPanelWrap.removeClass('openFolder');
  601.                 setTimeout(() => {
  602.                     folderPanelWrap.removeClass('openFolderAndClose')
  603.                 }, 300);
  604.  
  605.                 folderPanel.find('.sublevel.itemFolderOpen').each(function () {
  606.                     $(this)
  607.                         .removeClass('itemFolderOpen')
  608.                 })
  609.             });
  610.  
  611.             folderPanelWrap.on('click', function (e) {
  612.                 if ($(e.target).is('.folder-panel__wrap')) {
  613.                     folderPanelWrap.removeClass('openFolder');
  614.                     setTimeout(() => {
  615.                         folderPanelWrap.removeClass('openFolderAndClose')
  616.                     }, 300);
  617.  
  618.                     folderPanel.find('.sublevel.itemFolderOpen').each(function () {
  619.                         $(this)
  620.                             .removeClass('itemFolderOpen')
  621.                     })
  622.                 }
  623.             })
  624.  
  625.  
  626.  
  627.             const folderPanel = $('.folder-panel');
  628.             if (!folderPanel.length) {
  629.                 console.info("folder-panel yo'q");
  630.                 return;
  631.             }
  632.  
  633.             folderPanel.find('.sublevel>a').on('click', function (e) {
  634.                 e.preventDefault();
  635.  
  636.                 const $item = $(this).closest('.sublevel');
  637.  
  638.                 // Закрываем все активные, кроме текущего
  639.                 folderPanel.find('.sublevel.itemFolderOpen').not($item).each(function () {
  640.                     $(this)
  641.                         .removeClass('itemFolderOpen');
  642.                 });
  643.  
  644.                 // Переключаем текущий элемент
  645.                 if ($item.hasClass('itemFolderOpen')) {
  646.                     $item.removeClass('itemFolderOpen');
  647.                 } else {
  648.                     $item.addClass('itemFolderOpen');
  649.                 }
  650.             });
  651.         },
  652.         footerBlock: function () {
  653.  
  654.         },
  655.         /*Подвал*/
  656.  
  657.         recentBlock: function () {
  658.  
  659.             var sliderAutoplay = $('.recent-block__items').data("autoplay");
  660.             var respSettings = {
  661.                 320: {
  662.                     controls: false,
  663.                     items: 1,
  664.                     gutter: 0
  665.                 },
  666.                 768: {
  667.                     controls: false,
  668.                     items: 2,
  669.                     gutter: 20
  670.                 },
  671.                 1024: {
  672.                     controls: false,
  673.                     items: 2,
  674.                     gutter: 20
  675.                 },
  676.                 1261: {
  677.                     controls: false,
  678.                     items: 3,
  679.                     gutter: 20
  680.                 },
  681.                 1341: {
  682.                     controls: true,
  683.                     items: 3,
  684.                     gutter: 20
  685.                 }
  686.             };
  687.  
  688.             if ($('.recent-block__items').length > 0) {
  689.                 var recentSlider = tns({
  690.                     loop: true,
  691.                     container: '.recent-block__items',
  692.                     slideBy: 1,
  693.                     autoplayHoverPause: true,
  694.                     mode: "carousel",
  695.                     axis: "horizontal",
  696.                     autoplay: sliderAutoplay,
  697.                     autoplayButtonOutput: false,
  698.                     mouseDrag: true,
  699.                     center: false,
  700.                     autoWidth: false,
  701.                     nav: true,
  702.                     navPosition: "bottom",
  703.                     controlsText: shop2_gr.settings.sliderControls,
  704.                     preventActionWhenRunning: true,
  705.                     responsive: respSettings
  706.                 });
  707.             };
  708.  
  709.             shop2_gr.methods.arrowsPosition('.recent-block__items', '.gr-recent-image');
  710.  
  711.         },
  712.         /*Недавно просмотренные товары*/
  713.  
  714.         sortingPanel: function () {
  715.  
  716.             $('.shop-view').on('click', '.shop-view__btn', function () {
  717.                 $(this).parents('.shop-view__inner').toggleClass('active');
  718.             });
  719.  
  720.             $(document).on('click', function (e) {
  721.                 if (!$(e.target).closest('.shop-view .shop-view__btn').length) {
  722.                     $('.shop-view .shop-view__inner').removeClass('active');
  723.                 };
  724.             });
  725.  
  726.             /*$(document).on('click', '.sorting-button', function(){
  727.                 $('.sorting-block').addClass('active');
  728.             });
  729.  
  730.             $(document).on('click', '.sorting-block__title', function(){
  731.                 $('.sorting-block').removeClass('active');
  732.             });*/
  733.  
  734.             $('.sorting-block__body').on('click', function () {
  735.                 $(this).next().stop().slideToggle(250);
  736.                 $(this).parent().toggleClass('active');
  737.             });
  738.  
  739.             shop2_gr.methods.viewLots();
  740.  
  741.         },
  742.         /*Сортировка и виды*/
  743.  
  744.         actionsBlock: function () {
  745.             var actionEventName = 'mouseenter';
  746.             if (isMobile) {
  747.                 actionEventName = 'click';
  748.             };
  749.             $(document).on(actionEventName, '.shop2-product-actions dt:not(.promo-action)', function () {
  750.                 $('.shop2-product-actions dt').removeClass('dt_hover');
  751.                 $('.shop2-product-actions dd').css('left', 'auto');
  752.  
  753.                 if (!isMobile) {
  754.                     $(this).addClass('dt_hover');
  755.                 };
  756.  
  757.                 $(this).next().css('left', $(this).position().left);
  758.                 $(this).next().css('top', $(this).position().top - $(this).next().outerHeight());
  759.  
  760.                 var nextLeft = $(this).next().offset().left;
  761.                 var nextWidth = $(this).next().outerWidth();
  762.                 var offsetSum = nextLeft + nextWidth;
  763.                 var winWidth = $(window).width();
  764.  
  765.                 if ((offsetSum) > winWidth) {
  766.                     $(this).next().css('left', $(this).position().left - (offsetSum - winWidth))
  767.                 }
  768.             });
  769.  
  770.             $(document).on('mouseleave', '.shop2-product-actions dl', function () {
  771.                 $('.shop2-product-actions dt').removeClass('dt_hover');
  772.                 $('.shop2-product-actions dd').css('left', 'auto');
  773.             });
  774.  
  775.             $(document).off('click.getPromoLink').off('click.promoPagelist');
  776.  
  777.             var gr_promo_info = {};
  778.  
  779.             $(document).on('click', '.get-promo-link', function (e) {
  780.                 e.preventDefault();
  781.                 var is_main = $(this).data('is-main'),
  782.                     kind_id = $(this).data('kind-id'),
  783.                     discount_id = $(this).data('discount-id'),
  784.                     page = 0;
  785.  
  786.                 gr_promo_title = $(this).text(),
  787.                     gr_promo_desc = $(this).parents('.promo-action').find('.promo-action__text').html();
  788.  
  789.                 var gr_images_size = $('.product-list').data('images-size');
  790.                 var gr_images_view = $(".product-list").data("images-view");
  791.  
  792.                 var url = '/-/x-api/v1/public/?method=shop2/getPromoProducts' + '&param[kind_id]=' + kind_id + '&param[discount_id]=' + discount_id + '&param[is_main]=' + is_main + '&param[page]=' + page;
  793.  
  794.                 if (gr_images_view) {
  795.                     url += "&gr_images_view=" + gr_images_view;
  796.                 };
  797.  
  798.                 if (gr_images_size) {
  799.                     url += "&gr_images_size=" + gr_images_size;
  800.                 };
  801.  
  802.  
  803.                 $.ajax({
  804.                     url: url,
  805.                     type: 'POST',
  806.                     dataType: 'json',
  807.                     data: {},
  808.                     success: function (res) {
  809.                         shop2.alert(res.result.html, 'Закрыть', 'promo-products-list');
  810.  
  811.                         setTimeout(function () {
  812.                             $('.promo-header__title').html(gr_promo_title);
  813.                             if (!gr_promo_desc) {
  814.                                 $('.promo-header__desc').hide();
  815.                             };
  816.                             $('.promo-header__desc').html(gr_promo_desc);
  817.  
  818.                             if (!$('.promo-products-list .shop-pagelist').length) {
  819.                                 $('.promo-products-list .product-list.list .product-item:last-child').css('border-bottom', 'none');
  820.                             };
  821.  
  822.                             $('.promo-products-list').click().addClass('custom-scroll scroll-width-thin scroll');
  823.                             $('.promo-products-list .product-item').each(function () {
  824.                                 var $flags = $(this).find('.product-flags');
  825.                                 var $flagsContainer = $(this).find('.product-item__bottom-left');
  826.  
  827.                                 $flags.prependTo($flagsContainer);
  828.                             });
  829.  
  830.                             $('.product-list .gr_images_lazy_load').each(function () {
  831.                                 $(this).attr('src', $(this).attr('data-src'));
  832.                             });
  833.  
  834.                             shop2_gr.methods.amountInit();
  835.                         }, 100);
  836.                     }
  837.                 });
  838.  
  839.                 return gr_promo_info = {
  840.                     gr_promo_title: gr_promo_title,
  841.                     gr_promo_desc: gr_promo_desc
  842.                 }
  843.             });
  844.  
  845.             $(document).on('click', '.promo-products-list li', function (e) {
  846.                 e.preventDefault();
  847.  
  848.                 // Получаем строку URL из атрибута href
  849.                 var href = $(this).find('a').attr('href');
  850.  
  851.                 // Создаем объект URL
  852.                 var urlObject = new URL(href, window.location.origin);
  853.  
  854.                 // Получаем значение p из параметров запроса
  855.                 var pValue = urlObject.searchParams.get('p');
  856.  
  857.                 // Если p имеет значение, используем его для обновления значения параметра page
  858.                 if (pValue) {
  859.                     urlObject.searchParams.set('param[page]', pValue);
  860.                 } else {
  861.                     urlObject.searchParams.set('param[page]', 0);
  862.                 }
  863.  
  864.                 // Обновленный URL в виде строки
  865.                 var updatedUrl = urlObject.toString();
  866.  
  867.                 $.ajax({
  868.                     url: updatedUrl,
  869.                     type: 'POST',
  870.                     dataType: 'json',
  871.                     data: {},
  872.                     success: function (res) {
  873.                         shop2.alert(res.result.html, 'Закрыть', 'promo-products-list');
  874.  
  875.                         setTimeout(function () {
  876.                             $('.promo-header__title').html(gr_promo_info.gr_promo_title);
  877.                             if (!gr_promo_info.gr_promo_desc) {
  878.                                 $('.promo-header__desc').hide();
  879.                             };
  880.                             $('.promo-header__desc').html(gr_promo_info.gr_promo_desc);
  881.  
  882.                             $('.promo-products-list').click().addClass('custom-scroll scroll-width-thin scroll');
  883.                             $('.promo-products-list .product-item').each(function () {
  884.                                 var $flags = $(this).find('.product-flags');
  885.                                 var $flagsContainer = $(this).find('.product-item__bottom-left');
  886.  
  887.                                 $flags.prependTo($flagsContainer);
  888.                             });
  889.  
  890.                             $('.product-list .gr_images_lazy_load').each(function () {
  891.                                 $(this).attr('src', $(this).attr('data-src'));
  892.                             });
  893.                             shop2_gr.methods.amountInit();
  894.                         }, 100);
  895.                     }
  896.                 });
  897.             });
  898.  
  899.  
  900.         },
  901.         /*Подарок/Акция*/
  902.  
  903.         filterBlock: function () {
  904.  
  905.             $('.shop2-filter__title').on('click', function () {
  906.                 $(this).toggleClass('active');
  907.                 $(this).next().slideToggle(250);
  908.             });
  909.  
  910.             $('.shop2-filter__item').each(function () {
  911.                 var $this = $(this);
  912.                 var $btn = $this.find('.gr-filter-more__btn');
  913.                 var hideText = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
  914.  
  915.                 $btn.on('click', function () {
  916.                     var $hiddenCkeckbox = $this.find('.shop2-filter__checkbox:hidden');
  917.                     var $hiddenColor = $this.find('.shop2-color-ext-list__item:hidden');
  918.                     var currentText = $btn.data('text');
  919.  
  920.                     $hiddenCkeckbox.addClass('hidden_item');
  921.                     $hiddenColor.addClass('hidden_item');
  922.  
  923.                     if ($this.find('.hidden_item').hasClass('active')) {
  924.                         $btn.find('.gr-filter-more__text').text(currentText);
  925.                         $this.find('.hidden_item').removeClass('active');
  926.                     } else {
  927.                         $btn.find('.gr-filter-more__text').text(hideText);
  928.                         $this.find('.hidden_item').addClass('active');
  929.                     };
  930.                 });
  931.             });
  932.  
  933.             let setResizeWatchFilter = shop2_gr.methods.handleResizeController(
  934.                 '(min-width: 1260px)',
  935.                 () => $('.filter-block').appendTo('.filter-container')
  936.             );
  937.             setResizeWatchFilter();
  938.  
  939.  
  940.             $(document).on('opened', '[data-remodal-id="filter-popup"]', function () {
  941.                 $('.filter-block').appendTo('[data-remodal-id="filter-popup"]');
  942.             });
  943.  
  944.             $(document).on('closed', '[data-remodal-id="filter-popup"]', function () {
  945.                 $('.filter-block').appendTo('.filter-container');
  946.             });
  947.  
  948.         },
  949.         /*Фильтр*/
  950.  
  951.         productsBlock: function () {
  952.  
  953.             $(document).on('click', '.gr-options-more__btn', function () {
  954.                 var $parent = $(this).parents('.gr-product-options');
  955.                 var $params = $parent.find('.gr-options-container');
  956.                 var currentText = $(this).data('text');
  957.                 var hideText = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
  958.  
  959.                 if ($(this).hasClass('active')) {
  960.                     $(this).removeClass('active');
  961.                     $(this).find('ins').text(currentText);
  962.                 } else {
  963.                     $(this).addClass('active');
  964.                     $(this).find('ins').text(hideText);
  965.                 };
  966.  
  967.                 $params.stop().slideToggle(250);
  968.             });
  969.  
  970.             $('.shop2-color-ext-select .shop2-color-ext-options').on('click', function () {
  971.                 if ($(this).closest('.shop2-color-ext-select').hasClass('active')) {
  972.                     $(this).closest('.shop2-color-ext-select').removeClass('active');
  973.                 } else {
  974.                     $(this).closest('.shop2-color-ext-select').addClass('active');
  975.                 }
  976.             });
  977.  
  978.             $('#shop2-color-ext-select').on('click', function () {
  979.                 $('.shop2-color-ext-select').removeClass('active');
  980.             });
  981.  
  982.             $(document).on('click', '.shop2-color-ext-select', function () {
  983.                 if ($(this).parents('.product-item').length > 0) {
  984.                     $('#shop2-color-ext-select').addClass('product_item_color');
  985.                 }
  986.  
  987.                 if ($(this).parents('.shop2-product').length > 0) {
  988.                     $('#shop2-color-ext-select').addClass('shop_product_color');
  989.                 }
  990.             });
  991.  
  992.             $(document).on('click', '#shop2-color-ext-select', function () {
  993.                 $(this).removeClass('product_item_color');
  994.                 $(this).removeClass('shop_product_color');
  995.             });
  996.  
  997.             $(document).on('click', function (e) {
  998.                 if (!$(e.target).closest('#shop2-color-ext-select').length) {
  999.                     $('#shop2-color-ext-select').removeClass('product_item_color');
  1000.                     $('#shop2-color-ext-select').removeClass('shop_product_color');
  1001.                 }
  1002.             });
  1003.  
  1004.         },
  1005.         /*Товар*/
  1006.  
  1007.         cardPage: function () {
  1008.  
  1009.             if ($('.order-info-block').length) {
  1010.                 if (!isMobile) {
  1011.                     $('.order-info-block__title').hover(function () {
  1012.                         $(this).next().show();
  1013.                         $('.order-info-block__popup').removeClass('right_popup');
  1014.  
  1015.                         if ($(document).outerWidth() > $(window).outerWidth()) {
  1016.                             $(this).next().addClass('right_popup');
  1017.                         };
  1018.                     }, function (e) {
  1019.                         $(this).next().hide();
  1020.                         $('.order-info-block__popup').removeClass('right_popup');
  1021.                     });
  1022.                 } else {
  1023.                     $('.order-info-block__title').on('click', function () {
  1024.                         $('.order-info-block__popup').hide();
  1025.                         $('.order-info-block__popup').removeClass('right_popup');
  1026.                         $(this).next().show();
  1027.  
  1028.                         if ($(document).outerWidth() > $(window).outerWidth()) {
  1029.                             $(this).next().addClass('right_popup');
  1030.                         };
  1031.                     });
  1032.  
  1033.                     $('.order-info-block__close').on('click', function () {
  1034.                         $('.order-info-block__popup').hide();
  1035.                         $('.order-info-block__popup').removeClass('right_popup');
  1036.                     });
  1037.                 };
  1038.             };
  1039.  
  1040.             var $cardHiddenOptions = $('.card-page .shop2-product .gr-product-options .option-item:hidden');
  1041.  
  1042.             if ($cardHiddenOptions.length > 0) {
  1043.                 $('.shop2-product .gr-product-options-more').addClass('show_more_btn');
  1044.             };
  1045.  
  1046.             $(document).on('click', '.card-page .shop2-product .gr-product-options-more__btn', function () {
  1047.                 var currentText = $(this).data('text');
  1048.                 var hideText = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
  1049.  
  1050.                 if ($(this).hasClass('active')) {
  1051.                     $(this).removeClass('active');
  1052.                     $(this).find('ins').text(currentText);
  1053.                 } else {
  1054.                     $(this).addClass('active');
  1055.                     $(this).find('ins').text(hideText);
  1056.                 };
  1057.  
  1058.                 $cardHiddenOptions.stop().slideToggle(250);
  1059.             });
  1060.  
  1061.  
  1062.             if ($('.card-slider__thumbs-slider').length > 0) {
  1063.                 var vslider = tns({
  1064.                     container: '.card-slider__items-slider',
  1065.                     slideBy: 1,
  1066.                     mode: 'gallery',
  1067.                     axis: 'horizontal',
  1068.                     autoplay: false,
  1069.                     mouseDrag: true,
  1070.                     center: true,
  1071.                     autoWidth: false,
  1072.                     loop: false,
  1073.                     rewind: true,
  1074.                     preventActionWhenRunning: false,
  1075.                     nav: true,
  1076.                     lazyload: true,
  1077.                     swipeAngle: 50,
  1078.                     navPosition: 'bottom',
  1079.                     controlsText: shop2_gr.settings.sliderControls,
  1080.                     responsive: {
  1081.                         320: {
  1082.                             controls: false,
  1083.                             nav: true
  1084.                         },
  1085.                         768: {
  1086.                             controls: true,
  1087.                             nav: true
  1088.                         }
  1089.                     }
  1090.                 });
  1091.  
  1092.                 var small_slider = tns({
  1093.                     container: '.card-slider__thumbs-slider',
  1094.                     loop: false,
  1095.                     gutter: 10,
  1096.                     center: false,
  1097.                     mouseDrag: true,
  1098.                     nav: false,
  1099.                     controls: false,
  1100.                     navPosition: 'bottom',
  1101.                     preventActionWhenRunning: false,
  1102.                     axis: 'horizontal',
  1103.                     responsive: {
  1104.                         320: {
  1105.                             items: 3
  1106.                         },
  1107.                         640: {
  1108.                             items: 3
  1109.                         },
  1110.                         768: {
  1111.                             items: 3
  1112.                         },
  1113.                         1024: {
  1114.                             items: 4
  1115.                         },
  1116.                         1261: {
  1117.                             items: 4
  1118.                         },
  1119.                         1340: {
  1120.                             items: 4
  1121.                         }
  1122.                     }
  1123.                 });
  1124.  
  1125.                 var navIndex = $('.card-slider__items .tns-nav-active').index();
  1126.                 $('.card-slider__thumbs-slider .card-slider__thumb').removeClass('tns-nav-active');
  1127.                 $('.card-slider__thumbs-slider .card-slider__thumb').eq(navIndex).addClass('tns-nav-active');
  1128.  
  1129.                 vslider.events.on('indexChanged', function () {
  1130.                     var navIndex = $('.card-slider__items .tns-nav-active').index();
  1131.                     $('.card-slider__thumbs-slider .card-slider__thumb').removeClass('tns-nav-active');
  1132.                     $('.card-slider__thumbs-slider .card-slider__thumb').eq(navIndex).addClass('tns-nav-active');
  1133.  
  1134.                     /*if (vslider.getInfo().index>vslider.getInfo().indexCached) {
  1135.                         //console.log('right')
  1136.                     } else {
  1137.                         //console.log('left')
  1138.                     }*/
  1139.                 });
  1140.  
  1141.                 $(document).on('click', '.card-slider__thumbs-slider .card-slider__thumb', function () {
  1142.                     var thisIndex = $(this).index();
  1143.                     $('.card-slider__items .tns-nav button').eq(thisIndex).click();
  1144.                 });
  1145.  
  1146.                 vslider.events.on('indexChanged', function () {
  1147.                     small_slider.goTo(vslider.getInfo().index);
  1148.                 });
  1149.             };
  1150.  
  1151.             if (!isMobile && jQuery().zoom) {
  1152.                 $('.gr-image-zoom').zoom({
  1153.                     magnify: 1,
  1154.                     duration: 10,
  1155.                     onZoomIn: function () {
  1156.                         $(this).parent().addClass('hide_small_pic');
  1157.                     },
  1158.                     onZoomOut: function () {
  1159.                         $(this).parent().removeClass('hide_small_pic');
  1160.                     },
  1161.                     callback: function () {
  1162.                         var $zoomImg = $(this);
  1163.                         var containerHeight = $zoomImg.parent().outerHeight();
  1164.                         var containerWidth = $zoomImg.parent().outerWidth();
  1165.                         var zoomImgHeight = Math.floor($zoomImg.height());
  1166.                         var zoomImgWidth = Math.floor($zoomImg.width());
  1167.                         var floatHeight = Math.floor(20 * zoomImgHeight / 100);
  1168.                         var floatWidth = Math.floor(20 * zoomImgWidth / 100);
  1169.                         var prevWidth = Math.floor($(this).prev().outerWidth());
  1170.                         var prevHeight = Math.floor($(this).prev().outerHeight());
  1171.  
  1172.                         var zoomFloatHeight = zoomImgHeight + floatHeight;
  1173.                         var zoomFloatWidth = zoomImgWidth + floatWidth;
  1174.                         var finalHeight = prevHeight + floatHeight;
  1175.                         var finalWidth = prevWidth + floatWidth;
  1176.  
  1177.                         if (zoomFloatHeight <= prevHeight - floatHeight || zoomFloatWidth <= prevWidth - floatWidth) {
  1178.                             $(this).parent().addClass('hide_big_pic');
  1179.                         };
  1180.  
  1181.                         if (zoomImgHeight <= prevHeight || zoomImgWidth <= prevWidth) {
  1182.                             $zoomImg.css({
  1183.                                 'width': finalWidth,
  1184.                                 'height': finalHeight
  1185.                             });
  1186.                         }
  1187.  
  1188.                         if (finalHeight <= containerHeight && finalWidth <= containerWidth) {
  1189.                             $(this).parent().addClass('hide_zoom_pic');
  1190.                         }
  1191.                     }
  1192.                 });
  1193.             };
  1194.  
  1195.  
  1196.             if (shop2.mode == 'product') {
  1197.                 shop2_gr.methods.grLazyFunc({
  1198.                     selector: '.shop-product-share'
  1199.                 }, function () {
  1200.                     var url_1 = 'https://yastatic.net/es5-shims/0.0.2/es5-shims.min.js';
  1201.                     var url_2 = 'https://yastatic.net/share2/share.js';
  1202.  
  1203.                     $('.shop-product-share').append('<script src="' + url_1 + '"></script><script src="' + url_2 + '"></script>');
  1204.                     $('#product-yashare-noscript').remove();
  1205.                 });
  1206.             };
  1207.  
  1208.         },
  1209.         /*Слайдер в карточке товара*/
  1210.  
  1211.         responsiveTabs: function () {
  1212.             if ($('#product-tabs').length) {
  1213.                 $('.shop-product-data__nav li, .r-tabs-accordion-title').on('click', function (e) {
  1214.                     e.preventDefault();
  1215.                     let href = $(this).find('a').attr('href');
  1216.                     let $descArea = $(href);
  1217.  
  1218.                     localStorage.setItem('gr_tab_href', href);
  1219.  
  1220.                     if ($descArea.is(':hidden')) {
  1221.                         $('.shop-product-data__nav li, .r-tabs-accordion-title').removeClass('r-tabs-state-active');
  1222.                         $('.shop-product-data__desc .desc-area').stop().slideUp(300);
  1223.                     };
  1224.  
  1225.                     if (window.matchMedia("(min-width: 768px)").matches) {
  1226.                         $('#product-tabs a[href="' + href + '"]').parent().addClass('r-tabs-state-active');
  1227.                         $descArea.stop().slideDown(300);
  1228.                     } else {
  1229.                         $('#product-tabs a[href="' + href + '"]').parent().toggleClass('r-tabs-state-active');
  1230.                         $descArea.stop().slideToggle(300);
  1231.                         if ($('.r-tabs-accordion-title.r-tabs-state-active').length) {
  1232.                             setTimeout(function () {
  1233.                                 $('html, body').stop().animate({
  1234.                                     scrollTop: $('.r-tabs-accordion-title.r-tabs-state-active').offset().top - 70
  1235.                                 }, 500);
  1236.                             }, 301);
  1237.                         };
  1238.                     };
  1239.                 });
  1240.             };
  1241.  
  1242.         },
  1243.         /*Табы*/
  1244.  
  1245.         commentsBlock: function () {
  1246.             $('.comments-form__btn').on('click', function () {
  1247.                 $(this).next().slideToggle(200);
  1248.             });
  1249.         },
  1250.         /*Комментарии*/
  1251.  
  1252.         amountBlock: function () {
  1253.             var lazyAmount = false;
  1254.  
  1255.             shop2_gr.methods.grLazyFunc({
  1256.                 selector: '.shop2-product-amount'
  1257.             }, function () {
  1258.                 if (!lazyAmount) {
  1259.                     shop2_gr.methods.amountInit();
  1260.                 };
  1261.                 return lazyAmount = true;
  1262.             });
  1263.         },
  1264.         /*Количество*/
  1265.  
  1266.         buyOneClick: function () {
  1267.  
  1268.             $(document).on('click', '.buy-one-click:not(.preorder-btn-js):not(.buy-one-click-js)', function (e) {
  1269.                 var productName = $(this).data('product-name');
  1270.                 var productLink = $(this).data('product-link');
  1271.                 var $this = $(this);
  1272.  
  1273.                 if (shop2.mode == 'product' && $(this).parents('.kind-item').length < 1) {
  1274.                     var productAmount = $(this).parents('.shop2-product').find('.shop2-product-amount input').val();
  1275.                 } else if ($('.product-quick-view.remodal-is-opened').length > 0 && $(this).parents('.kind-item').length < 1) {
  1276.                     var productAmount = $(this).parents('.shop2-product').find('.shop2-product-amount input').val();
  1277.                 } else if ($(this).parents('.kind-item').length > 0) {
  1278.                     var productAmount = $(this).parents('.kind-item').find('.shop2-product-amount input').val();
  1279.                 } else {
  1280.                     var productAmount = $(this).parents('.shop2-product-item').find('.shop2-product-amount input').val();
  1281.                 }
  1282.  
  1283.                 $.ajax({
  1284.                     url: $(this).data('api-url'),
  1285.                     dataType: 'json',
  1286.                     success: function (response) {
  1287.                         if (!response.result.error) {
  1288.  
  1289.                             $('.remodal[data-remodal-id="buy-one-click"] .tpl-anketa').remove();
  1290.                             $(response.result.html).appendTo('.remodal[data-remodal-id="buy-one-click"]');
  1291.                             if ($this.hasClass('product_info_form')) {
  1292.                                 var nameValue = productName;
  1293.                             } else {
  1294.                                 var nameValue = productName + ', количество - ' + productAmount;
  1295.                             }
  1296.  
  1297.                             $('.remodal[data-remodal-id="buy-one-click"] .tpl-field__product-link input').val(productLink);
  1298.                             $('.remodal[data-remodal-id="buy-one-click"] .tpl-field__product-name input').val(nameValue);
  1299.  
  1300.                             s3From.initForms($('.remodal[data-remodal-id="buy-one-click"]'), function () {
  1301.                                 $('.remodal[data-remodal-id="buy-one-click"] .tpl-field__product-link input').val(productLink);
  1302.                                 $('.remodal[data-remodal-id="buy-one-click"] .tpl-field__product-name input').val(nameValue);
  1303.                             });
  1304.                             grFormDatePicker.init();
  1305.  
  1306.                         }
  1307.                     }
  1308.                 });
  1309.             });
  1310.  
  1311.         },
  1312.         /*Купить в 1 клик*/
  1313.  
  1314.         cartPreview: function () {
  1315.  
  1316.             $(document).on('click', '.gr_order_one_page', function (e) {
  1317.                 eraseCookie('gr_delivery_scroll');
  1318.                 createCookie('gr_delivery_scroll', 1, 30);
  1319.             });
  1320.  
  1321.             if (readCookie('gr_delivery_scroll') == '1') {
  1322.                 eraseCookie('gr_delivery_scroll');
  1323.  
  1324.                 setTimeout(function () {
  1325.                     $('html, body').animate({
  1326.                         scrollTop: $('.shop2-delivery').offset().top - 30
  1327.                     }, 800);
  1328.                 }, 1000);
  1329.             };
  1330.  
  1331.         },
  1332.         /*Скролл на странице корзины до доставки*/
  1333.  
  1334.         cartPage: function () {
  1335.  
  1336.             $(document).on('click', '.cart-params__more-btn', function () {
  1337.                 var $parent = $(this).parents('.cart-params');
  1338.                 var $params = $parent.find('.cart-params__body');
  1339.                 var currentText = $(this).data('text');
  1340.                 var hideText = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
  1341.  
  1342.                 if ($(this).hasClass('active')) {
  1343.                     $(this).removeClass('active');
  1344.                     $(this).find('ins').text(currentText);
  1345.                 } else {
  1346.                     $(this).addClass('active');
  1347.                     $(this).find('ins').text(hideText);
  1348.                 };
  1349.  
  1350.                 $params.stop().slideToggle(250);
  1351.             });
  1352.  
  1353.             $(document).on('opening', '.cart-remodal', function () {
  1354.                 $('.cart-remodal__body').prependTo('.cart-remodal__body_wrap');
  1355.             });
  1356.             if (shop2.mode == 'cart') {
  1357.                 $('.shop2-warning').prependTo('.cart-page__left');
  1358.             };
  1359.  
  1360.             /*Автопересчет в корзине*/
  1361.             if (shop2.mode == 'cart') {
  1362.                 var cartURL = shop2.uri + "/cart",
  1363.                     hash = {
  1364.                         del: shop2.apiHash.cartRemoveItem,
  1365.                         up: shop2.apiHash.cartUpdate
  1366.                     },
  1367.                     ajax, $idd,
  1368.                     shopCartDiv = $('.cart-page'),
  1369.                     cartPreloader = '<div class="gr-preloader-holder"><div class="gr-preloader"><svg xmlns="http://www.w3.org/2000/svg" width="34" height="26" viewBox="0 0 120 30" fill="#fff"><script xmlns=""></script> <circle cx="15" cy="15" r="15"> <animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite"></animate> <animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite"></animate> </circle> <circle cx="60" cy="15" r="9" fill-opacity="0.3"> <animate attributeName="r" from="9" to="9" begin="0s" dur="0.8s" values="9;15;9" calcMode="linear" repeatCount="indefinite"></animate> <animate attributeName="fill-opacity" from="0.5" to="0.5" begin="0s" dur="0.8s" values=".5;1;.5" calcMode="linear" repeatCount="indefinite"></animate> </circle> <circle cx="105" cy="15" r="15"> <animate attributeName="r" from="15" to="15" begin="0s" dur="0.8s" values="15;9;15" calcMode="linear" repeatCount="indefinite"></animate> <animate attributeName="fill-opacity" from="1" to="1" begin="0s" dur="0.8s" values="1;.5;1" calcMode="linear" repeatCount="indefinite"></animate> </circle></svg></div></div>';
  1370.  
  1371.                 $('.shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').append(cartPreloader);
  1372.  
  1373.                 shop2.on("afterCartAddItem", function (d, status) {
  1374.                     if (!d.errstr.length) {
  1375.                         getCart();
  1376.                     };
  1377.                 });
  1378.  
  1379.                 $(document).on('click', '#shop2-color-ext-select li.param-value:not(.shop2-color-ext-selected)', function () {
  1380.                     clearTimeout($idd);
  1381.                     $idd = setTimeout(updateForm, 500);
  1382.                     $('.shop2-cart-update').hide();
  1383.                 });
  1384.  
  1385.                 function getCart(callback) {
  1386.                     if (ajax) ajax.abort();
  1387.                     ajax = $.ajax({
  1388.                         url: cartURL + "?cart_only=1",
  1389.                         async: true,
  1390.                         success: function (data) {
  1391.                             var $shopWarning = $(data).filter('.shop2-warning').clone();
  1392.  
  1393.                             $('.cart-page__top').html($(data).find('.cart-page__top').html());
  1394.                             $('.cart-page__bottom').html($(data).find('.cart-page__bottom').html());
  1395.  
  1396.                             $shopWarning.prependTo('.cart-page__left');
  1397.                             initCart(shopCartDiv);
  1398.  
  1399.                             $('.shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').removeClass('gr-preloader-active');
  1400.  
  1401.                             if (typeof callback === 'function') {
  1402.                                 setTimeout(function () {
  1403.                                     callback();
  1404.                                 }, 100);
  1405.                             }
  1406.  
  1407.                             setTimeout(function () {
  1408.                                 shop2.queue.edost2();
  1409.                                 shop2.queue.bonus();
  1410.                                 shop2.queue.orderGetPayments();
  1411.  
  1412.                                 initDelivery();
  1413.  
  1414.                                 $('.shop2-order-form input[type="checkbox"]:not(.gr-fixed-checkbox), .shop2-order-form input[type="radio"], .tpl-field-reg input, .gr-authorization-checkbox, .shop2-order-options.shop2-payment-options .payment_methods-column input[type="radio"], #orderForm input[name="personal_data"]').mgStyler();
  1415.                             }, 100);
  1416.                         }
  1417.                     });
  1418.                 };
  1419.  
  1420.                 function initDelivery() {
  1421.                     if ($('.shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').find('.gr-preloader-holder').length < 1) {
  1422.                         $('.shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').append(cartPreloader);
  1423.                     };
  1424.  
  1425.                     shop2.queue.delivery();
  1426.                 };
  1427.  
  1428.                 function initCart($div) {
  1429.                     var $form = $div.find("#shop2-cart"),
  1430.                         $inp = $form.find("input:text"),
  1431.                         $item = $form.find(".cart-products__item"),
  1432.                         $recalc = $("a.shop2-cart-update"),
  1433.                         $minus = $form.find(".amount-minus"),
  1434.                         $plus = $form.find(".amount-plus");
  1435.  
  1436.                     if (!$form.length) return;
  1437.  
  1438.                     shop2_gr.methods.amountInit();
  1439.  
  1440.                     if (shop2.mode == 'cart') {
  1441.                         $('.shop2-warning').prependTo('.cart-page__left');
  1442.                     };
  1443.  
  1444.                     $('.cart-total-checkout, .cart-total-order-checkout, .cart-registration-btn').append(cartPreloader);
  1445.  
  1446.                     $('[data-remodal-id="cart-auth-remodal"]').remodal({
  1447.                         hashTracking: false
  1448.                     });
  1449.  
  1450.                     $('[data-remodal-id="coupon-remodal"]').remodal({
  1451.                         hashTracking: false
  1452.                     });
  1453.  
  1454.                     $('#shop2-cart .cart-delete a').off('click');
  1455.  
  1456.                     $item.each(function () {
  1457.                         var $del = $(this).find(".cart-delete a");
  1458.                         var $input = $(this).find(".shop2-product-amount input");
  1459.                         var $button = $(this).find(".shop2-product-amount button");
  1460.                         var $select = $(this).find("select.param-value");
  1461.  
  1462.  
  1463.                         $select.on('change', function () {
  1464.                             clearTimeout($idd);
  1465.                             $idd = setTimeout(updateForm, 500);
  1466.                             $('.shop2-cart-update').hide();
  1467.                         });
  1468.  
  1469.                         $input.on('change', function () {
  1470.                             clearTimeout($idd);
  1471.                             $idd = setTimeout(updateForm, 1000);
  1472.                             $('.shop2-cart-update').hide();
  1473.  
  1474.                             $('.cart-total-checkout, .cart-total-order-checkout, .cart-registration-btn, .shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').addClass('gr-preloader-active');
  1475.                         });
  1476.  
  1477.                         $button.on('click', function () {
  1478.                             clearTimeout($idd);
  1479.                             $idd = setTimeout(updateForm, 1000);
  1480.                             $('.shop2-cart-update').hide();
  1481.  
  1482.                             $('.cart-total-checkout, .cart-total-order-checkout, .cart-registration-btn, .shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').addClass('gr-preloader-active');
  1483.                         });
  1484.  
  1485.                         // Обновленное API
  1486.                         $del.on("click", function (e) {
  1487.  
  1488.  
  1489.                             var $this = $(this),
  1490.                                 $cartItem = $this.closest('.cart-products__item'),
  1491.                                 cartItemPos = $cartItem.data('position'),
  1492.                                 kind_id = $this.data('id'),
  1493.                                 params = {};
  1494.  
  1495.                             e.preventDefault();
  1496.  
  1497.                             if (typeof kind_id !== 'number') {
  1498.                                 // Попытаемся найти первый ключ с помощью регулярного выражения
  1499.                                 var matches = kind_id.match(/^\{'(\d+)':\{/);
  1500.                                 var firstKey = matches[1];
  1501.  
  1502.                                 // Продолжаем работать с оставшейся частью строки, чтобы вытащить остальные свойства.
  1503.                                 var params = {};
  1504.                                 // Удаляем первый ключ из строки
  1505.                                 var paramsStr = kind_id.match(/\{(.+?)\}\}$/)[1];
  1506.                                 // Извлекаем пары ключ-значение
  1507.                                 var re = /'([^']+?)':'([^']*)'/g;
  1508.                                 var match;
  1509.                                 while ((match = re.exec(paramsStr)) !== null) {
  1510.                                     params[match[1]] = match[2];
  1511.                                 }
  1512.  
  1513.                                 kind_id = firstKey;
  1514.                             }
  1515.  
  1516.                             $('.cart-total-checkout, .cart-total-order-checkout, .cart-registration-btn, .shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').addClass('gr-preloader-active');
  1517.  
  1518.                             kind_id = kind_id.toString().replace(/\"/g, '\\"').replace(/\'/g, '"');
  1519.                             kind_id = $.parseJSON(kind_id);
  1520.  
  1521.                             shop2.trigger('beforeCartRemoveItem');
  1522.  
  1523.                             $.getJSON(
  1524.                                 '/-/x-api/v1/public/?method=cart/removeItem', {
  1525.                                     param: {
  1526.                                         kind_id: kind_id,
  1527.                                         position: cartItemPos,
  1528.                                         params: params,
  1529.                                     }
  1530.                                 },
  1531.                                 function (d, status) {
  1532.                                     console.log(d);
  1533.                                     sessionStorage.setItem('cart-reload', 1);
  1534.                                     getCart();
  1535.                                     setTimeout(function () {
  1536.                                         $('.gr-cart-total-amount').text($('#shop2-cart').data('cart-amount') || '0');
  1537.                                     }, 1100);
  1538.  
  1539.                                     if (d.result.data.cart.length == 0) {
  1540.                                         document.location = shop2.uri + "?mode=cart&action=cleanup";
  1541.                                     };
  1542.  
  1543.  
  1544.                                     /*shop2.fire('afterCartRemoveItem', func, d, status);
  1545.                                     shop2.trigger('afterCartRemoveItem', d, status);*/
  1546.                                 }
  1547.                             );
  1548.  
  1549.                             return false;
  1550.                         });
  1551.  
  1552.                     });
  1553.  
  1554.                     $recalc.on("click", function (e) {
  1555.                         e.preventDefault();
  1556.                         updateForm();
  1557.                         return false;
  1558.                     });
  1559.  
  1560.  
  1561.                     shop2.on('afterCartAddCoupon, afterCartRemoveCoupon', function () {
  1562.                         document.location.reload();
  1563.                     });
  1564.  
  1565.                     $('.coupon-btn').on('click', function (e) {
  1566.                         var coupon = $('#coupon'),
  1567.                             code = coupon.val();
  1568.  
  1569.                         e.preventDefault();
  1570.  
  1571.                         if (code) {
  1572.                             shop2.cart.addCoupon(code);
  1573.                         }
  1574.                     });
  1575.  
  1576.  
  1577.                     $('.coupon-delete').on('click', function (e) {
  1578.                         var $this = $(this),
  1579.                             code = $this.data('code');
  1580.  
  1581.                         e.preventDefault();
  1582.  
  1583.                         if (code) {
  1584.                             shop2.cart.removeCoupon(code);
  1585.                         }
  1586.                     });
  1587.                 };
  1588.  
  1589.                 // Обновленное API
  1590.                 function updateForm() {
  1591.                     var data = $("#shop2-cart").serialize();
  1592.  
  1593.                     shop2.trigger('beforeCartUpdate');
  1594.  
  1595.                     $.ajax({
  1596.                         type: "POST",
  1597.                         url: '/-/x-api/v1/public/?method=cart/update',
  1598.                         data,
  1599.                         async: true,
  1600.                         success: function (d, status) {
  1601.                             sessionStorage.setItem('cart-reload', 1);
  1602.                             getCart(function () {
  1603.                                 $('.gr-cart-total-amount').text($('#shop2-cart').data('cart-amount') || '0');
  1604.                                 $('.gr-cart-total-sum ins').text($('.last_item .cart-total__body').data('total-price'));
  1605.                             });
  1606.                             shop2.trigger('afterCartUpdated');
  1607.                             initDelivery();
  1608.                         }
  1609.                     });
  1610.  
  1611.                     return false;
  1612.                 };
  1613.  
  1614.                 initCart(shopCartDiv);
  1615.             };
  1616.             /*Автопересчет в корзине*/
  1617.  
  1618.             $('.cart-products__item').each(function () {
  1619.                 if ($(this).find('.amount-min').length) {
  1620.                     $(this).find('.cart-sum').css('margin-top', $(this).find('.amount-min').outerHeight(true))
  1621.                 };
  1622.             });
  1623.  
  1624.             var cart_amount_min_timeout;
  1625.  
  1626.             $(window).on('resize', function () {
  1627.                 if (cart_amount_min_timeout) {
  1628.                     clearTimeout(cart_amount_min_timeout);
  1629.                 };
  1630.  
  1631.                 cart_amount_min_timeout = setTimeout(function () {
  1632.                     $('.cart-products__item').each(function () {
  1633.                         if ($(this).find('.amount-min').length) {
  1634.                             $(this).find('.cart-sum').css('margin-top', $(this).find('.amount-min').outerHeight(true))
  1635.                         };
  1636.                     });
  1637.                 }, 50);
  1638.             });
  1639.  
  1640.         },
  1641.         /*Корзина*/
  1642.  
  1643.         lightGallery: function () {
  1644.             if ($('.card-slider__items').length) {
  1645.                 $('.card-slider__items').lightGallery({
  1646.                     thumbnail: false,
  1647.                     download: false,
  1648.                     loop: false,
  1649.                     counter: false,
  1650.                     getCaptionFromTitleOrAlt: true,
  1651.                     selector: '.card-slider__image a'
  1652.                 });
  1653.             };
  1654.  
  1655.             if ($('.gr_cart_param_img').length) {
  1656.                 $('.gr_cart_param_img').lightGallery({
  1657.                     thumbnail: false,
  1658.                     download: false,
  1659.                     loop: false,
  1660.                     counter: false,
  1661.                     getCaptionFromTitleOrAlt: true,
  1662.                     selector: 'a'
  1663.                 });
  1664.             };
  1665.  
  1666.         },
  1667.         /*Галерея*/
  1668.         toolTips: function () {
  1669.             if (!isMobile) {
  1670.                 $('.shop-view .shop-view__item.thumbs').elemToolTip({
  1671.                     position: 'top',
  1672.                     text: 'Витрина',
  1673.                     margin: 12
  1674.                 });
  1675.  
  1676.                 $('.shop-view .shop-view__item.simple').elemToolTip({
  1677.                     position: 'top',
  1678.                     text: 'Простой',
  1679.                     margin: 12
  1680.                 });
  1681.  
  1682.                 $('.shop-view .shop-view__item.pricelist').elemToolTip({
  1683.                     position: 'top',
  1684.                     text: 'Прайс-лист',
  1685.                     margin: 12
  1686.                 });
  1687.  
  1688.                 $('.quick-view-trigger').elemToolTip({
  1689.                     position: 'top',
  1690.                     text: 'Быстрый просмотр',
  1691.                     margin: 12
  1692.                 });
  1693.             };
  1694.         },
  1695.         /*Тултипы*/
  1696.         alignElements: function () {
  1697.             window.addEventListener('orientationchange', function () {
  1698.                 setTimeout(function () {
  1699.                     $.fn.matchHeight._update();
  1700.                 }, 300);
  1701.             }, false);
  1702.  
  1703.             var lazyFuncTime, lazyFuncScroll = false;
  1704.  
  1705.             if ($(window).scrollTop() > 0) {
  1706.                 if (lazyFuncTime) {
  1707.                     clearTimeout(lazyFuncTime);
  1708.                 };
  1709.  
  1710.                 lazyFuncTime = setTimeout(function () {
  1711.                     if (!lazyFuncScroll) {
  1712.                         shop2_gr.methods.grLazyFunc({
  1713.                             selector: '.product-list.thumbs'
  1714.                         }, function () {
  1715.                             if (!$('.main-blocks').length) {
  1716.                                 $('.product-list.thumbs .product-price').matchHeight('remove');
  1717.                                 $('.product-list.thumbs .product-price').matchHeight();
  1718.                             };
  1719.                         });
  1720.                     };
  1721.  
  1722.                     return lazyFuncScroll = true;
  1723.                 }, 50);
  1724.             };
  1725.  
  1726.             $(window).on('scroll', function () {
  1727.                 if (lazyFuncTime) {
  1728.                     clearTimeout(lazyFuncTime);
  1729.                 };
  1730.  
  1731.                 lazyFuncTime = setTimeout(function () {
  1732.                     if (!lazyFuncScroll) {
  1733.                         shop2_gr.methods.grLazyFunc({
  1734.                             selector: '.product-list.thumbs'
  1735.                         }, function () {
  1736.                             if (!$('.main-blocks').length) {
  1737.                                 $('.product-list.thumbs .product-price').matchHeight('remove');
  1738.                                 $('.product-list.thumbs .product-price').matchHeight();
  1739.                             };
  1740.                         });
  1741.                     };
  1742.  
  1743.                     return lazyFuncScroll = true;
  1744.                 }, 50);
  1745.  
  1746.                 return lazyFuncScroll;
  1747.             });
  1748.  
  1749.  
  1750.             shop2_gr.methods.grLazyFunc({
  1751.                 selector: '.mods_block'
  1752.             }, function () {
  1753.                 $('.mods_block .kinds-block__items .kind-item__top').matchHeight();
  1754.                 $('.mods_block .kinds-block__items .kind-additional').matchHeight();
  1755.                 $('.mods_block .kinds-block__items .kind-price').matchHeight();
  1756.             });
  1757.         },
  1758.         /*Выравнивание блоков по высоте*/
  1759.         contactsPopup: function () {
  1760.             $(document).on('opening', '.remodal_contacts', function () {
  1761.                 $('.contacts-container-inner').prependTo('.contacts-popup-wrap');
  1762.             });
  1763.  
  1764.             $(document).on('closing', '.remodal_contacts', function () {
  1765.                 $('.contacts-container-inner').prependTo('.contacts-container');
  1766.             });
  1767.         },
  1768.         loginBlock: function () {
  1769.             $(document).on('opening', '.remodal_login', function () {
  1770.                 $('.login-container-inner').prependTo('.login-popup-wrap');
  1771.             });
  1772.  
  1773.             $(document).on('closing', '.remodal_login', function () {
  1774.                 $('.login-container-inner').prependTo('.login-container');
  1775.             });
  1776.         },
  1777.         btnUp: function () {
  1778.             $(window).scroll(function () {
  1779.                 if ($(document).scrollTop() > $(window).height()) {
  1780.                     $('.up-button').addClass('active')
  1781.                 } else {
  1782.                     $('.up-button').removeClass('active');
  1783.                 }
  1784.             });
  1785.  
  1786.             $('.up-button').on('click', function () {
  1787.                 $('html, body').animate({
  1788.                     scrollTop: 0
  1789.                 }, 1000);
  1790.             });
  1791.         },
  1792.         searchMain: function () {
  1793.             var $searchHiddenItem = $('.search__block__wrapper .search-form .search-rows__row:hidden').addClass('hidden-item');
  1794.             var $searchBtn = $('.search-rows__button-more');
  1795.             var $searchBtnParent = $searchBtn.parent('.search-rows__buttons-more');
  1796.  
  1797.             if ($searchHiddenItem.length) {
  1798.                 $searchBtnParent.show();
  1799.             } else {
  1800.                 $searchBtnParent.hide();
  1801.             };
  1802.  
  1803.             /*Клик на кнопку "еще"*/
  1804.             $searchBtn.on('click', function (e) {
  1805.                 e.stopPropagation();
  1806.  
  1807.                 var currentText = $(this).data('text');
  1808.                 var hideText = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
  1809.  
  1810.                 if ($searchBtnParent.hasClass('opened')) {
  1811.                     $searchBtnParent.removeClass('opened');
  1812.                     $(this).find('ins').text(currentText);
  1813.                     $(this).parents('.search-rows__body').removeClass('opened');
  1814.                     $('.search__block__wrapper .search-form .search-rows__row.hidden-item').removeClass('active');
  1815.  
  1816.                     $('.block-search').toggleClass('active');
  1817.                 } else {
  1818.                     $searchBtnParent.addClass('opened');
  1819.                     $(this).find('ins').text(hideText);
  1820.                     $(this).parents('.search-rows__body').addClass('opened');
  1821.                     $('.search__block__wrapper .search-form .search-rows__row.hidden-item').addClass('active');
  1822.                     $('.block-search').toggleClass('active');
  1823.                 };
  1824.             });
  1825.             $(document).on('click', function (e) {
  1826.                 var currentText = $searchBtn.data('text');
  1827.                 var hideText = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
  1828.  
  1829.                 if (!$(e.target).closest('.search-rows__folders, .search-rows__body').length) {
  1830.                     $searchBtnParent.removeClass('opened');
  1831.                     $searchBtn.find('ins').text(currentText);
  1832.                     $searchBtn.parents('.search-rows__body').removeClass('opened');
  1833.                     $('.search__block__wrapper .search-form .search-rows__row.hidden-item').removeClass('active');
  1834.                 };
  1835.             });
  1836.             /*Клик на кнопку "еще"*/
  1837.  
  1838.             /*Перенос глобальных полей*/
  1839.             var globalHtml = $('.search__block__inner #shop2_search_global_fields').find('.search-rows__row').addClass('global_fields_moved');
  1840.             $('.search__block__inner .search-form .search-rows__items').append(globalHtml);
  1841.             /*Перенос глобальных полей*/
  1842.  
  1843.             /*Перенос пользовательских полей*/
  1844.             function searchItemsMove() {
  1845.  
  1846.                 var customHtml = $('#shop2_search_custom_fields').find('.search-rows__row').addClass('moved');
  1847.                 $('.search__block__wrapper .search-form .search-rows__row:hidden').addClass('hidden-item');
  1848.  
  1849.                 if ($('.search-rows__body').hasClass('opened')) {
  1850.                     customHtml.addClass('active');
  1851.                 };
  1852.  
  1853.                 $('.search__block__inner .search-form .search-rows__items').append(customHtml);
  1854.             };
  1855.             /*Перенос пользовательских полей*/
  1856.  
  1857.             /*Переключение табов поиска*/
  1858.             var siteLoaded = true;
  1859.  
  1860.             if (siteLoaded) {
  1861.                 $('.search-rows__folders-fields label.first-folder-label input').prop('checked', true);
  1862.                 $('.folder-hidden select').val('').trigger('change');
  1863.                 siteLoaded = false;
  1864.             };
  1865.  
  1866.  
  1867.             $('.search-rows__folders-fields input').each(function () {
  1868.                 if ($(this).is(':checked')) {
  1869.                     $(this).parent().addClass('checked');
  1870.                 }
  1871.             });
  1872.  
  1873.             $('.search-rows__form [name="s[folder_id]"]').on('change', function () {
  1874.  
  1875.                 $('.search__block__inner .search-form .search-rows__folders-fields').addClass('loading');
  1876.  
  1877.  
  1878.                 setTimeout(function () {
  1879.                     $('.global_fields_moved').appendTo('#shop2_search_global_fields');
  1880.                     $('.search__block__inner .search-form .search-rows__row.moved').remove();
  1881.                 });
  1882.                
  1883.             });
  1884.             /*Переключение табов поиска*/
  1885.  
  1886.             /*Список мультиселекта*/
  1887.             function showCheckboxes() {
  1888.                 $(document).on('click', '.selectBox', function (e) {
  1889.                     var $this = $(this);
  1890.                     var multiselectDropParent = $this.parent(".row-body");
  1891.                     var multiselectDrop = multiselectDropParent.find(".multiselect-drop");
  1892.  
  1893.                     var searchRowParent = $this.parents(".search-rows__row");
  1894.  
  1895.                     searchRowParent.siblings().find($(".gr-field-multiselect .multiselect-drop")).removeClass("active");
  1896.  
  1897.                     if (!multiselectDrop.hasClass("active")) {
  1898.                         multiselectDrop.addClass("active");
  1899.                     } else {
  1900.                         multiselectDrop.removeClass("active");
  1901.                     }
  1902.                 });
  1903.                 $(document).on('click', function (e) {
  1904.                     if (!$(e.target).closest('.selectBox, .multiselect-drop').length) {
  1905.                         $('.multiselect-drop').removeClass('active');
  1906.                     };
  1907.                 });
  1908.             }
  1909.             showCheckboxes();
  1910.             /*Список мультиселекта*/
  1911.  
  1912.             /*Список мультиселекта заполнение поля*/
  1913.             function checkboxesVal() {
  1914.                 $('.search-rows__row.gr-field-multiselect').each(function () {
  1915.                     var $this = $(this);
  1916.                     var $text = $this.find($('.selectBox__textarea'));
  1917.                     var $box = $this.find($('.multiselect-drop li input[type="checkbox"]'));
  1918.                     var $title = $this.find($('.selectBox .selectBox__textarea')).data('select-title');
  1919.  
  1920.                     $text.html($title);
  1921.                     $box.prop('checked', false);
  1922.  
  1923.                     $box.on('change', function () {
  1924.                         var $this = $(this);
  1925.                         var $thisParent = $this.parents('.search-rows__row.gr-field-multiselect');
  1926.  
  1927.                         var values = $thisParent.find($('input[type="checkbox"]:checked')).map(function () {
  1928.                             return $(this).data('text');
  1929.                         }).get().join(', ');
  1930.  
  1931.                         if (values == '') {
  1932.                             $text.html($title);
  1933.                         } else {
  1934.                             var numberOfChecked = $thisParent.find($('input[type="checkbox"]:checked')).length;
  1935.  
  1936.                             if (numberOfChecked > 1) {
  1937.                                 $text.html('Выбранно: ' + numberOfChecked);
  1938.                             } else {
  1939.                                 $text.html(values);
  1940.                             }
  1941.                         }
  1942.                     });
  1943.                 });
  1944.             }
  1945.             checkboxesVal();
  1946.             /*Список мультиселекта заполнение поля*/
  1947.  
  1948.             shop2.on('afterGetFolderCustomFields', function () {
  1949.                 searchItemsMove();
  1950.                 checkboxesVal();
  1951.  
  1952.                 $('.search__block__inner .search-form .search-rows__folders-fields').removeClass('loading');
  1953.             });
  1954.  
  1955.             var elWidth = 0;
  1956.             var parentWidth = $('.search-rows__folders-fields').outerWidth();
  1957.             $('.search-rows__folders-fields > label').each(function () {
  1958.                 elWidth += $(this).outerWidth();
  1959.             })
  1960.  
  1961.             if (elWidth > parentWidth) {
  1962.                 $('.search-rows__folders').addClass('gr-mb');
  1963.             }
  1964.  
  1965.  
  1966.         },
  1967.         searchBlock: function () {
  1968.  
  1969.             $(document).on('click', '.search-form .row-title', function () {
  1970.                 $(this).toggleClass('active');
  1971.                 $(this).next().slideToggle(250);
  1972.             });
  1973.  
  1974.             function searchMoreFields() {
  1975.                 var hideText = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
  1976.                 var currentText = $('html').attr('lang') == 'ru' ? shop2.my.gr_filter_select_btn || 'Показать ещё' : shop2.my.gr_filter_select_btn || 'Show more';
  1977.  
  1978.                 $('.search-rows__row').each(function () {
  1979.                     var $this = $(this);
  1980.                     var $btn = $this.find('.gr-filter-more__btn');
  1981.  
  1982.                     $btn.find('.gr-filter-more__text').text(currentText);
  1983.  
  1984.                     $btn.off('click').on('click', function () {
  1985.                         var $hiddenCkeckbox = $this.find('ul li:hidden');
  1986.  
  1987.                         $hiddenCkeckbox.addClass('hidden_item');
  1988.  
  1989.                         if ($this.find('.hidden_item').hasClass('active')) {
  1990.                             $btn.find('.gr-filter-more__text').text(currentText);
  1991.                             $this.find('.hidden_item').removeClass('active');
  1992.                         } else {
  1993.                             $btn.find('.gr-filter-more__text').text(hideText);
  1994.                             $this.find('.hidden_item').addClass('active');
  1995.                         };
  1996.  
  1997.                         setTimeout(function () {
  1998.                             $('.search-rows__row').matchHeight();
  1999.                         });
  2000.                     });
  2001.                 });
  2002.             };
  2003.  
  2004.             searchMoreFields();
  2005.  
  2006.             shop2.on('afterGetFolderCustomFields', function () {
  2007.                 searchMoreFields();
  2008.  
  2009.                 if (shop2.facets.enabled) {
  2010.                     var url = '/-/x-api/v1/public/?method=shop2/getSearchMatches';
  2011.  
  2012.                     var formData = $(shop2.facets.search.wrapper).serialize();
  2013.  
  2014.                     shop2.facets.getDataSearch(url, formData);
  2015.                 };
  2016.             });
  2017.  
  2018.         },
  2019.         /*Поиск*/
  2020.         /*Поиск на главной*/
  2021.         searchTabs: function () {
  2022.            
  2023.             const containers = document.querySelectorAll('.js-search__container');
  2024.  
  2025.             containers.forEach(container => {
  2026.                 let buttons = container.querySelectorAll('.js-search__controls[data-var-width]');
  2027.                 buttons.forEach(btn => {
  2028.                     const cssVarName = btn.dataset.varWidth; // получаем имя переменной
  2029.                     const width = btn.offsetWidth + 'px'; // измеряем фактическую ширину
  2030.                     container.style.setProperty(`--${cssVarName}`, width); // устанавливаем CSS-переменную
  2031.  
  2032.                     btn.addEventListener('click', function (e) {
  2033.  
  2034.                         container.querySelector('.js-search__controls.active').classList.remove('active');
  2035.                         container.querySelector('.js-search__background').classList.toggle('active');
  2036.                         this.classList.add('active');
  2037.  
  2038.                         const parent = container.closest('js-block-search.active');
  2039.                         if (parent) {
  2040.                             parent.classList.remove('active');
  2041.                         }
  2042.                     });
  2043.                 });
  2044.             });
  2045.  
  2046.  
  2047.             function setButtonWidths() {
  2048.                 const containers = document.querySelectorAll('.js-search__container');
  2049.                 containers.forEach(container => {
  2050.                     const buttons = container.querySelectorAll('.js-search__controls[data-var-width]');
  2051.  
  2052.                     buttons.forEach(btn => {
  2053.                         const cssVarName = btn.dataset.varWidth;
  2054.                         const width = btn.offsetWidth + 'px';
  2055.                         container.style.setProperty(`--${cssVarName}`, width);
  2056.                     });
  2057.                 });
  2058.             }
  2059.             setButtonWidths();
  2060.             let blink = false;
  2061.             // 2. Обновляем при ресайзе, но только если <= 600px
  2062.             window.addEventListener('resize', () => {
  2063.                 if (window.innerWidth <= 600) {
  2064.                     setButtonWidths();
  2065.                     blink = true;
  2066.                 } else {
  2067.                     if (blink) {
  2068.                         setButtonWidths();
  2069.                         blink = false;
  2070.                     }
  2071.                 }
  2072.             });
  2073.         },
  2074.         searchPopup: function () {
  2075.             $(document).on('opening', '.remodal_search', function () {
  2076.                 const container = document.querySelector('.js-search__container');
  2077.                 const buttons = container.querySelectorAll('.js-search__controls[data-var-width]');
  2078.  
  2079.                 buttons.forEach(btn => {
  2080.                     const cssVarName = btn.dataset.varWidth;
  2081.                     const width = btn.offsetWidth + 'px';
  2082.                     container.style.setProperty(`--${cssVarName}`, width);
  2083.                 });
  2084.             });
  2085.         },
  2086.  
  2087.         otherScripts: function () {
  2088.             if($('.compare_favorit_amount').text() == '0'){
  2089.                 $('.keys-panel__login').removeClass('vis_amount');
  2090.             } else{
  2091.                 $('.keys-panel__login').addClass('vis_amount');
  2092.             }
  2093.             $(document).on('opening', '.compare-remodal', function () {
  2094.                 $('.compare-remodal__body').prependTo('.compare-remodal__body-wrap');
  2095.             });
  2096.  
  2097.             if ($('table').length) {
  2098.                 $('table').wrap('<div class="table-wrapper"></div>');
  2099.             };
  2100.             if (shop2.facets.enabled && $('.shop2-filter').length) {
  2101.                 shop2.filter.count();
  2102.             };
  2103.  
  2104.             $('body').removeClass('gr_hide_onload');
  2105.  
  2106.             // Нажатие на клавишу Esc
  2107.             $(document).on('keyup.esc_keyup', function (keyUp) {
  2108.                 if (keyUp.keyCode ==
  2109.                     27) {
  2110.                     $('html').removeClass('overflowHidden');
  2111.                     $('.sorting-block').removeClass('active');
  2112.                     $('.shop2-color-ext-select').removeClass('active');
  2113.                     $('.gr-favorite-popup').removeClass('opened');
  2114.                     $('#shop2-alert-ok').trigger('click');
  2115.                     return false;
  2116.                 };
  2117.             });
  2118.             $('.brends-popup__btn').removeClass('active');
  2119.             $('.brends-popup__body').removeClass('active');
  2120.             // Нажатие на клавишу Esc
  2121.  
  2122.             // Клик по документу
  2123.             $(document).on('click', function (e) {
  2124.                 if (!$(e.target).closest('.price-old.question, .cart-total .question').length) {
  2125.                     $('.shop2-product-discount-desc').hide();
  2126.                 };
  2127.  
  2128.                 if (!$(e.target).closest('.sorting-block').length && !$(e.target).closest('.sorting-button').length) {
  2129.                     $('.sorting-block').removeClass('active');
  2130.                 };
  2131.  
  2132.                 if (!$(e.target).closest('.shop2-color-ext-select .shop2-color-ext-options, #shop2-color-ext-select').length) {
  2133.                     $('.shop2-color-ext-select').removeClass('active');
  2134.                 };
  2135.  
  2136.                 if (!$(e.target).closest('.brends-popup').length) {
  2137.                     $('.brends-popup__btn').removeClass('active');
  2138.                     $('.brends-popup__body').removeClass('active');
  2139.                 };
  2140.  
  2141.                 setTimeout(function () {
  2142.                     $('#shop2-alert-ok').html('<span><svg class="gr-svg-icon gr_big_icon"><use xlink:href="#icon_site_close"></use></svg><svg class="gr-svg-icon"><use xlink:href="#icon_site_close_small"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_site_close_mini"></use></svg></span>');
  2143.                 }, 250)
  2144.             });
  2145.             // Клик по документу
  2146.  
  2147.             $(window).on('scroll', function () {
  2148.                 var scroll = $(window).scrollTop();
  2149.  
  2150.  
  2151.  
  2152.                 if ($('.up-button').length) {
  2153.                     if (scroll >= 300 && this.oldScroll > this.scrollY) {
  2154.                         $('.up-button__btn').addClass('active');
  2155.                     } else {
  2156.                         $('.up-button__btn').removeClass('active');
  2157.                     };
  2158.                 } else {
  2159.  
  2160.                     if (scroll >= 300) {
  2161.                         $('.up-button__btn').addClass('active');
  2162.                     } else {
  2163.                         $('.up-button__btn').removeClass('active');
  2164.                     };
  2165.                 };
  2166.  
  2167.                 this.oldScroll = this.scrollY;
  2168.             });
  2169.  
  2170.             /*Кнопка наверх*/
  2171.             $('.up-button__btn').on('click', function () {
  2172.                 $('html, body').stop().animate({
  2173.                     scrollTop: 0
  2174.                 }, 800);
  2175.             });
  2176.  
  2177.  
  2178.             shop2_gr.methods.changeFlagsColor();
  2179.  
  2180.             shop2_gr.methods.grLazyLoad();
  2181.  
  2182.             if (readCookie('rootMarginCookie')) {
  2183.                 shop2_gr.methods.grLazyLoad({
  2184.                     selector: 'gr_lazy_load_block',
  2185.                     margin: '10px'
  2186.                 });
  2187.             } else {
  2188.                 shop2_gr.methods.grLazyLoad({
  2189.                     selector: 'gr_lazy_load_block'
  2190.                 });
  2191.             };
  2192.             if (!readCookie('rootMarginCookie')) {
  2193.                 createCookie('rootMarginCookie', 1, 1); // Создаем куку, чтобы увеличить расстояние, при котором появляются блоки
  2194.             };
  2195.  
  2196.             jQuery.event.special.touchstart = {
  2197.                 setup: function (_, ns, handle) {
  2198.                     this.addEventListener("touchstart", handle, {
  2199.                         passive: true
  2200.                     });
  2201.                 }
  2202.             };
  2203.  
  2204.             jQuery.event.special.touchend = {
  2205.                 setup: function (_, ns, handle) {
  2206.                     this.addEventListener("touchend", handle, {
  2207.                         passive: true
  2208.                     });
  2209.                 }
  2210.             };
  2211.  
  2212.             jQuery.event.special.touchmove = {
  2213.                 setup: function (_, ns, handle) {
  2214.                     this.addEventListener("touchmove", handle, {
  2215.                         passive: true
  2216.                     });
  2217.                 }
  2218.             };
  2219.         } /*Разное*/
  2220.  
  2221.  
  2222.     };
  2223.  
  2224.     shop2_gr.settings = {
  2225.         imageObserver: null,
  2226.         searchIcon: '<i class="search-block__icon"><svg class="gr-svg-icon"><use xlink:href="#icon_shop_search"></use></svg></i>',
  2227.         sliderControls: ['<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_prev"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_prev_small"></use></svg>', '<svg class="gr-svg-icon"><use xlink:href="#icon_shop_slider_next"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_slider_next_small"></use></svg>']
  2228.     };
  2229.  
  2230.     shop2_gr.methods = {
  2231.         grLazyFunc: function (params, callback) {
  2232.             var elem = params.selector;
  2233.             var margin = '10px';
  2234.  
  2235.             if (params.margin) {
  2236.                 margin = params.margin
  2237.             }
  2238.  
  2239.             let options = {
  2240.                 rootMargin: margin
  2241.             };
  2242.  
  2243.             const imageObserver = new IntersectionObserver((entries, imgObserver) => {
  2244.                 entries.forEach((entry) => {
  2245.                     if (entry.isIntersecting) {
  2246.                         const lazyItem = entry.target // Текущий элемент
  2247.  
  2248.                         if (callback) {
  2249.                             callback();
  2250.                         };
  2251.  
  2252.                         imgObserver.unobserve(lazyItem);
  2253.                     }
  2254.                 })
  2255.             }, options);
  2256.  
  2257.             if (typeof elem == 'object') {
  2258.                 imageObserver.observe(elem);
  2259.             } else {
  2260.                 if (document.querySelector(elem) != null) {
  2261.                     if (document.querySelectorAll(elem).length > 1) {
  2262.                         const arr = document.querySelectorAll(elem);
  2263.                         arr.forEach((v) => {
  2264.                             imageObserver.observe(v);
  2265.                         });
  2266.                     } else {
  2267.                         imageObserver.observe(document.querySelector(elem));
  2268.                     }
  2269.                 }
  2270.             }
  2271.         },
  2272.         /*Отложенная загрузка скрипта*/
  2273.  
  2274.         grLazyLoad: function (params) {
  2275.             var elem = 'gr_images_lazy_load';
  2276.             var margin = '10px';
  2277.  
  2278.             if (params) {
  2279.                 if (params.selector) {
  2280.                     elem = params.selector;
  2281.                 };
  2282.  
  2283.                 if (params.margin) {
  2284.                     margin = params.margin;
  2285.                 };
  2286.             };
  2287.  
  2288.             let options = {
  2289.                 rootMargin: margin
  2290.             };
  2291.             shop2_gr.settings.imageObserver = new IntersectionObserver((entries, imgObserver) => {
  2292.                 entries.forEach((entry) => {
  2293.                     if (entry.isIntersecting) {
  2294.                         const lazyImage = entry.target // Текущий элемент
  2295.  
  2296.                         if (lazyImage.tagName == 'IMG') { // для обычных картинок
  2297.                             if (lazyImage.dataset.srcset) {
  2298.                                 // Чтобы загружать картинки маленьких размеров с помощью srcset
  2299.                                 lazyImage.srcset = lazyImage.dataset.srcset // Адрес картинки data-srcset=""
  2300.                                 lazyImage.classList.remove(elem);
  2301.                                 imgObserver.unobserve(lazyImage);
  2302.                             } else {
  2303.                                 lazyImage.src = lazyImage.dataset.src // Адрес картинки data-src=""
  2304.                                 lazyImage.classList.remove(elem);
  2305.                                 imgObserver.unobserve(lazyImage);
  2306.                             }
  2307.                         } else if (lazyImage.dataset.bg) {
  2308.                             if (window.innerWidth <= 768 && lazyImage.dataset.minbg) {
  2309.                                 lazyImage.style.backgroundImage = 'url(' + lazyImage.dataset.minbg + ')';
  2310.                                 lazyImage.classList.remove(elem);
  2311.                                 imgObserver.unobserve(lazyImage);
  2312.                             } else {
  2313.                                 lazyImage.style.backgroundImage = 'url(' + lazyImage.dataset.bg + ')';
  2314.                                 lazyImage.classList.remove(elem);
  2315.                                 imgObserver.unobserve(lazyImage);
  2316.                             }
  2317.                         } else if (lazyImage.dataset.func) { // Если элемент содержит data-func
  2318.                             if (typeof shop2_gr.methods[lazyImage.dataset.func] == 'function') {
  2319.                                 shop2_gr.methods[lazyImage.dataset.func](lazyImage); // Вызов функции
  2320.                                 lazyImage.classList.remove(elem);
  2321.                                 imgObserver.unobserve(lazyImage);
  2322.                             }
  2323.                         } else {
  2324.                             lazyImage.classList.remove(elem);
  2325.                             imgObserver.unobserve(lazyImage);
  2326.                         }
  2327.                     }
  2328.                 })
  2329.             }, options);
  2330.  
  2331.             const arr = document.querySelectorAll('.' + elem);
  2332.  
  2333.             arr.forEach((v) => {
  2334.                 shop2_gr.settings.imageObserver.observe(v);
  2335.             });
  2336.         },
  2337.         /*Отложенная загрузка*/
  2338.  
  2339.         forEach: function (array, callback, scope) {
  2340.             for (var i = 0; i < array.length; i++) {
  2341.                 callback.call(scope, i, array[i]);
  2342.             };
  2343.         },
  2344.         /*Для тини слайдера*/
  2345.  
  2346.         changeFlagsColor: function () {
  2347.             $('.product-flags__item.custom_item span').each(function () {
  2348.                 if ($(this).data('custom-bg')) {
  2349.                     var custom_bg = shop2_gr.methods.grConvertToRgb($(this).data('custom-bg'));
  2350.                     var text_color = Math.round(((parseInt(custom_bg[0]) * 299) + (parseInt(custom_bg[1]) * 587) + (parseInt(custom_bg[2]) * 114)) / 1000);
  2351.  
  2352.                     if (text_color > 140) {
  2353.                         $(this).css('color', '#000');
  2354.                     } else {
  2355.                         $(this).css('color', '#fff');
  2356.                     };
  2357.                 };
  2358.             });
  2359.         },
  2360.         /*Перекраска цвета текста кастомных флагов*/
  2361.         moreBtnAll: function (wrapper) {
  2362.  
  2363.             let $hidden = $(wrapper).find('.unit_item_block:hidden').addClass('hidden_item');
  2364.             let $btn = $(wrapper).find('.bottom_more_js');
  2365.  
  2366.             if ($hidden.length) {
  2367.                 $btn.parents('.bottom_more_panel').removeClass('hide');
  2368.             };
  2369.  
  2370.             $btn.on('click', function () {
  2371.                 $hidden.slideToggle(250);
  2372.                 var $currentText = $(this).find('ins').data('text');
  2373.  
  2374.                 var $hideText = $(this).find('ins').data('text_hidden');
  2375.  
  2376.                 if ($(this).hasClass('active')) {
  2377.                     $(this).removeClass('active');
  2378.                     $(this).find('ins').text($currentText);
  2379.                 } else {
  2380.                     $(this).addClass('active');
  2381.                     $(this).find('ins').text($hideText);
  2382.                 }
  2383.             });
  2384.         },
  2385.         mainBlocks: function(lazyElem) {
  2386.             if ($('.main-products').length) {
  2387.                 $('.product-list').removeClass('simple').removeClass('list').addClass('thumbs');
  2388.                
  2389.                 var slider = lazyElem.querySelector('.main_blocks_list');
  2390.                 var main_items = slider.getAttribute('data-main-items');
  2391.                 var respSettings = {};
  2392.                
  2393.                 var gr_images_size = slider.dataset["imagesSize"]; 
  2394.                 var gr_images_view = slider.dataset["imagesView"];
  2395.                 var gr_mode_catalog = slider.dataset["modeCatalog"];
  2396.                 var url = '/-/x-api/v1/public/?method=shop2/getProductsBySearchMatches';
  2397.                
  2398.                 if (gr_images_view){
  2399.                     url += "&gr_images_view=" + gr_images_view;
  2400.                 };
  2401.                
  2402.                 if (gr_images_size){
  2403.                     url += "&gr_images_size=" + gr_images_size;
  2404.                 };
  2405.                
  2406.                 if (gr_mode_catalog){
  2407.                     url += "&gr_mode_catalog=" + gr_mode_catalog;
  2408.                 };
  2409.                
  2410.                 if (main_items == 5) {
  2411.                     var main_items_1280 = 5,main_items_1024 = 4,main_items_768 = 3,main_items_320 = 2;
  2412.                 } else if (main_items == 4) {
  2413.                     var main_items_1280 = 4,main_items_1024 = 4,main_items_768 = 3,main_items_320 = 2;
  2414.                 } else if (main_items == 3) {
  2415.                     var main_items_1280 = 3,main_items_1024 = 3,main_items_768 = 3,main_items_320 = 2;
  2416.                 } else if (main_items == 2) {
  2417.                     var main_items_1280 = 2,main_items_1024 = 2,main_items_768 = 2,main_items_320 = 2;
  2418.                 };
  2419.  
  2420.                 respSettings = {
  2421.                     320: {controls: false,items: main_items_320,gutter: 20},
  2422.                     768: {controls: false,items: main_items_768,gutter: 20},
  2423.                     1024: {controls: false,items: main_items_1024,gutter: 20},
  2424.                     1261: {controls: true,items: main_items_1280,gutter: 30},
  2425.                     1341: {controls: true,items: main_items_1280,gutter: 30}
  2426.                 };
  2427.                
  2428.                 if ($(slider).length) {
  2429.                     var sliderAutoplay = +slider.getAttribute('data-autoplay');
  2430.                     var multislider = tns({
  2431.                         loop: false,
  2432.                         rewind: true,
  2433.                         container: slider,
  2434.                         slideBy: 1,
  2435.                         autoplayHoverPause: true,
  2436.                         mode: 'carousel',
  2437.                         axis: 'horizontal',
  2438.                         autoplay: sliderAutoplay,
  2439.                         autoplayButtonOutput: false,
  2440.                         mouseDrag: true,
  2441.                         center: false,
  2442.                         autoWidth: false,
  2443.                         nav: true,
  2444.                         swipeAngle: 50,
  2445.                         controlsText: shop2_gr.settings.sliderControls,
  2446.                         navPosition: 'bottom',
  2447.                         preventActionWhenRunning: false,
  2448.                         responsive: respSettings
  2449.                     });
  2450.                    
  2451.                     setTimeout(function(){
  2452.                         shop2_gr.methods.arrowsPosition($(lazyElem).find('.main_blocks_list'), '.gr-product-image');
  2453.                         if (!shop2.my.gr_main_blocks_ajax) {
  2454.                             $(lazyElem).addClass('main_products_loaded');
  2455.                         }
  2456.                     }, 10);
  2457.                    
  2458.                     if (shop2.my.gr_main_blocks_ajax) {
  2459.                         var empty_products = slider.querySelectorAll('.gr_empty_product');
  2460.                         var active_products = slider.querySelectorAll('.tns-slide-active');
  2461.                         var active_array = [];
  2462.                        
  2463.                         Array.prototype.forEach.call(active_products, function(item, i){
  2464.                             active_array[i] = item.dataset['mainProductId'];
  2465.                         });
  2466.                        
  2467.                         shop2_gr.methods.getMainProducts(url, active_array, empty_products, function(){
  2468.                             shop2_gr.methods.arrowsPosition($(lazyElem).find('.main_blocks_list'), '.gr-product-image');
  2469.                            
  2470.                             shop2_gr.methods.changeFlagsColor();
  2471.                            
  2472.                             setTimeout(function(){
  2473.                                 $(lazyElem).find('.product-item__bottom').matchHeight('remove');
  2474.                                 $(lazyElem).find('.product-item__bottom-left').matchHeight('remove');
  2475.                                 $(lazyElem).find('.product-item__bottom-right').matchHeight('remove');
  2476.                                 $(lazyElem).find('.product-price').matchHeight('remove');
  2477.                                
  2478.                                 $(lazyElem).find('.product-item__bottom').matchHeight();
  2479.                                 $(lazyElem).find('.product-item__bottom-left').matchHeight();
  2480.                                 $(lazyElem).find('.product-item__bottom-right').matchHeight();
  2481.                                 $(lazyElem).find('.product-price').matchHeight();
  2482.                             }, 300);
  2483.                            
  2484.                             $(slider).find('.gr_images_lazy_load').each(function(){
  2485.                                 $(this).attr('src', $(this).attr('data-src'));
  2486.                             });
  2487.                             $(lazyElem).addClass('main_products_loaded');
  2488.                             $(slider).find('.buy-one-click').attr('data-api-url', $(slider).data('popup-form'));
  2489.                             $(slider).find('.buy-one-click.product_info_form').attr('data-api-url', $(slider).data('info-popup-form'));
  2490.                             shop2_gr.methods.viewLots($(lazyElem).find('.product-list'));
  2491.                             shop2_gr.methods.amountInit($(lazyElem).find('.shop2-product-item'));
  2492.                            
  2493.                            
  2494.                             if (!isMobile) {
  2495.                                 $(lazyElem).find('.quick-view-trigger').elemToolTip({
  2496.                                     text: 'Быстрый просмотр',
  2497.                                     margin: 12
  2498.                                 });
  2499.                             };
  2500.                         });
  2501.                    
  2502.                    
  2503.                         function slider_handler(current_slider) {
  2504.                             if (!current_slider.container.classList.contains('all_products_done')) {
  2505.                                 var simple_products = current_slider.container.querySelectorAll('.gr_empty_product');
  2506.                                
  2507.                                 if (simple_products[0]) {
  2508.                                     var active_array = [];
  2509.                                                
  2510.                                     Array.prototype.forEach.call(simple_products, function(simple_product, i){
  2511.                                         active_array[i] = simple_product.dataset['mainProductId'];
  2512.                                     });
  2513.                                    
  2514.                                     shop2_gr.methods.getMainProducts(url, active_array, simple_products, function(){
  2515.                                         shop2_gr.methods.arrowsPosition($(current_slider.container).find('.main_blocks_list'), '.gr-product-image');
  2516.                                        
  2517.                                         $(current_slider.container).find('.gr_images_lazy_load').each(function(){
  2518.                                             $(this).attr('src', $(this).attr('data-src'));
  2519.                                         });
  2520.                                         $(lazyElem).addClass('main_products_loaded');
  2521.                                         $(current_slider.container).find('.buy-one-click').attr('data-api-url', $(current_slider.container).data('popup-form'));
  2522.                                         $(current_slider.container).find('.buy-one-click.product_info_form').attr('data-api-url', $(current_slider.container).data('info-popup-form'));
  2523.                                         shop2_gr.methods.viewLots($(current_slider.container).find('.product-list'));
  2524.                                         shop2_gr.methods.amountInit($(current_slider.container).find('.shop2-product-item'));
  2525.                                        
  2526.                                         if (!isMobile) {
  2527.                                             $(current_slider.container).find('.quick-view-trigger').elemToolTip({
  2528.                                                 text: 'Быстрый просмотр',
  2529.                                                 margin: 12
  2530.                                             });
  2531.                                         };
  2532.                                        
  2533.                                         shop2_gr.methods.changeFlagsColor();
  2534.                                        
  2535.                                         setTimeout(function(){
  2536.                                             $(current_slider.container).find('.product-item__bottom').matchHeight('remove');
  2537.                                             $(current_slider.container).find('.product-item__bottom-left').matchHeight('remove');
  2538.                                             $(current_slider.container).find('.product-item__bottom-right').matchHeight('remove');
  2539.                                             $(current_slider.container).find('.product-price').matchHeight('remove');
  2540.                                            
  2541.                                             $(current_slider.container).find('.product-item__bottom').matchHeight();
  2542.                                             $(current_slider.container).find('.product-item__bottom-left').matchHeight();
  2543.                                             $(current_slider.container).find('.product-item__bottom-right').matchHeight();
  2544.                                             $(current_slider.container).find('.product-price').matchHeight();
  2545.                                         }, 300);
  2546.                                     });
  2547.                                    
  2548.                                     current_slider.container.classList.add('all_products_done');
  2549.                                 };
  2550.                             } else {
  2551.                                 return;
  2552.                             };
  2553.                         };
  2554.                        
  2555.                        
  2556.                        
  2557.                         multislider.events.on('indexChanged', slider_handler);
  2558.                         multislider.events.on('newBreakpointEnd', slider_handler);
  2559.                     };
  2560.                    
  2561.                     if (!shop2.my.gr_main_blocks_ajax) {
  2562.                         shop2_gr.methods.grLazyFunc({selector:lazyElem}, function() {
  2563.                             $(lazyElem).find('.product-item__bottom').matchHeight('remove');
  2564.                             $(lazyElem).find('.product-item__bottom-left').matchHeight('remove');
  2565.                             $(lazyElem).find('.product-item__bottom-right').matchHeight('remove');
  2566.                             $(lazyElem).find('.product-price').matchHeight('remove');
  2567.                            
  2568.                             $(lazyElem).find('.product-item__bottom').matchHeight();
  2569.                             $(lazyElem).find('.product-item__bottom-left').matchHeight();
  2570.                             $(lazyElem).find('.product-item__bottom-right').matchHeight();
  2571.                             $(lazyElem).find('.product-price').matchHeight();
  2572.                         });
  2573.                     };
  2574.                    
  2575.                     var mainLazyFuncTime, mainLazyFuncScroll = false;
  2576.                     $(window).on('scroll', function() {
  2577.                         if (mainLazyFuncTime) {
  2578.                             clearTimeout(mainLazyFuncTime);
  2579.                         };
  2580.                         mainLazyFuncTime = setTimeout(function() {
  2581.                             if (!mainLazyFuncScroll) {
  2582.                                 shop2_gr.methods.grLazyFunc({selector:lazyElem}, function() {
  2583.                                     $(lazyElem).find('.product-item__bottom').matchHeight('remove');
  2584.                                     $(lazyElem).find('.product-item__bottom-left').matchHeight('remove');
  2585.                                     $(lazyElem).find('.product-item__bottom-right').matchHeight('remove');
  2586.                                     $(lazyElem).find('.product-price').matchHeight('remove');
  2587.                                    
  2588.                                     $(lazyElem).find('.product-item__bottom').matchHeight();
  2589.                                     $(lazyElem).find('.product-item__bottom-left').matchHeight();
  2590.                                     $(lazyElem).find('.product-item__bottom-right').matchHeight();
  2591.                                     $(lazyElem).find('.product-price').matchHeight();
  2592.                                 });
  2593.                             };
  2594.                    
  2595.                             return mainLazyFuncScroll = true;
  2596.                         }, 50);
  2597.                         return mainLazyFuncScroll;
  2598.                     });
  2599.                 };
  2600.             };
  2601.         }, /*Блоки на главной*/
  2602.         foldersBlocks: function (lazyElem) {
  2603.             if (!$(lazyElem).hasClass('folders_items_slider')) {
  2604.  
  2605.                 setTimeout(function () {
  2606.                     shop2_gr.methods.moreBtnAll(lazyElem);
  2607.                 }, 100);
  2608.  
  2609.             } else {
  2610.  
  2611.                 var folders = lazyElem.querySelector('.folders_items_slider .folders-block__body');
  2612.                 var sliderAutoplay = +folders.getAttribute('data-autoplay');
  2613.  
  2614.                 var respSettings = {
  2615.                     320: {
  2616.                         controls: false,
  2617.                         items: 2,
  2618.                         gutter: 10
  2619.                     },
  2620.                     479: {
  2621.                         controls: false,
  2622.                         items: 2,
  2623.                         gutter: 10
  2624.                     },
  2625.                     640: {
  2626.                         controls: false,
  2627.                         items: 3,
  2628.                         gutter: 20
  2629.                     },
  2630.                     1023: {
  2631.                         controls: true,
  2632.                         items: 3,
  2633.                         gutter: 36
  2634.                     },
  2635.                 };
  2636.  
  2637.                 let multislider = tns({
  2638.                     loop: false,
  2639.                     rewind: true,
  2640.                     container: folders,
  2641.                     slideBy: 1,
  2642.                     autoplayHoverPause: true,
  2643.                     mode: 'carousel',
  2644.                     axis: 'horizontal',
  2645.                     autoplay: sliderAutoplay,
  2646.                     autoplayButtonOutput: false,
  2647.                     mouseDrag: true,
  2648.                     center: false,
  2649.                     lazyload: true,
  2650.                     autoWidth: false,
  2651.                     autoHeight: true,
  2652.                     nav: true,
  2653.                     controls: true,
  2654.                     navPosition: 'bottom',
  2655.                     controlsPosition: 'top',
  2656.                     preventreviewsWhenRunning: true,
  2657.                     controlsText: shop2_gr.settings.sliderControls,
  2658.                     responsive: respSettings
  2659.                 });
  2660.             }
  2661.  
  2662.             shop2_gr.methods.grLazyFunc({
  2663.                 selector: '.folders-block'
  2664.             }, function () {
  2665.                 $('.folders-block__block').matchHeight();
  2666.             });
  2667.         },
  2668.         /* Категории на главной */
  2669.         actionBlocks: function (lazyElem) {
  2670.             if (!$(lazyElem).hasClass('reviews_items_slider')) {
  2671.  
  2672.                 setTimeout(function () {
  2673.                     shop2_gr.methods.moreBtnAll(lazyElem);
  2674.                 }, 100);
  2675.  
  2676.             } else {
  2677.                 var slider = lazyElem.querySelector('.reviews_items_slider .action-block__body');
  2678.                 var sliderAutoplay = +slider.getAttribute('data-autoplay');
  2679.  
  2680.                 var respSettings = {
  2681.                     320: {
  2682.                         controls: false,
  2683.                         items: 1,
  2684.                         gutter: 1
  2685.                     },
  2686.                     640: {
  2687.                         controls: false,
  2688.                         items: 1,
  2689.                         gutter: 1
  2690.                     },
  2691.                     1024: {
  2692.                         controls: false,
  2693.                         items: 1,
  2694.                         gutter: 1
  2695.                     },
  2696.                     1261: {
  2697.                         controls: true,
  2698.                         items: 2,
  2699.                         gutter: 20
  2700.                     }
  2701.                 };
  2702.  
  2703.                 var action = tns({
  2704.                     loop: false,
  2705.                     rewind: true,
  2706.                     container: slider,
  2707.                     slideBy: 1,
  2708.                     autoplayHoverPause: true,
  2709.                     mode: 'carousel',
  2710.                     axis: 'horizontal',
  2711.                     autoplay: sliderAutoplay,
  2712.                     autoplayButtonOutput: false,
  2713.                     mouseDrag: true,
  2714.                     center: false,
  2715.                     lazyload: true,
  2716.                     autoWidth: false,
  2717.                     nav: true,
  2718.                     controls: true,
  2719.                     navPosition: 'bottom',
  2720.                     controlsPosition: 'top',
  2721.                     preventActionWhenRunning: false,
  2722.                     controlsText: shop2_gr.settings.sliderControls,
  2723.                     responsive: respSettings,
  2724.                     speed: 500
  2725.                 });
  2726.  
  2727.                 setTimeout(function () {
  2728.                     shop2_gr.methods.arrowsPosition($(lazyElem).find('.action-block__body'), '.action-block__item-image');
  2729.                 }, 10);
  2730.  
  2731.                 shop2_gr.methods.grLazyFunc({
  2732.                     selector: '.action-block'
  2733.                 }, function () {
  2734.                     $('.action-block__item-in').matchHeight();
  2735.                 });
  2736.             };
  2737.  
  2738.         },
  2739.         /* Акции */
  2740.         siteBrands: function (lazyElem) {
  2741.             if (!$(lazyElem).find('.site_brands_slider').length) {
  2742.  
  2743.                 setTimeout(function () {
  2744.                     shop2_gr.methods.moreBtnAll(lazyElem);
  2745.                 }, 100);
  2746.  
  2747.             } else {
  2748.                 let slider = lazyElem.querySelector('.site_brands_slider');
  2749.                 let sliderAutoplay = +slider.getAttribute('data-autoplay');
  2750.  
  2751.                 let respSettings = {
  2752.                     640: {
  2753.                         controls: false,
  2754.                         items: 4,
  2755.                         gutter: 20
  2756.                     },
  2757.                     1260: {
  2758.                         controls: true,
  2759.                         items: 4,
  2760.                         gutter: 20
  2761.                     },
  2762.                     1261: {
  2763.                         controls: true,
  2764.                         items: 5,
  2765.                         gutter: 20
  2766.                     },
  2767.                     1280: {
  2768.                         controls: true,
  2769.                         items: 6,
  2770.                         gutter: 36
  2771.                     }
  2772.                 };
  2773.                 let brandsSlider;
  2774.  
  2775.                 function initSlider() {
  2776.                     if (!brandsSlider) {
  2777.                         brandsSlider = tns({
  2778.                             loop: false,
  2779.                             rewind: true,
  2780.                             container: slider,
  2781.                             slideBy: 1,
  2782.                             mode: "carousel",
  2783.                             axis: "horizontal",
  2784.                             autoplayHoverPause: true,
  2785.                             autoplay: sliderAutoplay,
  2786.                             autoplayButtonOutput: false,
  2787.                             mouseDrag: true,
  2788.                             nav: true,
  2789.                             navPosition: "bottom",
  2790.                             controlsText: shop2_gr.settings.sliderControls,
  2791.                             preventActionWhenRunning: true,
  2792.                             responsive: respSettings
  2793.                         });
  2794.                     }
  2795.                 }
  2796.                 setTimeout(function () {
  2797.                     shop2_gr.methods.arrowsPosition(slider, '.site-brands__container');
  2798.                 }, 100);
  2799.  
  2800.                 function destroySlider() {
  2801.                     if (brandsSlider) {
  2802.                         brandsSlider.destroy();
  2803.                         brandsSlider = null;
  2804.                     }
  2805.                 }
  2806.  
  2807.                 function checkSlider() {
  2808.                     if (window.innerWidth <= 639) {
  2809.                         destroySlider();
  2810.                     } else {
  2811.                         initSlider();
  2812.                     }
  2813.                 }
  2814.  
  2815.                 // запуск при загрузке
  2816.                 checkSlider();
  2817.                 // запуск при изменении размера окна
  2818.                 window.addEventListener('resize', checkSlider);
  2819.             };
  2820.         },
  2821.         /*Бренды*/
  2822.         articlesBlocks: function (lazyElem) {
  2823.  
  2824.             if (!$(lazyElem).hasClass('articles_items_slider')) {
  2825.  
  2826.                 setTimeout(function () {
  2827.                     shop2_gr.methods.moreBtnAll(lazyElem);
  2828.                 }, 100);
  2829.  
  2830.             } else {
  2831.                 var sliderAutoplay = $(lazyElem).find('.articles-block__body').data('autoplay');
  2832.  
  2833.  
  2834.                 // tiny-slider initialisation
  2835.                 var slider = lazyElem.querySelector('.articles-block__body');
  2836.                 var respSettings = {
  2837.                     320: {
  2838.                         controls: false,
  2839.                         items: 1,
  2840.                         gutter: 0
  2841.                     },
  2842.                     767: {
  2843.                         controls: false,
  2844.                         items: 1,
  2845.                         gutter: 0
  2846.                     },
  2847.                     768: {
  2848.                         controls: false,
  2849.                         items: 2,
  2850.                         gutter: 36
  2851.                     },
  2852.                     1260: {
  2853.                         controls: false,
  2854.                         items: 2,
  2855.                         gutter: 36
  2856.                     },
  2857.                     1261: {
  2858.                         controls: true,
  2859.                         items: 3,
  2860.                         gutter: 36
  2861.                     }
  2862.                 };
  2863.  
  2864.                 let multislider = tns({
  2865.                     loop: false,
  2866.                     rewind: true,
  2867.                     container: slider,
  2868.                     slideBy: 1,
  2869.                     autoplayHoverPause: true,
  2870.                     mode: 'carousel',
  2871.                     axis: 'horizontal',
  2872.                     autoplay: sliderAutoplay,
  2873.                     autoplayButtonOutput: false,
  2874.                     mouseDrag: true,
  2875.                     center: false,
  2876.                     lazyload: true,
  2877.                     autoWidth: false,
  2878.                     nav: true,
  2879.                     controls: true,
  2880.                     navPosition: 'bottom',
  2881.                     controlsPosition: 'top',
  2882.                     preventarticlesWhenRunning: true,
  2883.                     controlsText: shop2_gr.settings.sliderControls,
  2884.                     responsive: respSettings
  2885.                 });
  2886.                 setTimeout(function () {
  2887.                     shop2_gr.methods.arrowsPosition($(lazyElem).find('.articles-block__body'), '.articles-block__item_image_in');
  2888.                 }, 100);
  2889.             }
  2890.         },
  2891.         reviewsBlock: function (lazyElem) {
  2892.             if (!$(lazyElem).hasClass('reviews_items_slider')) {
  2893.  
  2894.                 setTimeout(function () {
  2895.                     shop2_gr.methods.moreBtnAll(lazyElem);
  2896.                 }, 100);
  2897.  
  2898.             } else {
  2899.                 var sliderAutoplay = $(lazyElem).find('.reviews-block__body').data('autoplay');
  2900.  
  2901.  
  2902.                 // tiny-slider initialisation
  2903.                 var slider = lazyElem.querySelector('.reviews-block__body');
  2904.  
  2905.                 var respSettings = {
  2906.                     320: {
  2907.                         controls: false,
  2908.                         items: 1,
  2909.                         gutter: 20
  2910.                     },
  2911.                     768: {
  2912.                         controls: false,
  2913.                         items: 2,
  2914.                         gutter: 20
  2915.                     },
  2916.                     1024: {
  2917.                         controls: false,
  2918.                         items: 2,
  2919.                         gutter: 20
  2920.                     },
  2921.                     1260: {
  2922.                         controls: false,
  2923.                         items: 2,
  2924.                         gutter: 30
  2925.                     },
  2926.                     1261: {
  2927.                         controls: true,
  2928.                         items: 2,
  2929.                         gutter: 30
  2930.                     }
  2931.                 };
  2932.  
  2933.                 let multislider = tns({
  2934.                     loop: false,
  2935.                     rewind: true,
  2936.                     container: slider,
  2937.                     slideBy: 1,
  2938.                     autoplayHoverPause: true,
  2939.                     mode: 'carousel',
  2940.                     axis: 'horizontal',
  2941.                     autoplay: sliderAutoplay,
  2942.                     autoplayButtonOutput: false,
  2943.                     mouseDrag: true,
  2944.                     center: false,
  2945.                     lazyload: true,
  2946.                     autoWidth: false,
  2947.                     autoHeight: true,
  2948.                     nav: true,
  2949.                     controls: true,
  2950.                     navPosition: 'bottom',
  2951.                     controlsPosition: 'top',
  2952.                     preventreviewsWhenRunning: true,
  2953.                     controlsText: shop2_gr.settings.sliderControls,
  2954.                     responsive: respSettings
  2955.                 });
  2956.             }
  2957.         },
  2958.         kindsBlock: function (lazyElem) {
  2959.  
  2960.             if ($('.kinds-block__items.kinds_slider').length > 0) {
  2961.                 var slider = lazyElem.querySelector('.kinds-block__items.kinds_slider');
  2962.                 var kind_items = slider.getAttribute('data-kind-items');
  2963.                 var respSettings = {};
  2964.  
  2965.                 if (kind_items == 4) {
  2966.                     var kind_items_1280 = 5,
  2967.                         kind_items_1024 = 4,
  2968.                         kind_items_768 = 3,
  2969.                         kind_items_320 = 2;
  2970.                 } else if (kind_items == 3) {
  2971.                     var kind_items_1280 = 4,
  2972.                         kind_items_1024 = 4,
  2973.                         kind_items_768 = 3,
  2974.                         kind_items_320 = 2;
  2975.                 } else if (kind_items == 3) {
  2976.                     var kind_items_1280 = 3,
  2977.                         kind_items_1024 = 3,
  2978.                         kind_items_768 = 3,
  2979.                         kind_items_320 = 2;
  2980.                 }
  2981.  
  2982.                 respSettings = {
  2983.                     320: {
  2984.                         controls: false,
  2985.                         items: kind_items_320,
  2986.                         gutter: 12
  2987.                     },
  2988.                     768: {
  2989.                         controls: false,
  2990.                         items: kind_items_768,
  2991.                         gutter: 20
  2992.                     },
  2993.                     1024: {
  2994.                         controls: false,
  2995.                         items: kind_items_1024,
  2996.                         gutter: 20
  2997.                     },
  2998.                     1261: {
  2999.                         controls: true,
  3000.                         items: kind_items_1280,
  3001.                         gutter: 20
  3002.                     },
  3003.                     1341: {
  3004.                         controls: true,
  3005.                         items: kind_items_1280,
  3006.                         gutter: 20
  3007.                     }
  3008.                 };
  3009.  
  3010.                 if ($(slider).length) {
  3011.                     var sliderAutoplay = +slider.getAttribute('data-autoplay');
  3012.  
  3013.                     var multislider = tns({
  3014.                         loop: false,
  3015.                         rewind: true,
  3016.                         container: slider,
  3017.                         slideBy: 1,
  3018.                         autoplayHoverPause: true,
  3019.                         mode: 'carousel',
  3020.                         axis: 'horizontal',
  3021.                         autoplay: sliderAutoplay,
  3022.                         autoplayButtonOutput: false,
  3023.                         mouseDrag: true,
  3024.                         center: false,
  3025.                         autoWidth: false,
  3026.                         nav: true,
  3027.                         swipeAngle: 50,
  3028.                         controlsText: shop2_gr.settings.sliderControls,
  3029.                         navPosition: 'bottom',
  3030.                         preventActionWhenRunning: false,
  3031.                         responsive: respSettings
  3032.                     });
  3033.  
  3034.                     setTimeout(function () {
  3035.                         shop2_gr.methods.arrowsPosition($(lazyElem).find('.kinds-block__items.kinds_slider'), '.kind-image');
  3036.                     }, 10);
  3037.  
  3038.                     var kindLazyFuncTime, kindLazyFuncScroll = false;
  3039.  
  3040.                     if ($(window).scrollTop() > 0) {
  3041.                         if (kindLazyFuncTime) {
  3042.                             clearTimeout(kindLazyFuncTime);
  3043.                         };
  3044.                         kindLazyFuncTime = setTimeout(function () {
  3045.                             if (!kindLazyFuncScroll) {
  3046.                                 if (readCookie('rootMarginCookie')) {
  3047.                                     shop2_gr.methods.grLazyFunc({
  3048.                                         selector: lazyElem,
  3049.                                         margin: '200px'
  3050.                                     }, function () {
  3051.  
  3052.                                         setTimeout(function () {
  3053.                                             $(lazyElem).find('.kinds-block__items.kinds_slider .kind-item__top').matchHeight('remove');
  3054.                                             $(lazyElem).find('.kinds-block__items.kinds_slider .kind-item__bottom').matchHeight('remove');
  3055.                                             $(lazyElem).find('.kinds-block__items.kinds_slider .kind-price').matchHeight('remove');
  3056.  
  3057.                                             $(lazyElem).find('.kinds-block__items.kinds_slider .kind-item__top').matchHeight();
  3058.                                             $(lazyElem).find('.kinds-block__items.kinds_slider .kind-item__bottom').matchHeight();
  3059.                                             $(lazyElem).find('.kinds-block__items.kinds_slider .kind-price').matchHeight();
  3060.                                         }, 300);
  3061.                                     });
  3062.                                 } else {
  3063.                                     shop2_gr.methods.grLazyFunc({
  3064.                                         selector: lazyElem
  3065.                                     }, function () {
  3066.                                         setTimeout(function () {
  3067.                                             $(lazyElem).find('.kinds-block__items.kinds_slider .kind-item__top').matchHeight('remove');
  3068.                                             $(lazyElem).find('.kinds-block__items.kinds_slider .kind-item__bottom').matchHeight('remove');
  3069.                                             $(lazyElem).find('.kinds-block__items.kinds_slider .kind-price').matchHeight('remove');
  3070.  
  3071.                                             $(lazyElem).find('.kinds-block__items.kinds_slider .kind-item__top').matchHeight();
  3072.                                             $(lazyElem).find('.kinds-block__items.kinds_slider .kind-item__bottom').matchHeight();
  3073.                                             $(lazyElem).find('.kinds-block__items.kinds_slider .kind-price').matchHeight();
  3074.                                         }, 300);
  3075.                                     });
  3076.                                 };
  3077.                             };
  3078.  
  3079.                             return kindLazyFuncScroll = true;
  3080.                         }, 50);
  3081.                     };
  3082.                 };
  3083.             };
  3084.  
  3085.         },
  3086.         /*Коллекции*/
  3087.         getMainProducts: function (url, active_array_id, empty_products, callback) {
  3088.             $.ajax({
  3089.                 url: url,
  3090.                 dataType: "JSON",
  3091.                 data: {
  3092.                     param: {
  3093.                         s: {
  3094.                             product_id: active_array_id
  3095.                         },
  3096.                         limit: (active_array_id.length + 1),
  3097.                         template: "global:shop2.2.130-product-list.tpl"
  3098.                     }
  3099.                 },
  3100.                 error: (error) => {
  3101.                     alert(error);
  3102.                     console.warn(error);
  3103.                     return false;
  3104.                 },
  3105.                 success: (response) => {
  3106.                     if (response.error) {
  3107.                         console.warn('Ошибка аякса: ', response);
  3108.                     } else if (response.result.success) {
  3109.                         var gr_has_compare = typeof gr_compare_kind_id;
  3110.                         $(response.result.html).find('.shop2-product-item').each(function () {
  3111.                             var _this_item = this;
  3112.                             var id_product = _this_item.querySelector('[name="product_id"]').value;
  3113.                             Array.prototype.forEach.call(empty_products, function (item, i) {
  3114.                                 if (+item.dataset['mainProductId'] == +id_product) {
  3115.                                     item.innerHTML = '';
  3116.                                     item.appendChild(_this_item.cloneNode(true));
  3117.  
  3118.                                     if (gr_has_compare != 'undefined' && gr_compare_kind_id[item.querySelector('[name="kind_id"]').value]) {
  3119.                                         product_compare = item.querySelector('.product-compare');
  3120.                                         product_compare.classList.add('product-compare-added');
  3121.                                         product_compare.innerHTML = `<label class="gr-compare-checkbox">
  3122.                                         <svg class="gr-svg-icon"><use xlink:href="#icon_shop_compare_added"></use></svg>
  3123.                                         <svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_compare_added_small"></use></svg>
  3124.                             <input type="checkbox" value="` + item.querySelector('[name="kind_id"]').value + `" checked="true" autocomplete="off"></label>
  3125.         <a class="link-reset custom-underlined-link" data-remodal-target="compare-preview-popup" href="/magazin/compare" target="_blank">Cравнить&nbsp;<span>` + Object.keys(gr_compare_kind_id).length + `</span></a>
  3126.                 </div>`;
  3127.                                     };
  3128.                                     item.classList.remove('gr_empty_product');
  3129.                                 };
  3130.                             });
  3131.                         });
  3132.  
  3133.                         if (callback) {
  3134.                             callback();
  3135.                         };
  3136.                     }
  3137.                 }
  3138.             });
  3139.         },
  3140.         /*Получение товаров на главной*/
  3141.         grConvertToRgb: function (hexCode) {
  3142.             var hex = hexCode.replace('#', '');
  3143.  
  3144.             if (hex.length === 3) {
  3145.                 hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
  3146.             }
  3147.  
  3148.             var r = parseInt(hex.substring(0, 2), 16),
  3149.                 g = parseInt(hex.substring(2, 4), 16),
  3150.                 b = parseInt(hex.substring(4, 6), 16);
  3151.  
  3152.             return [r, g, b];
  3153.         },
  3154.         /*Конвертация HEX в RGB*/
  3155.         viewLots: function (elem) {
  3156.             if (elem) {
  3157.                 var $productList = $(elem);
  3158.                 var $productItem = $productList.find('.product-item');
  3159.                 var loadedValue = $('.shop-view__item.active-view').data('value');
  3160.             } else {
  3161.                 var $productList = $('.product-list');
  3162.                 var $productItem = $('.product-item');
  3163.                 var loadedValue = $('.shop-view__item.active-view').data('value');
  3164.             };
  3165.  
  3166.             if (loadedValue == 'thumbs') {
  3167.                 $('.product-list-titles').addClass('hide');
  3168.  
  3169.                 $productItem.each(function () {
  3170.                     var $flags = $(this).find('.product-flags');
  3171.                     var $flagsContainer = $(this).find('.product-item__top');
  3172.  
  3173.                     $flags.appendTo($flagsContainer);
  3174.                 });
  3175.             } else if (loadedValue == 'simple') {
  3176.                 $('.product-list-titles').addClass('hide');
  3177.  
  3178.                 $productItem.each(function () {
  3179.                     var $flags = $(this).find('.product-flags');
  3180.                     var $flagsContainer = $(this).find('.product-item__top');
  3181.  
  3182.                     $flags.appendTo($flagsContainer);
  3183.                 });
  3184.             } else if (loadedValue == 'list') {
  3185.                 $('.product-list-titles').removeClass('hide');
  3186.  
  3187.                 $productItem.each(function () {
  3188.                     var $flags = $(this).find('.product-flags');
  3189.                     var $flagsContainer = $(this).find('.product-item__bottom-left');
  3190.  
  3191.                     $flags.prependTo($flagsContainer);
  3192.                 });
  3193.             };
  3194.  
  3195.             $('.shop-view .shop-view__item').on('click', function (e) {
  3196.                 var $this = $(this),
  3197.                     value = $this.data('value');
  3198.  
  3199.                 if (value == 'thumbs') {
  3200.                     $('.product-list-titles').addClass('hide');
  3201.  
  3202.                     $productItem.each(function () {
  3203.                         var $flags = $(this).find('.product-flags');
  3204.                         var $flagsContainer = $(this).find('.product-item__top');
  3205.  
  3206.                         $flags.appendTo($flagsContainer);
  3207.                     });
  3208.                 } else if (value == 'simple') {
  3209.                     $('.product-list-titles').addClass('hide');
  3210.  
  3211.                     $productItem.each(function () {
  3212.                         var $flags = $(this).find('.product-flags');
  3213.                         var $flagsContainer = $(this).find('.product-item__top');
  3214.  
  3215.                         $flags.appendTo($flagsContainer);
  3216.                     });
  3217.                 } else if (value == 'list') {
  3218.                     $('.product-list-titles').removeClass('hide');
  3219.  
  3220.                     $productItem.each(function () {
  3221.                         var $flags = $(this).find('.product-flags');
  3222.                         var $flagsContainer = $(this).find('.product-item__bottom-left');
  3223.  
  3224.                         $flags.prependTo($flagsContainer);
  3225.                     });
  3226.                 };
  3227.  
  3228.                 $this
  3229.                     .addClass('active-view')
  3230.                     .siblings()
  3231.                     .removeClass('active-view');
  3232.  
  3233.                 if ($productList.length > 0) {
  3234.                     $productList
  3235.                         .removeClass($productList.attr('class').replace(/[a-zA-Z0-9_-]+(?=\s)/, ""))
  3236.                         .addClass(value);
  3237.                 };
  3238.  
  3239.                 $(this).parents('.shop-view__inner').removeClass('active');
  3240.  
  3241.                 createCookie('views', value, 30);
  3242.  
  3243.                 setTimeout(function () {
  3244.                     $.fn.matchHeight._update();
  3245.                 }, 300);
  3246.  
  3247.                 e.preventDefault();
  3248.  
  3249.                 return false;
  3250.             });
  3251.         },
  3252.         /*Преключение видов отображения товаров в категории*/
  3253.         amountInit: function (elem) {
  3254.             var items = '.cart-products__item, .shop2-product-item, .shop2-product, .kind-item, .popup-product';
  3255.             if (elem) {
  3256.                 var items = elem;
  3257.             };
  3258.             $(items).each(function () {
  3259.                 var $this = $(this);
  3260.                 var $amountWrap = $this.find('.shop2-product-amount');
  3261.                 var $input = $amountWrap.find('input[type="text"]');
  3262.                 var $buttons = $amountWrap.find('button');
  3263.                 var $minus = $amountWrap.find('button.amount-minus');
  3264.                 var $plus = $amountWrap.find('button.amount-plus');
  3265.                 var min = $amountWrap.find('input').data('min');
  3266.                 var inputVal = +$input.val();
  3267.  
  3268.  
  3269.                 if (inputVal <= min) {
  3270.                     $minus.attr('disabled', 'disabled');
  3271.                 }
  3272.  
  3273.                 $buttons.on('click', function () {
  3274.                     var parent = $(this).parent();
  3275.                     var input = parent.find('input');
  3276.  
  3277.                     setTimeout(function () {
  3278.                         var inputVal = +input.val();
  3279.  
  3280.                         if (inputVal <= min) {
  3281.                             $minus.attr('disabled', 'disabled');
  3282.                         } else {
  3283.                             $minus.removeAttr('disabled');
  3284.                         }
  3285.                     }, 100);
  3286.                 });
  3287.  
  3288.                 $input.on('change', function (e) {
  3289.                     var curVal = +$(this).val();
  3290.  
  3291.                     if (curVal < min) {
  3292.                         $(this).val(min);
  3293.                     } else if (curVal == min) {
  3294.                         $minus.attr('disabled', 'disabled');
  3295.                     } else if (curVal > min) {
  3296.                         $minus.removeAttr('disabled');
  3297.                     }
  3298.                 });
  3299.             });
  3300.         },
  3301.         /*Количество*/
  3302.         arrowsPosition: function (slider, item) {
  3303.             if ($(slider).length) {
  3304.                 var arrows_timeout;
  3305.  
  3306.                 $(slider).each(function () {
  3307.                     var $this = $(this);
  3308.                     var $image = $this.find(item);
  3309.                     var $controls = $this.parents('.tns-outer').find('.tns-controls');
  3310.  
  3311.                     if ($image.parents('form').length) {
  3312.                         var paddingTop = $image.offset().top - $image.parents('form').offset().top;
  3313.                         var imgHeight = ($image.outerHeight() + paddingTop) - ($image.outerHeight() / 2);
  3314.                     } else {
  3315.                         var imgHeight = $image.outerHeight() / 2;
  3316.                     };
  3317.  
  3318.                     $controls.css({
  3319.                         "top": imgHeight
  3320.                     });
  3321.                 });
  3322.  
  3323.                 $(window).on('resize', function () {
  3324.                     if (arrows_timeout) {
  3325.                         clearTimeout(arrows_timeout);
  3326.                     };
  3327.  
  3328.                     arrows_timeout = setTimeout(function () {
  3329.                         $(slider).each(function () {
  3330.                             var $this = $(this);
  3331.                             var $image = $this.find(item);
  3332.                             var $controls = $this.parents('.tns-outer').find('.tns-controls');
  3333.  
  3334.                             if ($image.parents('form').length) {
  3335.                                 var paddingTop = $image.offset().top - $image.parents('form').offset().top;
  3336.                                 var imgHeight = ($image.outerHeight() + paddingTop) - ($image.outerHeight() / 2);
  3337.                             } else {
  3338.                                 var imgHeight = $image.outerHeight() / 2;
  3339.                             };
  3340.  
  3341.                             $controls.css({
  3342.                                 "top": imgHeight
  3343.                             });
  3344.                         });
  3345.                     }, 50);
  3346.                 });
  3347.             };
  3348.         },
  3349.         /*Позиционирование навигации слайдера относительно блоков*/
  3350.         formBlock: function (lazyElem) {
  3351.             /*if (document.querySelector('.form-block')!=null) {*/
  3352.             if ($(lazyElem) != null) {
  3353.                 var container = lazyElem.querySelector('.header-callback__container');
  3354.                 var api_url = container.getAttribute('data-api-url');
  3355.  
  3356.                 $.ajax({
  3357.                     url: api_url,
  3358.                     dataType: 'json',
  3359.                     success: function (response) {
  3360.                         if (!response.result.error) {
  3361.  
  3362.                             /*container.innerHTML = response.result.html;*/
  3363.                             $(container).append(response.result.html);
  3364.  
  3365.                             s3From.initForms();
  3366.                             grFormDatePicker.init();
  3367.  
  3368.                         }
  3369.                     }
  3370.                 });
  3371.             };
  3372.         },
  3373.         siteFormBlock: function(lazyElem){
  3374.             if (document.querySelector('.site-forms-block')!=null) {
  3375.                 var container = lazyElem.querySelector('.site-forms-block__form');
  3376.                 var api_url = container.getAttribute('data-api-url');
  3377.                
  3378.                 $.ajax({
  3379.                     url: api_url,
  3380.                     dataType: 'json',
  3381.                     success: function(response) {
  3382.                         if (!response.result.error) {
  3383.                            
  3384.                             $(container).append(response.result.html);
  3385.                            
  3386.                             s3From.initForms();
  3387.                             grFormDatePicker.init();
  3388.                        
  3389.                         }
  3390.                     }
  3391.                 });
  3392.             };
  3393.         }, /* Форма в блоке*/
  3394.         sliderBlock: function(lazyElem){
  3395.             var slider = lazyElem.querySelector('.js__main_slider-block');
  3396.  
  3397.             if (!!slider) {
  3398.                 var sliderAutoplay = +slider.getAttribute('data-autoplay');
  3399.  
  3400.                 var mslider = tns({
  3401.                     loop: true,
  3402.                     container: slider,
  3403.                     autoHeight: true,
  3404.                     slideBy: 1,
  3405.                     items: 1,
  3406.                     swipeAngle: true,
  3407.                     speed: 500,
  3408.                     autoplayHoverPause: true,
  3409.                     autoplay: sliderAutoplay,
  3410.                     autoplayButtonOutput: false,
  3411.                     controlsText: shop2_gr.settings.sliderControls,
  3412.                     preventActionWhenRunning: false,
  3413.                     controls: true,
  3414.                     lazyload: true,
  3415.                     navPosition: 'bottom',
  3416.                     controlsPosition: 'bottom',
  3417.                     controlsContainer: lazyElem.querySelector('.slider-controls'),
  3418.                     navContainer: lazyElem.querySelector('.slide-counter__del'),
  3419.  
  3420.                     responsive: {
  3421.                         0: {
  3422.                             controls: true,
  3423.                             nav: true,
  3424.                             gutter: 20
  3425.                         }
  3426.                     }
  3427.                 });
  3428.  
  3429.                 var info = mslider.getInfo(),
  3430.                     current = lazyElem.querySelector('.slide-counter__num'),
  3431.                     total = lazyElem.querySelector('.slide-counter__all');
  3432.  
  3433.                 current.textContent = mslider.getInfo().displayIndex;
  3434.                 total.textContent = info.slideCount;
  3435.  
  3436.                 mslider.events.on("indexChanged", function () {
  3437.                     current.textContent = mslider.getInfo().displayIndex;
  3438.                     total.textContent = info.slideCount;
  3439.                 });
  3440.             };
  3441.         },
  3442.         handleResizeController: function (strMediaQuery, funСatchMedia, funМissMedia) {
  3443.             let handleResize = function () {
  3444.                 let mediaQuery = window.matchMedia(strMediaQuery);
  3445.                 let resTimeout;
  3446.  
  3447.                 function mediaQueryChange(e) {
  3448.                     if (resTimeout) {
  3449.                         clearTimeout(resTimeout);
  3450.                     }
  3451.                     resTimeout = setTimeout(function () {
  3452.                         if (e.matches) {
  3453.                             if (typeof funСatchMedia === 'function')
  3454.                                 funСatchMedia();
  3455.                         } else {
  3456.                             if (typeof funМissMedia === 'function')
  3457.                                 funМissMedia();
  3458.                         }
  3459.  
  3460.                     }, 50)
  3461.                 }
  3462.                 mediaQuery.addListener(mediaQueryChange);
  3463.  
  3464.                 mediaQueryChange(mediaQuery);
  3465.             }
  3466.             return handleResize;
  3467.         }
  3468.     }
  3469.  
  3470.     shop2_gr.init();
  3471.     myObject.shop2_gr = shop2_gr;
  3472.  
  3473.  
  3474.     // Обновленное API      
  3475.     $(function () {
  3476.  
  3477.         $(document).on('click', '#shop2-color-ext-select li', function () {
  3478.             if (shop2.facets.enabled) {
  3479.                 setTimeout(function () {
  3480.                     var url = '/-/x-api/v1/public/?method=shop2/getSearchMatches';
  3481.  
  3482.                     var formData = $(shop2.facets.search.wrapper).serialize();
  3483.                     console.log(formData)
  3484.  
  3485.                     shop2.facets.getDataSearch(url, formData);
  3486.                 }, 100);
  3487.             };
  3488.         });
  3489.  
  3490.         $(document.body).on('change', '.shop2-block.search-form #shop2_search_custom_fields select, .shop2-block.search-form #shop2_search_custom_fields input', function () {
  3491.             if (shop2.facets.enabled) {
  3492.                 setTimeout(function () {
  3493.                     var url = '/-/x-api/v1/public/?method=shop2/getSearchMatches';
  3494.  
  3495.                     var formData = $(shop2.facets.search.wrapper).serialize();
  3496.  
  3497.                     shop2.facets.getDataSearch(url, formData);
  3498.                 }, 100);
  3499.             };
  3500.         });
  3501.     });
  3502.  
  3503. })(jQuery, window);
Advertisement
Add Comment
Please, Sign In to add comment