grayowlbear

abt__yt_func.js

Jul 3rd, 2025
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(_, $) {
  2.  
  3.     //--------------------------------------------------------------------------
  4.     // COUNTDOWN INIT Инициализация счетчика
  5.     //--------------------------------------------------------------------------
  6.     function fn_abt__yt_init_countdown(e){
  7.         e.find('span[data-countdown]').each(function() {
  8.             var cd = $(this);
  9.             cd.countdown(cd.data('countdown'), function(event) {
  10.                 cd.html(event.strftime(cd.data('str')));
  11.             });
  12.         });
  13.     }
  14.     $.ceEvent('on', 'ce.commoninit', function(context) {
  15.         fn_abt__yt_init_countdown(context);
  16.     });
  17.  
  18.     //--------------------------------------------------------------------------
  19.     // BANNERS - ЕСЛИ ПРОИЗОШЕЛ КЛИК ПО БАННЕРУ ОТКРЫВАЕМОГО В ПОПАПЕ
  20.     //  1. подгружаем данные
  21.     //  2. инициализируем попап
  22.     //--------------------------------------------------------------------------
  23.     $(document).on('click', 'div[class*=abyt-in-popup-]', function() {
  24.         // подгружаем данные и инициализируем попап если еще это не сделано
  25.         var bp_container = $(this).find("div.abt-yt-bp-container:not(.loaded)");
  26.         if (bp_container.length){
  27.             var link = bp_container.data('link');
  28.             $.ceAjax('request', fn_url('abt__yt.show_banner_in_popup'), {
  29.                 method: 'get',
  30.                 data : {
  31.                     link_id : link,
  32.                     sl: _.cart_language,
  33.                 },
  34.                 hidden: true,
  35.                 callback: function(response) {
  36.                     bp_container
  37.                         .addClass('loaded')
  38.                         .html(response.data)
  39.                         // инициализация
  40.                         .popup({
  41.                             scrolllock: true,
  42.                             openelement : '.abyt-in-popup-' + link,
  43.                             closeelement : '.abyt-closer-' + link,
  44.                             transition: 'all 0.1s',
  45.                             color: 'black',
  46.                             escape: false,
  47.                             blur: false,
  48.                             outline: true,
  49.                             opacity: 0.5,
  50.                             onclose : function () {
  51.                                 // если есть видео - ставим на паузу
  52.                                 var player = $('#youtube-player-' + link);
  53.                                 if (player.length){
  54.                                     player[0].contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
  55.                                 }
  56.                             },
  57.                         })
  58.                         // принудительно открываем
  59.                         .popup('show');
  60.                     $.commonInit(bp_container);
  61.                 },
  62.             });
  63.         }
  64.     });
  65.  
  66.     //--------------------------------------------------------------------------
  67.     // LOAD_MORE_PRODUCTS - Добавляем класс загрузки перед самим запросом
  68.     //--------------------------------------------------------------------------
  69.     var current_position = 0;
  70.  
  71.     $.ceEvent('on', 'dispatch_event_pre', function(e, jelm, processed) {
  72.         var link = jelm.is('a') ? jelm : jelm.parent();
  73.         if (e.type === 'click' && link.hasClass('cm-ajax') && link.data('caEventName') === 'ce.abt__yt_more_products_callback') {
  74.             current_position = $(window).scrollTop();
  75.             $('html').addClass('dialog-is-open');
  76.  
  77.             link.parent().addClass('load');
  78.             $('#tygh_container').addClass('loading-more-products');
  79.         }
  80.     });
  81.     //--------------------------------------------------------------------------
  82.     // LOAD_MORE_PRODUCTS - Скрываем блок для загрузки товров
  83.     //--------------------------------------------------------------------------
  84.     $.ceEvent('on', 'ce.ajaxlink.done.ce.abt__yt_more_products_callback', function(e, data) {
  85.         $(window).scrollTop(current_position);
  86.         $('html').removeClass('dialog-is-open');
  87.  
  88.         $('.more-products-link.load').removeClass('load').hide();
  89.         $('#tygh_container').removeClass('loading-more-products');
  90.     });
  91.  
  92.     //--------------------------------------------------------------------------
  93.     // Загрузка iframe youtube
  94.     //--------------------------------------------------------------------------
  95.     function fn_abt__yt_load_video (elm){
  96.         var id = elm.data('banner-youtube-id'), params = elm.data('banner-youtube-params');
  97.         elm.addClass('loaded').empty().append($('<iframe>', {
  98.                 src: 'https://www.youtube.com/embed/'+ id +'?' + params,
  99.                 frameborder: 0,
  100.                 allowfullscreen: 'true',
  101.                 allowscriptaccess: 'always',
  102.             })
  103.         );
  104.     }
  105.  
  106.     //--------------------------------------------------------------------------
  107.     // Отслеживать клики по видеобаннеру с видеоконтентом
  108.     //--------------------------------------------------------------------------
  109.     $(_.doc).on('click', 'a[data-content="video"]:not(.loaded),div.abyt-a-video .box:not(.loaded),div[data-banner-youtube-id]', function(e) {
  110.         if ($(e.target).attr('data-banner-youtube-id') || $(e.target).attr('data-type')){
  111.             var elm = $(e.target);
  112.             if ($(e.target).attr('data-type')) elm = elm.parent();
  113.             $(this).addClass('loaded');
  114.             fn_abt__yt_load_video(elm);
  115.             return false;
  116.         }
  117.  
  118.         return true;
  119.     });
  120.  
  121.     //--------------------------------------------------------------------------
  122.     // для мобильных версий скролим вверх, при добавлении товара в корзину
  123.     //--------------------------------------------------------------------------
  124.     $(document).on('click', 'button[type=submit][name^="dispatch[checkout.add"]', function() {
  125.         $.ceEvent('on', 'ce.notificationshow', function(notification) {
  126.             if (document.documentElement.clientWidth <= 767){
  127.                 if (notification.find('.ty-ab__ia_joins').length){
  128.                     notification.addClass('with-ab-ia-joins');
  129.                     $('html, body').animate({scrollTop: 0}, 400);
  130.                 }
  131.             }
  132.         });
  133.     });
  134.  
  135.     //--------------------------------------------------------------------------
  136.     // Фиксация top-panel
  137.     //--------------------------------------------------------------------------
  138.     $.ceEvent('on', 'ce.commoninit', function(context) {
  139.         context.find('input.cm-amount').on('change keyup', function(){
  140.             this.style.width = (this.value.length + 1) * 11 + 'px';
  141.         });
  142.  
  143.         var top_panel = context.find('#tygh_main_container > .tygh-top-panel'),
  144.             header = context.find('#tygh_main_container > .tygh-header'),
  145.             b = $('body'),
  146.  
  147.             top_panel_height = top_panel.height(),
  148.             header_height = header.height(),
  149.             height = top_panel_height + header_height,
  150.             fixed = 'fixed-top';
  151.  
  152.         $(window).on('resize scroll',function(e){
  153.             if (document.documentElement.clientWidth > 767){
  154.                 var scroll = $(window).scrollTop();
  155.                 if (scroll >= height && !b.hasClass(fixed)){
  156.                     // формируем панельку
  157.                     header.css('padding-top', top_panel_height + 'px');
  158.                     b.addClass(fixed);
  159.                     // таймер - чтобы отработала анимация в css
  160.                     window.setTimeout(function(){b.addClass('show');}, 50);
  161.  
  162.                 } else if (scroll < height && b.hasClass(fixed)){
  163.                     // расформировуем панельку
  164.                     header.css('padding-top', '');
  165.                     b.removeClass(fixed + ' show menu_fixed-top');
  166.                 }
  167.             }
  168.         });
  169.  
  170.         if (window.innerWidth > 1124 && _.abt__yt.device === 'desktop') {
  171.             var tabs = context.find('.ypi-dt-product-tabs');
  172.  
  173.             if (tabs.length && tabs.outerHeight() > 200) {
  174.                 var sticky = $('.yt-sticky-block');
  175.                 $(window).one('scroll', function () {
  176.                     /*$.ceAjax('request', fn_url('abt__yt.get_sticky_block'), {
  177.                         method: 'get',
  178.                         result_ids: sticky.attr('id'),
  179.                         hidden: true,
  180.                         callback: 'abt__yt.sticky_block_loaded',
  181.                     });*/
  182.                     sticky.addClass('loaded').show();
  183.  
  184.                     var tabs = $('.yt-tabs-n-sticky-block-wrapper');
  185.  
  186.                     $.ceEvent('on', 'ce.dialog.before_open', function (dialog_state, params) {
  187.                         if (!$('html').hasClass('dialog-is-open')) {
  188.                             var tabs_top = tabs.offset().top;
  189.  
  190.                             if (tabs_top < window.scrollY + 90) {
  191.                                 var tabs_bottom = tabs_top + tabs.outerHeight(true);
  192.                                 var sticky_bottom = window.scrollY + sticky.outerHeight() + 90;
  193.  
  194.                                 var top_pos = tabs_bottom - sticky_bottom + 90;
  195.                                 sticky.css({
  196.                                     'top': tabs_bottom < sticky_bottom ? top_pos + 'px' : '',
  197.                                     'position': 'fixed',
  198.                                     'left': sticky.offset().left + 'px',
  199.                                 });
  200.  
  201.                                 $.ceEvent('one', 'ce.dialogclose', function (d, e, u) {
  202.                                     setTimeout(function () {
  203.                                         sticky.css({
  204.                                             'position': '',
  205.                                             'left': '',
  206.                                             'top': '',
  207.                                         });
  208.                                     }, 45);
  209.                                 });
  210.                             }
  211.                         }
  212.                     });
  213.                 });
  214.  
  215.                 /*$.ceEvent('one', 'abt__yt.sticky_block_loaded', function () {
  216.                     sticky.addClass('loaded');
  217.  
  218.                     var tabs = $('.yt-tabs-n-sticky-block-wrapper');
  219.  
  220.                     $.ceEvent('on', 'ce.dialog.before_open', function (dialog_state, params) {
  221.                         if (!$('html').hasClass('dialog-is-open')) {
  222.                             var tabs_top = tabs.offset().top;
  223.  
  224.                             if (tabs_top < window.scrollY + 90) {
  225.                                 var tabs_bottom = tabs_top + tabs.outerHeight(true);
  226.                                 var sticky_bottom = window.scrollY + sticky.outerHeight() + 90;
  227.  
  228.                                 var top_pos = tabs_bottom - sticky_bottom + 90;
  229.                                 sticky.css({
  230.                                     'top': tabs_bottom < sticky_bottom ? top_pos + 'px' : '',
  231.                                     'position': 'fixed',
  232.                                     'left': sticky.offset().left + 'px',
  233.                                 });
  234.  
  235.                                 $.ceEvent('one', 'ce.dialogclose', function (d, e, u) {
  236.                                     setTimeout(function () {
  237.                                         sticky.css({
  238.                                             'position': '',
  239.                                             'left': '',
  240.                                             'top': '',
  241.                                         });
  242.                                     }, 45);
  243.                                 });
  244.                             }
  245.                         }
  246.                     });
  247.                 });*/
  248.             }
  249.         }
  250.     });
  251.  
  252.     //--------------------------------------------------------------------------
  253.     // Горизонтальное меню
  254.     //--------------------------------------------------------------------------
  255.     (function(_, $){
  256.         var container,
  257.             menu,
  258.             wrapper,
  259.             show_more_btn,
  260.             items,
  261.             mobile_menu,
  262.             items_widths,
  263.             total_width,
  264.             total_sections = 1,
  265.             current_menu_section = 1,
  266.             prev_width = 0;
  267.  
  268.         function show_menu_item(elem) {
  269.             elem.removeClass('ab__menu_hidden');
  270.         }
  271.         function hide_menu_item(elem) {
  272.             elem.addClass('ab__menu_hidden');
  273.         }
  274.         function toggle_menu_items() {
  275.             show_more_btn.html(current_menu_section + '/' + total_sections + '<i></i>');
  276.             var arr,
  277.                 widths = $.extend(true, [], items_widths),
  278.                 section;
  279.             if (current_menu_section === total_sections) {
  280.                 arr = $(items.get().reverse());
  281.                 section = 1;
  282.                 widths.reverse();
  283.                 show_more_btn.addClass('last-section');
  284.             } else {
  285.                 arr = items;
  286.                 section = current_menu_section;
  287.                 show_more_btn.removeClass('last-section');
  288.             }
  289.             var sum = 0;
  290.             arr.each(function(i) {
  291.                 var $item = $(this);
  292.                 sum += widths[i];
  293.                 if (section > 1 && sum > total_width) {
  294.                     sum = widths[i];
  295.                     section -= 1;
  296.                 }
  297.                 if (section > 1 || sum > total_width) {
  298.                     hide_menu_item($item);
  299.                 } else {
  300.                     show_menu_item($item);
  301.                 }
  302.             });
  303.         }
  304.         function ab__menu_init() {
  305.             var new_width = window.innerWidth;
  306.             if (new_width === prev_width || new_width <= 767) {
  307.                 return true;
  308.             }
  309.             prev_width = new_width;
  310.  
  311.             container = $('.abt_up-menu.extended');
  312.             menu = $('.ty-menu__items', container);
  313.             wrapper = menu.parent();
  314.             show_more_btn = $('.abt_yp_menu-show_more', container);
  315.             items = menu.children().filter(':not(.visible-phone)');
  316.             mobile_menu = menu.children().filter('.visible-phone');
  317.  
  318.             if (mobile_menu.css('display') === 'none') {
  319.                 container.addClass('extended');
  320.                 var sum = 0;
  321.                 items_widths = [];
  322.                 total_width = container.innerWidth() - show_more_btn.outerWidth() - 5;
  323.                 menu.css('visibility', 'hidden');
  324.                 show_menu_item(items);
  325.                 items.css('width', 'auto');
  326.                 items.each(function(i) {
  327.                     var item = $(this);
  328.                     items_widths[i] = item.outerWidth();
  329.                     item.css('width', item.innerWidth());
  330.                     sum += items_widths[i];
  331.                 });
  332.                 menu.css('width', sum);
  333.                 total_sections = Math.ceil(sum/total_width);
  334.                 if (total_sections > 1) {
  335.                     wrapper.css('width', total_width);
  336.                     show_more_btn.css('display', 'inline-block');
  337.                 } else {
  338.                     show_more_btn.hide();
  339.                 }
  340.                 current_menu_section = _get_init_menu_section();
  341.                 toggle_menu_items();
  342.                 menu.css('visibility', 'visible');
  343.  
  344.                 show_more_btn.off('click');
  345.                 show_more_btn.click(function(){
  346.                     if (current_menu_section === total_sections) {
  347.                         current_menu_section = 1;
  348.                     } else {
  349.                         current_menu_section += 1;
  350.                     }
  351.                     toggle_menu_items();
  352.                 });
  353.             } else {
  354.                 show_menu_item(items);
  355.                 items.css('width', 'auto');
  356.                 menu.css('width', 'auto');
  357.                 wrapper.css('width', 'auto');
  358.                 container.removeClass('extended');
  359.             }
  360.  
  361.             function _get_init_menu_section() {
  362.                 var sum = 0;
  363.                 var section = 1;
  364.                 var active_found = false;
  365.  
  366.                 items.each(function() {
  367.                     if (!active_found) {
  368.                         var item = $(this);
  369.                         sum += item.outerWidth(true);
  370.  
  371.                         if (sum >= total_width) {
  372.                             section++;
  373.                             sum = 0;
  374.                         }
  375.  
  376.                         if (item.hasClass('ty-menu__item-active')) {
  377.                             active_found = true;
  378.                         }
  379.                     }
  380.                 });
  381.  
  382.                 return active_found === true ? section : 1;
  383.             }
  384.         }
  385.         $(document).ready(function(){
  386.             setTimeout(ab__menu_init, 500);
  387.             $(window).resize(function(){
  388.                 ab__menu_init();
  389.             });
  390.             if (window.addEventListener) {
  391.                 window.addEventListener('orientationchange', function() {
  392.                     ab__menu_init();
  393.                 }, false);
  394.             }
  395.             $.ceEvent('on', 'ce.commoninit', function(context) {
  396.                 if ($('.abt_up-menu.extended', context).length) {
  397.                     ab__menu_init();
  398.                 }
  399.             });
  400.         });
  401.     })(Tygh, Tygh.$);
  402.  
  403.     //--------------------------------------------------------------------------
  404.     // Опт цены товаров
  405.     //--------------------------------------------------------------------------
  406.     $(_.doc).on('click', '.ab__show_qty_discounts', function() {
  407.         var product_id = $(this).data('caProductId');
  408.         if (product_id !== undefined) {
  409.             var container = $('#qty_discounts_' + product_id);
  410.             if (container.is(':empty')) {
  411.                 $.ceAjax('request', fn_url('abt__yt.qty_discounts'), {
  412.                     method: 'get',
  413.                     data: {
  414.                         product_id: product_id,
  415.                         sl: _.cart_language,
  416.                     },
  417.                     result_ids: 'qty_discounts_' + product_id
  418.                 });
  419.             }
  420.             container.toggleClass('hidden');
  421.         }
  422.     });
  423.  
  424.     (function() {
  425.         //--------------------------------------------------------------------------
  426.         // Displays features at the click of a button
  427.         //--------------------------------------------------------------------------
  428.         $(document).on('click', '.abt-yt-show-more-features span', function() {
  429.             var btn = $(this);
  430.             var parent = btn.parents('.ty-grid-list__item');
  431.             if (parent.hasClass('abt-yt-loaded-features')) {
  432.                 // if the list is displayed, then you need to hide it
  433.                 setTimeout(function(){
  434.                     parent.removeClass('abt-yt-loaded-features');
  435.                     parent.find('.uploaded-additional-features').css('display', 'none');
  436.                 }, 125);
  437.             } else {
  438.                 // Wrapper for a complete list of features
  439.                 var featuresL= parent.find('.abt-yt-full-features-list');
  440.  
  441.                 var productId = parseInt(featuresL.attr('data-product-id'));
  442.                 var categoryId = parseInt(featuresL.attr('data-main-category-id'));
  443.  
  444.                 parent.find("div[id^='product_data_features_update_'] > *").addClass('initial-feature');
  445.                 parent.find('.uploaded-additional-features').css('display', 'block');
  446.  
  447.                 parent.addClass('abt-yt-loaded-features');
  448.                 // if the list is already loaded && there is nothing in the data-product-id and data-main-category-id attributes -> we will not go further
  449.                 if (!parent.hasClass('loaded') && productId > 0 && categoryId > 0) {
  450.                     // Add a loading indicator
  451.                     var block_middle = parent.find('.block-middle');
  452.                     addIndicator( block_middle );
  453.                     $.ceAjax('request', fn_url('abt__yt.get_features'), {
  454.                         method: 'post',
  455.                         data: {
  456.                             product: productId,
  457.                             category: categoryId,
  458.                             existing_ids: featuresL.attr('data-existing-feature-ids'),
  459.                             sl: _.cart_language,
  460.                         },
  461.                         hidden: true,
  462.                         caching: false,
  463.                         callback: function (d) {
  464.                             block_middle.removeIndicator();
  465.                             // checking for null and undefined
  466.                             if (d.getted_features != void(0)) {
  467.                                 // add the loaded class so that you no longer send ajax
  468.                                 parent.addClass('loaded');
  469.                                 parent.find("div[id^='product_data_features_update_']").append('<div class="uploaded-additional-features">' + d.getted_features + '</div>');
  470.                             }
  471.                         }
  472.                     });
  473.                 }
  474.             }
  475.             // Upload identificator
  476.             // Adds an element the ability to remove it from the code
  477.             // The element must have relative / fixed / absolute positioning.
  478.             function addIndicator( elem ) {
  479.                 elem.append('<div class="abt-indicator-wrapper"><div class="abt-indicator-circle"><span></span></div></div>');
  480.                 elem.removeIndicator = function newFuncQ() {
  481.                     elem.find('.abt-indicator-wrapper').remove();
  482.                     elem.removeIndicator = false;
  483.                 }
  484.             }
  485.         });
  486.  
  487.         //--------------------------------------------------------------------------
  488.         // Hover delay in the horizontal menu
  489.         //--------------------------------------------------------------------------
  490.         var h_menu = $('.top-menu-grid .abt_up-menu .ty-menu__items');
  491.         if (h_menu.length) {
  492.             var elems = h_menu.find('.ty-menu__item');
  493.             elems.mouseenter(function(event) {
  494.                 if (event.relatedTarget !== null) {
  495.                     var $this = $(this);
  496.                     var subelem = $this.find('.ty-menu__submenu-items').css('display', 'none');
  497.  
  498.                     var timeout = 250;
  499.                     setTimeout(function () {
  500.                         subelem.css('display', '');
  501.                     }, timeout);
  502.                 }
  503.             });
  504.  
  505.             var menu_contextmenu_timeout;
  506.             $(document).contextmenu(function (event) {
  507.                 var submenu = $('.ty-menu__submenu');
  508.                 if (submenu.is(event.target) || submenu.has(event.target).length !== 0) {
  509.                     clearTimeout(menu_contextmenu_timeout);
  510.                     var menu_elem = $(event.target).parents('.ty-menu__item');
  511.                     menu_elem.attr('tabindex', '-1').focus();
  512.  
  513.                     menu_contextmenu_timeout = setTimeout(function(){
  514.                         menu_elem.blur();
  515.                     }, 1500);
  516.                 }
  517.             });
  518.         }
  519.     })();
  520.  
  521.     $.ceEvent('on', 'ce.commoninit', function (context) {
  522.         var filters_floating_btn = context.find('.cm-abt-floating-filters-btn');
  523.         if (filters_floating_btn.length) {
  524.             var filters_container = context.find('.ypi-filters-container');
  525.             if (filters_container.length) {
  526.                 var main_content = filters_container.next();
  527.  
  528.                 var filters_offset = filters_container.offset();
  529.                 var content_offset = main_content.offset();
  530.                 content_offset.bottom = content_offset.top + main_content.outerHeight();
  531.                 filters_offset.bottom = filters_offset.top + filters_container.height();
  532.  
  533.                 filters_floating_btn.click(() => {
  534.                     filters_floating_btn.removeClass('visible');
  535.                 });
  536.  
  537.                 var filters_closer = context.find('.cm-product-filters .closer');
  538.                 if (filters_closer.length) {
  539.                     filters_closer.click(() => {
  540.                         var is_filters_visible = _.abt__yt.functions.check_if_elem_on_screen(filters_offset);
  541.                         var is_main_content_visible = _.abt__yt.functions.check_if_elem_on_screen(content_offset);
  542.  
  543.                         if (!is_filters_visible && is_main_content_visible) {
  544.                             filters_floating_btn.addClass('visible');
  545.                         }
  546.                     });
  547.                 }
  548.  
  549.                 setTimeout(function () {
  550.                     var on_scroll = function () {
  551.                         var filters_floating_btn = context.find('.cm-abt-floating-filters-btn');
  552.  
  553.                         if (filters_floating_btn.length) {
  554.                             var is_filters_visible = _.abt__yt.functions.check_if_elem_on_screen(filters_offset);
  555.                             var is_main_content_visible = _.abt__yt.functions.check_if_elem_on_screen(content_offset);
  556.  
  557.                             if (!is_filters_visible && is_main_content_visible) {
  558.                                 filters_floating_btn.addClass('visible');
  559.                             } else {
  560.                                 filters_floating_btn.removeClass('visible');
  561.                             }
  562.                         }
  563.                     };
  564.  
  565.                     $(document).on('scroll resize', on_scroll);
  566.                     on_scroll();
  567.                 }, 400);
  568.             }
  569.         }
  570.  
  571.         context.find('span.link-more').on('mouseover', function() {
  572.             var _self = $(this);
  573.             _self.prev().addClass('view');
  574.             _self.addClass('hidden');
  575.         });
  576.  
  577.         (function(){
  578.             if (document.getElementsByClassName('abt-yt-search-show-only-icon').length) {
  579.                 var search_input = document.getElementById('search_input') || document.querySelector("[name='hint_q']") || document.querySelector("[name='q']");
  580.  
  581.                 if (search_input !== null) {
  582.                     document.querySelector('.ty-search-magnifier').onclick = function () {
  583.                         var parent = this.parentNode;
  584.                         if (!parent.classList.contains('opened')) {
  585.                             parent.classList.add('opened');
  586.                             search_input.focus();
  587.                             return false;
  588.                         }
  589.                     };
  590.  
  591.                     document.onclick = function (event) {
  592.                         var parent = search_input.parentNode;
  593.                         if (!parent.parentNode.parentNode.contains(event.target)) {
  594.                             parent.classList.remove('opened');
  595.                         }
  596.                     };
  597.                 }
  598.             }
  599.         })();
  600.  
  601.         context.find('.cm-ab-onclick-share').one('click', function(){
  602.             var btn = this;
  603.  
  604.             /*$.ceAjax('request', fn_url('abt__yt.get_social_buttons'), {
  605.                 result_ids: btn.nextSibling.getAttribute('id'),
  606.                 hidden: true,
  607.                 callback: 'yt_sb_loaded'
  608.             });*/
  609.         });
  610.  
  611.         $.ceEvent('one', 'yt_sb_loaded', function () {
  612.             $.ceLazyLoader('init');
  613.         });
  614.     });
  615.  
  616.  
  617.     $(document).on('ready', function () {
  618.         // Whether to add a block [...] to bread crumbs
  619.         if (_.abt__yt.settings.general.breadcrumbs_view[_.abt__yt.device] === 'hide_with_btn' && window.innerWidth <= 768) {
  620.             (function() {
  621.                 var main_content_breadcrumbs = $(".main-content-grid[class^='span']");
  622.                 var m_c_b_w = main_content_breadcrumbs.outerWidth();
  623.  
  624.                 var mobile_breadcrumbs = $('.ty-breadcrumbs').css({
  625.                     'display': 'inline-block',
  626.                     'white-space': 'nowrap',
  627.                 });
  628.  
  629.                 var m_b_w = mobile_breadcrumbs.outerWidth(true);
  630.  
  631.                 if (m_b_w >= m_c_b_w) {
  632.                     mobile_breadcrumbs.addClass('long');
  633.                 }
  634.  
  635.                 mobile_breadcrumbs.css({
  636.                     'display': '',
  637.                     'white-space': '',
  638.                 });
  639.             })();
  640.         }
  641.     });
  642.  
  643.     function fn_abt_timer_menu (menu) {
  644.         if (!menu.length || menu.hasClass('abt_inited')) {
  645.             return;
  646.         } else {
  647.             menu.addClass('abt_inited');
  648.         }
  649.         var timer, opened_menu = null;
  650.         menu.find('.first-lvl').hover(function () {
  651.             var elem = $(this).children('.ty-menu__submenu').children('ul');
  652.             clearTimeout(timer);
  653.             timer = setTimeout(function () {
  654.                 if (opened_menu !== null) {
  655.                     opened_menu.hide();
  656.                     opened_menu = null;
  657.                 }
  658.                 opened_menu = elem.show();
  659.             }, 100);
  660.         });
  661.         menu.mouseleave(function () {
  662.             clearTimeout(timer);
  663.             if (opened_menu !== null) {
  664.                 opened_menu.hide();
  665.                 opened_menu = null;
  666.             }
  667.         });
  668.     }
  669.  
  670.     function ajax_load_menu() {
  671.         var abtam = $('div.abtam');
  672.         if (abtam.length){
  673.             var ids = [];
  674.             abtam.each(function(){
  675.                 ids.push($(this).attr('id'));
  676.             });
  677.  
  678.             $.ceAjax('request', fn_url('abt__yt.load_menu'), {
  679.                 result_ids: ids.join(','),
  680.                 method: 'post',
  681.                 hidden: true,
  682.                 data: {
  683.                     sl: _.cart_language,
  684.                 },
  685.                 callback: function(data) {
  686.                     if (document.documentElement.clientWidth >= 768) {
  687.                         fn_abt_timer_menu($('.cm-responsive-menu'));
  688.                     }
  689.                 }
  690.             });
  691.         }
  692.     }
  693.  
  694.     if (document.documentElement.clientWidth >= 768) {
  695.         if ($('.top-menu-grid-vetrtical .ty-dropdown-box__title').hasClass('open')) {
  696.             $('.top-menu-grid-vetrtical .ty-dropdown-box__content').removeClass('hover-zone');
  697.         } else {
  698.             $('.top-menu-grid-vetrtical .ty-dropdown-box__content').addClass('hover-zone');
  699.             $('.hover-zone').hover(
  700.                 function () {
  701.                     $('body').addClass('shadow')
  702.                 },
  703.                 function () {
  704.                     $('body').removeClass('shadow')
  705.                 }
  706.             );
  707.         }
  708.  
  709.  
  710.         $(document).ready(function () {
  711.             // если нет меню с ajax-подгрузкой, запускаем запаздывание
  712.             var responsive_items = $('.cm-responsive-menu');
  713.  
  714.             if (!responsive_items.length){
  715.                 fn_abt_timer_menu(responsive_items);
  716.             }
  717.         });
  718.  
  719.         $.ceEvent('on', 'ce.commoninit', function (context) {
  720.             fn_abt_timer_menu($('.cm-responsive-menu', context));
  721.         });
  722.     }
  723.  
  724.     /* load menu */
  725.     $(document).ready(function () {
  726.         if (document.documentElement.clientWidth >= 768) {
  727.             ajax_load_menu();
  728.         } else {
  729.             $('.top-menu').one('click', function () {
  730.                 ajax_load_menu();
  731.             });
  732.         }
  733.     });
  734.  
  735.     //--------------------------------------------------------------------------
  736.     // Фильтр товаров
  737.     //--------------------------------------------------------------------------
  738.     $.ceEvent('on', 'ce.commoninit', function(context) {
  739.         var filter = context.find('.cm-horizontal-filters'),
  740.             container = context.find('.ypi-filters-container');
  741.         if (container.length) {
  742.             if (filter.length && !$.contains(container, filter)) {
  743.                 filter.appendTo(container);
  744.                 filter.css('visibility', 'visible');
  745.  
  746.                 $.ceEvent('trigger', 'ce.abt__filters_moved', [context]);
  747.             } else {
  748.                 container.addClass('ypi-nofilters');
  749.             }
  750.         }
  751.  
  752.         // Toggle buttons
  753.         context.find('.ypi-menu__fixed-button').on('click', function () {
  754.             $('.ypi-menu__fixed-button').toggleClass('active');
  755.             $('body').toggleClass('menu_fixed-top');
  756.         });
  757.         context.find('.closer_fixed-menu').on('click', function () {
  758.             $('body').removeClass('menu_fixed-top');
  759.             $('.ypi-menu__fixed-button').removeClass('active');
  760.         });
  761.  
  762.         // Toggle vertical filters buttons
  763.         context.find('.ypi-filters-container .ypi-white-vfbt').on('click', function () {
  764.             $('.ty-horizontal-product-filters').toggleClass('vertical-position');
  765.             $('.ty-horizontal-product-filters-dropdown__content').toggleClass('hidden').css('display','inline-block');
  766.             $('.ty-horizontal-product-filters .v-filters-header').toggleClass('hidden');
  767.             $('.ypi-filters-container .ypi-white-vfbt').toggleClass('open');
  768.             $('body').toggleClass('body-not-scroll');
  769.         });
  770.  
  771.         context.find('.ty-product-filters__wrapper .closer').on('click', function () {
  772.             $('.ty-horizontal-product-filters').removeClass('vertical-position');
  773.             $('.v-filters-header').addClass('hidden');
  774.             $('.ty-horizontal-product-filters-dropdown__content').toggleClass('hidden').css('display','none');
  775.             $('.ty-horizontal-product-filters-dropdown__wrapper').removeClass('open');
  776.             $('.ypi-filters-container .ypi-white-vfbt').removeClass('open');
  777.             $('body').removeClass('body-not-scroll');
  778.         });
  779.  
  780.         context.find('.enable-v-filters .ypi-filters-container .ypi-white-vfbt').on('click', function () {
  781.             $('.enable-v-filters').addClass('mobile-view');
  782.         });
  783.  
  784.         $('.enable-v-filters .v-filter .closer').on('click', function () {
  785.             $('.enable-v-filters').removeClass('mobile-view');
  786.             $('.ypi-filters-container .ypi-white-vfbt').removeClass('open');
  787.             $('body').removeClass('body-not-scroll');
  788.         });
  789.  
  790.         // Toggle list
  791.         context.find('.ToggleItem').on('click', function () {
  792.             $(this).toggleClass('is-open');
  793.         });
  794.     });
  795.  
  796.  
  797.     /* [[[ BEGIN ]]]
  798.      * handle product filter variant checked state change
  799.      * */
  800.     $(document).on('change', '.cm-product-filters-checkbox:enabled', (e) => {
  801.         const $filter_checkbox =  $(e.target);
  802.         const filter_checkbox_id = $filter_checkbox.attr('id');
  803.         let $updated_product_filters;
  804.         let $updated_filter_checkbox;
  805.         let $updated_filter_checkbox__container;
  806.         let $updated_filter_checkbox__body;
  807.         let $core_products_found_notice;
  808.         let $own_products_found_notice;
  809.         let inteval_id;
  810.         let h_corrective = 10;
  811.  
  812.         $.ceEvent('one', 'ce.ajaxdone', function (elms, data, response_text) {
  813.             if (elms.length) {
  814.                 $.each(elms, function (key, $elem) {
  815.                     $updated_filter_checkbox = $elem.find('#' + filter_checkbox_id);
  816.                     if ($updated_filter_checkbox.length) {
  817.                         $updated_product_filters = $elem;
  818.                         if ($updated_product_filters.closest('.ut2-dropdown-outside-position').length) {
  819.                             h_corrective = -5;
  820.                         }
  821.                         if ($updated_product_filters.closest('.ut2-hz-filters').length) {
  822.                             h_corrective = 15;
  823.                         }
  824.                         $updated_filter_checkbox__container = $updated_filter_checkbox.siblings('.ty-range-slider');
  825.                         if ($updated_filter_checkbox__container.length < 1) $updated_filter_checkbox__container = $updated_filter_checkbox.closest('.cm-product-filters-checkbox-container');
  826.                         $updated_filter_checkbox__body = $updated_filter_checkbox.parents('.ty-product-filters__block, .ty-product-filters, .ty-price-slider').last();
  827.  
  828.                         inteval_id = setInterval(function () {
  829.                             $core_products_found_notice = $('.ty-tooltip--filter:visible');
  830.                             if ($core_products_found_notice.length) {
  831.                                 clearInterval(inteval_id);
  832.                                 $core_products_found_notice.css({
  833.                                     "--ut2-changed-filter-checkbox-container-top": $updated_filter_checkbox__container.get(0).getBoundingClientRect().top + $updated_filter_checkbox__container.height() / 2 + "px",
  834.                                     "--ut2-changed-filter-checkbox-container-left": Tygh.language_direction === 'rtl' ? $(document).width() - $updated_filter_checkbox__body.get(0).getBoundingClientRect().left + h_corrective + "px" : $updated_filter_checkbox__body.get(0).getBoundingClientRect().right + h_corrective + "px"
  835.                                 });
  836.  
  837.                             }
  838.                         }, 200);
  839.                         setTimeout(function () {
  840.                             clearInterval(inteval_id);
  841.                         }, 2000);
  842.  
  843.                         return false;
  844.                     }
  845.                 });
  846.             }
  847.         });
  848.     });
  849.     /* handle product filter variant checked state change
  850.      * [[[ END ]]] */
  851.  
  852. }(Tygh, Tygh.$));
Add Comment
Please, Sign In to add comment