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

Commit 1d19663

Browse files
Gias Kay Leeajoslin
Gias Kay Lee
authored andcommitted
fix(carousel): do not allow user to change slide if transitioning
1 parent 88d17a7 commit 1d19663

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/carousel/carousel.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,20 @@ angular.module('ui.bootstrap.carousel', ['ui.bootstrap.transition'])
7777

7878
$scope.next = function() {
7979
var newIndex = (currentIndex + 1) % slides.length;
80-
return self.select(slides[newIndex], 'next');
80+
81+
//Prevent this user-triggered transition from occurring if there is already one in progress
82+
if (!$scope.$currentTransition) {
83+
return self.select(slides[newIndex], 'next');
84+
}
8185
};
8286

8387
$scope.prev = function() {
8488
var newIndex = currentIndex - 1 < 0 ? slides.length - 1 : currentIndex - 1;
85-
return self.select(slides[newIndex], 'prev');
89+
90+
//Prevent this user-triggered transition from occurring if there is already one in progress
91+
if (!$scope.$currentTransition) {
92+
return self.select(slides[newIndex], 'prev');
93+
}
8694
};
8795

8896
$scope.select = function(slide) {

src/carousel/test/carousel.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@ describe('carousel', function() {
205205
expect(contents.eq(0)).toHaveClass('active');
206206
expect(contents.eq(1).text()).toBe('new3');
207207
});
208+
209+
it('should not change if next is clicked while transitioning', function() {
210+
var carouselScope = elm.children().scope();
211+
var next = elm.find('a.right');
212+
213+
testSlideActive(0);
214+
carouselScope.$currentTransition = true;
215+
next.click();
216+
217+
testSlideActive(0);
218+
219+
carouselScope.$currentTransition = null;
220+
next.click();
221+
testSlideActive(1);
222+
});
208223
});
209224

210225
describe('controller', function() {

0 commit comments

Comments
 (0)