Advertisement
Igor150195

multishop_main.js

Feb 3rd, 2021
995
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.addEventListener("DOMContentLoaded", function() {
  2.     const imageObserver = new IntersectionObserver((entries, imgObserver) => {
  3.         entries.forEach((entry) => {
  4.             if (entry.isIntersecting) {
  5.  
  6.                 const lazyImage = entry.target;
  7.                
  8.                 if (lazyImage.tagName == 'IMG') {
  9.                     lazyImage.src = lazyImage.dataset.src;
  10.                 } else {
  11.                     lazyImage.style.backgroundImage = 'url('+ lazyImage.dataset.src +')';
  12.                 }
  13.                
  14.                 lazyImage.classList.remove("gr_images_lazy_load");
  15.                 imgObserver.unobserve(lazyImage);
  16.             }
  17.         })
  18.     });
  19.     const arr = document.querySelectorAll(".gr_images_lazy_load");
  20.    
  21.     arr.forEach((v) => {
  22.         imageObserver.observe(v);
  23.     })
  24. });
  25.  
  26. shop2.facets.search.wrapper = "";
  27. shop2.options.msgTime = 2000;
  28.  
  29. shop2.msg = function(text, obj) {
  30.     var selector = '#shop2-msg',
  31.         msg = $(selector),
  32.         offset = obj.offset(),
  33.         width = obj.outerWidth(true),
  34.         height = obj.outerHeight(true);
  35.  
  36.     if (!msg.get(0)) {
  37.         msg = $('<div id="shop2-msg">');
  38.         $(document.body).append(msg);
  39.         msg = $(selector);
  40.     }
  41.  
  42.     msg.html(text).fadeIn(150);
  43.  
  44.     var msgWidth = msg.outerWidth();
  45.     var msgHeight = msg.outerHeight();
  46.     var left = offset.left + width;
  47.     var top = offset.top + height;
  48.  
  49.     if (left + msgWidth > $(window).width()) {
  50.         left = offset.left - msgWidth;
  51.     }
  52.  
  53.     msg.css({
  54.         left: 50 + '%',
  55.         top: 50 + '%',
  56.         'position': 'fixed',
  57.         'margin-left': msgWidth / 2 * -1,
  58.         'margin-top': msgHeight / 2 * -1
  59.     });
  60.    
  61.     $.s3throttle('msg', function() {
  62.         msg.hide();
  63.     }, shop2.options.msgTime);
  64.  
  65.     $(document).on('click', '#shop2-msg', function() {
  66.         $(this).fadeOut(150);
  67.     });
  68. };
  69.  
  70. shop2.queue.compare = function() {
  71.  
  72.     var $document = $(document);
  73.     if ($('html').attr('lang') == 'ru') {
  74.         var compareBtn = '<a href="' + shop2.uri + '/compare" class="go-to-compare-btn" target="_blank">к сравнению</a>';
  75.         var compareBtn2 = '<a href="' + shop2.uri + '/compare" class="go-to-compare-btn" target="_blank">Перейти к сравнению</a>';
  76.     } else {
  77.         var compareBtn = '<a href="' + shop2.uri + '/compare" class="go-to-compare-btn" target="_blank">сompare</a>';
  78.         var compareBtn2 = '<a href="' + shop2.uri + '/compare" class="go-to-compare-btn" target="_blank">Compare</a>';
  79.     };
  80.  
  81.     function update(el, res) {
  82.  
  83.         $('input[type=checkbox][value=' + el.val() + ']').closest('.product-compare').replaceWith(res.data);
  84.         $('.product-compare-added a span').html(res.count);
  85.         $('.gr-compare-btn .gr-compare-btn-amount').html(res.count);
  86.        
  87.         if (+$('.gr-compare-btn .gr-compare-btn-amount').text() == '0') {
  88.             $('.gr-compare-btn').removeClass('active');
  89.         } else {
  90.             $('.gr-compare-btn').addClass('active');
  91.         };
  92.        
  93.         if (!$('.compare-remodal').hasClass('remodal-is-opened')) {
  94.             if ($('html').attr('lang') == 'ru') {
  95.                 shop2.msg('Товар добавлен ' + compareBtn + '&nbsp;&nbsp;' + res.count, $('body'));
  96.             } else {
  97.                 shop2.msg('Added to ' + compareBtn + '&nbsp;&nbsp;' + res.count, $('body'));
  98.             };
  99.         };
  100.  
  101.         if (res.panel) {
  102.             $('#shop2-panel').replaceWith(res.panel);
  103.         };
  104.  
  105.     }
  106.  
  107.     $document.on('click', '.product-compare input:checkbox', function() {
  108.         var $this = $(this),
  109.             action = $this.attr('checked') ? 'del' : 'add';
  110.            
  111.         shop2.compare.action(action, $this.val(), function(res, status) {
  112.             if (status == 'success') {
  113.                
  114.  
  115.                 if (res.errstr) {
  116.                     if (!$('.compare-remodal').hasClass('remodal-is-opened')) {
  117.                         shop2.msg(res.errstr + '&nbsp;<br>' + compareBtn2, $('body'));
  118.                     }
  119.                     $this.prop('checked', false);
  120.                 } else {
  121.                     update($this, res);
  122.                    
  123.                     if (action == 'del' && !$('.compare-remodal').hasClass('remodal-is-opened')) {
  124.                         if ($('html').attr('lang') == 'ru') {
  125.                             shop2.msg('Товар удален из сравнения', $('body'));
  126.                         } else {
  127.                             shop2.msg('Product removed from comparison', $('body'));
  128.                         };
  129.                     }
  130.                 }
  131.                
  132.             }
  133.         });
  134.     });
  135. };
  136.  
  137. shop2.product.getProductListItem = function(product_id, kind_id, func) {
  138.     var gr_images_size = $('.product-list').data('images-size');
  139.     var gr_images_view = $(".product-list").data("images-view");
  140.     var gr_mode_catalog = $(".product-list").data("mode-catalog");
  141.     var url = "/my/s3/api/shop2/?cmd=getProductListItem&hash=" + shop2.apiHash.getProductListItem + "&ver_id=" + shop2.verId + "&gr_images_view=" + gr_images_view + "&gr_images_size=" + gr_images_size + "&gr_mode_catalog=" + gr_mode_catalog;
  142.    
  143.     shop2.trigger('beforeGetProductListItem');
  144.  
  145.     $.post(
  146.         url, {
  147.             product_id: product_id,
  148.             kind_id: kind_id
  149.         },
  150.         function(d, status) {
  151.             shop2.fire('afterGetProductListItem', func, d, status);
  152.             shop2.trigger('afterGetProductListItem', d, status);
  153.         }
  154.     );
  155. };
  156.  
  157. shop2.queue.lazyLoad = function() {
  158.     var $document = $(document),
  159.         $window = $(window),
  160.         blocked = false,
  161.         products = $('.product-list');
  162.  
  163.     function path(url, param, value) {
  164.         return url + (~url.indexOf("?") ? "&" : "?") + param + "=" + value;
  165.     }
  166.    
  167.     if (shop2.my.lazy_load_subpages && products.get(0)) {
  168.         $document.on('click', '.lazy-pagelist-btn', function(e){
  169.            
  170.             e.preventDefault();
  171.            
  172.             var pagelist = $('.shop-pagelist');
  173.             var next = pagelist.find('.active-num').next().find('a');
  174.  
  175.             if (!next.length) {
  176.                 return;
  177.             }
  178.  
  179.             if (!blocked && next.get(0)) {
  180.                 blocked = true;
  181.              
  182.                 $.get(path(next.attr('href'), 'products_only', 1), function(data) {
  183.                     var productsHtml = $(data).filter('.product-list').html();
  184.                     var $lazyLoad = $(data).filter('.lazy-pagelist');
  185.                    
  186.                     $('.lazy-pagelist').remove();
  187.                    
  188.                     $('.product-list').append(productsHtml);
  189.                     $('.product-list').after($lazyLoad);
  190.                    
  191.                     $('.product-list .gr_images_lazy_load').each(function(){
  192.                         $(this).attr('src', $(this).attr('data-src'));
  193.                     });
  194.                    
  195.                     $('.quick-view-trigger').elemToolTip({
  196.                         text: 'Быстрый просмотр',
  197.                         margin: 12
  198.                     });
  199.                    
  200.                     $('.product-additional__top-right').matchHeight();
  201.                     $('.product-list.thumbs .product-item .product-price').matchHeight();
  202.                    
  203.                     shop2_gr.methods.viewLots();
  204.                     shop2_gr.methods.amountInit();
  205.                    
  206.                     pagelist = $('.shop-pagelist');
  207.                    
  208.                     pagelist.find('a').each(function() {
  209.                         var $this = $(this),
  210.                             href = $this.attr('href');
  211.                         $this.attr('href', href.replace(/[&|\?]*products_only=[^&]/, ""));
  212.                     });
  213.  
  214.                     blocked = false;
  215.                 });
  216.             }
  217.         });
  218.     }
  219. };
  220.  
  221. shop2.queue.addToCart = function() {
  222.     $(document).on('click', '.shop-product-btn', function(e) {
  223.  
  224.         var $this = $(this),
  225.             $form = $this.closest('form'),
  226.             form = $form.get(0),
  227.             adds = $form.find('.additional-cart-params'),
  228.             len = adds.length,
  229.             i, el,
  230.             a4 = form.amount.value,
  231.             kind_id = form.kind_id.value;
  232.    
  233.         e.preventDefault();
  234.  
  235.         if (len) {
  236.             a4 = {
  237.                 amount: a4
  238.             };
  239.  
  240.             for (i = 0; i < len; i += 1) {
  241.                 el = adds[i];
  242.                 if (el.value) {
  243.                     a4[el.name] = el.value;
  244.                 }
  245.             }
  246.         }
  247.        
  248.         shop2.cart.add(kind_id, a4, function(d) {
  249.             $('#shop2-cart-preview').replaceWith(d.data);
  250.            
  251.             var totalCartAmount = +$(d.data).find('.gr-cart-total-amount').text();
  252.             var totalCartSum = $(d.data).find('.gr-cart-total-sum').data('total-price');
  253.            
  254.             if (totalCartAmount>0) {
  255.                 $('.gr-cart-popup-btn').removeClass('pointer_events_none');
  256.                 $('.gr-cart-total-amount').text(totalCartAmount);
  257.                 $('.gr-cart-total-sum ins').text(totalCartSum);
  258.             } else{
  259.                 $('.gr-cart-popup-btn').addClass('pointer_events_none');
  260.                 $('.gr-cart-total-amount').text('0');
  261.                 $('.gr-cart-total-sum ins').text('0');
  262.             };
  263.  
  264.             if (d.errstr) {
  265.                 shop2.msg(d.errstr, $this);
  266.             } else {
  267.                 var $text = window._s3Lang.JS_SHOP2_ADD_CART_WITH_LINK;
  268.                
  269.                 shop2.msg($text.replace("%s", shop2.uri + "/cart"), $this);
  270.             }
  271.  
  272.             if (d.panel) {
  273.                 $('#shop2-panel').replaceWith(d.panel);
  274.             };
  275.         });
  276.     });
  277. };
  278.  
  279. shop2.filter.sort = function(name, elem) {
  280.     var re = new RegExp(this.escape('s[sort_by]') + '=([^&]*)'),
  281.         params = this.str.match(re),
  282.         desc = name + ' desc',
  283.         asc = name + ' asc',
  284.         isDesc = (elem.is('.sort-param-desc'));
  285.  
  286.  
  287.     params = (params && params.length > 1) ? params[1] : "";
  288.    
  289.     params = (isDesc) ? desc : asc;
  290.  
  291.     this.remove('s[sort_by]');
  292.     this.add('s[sort_by]', params);
  293.     return this;
  294. };
  295.  
  296. shop2.queue.sort = function() {
  297.     var wrap = $('.sorting');
  298.  
  299.     wrap.find('.sort-param').on('click', function(e) {
  300.         var $this = $(this),
  301.             name = $this.data('name');
  302.  
  303.         e.preventDefault();
  304.         shop2.filter.sort(name, $this);
  305.         shop2.filter.go();
  306.     });
  307.  
  308.     wrap.find('.sort-reset').on('click', function(e) {
  309.         e.preventDefault();
  310.         shop2.filter.remove('s[sort_by]');
  311.         shop2.filter.go();
  312.     });
  313. };
  314.  
  315. shop2.queue.colorPopup = function() {
  316.     var handle;
  317.  
  318.     $(document).on('click', '.shop2-color-ext-list li', function() {
  319.         var caption = $(this);
  320.         var wrap = caption.closest('.shop2-color-ext-popup');
  321.         var ul = wrap.find('.shop2-color-ext-list');
  322.         var offset = caption.offset();
  323.         var $this = $(this);
  324.         var data = $this.data();
  325.         var input = $this.parent().find('input.additional-cart-params');
  326.         var isSelected = $this.is('.shop2-color-ext-selected');
  327.  
  328.         colors = ul.children('li');
  329.  
  330.         if (typeof data.kinds !== 'undefined' || input.length) {
  331.             $this.addClass('shop2-color-ext-selected').siblings().removeClass('shop2-color-ext-selected');
  332.  
  333.             if (input.length) {
  334.                 input.val(data.value);
  335.             } else {
  336.                 if (!isSelected) {
  337.                     shop2.product._reload(this);
  338.                 }
  339.             }
  340.  
  341.         } else {
  342.             var index = $this.index();
  343.            
  344.             colors.eq(index).toggleClass('shop2-color-ext-selected');
  345.             shop2.filter.toggle(data.name, data.value);
  346.             shop2.filter.count();
  347.  
  348.             var offsetTop = $(this).position().top;
  349.  
  350.             $('.result-popup').css({
  351.                 'top': offsetTop,
  352.                 'visibility': 'visible',
  353.                 'opacity': '1',
  354.                 'display': 'block'
  355.             });
  356.  
  357.         }
  358.         return false;
  359.     });
  360. };
  361.  
  362.  
  363. (function($, myObject) {
  364.    
  365.     var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),
  366.         isApple = /iPod|iPad|iPhone/i.test(navigator.userAgent),
  367.         $doc = $(document),
  368.         $win = $(window),
  369.         $html = $(document.documentElement);
  370.        
  371.     var shop2_gr = {
  372.         queue: {},
  373.         methods : {},
  374.         init: function() {
  375.  
  376.             $(function() {
  377.  
  378.                 let queue = shop2_gr.queue;
  379.  
  380.                 if (isMobile) $html.addClass('mobile');
  381.  
  382.                 for (key in queue) {
  383.                     let f = queue[key];
  384.                     if (typeof f === 'function') {
  385.                         f();
  386.                     };
  387.                 }
  388.                
  389.             });
  390.  
  391.         }
  392.     };
  393.  
  394.     shop2_gr.queue = {
  395.  
  396.         ajaxRequestsComplete: function() {
  397.  
  398.             /*$.ajaxSetup({
  399.                 complete: function() {
  400.                    
  401.                 }
  402.             });*/
  403.  
  404.             shop2.on('afterProductReloaded', function(){
  405.                 setTimeout(function(){
  406.                     shop2_gr.methods.viewLots();
  407.                     shop2_gr.methods.amountInit();
  408.  
  409.                     $('.shop2-product-item .buy-one-click').attr('data-api-url', $('.product-list').data('popup-form'));
  410.  
  411.                     $('.product-list .gr_images_lazy_load').each(function(){
  412.                         $(this).attr('src', $(this).attr('data-src'));
  413.                     });
  414.  
  415.                     $('.quick-view-trigger').elemToolTip({
  416.                         text: 'Быстрый просмотр',
  417.                         margin: 12
  418.                     });
  419.                    
  420.                     $('#shop2-tooltip').hide();
  421.                     $('.main-blocks .product-list.thumbs .product-item__bottom').matchHeight();
  422.                 });
  423.                 $.fn.matchHeight._update();
  424.             });
  425.  
  426.         }, /*Обновление скриптов при аякс-запросах*/
  427.        
  428.         ajaxCompare: function(){
  429.             /*if (shop2.mode=="") {
  430.                 var url = document.location.origin;
  431.                 $.ajax({
  432.                     url: url,
  433.                         success: function(data){
  434.                         var html = $(data).find('.gr-compare-btn');
  435.                         $('.gr-compare-btn').replaceWith(html);
  436.                     }
  437.                 });
  438.             }*/
  439.         }, /*Сравнение на страницах "не магазина"*/
  440.  
  441.         checkboxes: function() {
  442.             $('#orderForm input[name="personal_data"]').parents('label').next('a').appendTo($('#orderForm input[name="personal_data"]').parents('label'));
  443.            
  444.             $('.shop2-order-form input[type="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();
  445.            
  446.             $('#orderForm .mg-styler-label--checkbox a').on('click', function(e){
  447.                 var $label = $(this).parent();
  448.                 var $input = $(this).parents('label').find('input');
  449.                 var href = $(this).attr('href');
  450.                 window.open(href, '_blank');
  451.                
  452.                 if ($('.mg-styler-label--checkbox input').is(':checked')) {
  453.                     setTimeout(function(){
  454.                         $input.prop('checked', true);
  455.                         $label.addClass('checked');
  456.                     }, 10);
  457.                 } else {
  458.                     setTimeout(function(){
  459.                         $input.prop('checked', false);
  460.                         $label.removeClass('checked');
  461.                     }, 10);
  462.                 }
  463.             });
  464.  
  465.             $(document).on('click', '.shop2-edost-variant > label', function(){
  466.                 if ($('.shop2-edost-variant > label > .shop2-edost-control input[type="radio"]:checked')) {
  467.                     $('.shop2-edost-variant > label > .shop2-edost-control').removeClass("active");
  468.                     $('.shop2-edost-variant > label > .shop2-edost-control input[type="radio"]:checked').parent().addClass('active');
  469.                 }
  470.                
  471.                 if ($('.shop2-edost-office > label > .shop2-edost-control input[type="radio"]:checked')) {
  472.                     $('.shop2-edost-office > label > .shop2-edost-control').removeClass("active");
  473.                     $('.shop2-edost-office > label > .shop2-edost-control input[type="radio"]:checked').parent().addClass('active');
  474.                 }
  475.             });
  476.  
  477.             $(document).on("click", ".shop2-edost-office > label", function(){
  478.                 if ($('.shop2-edost-office > label > .shop2-edost-control input[type="radio"]:checked')) {
  479.                     $('.shop2-edost-office > label > .shop2-edost-control').removeClass("active");
  480.                     $('.shop2-edost-office > label > .shop2-edost-control input[type="radio"]:checked').parent().addClass('active');
  481.                 }
  482.             });
  483.         }, /*Чекбоксы*/
  484.  
  485.         colorSelect: function() {
  486.  
  487.             $(document).on('click', '.shop-search-color-select li', function(){
  488.                 var $input = $(this).find('input');
  489.                 var value = $(this).data('value');
  490.  
  491.                 if ($(this).hasClass('shop2-color-ext-selected')) {
  492.                     $input.val("");
  493.                     $(this).removeClass('shop2-color-ext-selected');
  494.                 } else {
  495.                     $(this).addClass('shop2-color-ext-selected');
  496.                     $input.val(value);
  497.                 }
  498.                
  499.                 var url = '/my/s3/api/shop2/?cmd=getSearchMatches&hash=' +
  500.                     shop2.apiHash.getSearchMatches +
  501.                     '&ver_id=' + shop2.verId + '&',
  502.                     fullUrl = url + $(shop2.facets.search.wrapper).serialize();
  503.            
  504.                 shop2.facets.getDataSearch(fullUrl);
  505.             });
  506.  
  507.         }, /*Допполе "Цвет" в фасетном поиске*/
  508.  
  509.         topSlider: function() {
  510.  
  511.             var sliders = document.querySelectorAll('.site-top-slider__items');
  512.  
  513.             shop2_gr.methods.forEach(sliders, function(index, value) {
  514.                 var sliderAutoplay = +sliders[index].getAttribute('data-autoplay');
  515.                 var multislider = tns({
  516.                     loop: false,
  517.                     rewind: true,
  518.                     container: value,
  519.                     slideBy: 1,
  520.                     items: 1,
  521.                     autoplayHoverPause: true,
  522.                     mode: 'carousel',
  523.                     axis: 'horizontal',
  524.                     autoplay: sliderAutoplay,
  525.                     autoplayButtonOutput: false,
  526.                     mouseDrag: true,
  527.                     center: false,
  528.                     autoWidth: false,
  529.                     nav: true,
  530.                     swipeAngle: 50,
  531.                     lazyload: true,
  532.                     controlsText: ['<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>'],
  533.                     navPosition: 'bottom',
  534.                     preventActionWhenRunning: false,
  535.                     responsive: {
  536.                         320: {
  537.                             autoHeight: true,
  538.                             controls: false
  539.                         },
  540.                         768: {
  541.                             autoHeight: true,
  542.                             controls: false
  543.                         },
  544.                         1024: {
  545.                             autoHeight: false,
  546.                             controls: false
  547.                         },
  548.                         1261: {
  549.                             autoHeight: false,
  550.                             controls: true
  551.                         }
  552.                     }
  553.                 });
  554.  
  555.                 shop2_gr.methods.arrowsPosition('.site-top-slider__items', '.site-top-slider__pic');
  556.             });
  557.  
  558.         }, /*Слайдер в шапке*/
  559.        
  560.         mainBlocks: function() {
  561.            
  562.             if (shop2.mode == 'main' && $('.main-products').length) {
  563.                 $('.product-list').removeClass('simple').removeClass('list').addClass('thumbs');
  564.             }
  565.            
  566.             var $mainBlocksClass = $('.main_blocks_list');
  567.  
  568.             if ($mainBlocksClass.length>0) {
  569.                 var sliderAutoplay = $('.main_blocks_list').data('autoplay');
  570.                 var main_items = $('.main_blocks_list').data('main-items');
  571.  
  572.                 if (main_items == 5) {
  573.                     $mainBlocksClass.addClass('main_columns_5');
  574.                     var main_items_1920 = 7,
  575.                         main_items_1600 = 6,
  576.                         main_items_1440 = 5,
  577.                         main_items_1366 = 5,
  578.                         main_items_1280 = 4,
  579.                         main_items_1024 = 4,
  580.                         main_items_768 = 3,
  581.                         main_items_320 = 2;
  582.                 } else if (main_items == 4) {
  583.                     $mainBlocksClass.addClass('main_columns_4');
  584.                     var main_items_1920 = 5,
  585.                         main_items_1600 = 4,
  586.                         main_items_1440 = 4,
  587.                         main_items_1366 = 4,
  588.                         main_items_1280 = 4,
  589.                         main_items_1024 = 4,
  590.                         main_items_768 = 3,
  591.                         main_items_320 = 2;
  592.                 } else if (main_items == 3) {
  593.                     $mainBlocksClass.addClass('main_columns_3');
  594.                     var main_items_1920 = 4,
  595.                         main_items_1600 = 4,
  596.                         main_items_1440 = 3,
  597.                         main_items_1366 = 3,
  598.                         main_items_1280 = 3,
  599.                         main_items_1024 = 3,
  600.                         main_items_768 = 3,
  601.                         main_items_320 = 2;
  602.                 } else if (main_items == 2) {
  603.                     $mainBlocksClass.addClass('main_columns_2');
  604.                     var main_items_1920 = 3,
  605.                         main_items_1600 = 3,
  606.                         main_items_1440 = 3,
  607.                         main_items_1366 = 2,
  608.                         main_items_1280 = 2,
  609.                         main_items_1024 = 2,
  610.                         main_items_768 = 2,
  611.                         main_items_320 = 2;
  612.                 }
  613.                
  614.                 // tiny-slider initialisation
  615.                 var sliders = document.querySelectorAll('.main_blocks_list');
  616.                 shop2_gr.methods.forEach(sliders, function(index, value) {
  617.                     var multislider = tns({
  618.                         loop: false,
  619.                         rewind: true,
  620.                         container: value,
  621.                         slideBy: 1,
  622.                         autoplayHoverPause: true,
  623.                         mode: 'carousel',
  624.                         axis: 'horizontal',
  625.                         autoplay: sliderAutoplay,
  626.                         autoplayButtonOutput: false,
  627.                         mouseDrag: true,
  628.                         center: false,
  629.                         autoWidth: false,
  630.                         nav: true,
  631.                         swipeAngle: 50,
  632.                         controlsText: ['<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>'],
  633.                         navPosition: 'bottom',
  634.                         preventActionWhenRunning: false,
  635.                         responsive: {
  636.                             320: {
  637.                                 controls: false,
  638.                                 items: main_items_320,
  639.                                 gutter: 12
  640.                             },
  641.                             768: {
  642.                                 controls: false,
  643.                                 items: main_items_768,
  644.                                 gutter: 20
  645.                             },
  646.                             1024: {
  647.                                 controls: false,
  648.                                 items: main_items_1024,
  649.                                 gutter: 20
  650.                             },
  651.                             1261: {
  652.                                 controls: true,
  653.                                 items: main_items_1280,
  654.                                 gutter: 20
  655.                             },
  656.                             1341: {
  657.                                 controls: true,
  658.                                 items: main_items_1366,
  659.                                 gutter: 20
  660.                             },
  661.                             1367: {
  662.                                 controls: true,
  663.                                 items: main_items_1440,
  664.                                 gutter: 20
  665.                             },
  666.                             1441: {
  667.                                 controls: true,
  668.                                 items: main_items_1600,
  669.                                 gutter: 20
  670.                             },
  671.                             1601: {
  672.                                 controls: true,
  673.                                 items: main_items_1920,
  674.                                 gutter: 20
  675.                             }
  676.                         }
  677.                     });
  678.                 });
  679.             }
  680.                
  681.         }, /*Блоки на главной*/
  682.        
  683.         sortingPanel : function() {
  684.  
  685.             $('.shop-view').on('click', '.shop-view__btn', function(){
  686.                 $(this).parents('.shop-view__inner').toggleClass('active');
  687.             });
  688.  
  689.             $(document).on('click', function(e){
  690.                 if (!$(e.target).closest('.shop-view .shop-view__btn').length) {
  691.                     $('.shop-view .shop-view__inner').removeClass('active');
  692.                 };
  693.             });
  694.  
  695.             $(document).on('click', '.sorting-button', function(){
  696.                 $('.sorting-block').addClass('active');
  697.             });
  698.  
  699.             $(document).on('click', '.sorting-block__title', function(){
  700.                 $('.sorting-block').removeClass('active');
  701.             });
  702.  
  703.             shop2_gr.methods.viewLots();
  704.            
  705.         }, /*Сортировка и виды*/
  706.  
  707.         searchBlock: function() {
  708.  
  709.             $(document).on('click', '.search-form .row-title', function(){
  710.                 $(this).toggleClass('active');
  711.                 $(this).next().slideToggle(250);
  712.             });
  713.            
  714.             function searchMoreFields() {
  715.                 $('.search-rows__row').each(function() {
  716.                     var $this            = $(this);
  717.                     var $btn             = $this.find('.gr-filter-more__btn');
  718.                     var hideText         = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
  719.    
  720.                     $btn.off('click').on('click', function(){
  721.                         var $hiddenCkeckbox  = $this.find('ul li:hidden');
  722.                         var currentText  = $btn.data('text');
  723.    
  724.                         $hiddenCkeckbox.addClass('hidden_item');
  725.    
  726.                         if ($this.find('.hidden_item').hasClass('active')) {
  727.                             $btn.find('.gr-filter-more__text').text(currentText);
  728.                             $this.find('.hidden_item').removeClass('active');
  729.                         } else {
  730.                             $btn.find('.gr-filter-more__text').text(hideText);
  731.                             $this.find('.hidden_item').addClass('active');
  732.                         };
  733.                     });
  734.                 });
  735.             };
  736.            
  737.             searchMoreFields();
  738.            
  739.             shop2.on('afterGetFolderCustomFields', function(){
  740.                 searchMoreFields();
  741.                
  742.                 var url = '/my/s3/api/shop2/?cmd=getSearchMatches&hash=' +
  743.                     shop2.apiHash.getSearchMatches +
  744.                     '&ver_id=' + shop2.verId + '&',
  745.                     fullUrl = url + $(shop2.facets.search.wrapper).serialize();
  746.            
  747.                 shop2.facets.getDataSearch(fullUrl);
  748.             });
  749.  
  750.         }, /*Поиск*/
  751.        
  752.         filterBlock: function() {
  753.  
  754.             $('.shop2-filter__title').on('click', function(){
  755.                 $(this).toggleClass('active');
  756.                 $(this).next().slideToggle(250);
  757.             });
  758.  
  759.             $('.shop2-filter__item').each(function() {
  760.                 var $this            = $(this);
  761.                 var $btn             = $this.find('.gr-filter-more__btn');
  762.                 var hideText         = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
  763.  
  764.                 $btn.on('click', function(){
  765.                     var $hiddenCkeckbox  = $this.find('.shop2-filter__checkbox:hidden');
  766.                     var $hiddenColor     = $this.find('.shop2-color-ext-list__item:hidden');
  767.                     var currentText  = $btn.data('text');
  768.  
  769.                     $hiddenCkeckbox.addClass('hidden_item');
  770.                     $hiddenColor.addClass('hidden_item');
  771.  
  772.                     if ($this.find('.hidden_item').hasClass('active')) {
  773.                         $btn.find('.gr-filter-more__text').text(currentText);
  774.                         $this.find('.hidden_item').removeClass('active');
  775.                     } else {
  776.                         $btn.find('.gr-filter-more__text').text(hideText);
  777.                         $this.find('.hidden_item').addClass('active');
  778.                     };
  779.                 });
  780.             });
  781.  
  782.         }, /*Фильтр*/
  783.        
  784.         productsBlock: function() {
  785.  
  786.             $(document).on('click', '.gr-options-more__btn', function(){
  787.                 var $parent     = $(this).parents('.gr-product-options');
  788.                 var $params     = $parent.find('.gr-options-container');
  789.                 var currentText = $(this).data('text');
  790.                 var hideText    = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
  791.  
  792.                 if ($(this).hasClass('active')) {
  793.                     $(this).removeClass('active');
  794.                     $(this).find('ins').text(currentText);
  795.                 } else {
  796.                     $(this).addClass('active');
  797.                     $(this).find('ins').text(hideText);
  798.                 };
  799.  
  800.                 $params.stop().slideToggle(250);
  801.             });
  802.  
  803.             $('.shop2-color-ext-select .shop2-color-ext-options').on('click', function() {
  804.                 if ($(this).closest('.shop2-color-ext-select').hasClass('active')) {
  805.                     $(this).closest('.shop2-color-ext-select').removeClass('active');
  806.                 } else {
  807.                     $(this).closest('.shop2-color-ext-select').addClass('active');
  808.                 }
  809.             });
  810.  
  811.             $('#shop2-color-ext-select').on('click', function() {
  812.                 $('.shop2-color-ext-select').removeClass('active');
  813.             });
  814.  
  815.  
  816.  
  817.             $(document).on('click', '.shop2-color-ext-select', function() {
  818.                 if ($(this).parents('.product-item').length>0) {
  819.                     $('#shop2-color-ext-select').addClass('product_item_color');
  820.                 }
  821.  
  822.                 if ($(this).parents('.shop2-product').length>0) {
  823.                     $('#shop2-color-ext-select').addClass('shop_product_color');
  824.                 }
  825.             });
  826.  
  827.             $(document).on('click', '#shop2-color-ext-select', function() {
  828.                 $(this).removeClass('product_item_color');
  829.                 $(this).removeClass('shop_product_color');
  830.             });
  831.             $(document).on('click', function(e){
  832.                 if (!$(e.target).closest('#shop2-color-ext-select').length) {
  833.                     $('#shop2-color-ext-select').removeClass('product_item_color');
  834.                     $('#shop2-color-ext-select').removeClass('shop_product_color');
  835.                 }
  836.             });
  837.  
  838.         }, /*Товар*/
  839.        
  840.         cardPage: function(){
  841.  
  842.             var $cardHiddenOptions = $('.card-page .shop2-product .gr-product-options .option-item:hidden');
  843.            
  844.             if ($cardHiddenOptions.length>0) {
  845.                 $('.shop2-product .gr-product-options-more').addClass('show_more_btn');
  846.             };
  847.  
  848.             $(document).on('click', '.card-page .shop2-product .gr-product-options-more__btn', function(){
  849.                 var currentText = $(this).data('text');
  850.                 var hideText    = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
  851.  
  852.                 if ($(this).hasClass('active')) {
  853.                     $(this).removeClass('active');
  854.                     $(this).find('ins').text(currentText);
  855.                 } else {
  856.                     $(this).addClass('active');
  857.                     $(this).find('ins').text(hideText);
  858.                 };
  859.  
  860.                 $cardHiddenOptions.stop().slideToggle(250);
  861.             });
  862.  
  863.  
  864.             if ($('.card-slider__thumbs-slider').length>0) {
  865.                 var vslider = tns({
  866.                     container: '.card-slider__items-slider',
  867.                     slideBy: 1,
  868.                     mode: 'gallery',
  869.                     axis: 'horizontal',
  870.                     autoplay: false,
  871.                     mouseDrag: true,
  872.                     center: true,
  873.                     autoWidth: false,
  874.                     loop: false,
  875.                     rewind: true,
  876.                     swipeAngle: false,
  877.                     preventActionWhenRunning: false,
  878.                     nav: true,
  879.                     swipeAngle: 50,
  880.                     navPosition: 'bottom',
  881.                     controlsText: ['<svg class="gr-svg-icon"><use xlink:href="#icon_shop_card_sl_prev"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_card_sl_prev_small"></use></svg>', '<svg class="gr-svg-icon"><use xlink:href="#icon_shop_card_sl_next"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_card_sl_next_small"></use></svg>'],
  882.                     responsive: {
  883.                         320: {
  884.                             controls: false,
  885.                             nav: true
  886.                         },
  887.                         768: {
  888.                             controls: true,
  889.                             nav: true
  890.                         }
  891.                     }
  892.                 });
  893.  
  894.  
  895.                 var small_slider = tns({
  896.                     container: '.card-slider__thumbs-slider',
  897.                     loop: false,
  898.                     gutter: 20,
  899.                     center:false,
  900.                     mouseDrag: true,
  901.                     nav: false,
  902.                     controls: false,
  903.                     navPosition: 'bottom',
  904.                     preventActionWhenRunning: false,
  905.                     axis: 'horizontal',
  906.                     responsive: {
  907.                         320: {
  908.                             items: 3
  909.                         },
  910.                         640: {
  911.                             items: 6
  912.                         },
  913.                         768: {
  914.                             items: 3
  915.                         },
  916.                         1024: {
  917.                             items: 5
  918.                         },
  919.                         1261: {
  920.                             items: 4
  921.                         },
  922.                         1340: {
  923.                             items: 5
  924.                         }
  925.                     }
  926.                 });
  927.                
  928.                 var navIndex = $('.card-slider__items .tns-nav-active').index();
  929.                 $('.card-slider__thumbs-slider .card-slider__thumb').removeClass('tns-nav-active');
  930.                 $('.card-slider__thumbs-slider .card-slider__thumb').eq(navIndex).addClass('tns-nav-active');
  931.                
  932.                 vslider.events.on('indexChanged', function(){
  933.                     var navIndex = $('.card-slider__items .tns-nav-active').index();
  934.                     $('.card-slider__thumbs-slider .card-slider__thumb').removeClass('tns-nav-active');
  935.                     $('.card-slider__thumbs-slider .card-slider__thumb').eq(navIndex).addClass('tns-nav-active');
  936.  
  937.                     /*if (vslider.getInfo().index>vslider.getInfo().indexCached) {
  938.                         //console.log('right')
  939.                     } else {
  940.                         //console.log('left')
  941.                     }*/
  942.                 });
  943.  
  944.                 $(document).on('click', '.card-slider__thumbs-slider .card-slider__thumb', function(){
  945.                     var thisIndex = $(this).index();
  946.                     $('.card-slider__items .tns-nav button').eq(thisIndex).click();
  947.                 });
  948.  
  949.                 vslider.events.on('indexChanged', function(){
  950.                     small_slider.goTo(vslider.getInfo().index);
  951.                 });
  952.             };
  953.            
  954.             if (!isMobile && jQuery().zoom) {
  955.                 $('.gr-image-zoom').zoom({
  956.                     magnify: 1,
  957.                     duration: 10,
  958.                     onZoomIn: function(){
  959.                         $(this).parent().addClass('hide_small_pic');
  960.                     },
  961.                     onZoomOut: function(){
  962.                         $(this).parent().removeClass('hide_small_pic');
  963.                     },
  964.                     callback: function(){
  965.                         var $zoomImg = $(this);
  966.                         var containerHeight = $zoomImg.parent().outerHeight();
  967.                         var containerWidth = $zoomImg.parent().outerWidth();
  968.                         var zoomImgHeight = Math.floor($zoomImg.height());
  969.                         var zoomImgWidth = Math.floor($zoomImg.width());
  970.                         var floatHeight = Math.floor(20 * zoomImgHeight / 100);
  971.                         var floatWidth = Math.floor(20 * zoomImgWidth / 100);
  972.                         var prevWidth = Math.floor($(this).prev().outerWidth());
  973.                         var prevHeight = Math.floor($(this).prev().outerHeight());
  974.                        
  975.                         var zoomFloatHeight = zoomImgHeight + floatHeight;
  976.                         var zoomFloatWidth = zoomImgWidth + floatWidth;
  977.                         var finalHeight = prevHeight+floatHeight;
  978.                         var finalWidth = prevWidth+floatWidth;
  979.                        
  980.                         if (zoomFloatHeight<=prevHeight-floatHeight || zoomFloatWidth<=prevWidth-floatWidth) {
  981.                             $(this).parent().addClass('hide_big_pic');
  982.                         };
  983.                        
  984.                         if (zoomImgHeight<=prevHeight || zoomImgWidth <=prevWidth) {
  985.                             $zoomImg.css({
  986.                                 'width': finalWidth,
  987.                                 'height': finalHeight
  988.                             });
  989.                         }
  990.                        
  991.                         if (finalHeight<=containerHeight && finalWidth<=containerWidth) {
  992.                             $(this).parent().addClass('hide_zoom_pic');
  993.                         }
  994.                     }
  995.                 });
  996.             };
  997.  
  998.         }, /*Слайдер в карточке товара*/
  999.        
  1000.         responsiveTabs: function() {
  1001.  
  1002.             var $tabs = $('#product-tabs');
  1003.  
  1004.             $tabs.responsiveTabs({
  1005.                 rotate: false,
  1006.                 startCollapsed: 'accordion',
  1007.                 collapsible: 'accordion',
  1008.                 animation: 'slide',
  1009.                 duration: 500,
  1010.                 animationqueue: false,
  1011.                 setHash: true,
  1012.                 scrollToAccordion: true,
  1013.                 scrollToAccordionOffset: 60,
  1014.                 click: function(event, tab) {
  1015.                     setTimeout(function(){
  1016.                         $.fn.matchHeight._update();
  1017.                     }, 501);
  1018.                 }
  1019.             });
  1020.  
  1021.         }, /*Табы*/
  1022.  
  1023.         kindsBlock: function() {
  1024.  
  1025.             var $kindClass = $('.kinds-block__items.kinds_slider');
  1026.  
  1027.             if ($kindClass.length>0) {
  1028.                 var sliderAutoplay = $('.kinds-block__items.kinds_slider').data('autoplay');
  1029.                 var kind_items = $('.kinds-block__items.kinds_slider').data('kind-items');
  1030.  
  1031.                 if (kind_items == 5) {
  1032.                     $('.kinds-block.collections_block').addClass('kind_columns_5');
  1033.                     var kind_items_1920 = 7,
  1034.                         kind_items_1600 = 6,
  1035.                         kind_items_1440 = 5,
  1036.                         kind_items_1366 = 5,
  1037.                         kind_items_1280 = 4,
  1038.                         kind_items_1024 = 4,
  1039.                         kind_items_768 = 3,
  1040.                         kind_items_320 = 2;
  1041.                 } else if (kind_items == 4) {
  1042.                     $('.kinds-block.collections_block').addClass('kind_columns_4');
  1043.                     var kind_items_1920 = 5,
  1044.                         kind_items_1600 = 4,
  1045.                         kind_items_1440 = 4,
  1046.                         kind_items_1366 = 4,
  1047.                         kind_items_1280 = 4,
  1048.                         kind_items_1024 = 4,
  1049.                         kind_items_768 = 3,
  1050.                         kind_items_320 = 2;
  1051.                 } else if (kind_items == 3) {
  1052.                     $('.kinds-block.collections_block').addClass('kind_columns_3');
  1053.                     var kind_items_1920 = 4,
  1054.                         kind_items_1600 = 4,
  1055.                         kind_items_1440 = 3,
  1056.                         kind_items_1366 = 3,
  1057.                         kind_items_1280 = 3,
  1058.                         kind_items_1024 = 3,
  1059.                         kind_items_768 = 3,
  1060.                         kind_items_320 = 2;
  1061.                 } else if (kind_items == 2) {
  1062.                     $('.kinds-block.collections_block').addClass('kind_columns_2');
  1063.                     var kind_items_1920 = 3,
  1064.                         kind_items_1600 = 3,
  1065.                         kind_items_1440 = 3,
  1066.                         kind_items_1366 = 2,
  1067.                         kind_items_1280 = 2,
  1068.                         kind_items_1024 = 2,
  1069.                         kind_items_768 = 2,
  1070.                         kind_items_320 = 2;
  1071.                 }
  1072.  
  1073.                 var respSettings = {};
  1074.  
  1075.                 if ($('.dynamic_width').length) {
  1076.                     respSettings = {
  1077.                         320: {
  1078.                             controls: false,
  1079.                             items: kind_items_320,
  1080.                             gutter: 12
  1081.                         },
  1082.                         768: {
  1083.                             controls: false,
  1084.                             items: kind_items_768,
  1085.                             gutter: 20
  1086.                         },
  1087.                         1024: {
  1088.                             controls: false,
  1089.                             items: kind_items_1024,
  1090.                             gutter: 20
  1091.                         },
  1092.                         1261: {
  1093.                             controls: true,
  1094.                             items: kind_items_1280,
  1095.                             gutter: 20
  1096.                         },
  1097.                         1341: {
  1098.                             controls: true,
  1099.                             items: kind_items_1366,
  1100.                             gutter: 20
  1101.                         },
  1102.                         1367: {
  1103.                             controls: true,
  1104.                             items: kind_items_1440,
  1105.                             gutter: 20
  1106.                         },
  1107.                         1441: {
  1108.                             controls: true,
  1109.                             items: kind_items_1600,
  1110.                             gutter: 20
  1111.                         },
  1112.                         1601: {
  1113.                             controls: true,
  1114.                             items: kind_items_1920,
  1115.                             gutter: 20
  1116.                         }
  1117.                     }
  1118.                 } else {
  1119.                     respSettings = {
  1120.                         320: {
  1121.                             controls: false,
  1122.                             items: kind_items_320,
  1123.                             gutter: 12
  1124.                         },
  1125.                         768: {
  1126.                             controls: false,
  1127.                             items: kind_items_768,
  1128.                             gutter: 20
  1129.                         },
  1130.                         1024: {
  1131.                             controls: false,
  1132.                             items: kind_items_1024,
  1133.                             gutter: 20
  1134.                         },
  1135.                         1261: {
  1136.                             controls: true,
  1137.                             items: kind_items_1280,
  1138.                             gutter: 20
  1139.                         }
  1140.                     }
  1141.                 }
  1142.  
  1143.                 // tiny-slider initialisation
  1144.                 var sliders = document.querySelectorAll('.kinds-block__items.kinds_slider');
  1145.                 shop2_gr.methods.forEach(sliders, function(index, value) {
  1146.                     var multislider = tns({
  1147.                         loop: false,
  1148.                         rewind: true,
  1149.                         container: value,
  1150.                         slideBy: 1,
  1151.                         autoplayHoverPause: true,
  1152.                         mode: 'carousel',
  1153.                         axis: 'horizontal',
  1154.                         autoplay: sliderAutoplay,
  1155.                         autoplayButtonOutput: false,
  1156.                         mouseDrag: true,
  1157.                         center: false,
  1158.                         autoWidth: false,
  1159.                         nav: true,
  1160.                         swipeAngle: 50,
  1161.                         controlsText: ['<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>'],
  1162.                         navPosition: 'bottom',
  1163.                         preventActionWhenRunning: false,
  1164.                         responsive: respSettings
  1165.                     });
  1166.                 });
  1167.             }
  1168.  
  1169.         }, /*Коллекции*/
  1170.        
  1171.         commentsBlock: function() {
  1172.             $('.comments-form__btn').on('click', function(){
  1173.                 $(this).next().slideToggle(200);   
  1174.             });
  1175.         }, /*Комментарии*/
  1176.  
  1177.         rangeSlider: function() {
  1178.             if ($('.input_range_slider').length>0) {
  1179.                 shop2_gr.methods.rangeSliderInit('.filter-block .input_range_slider');
  1180.                 shop2_gr.methods.rangeSliderInit('.search-form .input_range_slider', false);
  1181.             };
  1182.         }, /*Бегунки*/
  1183.  
  1184.         amountBlock: function() {
  1185.             shop2_gr.methods.amountInit();
  1186.         }, /*Количество*/
  1187.  
  1188.         buyOneClick: function() {
  1189.  
  1190.             $(document).on('click', '.buy-one-click', function(e) {
  1191.                 var productName = $(this).data('product-name');
  1192.                 var productLink = $(this).data('product-link');
  1193.                
  1194.                 if (shop2.mode == 'product' && $(this).parents('.kind-item').length<1) {
  1195.                     var productAmount = $(this).parents('.shop2-product').find('.shop2-product-amount input').val();
  1196.                 } else if ($('.product-quick-view').length>0 && $(this).parents('.kind-item').length<1) {
  1197.                     var productAmount = $(this).parents('.shop2-product').find('.shop2-product-amount input').val();
  1198.                 } else if ($(this).parents('.kind-item').length>0) {
  1199.                     var productAmount = $(this).parents('.kind-item').find('.shop2-product-amount input').val();
  1200.                 } else {
  1201.                     var productAmount = $(this).parents('.shop2-product-item').find('.shop2-product-amount input').val();
  1202.                 }
  1203.                
  1204.                 $.ajax({
  1205.                     url: $(this).data('api-url'),
  1206.                     dataType: 'json',
  1207.                     success: function(response) {
  1208.                         if (!response.result.error) {
  1209.                            
  1210.                             $('.remodal[data-remodal-id="buy-one-click"] .tpl-anketa').remove();
  1211.                             $(response.result.html).appendTo('.remodal[data-remodal-id="buy-one-click"]');
  1212.                            
  1213.                             var nameValue = productName  + ', количество - ' + productAmount;
  1214.                            
  1215.                             $('.remodal[data-remodal-id="buy-one-click"] .tpl-field__product-link input').val(productLink);
  1216.                             $('.remodal[data-remodal-id="buy-one-click"] .tpl-field__product-name input').val(nameValue);
  1217.  
  1218.                             s3From.initForms($('.remodal[data-remodal-id="buy-one-click"]'), function(){
  1219.                                 $('.remodal[data-remodal-id="buy-one-click"] .tpl-field__product-link input').val(productLink);
  1220.                                 $('.remodal[data-remodal-id="buy-one-click"] .tpl-field__product-name input').val(nameValue);
  1221.                             });
  1222.                             grFormDatePicker.init();
  1223.                            
  1224.                         }
  1225.                     }
  1226.                 });
  1227.             });
  1228.                        
  1229.         }, /*Купить в 1 клик*/
  1230.  
  1231.         actionsBlock: function() {
  1232.             var actionEventName = 'mouseenter';
  1233.             if (isMobile) {
  1234.                 actionEventName = 'click';
  1235.             };
  1236.             $(document).on(actionEventName, '.shop2-product-actions dt', function(){
  1237.                 $('.shop2-product-actions dt').removeClass('dt_hover');
  1238.                 $('.shop2-product-actions dd').css('left', 'auto');
  1239.  
  1240.                 if (!isMobile) {
  1241.                     $(this).addClass('dt_hover');
  1242.                 };
  1243.  
  1244.                 $(this).next().css('left', $(this).position().left);
  1245.                 $(this).next().css('top', $(this).position().top - $(this).next().outerHeight());
  1246.  
  1247.                 var nextLeft = $(this).next().offset().left;
  1248.                 var nextWidth = $(this).next().outerWidth();
  1249.                 var offsetSum = nextLeft + nextWidth;
  1250.                 var winWidth = $(window).width();
  1251.  
  1252.                 if ((offsetSum) > winWidth) {
  1253.                     $(this).next().css('left', $(this).position().left - (offsetSum - winWidth))
  1254.                 }
  1255.             });
  1256.  
  1257.             $(document).on('mouseleave', '.shop2-product-actions dl', function(){
  1258.                 $('.shop2-product-actions dt').removeClass('dt_hover');
  1259.                 $('.shop2-product-actions dd').css('left', 'auto');
  1260.             });
  1261.  
  1262.         }, /*Подарок/Акция*/
  1263.        
  1264.         cartPreview: function(){
  1265.            
  1266.             $(document).on('click', '.gr_order_one_page', function(e){
  1267.                 eraseCookie('gr_delivery_scroll');
  1268.                 createCookie('gr_delivery_scroll', 1, 30);
  1269.             });
  1270.            
  1271.             if (readCookie('gr_delivery_scroll') == '1') {
  1272.                 eraseCookie('gr_delivery_scroll');
  1273.                
  1274.                 setTimeout(function(){
  1275.                     $('html, body').animate({
  1276.                         scrollTop: $('.shop2-delivery').offset().top - 30
  1277.                     }, 800);
  1278.                 }, 1000);
  1279.             };
  1280.                
  1281.         }, /*Скролл на странице корзины до доставки*/
  1282.  
  1283.         cartPage: function() {
  1284.  
  1285.             $(document).on('click', '.cart-params__more-btn', function(){
  1286.                 var $parent     = $(this).parents('.cart-params');
  1287.                 var $params     = $parent.find('.cart-params__body');
  1288.                 var currentText = $(this).data('text');
  1289.                 var hideText    = $('html').attr('lang') == 'ru' ? 'Свернуть' : 'Hide';
  1290.  
  1291.                 if ($(this).hasClass('active')) {
  1292.                     $(this).removeClass('active');
  1293.                     $(this).find('ins').text(currentText);
  1294.                 } else {
  1295.                     $(this).addClass('active');
  1296.                     $(this).find('ins').text(hideText);
  1297.                 };
  1298.  
  1299.                 $params.stop().slideToggle(250);
  1300.             });
  1301.  
  1302.  
  1303.             if (shop2.mode=='cart') {
  1304.                 $('.shop2-warning').prependTo('.cart-page__left');     
  1305.             };
  1306.            
  1307.             /*Автопересчет в корзине*/
  1308.             if (shop2.mode=='cart') {
  1309.                 var cartURL = shop2.uri + "/cart",
  1310.                     ajax, hash, $idd,
  1311.                     shopCartDiv = $('.cart-page'),
  1312.                     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>';
  1313.                    
  1314.                 $('.shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').append(cartPreloader);
  1315.            
  1316.                 $.get(cartURL + "?gethash=1", function(d) {
  1317.                     d = $.trim(d).replace(/<script[\s\S]*/, '');
  1318.                     d = $.trim(d).replace(/.*(\{[^}]*\})/g, "$1");
  1319.                     d = $.trim(d).replace(/<!--(.*?)-->/gm, "");
  1320.                     d = $.trim(d);
  1321.                     hash = JSON.parse(d);
  1322.                     shop2.on("afterCartAddItem", function(d, status) {
  1323.                         if (!d.errstr.length) {
  1324.                             getCart();
  1325.                         };
  1326.                     });
  1327.                 });
  1328.                
  1329.                 $(document).on('click', '#shop2-color-ext-select li.param-value:not(.shop2-color-ext-selected)', function() {
  1330.                     clearTimeout($idd);
  1331.                     $idd = setTimeout(updateForm, 500);
  1332.                     $('.shop2-cart-update').hide();
  1333.                 });
  1334.            
  1335.                 function getCart() {
  1336.                     if (ajax) ajax.abort();
  1337.                     ajax = $.ajax({
  1338.                         url: cartURL + "?cart_only=1",
  1339.                         async: false,
  1340.                         success: function(data) {
  1341.                             var $shopWarning = $(data).filter('.shop2-warning').clone();
  1342.  
  1343.                             $('.cart-page__top').html($(data).find('.cart-page__top').html());
  1344.                             $('.cart-page__bottom').html($(data).find('.cart-page__bottom').html());
  1345.                            
  1346.                             $shopWarning.prependTo('.cart-page__left');
  1347.                             initCart(shopCartDiv);
  1348.                            
  1349.                             $('.shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').removeClass('gr-preloader-active');
  1350.                         }
  1351.                     });
  1352.                 };
  1353.                
  1354.                 function initDelivery() {
  1355.                     if ($('.shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').find('.gr-preloader-holder').length<1) {
  1356.                         $('.shop2-order-form ~ .form-item.form-item-submit button.shop2-btn').append(cartPreloader);
  1357.                     };
  1358.                    
  1359.                     /*Код из shop2.queue.cart*/
  1360.                     $('#shop2-deligate-calc').on('click', function(e) {
  1361.                         var data = {},
  1362.                             delivery = $('#shop2-order-delivery'),
  1363.                             tabs = delivery.find('.shop2-delivery--item__tab');
  1364.                    
  1365.                         $('#shop2-perfect-form').find('input, textearea, select').each(function() {
  1366.                             var $this = $(this);
  1367.                             if (this.tagName === 'INPUT' && this.type === 'checkbox') {
  1368.                                 if (this.checked) {
  1369.                                     data[this.name] = 'on';
  1370.                                 }
  1371.                             } else {
  1372.                                 data[this.name] = $(this).val();
  1373.                             }
  1374.                         });
  1375.                    
  1376.                         e.preventDefault();
  1377.                         tabs.removeClass('active-tab');
  1378.                         tabs.removeClass('point');
  1379.                         delivery.addClass('preloader');
  1380.                         $('#shop2-delivery-wait').show();
  1381.                         $('input#address').blur();
  1382.                         $('#shop2-deligate-calc').hide();
  1383.                    
  1384.                         $.ajax({
  1385.                             url: '/my/s3/xapi/public/?method=deligate/calc&param[get_vars][]',
  1386.                             type: 'post',
  1387.                             dataType: 'json',
  1388.                             data: data,
  1389.                             success: function(result) {
  1390.                                 delivery.removeClass('preloader');
  1391.                                 $('#shop2-delivery-wait').hide();
  1392.                                 $('#shop2-order-delivery').html(result.result.html);
  1393.                                 $('#shop2-order-delivery').append('<div class="preloader"><div class="spinner"></div></div>');
  1394.                                 $('#shop2-order-delivery').find('.delivery-items').each(function() {
  1395.                                     var $this = $(this);
  1396.                                     if ($.trim($this.text()) == "") {
  1397.                                         $this.parents('.shop2-delivery--item__tab:first').addClass('disabled');
  1398.                                     }
  1399.                                 });
  1400.                                 if (result.result.error) {
  1401.                                     shop2.alert(result.result.error);
  1402.                                 } else {
  1403.                    
  1404.                                     var dadataJson = $.parseJSON($('#dadata').val()),
  1405.                                         coordsCenter = [dadataJson.geo_lat, dadataJson.geo_lon];
  1406.                    
  1407.                                     shop2.queue.edost2();
  1408.                                     $('#shop2-ems-calc, #shop2-edost-calc').on('click', function(e) {
  1409.                                         var $this = $(this);
  1410.                                         var attach_id = $this.data('attach-id');
  1411.                                         var to = $('select[name=' + attach_id + '\\[to\\]]');
  1412.                                         var zip = $('input[name=' + attach_id + '\\[zip\\]]');
  1413.                                         var order_value = $('input[name=' + attach_id + '\\[order_value\\]]');
  1414.                    
  1415.                                         if (to.length == 0) {
  1416.                                             to = $('#shop2-edost2-to');
  1417.                                         }
  1418.                    
  1419.                                         e.preventDefault();
  1420.                    
  1421.                                         to = to.get(0) ? to.val() : '';
  1422.                                         zip = zip.get(0) ? zip.val() : '';
  1423.                                         order_value = order_value.prop("checked") ? 'on' : '';
  1424.                    
  1425.                                         shop2.delivery.calc(attach_id, 'to=' + to + '&zip=' + zip + '&order_value=' + order_value, function(d) {
  1426.                                             if (!d.data && d.errstr) {
  1427.                                                 shop2.alert(d.errstr);
  1428.                                                 $('#delivery-' + attach_id + '-cost').html(0);
  1429.                                             } else {
  1430.                                                 $('#delivery-' + attach_id + '-cost').html(d.data.cost);
  1431.                    
  1432.                                                 if (d.data.html) {
  1433.                                                     $('#delivery-' + attach_id + '-html').html(d.data.html);
  1434.                                                     shop2.queue.edost();
  1435.                                                 }
  1436.                                             }
  1437.                                         });
  1438.                    
  1439.                                     });
  1440.                                     $('#shop2-deligate-calc').hide();
  1441.                                 }
  1442.                             }
  1443.                         });
  1444.                     });
  1445.                     /*Код из shop2.queue.cart*/
  1446.                    
  1447.                     /*Код из shop2.queue.delivery*/
  1448.                     $('#shop2-order-delivery').find('.delivery-items').each(function() {
  1449.                         var $this = $(this);
  1450.                         if ($.trim($this.text()) == "") {
  1451.                             $this.parents('.shop2-delivery--item__tab:first').addClass('disabled');
  1452.                         }
  1453.                     });
  1454.                     $('#shop2-ems-calc, #shop2-edost-calc').on('click', function(e) {
  1455.                         var $this = $(this);
  1456.                         var attach_id = $this.data('attach-id');
  1457.                         var to = $('select[name=' + attach_id + '\\[to\\]]');
  1458.                         var zip = $('input[name=' + attach_id + '\\[zip\\]]');
  1459.                         var order_value = $('input[name=' + attach_id + '\\[order_value\\]]');
  1460.                    
  1461.                         if (to.length == 0) {
  1462.                             to = $('#shop2-edost2-to');
  1463.                         }
  1464.                    
  1465.                         e.preventDefault();
  1466.                    
  1467.                         to = to.get(0) ? to.val() : '';
  1468.                         zip = zip.get(0) ? zip.val() : '';
  1469.                         order_value = order_value.prop("checked") ? 'on' : '';
  1470.                    
  1471.                         shop2.delivery.calc(attach_id, 'to=' + to + '&zip=' + zip + '&order_value=' + order_value, function(d) {
  1472.                             if (!d.data && d.errstr) {
  1473.                                 shop2.alert(d.errstr);
  1474.                                 $('#delivery-' + attach_id + '-cost').html(0);
  1475.                             } else {
  1476.                                 $('#delivery-' + attach_id + '-cost').html(d.data.cost);
  1477.                    
  1478.                                 if (d.data.html) {
  1479.                                     $('#delivery-' + attach_id + '-html').html(d.data.html);
  1480.                                     shop2.queue.edost();
  1481.                                 }
  1482.                             }
  1483.                         });
  1484.                    
  1485.                     });
  1486.                     /*Код из shop2.queue.delivery*/
  1487.                 };
  1488.            
  1489.                 function initCart($div) {
  1490.                     var $form = $div.find("#shop2-cart"),
  1491.                         $inp = $form.find("input:text"),
  1492.                         $item = $form.find(".cart-products__item"),
  1493.                         $recalc = $("a.shop2-cart-update"),
  1494.                         $minus = $form.find(".amount-minus"),
  1495.                         $plus = $form.find(".amount-plus");
  1496.            
  1497.                     if (!$form.length) return;
  1498.                    
  1499.                     shop2_gr.methods.amountInit();
  1500.                    
  1501.                     if (shop2.mode=='cart') {
  1502.                         $('.shop2-warning').prependTo('.cart-page__left');     
  1503.                     };
  1504.                    
  1505.                     $('.cart-total-checkout, .cart-total-order-checkout, .cart-registration-btn').append(cartPreloader);
  1506.                    
  1507.                     $('[data-remodal-id="cart-auth-remodal"]').remodal({
  1508.                         hashTracking: false
  1509.                     });
  1510.                    
  1511.                     $('[data-remodal-id="coupon-remodal"]').remodal({
  1512.                         hashTracking: false
  1513.                     });
  1514.                    
  1515.                     $('#shop2-cart .cart-delete a').off('click');
  1516.                    
  1517.                     $item.each(function(){
  1518.                         var $del = $(this).find(".cart-delete a");
  1519.                         var $input = $(this).find(".shop2-product-amount input");
  1520.                         var $button = $(this).find(".shop2-product-amount button");
  1521.                         var $select = $(this).find("select.param-value");
  1522.                        
  1523.                        
  1524.                         $select.on('change', function() {
  1525.                             clearTimeout($idd);
  1526.                             $idd = setTimeout(updateForm, 500);
  1527.                             $('.shop2-cart-update').hide();
  1528.                         });
  1529.                        
  1530.                         $input.on('change', function() {
  1531.                             clearTimeout($idd);
  1532.                             $idd = setTimeout(updateForm, 1000);
  1533.                             $('.shop2-cart-update').hide();
  1534.                            
  1535.                             $('.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');
  1536.                         });
  1537.                        
  1538.                         $button.on('click', function() {
  1539.                             clearTimeout($idd);
  1540.                             $idd = setTimeout(updateForm, 1000);
  1541.                             $('.shop2-cart-update').hide();
  1542.                            
  1543.                             $('.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');
  1544.                         });
  1545.                        
  1546.                         $del.on("click", function(e) {
  1547.                             var $this = $(this),
  1548.                                 kind_id = $this.data('id');
  1549.                                
  1550.                             e.preventDefault();
  1551.                            
  1552.                             $('.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');
  1553.                
  1554.                             kind_id = kind_id.toString().replace(/\"/g, '\\"').replace(/\'/g, '"');
  1555.                             kind_id = $.parseJSON(kind_id);
  1556.                
  1557.                             shop2.trigger('beforeCartRemoveItem');
  1558.                
  1559.                             $.ajax({
  1560.                                 url: '/my/s3/api/shop2/?cmd=cartRemoveItem',
  1561.                                 async: false,
  1562.                                 dataType: "json",
  1563.                                 data: {
  1564.                                     hash: hash.del,
  1565.                                     ver_id: shop2.verId,
  1566.                                     kind_id: kind_id
  1567.                                 },
  1568.                                 success: function (d, status) {
  1569.                                     sessionStorage.setItem('cart-reload', 1);
  1570.                                     getCart();
  1571.                                    
  1572.                                     $('.gr-cart-total-amount').text($('#shop2-cart').data('cart-amount') || '0');
  1573.                                    
  1574.                                     if (d.data.cart.length == 0) {
  1575.                                         document.location = shop2.uri + "?mode=cart&action=cleanup";
  1576.                                     };
  1577.                                 }
  1578.                             });
  1579.                
  1580.                             return false;
  1581.                         });
  1582.                     });
  1583.            
  1584.                     $recalc.on("click", function(e) {
  1585.                         e.preventDefault();
  1586.                         updateForm();
  1587.                         return false;
  1588.                     });
  1589.                    
  1590.                    
  1591.                     shop2.on('afterCartAddCoupon, afterCartRemoveCoupon', function() {
  1592.                         document.location.reload();
  1593.                     });
  1594.                    
  1595.                     $('.coupon-btn').on('click', function(e) {
  1596.                         var coupon = $('#coupon'),
  1597.                             code = coupon.val();
  1598.                    
  1599.                         e.preventDefault();
  1600.                    
  1601.                         if (code) {
  1602.                    
  1603.                             shop2.cart.addCoupon(code);
  1604.                    
  1605.                         }
  1606.                    
  1607.                     });
  1608.                    
  1609.                    
  1610.                     $('.coupon-delete').on('click', function(e) {
  1611.                         var $this = $(this),
  1612.                             code = $this.data('code');
  1613.                    
  1614.                         e.preventDefault();
  1615.                    
  1616.                         if (code) {
  1617.                    
  1618.                             shop2.cart.removeCoupon(code);
  1619.                    
  1620.                         }
  1621.                     });
  1622.                 };
  1623.                
  1624.                 function updateForm() {
  1625.                     var data = $("#shop2-cart").serialize();
  1626.                    
  1627.                     shop2.trigger('beforeCartUpdate');
  1628.        
  1629.                     $.ajax({
  1630.                         type: "POST",
  1631.                         url:
  1632.                         '/my/s3/api/shop2/?cmd=cartUpdate' +
  1633.                         '&ver_id=' + shop2.verId +
  1634.                         '&hash=' + hash.up +
  1635.                         '&' + data,
  1636.                         async: false,
  1637.                         success: function (d, status) {
  1638.                             sessionStorage.setItem('cart-reload', 1);
  1639.                             getCart();
  1640.                             shop2.trigger('afterCartUpdated');
  1641.                             $('.gr-cart-total-amount').text($('#shop2-cart').data('cart-amount') || '0');
  1642.                             $('.gr-cart-total-sum ins').text($('.last_item .cart-total__body').data('total-price'));
  1643.                             initDelivery();
  1644.                         }
  1645.                     });
  1646.        
  1647.                     return false;
  1648.                 };
  1649.                
  1650.                 initCart(shopCartDiv);
  1651.             };
  1652.             /*Автопересчет в корзине*/
  1653.            
  1654.         }, /*Корзина*/
  1655.            
  1656.         specialPopup: function(){
  1657.            
  1658.             var specialRemodal = $('[data-remodal-id=special-popup]').remodal();
  1659.             var showSpecOnReturn = true;
  1660.            
  1661.             function init() {
  1662.                 if (document.layers) document.captureEvents(Event.MOUSEMOVE);
  1663.                 document.onmousemove = mousemove;
  1664.             }
  1665.             function mousemove(event) {
  1666.                 var mouse_y = 0;
  1667.                 if (document.attachEvent != null) {
  1668.                     mouse_y = window.event.clientY;
  1669.                 } else if (!document.attachEvent && document.addEventListener) {
  1670.                     mouse_y = event.clientY;
  1671.                 }
  1672.                
  1673.                 var showSpecOn = function () {
  1674.                     setTimeout(function(){
  1675.                        
  1676.                         //specialRemodal.open();
  1677.                        
  1678.                         showSpecOnReturn = false ;
  1679.                     }, 300);
  1680.                    
  1681.                 }
  1682.                 if (mouse_y <= 10 && showSpecOnReturn != false ) {
  1683.                     showSpecOn()
  1684.                 }
  1685.             }
  1686.             init();
  1687.                
  1688.         }, /*Форма "Спецпредложение"*/
  1689.  
  1690.         lightGallery: function() {
  1691.  
  1692.             $('.card-slider__items').lightGallery({
  1693.                 thumbnail: false,
  1694.                 download: true,
  1695.                 loop: false,
  1696.                 counter: false,
  1697.                 share: false,
  1698.                 getCaptionFromTitleOrAlt: true,
  1699.                 selector: '.card-slider__image a'
  1700.             });
  1701.  
  1702.             $('.gr_cart_param_img').lightGallery({
  1703.                 thumbnail: false,
  1704.                 download: true,
  1705.                 loop: false,
  1706.                 counter: false,
  1707.                 share: false,
  1708.                 getCaptionFromTitleOrAlt: true,
  1709.                 selector: 'a'
  1710.             });
  1711.  
  1712.         }, /*Галерея*/
  1713.  
  1714.         toolTips: function(){
  1715.  
  1716.             $('.shop-view .shop-view__item.thumbs').elemToolTip({
  1717.                 position: 'top',
  1718.                 text: 'Витрина',
  1719.                 margin: 12
  1720.             });
  1721.  
  1722.             $('.shop-view .shop-view__item.simple').elemToolTip({
  1723.                 position: 'top',
  1724.                 text: 'Простой',
  1725.                 margin: 12
  1726.             });
  1727.  
  1728.             $('.shop-view .shop-view__item.pricelist').elemToolTip({
  1729.                 position: 'top',
  1730.                 text: 'Прайс-лист',
  1731.                 margin: 12
  1732.             });
  1733.  
  1734.             $('.quick-view-trigger').elemToolTip({
  1735.                 position: 'top',
  1736.                 text: 'Быстрый просмотр',
  1737.                 margin: 12
  1738.             });
  1739.  
  1740.         }, /*Тултипы*/
  1741.  
  1742.         alignElements : function() {
  1743.  
  1744.             function blocksMatchHeight(arr) {
  1745.                 for (var i = 0; i< arr.length; i++) {
  1746.                     $(arr[i]).matchHeight();
  1747.                 }
  1748.             }
  1749.  
  1750.             var alignBlocks = function(){
  1751.                 blocksMatchHeight([
  1752.                     '.kinds-block__items.kinds_slider .kind-item__top',
  1753.                     '.kinds-block__items.kinds_slider .kind-price',
  1754.                     '.kinds-block__items.kinds_slider .kind-additional__top',
  1755.                     '.mods_block .kinds-block__items .kind-item__top',
  1756.                     '.mods_block .kinds-block__items .kind-price',
  1757.                     '.kinds-block .kind-additional__btns',
  1758.                     '.kinds-block .kind-item__bottom',
  1759.                     '.product-list.thumbs .product-item .product-price',
  1760.                     '.product-list.thumbs .product-item .product-additional__top-right',
  1761.                     '.main-blocks .product-list.thumbs .product-item__bottom'
  1762.                 ]);
  1763.             }
  1764.             setTimeout(function(){
  1765.                 alignBlocks();
  1766.             }, 100);
  1767.            
  1768.             window.addEventListener('orientationchange', function() {
  1769.                 setTimeout(function(){
  1770.                     $.fn.matchHeight._update();
  1771.                 }, 300);
  1772.             }, false);
  1773.  
  1774.         }, /*Выравнивание блоков по высоте*/
  1775.  
  1776.         foldersInBlock: function(){
  1777.             if ($('.folders_slider').length<1) {
  1778.                 $('.site-folders-in-block').each(function() {
  1779.                     var $hiddenItems = $(this).find('.site-folders-in-block__item:hidden');
  1780.  
  1781.                     if ($hiddenItems.length>0) {
  1782.                         $(this).find('.site-folders-in-block__more').show();
  1783.                     };
  1784.  
  1785.                     $(this).find('.site-folders-in-block__more-btn').on('click', function(){
  1786.                         var $this        = $(this);
  1787.                         var $ins        = $(this).find('ins');
  1788.                         var currentText  = $this.data('text');
  1789.                         var hideText     = $('html').attr('lang') == 'ru' ? 'Скрыть' : 'Hide';
  1790.  
  1791.                         if ($hiddenItems.hasClass('active')) {
  1792.                             $ins.text(currentText);
  1793.                             $this.removeClass('active');
  1794.                             $hiddenItems.removeClass('active');
  1795.                             $hiddenItems.slideToggle(200);
  1796.                         } else {
  1797.                             $ins.text(hideText);
  1798.                             $this.addClass('active');
  1799.                             $hiddenItems.addClass('active');
  1800.                             $hiddenItems.slideToggle(200);
  1801.                         };
  1802.                     });
  1803.                 });
  1804.             };
  1805.  
  1806.             var respSettings = {};
  1807.  
  1808.             if ($('.site-folders-in-block__items').hasClass('small_folders')) {
  1809.                 respSettings = {
  1810.                     1024: {
  1811.                         controls: false,
  1812.                         items: 7,
  1813.                         gutter: 30
  1814.                     },
  1815.                     1261: {
  1816.                         controls: true,
  1817.                         items: 7,
  1818.                         gutter: 30
  1819.                     }
  1820.                 }
  1821.             } else if ($('.site-folders-in-block__items').hasClass('medium_folders')) {
  1822.                 respSettings = {
  1823.                     1024: {
  1824.                         controls: false,
  1825.                         items: 6,
  1826.                         gutter: 30
  1827.                     },
  1828.                     1261: {
  1829.                         controls: true,
  1830.                         items: 6,
  1831.                         gutter: 30
  1832.                     }
  1833.                 }
  1834.             } else if ($('.site-folders-in-block__items').hasClass('large_folders')) {
  1835.                 respSettings = {
  1836.                     1024: {
  1837.                         controls: false,
  1838.                         items: 4,
  1839.                         gutter: 30
  1840.                     },
  1841.                     1261: {
  1842.                         controls: true,
  1843.                         items: 4,
  1844.                         gutter: 30
  1845.                     }
  1846.                 }
  1847.             };
  1848.  
  1849.             var $slider = $('.folders_slider .site-folders-in-block__items');
  1850.             var sliderAutoplay = $slider.data('autoplay');
  1851.             if ($slider.length>0) {
  1852.                 var slider = tns({
  1853.                     loop: false,
  1854.                     rewind: true,
  1855.                     container: '.folders_slider .site-folders-in-block__items',
  1856.                     slideBy: 1,
  1857.                     autoplayHoverPause: true,
  1858.                     mode: 'carousel',
  1859.                     axis: 'horizontal',
  1860.                     autoplay: sliderAutoplay,
  1861.                     autoplayButtonOutput: false,
  1862.                     mouseDrag: true,
  1863.                     center: false,
  1864.                     autoWidth: false,
  1865.                     nav: true,
  1866.                     swipeAngle: 50,
  1867.                     controlsText: ['<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>'],
  1868.                     navPosition: 'bottom',
  1869.                     preventActionWhenRunning: false,
  1870.                     responsive: respSettings
  1871.                 });
  1872.  
  1873.                 shop2_gr.methods.arrowsPosition('.folders_slider .site-folders-in-block__items', '.site-folders-in-block__pic');
  1874.  
  1875.                 var folders_slider_timeout;
  1876.                 var winWidth =  window.innerWidth;
  1877.  
  1878.                 if (winWidth <= 1260) {
  1879.                     if ($slider.hasClass('tns-slider')) {
  1880.                         slider.destroy();
  1881.                     };
  1882.                 } else {
  1883.                     if (!$slider.hasClass('tns-slider')) {
  1884.                         slider = slider.rebuild();
  1885.                     };
  1886.                 };
  1887.  
  1888.                 $(window).on('resize', function(){
  1889.                     var $slider = $('.folders_slider .site-folders-in-block__items');
  1890.                     var winWidth =  window.innerWidth;
  1891.  
  1892.                     if (folders_slider_timeout) {
  1893.                         clearTimeout(folders_slider_timeout);
  1894.                     };
  1895.  
  1896.                     folders_slider_timeout = setTimeout(function(){
  1897.                         if (winWidth <= 1260) {
  1898.                             if ($slider.hasClass('tns-slider')) {
  1899.                                 slider.destroy();
  1900.                             };
  1901.                         } else {
  1902.                             if (!$slider.hasClass('tns-slider')) {
  1903.                                 slider = slider.rebuild();
  1904.                             };
  1905.                         };
  1906.  
  1907.                         shop2_gr.methods.arrowsPosition('.folders_slider .site-folders-in-block__items', '.site-folders-in-block__pic');
  1908.  
  1909.                         return slider;
  1910.                     }, 50);
  1911.  
  1912.                     return slider;
  1913.                 });
  1914.             };
  1915.  
  1916.         }, /*Категории в блоке*/
  1917.  
  1918.         siteActions: function() {
  1919.  
  1920.             shop2_gr.methods.initMoreBtn('.site-actions__items', function(){
  1921.                 $('.site-actions__items:not(.abosolute_text) .site-actions__bottom').matchHeight();
  1922.             }, function(){
  1923.                 setTimeout(function(){
  1924.                     $('.site-actions__items:not(.abosolute_text) .site-actions__text').matchHeight();
  1925.                 }, 300);
  1926.             });
  1927.            
  1928.         }, /*Акции*/
  1929.  
  1930.         siteActions2: function() {
  1931.            
  1932.             shop2_gr.methods.initMoreBtn('.site-actions-2__items:not(.actions2_slider)');
  1933.            
  1934.             // tiny-slider initialisation
  1935.             var sliders = document.querySelectorAll('.site-actions-2__items.actions2_slider');
  1936.             var slidersCounter = 0;
  1937.             var respSettings = {};
  1938.  
  1939.             if ($('.dynamic_width').length) {
  1940.                 respSettings = {
  1941.                     320: {
  1942.                         controls: false,
  1943.                         items: 1,
  1944.                         gutter: 0
  1945.                     },
  1946.                     640: {
  1947.                         controls: false,
  1948.                         items: 2,
  1949.                         gutter: 16
  1950.                     },
  1951.                     768: {
  1952.                         controls: false,
  1953.                         items: 3,
  1954.                         gutter: 20
  1955.                     },
  1956.                     1024: {
  1957.                         controls: false,
  1958.                         items: 4,
  1959.                         gutter: 20
  1960.                     },
  1961.                     1261: {
  1962.                         controls: true,
  1963.                         items: 4,
  1964.                         gutter: 20
  1965.                     },
  1966.                     1341: {
  1967.                         controls: true,
  1968.                         items: 4,
  1969.                         gutter: 20
  1970.                     },
  1971.                     1367: {
  1972.                         controls: true,
  1973.                         items: 4,
  1974.                         gutter: 30
  1975.                     }
  1976.                 }
  1977.             } else {
  1978.                 respSettings = {
  1979.                     320: {
  1980.                         controls: false,
  1981.                         items: 1,
  1982.                         gutter: 0
  1983.                     },
  1984.                     640: {
  1985.                         controls: false,
  1986.                         items: 2,
  1987.                         gutter: 16
  1988.                     },
  1989.                     768: {
  1990.                         controls: true,
  1991.                         items: 3,
  1992.                         gutter: 20
  1993.                     },
  1994.                     1024: {
  1995.                         controls: false,
  1996.                         items: 4,
  1997.                         gutter: 20
  1998.                     },
  1999.                     1261: {
  2000.                         controls: true,
  2001.                         items: 4,
  2002.                         gutter: 30
  2003.                     }
  2004.                 }
  2005.             };
  2006.  
  2007.             shop2_gr.methods.forEach(sliders, function(index, value) {
  2008.                 var sliderAutoplay = +sliders[index].getAttribute('data-autoplay');
  2009.                 var multislider = tns({
  2010.                     loop: false,
  2011.                     rewind: true,
  2012.                     container: value,
  2013.                     slideBy: 1,
  2014.                     autoplayHoverPause: true,
  2015.                     mode: 'carousel',
  2016.                     axis: 'horizontal',
  2017.                     autoplay: sliderAutoplay,
  2018.                     autoplayButtonOutput: false,
  2019.                     mouseDrag: true,
  2020.                     center: false,
  2021.                     autoWidth: false,
  2022.                     nav: true,
  2023.                     swipeAngle: 50,
  2024.                     controlsText: ['<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>'],
  2025.                     navPosition: 'bottom',
  2026.                     preventActionWhenRunning: false,
  2027.                     responsive: respSettings
  2028.                 });
  2029.  
  2030.                 slidersCounter += 1;
  2031.  
  2032.                 return slidersCounter;
  2033.             });
  2034.  
  2035.             if (slidersCounter == sliders.length) {
  2036.                 setTimeout(function(){
  2037.                     shop2_gr.methods.insertTinyDots('.site-actions-2', '.site-actions-2__nav');
  2038.                     shop2_gr.methods.arrowsPosition('.site-actions-2__items.actions2_slider', '.site-actions-2__image');
  2039.                 }, 300);
  2040.             };
  2041.            
  2042.         }, /*Акции 2*/
  2043.  
  2044.         dayProduct: function() {
  2045.             var grTimerTemplate = function(wrap) {
  2046.                 var timerBlocksFirst = $(wrap + '.gr-timer'),
  2047.                     $htmlLang = window._s3Lang.code;
  2048.                 if ($htmlLang == 'de' || $htmlLang == 'en') {
  2049.                     timerDays = 'days';
  2050.                     timerHours = 'hours';
  2051.                     timerMinutes = 'minutes';
  2052.                     timerSeconds = 'seconds'
  2053.                 } else {
  2054.                     timerDays = 'Дней';
  2055.                     timerHours = 'Часов';
  2056.                     timerMinutes = 'Минут';
  2057.                     timerSeconds = 'Секунд'
  2058.                 };
  2059.  
  2060.                 var outputFormat = '<span class="gr-timer-elem gr-timer-days"> <span class="gr-timer-number">%d </span> <em>' + timerDays + '</em> </span> <span class="gr-timer-delim"><svg class="gr-svg-icon"><use xlink:href="#icon_shop_timer_dots"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_timer_dots_small"></use></svg></span> <span class="gr-timer-elem"> <span class="gr-timer-number">%h </span> <em>' + timerHours + '</em> </span> <span class="gr-timer-delim"><svg class="gr-svg-icon"><use xlink:href="#icon_shop_timer_dots"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_timer_dots_small"></use></svg></span> <span class="gr-timer-elem"> <span class="gr-timer-number">%m </span> <em>' + timerMinutes + '</em> </span> <span class="gr-timer-delim"><svg class="gr-svg-icon"><use xlink:href="#icon_shop_timer_dots"></use></svg><svg class="gr-svg-icon gr_small_icon"><use xlink:href="#icon_shop_timer_dots_small"></use></svg></span> <span class="gr-timer-elem"> <span class="gr-timer-number">%s </span> <em>' + timerSeconds + '</em> </span>';
  2061.  
  2062.                 if (timerBlocksFirst.length) {
  2063.                     timerBlocksFirst.timer({
  2064.                         format_in: "%d.%M.%y %h:%m:%s",
  2065.                         format_out: outputFormat,
  2066.                         wrapChar: 'ins class="timerWrapChar"',
  2067.                         language: $htmlLang,
  2068.                         update_time: 1000,
  2069.                         onEnd: function() {
  2070.                             $(this).hide();
  2071.                         },
  2072.                         onTimeChange: function() {
  2073.                             $('.site-sale__date .gr-timer-days').each(function() {
  2074.                                 var $first = $(this).find('.timerWrapChar:first-child');
  2075.                                 var $last = $(this).find('.timerWrapChar:last-child');
  2076.  
  2077.                                 if (+$first.text() == 0 && +$last.text() == 0) {
  2078.                                     $(this).hide();
  2079.                                     $(this).next().hide();
  2080.                                 }
  2081.                             });
  2082.                         }
  2083.                     });
  2084.                 }
  2085.             };
  2086.             grTimerTemplate('.site-sale__date');
  2087.  
  2088.             $('.site-sale__date .gr-timer-days').each(function() {
  2089.                 var $first = $(this).find('.timerWrapChar:first-child');
  2090.                 var $last = $(this).find('.timerWrapChar:last-child');
  2091.  
  2092.                 if (+$first.text() == 0 && +$last.text() == 0) {
  2093.                     $(this).hide();
  2094.                     $(this).next().hide();
  2095.                 }
  2096.             });
  2097.         }, /*Товар дня*/
  2098.  
  2099.         reviewsSlider: function(){
  2100.  
  2101.             $('.site-reviews__items:not(.reviews_slider)').each(function() {
  2102.                 var $parent = $(this).parents('.site-reviews');
  2103.                 var $hiddenItems = $(this).find('.site-reviews__item:hidden');
  2104.  
  2105.                 if ($hiddenItems.length > 0) {
  2106.                     $parent.find('.site-reviews__more').show();
  2107.                 };
  2108.  
  2109.                 $parent.find('.site-reviews__more-btn').on('click', function() {
  2110.                     var $this = $(this);
  2111.                     var $ins = $(this).find('ins');
  2112.                     var currentText = $this.data('text');
  2113.                     var hideText = $('html').attr('lang') == 'ru' ? 'Скрыть' : 'Hide';
  2114.  
  2115.                     if ($hiddenItems.hasClass('active')) {
  2116.                         $ins.text(currentText);
  2117.                         $this.removeClass('active');
  2118.                         $hiddenItems.removeClass('active');
  2119.                         $hiddenItems.slideToggle(200);
  2120.                     } else {
  2121.                         $ins.text(hideText);
  2122.                         $this.addClass('active');
  2123.                         $hiddenItems.addClass('active');
  2124.                         $hiddenItems.slideToggle(200);
  2125.                     };
  2126.                 });
  2127.             });
  2128.            
  2129.             // tiny-slider initialisation
  2130.             var sliders = document.querySelectorAll('.site-reviews__items.reviews_slider');
  2131.             var slidersCounter = 0;
  2132.  
  2133.             shop2_gr.methods.forEach(sliders, function(index, value) {
  2134.                 var sliderAutoplay = +sliders[index].getAttribute('data-autoplay');
  2135.                 var multislider = tns({
  2136.                     loop: false,
  2137.                     rewind: true,
  2138.                     container: value,
  2139.                     slideBy: 1,
  2140.                     autoplayHoverPause: true,
  2141.                     mode: 'carousel',
  2142.                     axis: 'horizontal',
  2143.                     autoplay: sliderAutoplay,
  2144.                     autoplayButtonOutput: false,
  2145.                     mouseDrag: true,
  2146.                     center: false,
  2147.                     autoWidth: false,
  2148.                     nav: true,
  2149.                     swipeAngle: 50,
  2150.                     controlsText: ['<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>'],
  2151.                     navPosition: 'bottom',
  2152.                     preventActionWhenRunning: false,
  2153.                     responsive: {
  2154.                         320: {
  2155.                             controls: false,
  2156.                             items: 1,
  2157.                             gutter: 0
  2158.                         },
  2159.                         768: {
  2160.                             controls: false,
  2161.                             items: 1,
  2162.                             gutter: 0
  2163.                         },
  2164.                         1024: {
  2165.                             controls: false,
  2166.                             items: 2,
  2167.                             gutter: 20
  2168.                         },
  2169.                         1261: {
  2170.                             controls: false,
  2171.                             items: 3,
  2172.                             gutter: 20
  2173.                         },
  2174.                         1341: {
  2175.                             controls: true,
  2176.                             items: 3,
  2177.                             gutter: 20
  2178.                         },
  2179.                         1367: {
  2180.                             controls: true,
  2181.                             items: 3,
  2182.                             gutter: 30
  2183.                         }
  2184.                     }
  2185.                 });
  2186.  
  2187.                 slidersCounter += 1;
  2188.  
  2189.                 return slidersCounter;
  2190.             });
  2191.  
  2192.             if (slidersCounter == sliders.length) {
  2193.                 setTimeout(function(){
  2194.                     shop2_gr.methods.insertTinyDots('.site-reviews', '.site-reviews__nav');
  2195.                 }, 300);
  2196.             };
  2197.  
  2198.         }, /*Отзывы*/
  2199.  
  2200.         reviews2Slider: function(){
  2201.  
  2202.             $('.site-reviews-2__items:not(.reviews2_slider)').each(function() {
  2203.                 var $parent = $(this).parents('.site-reviews-2');
  2204.                 var $hiddenItems = $(this).find('.site-reviews-2__item:hidden');
  2205.  
  2206.                 if ($hiddenItems.length > 0) {
  2207.                     $parent.find('.site-reviews-2__more').show();
  2208.                 };
  2209.  
  2210.                 $parent.find('.site-reviews-2__more-btn').on('click', function() {
  2211.                     var $this = $(this);
  2212.                     var $ins = $(this).find('ins');
  2213.                     var currentText = $this.data('text');
  2214.                     var hideText = $('html').attr('lang') == 'ru' ? 'Скрыть' : 'Hide';
  2215.  
  2216.                     if ($hiddenItems.hasClass('active')) {
  2217.                         $ins.text(currentText);
  2218.                         $this.removeClass('active');
  2219.                         $hiddenItems.removeClass('active');
  2220.                         $hiddenItems.slideToggle(200);
  2221.                     } else {
  2222.                         $ins.text(hideText);
  2223.                         $this.addClass('active');
  2224.                         $hiddenItems.addClass('active');
  2225.                         $hiddenItems.slideToggle(200);
  2226.                     };
  2227.                 });
  2228.             });
  2229.            
  2230.             // tiny-slider initialisation
  2231.             var sliders = document.querySelectorAll('.site-reviews-2__items.reviews2_slider');
  2232.             var slidersCounter = 0;
  2233.  
  2234.             shop2_gr.methods.forEach(sliders, function(index, value) {
  2235.                 var sliderAutoplay = +sliders[index].getAttribute('data-autoplay');
  2236.                 var multislider = tns({
  2237.                     loop: false,
  2238.                     rewind: true,
  2239.                     container: value,
  2240.                     slideBy: 1,
  2241.                     autoplayHoverPause: true,
  2242.                     mode: 'carousel',
  2243.                     axis: 'horizontal',
  2244.                     autoplay: sliderAutoplay,
  2245.                     autoplayButtonOutput: false,
  2246.                     mouseDrag: true,
  2247.                     center: false,
  2248.                     autoWidth: false,
  2249.                     nav: true,
  2250.                     swipeAngle: 50,
  2251.                     controlsText: ['<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>'],
  2252.                     navPosition: 'bottom',
  2253.                     preventActionWhenRunning: false,
  2254.                     responsive: {
  2255.                         320: {
  2256.                             controls: false,
  2257.                             items: 1,
  2258.                             gutter: 0
  2259.                         },
  2260.                         768: {
  2261.                             controls: false,
  2262.                             items: 1,
  2263.                             gutter: 0
  2264.                         },
  2265.                         1024: {
  2266.                             controls: false,
  2267.                             items: 2,
  2268.                             gutter: 20
  2269.                         },
  2270.                         1261: {
  2271.                             controls: true,
  2272.                             items: 2,
  2273.                             gutter: 20
  2274.                         },
  2275.                         1341: {
  2276.                             controls: true,
  2277.                             items: 2,
  2278.                             gutter: 20
  2279.                         },
  2280.                         1367: {
  2281.                             controls: true,
  2282.                             items: 2,
  2283.                             gutter: 30
  2284.                         }
  2285.                     }
  2286.                 });
  2287.  
  2288.                 slidersCounter += 1;
  2289.  
  2290.                 return slidersCounter;
  2291.             });
  2292.  
  2293.             if (slidersCounter == sliders.length) {
  2294.                 setTimeout(function(){
  2295.                     shop2_gr.methods.insertTinyDots('.site-reviews-2', '.site-reviews-2__nav');
  2296.                 }, 300);
  2297.             };
  2298.  
  2299.         }, /*Отзывы 2*/
  2300.  
  2301.         articlesSlider: function(){
  2302.             shop2_gr.methods.initMoreBtn('.site-articles__items:not(.articles_slider)');
  2303.  
  2304.             // tiny-slider initialisation
  2305.             var sliders = document.querySelectorAll('.site-articles__items.articles_slider');
  2306.             var slidersCounter = 0;
  2307.  
  2308.             shop2_gr.methods.forEach(sliders, function(index, value) {
  2309.                 var sliderAutoplay = +sliders[index].getAttribute('data-autoplay');
  2310.                 var multislider = tns({
  2311.                     loop: false,
  2312.                     rewind: true,
  2313.                     container: value,
  2314.                     slideBy: 1,
  2315.                     autoplayHoverPause: true,
  2316.                     mode: 'carousel',
  2317.                     axis: 'horizontal',
  2318.                     autoplay: sliderAutoplay,
  2319.                     autoplayButtonOutput: false,
  2320.                     mouseDrag: true,
  2321.                     center: false,
  2322.                     autoWidth: false,
  2323.                     nav: true,
  2324.                     swipeAngle: 50,
  2325.                     controlsText: ['<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>'],
  2326.                     navPosition: 'bottom',
  2327.                     preventActionWhenRunning: false,
  2328.                     responsive: {
  2329.                         320: {
  2330.                             controls: false,
  2331.                             items: 1,
  2332.                             gutter: 0
  2333.                         },
  2334.                         640: {
  2335.                             controls: false,
  2336.                             items: 2,
  2337.                             gutter: 16
  2338.                         },
  2339.                         768: {
  2340.                             controls: false,
  2341.                             items: 3,
  2342.                             gutter: 20
  2343.                         },
  2344.                         1024: {
  2345.                             controls: false,
  2346.                             items: 4,
  2347.                             gutter: 20
  2348.                         },
  2349.                         1261: {
  2350.                             controls: true,
  2351.                             items: 4,
  2352.                             gutter: 20
  2353.                         },
  2354.                         1341: {
  2355.                             controls: true,
  2356.                             items: 4,
  2357.                             gutter: 20
  2358.                         },
  2359.                         1367: {
  2360.                             controls: true,
  2361.                             items: 4,
  2362.                             gutter: 30
  2363.                         }
  2364.                     }
  2365.                 });
  2366.  
  2367.                 slidersCounter += 1;
  2368.  
  2369.                 return slidersCounter;
  2370.             });
  2371.  
  2372.             if (slidersCounter == sliders.length) {
  2373.                 setTimeout(function(){
  2374.                     shop2_gr.methods.insertTinyDots('.site-articles', '.site-articles__nav');
  2375.                     shop2_gr.methods.arrowsPosition('.site-articles__items.articles_slider', '.site-articles__image');
  2376.                 }, 300);
  2377.             };
  2378.  
  2379.         }, /*Статьи*/
  2380.  
  2381.         otherScripts : function() {
  2382.  
  2383.             $('table').wrap('<div class="table-wrapper"></div>');
  2384.  
  2385.             // Нажатие на клавишу Esc
  2386.                 $(document).on('keyup.esc_keyup', function(keyUp){
  2387.                     if (keyUp.keyCode
  2388.                         == 27) {
  2389.                        
  2390.                             $('.sorting-block').removeClass('active');
  2391.                             $('.shop2-color-ext-select').removeClass('active');
  2392.  
  2393.                         return false;
  2394.                     };
  2395.                 });
  2396.             // Нажатие на клавишу Esc
  2397.  
  2398.             // Клик по документу
  2399.             $(document).on('click', function(e){
  2400.                 if (!$(e.target).closest('.sorting-block').length && !$(e.target).closest('.sorting-button').length) {
  2401.                     $('.sorting-block').removeClass('active');
  2402.                 };
  2403.  
  2404.                 if (!$(e.target).closest('.shop2-color-ext-select .shop2-color-ext-options, #shop2-color-ext-select').length) {
  2405.                     $('.shop2-color-ext-select').removeClass('active');
  2406.                 };
  2407.  
  2408.                 setTimeout(function(){
  2409.                     $('#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>');
  2410.                 }, 250)
  2411.             });
  2412.             // Клик по документу
  2413.  
  2414.             // Меню в подвале
  2415.             function divideList() {
  2416.                 var $list = $('.site-footer-top .footer-menu > li');
  2417.                 var devider = Math.ceil($list.length/2);
  2418.  
  2419.                 for (var i = 0; i < $list.length; i += devider) {
  2420.                     $list.slice(i, i + devider).wrapAll("<div class='footer-menu__column'></div>");
  2421.                 };
  2422.             };
  2423.             divideList();
  2424.             // Меню в подвале
  2425.         }
  2426.  
  2427.  
  2428.     };
  2429.  
  2430.     shop2_gr.methods = {
  2431.  
  2432.         forEach: function(array, callback, scope) {
  2433.             for (var i = 0; i < array.length; i++) {
  2434.                 callback.call(scope, i, array[i]);
  2435.             };
  2436.         },
  2437.  
  2438.         viewLots: function() {
  2439.             var $productList        = $('.product-list');
  2440.             var $productItems       = $('.shop2-product-item');
  2441.             var loadedValue = $('.shop-view__item.active-view').data('value');
  2442.  
  2443.             if ( loadedValue == 'thumbs' ) {
  2444.                 $('.product-list-titles').addClass('hide');
  2445.  
  2446.                 $('.product-item').each(function() {
  2447.                     var $flags = $(this).find('.product-flags');
  2448.                     var $flagsContainer = $(this).find('.product-item__top');
  2449.  
  2450.                     $flags.appendTo($flagsContainer);
  2451.                 });
  2452.             } else if ( loadedValue == 'simple' ) {
  2453.                 $('.product-list-titles').addClass('hide');
  2454.  
  2455.                 $('.product-item').each(function() {
  2456.                     var $flags = $(this).find('.product-flags');
  2457.                     var $flagsContainer = $(this).find('.product-item__top');
  2458.  
  2459.                     $flags.appendTo($flagsContainer);
  2460.                 });
  2461.             } else if ( loadedValue == 'list' ) {
  2462.                 $('.product-list-titles').removeClass('hide');
  2463.  
  2464.                 $('.product-item').each(function() {
  2465.                     var $flags = $(this).find('.product-flags');
  2466.                     var $flagsContainer = $(this).find('.product-item__bottom-left');
  2467.  
  2468.                     $flags.prependTo($flagsContainer);
  2469.                 });
  2470.             };
  2471.  
  2472.             $('.shop-view .shop-view__item').on('click', function(e) {
  2473.                 var $this           = $(this),
  2474.                     value           = $this.data('value');
  2475.  
  2476.                 if ( value == 'thumbs' ) {
  2477.                     $('.product-list-titles').addClass('hide');
  2478.  
  2479.                     $('.product-item').each(function() {
  2480.                         var $flags = $(this).find('.product-flags');
  2481.                         var $flagsContainer = $(this).find('.product-item__top');
  2482.  
  2483.                         $flags.appendTo($flagsContainer);
  2484.                     });
  2485.                 } else if ( value == 'simple' ) {
  2486.                     $('.product-list-titles').addClass('hide');
  2487.  
  2488.                     $('.product-item').each(function() {
  2489.                         var $flags = $(this).find('.product-flags');
  2490.                         var $flagsContainer = $(this).find('.product-item__top');
  2491.  
  2492.                         $flags.appendTo($flagsContainer);
  2493.                     });
  2494.                 } else if ( value == 'list' ) {
  2495.                     $('.product-list-titles').removeClass('hide');
  2496.  
  2497.                     $('.product-item').each(function() {
  2498.                         var $flags = $(this).find('.product-flags');
  2499.                         var $flagsContainer = $(this).find('.product-item__bottom-left');
  2500.  
  2501.                         $flags.prependTo($flagsContainer);
  2502.                     });
  2503.                 };
  2504.  
  2505.                 $this
  2506.                     .addClass('active-view')
  2507.                     .siblings()
  2508.                     .removeClass('active-view');
  2509.  
  2510.                 if ($productList.length>0) {
  2511.                     $productList
  2512.                         .removeClass($productList.attr('class').replace( /[a-zA-Z0-9_-]+(?=\s)/, "" ))
  2513.                         .addClass(value);
  2514.                 };
  2515.  
  2516.                 $(this).parents('.shop-view__inner').removeClass('active');
  2517.  
  2518.                 createCookie('views', value, 30);
  2519.  
  2520.                 setTimeout(function() {
  2521.                     $.fn.matchHeight._update();
  2522.                 }, 300);
  2523.                
  2524.                 e.preventDefault();
  2525.  
  2526.                 return false;
  2527.             });
  2528.         },
  2529.  
  2530.         amountInit: function() {
  2531.             $('.cart-products__item, .shop2-product-item, .shop2-product, .kind-item, .popup-product').each(function() {
  2532.                 var $this       = $(this);
  2533.                 var $amountWrap = $this.find('.shop2-product-amount');
  2534.                 var $input      = $amountWrap.find('input[type="text"]');
  2535.                 var $buttons    = $amountWrap.find('button');
  2536.                 var $minus      = $amountWrap.find('button.amount-minus');
  2537.                 var $plus       = $amountWrap.find('button.amount-plus');
  2538.                 var min         = $amountWrap.find('input').data('min');
  2539.                 var inputVal    = +$input.val();
  2540.                
  2541.  
  2542.                 if (inputVal<=min) {
  2543.                     $minus.attr('disabled', 'disabled');
  2544.                 }
  2545.                
  2546.                 $buttons.on('click', function(){
  2547.                     var parent = $(this).parent();
  2548.                     var input  = parent.find('input');
  2549.  
  2550.                     setTimeout(function(){
  2551.                         var inputVal = +input.val();
  2552.                        
  2553.                         if (inputVal<=min) {
  2554.                             $minus.attr('disabled', 'disabled');
  2555.                         } else {
  2556.                             $minus.removeAttr('disabled');
  2557.                         }
  2558.                     }, 100);
  2559.                 });
  2560.                
  2561.                 $input.on('change', function(e) {
  2562.                     var curVal = +$(this).val();
  2563.                    
  2564.                     if (curVal < min) {
  2565.                         $(this).val(min);
  2566.                     } else if (curVal == min) {
  2567.                         $minus.attr('disabled', 'disabled');
  2568.                     } else if (curVal > min) {
  2569.                         $minus.removeAttr('disabled');
  2570.                     }
  2571.                 });
  2572.             });
  2573.         },
  2574.  
  2575.         rangeSliderInit: function(element, isFilter) {
  2576.             if (isFilter === undefined) {
  2577.                 isFilter = true
  2578.             };
  2579.  
  2580.             $(element).each(function() {
  2581.                 var curMin = $(this).siblings('.input-from').find('input').val() != "" ? parseInt($(this).siblings('.input-from').find('input').val()) : 0;
  2582.                 var curMax = $(this).siblings('.input-to').find('input').val() != "" ? parseInt($(this).siblings('.input-to').find('input').val()) : 200000;
  2583.                
  2584.                 var rangeMin = $(this).siblings('.input-to').find('input').data('range_min');
  2585.                 var rangeMax = $(this).siblings('.input-to').find('input').data('range_max');
  2586.  
  2587.                 var $this       = $(this),
  2588.                     $lower      = $this.siblings('.input-from').find('input'),
  2589.                     $upper      = $this.siblings('.input-to').find('input'),
  2590.                     arr         = [curMin, curMax];
  2591.  
  2592.                 var randomNum    = parseInt(Math.random() * 100 * 33);
  2593.                 var throttleName = 'randomThrottleName-' + randomNum;
  2594.                    
  2595.                 $this.slider({
  2596.                     range: true,
  2597.                     min: rangeMin,
  2598.                     max: rangeMax,
  2599.                     values: arr,
  2600.                     classes: {
  2601.                         'ui-slider-range': 'ui-corner-all ui-widget-header2'
  2602.                     },
  2603.                     slide: function( event, ui ) {
  2604.                         $lower.val( ui.values[ 0 ] );
  2605.                         $upper.val( ui.values[ 1 ] );
  2606.  
  2607.                         if (isFilter) {
  2608.                             $.s3throttle(throttleName, function() {
  2609.                                 $('.range-input').each(function() {
  2610.                                     var name  = $(this).attr('name');
  2611.                                     var value = $(this).val();
  2612.  
  2613.                                     shop2.filter.add(name, value);
  2614.                                     shop2.filter.count();
  2615.                                 });
  2616.                             }, 500);
  2617.                         }
  2618.  
  2619.                     },
  2620.                     create: function( event, ui ) {
  2621.                         $lower.val( arr[ 0 ] );
  2622.                         $upper.val( arr[ 1 ] );
  2623.                     }
  2624.                 });
  2625.                
  2626.                 $lower.on('keyup', function() {
  2627.                     $this.slider( 'values', [ $lower.val(), $upper.val() ] );
  2628.                 });
  2629.  
  2630.                 $upper.on('keyup', function() {
  2631.                     $this.slider( 'values', [ $lower.val(), $upper.val() ] );
  2632.                 });
  2633.             });
  2634.         },
  2635.  
  2636.         resizeController: function() {
  2637.             var $win = $(window),
  2638.                 winWidth = window.innerWidth,
  2639.                 range = [],
  2640.                 func = [],
  2641.                 toggleState = [undefined, undefined];
  2642.  
  2643.             if (!!arguments.length) {
  2644.                 for (var i = 0; i <= arguments.length-1; i++) {
  2645.                    
  2646.                     if ($.isArray(arguments[i])) {
  2647.                         range = arguments[i];
  2648.                     } else if ($.isNumeric(arguments[i])) {
  2649.                         range.push(arguments[i]);
  2650.                     } else if ($.isFunction(arguments[i])) {
  2651.                         func.push(arguments[i]);
  2652.                     }
  2653.                 };
  2654.             }
  2655.  
  2656.             $win.resize(function(event) {
  2657.                 winWidth = window.innerWidth;
  2658.                
  2659.                 if (range.length > 1) {
  2660.                     if (winWidth >= range[0] && winWidth <= range[range.length-1] && typeof toggleState[0] === 'undefined') {
  2661.                         func[0]();
  2662.                         toggleState[0] = true;
  2663.                         toggleState[1] = undefined;                                            
  2664.                     } else if ((winWidth < range[0] || winWidth > range[range.length-1]) && typeof toggleState[1] === 'undefined') {                       
  2665.                         toggleState[0] = undefined;
  2666.                         toggleState[1] = true;
  2667.  
  2668.                         if ($.isFunction(func[1])) {
  2669.                             func[1]();
  2670.                         }
  2671.                     }
  2672.                 } else if (range.length == 1) {
  2673.                     if (winWidth <= range[0] && typeof toggleState[0] === 'undefined') {
  2674.                         func[0]();
  2675.                         toggleState[0] = true;
  2676.                         toggleState[1] = undefined;
  2677.                     } else if (winWidth > range[0] && typeof toggleState[1] === 'undefined') {
  2678.                         toggleState[0] = undefined;
  2679.                         toggleState[1] = true;
  2680.  
  2681.                         if ($.isFunction(func[1])) {
  2682.                             func[1]();
  2683.                         }
  2684.                     }
  2685.                 }
  2686.             }).trigger('resize');
  2687.         },
  2688.  
  2689.         insertTinyDots: function(itemContainer, itemNav) {
  2690.             var item = document.querySelectorAll(itemContainer);
  2691.  
  2692.             for (var i = item.length - 1; i >= 0; i--) {
  2693.                 var nav = item[i].querySelector('.tns-nav');
  2694.                 var navContainer = item[i].querySelector(itemNav);
  2695.  
  2696.                 if (nav != null) {
  2697.                     navContainer.insertAdjacentElement('afterbegin', nav);
  2698.                 };
  2699.             };
  2700.         },
  2701.  
  2702.         arrowsPosition: function(slider, item) {
  2703.             var arrows_timeout;
  2704.  
  2705.             $(slider).each(function() {
  2706.                 var $this = $(this);
  2707.                 var $image = $this.find(item);
  2708.                 var $controls = $this.parents('.tns-outer').find('.tns-controls');
  2709.                 var imgHeight = $image.outerHeight();
  2710.  
  2711.                 $controls.css({
  2712.                     "top": imgHeight / 2
  2713.                 });
  2714.             });
  2715.  
  2716.             $(window).on('resize', function() {
  2717.                 if (arrows_timeout) {
  2718.                     clearTimeout(arrows_timeout);
  2719.                 };
  2720.  
  2721.                 arrows_timeout = setTimeout(function() {
  2722.                     $(slider).each(function() {
  2723.                         var $this = $(this);
  2724.                         var $image = $this.find(item);
  2725.                         var $controls = $this.parents('.tns-outer').find('.tns-controls');
  2726.                         var imgHeight = $image.outerHeight();
  2727.  
  2728.                         $controls.css({
  2729.                             "top": imgHeight / 2
  2730.                         });
  2731.                     });
  2732.                 }, 50);
  2733.             });
  2734.         },
  2735.  
  2736.         initMoreBtn: function(item, afterInit, afterOpened) {
  2737.             $(item).each(function() {
  2738.                 var $parent = $(this).parents('.js_block_parent');
  2739.                 var $btn = $parent.find('.js_block_more_btn');
  2740.                 var $hiddenItems = $(this).find('.js_block_item:hidden');
  2741.  
  2742.                 if ($hiddenItems.length > 0) {
  2743.                     $parent.find('.js_block_more').show();
  2744.                 } else {
  2745.                     $parent.find('.js_block_more').hide();
  2746.                 };
  2747.  
  2748.                 if (afterInit) {
  2749.                     afterInit();
  2750.                 };
  2751.  
  2752.                 $btn.on('click', function() {
  2753.                     var $this = $(this);
  2754.                     var $ins = $(this).find('ins');
  2755.                     var currentText = $this.data('text');
  2756.                     var hideText = $('html').attr('lang') == 'ru' ? 'Скрыть' : 'Hide';
  2757.  
  2758.                     if ($hiddenItems.hasClass('active')) {
  2759.                         $ins.text(currentText);
  2760.                         $this.removeClass('active');
  2761.                         $hiddenItems.removeClass('active');
  2762.                         $hiddenItems.slideToggle(200);
  2763.                     } else {
  2764.                         $ins.text(hideText);
  2765.                         $this.addClass('active');
  2766.                         $hiddenItems.addClass('active');
  2767.                         $hiddenItems.slideToggle(200);
  2768.  
  2769.                         if (afterOpened) {
  2770.                             afterOpened();
  2771.                         };
  2772.                     };
  2773.                 });
  2774.                
  2775.             });
  2776.         }
  2777.  
  2778.     }
  2779.  
  2780.     shop2_gr.init();
  2781.     myObject.shop2_gr = shop2_gr;
  2782.  
  2783. })(jQuery, window);
  2784.  
  2785.  
  2786.  
  2787.  
  2788.  
  2789.  
  2790.  
  2791.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement