PageSourceSearch

https://gdekomfort.ru/modules/affiliate/view/js/rscomponent/affiliate.js

js gdekomfort.ru collected 2026-10-05 02:26:04 UTC 4,383 bytes, 130 lines download raw bytes

1/**
2 * Инииализирует поиск по филиалам
3 *
4 * Зависит от autoComplete.js
5 */
6new class Affiliate extends RsJsCore.classes.component
7{
8    constructor()
9    {
10        super();
11        let defaults = {
12            confirmDialog: '.affilliate-confirm',
13            confirmClose: '.modal-close',
14
15            inputSearch: '.rs-city-search',
16            autocompleteResult: '.rs-autocomplete-result',
17            affiliateConfirmTemplate: '#affiliate-confirm-template'
18        };
19
20        this.settings = {...defaults, ...this.getExtendsSettings()};
21    }
22
23    /**
24     * Находит все autocomplete input'ы, вутри newElement и активирует их
25     *
26     * @param newElement
27     */
28    initSearchAffiliateInDialog(newElement)
29    {
30        let input = newElement.querySelector(this.settings.inputSearch);
31        let resultWrapper = input && input.parentNode.querySelector(this.settings.autocompleteResult);
32        let cancelController;
33
34        if (input && !input.rsInitialized) {
35            input.rsInitialized = true;
36            let autoCompleteInstance = new autoComplete({
37                selector: () => input,
38                searchEngine: () => true,
39                wrapper:false,
40                data: {
41                    src: async () => {
42                        if (cancelController) cancelController.abort();
43                        cancelController = new AbortController();
44
45                        let data = await this.utils.fetchJSON(input.dataset.urlSearch + '&' + new URLSearchParams({
46                            term:autoCompleteInstance.input.value
47                        }), {
48                            signal: cancelController.signal
49                        });
50
51                        return data ? data.list : [];
52                    },
53                    keys:['label']
54                },
55                resultsList: {
56                    class: '',
57                    maxResults:20,
58                    position:'beforeend',
59                    destination:() => resultWrapper,
60                },
61                resultItem: {
62                    element: (element, data) => {
63                        let tpl;
64                        tpl = `<a class="dropdown-item" href="${data.value.url}">
65                                        <div class="col">${data.value.label}</div>
66                                    </a>`;
67                        element.innerHTML = tpl;
68                    },
69                    selected: 'selected'
70                },
71                events: {
72                    input: {
73                        selection: (event) => {
74                            location.href = event.detail.selection.value.url;
75                        }
76                    }
77                }
78            });
79        }
80    }
81
82    /**
83     * Проверяем, нужно ли отображать диалог подтверждения определенного филиала.
84     * Если да, то отображаем его
85     */
86    checkNeedConfirmAffiliate() {
87        let template = document.querySelector(this.settings.affiliateConfirmTemplate);
88        if (template) {
89            document.body.appendChild(template.content);
90            let win = document.querySelector(this.settings.confirmDialog);
91            win.querySelectorAll(this.settings.confirmClose).forEach(it => {
92                it.addEventListener('click', event => this.closeConfirmAffiliate(event));
93            });
94        }
95    }
96
97    /**
98     * Закрывает окно подтверждения филиала
99     *
100     * @param event
101     */
102    closeConfirmAffiliate(event) {
103        let context = event.target.closest(this.settings.confirmDialog);
104        context && context.remove();
105
106        let domain = context.dataset.domain || '';
107
108        this.plugins.cookie.setCookie('affiliate_already_select', 1, {
109            domain:domain
110        });
111    }
112
113    /**
114     * Выполняется, когда страница загружается
115     */
116    onDocumentReady()
117    {
118        this.checkNeedConfirmAffiliate();
119    }
120
121    /**
122     * Выполняется, когда на странице появл
122яется новый контент
123     *
124     * @param event
125     */
126    onContentReady(event)
127    {
128        this.initSearchAffiliateInDialog(event.target);
129    }
130};

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.