|
3 | 3 | 'use strict' |
4 | 4 | // document load event |
5 | 5 | $(document).ready(function () { |
6 | | - var $swiperContainerWrapper = $('.js__slider-container__wrapper') |
7 | | - $swiperContainerWrapper.each(function () { |
8 | | - $(this).children().wrap('<div class="swiper-slide slider-container__slide js__slider-container__slide"></div>') |
9 | | - }) |
10 | | - |
11 | | - var $swiperContainer = $('.js__slider-container__container') |
12 | | - $swiperContainer.each(function () { |
13 | | - var time = $(this).attr('data-autoplay') |
14 | | - var loopParam = $(this).attr('data-loop') |
15 | | - var amountOfSlides = parseInt($(this).attr('data-slidesperview')) |
16 | | - var effectName = $(this).attr('data-effect') |
17 | | - var transition = $(this).attr('data-speed') |
18 | | - var widthForMobile |
19 | | - var widthForTablet |
20 | | - var widthForLaptop |
21 | | - var widthForMediumLaptop |
22 | | - if (amountOfSlides >= 4) { |
23 | | - widthForMobile = 1 |
24 | | - widthForTablet = 2 |
25 | | - widthForLaptop = 3 |
26 | | - widthForMediumLaptop = 4 |
27 | | - } else if (amountOfSlides === 2) { |
28 | | - widthForMobile = 1 |
29 | | - widthForTablet = 1 |
30 | | - widthForLaptop = 1 |
31 | | - widthForMediumLaptop = 2 |
32 | | - } else if (amountOfSlides === 1) { |
33 | | - widthForMobile = 1 |
34 | | - widthForTablet = 1 |
35 | | - widthForLaptop = 1 |
36 | | - widthForMediumLaptop = 1 |
37 | | - } else { |
38 | | - widthForMobile = 1 |
39 | | - widthForTablet = 2 |
40 | | - widthForLaptop = 2 |
41 | | - widthForMediumLaptop = 3 |
42 | | - } |
43 | | - var slider = new Swiper($(this), { |
44 | | - containerModifierClass: 'js__slider-container__container', |
45 | | - wrapperClass: 'js__slider-container__wrapper', |
46 | | - slideClass: 'js__slider-container__slide', |
47 | | - nextButton: $(this).parent().find('.js__slider-container__btn-next'), |
48 | | - prevButton: $(this).parent().find('.js__slider-container__btn-prev'), |
49 | | - pagination: $(this).parent().find('.js__slider-container__pagination'), |
50 | | - paginationClickable: true, |
51 | | - speed: parseInt(transition), |
52 | | - loop: loopParam, |
53 | | - autoplay: time, |
54 | | - effect: effectName, |
55 | | - watchSlidesVisibility: true, |
56 | | - spaceBetween: 20, |
57 | | - preloadImages: false, |
58 | | - lazyLoading: true, |
59 | | - lazyLoadingInPrevNext: true, |
60 | | - slidesPerView: amountOfSlides, |
61 | | - breakpoints: { |
62 | | - // Responsive breakpoints |
63 | | - 480: { |
64 | | - slidesPerView: widthForMobile |
| 6 | + if ($('.slider-container').length > 0) { |
| 7 | + var $swiperContainerWrapper = $('.js__slider-container__wrapper') |
| 8 | + // dividing content into sliders |
| 9 | + $swiperContainerWrapper.each(function () { |
| 10 | + $(this).children().wrap('<div class="swiper-slide slider-container__slide js__slider-container__slide"></div>') |
| 11 | + }) |
| 12 | + var $swiperContainer = $('.js__slider-container__container') |
| 13 | + // initialization of the Slider |
| 14 | + $swiperContainer.each(function () { |
| 15 | + var currentSlider = $(this) |
| 16 | + var time = currentSlider.attr('data-autoplay') |
| 17 | + var loopParam = currentSlider.attr('data-loop') |
| 18 | + var amountOfSlides = parseInt(currentSlider.attr('data-slidesperview')) |
| 19 | + var effectName = currentSlider.attr('data-effect') |
| 20 | + var transition = currentSlider.attr('data-speed') |
| 21 | + var widthForMobile |
| 22 | + var widthForTablet |
| 23 | + var widthForLaptop |
| 24 | + var widthForMediumLaptop |
| 25 | + if (amountOfSlides >= 4) { |
| 26 | + widthForMobile = 1 |
| 27 | + widthForTablet = 2 |
| 28 | + widthForLaptop = 3 |
| 29 | + widthForMediumLaptop = 4 |
| 30 | + } else if (amountOfSlides === 2) { |
| 31 | + widthForMobile = 1 |
| 32 | + widthForTablet = 1 |
| 33 | + widthForLaptop = 1 |
| 34 | + widthForMediumLaptop = 2 |
| 35 | + } else if (amountOfSlides === 1) { |
| 36 | + widthForMobile = 1 |
| 37 | + widthForTablet = 1 |
| 38 | + widthForLaptop = 1 |
| 39 | + widthForMediumLaptop = 1 |
| 40 | + } else { |
| 41 | + widthForMobile = 1 |
| 42 | + widthForTablet = 2 |
| 43 | + widthForLaptop = 2 |
| 44 | + widthForMediumLaptop = 3 |
| 45 | + } |
| 46 | + var slider = new Swiper(currentSlider, { |
| 47 | + containerModifierClass: 'js__slider-container__container', |
| 48 | + wrapperClass: 'js__slider-container__wrapper', |
| 49 | + slideClass: 'js__slider-container__slide', |
| 50 | + nextButton: currentSlider.parent().find('.js__slider-container__btn-next'), |
| 51 | + prevButton: currentSlider.parent().find('.js__slider-container__btn-prev'), |
| 52 | + pagination: currentSlider.parent().find('.js__slider-container__pagination'), |
| 53 | + paginationClickable: true, |
| 54 | + speed: parseInt(transition), |
| 55 | + loop: loopParam, |
| 56 | + autoplay: time, |
| 57 | + effect: effectName, |
| 58 | + watchSlidesVisibility: true, |
| 59 | + spaceBetween: 20, |
| 60 | + preloadImages: false, |
| 61 | + lazyLoading: true, |
| 62 | + lazyLoadingInPrevNext: true, |
| 63 | + slidesPerView: amountOfSlides, |
| 64 | + breakpoints: { |
| 65 | + // Responsive breakpoints |
| 66 | + 480: { |
| 67 | + slidesPerView: widthForMobile |
| 68 | + }, |
| 69 | + 767: { |
| 70 | + slidesPerView: widthForTablet |
| 71 | + }, |
| 72 | + 992: { |
| 73 | + slidesPerView: widthForLaptop |
| 74 | + }, |
| 75 | + 1024: { |
| 76 | + slidesPerView: widthForMediumLaptop |
| 77 | + } |
| 78 | + }, |
| 79 | + coverflow: { |
| 80 | + rotate: 90, |
| 81 | + stretch: 0, |
| 82 | + depth: 200, |
| 83 | + modifier: 1, |
| 84 | + slideShadows: false |
65 | 85 | }, |
66 | | - 767: { |
67 | | - slidesPerView: widthForTablet |
| 86 | + cube: { |
| 87 | + slideShadows: false, |
| 88 | + shadow: false |
68 | 89 | }, |
69 | | - 992: { |
70 | | - slidesPerView: widthForLaptop |
| 90 | + fade: { |
| 91 | + crossFade: true |
71 | 92 | }, |
72 | | - 1024: { |
73 | | - slidesPerView: widthForMediumLaptop |
| 93 | + flip: { |
| 94 | + slideShadows: false |
| 95 | + }, |
| 96 | + onInit: function () { |
| 97 | + currentSlider.closest('.slider-container').css('height', 'auto') |
| 98 | + $('.slider-container_loader').css('display', 'none') |
74 | 99 | } |
75 | | - }, |
76 | | - coverflow: { |
77 | | - rotate: 90, |
78 | | - stretch: 0, |
79 | | - depth: 200, |
80 | | - modifier: 1, |
81 | | - slideShadows: false |
82 | | - }, |
83 | | - cube: { |
84 | | - slideShadows: false, |
85 | | - shadow: false |
86 | | - }, |
87 | | - fade: { |
88 | | - crossFade: true |
89 | | - }, |
90 | | - flip: { |
91 | | - slideShadows: false |
92 | | - } |
93 | | - }) |
94 | | - // Makes it possible to skip between slider images if they have links, using the tab button |
95 | | - slider.container.on('focus', 'a', function (e) { |
96 | | - // Index of focused slide |
97 | | - var focusIndex = $(e.target).parents('.slider-container__slide').index() |
98 | | - // Reset scrollLeft set by browser on focus |
99 | | - slider.container.scrollLeft(0) |
100 | | - // IE fix |
101 | | - setTimeout(function () { |
| 100 | + }) |
| 101 | + // Makes it possible to skip between slider images if they have links, using the tab button |
| 102 | + slider.container.on('focus', 'a', function (e) { |
| 103 | + // Index of focused slide |
| 104 | + var focusIndex = $(e.target).parents('.slider-container__slide').index() |
| 105 | + // Reset scrollLeft set by browser on focus |
102 | 106 | slider.container.scrollLeft(0) |
103 | | - }, 0) |
104 | | - // Slide to focused slide |
105 | | - slider.slideTo(focusIndex) |
| 107 | + // IE fix |
| 108 | + setTimeout(function () { |
| 109 | + slider.container.scrollLeft(0) |
| 110 | + }, 0) |
| 111 | + // Slide to focused slide |
| 112 | + slider.slideTo(focusIndex) |
| 113 | + }) |
106 | 114 | }) |
107 | | - }) |
| 115 | + } |
108 | 116 | }) |
109 | 117 | })(jQuery) |
0 commit comments