|
1 |
| -const controlZIndex = (container) => { |
| 1 | +const controlZIndex = (container, listenerContainer, resetedZIndex = 'initial') => { |
2 | 2 | const initialZIndex = container.style.zIndex;
|
3 |
| - |
4 |
| - container.addEventListener('show.bs.modal', () => { |
5 |
| - container.style.zIndex = 'initial'; |
6 |
| - }); |
7 |
| - container.addEventListener('hide.bs.modal', () => { |
| 3 | + const finalListenerContainer = listenerContainer ?? container; |
| 4 | + const handleShowModal = () => { |
| 5 | + container.style.zIndex = resetedZIndex; |
| 6 | + }; |
| 7 | + const handleCloseModal = () => { |
8 | 8 | container.style.zIndex = initialZIndex;
|
9 |
| - }); |
| 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 | + |
| 17 | + finalListenerContainer.addEventListener('show.bs.modal', handleShowModal, false); |
| 18 | + finalListenerContainer.addEventListener('hidden.bs.modal', handleCloseModal, false); |
10 | 19 |
|
11 | 20 | document.body.dispatchEvent(new CustomEvent('ibexa-control-z-index:events-attached'));
|
| 21 | + |
| 22 | + return { |
| 23 | + removeControlZIndexListeners, |
| 24 | + }; |
| 25 | +}; |
| 26 | + |
| 27 | +const controlZIndexBulk = (items) => { |
| 28 | + const storedControlZIndex = items.map((item) => { |
| 29 | + return controlZIndex(...item); |
| 30 | + }); |
| 31 | + const removeControlZIndexListeners = () => { |
| 32 | + storedControlZIndex.forEach((item) => { |
| 33 | + item.removeControlZIndexListeners(); |
| 34 | + }); |
| 35 | + }; |
| 36 | + |
| 37 | + return { |
| 38 | + removeControlZIndexListeners, |
| 39 | + }; |
12 | 40 | };
|
13 | 41 |
|
14 |
| -export { controlZIndex }; |
| 42 | +export { controlZIndex, controlZIndexBulk }; |
0 commit comments