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

Commit c7f19d5

Browse files
committed
fix(modal): add $animateCss support
- Add support for `$animateCss` Closes #4121 Fixes #4119
1 parent 265d429 commit c7f19d5

File tree

2 files changed

+74
-11
lines changed

2 files changed

+74
-11
lines changed

src/carousel/carousel.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ angular.module('ui.bootstrap.carousel', [])
3838
angular.extend(slide, {direction: direction, active: true});
3939
angular.extend(self.currentSlide || {}, {direction: direction, active: false});
4040
if ($animate.enabled() && !$scope.noTransition && !$scope.$currentTransition &&
41-
slide.$element) {
41+
slide.$element && self.slides.length > 1) {
4242
slide.$element.data(SLIDE_DIRECTION, slide.direction);
4343
if (self.currentSlide && self.currentSlide.$element) {
4444
self.currentSlide.$element.data(SLIDE_DIRECTION, slide.direction);
@@ -334,7 +334,13 @@ function CarouselDemoCtrl($scope) {
334334
function ($injector, $animate, ANIMATE_CSS) {
335335
var NO_TRANSITION = 'uib-noTransition',
336336
SLIDE_DIRECTION = 'uib-slideDirection',
337-
$animateCss = ANIMATE_CSS ? $injector.get('$animateCss') : null;
337+
$animateCss = null;
338+
339+
if (ANIMATE_CSS) {
340+
try {
341+
$animateCss = $injector.get('$animateCss');
342+
} catch(e) {}
343+
}
338344

339345
function removeClass(element, className, callback) {
340346
element.removeClass(className);

src/modal/modal.js

+66-9
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,16 @@ angular.module('ui.bootstrap.modal', [])
5858
* A helper directive for the $modal service. It creates a backdrop element.
5959
*/
6060
.directive('modalBackdrop', [
61-
'$animate', '$modalStack',
62-
function ($animate , $modalStack) {
61+
'$animate', '$injector', '$modalStack',
62+
function ($animate , $injector, $modalStack) {
63+
var $animateCss = null;
64+
65+
if (angular.version.minor >= 4) {
66+
try {
67+
$animateCss = $injector.get('$animateCss');
68+
} catch(e) {}
69+
}
70+
6371
return {
6472
restrict: 'EA',
6573
replace: true,
@@ -72,19 +80,39 @@ angular.module('ui.bootstrap.modal', [])
7280

7381
function linkFn(scope, element, attrs) {
7482
if (attrs.modalInClass) {
75-
$animate.addClass(element, attrs.modalInClass);
83+
if ($animateCss) {
84+
$animateCss(element, {
85+
addClass: attrs.modalInClass
86+
}).start();
87+
} else {
88+
$animate.addClass(element, attrs.modalInClass);
89+
}
7690

7791
scope.$on($modalStack.NOW_CLOSING_EVENT, function (e, setIsAsync) {
7892
var done = setIsAsync();
79-
$animate.removeClass(element, attrs.modalInClass).then(done);
93+
if ($animateCss) {
94+
$animateCss(element, {
95+
removeClass: attrs.modalInClass
96+
}).start().then(done);
97+
} else {
98+
$animate.removeClass(element, attrs.modalInClass).then(done);
99+
}
80100
});
81101
}
82102
}
83103
}])
84104

85105
.directive('modalWindow', [
86-
'$modalStack', '$q', '$animate',
87-
function ($modalStack , $q , $animate) {
106+
'$modalStack', '$q', '$animate', '$injector',
107+
function ($modalStack , $q , $animate, $injector) {
108+
var $animateCss = null;
109+
110+
if (angular.version.minor >= 4) {
111+
try {
112+
$animateCss = $injector.get('$animateCss');
113+
} catch(e) {}
114+
}
115+
88116
return {
89117
restrict: 'EA',
90118
scope: {
@@ -125,11 +153,23 @@ angular.module('ui.bootstrap.modal', [])
125153

126154
modalRenderDeferObj.promise.then(function () {
127155
if (attrs.modalInClass) {
128-
$animate.addClass(element, attrs.modalInClass);
156+
if ($animateCss) {
157+
$animateCss(element, {
158+
addClass: attrs.modalInClass
159+
}).start();
160+
} else {
161+
$animate.addClass(element, attrs.modalInClass);
162+
}
129163

130164
scope.$on($modalStack.NOW_CLOSING_EVENT, function (e, setIsAsync) {
131165
var done = setIsAsync();
132-
$animate.removeClass(element, attrs.modalInClass).then(done);
166+
if ($animateCss) {
167+
$animateCss(element, {
168+
removeClass: attrs.modalInClass
169+
}).start().then(done);
170+
} else {
171+
$animate.removeClass(element, attrs.modalInClass).then(done);
172+
}
133173
});
134174
}
135175

@@ -183,10 +223,19 @@ angular.module('ui.bootstrap.modal', [])
183223
.factory('$modalStack', [
184224
'$animate', '$timeout', '$document', '$compile', '$rootScope',
185225
'$q',
226+
'$injector',
186227
'$$stackedMap',
187228
function ($animate , $timeout , $document , $compile , $rootScope ,
188229
$q,
230+
$injector,
189231
$$stackedMap) {
232+
var $animateCss = null;
233+
234+
if (angular.version.minor >= 4) {
235+
try {
236+
$animateCss = $injector.get('$animateCss');
237+
} catch(e) {}
238+
}
190239

191240
var OPENED_MODAL_CLASS = 'modal-open';
192241

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

282-
$animate.leave(domEl);
331+
if ($animateCss) {
332+
$animateCss(domEl, {
333+
event: 'leave'
334+
}).start().then(function() {
335+
domEl.remove();
336+
});
337+
} else {
338+
$animate.leave(domEl);
339+
}
283340
scope.$destroy();
284341
if (done) {
285342
done();

0 commit comments

Comments
 (0)