diff --git a/src/carousel/carousel.js b/src/carousel/carousel.js index 14dd3a6bca..ce50c9429a 100644 --- a/src/carousel/carousel.js +++ b/src/carousel/carousel.js @@ -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; }); @@ -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) {