PageSourceSearch

https://ligacybersport.ru/nsk/wp-content/plugins/elementor-smartcaptcha/smartcaptcha-init.js?ver=2.8

js ligacybersport.ru collected 2026-10-07 18:10:17 UTC 13,682 bytes, 379 lines download raw bytes

1(function($) {
2    'use strict';
3
4    var readyCallbacks = [];
5    var readyTimer = null;
6    var readyStarted = false;
7    var lastSubmitter = null;
8
9    function getConfig() {
10        return window.elementorSmartCaptcha || {};
11    }
12
13    function getMessage(key, fallback) {
14        var config = getConfig();
15        return config.messages && config.messages[key] ? config.messages[key] : fallback;
16    }
17
18    function forceElementorAjaxUrl() {
19        var config = getConfig();
20        var ajaxUrl = config.ajaxUrl;
21
22        if (!ajaxUrl) {
23            return;
24        }
25
26        try {
27            if (window.elementorFrontendConfig) {
28                window.elementorFrontendConfig.ajaxurl = ajaxUrl;
29            }
30
31            if (window.elementorProFrontendConfig) {
32                window.elementorProFrontendConfig.ajaxurl = ajaxUrl;
33            }
34
35            if (window.elementorFrontend && window.elementorFrontend.config) {
36                window.elementorFrontend.config.ajaxurl = ajaxUrl;
37            }
38        } catch (error) {
39            // Не останавливаем форму, если сторонний скрипт запретил изменение config.
40        }
41    }
42
43    function waitForSmartCaptcha(onReady, onTimeout) {
44        if (typeof window.smartCaptcha !== 'undefined') {
45            onReady();
46            return;
47        }
48
49        readyCallbacks.push(onReady);
50
51        if (readyStarted) {
52            return;
53        }
54
55        readyStarted = true;
56        var attempts = 0;
57        var maxAttempts = 120; // 12 секунд
58
59        readyTimer = setInterval(function() {
60            attempts++;
61
62            if (typeof window.smartCaptcha !== 'undefined') {
63                clearInterval(readyTimer);
64                readyTimer = null;
65                readyStarted = false;
66
67                var callbacks = readyCallbacks.slice();
68                readyCallbacks = [];
69                callbacks.forEach(function(callback) {
70                    callback();
71                });
72            } else if (attempts >= maxAttempts) {
73                clearInterval(readyTimer);
74                readyTimer = null;
75                readyStarted = false;
76                readyCallbacks = [];
77
78                if (typeof onTimeout === 'function') {
79                    onTimeout();
80                }
81            }
82        }, 100);
83    }
84
85    function ensureTokenInput($form) {
86        var $tokenInput = $form.find('input[name="smart-token"]');
87        if ($tokenInput.length === 0) {
88            $tokenInput = $('<input type="hidden" name="smart-token">');
89            $form.append($tokenInput);
90        }
91        return $tokenInput;
92    }
93
94    function isInvisible($container) {
95        return String($container.data('mode')) === 'invisible' || String($container.data('invisible')) === '1';
96    }
97
98    function clearToken($container) {
99        var $form = $container.closest('form');
100        $form.find('input[name="smart-token"]').val('');
101    }
102
103    function resetCaptcha($container) {
104        var widgetId = $container.data('widget-id');
105        clearToken($container);
106
107        if (typeof window.smartCaptcha !== 'undefined' && typeof window.smartCaptcha.reset === 'function' && widgetId !== undefined) {
108            try {
109                window.smartCaptcha.reset(widgetId);
110            } catch (error) {
111                // reset может быть недоступен, если виджет уже уничтожен Elementor popup'ом
112            }
113        }
114    }
115
116    function setFormBusy($form, isBusy) {
117        var $buttons = $form.find('button[type="submit"], input[type="submit"]');
118
119        $form.attr('aria-busy', isBusy ? 'true' : 'false');
120
121        $buttons.each(function() {
122            var $button = $(this);
123
124            if (isBusy) {
125                if (typeof $button.data('smartcaptcha-was-disabled') === 'undefined') {
126                    $button.data('smartcaptcha-was-disabled', $button.prop('disabled') ? '1' : '0');
127                }
128                $button.prop('disabled', true);
129            } else {
130                var wasDisabled = $button.data('smartcaptcha-was-disabled');
131                if (typeof wasDisabled !== 'undefined') {
132                    $button.prop('disabled', wasDisabled === '1');
133                    $button.removeData('smartcaptcha-was-disabled');
134                }
135            }
136        });
137    }
138
139    function showInlineMessage($form, message) {
140        var $message = $form.find('.elementor-smartcaptcha-message');
141        if ($message.length === 0) {
142            $message = $('<div class="elementor-message elementor-message-danger elementor-smartcaptcha-message" role="alert"></div>');
143            var $captcha = $form.find('.elementor-smartcaptcha').first();
144            if ($captcha.length) {
145                $captcha.closest('.elementor-field').after($message);
146            } else {
147                $form.prepend($message);
148            }
149        }
150        $message.text(message).show();
151    }
152
153    function hideInlineMessage($form) {
154        $form.find('.elementor-smartcaptcha-message').hide();
155    }
156
157    function getSubmitter(form) {
158        if (lastSubmitter && lastSubmitter.form === form) {
159            return lastSubmitter;
160        }
161
162        var active = document.activeElement;
163        if (active && active.form === form && /^(submit|image)$/i.test(active.type || '')) {
164            return active;
165        }
166
167        return null;
168    }
169
170    function resumeFormSubmit(form, submitter) {
171        forceElementorAjaxUrl();
172
173        if (!form) {
174            return;
175        }
176
177        if (submitter && typeof form.requestSubmit === 'function') {
178            form.requestSubmit(submitter);
179            return;
180        }
181
182        if (typeof form.requestSubmit === 'function') {
183            form.requestSubmit();
184            return;
185        }
186
187        var event;
188        if (typeof Event === 'function') {
189            event = new Event('submit', { bubbles: true, cancelable: true });
190        } else {
191            event = document.createEvent('Event');
192            event.initEvent('submit', true, true);
193        }
194
195        if (form.dispatchEvent(event)) {
196            form.submit();
197        }
198    }
199
200    function executeInvisibleCaptcha($container, submitter) {
201        var $form = $container.closest('form');
202        var widgetId = $container.data('widget-id');
203
204        hideInlineMessage($form);
205        setFormBusy($form, true);
206        $container.data('captcha-pending-submit', true);
207        $container.data('captcha-submit-clicked', submitter || null);
208
209        try {
210            window.smartCaptcha.execute(widgetId);
211        } catch (error) {
212            console.error('Ошибка запуска SmartCaptcha:', error);
213            $container.data('captcha-pending-submit', false);
214            setFormBusy($form, false);
215            showInlineMessage($form, getMessage('executeError', 'Не удалось запустить проверку. Обновите страницу и попробуйте снова.'));
216        }
217    }
218
219    function initSmartCaptcha() {
220        if (typeof window.smartCaptcha === 'undefined') {
221            return;
222        }
223
224        $('.elementor-smartcaptcha.smart-captcha, .smart-captcha[data-sitekey]').each(function() {
225            var $container = $(this);
226
227            if ($container.data('captcha-initialized')) {
228                return;
229            }
230
231            var sitekey = $container.data('sitekey') || getConfig().sitekey;
232            if (!sitekey) {
233                return;
234            }
235
236            var $form = $container.closest('form');
237            if ($form.length === 0) {
238                return;
239            }
240
241            try {
242                var params = {
243                    sitekey: sitekey,
244                    callback: function(token) {
245                        var $tokenInput = ensureTokenInput($form);
246                        $tokenInput.val(token || '');
247
248                        if (isInvisible($container) && $container.data('captcha-pending-submit')) {
249                            var form = $form[0];
250                            var submitter = $container.data('captcha-submit-clicked') || null;
251
252                            $container.data('captcha-pending-submit', false);
253                            $container.removeData('captcha-submit-clicked');
254                            setFormBusy($form, false);
255
256                            if (token) {
257                                window.setTimeout(function() {
258                                    resumeFormSubmit(form, submitter);
259                                }, 0);
260
261                                window.setTimeout(function() {
262                                    resetCaptcha($container);
263                                }, 10000);
264                            } else {
265                                showInlineMessage($form, getMessage('emptyToken', 'Проверка не завершена. Попробуйте отправить форму еще раз.'));
266                            }
267                        }
268                    }
269                };
270
271                if (isInvisible($container)) {
272                    params.invisible = true;
273                    var shield = String($container.data('shield') || getConfig().shield || 'hide');
274                    if (shield === 'hide') {
275                        params.hideShield = true;
276                    } else {
277                        params.shieldPosition = shield;
278                    }
279                }
280
281                var widgetId = window.smartCaptcha.render($container[0], params);
282
283                $container.data('captcha-initialized', true);
284                $container.data('widget-id', widgetId);
285
286                if (typeof window.smartCaptcha.subscribe === 'function') {
287                    window.smartCaptcha.subscribe(widgetId, 'token-expired', function() {
288                        clearToken($container);
289                    });
290
291                    window.smartCaptcha.subscribe(widgetId, 'network-error', function() {
292                        setFormBusy($form, false);
293                        showInlineMessage($form, getMessage('networkError', 'Ошибка сети при проверке. Попробуйте еще раз.'));
294                    });
295
296                    window.smartCaptcha.subscribe(widgetId, 'javascript-error', function() {
297                        setFormBusy($form, false);
298                        showInlineMessage($form, getMessage('javascriptError', 'Не удалось выполнить проверку безопасности. Обновите страницу и попробуйте снова.'));
299                    });
300                }
301            } catch (error) {
302                console.error('Ошибка инициализации SmartCaptcha:', error);
303                var message = (error && error.message) ? String(error.message) : '';
304                if (message.indexOf('Invalid key') !== -1) {
305                    showInlineMessage($form, getMessage('invalidKey', 'SmartCaptcha не смогла запуститься: проверьте Client Key и домен в настройках Yandex Cloud.'));
306                } else {
307                    showInlineMessage($form, getMessage('javascriptError', 'Не удалось выполнить проверку безопасности. Обновите страницу и попробуйте снова.'));
308                }
309            }
310        });
311    }
312
313    function findInvisibleCaptchaContainer(form) {
314        var $form = $(form);
315        var $container = $form.find('.elementor-smartcaptcha--invisible, .elementor-smartcaptcha[data-mode="invisible"], .smart-captcha[data-mode="invisible"]').first();
316        return $container.length ? $container : $();
317    }
318
319    function handleInvisibleSubmit(event) {
320        forceElementorAjaxUrl();
321
322        var form = event.target;
323        var $container = findInvisibleCaptchaContainer(form);
324
325        if ($container.length === 0) {
326            return;
327        }
328
329        var $form = $(form);
330        var token = $form.find('input[name="smart-token"]').val();
331
332        if (token) {
333            return;
334        }
335
336        event.preventDefault();
337        if (typeof event.stopImmediatePropagation === 'function') {
338            event.stopImmediatePropagation();
339        } else {
340            event.stopPropagation();
341        }
342
343        var submitter = event.submitter || getSubmitter(form);
344
345        waitForSmartCaptcha(function() {
346            initSmartCaptcha();
347            executeInvisibleCaptcha($container, submitter);
348        }, function() {
349            setFormBusy($form, false);
350            showInlineMessage($form, getMessage('loadError', 'Проверка безопасности еще не загрузилась. Попробуйте отправить форму через несколько секунд.'));
351        });
352    }
353
354    $(document).on('click', 'button[type="submit"], input[type="submit"]', function() {
355        lastSubmitter = this;
356    });
357
358    if (document.addEventListener) {
359        document.addEventListener('submit', handleInvisibleSubmit, true);
360    }
361
362    $(document).ready(function() {
363        forceElementorAjaxUrl();
364        waitForSmartCaptcha(initSmartCaptcha);
365    });
366
367    $(document).on('elementor/popup/show', function() {
368        window.setTimeout(function() {
369            waitForSmartCaptcha(initSmartCaptcha);
370        }, 300);
371    });
372
373    $(document).on('elementor-pro/forms/new elementor/frontend/init', function() {
374        waitForSmartCaptcha(initSmartCaptcha);
375    });
376
377    window.elementorSmartCaptchaInit = initSmartCaptcha;
378
379})(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.