MutationObserver
-
Hello!
Could you please add the use of MutationObserver to your script. There is a javascript code example of how this might look like
const wpcf7Forms = document.querySelectorAll( '.wpcf7' );
if ( wpcf7Forms.length ) {
for ( const wpcf7Form of wpcf7Forms ) {
init(wpcf7Form);
}
}
const observer = new MutationObserver((mutationList, observer) => {
for (const mutation of mutationList) {
for (let node of mutation.addedNodes) {
if (!(node instanceof HTMLElement)) continue;
const forms = node.querySelectorAll( '.wpcf7' );
if ( forms.length ) {
for ( const form of forms ) {
init(form);
}
}
}
}
});
observer.observe(document.body, {childList: true, subtree: true});This is to make the script apply to dynamically loaded content, such as popups created with javascript code and ajax.
Also, to be able to use it with ajax content, you need to modify this check in the method
\CF7_AntiSpam\Core\CF7_AntiSpam::load_frontend()if ( ! is_admin() || wp_doing_ajax() ) {
//...
}Thanks.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘MutationObserver’ is closed to new replies.