@@ -57,9 +57,7 @@ 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' , [
61
- '$animate' , '$modalStack' ,
62
- function ( $animate , $modalStack ) {
60
+ . directive ( 'modalBackdrop' , [ '$timeout' , function ( $timeout ) {
63
61
return {
64
62
restrict : 'EA' ,
65
63
replace : true ,
@@ -71,24 +69,21 @@ angular.module('ui.bootstrap.modal', [])
71
69
} ;
72
70
73
71
function linkFn ( scope , element , attrs ) {
74
- if ( attrs . modalInClass ) {
75
- $animate . addClass ( element , attrs . modalInClass ) ;
72
+ scope . animate = false ;
76
73
77
- scope . $on ( $modalStack . NOW_CLOSING_EVENT , function ( e , setIsAsync ) {
78
- var done = setIsAsync ( ) ;
79
- $animate . removeClass ( element , attrs . modalInClass ) . then ( done ) ;
80
- } ) ;
81
- }
74
+ //trigger CSS transitions
75
+ $timeout ( function ( ) {
76
+ scope . animate = true ;
77
+ } ) ;
82
78
}
83
79
} ] )
84
80
85
- . directive ( 'modalWindow' , [
86
- '$modalStack' , '$q' , '$animate' ,
87
- function ( $modalStack , $q , $animate ) {
81
+ . directive ( 'modalWindow' , [ '$modalStack' , '$q' , function ( $modalStack , $q ) {
88
82
return {
89
83
restrict : 'EA' ,
90
84
scope : {
91
- index : '@'
85
+ index : '@' ,
86
+ animate : '='
92
87
} ,
93
88
replace : true ,
94
89
transclude : true ,
@@ -124,14 +119,8 @@ angular.module('ui.bootstrap.modal', [])
124
119
} ) ;
125
120
126
121
modalRenderDeferObj . promise . then ( function ( ) {
127
- if ( attrs . modalInClass ) {
128
- $animate . addClass ( element , attrs . modalInClass ) ;
129
-
130
- scope . $on ( $modalStack . NOW_CLOSING_EVENT , function ( e , setIsAsync ) {
131
- var done = setIsAsync ( ) ;
132
- $animate . removeClass ( element , attrs . modalInClass ) . then ( done ) ;
133
- } ) ;
134
- }
122
+ // trigger CSS transitions
123
+ scope . animate = true ;
135
124
136
125
var inputsWithAutofocus = element [ 0 ] . querySelectorAll ( '[autofocus]' ) ;
137
126
/**
@@ -180,21 +169,14 @@ angular.module('ui.bootstrap.modal', [])
180
169
} ;
181
170
} )
182
171
183
- . factory ( '$modalStack' , [
184
- '$animate' , '$timeout' , '$document' , '$compile' , '$rootScope' ,
185
- '$q' ,
186
- '$$stackedMap' ,
187
- function ( $animate , $timeout , $document , $compile , $rootScope ,
188
- $q ,
189
- $$stackedMap ) {
172
+ . factory ( '$modalStack' , [ '$animate' , '$timeout' , '$document' , '$compile' , '$rootScope' , '$$stackedMap' ,
173
+ function ( $animate , $timeout , $document , $compile , $rootScope , $$stackedMap ) {
190
174
191
175
var OPENED_MODAL_CLASS = 'modal-open' ;
192
176
193
177
var backdropDomEl , backdropScope ;
194
178
var openedWindows = $$stackedMap . createNew ( ) ;
195
- var $modalStack = {
196
- NOW_CLOSING_EVENT : 'modal.stack.now-closing'
197
- } ;
179
+ var $modalStack = { } ;
198
180
199
181
function backdropIndex ( ) {
200
182
var topBackdropIndex = - 1 ;
@@ -213,25 +195,19 @@ angular.module('ui.bootstrap.modal', [])
213
195
}
214
196
} ) ;
215
197
216
- function removeModalWindow ( modalInstance , elementToReceiveFocus ) {
198
+ function removeModalWindow ( modalInstance ) {
217
199
218
200
var body = $document . find ( 'body' ) . eq ( 0 ) ;
219
201
var modalWindow = openedWindows . get ( modalInstance ) . value ;
220
202
221
203
//clean up the stack
222
204
openedWindows . remove ( modalInstance ) ;
223
205
206
+ //remove window DOM element
224
207
removeAfterAnimate ( modalWindow . modalDomEl , modalWindow . modalScope , function ( ) {
225
208
body . toggleClass ( OPENED_MODAL_CLASS , openedWindows . length ( ) > 0 ) ;
226
209
checkRemoveBackdrop ( ) ;
227
210
} ) ;
228
-
229
- //move focus to specified element if available, or else to body
230
- if ( elementToReceiveFocus && elementToReceiveFocus . focus ) {
231
- elementToReceiveFocus . focus ( ) ;
232
- } else {
233
- body . focus ( ) ;
234
- }
235
211
}
236
212
237
213
function checkRemoveBackdrop ( ) {
@@ -247,24 +223,18 @@ angular.module('ui.bootstrap.modal', [])
247
223
}
248
224
249
225
function removeAfterAnimate ( domEl , scope , done ) {
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 ) ;
226
+ // Closing animation
227
+ scope . animate = false ;
228
+
229
+ if ( domEl . attr ( 'modal-animation' ) && $animate . enabled ( ) ) {
230
+ // transition out
231
+ domEl . one ( '$animate:close' , function closeFn ( ) {
232
+ $rootScope . $evalAsync ( afterAnimating ) ;
233
+ } ) ;
234
+ } else {
235
+ // Ensure this call is async
236
+ $timeout ( afterAnimating ) ;
237
+ }
268
238
269
239
function afterAnimating ( ) {
270
240
if ( afterAnimating . done ) {
@@ -296,8 +266,6 @@ angular.module('ui.bootstrap.modal', [])
296
266
297
267
$modalStack . open = function ( modalInstance , modal ) {
298
268
299
- var modalOpener = $document [ 0 ] . activeElement ;
300
-
301
269
openedWindows . add ( modalInstance , {
302
270
deferred : modal . deferred ,
303
271
renderDeferred : modal . renderDeferred ,
@@ -335,7 +303,6 @@ angular.module('ui.bootstrap.modal', [])
335
303
336
304
var modalDomEl = $compile ( angularDomEl ) ( modal . scope ) ;
337
305
openedWindows . top ( ) . value . modalDomEl = modalDomEl ;
338
- openedWindows . top ( ) . value . modalOpener = modalOpener ;
339
306
body . append ( modalDomEl ) ;
340
307
body . addClass ( OPENED_MODAL_CLASS ) ;
341
308
} ;
@@ -348,7 +315,7 @@ angular.module('ui.bootstrap.modal', [])
348
315
var modalWindow = openedWindows . get ( modalInstance ) ;
349
316
if ( modalWindow && broadcastClosing ( modalWindow , result , true ) ) {
350
317
modalWindow . value . deferred . resolve ( result ) ;
351
- removeModalWindow ( modalInstance , modalWindow . value . modalOpener ) ;
318
+ removeModalWindow ( modalInstance ) ;
352
319
return true ;
353
320
}
354
321
return ! modalWindow ;
@@ -358,7 +325,7 @@ angular.module('ui.bootstrap.modal', [])
358
325
var modalWindow = openedWindows . get ( modalInstance ) ;
359
326
if ( modalWindow && broadcastClosing ( modalWindow , reason , false ) ) {
360
327
modalWindow . value . deferred . reject ( reason ) ;
361
- removeModalWindow ( modalInstance , modalWindow . value . modalOpener ) ;
328
+ removeModalWindow ( modalInstance ) ;
362
329
return true ;
363
330
}
364
331
return ! modalWindow ;
@@ -390,17 +357,20 @@ angular.module('ui.bootstrap.modal', [])
390
357
var $modalProvider = {
391
358
options : {
392
359
animation : true ,
393
- backdrop : true , //can also be false or 'static'
360
+ backdrop : true , //can be also false or 'static'
394
361
keyboard : true
395
362
} ,
396
- $get : [ '$injector' , '$rootScope' , '$q' , '$templateRequest ' , '$controller' , '$modalStack' ,
397
- function ( $injector , $rootScope , $q , $templateRequest , $controller , $modalStack ) {
363
+ $get : [ '$injector' , '$rootScope' , '$q' , '$http' , '$templateCache ', '$controller' , '$modalStack' ,
364
+ function ( $injector , $rootScope , $q , $http , $templateCache , $controller , $modalStack ) {
398
365
399
366
var $modal = { } ;
400
367
401
368
function getTemplatePromise ( options ) {
402
369
return options . template ? $q . when ( options . template ) :
403
- $templateRequest ( angular . isFunction ( options . templateUrl ) ? ( options . templateUrl ) ( ) : options . templateUrl ) ;
370
+ $http . get ( angular . isFunction ( options . templateUrl ) ? ( options . templateUrl ) ( ) : options . templateUrl ,
371
+ { cache : $templateCache } ) . then ( function ( result ) {
372
+ return result . data ;
373
+ } ) ;
404
374
}
405
375
406
376
function getResolvePromises ( resolves ) {
@@ -488,8 +458,8 @@ angular.module('ui.bootstrap.modal', [])
488
458
489
459
templateAndResolvePromise . then ( function ( ) {
490
460
modalOpenedDeferred . resolve ( true ) ;
491
- } , function ( reason ) {
492
- modalOpenedDeferred . reject ( reason ) ;
461
+ } , function ( ) {
462
+ modalOpenedDeferred . reject ( false ) ;
493
463
} ) ;
494
464
495
465
return modalInstance ;
0 commit comments