1
1
import { isObject , extend } from './utils' ;
2
2
3
- function updateSwiper ( swiper , slides , passedParams , changedParams ) {
3
+ function updateSwiper ( {
4
+ swiper,
5
+ slides,
6
+ passedParams,
7
+ changedParams,
8
+ nextEl,
9
+ prevEl,
10
+ paginationEl,
11
+ scrollbarEl,
12
+ } ) {
4
13
const updateParams = changedParams . filter ( ( key ) => key !== 'children' && key !== 'direction' ) ;
5
14
const { params : currentParams , pagination, navigation, scrollbar, virtual, thumbs } = swiper ;
6
15
let needThumbsInit ;
@@ -29,7 +38,7 @@ function updateSwiper(swiper, slides, passedParams, changedParams) {
29
38
if (
30
39
changedParams . includes ( 'pagination' ) &&
31
40
passedParams . pagination &&
32
- passedParams . pagination . el &&
41
+ ( passedParams . pagination . el || paginationEl ) &&
33
42
( currentParams . pagination || currentParams . pagination === false ) &&
34
43
pagination &&
35
44
! pagination . el
@@ -40,7 +49,7 @@ function updateSwiper(swiper, slides, passedParams, changedParams) {
40
49
if (
41
50
changedParams . includes ( 'scrollbar' ) &&
42
51
passedParams . scrollbar &&
43
- passedParams . scrollbar . el &&
52
+ ( passedParams . scrollbar . el || scrollbarEl ) &&
44
53
( currentParams . scrollbar || currentParams . scrollbar === false ) &&
45
54
scrollbar &&
46
55
! scrollbar . el
@@ -51,8 +60,8 @@ function updateSwiper(swiper, slides, passedParams, changedParams) {
51
60
if (
52
61
changedParams . includes ( 'navigation' ) &&
53
62
passedParams . navigation &&
54
- passedParams . navigation . prevEl &&
55
- passedParams . navigation . nextEl &&
63
+ ( passedParams . navigation . prevEl || prevEl ) &&
64
+ ( passedParams . navigation . nextEl || nextEl ) &&
56
65
( currentParams . navigation || currentParams . navigation === false ) &&
57
66
navigation &&
58
67
! navigation . prevEl &&
@@ -61,11 +70,35 @@ function updateSwiper(swiper, slides, passedParams, changedParams) {
61
70
needNavigationInit = true ;
62
71
}
63
72
73
+ const destroyModule = ( mod ) => {
74
+ if ( ! swiper [ mod ] ) return ;
75
+ swiper [ mod ] . destroy ( ) ;
76
+ if ( mod === 'navigation' ) {
77
+ currentParams [ mod ] . prevEl = undefined ;
78
+ currentParams [ mod ] . nextEl = undefined ;
79
+ swiper [ mod ] . prevEl = undefined ;
80
+ swiper [ mod ] . nextEl = undefined ;
81
+ } else {
82
+ currentParams [ mod ] . el = undefined ;
83
+ swiper [ mod ] . el = undefined ;
84
+ }
85
+ } ;
86
+
64
87
updateParams . forEach ( ( key ) => {
65
88
if ( isObject ( currentParams [ key ] ) && isObject ( passedParams [ key ] ) ) {
66
89
extend ( currentParams [ key ] , passedParams [ key ] ) ;
67
90
} else {
68
- currentParams [ key ] = passedParams [ key ] ;
91
+ const newValue = passedParams [ key ] ;
92
+ if (
93
+ ( newValue === true || newValue === false ) &&
94
+ ( key === 'navigation' || key === 'pagination' || key === 'scrollbar' )
95
+ ) {
96
+ if ( newValue === false ) {
97
+ destroyModule ( key ) ;
98
+ }
99
+ } else {
100
+ currentParams [ key ] = passedParams [ key ] ;
101
+ }
69
102
}
70
103
} ) ;
71
104
@@ -86,18 +119,22 @@ function updateSwiper(swiper, slides, passedParams, changedParams) {
86
119
}
87
120
88
121
if ( needPaginationInit ) {
122
+ if ( paginationEl ) currentParams . pagination . el = paginationEl ;
89
123
pagination . init ( ) ;
90
124
pagination . render ( ) ;
91
125
pagination . update ( ) ;
92
126
}
93
127
94
128
if ( needScrollbarInit ) {
129
+ if ( scrollbarEl ) currentParams . scrollbar . el = scrollbarEl ;
95
130
scrollbar . init ( ) ;
96
131
scrollbar . updateSize ( ) ;
97
132
scrollbar . setTranslate ( ) ;
98
133
}
99
134
100
135
if ( needNavigationInit ) {
136
+ if ( nextEl ) currentParams . navigation . nextEl = nextEl ;
137
+ if ( prevEl ) currentParams . navigation . prevEl = prevEl ;
101
138
navigation . init ( ) ;
102
139
navigation . update ( ) ;
103
140
}
0 commit comments