Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit ef45ecf

Browse files
wesleychochrisirhc
authored andcommitted
fix(carousel): disable transition until animation completes
- Force the carousel indicator to not select the slide if the animation has not completed - Factor out `goNext` function to not redefine on each execution of `select` chore(carousel): move `$currentTransition` check to `select` method Fixes #3729 Closes #3757
1 parent 83c4266 commit ef45ecf

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

src/carousel/carousel.js

+25-26
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,33 @@ angular.module('ui.bootstrap.carousel', [])
2222
if (direction === undefined) {
2323
direction = nextIndex > self.getCurrentIndex() ? 'next' : 'prev';
2424
}
25-
if (nextSlide && nextSlide !== self.currentSlide) {
26-
goNext();
25+
//Prevent this user-triggered transition from occurring if there is already one in progress
26+
if (nextSlide && nextSlide !== self.currentSlide && !$scope.$currentTransition) {
27+
goNext(nextSlide, nextIndex, direction);
2728
}
28-
function goNext() {
29-
// Scope has been destroyed, stop here.
30-
if (destroyed) { return; }
29+
};
3130

32-
angular.extend(nextSlide, {direction: direction, active: true});
33-
angular.extend(self.currentSlide || {}, {direction: direction, active: false});
34-
if ($animate.enabled() && !$scope.noTransition && nextSlide.$element) {
35-
$scope.$currentTransition = true;
36-
nextSlide.$element.one('$animate:close', function closeFn() {
37-
$scope.$currentTransition = null;
38-
});
39-
}
31+
function goNext(slide, index, direction) {
32+
// Scope has been destroyed, stop here.
33+
if (destroyed) { return; }
4034

41-
self.currentSlide = nextSlide;
42-
currentIndex = nextIndex;
43-
//every time you change slides, reset the timer
44-
restartTimer();
35+
angular.extend(slide, {direction: direction, active: true});
36+
angular.extend(self.currentSlide || {}, {direction: direction, active: false});
37+
if ($animate.enabled() && !$scope.noTransition && !$scope.$currentTransition &&
38+
slide.$element) {
39+
$scope.$currentTransition = true;
40+
slide.$element.one('$animate:close', function closeFn() {
41+
$scope.$currentTransition = null;
42+
});
4543
}
46-
};
44+
45+
self.currentSlide = slide;
46+
currentIndex = index;
47+
48+
//every time you change slides, reset the timer
49+
restartTimer();
50+
}
51+
4752
$scope.$on('$destroy', function () {
4853
destroyed = true;
4954
});
@@ -75,19 +80,13 @@ angular.module('ui.bootstrap.carousel', [])
7580
$scope.next = function() {
7681
var newIndex = (self.getCurrentIndex() + 1) % slides.length;
7782

78-
//Prevent this user-triggered transition from occurring if there is already one in progress
79-
if (!$scope.$currentTransition) {
80-
return self.select(getSlideByIndex(newIndex), 'next');
81-
}
83+
return self.select(getSlideByIndex(newIndex), 'next');
8284
};
8385

8486
$scope.prev = function() {
8587
var newIndex = self.getCurrentIndex() - 1 < 0 ? slides.length - 1 : self.getCurrentIndex() - 1;
8688

87-
//Prevent this user-triggered transition from occurring if there is already one in progress
88-
if (!$scope.$currentTransition) {
89-
return self.select(getSlideByIndex(newIndex), 'prev');
90-
}
89+
return self.select(getSlideByIndex(newIndex), 'prev');
9190
};
9291

9392
$scope.isActive = function(slide) {

0 commit comments

Comments
 (0)