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

feat(modal): change to use $animate #4834

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
55 changes: 18 additions & 37 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,8 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
}])

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

if ($injector.has('$animateCss')) {
$animateCss = $injector.get('$animateCss');
}

'$uibModalStack', '$q', '$animate', '$animateCss',
function($modalStack, $q, $animate, $animateCss) {
return {
scope: {
index: '@'
Expand Down Expand Up @@ -160,13 +154,9 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
var animationPromise = null;

if (attrs.modalInClass) {
if ($animateCss) {
animationPromise = $animateCss(element, {
addClass: attrs.modalInClass
}).start();
} else {
animationPromise = $animate.addClass(element, attrs.modalInClass);
}
animationPromise = $animateCss(element, {
addClass: attrs.modalInClass
}).start();

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

.factory('$uibModalStack', [
'$animate', '$timeout', '$document', '$compile', '$rootScope',
'$animate', '$animateCss', '$timeout', '$document', '$compile', '$rootScope',
'$q',
'$injector',
'$$multiMap',
'$$stackedMap',
function($animate , $timeout , $document , $compile , $rootScope ,
function($animate , $animateCss, $timeout , $document , $compile , $rootScope ,
$q,
$injector,
$$multiMap,
$$stackedMap) {
var $animateCss = null;

if ($injector.has('$animateCss')) {
$animateCss = $injector.get('$animateCss');
}

var OPENED_MODAL_CLASS = 'modal-open';

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

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

scope.$destroy();
if (done) {
done();
Expand Down Expand Up @@ -441,7 +420,7 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
angularBackgroundDomEl.attr('modal-animation', 'true');
}
backdropDomEl = $compile(angularBackgroundDomEl)(backdropScope);
appendToElement.append(backdropDomEl);
$animate.enter(backdropDomEl, appendToElement);
}

var angularDomEl = angular.element('<div uib-modal-window="modal-window"></div>');
Expand All @@ -460,8 +439,10 @@ angular.module('ui.bootstrap.modal', ['ui.bootstrap.stackedMap'])
var modalDomEl = $compile(angularDomEl)(modal.scope);
openedWindows.top().value.modalDomEl = modalDomEl;
openedWindows.top().value.modalOpener = modalOpener;
appendToElement.append(modalDomEl);
appendToElement.addClass(modalBodyClass);
$animate.enter(modalDomEl, appendToElement)
.then(function() {
$animate.addClass(appendToElement, modalBodyClass);
});

$modalStack.clearFocusListCache();
};
Expand Down
14 changes: 14 additions & 0 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,8 @@ describe('$uibModal', function () {
template: '<div>dummy modal</div>'
});

$animate.flush();

expect(body).toHaveClass('modal-open');
});

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

$animate.flush();

expect(body).toHaveClass('foo');
expect(body).not.toHaveClass('modal-open');
});
Expand All @@ -907,6 +911,8 @@ describe('$uibModal', function () {
openedClass: 'foo'
});

$animate.flush();

expect(body).toHaveClass('foo');

close(modal);
Expand All @@ -920,6 +926,8 @@ describe('$uibModal', function () {
openedClass: 'foo'
});

$animate.flush();

expect(body).toHaveClass('foo');
expect(body).not.toHaveClass('modal-open');

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

$animate.flush();

expect(body).toHaveClass('foo');
expect(body).toHaveClass('bar');
expect(body).not.toHaveClass('modal-open');
Expand All @@ -937,6 +947,8 @@ describe('$uibModal', function () {
openedClass: 'foo'
});

$animate.flush();

expect(body).toHaveClass('foo');
expect(body).toHaveClass('bar');
expect(body).not.toHaveClass('modal-open');
Expand Down Expand Up @@ -1009,9 +1021,11 @@ describe('$uibModal', function () {
expect(body).not.toHaveClass('modal-open');

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

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

dismiss(modal1);
Expand Down