idx(function(){
// Track the time for captchas because there's a 2 minute expiration on the token. var idxRecaptchaTimer = [];
/** * Clear the captcha timer for a recently submitted element. * * @param tokenElement The hidden input element for the token. */ function clearCaptchaTimer(tokenElement) { clearInterval(idxRecaptchaTimer[tokenElement.attr('id')]); delete idxRecaptchaTimer[tokenElement.attr('id')]; tokenElement.val(''); tokenElement.closest('form').removeClass('IDX-clearCaptchaTimer'); }
/** * Fetch a captcha token. * * @param tokenElement The hidden input element for the token. */ function fetchCaptchaToken(tokenElement) { grecaptcha.execute('6LcUhOYUAAAAAF694SR5_qDv-ZdRHv77I6ZmSiij', {action: tokenElement.attr('data-action')}).then(function(token) { idx(tokenElement).val(token); }); }
/** * When a form element inside a form is focused. * * @param event jQuery focus event. */ function recaptchaFormInputFocused(event) { var form = idx(this).closest('form');
var tokenElement = form.find('.IDX-recaptchaToken'); form.addClass('IDX-clearCaptchaTimer').data('tokenElement', tokenElement);
var elementID = tokenElement.attr('id'); if (idxRecaptchaTimer[elementID] != undefined) { return; }
// Every 2 minutes. var tokenExpiration = 2 * 60 * 1000;
fetchCaptchaToken(tokenElement); idxRecaptchaTimer[elementID] = setInterval(fetchCaptchaToken, tokenExpiration, tokenElement); } // Listen to focus events. idx('.IDX-recaptchaToken').closest('form').find(':input:not([type=hidden])').on('focus', recaptchaFormInputFocused); })
Enter any number