1 | import { extend } from '../../shared/utils.js';
|
2 |
|
3 | const isGridEnabled = (swiper, params) => {
|
4 | return swiper.grid && params.grid && params.grid.rows > 1;
|
5 | };
|
6 |
|
7 | export default function setBreakpoint() {
|
8 | const swiper = this;
|
9 | const {
|
10 | activeIndex,
|
11 | initialized,
|
12 | loopedSlides = 0,
|
13 | params,
|
14 | $el
|
15 | } = swiper;
|
16 | const breakpoints = params.breakpoints;
|
17 | if (!breakpoints || breakpoints && Object.keys(breakpoints).length === 0) return;
|
18 |
|
19 | const breakpoint = swiper.getBreakpoint(breakpoints, swiper.params.breakpointsBase, swiper.el);
|
20 | if (!breakpoint || swiper.currentBreakpoint === breakpoint) return;
|
21 | const breakpointOnlyParams = breakpoint in breakpoints ? breakpoints[breakpoint] : undefined;
|
22 | const breakpointParams = breakpointOnlyParams || swiper.originalParams;
|
23 | const wasMultiRow = isGridEnabled(swiper, params);
|
24 | const isMultiRow = isGridEnabled(swiper, breakpointParams);
|
25 | const wasEnabled = params.enabled;
|
26 |
|
27 | if (wasMultiRow && !isMultiRow) {
|
28 | $el.removeClass(`${params.containerModifierClass}grid ${params.containerModifierClass}grid-column`);
|
29 | swiper.emitContainerClasses();
|
30 | } else if (!wasMultiRow && isMultiRow) {
|
31 | $el.addClass(`${params.containerModifierClass}grid`);
|
32 |
|
33 | if (breakpointParams.grid.fill && breakpointParams.grid.fill === 'column' || !breakpointParams.grid.fill && params.grid.fill === 'column') {
|
34 | $el.addClass(`${params.containerModifierClass}grid-column`);
|
35 | }
|
36 |
|
37 | swiper.emitContainerClasses();
|
38 | }
|
39 |
|
40 | const directionChanged = breakpointParams.direction && breakpointParams.direction !== params.direction;
|
41 | const needsReLoop = params.loop && (breakpointParams.slidesPerView !== params.slidesPerView || directionChanged);
|
42 |
|
43 | if (directionChanged && initialized) {
|
44 | swiper.changeDirection();
|
45 | }
|
46 |
|
47 | extend(swiper.params, breakpointParams);
|
48 | const isEnabled = swiper.params.enabled;
|
49 | Object.assign(swiper, {
|
50 | allowTouchMove: swiper.params.allowTouchMove,
|
51 | allowSlideNext: swiper.params.allowSlideNext,
|
52 | allowSlidePrev: swiper.params.allowSlidePrev
|
53 | });
|
54 |
|
55 | if (wasEnabled && !isEnabled) {
|
56 | swiper.disable();
|
57 | } else if (!wasEnabled && isEnabled) {
|
58 | swiper.enable();
|
59 | }
|
60 |
|
61 | swiper.currentBreakpoint = breakpoint;
|
62 | swiper.emit('_beforeBreakpoint', breakpointParams);
|
63 |
|
64 | if (needsReLoop && initialized) {
|
65 | swiper.loopDestroy();
|
66 | swiper.loopCreate();
|
67 | swiper.updateSlides();
|
68 | swiper.slideTo(activeIndex - loopedSlides + swiper.loopedSlides, 0, false);
|
69 | }
|
70 |
|
71 | swiper.emit('breakpoint', breakpointParams);
|
72 | } |
\ | No newline at end of file |