Created
November 8, 2019 09:31
-
-
Save markhallen/89ce32c75838d1f198691f6ad7537629 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// listen for creation of a modal | |
$(document).on('click', '.modal-with-react', function() { | |
addChildListListener('modal-holder') | |
}) | |
export function addChildListListener(elementId){ | |
// Select the node that will be observed for mutations | |
const targetNode = document.getElementById(elementId) | |
// Options for the observer (which mutations to observe) | |
const config = { childList: true } | |
// Callback function to execute when mutations are observed | |
const callback = function(mutationsList, observer) { | |
for(let mutation of mutationsList) { | |
if (mutation.type === 'childList') { | |
insertDatePickers() | |
// stop observing | |
observer.disconnect(); | |
} | |
} | |
}; | |
// Create an observer instance linked to the callback function | |
const observer = new MutationObserver(callback) | |
// Start observing the target node for configured mutations | |
observer.observe(targetNode, config) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment