diff --git a/src/carousel/carousel.js b/src/carousel/carousel.js index 4fb09b7e87..4e9edd21ee 100644 --- a/src/carousel/carousel.js +++ b/src/carousel/carousel.js @@ -77,12 +77,20 @@ angular.module('ui.bootstrap.carousel', ['ui.bootstrap.transition']) $scope.next = function() { var newIndex = (currentIndex + 1) % slides.length; - return self.select(slides[newIndex], 'next'); + + //Prevent this user-triggered transition from occurring if there is already one in progress + if (!$scope.$currentTransition) { + return self.select(slides[newIndex], 'next'); + } }; $scope.prev = function() { var newIndex = currentIndex - 1 < 0 ? slides.length - 1 : currentIndex - 1; - return self.select(slides[newIndex], 'prev'); + + //Prevent this user-triggered transition from occurring if there is already one in progress + if (!$scope.$currentTransition) { + return self.select(slides[newIndex], 'prev'); + } }; $scope.select = function(slide) { diff --git a/src/carousel/test/carousel.spec.js b/src/carousel/test/carousel.spec.js index a962bc15dc..e7b44f87e1 100644 --- a/src/carousel/test/carousel.spec.js +++ b/src/carousel/test/carousel.spec.js @@ -205,6 +205,21 @@ describe('carousel', function() { expect(contents.eq(0)).toHaveClass('active'); expect(contents.eq(1).text()).toBe('new3'); }); + + it('should not change if next is clicked while transitioning', function() { + var carouselScope = elm.children().scope(); + var next = elm.find('a.right'); + + testSlideActive(0); + carouselScope.$currentTransition = true; + next.click(); + + testSlideActive(0); + + carouselScope.$currentTransition = null; + next.click(); + testSlideActive(1); + }); }); describe('controller', function() {