1
1
angular . module ( 'ui.bootstrap.carousel' , [ ] )
2
2
3
- . controller ( 'UibCarouselController' , [ '$scope' , '$element' , '$interval' , '$animate' , function ( $scope , $element , $interval , $animate ) {
3
+ . controller ( 'UibCarouselController' , [ '$scope' , '$element' , '$interval' , '$timeout' , '$ animate', function ( $scope , $element , $interval , $timeout , $animate ) {
4
4
var self = this ,
5
5
slides = self . slides = $scope . slides = [ ] ,
6
6
SLIDE_DIRECTION = 'uib-slideDirection' ,
7
7
currentIndex = - 1 ,
8
- currentInterval , isPlaying ;
8
+ currentInterval , isPlaying , bufferedTransitions = [ ] ;
9
9
self . currentSlide = null ;
10
10
11
11
var destroyed = false ;
@@ -19,6 +19,8 @@ angular.module('ui.bootstrap.carousel', [])
19
19
//Prevent this user-triggered transition from occurring if there is already one in progress
20
20
if ( nextSlide && nextSlide !== self . currentSlide && ! $scope . $currentTransition ) {
21
21
goNext ( nextSlide , nextIndex , direction ) ;
22
+ } else if ( nextSlide && nextSlide !== self . currentSlide && $scope . $currentTransition ) {
23
+ bufferedTransitions . push ( nextSlide ) ;
22
24
}
23
25
} ;
24
26
@@ -40,6 +42,14 @@ angular.module('ui.bootstrap.carousel', [])
40
42
if ( phase === 'close' ) {
41
43
$scope . $currentTransition = null ;
42
44
$animate . off ( 'addClass' , element ) ;
45
+ if ( bufferedTransitions . length ) {
46
+ var nextSlide = bufferedTransitions . pop ( ) ;
47
+ var nextIndex = $scope . indexOfSlide ( nextSlide ) ;
48
+ var nextDirection = nextIndex > self . getCurrentIndex ( ) ? 'next' : 'prev' ;
49
+ clearBufferedTransitions ( ) ;
50
+
51
+ goNext ( nextSlide , nextIndex , nextDirection ) ;
52
+ }
43
53
}
44
54
} ) ;
45
55
}
@@ -134,6 +144,13 @@ angular.module('ui.bootstrap.carousel', [])
134
144
function resetTransition ( slides ) {
135
145
if ( ! slides . length ) {
136
146
$scope . $currentTransition = null ;
147
+ clearBufferedTransitions ( ) ;
148
+ }
149
+ }
150
+
151
+ function clearBufferedTransitions ( ) {
152
+ while ( bufferedTransitions . length ) {
153
+ bufferedTransitions . shift ( ) ;
137
154
}
138
155
}
139
156
@@ -155,6 +172,10 @@ angular.module('ui.bootstrap.carousel', [])
155
172
slides . push ( slide ) ;
156
173
//if this is the first slide or the slide is set to active, select it
157
174
if ( slides . length === 1 || slide . active ) {
175
+ if ( $scope . $currentTransition ) {
176
+ $scope . $currentTransition = null ;
177
+ }
178
+
158
179
self . select ( slides [ slides . length - 1 ] ) ;
159
180
if ( slides . length === 1 ) {
160
181
$scope . play ( ) ;
@@ -170,22 +191,30 @@ angular.module('ui.bootstrap.carousel', [])
170
191
return + a . index > + b . index ;
171
192
} ) ;
172
193
}
194
+
195
+ var bufferedIndex = bufferedTransitions . indexOf ( slide ) ;
196
+ if ( bufferedIndex !== - 1 ) {
197
+ bufferedTransitions . splice ( bufferedIndex , 1 ) ;
198
+ }
173
199
//get the index of the slide inside the carousel
174
200
var index = slides . indexOf ( slide ) ;
175
201
slides . splice ( index , 1 ) ;
176
- if ( slides . length > 0 && slide . active ) {
177
- if ( index >= slides . length ) {
178
- self . select ( slides [ index - 1 ] ) ;
179
- } else {
180
- self . select ( slides [ index ] ) ;
202
+ $timeout ( function ( ) {
203
+ if ( slides . length > 0 && slide . active ) {
204
+ if ( index >= slides . length ) {
205
+ self . select ( slides [ index - 1 ] ) ;
206
+ } else {
207
+ self . select ( slides [ index ] ) ;
208
+ }
209
+ } else if ( currentIndex > index ) {
210
+ currentIndex -- ;
181
211
}
182
- } else if ( currentIndex > index ) {
183
- currentIndex -- ;
184
- }
212
+ } ) ;
185
213
186
214
//clean the currentSlide when no more slide
187
215
if ( slides . length === 0 ) {
188
216
self . currentSlide = null ;
217
+ clearBufferedTransitions ( ) ;
189
218
}
190
219
} ;
191
220
0 commit comments