Render reCaptcha after its initialization
[MAILPOET-3390]
This commit is contained in:
@@ -6,19 +6,27 @@ import 'parsleyjs';
|
|||||||
const exitIntentEvent = 'mouseleave.mailpoet.form-exit-intent';
|
const exitIntentEvent = 'mouseleave.mailpoet.form-exit-intent';
|
||||||
|
|
||||||
jQuery(($) => {
|
jQuery(($) => {
|
||||||
window.reCaptchaCallback = function reCaptchaCallback() {
|
function renderCaptcha(element, iteration) {
|
||||||
$('.mailpoet_recaptcha').each((index, element) => {
|
if (!window.recaptcha || !window.grecaptcha.ready) {
|
||||||
|
if (iteration < 20) {
|
||||||
|
setTimeout(renderCaptcha, 400, element, iteration + 1);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
const recaptcha = $(element);
|
const recaptcha = $(element);
|
||||||
const sitekey = recaptcha.attr('data-sitekey');
|
const sitekey = recaptcha.attr('data-sitekey');
|
||||||
const container = recaptcha.find('> .mailpoet_recaptcha_container').get(0);
|
const container = recaptcha.find('> .mailpoet_recaptcha_container').get(0);
|
||||||
const field = recaptcha.find('> .mailpoet_recaptcha_field');
|
const field = recaptcha.find('> .mailpoet_recaptcha_field');
|
||||||
let widgetId;
|
|
||||||
if (sitekey) {
|
if (sitekey) {
|
||||||
widgetId = window.grecaptcha.render(container, { sitekey, size: 'compact' });
|
const widgetId = window.grecaptcha.render(container, { sitekey, size: 'compact' });
|
||||||
field.val(widgetId);
|
field.val(widgetId);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.mailpoet_recaptcha').each((index, element) => {
|
||||||
|
setTimeout(renderCaptcha, 400, element, 1);
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param form jQuery object of form form.mailpoet_form
|
* @param form jQuery object of form form.mailpoet_form
|
||||||
|
Reference in New Issue
Block a user