Advertisement
Igor150195

Правка табов для Вани

Nov 8th, 2023
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. lpc_template.queue.tabsInit = function ($self) {
  2.         let $block = $self.find('.lpc-tabs-init');
  3.    
  4.         if ($block.length) {
  5.             $block.each(function () {
  6.                 let $this = $(this);
  7.                 let $tab = $this.find('.lpc-tabs-title');
  8.                 let $acc = $this.find('.lpc-accord-title');
  9.                 let $body = $this.find('.lpc-tabs-body');
  10.                 let isVertical = $this.hasClass('lpc-tabs-vertical');
  11.                 let blockId = $this.data('blockId');
  12.                
  13.    
  14.                 function accord() {
  15.                     $tab.off('click.tabs');
  16.                     $acc.off('click.accorDeon').on('click.accorDeon', function () {
  17.                         let $currentAcc = $(this);
  18.                         let $currentBody = $currentAcc.next('.lpc-tabs-body');
  19.                         let isActive = $currentAcc.hasClass('active');
  20.    
  21.                         $acc.removeClass('active');
  22.                         $body.slideUp(200).removeClass('active');
  23.    
  24.                         if (!isActive) {
  25.                             $currentAcc.addClass('active');
  26.                             $currentBody.slideDown(200).addClass('active');
  27.                             let index = $currentAcc.data('index');
  28.    
  29.                             localStorage.setItem('activeTab_' + blockId, index);
  30.                         }
  31.    
  32.                         if ($currentAcc.hasClass('active')) {
  33.                             setTimeout(function(){
  34.                                 $('html, body').stop().animate({
  35.                                     scrollTop: $currentAcc.offset().top - 50
  36.                                 }, 500);
  37.                             }, 301);
  38.                         }
  39.                     });
  40.                 }
  41.    
  42.                 function tabs() {
  43.                     $acc.off('click.accorDeon');
  44.                     $tab.off('click.tabs').on('click.tabs', function () {
  45.                         let $currentTab = $(this);
  46.                         let index = $currentTab.data('index');
  47.                         let $currentBody = $this.find('.lpc-tabs-body[data-index="' + index + '"]');
  48.    
  49.                         if (!$currentTab.hasClass('active')) {
  50.                             $tab.removeClass('active');
  51.                             $body.removeClass('active');
  52.                             $currentTab.addClass('active');
  53.                             $currentBody.addClass('active');
  54.    
  55.                             localStorage.setItem('activeTab_' + blockId, index);
  56.                         }
  57.                     });
  58.                 }
  59.    
  60.                 function updateActiveTab() {
  61.                     let dataMedia = document.querySelector('.decor-wrap').dataset.mediaSource;
  62.    
  63.                     if ((isVertical && (dataMedia === 'media-md' || dataMedia === 'media-sm' || dataMedia === 'media-xs')) || (!isVertical && dataMedia === 'media-xs')) {
  64.                         accord();
  65.                     } else {
  66.                         tabs();
  67.                     }                  
  68.    
  69.                     let activeBlockId = localStorage.getItem('activeTab_' + blockId);
  70.                     let index = parseInt(activeBlockId, 10) || 0;
  71.    
  72.                     if ((isVertical && (dataMedia === 'media-md' || dataMedia === 'media-sm' || dataMedia === 'media-xs')) || (!isVertical && dataMedia === 'media-xs')) {
  73.                         $acc.removeClass('active');
  74.                         $body.hide().removeClass('active');
  75.    
  76.                         $acc.eq(index).addClass('active');
  77.                         $body.eq(index).toggle().addClass('active');
  78.    
  79.                     } else {
  80.                         $tab.removeClass('active').removeAttr('style');
  81.                         $body.removeClass('active').removeAttr('style');
  82.    
  83.                         $tab.eq(index).addClass('active').removeAttr('style');
  84.                         $body.eq(index).addClass('active').removeAttr('style');
  85.                     }
  86.                 }
  87.    
  88.                 updateActiveTab();
  89.  
  90.                 window.addEventListener('orientationchange', function () {
  91.                     setTimeout(function () {
  92.                         updateActiveTab();
  93.                     }, 300); // Подождать 1 секунду перед вызовом функции
  94.                 });
  95.             });
  96.         }
  97.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement