Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lpc_template.queue.tabsInit = function ($self) {
- let $block = $self.find('.lpc-tabs-init');
- if ($block.length) {
- $block.each(function () {
- let $this = $(this);
- let $tab = $this.find('.lpc-tabs-title');
- let $acc = $this.find('.lpc-accord-title');
- let $body = $this.find('.lpc-tabs-body');
- let isVertical = $this.hasClass('lpc-tabs-vertical');
- let blockId = $this.data('blockId');
- function accord() {
- $tab.off('click.tabs');
- $acc.off('click.accorDeon').on('click.accorDeon', function () {
- let $currentAcc = $(this);
- let $currentBody = $currentAcc.next('.lpc-tabs-body');
- let isActive = $currentAcc.hasClass('active');
- $acc.removeClass('active');
- $body.slideUp(200).removeClass('active');
- if (!isActive) {
- $currentAcc.addClass('active');
- $currentBody.slideDown(200).addClass('active');
- let index = $currentAcc.data('index');
- localStorage.setItem('activeTab_' + blockId, index);
- }
- if ($currentAcc.hasClass('active')) {
- setTimeout(function(){
- $('html, body').stop().animate({
- scrollTop: $currentAcc.offset().top - 50
- }, 500);
- }, 301);
- }
- });
- }
- function tabs() {
- $acc.off('click.accorDeon');
- $tab.off('click.tabs').on('click.tabs', function () {
- let $currentTab = $(this);
- let index = $currentTab.data('index');
- let $currentBody = $this.find('.lpc-tabs-body[data-index="' + index + '"]');
- if (!$currentTab.hasClass('active')) {
- $tab.removeClass('active');
- $body.removeClass('active');
- $currentTab.addClass('active');
- $currentBody.addClass('active');
- localStorage.setItem('activeTab_' + blockId, index);
- }
- });
- }
- function updateActiveTab() {
- let dataMedia = document.querySelector('.decor-wrap').dataset.mediaSource;
- if ((isVertical && (dataMedia === 'media-md' || dataMedia === 'media-sm' || dataMedia === 'media-xs')) || (!isVertical && dataMedia === 'media-xs')) {
- accord();
- } else {
- tabs();
- }
- let activeBlockId = localStorage.getItem('activeTab_' + blockId);
- let index = parseInt(activeBlockId, 10) || 0;
- if ((isVertical && (dataMedia === 'media-md' || dataMedia === 'media-sm' || dataMedia === 'media-xs')) || (!isVertical && dataMedia === 'media-xs')) {
- $acc.removeClass('active');
- $body.hide().removeClass('active');
- $acc.eq(index).addClass('active');
- $body.eq(index).toggle().addClass('active');
- } else {
- $tab.removeClass('active').removeAttr('style');
- $body.removeClass('active').removeAttr('style');
- $tab.eq(index).addClass('active').removeAttr('style');
- $body.eq(index).addClass('active').removeAttr('style');
- }
- }
- updateActiveTab();
- window.addEventListener('orientationchange', function () {
- setTimeout(function () {
- updateActiveTab();
- }, 300); // Подождать 1 секунду перед вызовом функции
- });
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement