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

Commit 061ec62

Browse files
committed
feat(modal): add option to disable animations
1 parent c4d324c commit 061ec62

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

Diff for: src/modal/modal.js

+32-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
angular.module('ui.bootstrap.modal', [])
22

3+
.constant('modalConfig', {
4+
animation: true
5+
})
6+
37
/**
48
* A helper, internal data structure that acts as a map but also allows getting / removing
59
* elements in the LIFO order
@@ -57,22 +61,29 @@ angular.module('ui.bootstrap.modal', [])
5761
/**
5862
* A helper directive for the $modal service. It creates a backdrop element.
5963
*/
60-
.directive('modalBackdrop', ['$timeout', function ($timeout) {
64+
.directive('modalBackdrop', ['$timeout', 'modalConfig', function ($timeout, modalConfig) {
6165
return {
6266
restrict: 'EA',
6367
replace: true,
6468
templateUrl: 'template/modal/backdrop.html',
65-
link: function (scope, element, attrs) {
66-
scope.backdropClass = attrs.backdropClass || '';
69+
compile: function (tElement, tAttrs) {
70+
tElement.addClass(tAttrs.backdropClass);
71+
return linkFn;
72+
},
73+
};
6774

75+
function linkFn(scope, element, attrs) {
76+
if (modalConfig.animation) {
6877
scope.animate = false;
6978

7079
//trigger CSS transitions
7180
$timeout(function () {
7281
scope.animate = true;
7382
});
83+
} else {
84+
scope.animate = true;
7485
}
75-
};
86+
}
7687
}])
7788

7889
.directive('modalWindow', ['$modalStack', '$timeout', function ($modalStack, $timeout) {
@@ -120,6 +131,18 @@ angular.module('ui.bootstrap.modal', [])
120131
};
121132
}])
122133

134+
.directive('modalAnimationClass', [
135+
'modalConfig',
136+
function (modalConfig) {
137+
return {
138+
compile: function (tElement, tAttrs) {
139+
if (modalConfig.animation) {
140+
tElement.addClass(tAttrs.modalAnimationClass);
141+
}
142+
}
143+
};
144+
}])
145+
123146
.directive('modalTransclude', function () {
124147
return {
125148
link: function($scope, $element, $attrs, controller, $transclude) {
@@ -131,8 +154,8 @@ angular.module('ui.bootstrap.modal', [])
131154
};
132155
})
133156

134-
.factory('$modalStack', ['$animate', '$timeout', '$document', '$compile', '$rootScope', '$$stackedMap',
135-
function ($animate, $timeout, $document, $compile, $rootScope, $$stackedMap) {
157+
.factory('$modalStack', ['$animate', '$timeout', '$document', '$compile', '$rootScope', '$$stackedMap', 'modalConfig',
158+
function ($animate, $timeout, $document, $compile, $rootScope, $$stackedMap, modalConfig) {
136159

137160
var OPENED_MODAL_CLASS = 'modal-open';
138161

@@ -185,10 +208,10 @@ angular.module('ui.bootstrap.modal', [])
185208
}
186209

187210
function removeAfterAnimate(domEl, scope, done) {
188-
// Closing animation
189-
scope.animate = false;
211+
if (modalConfig.animation && $animate.enabled()) {
212+
// Closing animation
213+
scope.animate = false;
190214

191-
if ($animate.enabled()) {
192215
// transition out
193216
domEl.on('$animate:close', function closeFn() {
194217
afterAnimating();

Diff for: template/modal/backdrop.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<div class="modal-backdrop fade {{ backdropClass }}"
1+
<div class="modal-backdrop"
2+
modal-animation-class="fade"
23
ng-class="{in: animate}"
34
ng-style="{'z-index': 1040 + (index && 1 || 0) + index*10}"
45
></div>

Diff for: template/modal/window.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
<div tabindex="-1" role="dialog" class="modal fade" ng-class="{in: animate}" ng-style="{'z-index': 1050 + index*10, display: 'block'}" ng-click="close($event)">
1+
<div tabindex="-1" role="dialog" class="modal"
2+
modal-animation-class="fade"
3+
ng-class="{in: animate}" ng-style="{'z-index': 1050 + index*10, display: 'block'}" ng-click="close($event)">
24
<div class="modal-dialog" ng-class="{'modal-sm': size == 'sm', 'modal-lg': size == 'lg'}"><div class="modal-content" modal-transclude></div></div>
35
</div>

0 commit comments

Comments
 (0)