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

fix(modal): add $animateCss support #4121

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions src/carousel/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ angular.module('ui.bootstrap.carousel', [])
angular.extend(slide, {direction: direction, active: true});
angular.extend(self.currentSlide || {}, {direction: direction, active: false});
if ($animate.enabled() && !$scope.noTransition && !$scope.$currentTransition &&
slide.$element) {
slide.$element && self.slides.length > 1) {
slide.$element.data(SLIDE_DIRECTION, slide.direction);
if (self.currentSlide && self.currentSlide.$element) {
self.currentSlide.$element.data(SLIDE_DIRECTION, slide.direction);
Expand Down Expand Up @@ -334,7 +334,13 @@ function CarouselDemoCtrl($scope) {
function ($injector, $animate, ANIMATE_CSS) {
var NO_TRANSITION = 'uib-noTransition',
SLIDE_DIRECTION = 'uib-slideDirection',
$animateCss = ANIMATE_CSS ? $injector.get('$animateCss') : null;
$animateCss = null;

if (ANIMATE_CSS) {
try {
$animateCss = $injector.get('$animateCss');
} catch(e) {}
}

function removeClass(element, className, callback) {
element.removeClass(className);
Expand Down
75 changes: 66 additions & 9 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,16 @@ angular.module('ui.bootstrap.modal', [])
* A helper directive for the $modal service. It creates a backdrop element.
*/
.directive('modalBackdrop', [
'$animate', '$modalStack',
function ($animate , $modalStack) {
'$animate', '$injector', '$modalStack',
function ($animate , $injector, $modalStack) {
var $animateCss = null;

if (angular.version.minor >= 4) {
try {
$animateCss = $injector.get('$animateCss');
} catch(e) {}
}

return {
restrict: 'EA',
replace: true,
Expand All @@ -72,19 +80,39 @@ angular.module('ui.bootstrap.modal', [])

function linkFn(scope, element, attrs) {
if (attrs.modalInClass) {
$animate.addClass(element, attrs.modalInClass);
if ($animateCss) {
$animateCss(element, {
addClass: attrs.modalInClass
}).start();
} else {
$animate.addClass(element, attrs.modalInClass);
}

scope.$on($modalStack.NOW_CLOSING_EVENT, function (e, setIsAsync) {
var done = setIsAsync();
$animate.removeClass(element, attrs.modalInClass).then(done);
if ($animateCss) {
$animateCss(element, {
removeClass: attrs.modalInClass
}).start().then(done);
} else {
$animate.removeClass(element, attrs.modalInClass).then(done);
}
});
}
}
}])

.directive('modalWindow', [
'$modalStack', '$q', '$animate',
function ($modalStack , $q , $animate) {
'$modalStack', '$q', '$animate', '$injector',
function ($modalStack , $q , $animate, $injector) {
var $animateCss = null;

if (angular.version.minor >= 4) {
try {
$animateCss = $injector.get('$animateCss');
} catch(e) {}
}

return {
restrict: 'EA',
scope: {
Expand Down Expand Up @@ -125,11 +153,23 @@ angular.module('ui.bootstrap.modal', [])

modalRenderDeferObj.promise.then(function () {
if (attrs.modalInClass) {
$animate.addClass(element, attrs.modalInClass);
if ($animateCss) {
$animateCss(element, {
addClass: attrs.modalInClass
}).start();
} else {
$animate.addClass(element, attrs.modalInClass);
}

scope.$on($modalStack.NOW_CLOSING_EVENT, function (e, setIsAsync) {
var done = setIsAsync();
$animate.removeClass(element, attrs.modalInClass).then(done);
if ($animateCss) {
$animateCss(element, {
removeClass: attrs.modalInClass
}).start().then(done);
} else {
$animate.removeClass(element, attrs.modalInClass).then(done);
}
});
}

Expand Down Expand Up @@ -183,10 +223,19 @@ angular.module('ui.bootstrap.modal', [])
.factory('$modalStack', [
'$animate', '$timeout', '$document', '$compile', '$rootScope',
'$q',
'$injector',
'$$stackedMap',
function ($animate , $timeout , $document , $compile , $rootScope ,
$q,
$injector,
$$stackedMap) {
var $animateCss = null;

if (angular.version.minor >= 4) {
try {
$animateCss = $injector.get('$animateCss');
} catch(e) {}
}

var OPENED_MODAL_CLASS = 'modal-open';

Expand Down Expand Up @@ -279,7 +328,15 @@ angular.module('ui.bootstrap.modal', [])
}
afterAnimating.done = true;

$animate.leave(domEl);
if ($animateCss) {
$animateCss(domEl, {
event: 'leave'
}).start().then(function() {
domEl.remove();
});
} else {
$animate.leave(domEl);
}
scope.$destroy();
if (done) {
done();
Expand Down