1jQuery(window).on("elementor/frontend/init", function () { 2 elementorFrontend.hooks.addAction( 3 "frontend/element_ready/rform-recaptcha.default", 4 function ($scope, $) { 5 const $form = $scope.closest("form"); 6 7 if (typeof grecaptcha !== "undefined") { 8 const recaptchaV2Elements = $scope.find(".rform-recaptcha-v2"); 9 const recaptchaV3Elements = $scope.find(".rform-recaptcha-token"); 10 if (recaptchaV2Elements.length > 0) { 11 recaptchaV2Elements.each(function () { 12 const siteKey = $(this).data("sitekey"); 13 const theme = $(this).data("theme") ?? "light"; 14 let verificationDone = false; 15 const thisEl = this; 16 grecaptcha.ready(function () { 17 grecaptcha.render(thisEl, { 18 sitekey: siteKey, 19 theme: theme, 20 callback: function (token) { 21 // You can store the token in a hidden input or send it to your server here 22 verificationDone = true; 23 $scope 24 .find(".rform-recaptcha-wrapper") 25 .removeAttr("aria-invalid"); 26 }, 27 "expired-callback": function () { 28 grecaptcha.reset(); 29 verificationDone = false; 30 $scope 31 .find(".rform-recaptcha-wrapper") 32 .attr("aria-invalid", "true"); 33 }, 34 }); 35 }); 36 $form 37 .find("button.rform-button-submit")[0] 38 .addEventListener("click", function () { 39 console.log( 40 "Form submitted with reCAPTCHA token:", 41 grecaptcha.getResponse(), 42 ); 43 if (!verificationDone) { 44 $scope 45 .find(".rform-recaptcha-wrapper") 46 .attr("aria-invalid", "true"); 47 } else { 48 $scope 49 .find(".rform-recaptcha-wrapper") 50 .removeAttr("aria-invalid"); 51 } 52 }); 53 }); 54 } else if (recaptchaV3Elements.length > 0) { 55 // console.log("reCAPTCHA v3 detected, executing..."); 56 recaptchaV3Elements.each(function () { 57 const siteKey = $(this).data("sitekey"); 58 grecaptcha.ready(function () { 59 grecaptcha 60 .execute(siteKey, { action: "submit" }) 61 .then(function (token) { 62 recaptchaV3Elements.val(token); 63 $form 64 .find("button.rform-button-submit")[0] 65 .addEventListener("click", function () { 66 const newToken = generateRecaptchaToken( 67 "submit", 68 siteKey, 69 ); 70 recaptchaV3Elements.val(newToken); 71 }); 72 }); 73 }); 74 }); 75 } 76 } 77 }, 78 ); 79}); 80 81function generateRecaptchaToken(action = "submit", siteKey) { 82 return new Promise((resolve, reject) => { 83 grecaptcha.ready(function () { 84 grecaptcha.execute(siteKey, { action }).then(resolve).catch(reject); 85 }); 86 }); 87}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.