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

Commit 742132a

Browse files
committed
feat(modal): change to use $animate
- Change to use $animate and $animateCss Closes #3418 Closes #4834
1 parent 342c576 commit 742132a

File tree

2 files changed

+32
-37
lines changed

2 files changed

+32
-37
lines changed

Diff for: src/modal/modal.js

+18-37
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,8 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
107107
}])
108108

109109
.directive('uibModalWindow', [
110-
'$uibModalStack', '$q', '$animate', '$injector',
111-
function($modalStack , $q , $animate, $injector) {
112-
var $animateCss = null;
113-
114-
if ($injector.has('$animateCss')) {
115-
$animateCss = $injector.get('$animateCss');
116-
}
117-
110+
'$uibModalStack', '$q', '$animate', '$animateCss',
111+
function($modalStack, $q, $animate, $animateCss) {
118112
return {
119113
scope: {
120114
index: '@'
@@ -160,13 +154,9 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
160154
var animationPromise = null;
161155

162156
if (attrs.modalInClass) {
163-
if ($animateCss) {
164-
animationPromise = $animateCss(element, {
165-
addClass: attrs.modalInClass
166-
}).start();
167-
} else {
168-
animationPromise = $animate.addClass(element, attrs.modalInClass);
169-
}
157+
animationPromise = $animateCss(element, {
158+
addClass: attrs.modalInClass
159+
}).start();
170160

171161
scope.$on($modalStack.NOW_CLOSING_EVENT, function(e, setIsAsync) {
172162
var done = setIsAsync();
@@ -230,22 +220,14 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
230220
})
231221

232222
.factory('$uibModalStack', [
233-
'$animate', '$timeout', '$document', '$compile', '$rootScope',
223+
'$animate', '$animateCss', '$timeout', '$document', '$compile', '$rootScope',
234224
'$q',
235-
'$injector',
236225
'$$multiMap',
237226
'$$stackedMap',
238-
function($animate , $timeout , $document , $compile , $rootScope ,
227+
function($animate , $animateCss, $timeout , $document , $compile , $rootScope ,
239228
$q,
240-
$injector,
241229
$$multiMap,
242230
$$stackedMap) {
243-
var $animateCss = null;
244-
245-
if ($injector.has('$animateCss')) {
246-
$animateCss = $injector.get('$animateCss');
247-
}
248-
249231
var OPENED_MODAL_CLASS = 'modal-open';
250232

251233
var backdropDomEl, backdropScope;
@@ -350,15 +332,12 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
350332
}
351333
afterAnimating.done = true;
352334

353-
if ($animateCss) {
354-
$animateCss(domEl, {
355-
event: 'leave'
356-
}).start().then(function() {
357-
domEl.remove();
358-
});
359-
} else {
360-
$animate.leave(domEl);
361-
}
335+
$animateCss(domEl, {
336+
event: 'leave'
337+
}).start().then(function() {
338+
domEl.remove();
339+
});
340+
362341
scope.$destroy();
363342
if (done) {
364343
done();
@@ -441,7 +420,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
441420
angularBackgroundDomEl.attr('modal-animation', 'true');
442421
}
443422
backdropDomEl = $compile(angularBackgroundDomEl)(backdropScope);
444-
appendToElement.append(backdropDomEl);
423+
$animate.enter(backdropDomEl, appendToElement);
445424
}
446425

447426
var angularDomEl = angular.element('<div uib-modal-window="modal-window"></div>');
@@ -460,8 +439,10 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
460439
var modalDomEl = $compile(angularDomEl)(modal.scope);
461440
openedWindows.top().value.modalDomEl = modalDomEl;
462441
openedWindows.top().value.modalOpener = modalOpener;
463-
appendToElement.append(modalDomEl);
464-
appendToElement.addClass(modalBodyClass);
442+
$animate.enter(modalDomEl, appendToElement)
443+
.then(function() {
444+
$animate.addClass(appendToElement, modalBodyClass);
445+
});
465446

466447
$modalStack.clearFocusListCache();
467448
};

Diff for: src/modal/test/modal.spec.js

+14
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,8 @@ describe('$uibModal', function () {
888888
template: '<div>dummy modal</div>'
889889
});
890890

891+
$animate.flush();
892+
891893
expect(body).toHaveClass('modal-open');
892894
});
893895

@@ -897,6 +899,8 @@ describe('$uibModal', function () {
897899
openedClass: 'foo'
898900
});
899901

902+
$animate.flush();
903+
900904
expect(body).toHaveClass('foo');
901905
expect(body).not.toHaveClass('modal-open');
902906
});
@@ -907,6 +911,8 @@ describe('$uibModal', function () {
907911
openedClass: 'foo'
908912
});
909913

914+
$animate.flush();
915+
910916
expect(body).toHaveClass('foo');
911917

912918
close(modal);
@@ -920,6 +926,8 @@ describe('$uibModal', function () {
920926
openedClass: 'foo'
921927
});
922928

929+
$animate.flush();
930+
923931
expect(body).toHaveClass('foo');
924932
expect(body).not.toHaveClass('modal-open');
925933

@@ -928,6 +936,8 @@ describe('$uibModal', function () {
928936
openedClass: 'bar'
929937
});
930938

939+
$animate.flush();
940+
931941
expect(body).toHaveClass('foo');
932942
expect(body).toHaveClass('bar');
933943
expect(body).not.toHaveClass('modal-open');
@@ -937,6 +947,8 @@ describe('$uibModal', function () {
937947
openedClass: 'foo'
938948
});
939949

950+
$animate.flush();
951+
940952
expect(body).toHaveClass('foo');
941953
expect(body).toHaveClass('bar');
942954
expect(body).not.toHaveClass('modal-open');
@@ -1009,9 +1021,11 @@ describe('$uibModal', function () {
10091021
expect(body).not.toHaveClass('modal-open');
10101022

10111023
var modal1 = open({template: '<div>Content1</div>'});
1024+
$animate.flush();
10121025
expect(body).toHaveClass('modal-open');
10131026

10141027
var modal2 = open({template: '<div>Content1</div>'});
1028+
$animate.flush();
10151029
expect(body).toHaveClass('modal-open');
10161030

10171031
dismiss(modal1);

0 commit comments

Comments
 (0)