PageSourceSearch

https://cadlab.io/sites/all/modules/cloud/cloudflare_turnstile/cloudflare_turnstile.js?tlv5nf

js cadlab.io collected 2026-10-03 22:46:41 UTC 2,360 bytes, 69 lines download raw bytes

1/**
2 * @file
3 * Renders Turnstile widgets explicitly so they (re-)initialize when HTML is
4 * injected via AJAX (e.g. login/register form after validation errors).
5 */
6(function ($, Drupal) {
7  'use strict';
8
9  Drupal.behaviors.cloudflareTurnstile = {
10    attach: function (context, settings) {
11      var $containers = $(context).find('.cf-turnstile-container').once('turnstile-render');
12      if (!$containers.length) {
13        return;
14      }
15      var hasVisibleWidget = false;
16      function doRender() {
17        $containers.each(function () {
18          var el = this;
19          var id = el.id;
20          if (!id) {
21            return;
22          }
23          var $el = $(el);
24          var sitekey = $el.attr('data-sitekey');
25          if (!sitekey) {
26            return;
27          }
28          if ($el.attr('data-visible-widget') === '1') {
29            hasVisibleWidget = true;
30          }
31          window.turnstile.render('#' + id, {
32            sitekey: sitekey,
33            theme: $el.attr('data-theme') || 'light',
34            size: $el.attr('data-size') || 'flexible'
35          });
36        });
37        if (!hasVisibleWidget) {
38          return;
39        }
40        try {
41          var parentDoc = window.parent && window.parent.document;
42          var iframes = parentDoc && parentDoc.querySelectorAll('.cadlab-form-iframe');
43          if (!iframes || !iframes.length) {
44            return;
45          }
46          for (var i = 0; i < iframes.length; i++) {
47            var iframe = iframes[i];
48            var style = parentDoc.defaultView && parentDoc.defaultView.getComputedStyle(iframe);
49            var visible = iframe.offsetParent !== null && (!style || (style.display !== 'none' && style.visibility !== 'hidden'));
50            if (visible) {
51              var h = parseInt(iframe.style.height, 10) || iframe.offsetHeight || 0;
52              iframe.style.height = (h + 50) + 'px';
53            }
54          }
55        } catch (e) {}
56      }
57      function renderWidgets() {
58        if (typeof window.turnstile === 'undefined') {
59          setTimeout(renderWidgets, 50);
60          return;
61        }
62        // Call render directly; turnstile.ready() fires only once on first load, so
63        // it never runs again after AJAX injects new content — avoid using it here.
64        doRender();
65      }
66      renderWidgets();
67    }
68  };
69})(jQuery, Drupal);

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.