@@ -9,72 +9,82 @@ export default function setBreakpoint() {
9
9
// Get breakpoint for window width and update parameters
10
10
const breakpoint = swiper . getBreakpoint ( breakpoints , swiper . params . breakpointsBase , swiper . el ) ;
11
11
12
- if ( breakpoint && swiper . currentBreakpoint !== breakpoint ) {
13
- const breakpointOnlyParams = breakpoint in breakpoints ? breakpoints [ breakpoint ] : undefined ;
14
- if ( breakpointOnlyParams ) {
15
- [
16
- 'slidesPerView' ,
17
- 'spaceBetween' ,
18
- 'slidesPerGroup' ,
19
- 'slidesPerGroupSkip' ,
20
- 'slidesPerColumn' ,
21
- ] . forEach ( ( param ) => {
22
- const paramValue = breakpointOnlyParams [ param ] ;
23
- if ( typeof paramValue === 'undefined' ) return ;
24
- if ( param === 'slidesPerView' && ( paramValue === 'AUTO' || paramValue === 'auto' ) ) {
25
- breakpointOnlyParams [ param ] = 'auto' ;
26
- } else if ( param === 'slidesPerView' ) {
27
- breakpointOnlyParams [ param ] = parseFloat ( paramValue ) ;
28
- } else {
29
- breakpointOnlyParams [ param ] = parseInt ( paramValue , 10 ) ;
30
- }
31
- } ) ;
32
- }
12
+ if ( ! breakpoint || swiper . currentBreakpoint === breakpoint ) return ;
33
13
34
- const breakpointParams = breakpointOnlyParams || swiper . originalParams ;
35
- const wasMultiRow = params . slidesPerColumn > 1 ;
36
- const isMultiRow = breakpointParams . slidesPerColumn > 1 ;
37
- if ( wasMultiRow && ! isMultiRow ) {
38
- $el . removeClass (
39
- `${ params . containerModifierClass } multirow ${ params . containerModifierClass } multirow-column` ,
40
- ) ;
41
- swiper . emitContainerClasses ( ) ;
42
- } else if ( ! wasMultiRow && isMultiRow ) {
43
- $el . addClass ( `${ params . containerModifierClass } multirow` ) ;
44
- if ( breakpointParams . slidesPerColumnFill === 'column' ) {
45
- $el . addClass ( `${ params . containerModifierClass } multirow-column` ) ;
14
+ const breakpointOnlyParams = breakpoint in breakpoints ? breakpoints [ breakpoint ] : undefined ;
15
+ if ( breakpointOnlyParams ) {
16
+ [
17
+ 'slidesPerView' ,
18
+ 'spaceBetween' ,
19
+ 'slidesPerGroup' ,
20
+ 'slidesPerGroupSkip' ,
21
+ 'slidesPerColumn' ,
22
+ ] . forEach ( ( param ) => {
23
+ const paramValue = breakpointOnlyParams [ param ] ;
24
+ if ( typeof paramValue === 'undefined' ) return ;
25
+ if ( param === 'slidesPerView' && ( paramValue === 'AUTO' || paramValue === 'auto' ) ) {
26
+ breakpointOnlyParams [ param ] = 'auto' ;
27
+ } else if ( param === 'slidesPerView' ) {
28
+ breakpointOnlyParams [ param ] = parseFloat ( paramValue ) ;
29
+ } else {
30
+ breakpointOnlyParams [ param ] = parseInt ( paramValue , 10 ) ;
46
31
}
47
- swiper . emitContainerClasses ( ) ;
48
- }
32
+ } ) ;
33
+ }
49
34
50
- const directionChanged =
51
- breakpointParams . direction && breakpointParams . direction !== params . direction ;
52
- const needsReLoop =
53
- params . loop && ( breakpointParams . slidesPerView !== params . slidesPerView || directionChanged ) ;
35
+ const breakpointParams = breakpointOnlyParams || swiper . originalParams ;
36
+ const wasMultiRow = params . slidesPerColumn > 1 ;
37
+ const isMultiRow = breakpointParams . slidesPerColumn > 1 ;
54
38
55
- if ( directionChanged && initialized ) {
56
- swiper . changeDirection ( ) ;
39
+ const wasEnabled = params . enabled ;
40
+ const isEnabled = breakpointParams . enabled ;
41
+
42
+ if ( wasMultiRow && ! isMultiRow ) {
43
+ $el . removeClass (
44
+ `${ params . containerModifierClass } multirow ${ params . containerModifierClass } multirow-column` ,
45
+ ) ;
46
+ swiper . emitContainerClasses ( ) ;
47
+ } else if ( ! wasMultiRow && isMultiRow ) {
48
+ $el . addClass ( `${ params . containerModifierClass } multirow` ) ;
49
+ if ( breakpointParams . slidesPerColumnFill === 'column' ) {
50
+ $el . addClass ( `${ params . containerModifierClass } multirow-column` ) ;
57
51
}
52
+ swiper . emitContainerClasses ( ) ;
53
+ }
58
54
59
- extend ( swiper . params , breakpointParams ) ;
55
+ const directionChanged =
56
+ breakpointParams . direction && breakpointParams . direction !== params . direction ;
57
+ const needsReLoop =
58
+ params . loop && ( breakpointParams . slidesPerView !== params . slidesPerView || directionChanged ) ;
60
59
61
- extend ( swiper , {
62
- allowTouchMove : swiper . params . allowTouchMove ,
63
- allowSlideNext : swiper . params . allowSlideNext ,
64
- allowSlidePrev : swiper . params . allowSlidePrev ,
65
- } ) ;
60
+ if ( directionChanged && initialized ) {
61
+ swiper . changeDirection ( ) ;
62
+ }
66
63
67
- swiper . currentBreakpoint = breakpoint ;
64
+ extend ( swiper . params , breakpointParams ) ;
68
65
69
- swiper . emit ( '_beforeBreakpoint' , breakpointParams ) ;
66
+ extend ( swiper , {
67
+ allowTouchMove : swiper . params . allowTouchMove ,
68
+ allowSlideNext : swiper . params . allowSlideNext ,
69
+ allowSlidePrev : swiper . params . allowSlidePrev ,
70
+ } ) ;
70
71
71
- if ( needsReLoop && initialized ) {
72
- swiper . loopDestroy ( ) ;
73
- swiper . loopCreate ( ) ;
74
- swiper . updateSlides ( ) ;
75
- swiper . slideTo ( activeIndex - loopedSlides + swiper . loopedSlides , 0 , false ) ;
76
- }
72
+ if ( wasEnabled && ! isEnabled ) {
73
+ swiper . disable ( ) ;
74
+ } else if ( ! wasEnabled && isEnabled ) {
75
+ swiper . enable ( ) ;
76
+ }
77
77
78
- swiper . emit ( 'breakpoint' , breakpointParams ) ;
78
+ swiper . currentBreakpoint = breakpoint ;
79
+
80
+ swiper . emit ( '_beforeBreakpoint' , breakpointParams ) ;
81
+
82
+ if ( needsReLoop && initialized ) {
83
+ swiper . loopDestroy ( ) ;
84
+ swiper . loopCreate ( ) ;
85
+ swiper . updateSlides ( ) ;
86
+ swiper . slideTo ( activeIndex - loopedSlides + swiper . loopedSlides , 0 , false ) ;
79
87
}
88
+
89
+ swiper . emit ( 'breakpoint' , breakpointParams ) ;
80
90
}
0 commit comments