PageSourceSearch

https://lspatterns.ru/local/components/ilar/subscribe.user/templates/footer/script.js

js lspatterns.ru collected 2026-10-08 15:24:28 UTC 2,891 bytes, 73 lines download raw bytes

1(function () {
2    const forms = document.querySelectorAll('.js-subscribe-form');
3    if (!forms.length) return;
4
5    forms.forEach(function(form) {
6        const emailInput = form.querySelector('.js-subscribe-email');
7        const inputWrap  = form.querySelector('.js-input-wrap');
8        const errors     = form.querySelectorAll('.js-subscribe-error');
9        const btn        = form.querySelector('.js-subscribe-btn');
10
11        function setError(message) {
12            inputWrap.classList.add('error');
13            errors.forEach(el => el.textContent = message);
14        }
15
16        function clearError() {
17            inputWrap.classList.remove('error');
18            errors.forEach(el => el.textContent = '');
19        }
20
21        emailInput.addEventListener('input', clearError);
22
23        form.addEventListener('submit', (e) => {
24            e.preventDefault();
25
26            const email = emailInput.value.trim();
27            if (!email) {
28                setError('Введите e-mail');
29                return;
30            }
31
32            // Блокируем кнопку и меняем текст
33            btn.disabled = true;
34            btn.textContent = 'Подписываем...';
35            clearError();
36
37            BX.ajax.runComponentAction('ilar:subscribe.user', 'subscribe', {
38                mode: 'ajax',
39                data: { email: email },
40            })
41                .then(function (response) {
42                    // Успешная подписка
43                    btn.textContent = 'Вы подписаны ✓';
44                    emailInput.value = '';
45                    clearError();
46
47                    // Открываем модальное окно
48                    if (typeof modal !== 'undefined' && typeof modal.open === 'function') {
49                        modal.close('burger-menu')
50                        modal.open('sucsess-subscribe');
51                    }
52
53                    // Возвращаем кнопку в исходное состояние через 3 секунды
54                    setTimeout(() => {
55                        btn.disabled = false;
56                        btn.textContent = 'Подписаться';
57                    }, 3000);
58                })
59                .catch(function (response) {
60                    // Обработка ошибок
61                    let errorMessage = 'Ошибка при подписке';
62
63                    if (response.errors && Array.isArray(response.errors)) {
64                        errorMessage = response.errors.map(e => e.message).join(', ');
65                    }
66
67                    setError(errorMessage);
68                    btn.disabled = false;
69                    btn.textContent = 'Подписаться';
70                });
71        });
72    });
73})();

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.