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

fix(carousel): disable transition until animation completes #3757

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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