Advertisement
akozhomka

JS (themes/redesign/custom-js/filters-pane.js)

Feb 23rd, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.querySelector(document).addEventListener('ready', function () {
  2.     let filterChooseBlock = document.querySelector('.catalog__goods-pane-filter-choose-wrap'),
  3.         animationDuration = 300,
  4.         isScrolled = false;
  5.  
  6.     arrowVisibility();
  7.  
  8.     filterChooseBlock.addEventListener('scroll', () => {
  9.         arrowVisibility();
  10.     });
  11.  
  12.     if (isScrollActive()) {
  13.         document.querySelector('.filterPaneBlock').classList.add('scrollActive');
  14.     }
  15.  
  16.     filterChooseBlock.addEventListener('scroll', () => {
  17.         if (!isScrolled) {
  18.             gaWrapper.ga('send', 'event', 'Products-Filter', 'filter-tab-scroll');
  19.  
  20.             isScrolled = true;
  21.         }
  22.     })
  23.  
  24.     if (typeof ResizeObserver === 'function') {
  25.         let resizeObserver = new ResizeObserver(() => {
  26.             arrowVisibility();
  27.  
  28.             if (isScrollActive()) {
  29.                 document.querySelector('.filterPaneBlock').classList.add('scrollActive');
  30.  
  31.                 return;
  32.             }
  33.  
  34.             document.querySelector('.filterPaneBlock').removeClass('scrollActive');
  35.         });
  36.  
  37.         resizeObserver.observe(document.getElementsByClassName('catalog__goods-pane-filter-choose-wrap')[0]);
  38.     }
  39.  
  40.     document.querySelector('.clickLeftBlock').addEventListener('click', () => {
  41.         filterChooseBlock.finish()
  42.         filterChooseBlock.animate({scrollLeft: filterChooseBlock.scrollLeft() - 100},
  43.             animationDuration,
  44.             arrowVisibility);
  45.     });
  46.     document.querySelector('.clickRightBlock').addEventListener('click', (event) => {
  47.         filterChooseBlock.finish()
  48.         filterChooseBlock.animate({scrollLeft: filterChooseBlock.scrollLeft() + 100},
  49.             animationDuration,
  50.             arrowVisibility);
  51.     });
  52.  
  53.     document.querySelector('.select-sort-current').addEventListener('click',  (event) => {
  54.         if (globalUI.isMobile && !document.querySelector('.select-sort_open').length) {
  55.             event.stopPropagation();
  56.             sortSelectPopUp();
  57.         }
  58.     });
  59. });
  60.  
  61. function sortSelectPopUp() {
  62.     if (document.querySelector('.select-sort_open').length) {
  63.         return;
  64.     }
  65.  
  66.     let sortSelect =  document.querySelector('.catalog__sort-form-mobile');
  67.  
  68.     document.querySelector('body').insertAdjacentHTML("beforeend",'<span class="darkMask"></span>');
  69.     sortSelect.css('display', 'block');
  70.  
  71.     document.querySelector(document).addEventListener('click', (event) => {
  72.         if (!document.querySelector(event.target).closest('.catalog__sort-form-mobile').length) {
  73.             sortSelect.css('display', 'none');
  74.             document.querySelector('.darkMask').remove();
  75.  
  76.             gaWrapper.ga('send', 'event', 'Products-Sort', 'sort-option', 'deactivate');
  77.         }
  78.     })
  79. }
  80.  
  81. function arrowVisibility() {
  82.     let filterChooseBlock = document.querySelector('.catalog__goods-pane-filter-choose-wrap'),
  83.         rightSelector = document.querySelector('.clickRightBlock'),
  84.         leftSelector = document.querySelector('.clickLeftBlock');
  85.  
  86.     if (isScrollActive()) {
  87.         if (filterChooseBlock.get(0).scrollWidth - filterChooseBlock.scrollLeft() <= filterChooseBlock.outerWidth()) {
  88.             rightSelector.css('visibility', 'hidden');
  89.         } else {
  90.             rightSelector.css('visibility', 'visible');
  91.         }
  92.  
  93.         if (filterChooseBlock.scrollLeft() === 0) {
  94.             leftSelector.css('visibility', 'hidden');
  95.         } else {
  96.             leftSelector.css('visibility', 'visible');
  97.         }
  98.  
  99.         return;
  100.     }
  101.  
  102.     rightSelector.css('visibility', 'hidden');
  103.     leftSelector.css('visibility', 'hidden');
  104. }
  105.  
  106. function isScrollActive() {
  107.     let element = document.querySelector('.catalog__goods-pane-filter-choose-wrap').get(0);
  108.  
  109.     return element.scrollWidth > element.clientWidth;
  110. }
  111.  
  112. function sortListBorderColorChange(currentPageUrl) {
  113.     let borderColorSelected = '#1A77D2',
  114.         selectSortClass = '.select-sort';
  115.  
  116.     if (localStorage.getItem('sortPage') === currentPageUrl) {
  117.         document.querySelector(selectSortClass).css('border-color', borderColorSelected);
  118.  
  119.         return;
  120.     }
  121.  
  122.     document.querySelector('.select-sort-mobile, .select-sort li').addEventListener('click', () => {
  123.         document.querySelector(selectSortClass).css('border-color', borderColorSelected);
  124.         localStorage.setItem('sortPage', currentPageUrl);
  125.     });
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement