PageSourceSearch

https://fabrika38.ru/local/components/wms/cookie-agreement/templates/.default/script.js?17893705863953

js fabrika38.ru collected 2026-10-07 20:05:08 UTC 3,953 bytes, 90 lines download raw bytes

1document.addEventListener('DOMContentLoaded', function () {
2
3    const cookieSettings = document.getElementById('variantsModalCookie');
4    const openSettings = document.getElementById('wms-open-settings');
5    const acceptAllBtn = document.getElementById('wms-accept-all');
6    const acceptEssentialBtn = document.getElementById('wms-accept-essential');
7    const banner = document.getElementById('cookieBanner');
8    const saveSettings = document.getElementById('save-settings');
9
10    document.querySelectorAll(".closeCookie").forEach(function (button) {
11        button.addEventListener("click", function () {
12            this.closest('.modalCookie').classList.remove('active');
13        });
14    });
15
16    saveSettings?.addEventListener('click', () => {
17        const categories = [];
18        document.querySelectorAll('input[name="categories[]"]:checked').forEach(cb => {
19            categories.push(cb.value);
20        });
21        submitConsent(categories);
22    });
23
24    // === Быстрое согласие: Принять все ===
25    acceptAllBtn?.addEventListener('click', () => {
26        submitConsent(['ANALYTICS', 'MARKETING']);
27    });
28
29    // === Быстрое согласие: Только необходимые ===
30    acceptEssentialBtn?.addEventListener('click', () => {
31        submitConsent([]);
32    });
33
34    openSettings?.addEventListener('click', openCookieSettings);
35
36    function submitConsent(selectedCategories = []) {
37        const categories = ['ESSENTIAL', ...selectedCategories];
38
39        BX.ajax.runComponentAction('wms:cookie-agreement', 'saveSettings', {
40            mode: 'class',
41            data: {
42                categories: categories,
43                sessid: BX.bitrix_sessid()
44            }
45        }).then(function (response) {
46            if (response.data && response.data.status === 'ok') {
47                // Успешно сохранено
48                document.cookie = 'wms_cookie_agreed=Y; path=/; max-age=' + (365 * 24 * 60 * 60);
49                document.cookie = 'wms_cookie_categories=' + encodeURIComponent(categories.join(',')) + '; path=/; max-age=' + (365 * 24 * 60 * 60);
50                closeCookieSettings();
51                window.location.reload();
52            } else {
53                // Ошибка на уровне бизнес-логики
54                const errorMsg = response.data?.errors?.[0]?.message || 'Неизвестная ошибка';
55                console.error('Ошибка сохранения согласия:', errorMsg);
56                alert('Не удалось сохранить настройки: ' + errorMsg);
57            }
58        }).catch(function (error) {
59            // Ошибка сети или сервера
60            console.error('AJAX ошибка:', error);
61            alert('Произошла ошибка при подключении. Попробуйте снова.');
62        });
63    }
64
65    function closeCookieSettings() {
66        if (banner) banner.classList.remove('active');
67        if (cookieSettings) cookieSettings.classList.remove('active');
68    }
69
70    function openCookieSettings() {
71        loadCurrentSettings();
72        const wmsModal = new bootstrap.Modal(cookieSettings);
73        wmsModal.show();
74    }
75
76    function loadCurrentSettings() {
77        BX.ajax.runComponentAction('wms:cookie-agreement', 'loadSettings', {
78            mode: 'class'
79        }).then(function (response) {
80            const data = response.data || ['ESSENTIAL'];
81            const analyticsCb = document.getElementById('analytics');
82            const marketingCb = document.getElementById('marketing');
83
84            if (analyticsCb) analyticsCb.checked = data.includes('ANALYTICS');
85            if (marketingCb) marketingCb.checked = data.includes('MARKETING');
86        }).catch(function (response) {
87            console.error('Не удалось загрузить настройки cookie', response);
88        });
89    }
90});

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.