PageSourceSearch

https://tmglobal.com.my/modules/contrib/simple_recaptcha/js/simple_recaptcha_v3.js?v=1.x

js tmglobal.com.my collected 2026-10-04 10:41:49 UTC 3,449 bytes, 71 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          $(once('simple-recaptcha', $form)).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('.simple-recaptcha-submit');
14          $submit.attr("data-disabled", "true");
15          $submit.attr('data-html-form-id', $form.attr("id"));
16          const $captcha = $(this).closest("form").find(".recaptcha-wrapper");
17          const captchas = [];
18
19          // AJAX forms - add submit handler to form.beforeSend.
20          // Update Drupal.Ajax.prototype.beforeSend only once.
21          if (typeof Drupal.Ajax !== 'undefined' && typeof Drupal.Ajax.prototype.beforeSubmitSimpleRecaptchaOriginal === 'undefined') {
22            Drupal.Ajax.prototype.beforeSubmitSimpleRecaptchaOriginal = Drupal.Ajax.prototype.beforeSubmit;
23            Drupal.Ajax.prototype.beforeSubmit = function (form_values, element_settings, options) {
24              let currentFormIsRecaptcha = form_values.find(function (form_id) {
25                return form_id.value === formId;
26              });
27              if (typeof currentFormIsRecaptcha !== 'undefined') {
28                let $element = $(this.element);
29                let isFormActions = $element
30                    .closest('.form-actions').length;
31                let token = $form.find('input[name="simple_recaptcha_token"]').val();
32                if (isFormActions && (typeof token === 'undefined' || token === '')) {
33                  this.ajaxing = false;
34                  return false;
35                }
36              }
37              return this.beforeSubmitSimpleRecaptchaOriginal(this, arguments);
38            }
39          }
40
41          $submit.on("click", function (e) {
42            if ($(this).attr("data-disabled") === "true") {
43              // Get HTML IDs for further processing.
44              const formHtmlId = $form.attr("id");
45
46              // Find captcha wrapper.
47              const $captcha = $(this).prev(".recaptcha-v3-wrapper");
48
49              if ( typeof captchas[formHtmlId] === 'undefined' ) {
50                e.preventDefault();
51                $captcha.hide();
52                grecaptcha.ready(function () {
53                  captchas[formHtmlId] = grecaptcha.execute(drupalSettings.simple_recaptcha_v3.sitekey, {action: formSettings.action}).then(function (token) {
54                    const $currentSubmit = $('[data-html-form-id="' + formHtmlId + '"]');
55                    $form.find('input[name="simple_recaptcha_token"]').val(token);
56                    $form.find('input[name="simple_recaptcha_message"]').val(formSettings.error_message);
57                    $currentSubmit.removeAttr("data-disabled");
58                    // Click goes for regular forms, mousedown for AJAX forms.
59                    $currentSubmit.click();
60                    $currentSubmit.mousedown();
61                  });
62                });
63              }
64              e.preventDefault();
65            }
66          });
67        });
68      }
69    }
70  };
71})(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.