PageSourceSearch

https://magok.ru/local/templates/dz_magok/components/site/block/geo_location/script.js?17628763226456

js magok.ru collected 2026-10-03 23:49:24 UTC 6,456 bytes, 155 lines download raw bytes

1if(document.body !== null) {
2    document.body.addEventListener('click', function (e) {
3        if (e.target.parentNode && e.target.parentNode.classList.contains("geo_location")) {
4            getGeoLocation();
5        }
6    });
7}
8
9function getGeoLocation(){
10    axios.get('/local/ajax/geo-modal.php').then(function (response) {
11        document.querySelector('#location-modal .modal-inner').innerHTML = response.data;
12        addJs(window.url + window.SITE_TEMPLATE_PATH + '/assets/js/vendor/fancybox.js', 'fancybox-script', ()=>{
13            let options = {};
14            if(document.querySelector('[name="ORDER_FORM"]')){
15                options = {
16                    on: {
17                        shouldClose: () => {
18                            if(Cookies.get('select_city') == '' || Cookies.get('select_city') == undefined) {
19                                return false;
20                            }
21                        }
22                    }
23                }
24            }
25            window.location_modal = new Fancybox([{ src: "#location-modal", type: "inline" }], options);
26        });
27        addCss(window.url + window.SITE_TEMPLATE_PATH + '/assets/css/vendor/tom-select.css', 'tom-select-style', function (){});
28        addJs(window.url + window.SITE_TEMPLATE_PATH + '/assets/js/vendor/tom-select.complete.min.js', 'tom-select-script', () => {
29            TomSelect.define('no_close',function(){
30                this.close = function(){};
31            });
32            let selectCitySelect = new TomSelect('#search_location',{
33                plugins:['no_close'],
34                valueField: 'CODE',
35                labelField: 'NAME_FULL',
36                placeholder: 'Поиск по городам',
37                searchField: 'NAME',
38                create: false,
39                sortField: {
40                    field: "NAME",
41                    direction: "asc"
42                },
43                maxItems: 1,
44                load: function(query, callback) {
45                    axios.post('/api/v2/locations/Search/', {q: query})
46                        .then(response => {
47                            window.location_search_items = response.data.items;
48                            callback(response.data.items);
49                            if(document.querySelector('#search_location-ts-dropdown .spinner')) {
50                                document.querySelector('#search_location-ts-dropdown .spinner').remove();
51                            }
52                        }).catch(() => {
53                        callback();
54                        if(document.querySelector('#search_location-ts-dropdown .spinner')) {
55                            document.querySelector('#search_location-ts-dropdown .spinner').remove();
56                        }
57                    });
58
59                },
60                render: {
61                    option: function(item, escape) {
62                        return `<div class="py-2 d-flex" onclick="setValueCity('${item.CODE}', '${item.NAME}'); return true;">
63						 		        <div class="description">${ escape(item.NAME_FULL) }</div>
64						            </div>`;
65                    },
66                    item: function(item, escape) {
67                        return `<div class="py-2 d-flex">
68						 		        <div class="description">${ escape(item.NAME) }</div>
69						            </div>`;
70                    }
71                },
72            });
73            let formItem = document.querySelectorAll('.form-item');
74            setFormItem(formItem);
75        });
76    });
77}
78
79async function setValueCity(id, name){
80    // Используем централизованную функцию из app.js
81    if (typeof selectCity === 'function') {
82        // Создаем временный элемент с нужными атрибутами
83        const tempEl = document.createElement('div');
84        tempEl.setAttribute('data-code', id);
85        tempEl.setAttribute('data-name', name);
86        
87        // Получаем полные данные города из результатов поиска
88        if (window.location_search_items) {
89            const cityData = window.location_search_items.find(item => item.CODE === id);
90            if (cityData) {
91                tempEl.setAttribute('data-item', JSON.stringify(cityData));
92            }
93        }
94        
95        // Вызываем selectCity - теперь она может работать с одним параметром
96        selectCity(tempEl);
97    } else {
98        // Fallback на случай, если selectCity недоступна
99        Cookies.set('select_city', id, { expires: 365, domain: '.magok.ru', path: '/' });
100        Cookies.set('select_city_name', name, { expires: 365, domain: '.magok.ru', path: '/' });
101        
102        // Обновляем интерфейс
103        document.querySelectorAll('.geo_location span').forEach(el => {
104            el.innerText = name;
105        });
106        
107        if(document.querySelector('[name="ORDER_FORM"]')){
108            document.querySelector('[name="prop_LOCATION"]').value = id;
109            refreshOrder();
110        }
111    }
112    
113    // Обновляем доставку (если есть)
114    if(document.getElementById('delivery_in_product') && deliveryInProduct !== undefined){
115        deliveryInProduct.reSet();
116    }
117    
118    // Закрываем модальное окно
119    if (window.location_modal) {
120        window.location_modal.close();
121    }
122
123    // Ждем результат проверки поддомена
124    try {
125        const redirectResult = await checkCitySubdomain(id, name);
126        console.log('Результат проверки поддомена:', redirectResult);
127        
128        if (!redirectResult.needsRedirect) {
129            console.log('Редирект не требуется, остаемся на текущей странице');
130            return false;
131        }
132    } catch (error) {
133        console.error('Ошибка при проверке поддомена:', error);
134        return false;
135    }
136    
137    return false;
138}
139
140function setTitle(){
141
142}
143
144document.querySelectorAll('.geo_location span').forEach(el => {
145
146    if(Cookies.get('select_city_name') != null){
147        el.innerHTML = Cookies.get('select_city_name');
148
149        if(document.querySelector('.conform_geo_location')){
150            document.querySelector('.conform_geo_location').remove();
151        }
152    }
153
154
155});

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.