Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.  
  3.     var swiperInit = function() {
  4.  
  5.         var swiperElements = document.querySelectorAll('[data-swiper]');
  6.  
  7.         swiperElements.forEach(function($node) {
  8.  
  9.             if($node.classList.contains('swiper-container-horizontal') || $node.classList.contains('swiper-container-vertical')) {
  10.                 return false;
  11.             }
  12.  
  13.             var options = JSON.parse($node.getAttribute('data-options'));
  14.             var length = $node.querySelectorAll('.swiper-slide').length;
  15.  
  16.             if(!options.pagination) {
  17.                 options.pagination = {};
  18.             }
  19.  
  20.             options.pagination.el = $node.parentNode.querySelector('.js-swiper-pagination');
  21.             options.pagination.clickable = true;
  22.  
  23.             options.navigation = {
  24.                 nextEl: $node.parentNode.querySelector('.js-swiper__next'),
  25.                 prevEl: $node.parentNode.querySelector('.js-swiper__prev')
  26.             }
  27.  
  28.             if(!options.slidesPerView) {
  29.                 if(length < 2) {
  30.                     if(options.navigation.prevEl || options.navigation.nextEl) {
  31.                         options.navigation.prevEl.style.display = 'none';
  32.                         options.navigation.nextEl.style.display = 'none';
  33.                     }
  34.                 }
  35.             } else {
  36.                 if(length < parseInt(options.slidesPerView)) {
  37.                     if(options.navigation.prevEl || options.navigation.nextEl) {
  38.                         options.navigation.prevEl.style.display = 'none';
  39.                         options.navigation.nextEl.style.display = 'none';
  40.                     }
  41.                 }
  42.             }
  43.  
  44.             new Swiper($node, options);
  45.  
  46.         });
  47.     }  
  48.  
  49.     if(document.querySelector('[data-swiper]')) {
  50.  
  51.         swiperInit();
  52.  
  53.     }
  54.  
  55. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement