@@ -78,12 +78,13 @@ angular.module('ui.bootstrap.modal', [])
78
78
}
79
79
} ] )
80
80
81
- . directive ( 'modalWindow' , [ '$modalStack' , '$q' , function ( $modalStack , $q ) {
81
+ . directive ( 'modalWindow' , [
82
+ '$modalStack' , '$q' , '$animate' ,
83
+ function ( $modalStack , $q , $animate ) {
82
84
return {
83
85
restrict : 'EA' ,
84
86
scope : {
85
- index : '@' ,
86
- animate : '='
87
+ index : '@'
87
88
} ,
88
89
replace : true ,
89
90
transclude : true ,
@@ -119,8 +120,14 @@ angular.module('ui.bootstrap.modal', [])
119
120
} ) ;
120
121
121
122
modalRenderDeferObj . promise . then ( function ( ) {
122
- // trigger CSS transitions
123
- scope . animate = true ;
123
+ if ( attrs . modalInClass ) {
124
+ $animate . addClass ( element , attrs . modalInClass ) ;
125
+
126
+ scope . $on ( $modalStack . WINDOW_CLOSING_EVENT , function ( e , setIsAsync ) {
127
+ var done = setIsAsync ( ) ;
128
+ $animate . removeClass ( element , attrs . modalInClass ) . then ( done ) ;
129
+ } ) ;
130
+ }
124
131
125
132
var inputsWithAutofocus = element [ 0 ] . querySelectorAll ( '[autofocus]' ) ;
126
133
/**
@@ -169,14 +176,21 @@ angular.module('ui.bootstrap.modal', [])
169
176
} ;
170
177
} )
171
178
172
- . factory ( '$modalStack' , [ '$animate' , '$timeout' , '$document' , '$compile' , '$rootScope' , '$$stackedMap' ,
173
- function ( $animate , $timeout , $document , $compile , $rootScope , $$stackedMap ) {
179
+ . factory ( '$modalStack' , [
180
+ '$animate' , '$timeout' , '$document' , '$compile' , '$rootScope' ,
181
+ '$q' ,
182
+ '$$stackedMap' ,
183
+ function ( $animate , $timeout , $document , $compile , $rootScope ,
184
+ $q ,
185
+ $$stackedMap ) {
174
186
175
187
var OPENED_MODAL_CLASS = 'modal-open' ;
176
188
177
189
var backdropDomEl , backdropScope ;
178
190
var openedWindows = $$stackedMap . createNew ( ) ;
179
- var $modalStack = { } ;
191
+ var $modalStack = {
192
+ WINDOW_CLOSING_EVENT : 'modal.stack.window-closing'
193
+ } ;
180
194
181
195
function backdropIndex ( ) {
182
196
var topBackdropIndex = - 1 ;
@@ -203,8 +217,25 @@ angular.module('ui.bootstrap.modal', [])
203
217
//clean up the stack
204
218
openedWindows . remove ( modalInstance ) ;
205
219
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
+
206
234
//remove window DOM element
207
- removeAfterAnimate ( modalWindow . modalDomEl , modalWindow . modalScope , function ( ) {
235
+ $q . when ( closingPromise ) . then ( function ( ) {
236
+ modalWindow . modalDomEl . remove ( ) ;
237
+ modalWindow . modalScope . $destroy ( ) ;
238
+
208
239
body . toggleClass ( OPENED_MODAL_CLASS , openedWindows . length ( ) > 0 ) ;
209
240
checkRemoveBackdrop ( ) ;
210
241
} ) ;
0 commit comments