|
1 | | -const controlZIndex = (container, listenerContainer, resetedZIndex = 'initial') => { |
| 1 | +const controlZIndex = (container) => { |
2 | 2 | const initialZIndex = container.style.zIndex; |
3 | | - const finalListenerContainer = listenerContainer ?? container; |
4 | | - const handleShowModal = () => { |
5 | | - container.style.zIndex = resetedZIndex; |
6 | | - }; |
7 | | - const handleCloseModal = () => { |
8 | | - container.style.zIndex = initialZIndex; |
9 | | - }; |
10 | | - const removeControlZIndexListeners = () => { |
11 | | - finalListenerContainer.removeEventListener('show.bs.modal', handleShowModal, false); |
12 | | - finalListenerContainer.removeEventListener('hidden.bs.modal', handleCloseModal, false); |
13 | | - |
14 | | - document.body.dispatchEvent(new CustomEvent('ibexa-control-z-index:events-detached')); |
15 | | - }; |
16 | 3 |
|
17 | | - finalListenerContainer.addEventListener('show.bs.modal', handleShowModal, false); |
18 | | - finalListenerContainer.addEventListener('hidden.bs.modal', handleCloseModal, false); |
| 4 | + container.addEventListener('show.bs.modal', () => { |
| 5 | + container.style.zIndex = 'initial'; |
| 6 | + }); |
| 7 | + container.addEventListener('hide.bs.modal', () => { |
| 8 | + container.style.zIndex = initialZIndex; |
| 9 | + }); |
19 | 10 |
|
20 | 11 | document.body.dispatchEvent(new CustomEvent('ibexa-control-z-index:events-attached')); |
21 | | - |
22 | | - return { |
23 | | - removeControlZIndexListeners, |
24 | | - }; |
25 | 12 | }; |
26 | 13 |
|
27 | | -const controlZIndexBulk = (items) => { |
28 | | - const storedControlZIndex = items.map((item) => { |
29 | | - return controlZIndex(...item); |
30 | | - }); |
| 14 | +const betterControlZIndex = (containers, listenerContainer, resetedZIndex = 'initial') => { |
| 15 | + const listenersAbortController = new AbortController(); |
| 16 | + const containersInitialZIndexes = new Map(); |
31 | 17 | const removeControlZIndexListeners = () => { |
32 | | - storedControlZIndex.forEach((item) => { |
33 | | - item.removeControlZIndexListeners(); |
| 18 | + listenersAbortController.abort(); |
| 19 | + listenerContainer.dispatchEvent(new CustomEvent('ibexa-control-z-index:events-detached')); |
| 20 | + } |
| 21 | + |
| 22 | + containers.forEach((container) => { |
| 23 | + containersInitialZIndexes.set(container, container.style.zIndex); |
| 24 | + }); |
| 25 | + |
| 26 | + containers.forEach((container) => { |
| 27 | + listenerContainer.addEventListener('show.bs.modal', () => { |
| 28 | + container.style.zIndex = resetedZIndex; |
34 | 29 | }); |
35 | | - }; |
| 30 | + }); |
| 31 | + |
| 32 | + // listenerContainer.addEventListener('show.bs.modal', () => { |
| 33 | + // containers.forEach((container) => { |
| 34 | + // container.style.zIndex = resetedZIndex; |
| 35 | + // }); |
| 36 | + // }, { signal: listenersAbortController.signal }); |
| 37 | + |
| 38 | + listenerContainer.addEventListener('hidden.bs.modal', () => { |
| 39 | + containers.forEach((container) => { |
| 40 | + container.style.zIndex = containersInitialZIndexes.get(container); |
| 41 | + }); |
| 42 | + }, { signal: listenersAbortController.signal }); |
| 43 | + |
| 44 | + listenerContainer.dispatchEvent(new CustomEvent('ibexa-control-z-index:events-attached')); |
36 | 45 |
|
37 | 46 | return { |
38 | 47 | removeControlZIndexListeners, |
39 | | - }; |
40 | | -}; |
| 48 | + } |
| 49 | +} |
41 | 50 |
|
42 | | -export { controlZIndex, controlZIndexBulk }; |
| 51 | +export { controlZIndex, betterControlZIndex }; |
0 commit comments