@@ -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 ,
@@ -69,12 +71,14 @@ angular.module('ui.bootstrap.modal', [])
69
71
} ;
70
72
71
73
function linkFn ( scope , element , attrs ) {
72
- scope . animate = false ;
74
+ if ( attrs . modalInClass ) {
75
+ $animate . addClass ( element , attrs . modalInClass ) ;
73
76
74
- //trigger CSS transitions
75
- $timeout ( function ( ) {
76
- scope . animate = true ;
77
- } ) ;
77
+ scope . $on ( $modalStack . NOW_CLOSING_EVENT , function ( e , setIsAsync ) {
78
+ var done = setIsAsync ( ) ;
79
+ $animate . removeClass ( element , attrs . modalInClass ) . then ( done ) ;
80
+ } ) ;
81
+ }
78
82
}
79
83
} ] )
80
84
@@ -123,7 +127,7 @@ angular.module('ui.bootstrap.modal', [])
123
127
if ( attrs . modalInClass ) {
124
128
$animate . addClass ( element , attrs . modalInClass ) ;
125
129
126
- scope . $on ( $modalStack . WINDOW_CLOSING_EVENT , function ( e , setIsAsync ) {
130
+ scope . $on ( $modalStack . NOW_CLOSING_EVENT , function ( e , setIsAsync ) {
127
131
var done = setIsAsync ( ) ;
128
132
$animate . removeClass ( element , attrs . modalInClass ) . then ( done ) ;
129
133
} ) ;
@@ -189,7 +193,7 @@ angular.module('ui.bootstrap.modal', [])
189
193
var backdropDomEl , backdropScope ;
190
194
var openedWindows = $$stackedMap . createNew ( ) ;
191
195
var $modalStack = {
192
- WINDOW_CLOSING_EVENT : 'modal.stack.window -closing'
196
+ NOW_CLOSING_EVENT : 'modal.stack.now -closing'
193
197
} ;
194
198
195
199
function backdropIndex ( ) {
@@ -217,25 +221,7 @@ angular.module('ui.bootstrap.modal', [])
217
221
//clean up the stack
218
222
openedWindows . remove ( modalInstance ) ;
219
223
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
-
224
+ removeAfterAnimate ( modalWindow . modalDomEl , modalWindow . modalScope , function ( ) {
239
225
body . toggleClass ( OPENED_MODAL_CLASS , openedWindows . length ( ) > 0 ) ;
240
226
checkRemoveBackdrop ( ) ;
241
227
} ) ;
@@ -261,18 +247,24 @@ angular.module('ui.bootstrap.modal', [])
261
247
}
262
248
263
249
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
- }
250
+ var asyncDeferred ;
251
+ var asyncPromise = null ;
252
+ var setIsAsync = function ( ) {
253
+ if ( ! asyncDeferred ) {
254
+ asyncDeferred = $q . defer ( ) ;
255
+ asyncPromise = asyncDeferred . promise ;
256
+ }
257
+
258
+ return function asyncDone ( ) {
259
+ asyncDeferred . resolve ( ) ;
260
+ } ;
261
+ } ;
262
+ scope . $broadcast ( $modalStack . NOW_CLOSING_EVENT , setIsAsync ) ;
263
+
264
+ // Note that it's intentional that asyncPromise might be null.
265
+ // That's when setIsAsync has not been called during the
266
+ // NOW_CLOSING_EVENT broadcast.
267
+ return $q . when ( asyncPromise ) . then ( afterAnimating ) ;
276
268
277
269
function afterAnimating ( ) {
278
270
if ( afterAnimating . done ) {
0 commit comments