PageSourceSearch

https://hadashot.kiev.ua/modules/contrib/simple_recaptcha/js/simple_recaptcha_v3.js?v=1.x

js hadashot.kiev.ua collected 2026-10-02 12:00:11 UTC 3,125 bytes, 66 lines download raw bytes

1(function($) {
2  "use strict";
3  Drupal.behaviors.simple_recaptcha_v3 = {
4    attach: function(context, drupalSettings) {
5      // Grab form IDs from settings and loop through them.
6       for( let formId in drupalSettings.simple_recaptcha_v3.forms) {
7        const $form = $('form[data-recaptcha-id="'+formId+'"]');
8          let formSettings = drupalSettings.simple_recaptcha_v3.forms[formId];
9          $form.once("simple-recaptcha").each(function() {
10          $form.find('input[name="simple_recaptcha_score"]').val(formSettings.score);
11
12          // Disable submit buttons on form.
13          const $submit = $form.find('[type="submit"]');
14          $submit.attr("data-disabled", "true");
15          const $captcha = $(this).closest("form").find(".recaptcha-wrapper");
16          const captchas = [];
17
18          // AJAX forms - add submit handler to form.beforeSend.
19          // Update Drupal.Ajax.prototype.beforeSend only once.
20          if (typeof Drupal.Ajax !== 'undefined' && typeof Drupal.Ajax.prototype.beforeSubmitSimpleRecaptchaOriginal === 'undefined') {
21            Drupal.Ajax.prototype.beforeSubmitSimpleRecaptchaOriginal = Drupal.Ajax.prototype.beforeSubmit;
22            Drupal.Ajax.prototype.beforeSubmit = function (form_values, element_settings, options) {
23              let $element = $(this.element);
24              let isFormActions = $element
25                .closest('.form-actions').length;
26              let $token = $form.find('input[name="simple_recaptcha_token"]').val();
27              if (isFormActions && ($token === 'undefined' || $token === '')) {
28                this.ajaxing = false;
29                return false;
30              }
31              return this.beforeSubmitSimpleRecaptchaOriginal();
32            }
33          }
34
35          $submit.on("click", function(e) {
36            if ($(this).attr("data-disabled") === "true") {
37              // Get HTML IDs for further processing.
38              const formHtmlId = $form.attr("id");
39              const submitHtmlId = $(this).attr("id");
40
41              // Find captcha wrapper.
42              const $captcha = $(this).prev(".recaptcha-v3-wrapper");
43
44              if ( typeof captchas[formHtmlId] === "undefined" ) {
45                e.preventDefault();
46                $captcha.hide();
47                grecaptcha.ready(function() {
48                  captchas[formHtmlId] = grecaptcha.execute(drupalSettings.simple_recaptcha_v3.sitekey, {action: formSettings.action}).then(function(token){
49                    const $currentSubmit = $('#' + submitHtmlId);
50                    $form.find('input[name="simple_recaptcha_token"]').val(token);
51                    $form.find('input[name="simple_recaptcha_message"]').val(formSettings.error_message);
52                    $currentSubmit.removeAttr("data-disabled");
53                    // Click goes for regular forms, mousedown for AJAX forms.
54                    $currentSubmit.click();
55                    $currentSubmit.mousedown();
56                  });
57                });
58              }
59              e.preventDefault();
60            }
61          });
62        });
63      }
64    }
65  };
66})(jQuery);

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.