@@ -57,7 +57,9 @@ angular.module('ui.bootstrap.modal', [])
57
57
/**
58
58
* A helper directive for the $modal service. It creates a backdrop element.
59
59
*/
60
- . directive ( 'modalBackdrop' , [ '$timeout' , function ( $timeout ) {
60
+ . directive ( 'modalBackdrop' , [
61
+ '$animate' , '$modalStack' ,
62
+ function ( $animate , $modalStack ) {
61
63
return {
62
64
restrict : 'EA' ,
63
65
replace : true ,
@@ -71,10 +73,14 @@ angular.module('ui.bootstrap.modal', [])
71
73
function linkFn ( scope , element , attrs ) {
72
74
scope . animate = false ;
73
75
74
- //trigger CSS transitions
75
- $timeout ( function ( ) {
76
- scope . animate = true ;
77
- } ) ;
76
+ if ( attrs . modalInClass ) {
77
+ $animate . addClass ( element , attrs . modalInClass ) ;
78
+
79
+ scope . $on ( $modalStack . NOW_CLOSING_EVENT , function ( e , setIsAsync ) {
80
+ var done = setIsAsync ( ) ;
81
+ $animate . removeClass ( element , attrs . modalInClass ) . then ( done ) ;
82
+ } ) ;
83
+ }
78
84
}
79
85
} ] )
80
86
@@ -123,7 +129,7 @@ angular.module('ui.bootstrap.modal', [])
123
129
if ( attrs . modalInClass ) {
124
130
$animate . addClass ( element , attrs . modalInClass ) ;
125
131
126
- scope . $on ( $modalStack . WINDOW_CLOSING_EVENT , function ( e , setIsAsync ) {
132
+ scope . $on ( $modalStack . NOW_CLOSING_EVENT , function ( e , setIsAsync ) {
127
133
var done = setIsAsync ( ) ;
128
134
$animate . removeClass ( element , attrs . modalInClass ) . then ( done ) ;
129
135
} ) ;
@@ -189,7 +195,7 @@ angular.module('ui.bootstrap.modal', [])
189
195
var backdropDomEl , backdropScope ;
190
196
var openedWindows = $$stackedMap . createNew ( ) ;
191
197
var $modalStack = {
192
- WINDOW_CLOSING_EVENT : 'modal.stack.window -closing'
198
+ NOW_CLOSING_EVENT : 'modal.stack.now -closing'
193
199
} ;
194
200
195
201
function backdropIndex ( ) {
@@ -217,25 +223,7 @@ angular.module('ui.bootstrap.modal', [])
217
223
//clean up the stack
218
224
openedWindows . remove ( modalInstance ) ;
219
225
220
- var closingDeferred ;
221
- var closingPromise ;
222
- var setIsAsync = function ( ) {
223
- if ( ! closingDeferred ) {
224
- closingDeferred = $q . defer ( ) ;
225
- closingPromise = closingDeferred . promise ;
226
- }
227
-
228
- return function ( ) {
229
- closingDeferred . resolve ( ) ;
230
- } ;
231
- } ;
232
- modalWindow . modalScope . $broadcast ( $modalStack . WINDOW_CLOSING_EVENT , setIsAsync ) ;
233
-
234
- //remove window DOM element
235
- $q . when ( closingPromise ) . then ( function ( ) {
236
- modalWindow . modalDomEl . remove ( ) ;
237
- modalWindow . modalScope . $destroy ( ) ;
238
-
226
+ removeAfterAnimate ( modalWindow . modalDomEl , modalWindow . modalScope , function ( ) {
239
227
body . toggleClass ( OPENED_MODAL_CLASS , openedWindows . length ( ) > 0 ) ;
240
228
checkRemoveBackdrop ( ) ;
241
229
} ) ;
@@ -261,18 +249,21 @@ angular.module('ui.bootstrap.modal', [])
261
249
}
262
250
263
251
function removeAfterAnimate ( domEl , scope , done ) {
264
- // Closing animation
265
- scope . animate = false ;
266
-
267
- if ( domEl . attr ( 'modal-animation' ) && $animate . enabled ( ) ) {
268
- // transition out
269
- domEl . one ( '$animate:close' , function closeFn ( ) {
270
- $rootScope . $evalAsync ( afterAnimating ) ;
271
- } ) ;
272
- } else {
273
- // Ensure this call is async
274
- $timeout ( afterAnimating ) ;
275
- }
252
+ var closingDeferred ;
253
+ var closingPromise ;
254
+ var setIsAsync = function ( ) {
255
+ if ( ! closingDeferred ) {
256
+ closingDeferred = $q . defer ( ) ;
257
+ closingPromise = closingDeferred . promise ;
258
+ }
259
+
260
+ return function ( ) {
261
+ closingDeferred . resolve ( ) ;
262
+ } ;
263
+ } ;
264
+ scope . $broadcast ( $modalStack . NOW_CLOSING_EVENT , setIsAsync ) ;
265
+
266
+ return $q . when ( closingPromise ) . then ( afterAnimating ) ;
276
267
277
268
function afterAnimating ( ) {
278
269
if ( afterAnimating . done ) {
0 commit comments