Skip to content

Commit

Permalink
fix(carousel): disable transition until animation completes
Browse files Browse the repository at this point in the history
- 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 angular-ui#3729
Closes angular-ui#3757
  • Loading branch information
wesleycho authored and bleggett committed Jun 11, 2015
1 parent b186945 commit 1b9f41d
Showing 1 changed file with 25 additions and 26 deletions.
51 changes: 25 additions & 26 deletions src/carousel/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,33 @@ angular.module('ui.bootstrap.carousel', [])
if (direction === undefined) {
direction = nextIndex > self.getCurrentIndex() ? 'next' : 'prev';
}
if (nextSlide && nextSlide !== self.currentSlide) {
goNext();
//Prevent this user-triggered transition from occurring if there is already one in progress
if (nextSlide && nextSlide !== self.currentSlide && !$scope.$currentTransition) {
goNext(nextSlide, nextIndex, direction);
}
function goNext() {
// Scope has been destroyed, stop here.
if (destroyed) { return; }
};

angular.extend(nextSlide, {direction: direction, active: true});
angular.extend(self.currentSlide || {}, {direction: direction, active: false});
if ($animate.enabled() && !$scope.noTransition && nextSlide.$element) {
$scope.$currentTransition = true;
nextSlide.$element.one('$animate:close', function closeFn() {
$scope.$currentTransition = null;
});
}
function goNext(slide, index, direction) {
// Scope has been destroyed, stop here.
if (destroyed) { return; }

self.currentSlide = nextSlide;
currentIndex = nextIndex;
//every time you change slides, reset the timer
restartTimer();
angular.extend(slide, {direction: direction, active: true});
angular.extend(self.currentSlide || {}, {direction: direction, active: false});
if ($animate.enabled() && !$scope.noTransition && !$scope.$currentTransition &&
slide.$element) {
$scope.$currentTransition = true;
slide.$element.one('$animate:close', function closeFn() {
$scope.$currentTransition = null;
});
}
};

self.currentSlide = slide;
currentIndex = index;

//every time you change slides, reset the timer
restartTimer();
}

$scope.$on('$destroy', function () {
destroyed = true;
});
Expand Down Expand Up @@ -75,19 +80,13 @@ angular.module('ui.bootstrap.carousel', [])
$scope.next = function() {
var newIndex = (self.getCurrentIndex() + 1) % slides.length;

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

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

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

$scope.isActive = function(slide) {
Expand Down

0 comments on commit 1b9f41d

Please sign in to comment.