@@ -54,6 +54,61 @@ angular.module('ui.bootstrap.modal', [])
54
54
} ;
55
55
} )
56
56
57
+ /**
58
+ * A helper, internal data structure that stores all references attached to key
59
+ */
60
+ . factory ( '$$multiMap' , function ( ) {
61
+ return {
62
+ createNew : function ( ) {
63
+ var map = { } ;
64
+
65
+ return {
66
+ entries : function ( ) {
67
+ return Object . keys ( map ) . map ( function ( key ) {
68
+ return {
69
+ key : key ,
70
+ value : map [ key ]
71
+ } ;
72
+ } ) ;
73
+ } ,
74
+ get : function ( key ) {
75
+ return map [ key ] ;
76
+ } ,
77
+ hasKey : function ( key ) {
78
+ return ! ! map [ key ] ;
79
+ } ,
80
+ keys : function ( ) {
81
+ return Object . keys ( map ) ;
82
+ } ,
83
+ put : function ( key , value ) {
84
+ if ( ! map [ key ] ) {
85
+ map [ key ] = [ ] ;
86
+ }
87
+
88
+ map [ key ] . push ( value ) ;
89
+ } ,
90
+ remove : function ( key , value ) {
91
+ var values = map [ key ] ;
92
+
93
+ if ( ! values ) {
94
+ return ;
95
+ }
96
+
97
+ var idx = values . indexOf ( value ) ;
98
+
99
+ if ( idx !== - 1 ) {
100
+ values . splice ( idx , 1 ) ;
101
+ }
102
+
103
+ if ( ! values . length ) {
104
+ delete map [ key ] ;
105
+ }
106
+ }
107
+ } ;
108
+ }
109
+ } ;
110
+ } )
111
+
57
112
/**
58
113
* A helper directive for the $modal service. It creates a backdrop element.
59
114
*/
@@ -220,10 +275,12 @@ angular.module('ui.bootstrap.modal', [])
220
275
'$animate' , '$timeout' , '$document' , '$compile' , '$rootScope' ,
221
276
'$q' ,
222
277
'$injector' ,
278
+ '$$multiMap' ,
223
279
'$$stackedMap' ,
224
280
function ( $animate , $timeout , $document , $compile , $rootScope ,
225
281
$q ,
226
282
$injector ,
283
+ $$multiMap ,
227
284
$$stackedMap ) {
228
285
var $animateCss = null ;
229
286
@@ -235,6 +292,7 @@ angular.module('ui.bootstrap.modal', [])
235
292
236
293
var backdropDomEl , backdropScope ;
237
294
var openedWindows = $$stackedMap . createNew ( ) ;
295
+ var openedClasses = $$multiMap . createNew ( ) ;
238
296
var $modalStack = {
239
297
NOW_CLOSING_EVENT : 'modal.stack.now-closing'
240
298
} ;
@@ -264,15 +322,16 @@ angular.module('ui.bootstrap.modal', [])
264
322
} ) ;
265
323
266
324
function removeModalWindow ( modalInstance , elementToReceiveFocus ) {
267
-
268
325
var body = $document . find ( 'body' ) . eq ( 0 ) ;
269
326
var modalWindow = openedWindows . get ( modalInstance ) . value ;
270
327
271
328
//clean up the stack
272
329
openedWindows . remove ( modalInstance ) ;
273
330
274
331
removeAfterAnimate ( modalWindow . modalDomEl , modalWindow . modalScope , function ( ) {
275
- body . toggleClass ( modalWindow . openedClass || OPENED_MODAL_CLASS , openedWindows . length ( ) > 0 ) ;
332
+ var modalBodyClass = modalWindow . openedClass || OPENED_MODAL_CLASS ;
333
+ openedClasses . remove ( modalBodyClass , modalInstance ) ;
334
+ body . toggleClass ( modalBodyClass , openedClasses . hasKey ( modalBodyClass ) ) ;
276
335
} ) ;
277
336
checkRemoveBackdrop ( ) ;
278
337
@@ -377,7 +436,8 @@ angular.module('ui.bootstrap.modal', [])
377
436
} ) ;
378
437
379
438
$modalStack . open = function ( modalInstance , modal ) {
380
- var modalOpener = $document [ 0 ] . activeElement ;
439
+ var modalOpener = $document [ 0 ] . activeElement ,
440
+ modalBodyClass = modal . openedClass || OPENED_MODAL_CLASS ;
381
441
382
442
openedWindows . add ( modalInstance , {
383
443
deferred : modal . deferred ,
@@ -388,6 +448,8 @@ angular.module('ui.bootstrap.modal', [])
388
448
openedClass : modal . openedClass
389
449
} ) ;
390
450
451
+ openedClasses . put ( modalBodyClass , modalInstance ) ;
452
+
391
453
var body = $document . find ( 'body' ) . eq ( 0 ) ,
392
454
currBackdropIndex = backdropIndex ( ) ;
393
455
@@ -419,7 +481,8 @@ angular.module('ui.bootstrap.modal', [])
419
481
openedWindows . top ( ) . value . modalDomEl = modalDomEl ;
420
482
openedWindows . top ( ) . value . modalOpener = modalOpener ;
421
483
body . append ( modalDomEl ) ;
422
- body . addClass ( modal . openedClass || OPENED_MODAL_CLASS ) ;
484
+ body . addClass ( modalBodyClass ) ;
485
+
423
486
$modalStack . clearFocusListCache ( ) ;
424
487
} ;
425
488
0 commit comments