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

Commit

Permalink
fix(modal): add $animateCss support
Browse files Browse the repository at this point in the history
- Add support for `$animateCss`
  • Loading branch information
wesleycho committed Aug 6, 2015
1 parent e60c3ff commit 0d5e619
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 10 deletions.
8 changes: 7 additions & 1 deletion src/carousel/carousel.js
Original file line number Diff line number Diff line change
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

0 comments on commit 0d5e619

Please sign in to comment.