Skip to content

Commit 53bd5c0

Browse files
authored
Create swiper.js
First commit
0 parents  commit 53bd5c0

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

swiper.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
const swiperElements = document.querySelectorAll('[cw-swiper="swiper"]');
2+
3+
swiperElements.forEach((swiperElement) => {
4+
const swiper = new Swiper(swiperElement.querySelector('.swiper'), {
5+
loop: swiperElement.getAttribute('cw-swiper-loop') === 'true',
6+
direction: swiperElement.getAttribute('cw-swiper-direction') || 'horizontal',
7+
speed: parseInt(swiperElement.getAttribute('cw-swiper-speed')) || 300,
8+
initialSlide: parseInt(swiperElement.getAttribute('cw-swiper-initial-slide')) || 0,
9+
effect: swiperElement.getAttribute('cw-swiper-effect') || 'slide',
10+
grabCursor: swiperElement.getAttribute('cw-swiper-grab-cursor') === 'true',
11+
centeredSlides: swiperElement.getAttribute('cw-swiper-centered-slides') === 'true',
12+
spaceBetween: parseInt(swiperElement.getAttribute('cw-swiper-space-between')) || 20,
13+
14+
autoplay: swiperElement.getAttribute('cw-swiper-autoplay') === 'true' ? {
15+
delay: parseInt(swiperElement.getAttribute('cw-swiper-autoplay-delay')) || 3000,
16+
disableOnInteraction: swiperElement.getAttribute('cw-swiper-autoplay-disable-on-interaction') === 'true'
17+
} : false,
18+
19+
pagination: swiperElement.getAttribute('cw-swiper-pagination') === 'true' ? {
20+
el: swiperElement.querySelector(`.${swiperElement.getAttribute('cw-swiper-pagination-el')}`),
21+
clickable: swiperElement.getAttribute('cw-swiper-pagination-clickable') === 'true',
22+
type: swiperElement.getAttribute('cw-swiper-pagination-type') || 'bullets',
23+
dynamicBullets: swiperElement.getAttribute('cw-swiper-pagination-dynamic-bullets') === 'true',
24+
bulletClass: swiperElement.getAttribute('cw-swiper-pagination-bullet-class') || 'swiper_bullet',
25+
bulletActiveClass: swiperElement.getAttribute('cw-swiper-pagination-bullet-active-class') || 'swiper_bullet-active'
26+
} : false,
27+
28+
navigation: {
29+
nextEl: swiperElement.querySelector(`.${swiperElement.getAttribute('cw-swiper-navigation-next-el')}`),
30+
prevEl: swiperElement.querySelector(`.${swiperElement.getAttribute('cw-swiper-navigation-prev-el')}`),
31+
disabledClass: swiperElement.getAttribute('cw-swiper-navigation-disabled-class') || 'swiper_button-disabled'
32+
},
33+
34+
breakpoints: {
35+
0: {
36+
slidesPerView: parseInt(swiperElement.getAttribute('cw-swiper-mobile-slides-per-view')) || 1,
37+
spaceBetween: parseInt(swiperElement.getAttribute('cw-swiper-mobile-space-between')) || 10
38+
},
39+
767: {
40+
slidesPerView: parseInt(swiperElement.getAttribute('cw-swiper-tablet-slides-per-view')) || 2,
41+
spaceBetween: parseInt(swiperElement.getAttribute('cw-swiper-tablet-space-between')) || 15
42+
},
43+
988: {
44+
slidesPerView: parseInt(swiperElement.getAttribute('cw-swiper-desktop-slides-per-view')) || 3,
45+
spaceBetween: parseInt(swiperElement.getAttribute('cw-swiper-desktop-space-between')) || 20
46+
}
47+
},
48+
49+
thumbs: swiperElement.getAttribute('cw-swiper-thumbs') ? {
50+
swiper: document.querySelector(`.${swiperElement.getAttribute('cw-swiper-thumbs')}`)
51+
} : undefined, // Use undefined if thumbs is not provided
52+
});
53+
});

0 commit comments

Comments
 (0)