@@ -11,4 +11,43 @@ const controlZIndex = (container) => {
1111 document . body . dispatchEvent ( new CustomEvent ( 'ibexa-control-z-index:events-attached' ) ) ;
1212} ;
1313
14- export { controlZIndex } ;
14+ const controlManyZIndexes = ( items , listenerContainer ) => {
15+ const listenersAbortController = new AbortController ( ) ;
16+ const containersInitialZIndexes = new Map ( ) ;
17+ const removeControlManyZIndexesListeners = ( ) => {
18+ listenersAbortController . abort ( ) ;
19+ listenerContainer . dispatchEvent ( new CustomEvent ( 'ibexa-control-z-index:events-detached' ) ) ;
20+ } ;
21+
22+ items . forEach ( ( { container } ) => {
23+ containersInitialZIndexes . set ( container , container . style . zIndex ) ;
24+ } ) ;
25+
26+ listenerContainer . addEventListener (
27+ 'show.bs.modal' ,
28+ ( ) => {
29+ items . forEach ( ( { container, zIndex = 'initial' } ) => {
30+ container . style . zIndex = zIndex ;
31+ } ) ;
32+ } ,
33+ { signal : listenersAbortController . signal } ,
34+ ) ;
35+
36+ listenerContainer . addEventListener (
37+ 'hidden.bs.modal' ,
38+ ( ) => {
39+ items . forEach ( ( { container } ) => {
40+ container . style . zIndex = containersInitialZIndexes . get ( container ) ;
41+ } ) ;
42+ } ,
43+ { signal : listenersAbortController . signal } ,
44+ ) ;
45+
46+ listenerContainer . dispatchEvent ( new CustomEvent ( 'ibexa-control-z-index:events-attached' ) ) ;
47+
48+ return {
49+ removeControlManyZIndexesListeners,
50+ } ;
51+ } ;
52+
53+ export { controlZIndex , controlManyZIndexes } ;
0 commit comments