FriendlyCaptcha / friendly-captcha-wordpress

WordPress plugin for Friendly Captcha. Protect WordPress website forms from spam and abuse with Friendly Captcha, a privacy-first anti-bot solution.
https://friendlycaptcha.com
19 stars 9 forks source link

Initialize widgets that are dynamically added to the page #111

Closed merlinfuchs closed 8 months ago

merlinfuchs commented 8 months ago

This PR introduces a new settings which allows our plugin to initialize widgets that are dynamically added to the page after load. This includes popups, multi-step forms and generally content loaded with AJAX.

We achieve this by adding a MutationObserver to the document body which looks for new nodes being added to the DOM. It then initializes any element with the .frc-captcha class if it doesn't have the friendlyChallengeWidget property which is added by the friendly-challenge library. We look for the friendlyChallengeWidget property instead of the data-attached attribute because the latter persists when HTML is removed and added back to the DOM.

This is opt-in because it could potentially affect the performance of the page. After all we are running a bit of code whenever a new node is added to the DOM.

grafik