|
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 | + }; |
| 10 | + const removeControlZIndexListeners = () => { |
| 11 | + finalListenerContainer.removeEventListener('show.bs.modal', handleShowModal, false); |
| 12 | + finalListenerContainer.removeEventListener('hidden.bs.modal', handleCloseModal, false); |
| 13 | + }; |
| 14 | + |
| 15 | + finalListenerContainer.addEventListener('show.bs.modal', handleShowModal, false); |
| 16 | + finalListenerContainer.addEventListener('hidden.bs.modal', handleCloseModal, false); |
| 17 | + |
| 18 | + return { |
| 19 | + removeControlZIndexListeners, |
| 20 | + }; |
| 21 | +}; |
| 22 | + |
| 23 | +const controlZIndexBulk = (items) => { |
| 24 | + const storedControlZIndex = items.map((item) => { |
| 25 | + return controlZIndex(...item); |
9 | 26 | });
|
| 27 | + const removeControlZIndexListeners = () => { |
| 28 | + storedControlZIndex.forEach((item) => { |
| 29 | + item.removeControlZIndexListeners(); |
| 30 | + }); |
| 31 | + }; |
| 32 | + |
| 33 | + return { |
| 34 | + removeControlZIndexListeners, |
| 35 | + }; |
10 | 36 | };
|
11 | 37 |
|
12 |
| -export { controlZIndex }; |
| 38 | +export { controlZIndex, controlZIndexBulk }; |
0 commit comments