Files
2024_WORDPRESS_PLUGIN_fbpatch/js/modals.js
2024-07-17 15:30:32 +02:00

30 lines
1.0 KiB
JavaScript

let modal_wrapper_CIPF = document.querySelector('#de-fb-modal-wrapper-');
// create an observer on first #de-fb-modal-wrapper- to check if child nodes are added
const observer_CIPF = new MutationObserver(wait_for_close_button_CIPF);
observer_CIPF.observe(modal_wrapper_CIPF, {
subtree: true,
childList: true,
});
// observe mutations to see if they include the creation of the button .modal-close
// if the button is created, add an eventListener to it
function wait_for_close_button_CIPF(mutationsList) {
mutationsList.forEach((mutation) => {
// check if nodes were added
if (mutation.type !== 'childList')
return;
// check if added nodes includes the button .modal-close
let modal_close = document.querySelector('#de-fb-modal-wrapper- .modal-close');
if (modal_close !== null) {
modal_close.addEventListener("click", delete_modal_CIPF);
}
});
}
// when triggered, the .modal-close button will remove all childs from #de-fb-modal-wrapper-
function delete_modal_CIPF() {
modal_wrapper_CIPF.innerHTML = '';
}