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

Commit

Permalink
fix(carousel): do not allow user to change slide if transitioning
Browse files Browse the repository at this point in the history
  • Loading branch information
Gias Kay Lee authored and ajoslin committed May 30, 2013
1 parent 88d17a7 commit 1d19663
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/carousel/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions src/carousel/test/carousel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 1d19663

Please sign in to comment.