PageSourceSearch

https://mi.by/local/templates/mi/js/script.js

js mi.by collected 2026-10-04 02:39:57 UTC 10,665 bytes, 341 lines download raw bytes

1function sentEventToGA(eventName) {
2    ga('send', 'event', eventName, eventName);    
3    return 1;
4}
5
6function sentEventToGANew(eventName, data) {
7    if (typeof gtag === 'function') {
8        gtag("event", eventName, {
9            currency: data.GTAG_CURRENCY,
10            value: data.GTAG_PRICE,
11            items: [
12                {
13                    item_id: data.GTAG_ITEM_ID,
14                    item_name: data.GTAG_ITEM_NAME,
15                    item_brand: data.GTAG_ITEM_BRAND,
16                    price: data.GTAG_PRICE,
17                    quantity: data.GTAG_QUANTITY,
18                }
19            ],
20        });
21    } else {
22        if(typeof dataLayer !== 'undefined' && dataLayer){
23            dataLayer.push({
24                'event': eventName,
25                'ecommerce': {
26                    currency: data.GTAG_CURRENCY,
27                    value: data.GTAG_PRICE,
28                    items: [
29                        {
30                            item_id: data.GTAG_ITEM_ID,
31                            item_name: data.GTAG_ITEM_NAME,
32                            item_brand: data.GTAG_ITEM_BRAND,
33                            price: data.GTAG_PRICE,
34                            quantity: data.GTAG_QUANTITY,
35                        }
36                    ],
37                }
38            });
39        }
40    }
41    return 1;
42}
43
44function sentEventToGASection(eventName, item) {
45    if (typeof gtag === 'function') {
46        gtag("event", eventName, {
47          currency: item.CURRENCY,
48          value: item.PRICE,
49          items: [
50            {
51              item_id: item.ID,
52              item_name: item.NAME,
53              item_brand: item.BRAND,
54              price: item.PRICE,
55              quantity: item.QUANTITY,
56            }
57          ],
58        });
59    } else {
60        if(typeof dataLayer !== 'undefined' && dataLayer){
61            dataLayer.push({
62                'event': eventName,
63                'ecommerce': {
64                    currency: item.CURRENCY,
65                    value: item.PRICE,
66                    items: [
67                        {
68                            item_id: item.ID,
69                            item_name: item.NAME,
70                            item_brand: item.BRAND,
71                            price: item.PRICE,
72                            quantity: item.QUANTITY,
73                        }
74                    ],
75                }
76            });
77        }
78    }
79    return 1;
80}
81
82function sentEventToGAArray(eventName, arData, currency, allSum) {
83    if (typeof gtag === 'function') {
84        gtag("event", eventName, {
85          currency: currency,
86          value: allSum,
87          items: arData,
88        });
89        console.log('ok');
90    } else {
91        if(typeof dataLayer !== 'undefined' && dataLayer){
92            dataLayer.push({
93                'event': eventName,
94                'ecommerce': {
95                    currency: currency,
96                    value: allSum,
97                    items: arData,
98                }
99            });
100        }
101    }
102    return 1;
103}
104
105$(document).ready(function () {
106    favoritesHandler();
107
108    $('[name="location"]').on('change', function(event){
109        initDeliveryDate(event.target.value);
110    });
111    
112    $('#element_num_reviews').click(function(){
113        $('#tab-5').click();
114    })
115    
116    $("#promo").on('input', function(evt) {
117          var input = $(this);
118          var start = input[0].selectionStart;
119          $(this).val(function (_, val) {
120            return val.toUpperCase();
121          });
122          input[0].selectionStart = input[0].selectionEnd = start;
123        });
124    
125    //ADD TO FAVORITES FOR GA 28203
126    /*
127    $('.card__header--favorites a').click(function(){
128        if ($(this).hasClass('active')) {} else {sentEventToGA('add_to_wishlist');}     
129    });
130    $('.card-item__to-favorites').click(function(){
131        if ($(this).hasClass('active')) {} else {sentEventToGA('add_to_wishlist');}     
132    });
133    $('.add-to-card').click(function(){
134        if ($(this).hasClass('active')) {} else {sentEventToGA('add_to_cart');}     
135    });
136    $('.buy-one-click').click(function(){
137        sentEventToGA('one_click_buy');     
138    });
139    $('.good__remove').click(function(){
140        sentEventToGA('removefromcart');     
141    });
142    $('input[name=DELIVERY_ID]').click(function(){
143        sentEventToGA('add_shipping_info');     
144    });
145    $('.checkoutRadio__text').click(function(){
146        sentEventToGA('add_shipping_info');     
147    });   
148    */
149    
150});
151function favoritesHandler() {
152    $('.favorites__section').on('click', function (e) {
153        let sectionID = $(this).attr('data-section');
154        let item = $('.favorites__sort .custom-select__select .custom-select__select-item.js-select-item .selected');
155
156        if ($('#panel-' + sectionID).length > 0) {
157            return;
158        }
159
160        $.ajax({
161            url: window.location.href,
162            data: {
163                sort_field: item.attr('data-field'),
164                sort_order: item.attr('data-order'),
165                sectionID: sectionID
166            },
167            beforeSend: function () {
168                $("#loader-shop").show();
169            },
170            success: function (response) {
171                let panel = $(response).find('#panel-' + sectionID);
172                $('#panel-0').after(panel);
173            },
174            complete: function () {
175                $("#loader-shop").hide();
176            }
177        })
178    })
179
180    let favoritesSort = document.querySelector('.sort.favorites_sort select');
181    favoritesSort && favoritesSort.addEventListener('change', function () {
182        let sectionID = $('.favorites__section[aria-selected="true"]').attr('data-section');
183        let itemSort = $(this).find(':selected');
184        let sortField = itemSort.attr('data-field');
185        let sortOrder = itemSort.attr('data-order');
186
187        $.setUrlParam('sort_field', sortField);
188        $.setUrlParam('sort_order', sortOrder);
189
190        $.ajax({
191            url: window.location.href,
192            data: {
193                sectionID: sectionID
194            },
195            success: function (response) {
196                let panel = $(response).find('#panel-' + sectionID);
197                $('#panel-' + sectionID).html(panel[0].innerHTML);
198            },
199        })
200    });
201
202    let catalogSort = document.querySelector('.sort.catalog__sort select');
203    catalogSort && catalogSort.addEventListener('change', function () {
204        let itemSort = $(this).find(':selected');
205        let sortField = itemSort.attr('data-field');
206        let sortOrder = itemSort.attr('data-order');
207
208        $.setUrlParam('sort_field', sortField);
209        $.setUrlParam('sort_order', sortOrder);
210
211        $.ajax({
212            url: window.location.href,
213            success: function (response) {
214                let catalogGrid = $(response).find('.catalog__grid')[0];
215                $('.catalog__grid').html(catalogGrid.innerHTML);
216
217                let pagination = $(response).find('.pagination')[0];
218                $('.pagination').html(pagination.innerHTML);
219            },
220        })
221    });
222
223    let catalogQuantity = document.querySelector('.sort.catalog__quantity-show select');
224    catalogQuantity && catalogQuantity.addEventListener('change', function () {
225        let quantity = $(this).find(':selected').val();
226        $.setUrlParam('quantity', quantity);
227
228        $.ajax({
229            url: window.location.href,
230            success: function (response) {
231                let catalogGrid = $(response).find('.catalog__grid').parent()[0];
232                $('.catalog__grid').parent().html(catalogGrid.innerHTML);
233            },
234        })
235    });
236
237    let searchSort = document.querySelector('.sort.search_sort select');
238    searchSort && searchSort.addEventListener('change', function () {
239        let itemSort = $(this).find(':selected');
240        let sortField = itemSort.attr('data-field');
241        let sortOrder = itemSort.attr('data-order');
242
243        $.setUrlParam('sort_field', sortField);
244        $.setUrlParam('sort_order', sortOrder);
245
246        $.ajax({
247            url: window.location.href,
248            data: {},
249            success: function (response) {
250                let container = $(response).find('#search');
251                $('#search').html(container[0].innerHTML);
252            },
253        })
254    });
255}
256
257function initDeliveryDate(location = false){
258 /*   if(!location){
259        location = getCookie('location');
260    }
261
262    let deliveryDate = document.querySelector('#delivery-date');
263    console.log(deliveryDate);
264    if(deliveryDate && location){
265        //let dataDeliveryDay = JSON.parse(deliveryDate.getAttribute('data-day'));
266        let date = new Date();
267        date.setDate(date.getDate() + 3);//parseInt(dataDeliveryDay[location]));
268        var options = {
269            year: 'numeric',
270            month: 'numeric',
271            day: 'numeric'
272        };
273        deliveryDate.querySelector('.text').innerHTML = date.toLocaleString("ru", options);
274    }*/
275}
276
277$.setUrlParam = function (name, value) {
278    let url = new URL(window.location.href);
279    url.searchParams.set(name, value);
280    window.history.pushState(null, null, url.pathname + url.search);
281}
282
283$.getUrlParam = function (name) {
284    let url = new URL(window.location.href);
285    return url.searchParams.get(name);
286}
287
288$.getAllUrlParams = function (name) {
289    let url = new URL(window.location.href);
290    return url.searchParams.getAll(name);
291}
292
293function getCookie(name) {
294    let matches = document.cookie.match(new RegExp(
295      "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
296    ));
297    return matches ? decodeURIComponent(matches[1]) : undefined;
298}
299
300BX.showWait = function(a, b){};
301
302//Задача № 28119
303
304$(document).ready(function () {
305    const target = document.querySelector('.favorites');
306
307    if(target){
308        const config = {
309            attributes: true,
310            childList: true,
311            subtree: true,
312        };
313
314        const callback = function (mutationsList, observer) {
315
316            for (let mutation of mutationsList) {
317                if (mutation.type === "childList") {
318                    if ($(".favorites")[0].childElementCount < 2) {
319                        $(".favorites_sort").hide();
320                    }
321                }
322            }
323        };
324
325        const observer = new MutationObserver(callback);
326        observer.observe(target, config);
327    }
328
329});
330
331// /Задача № 28119
332
333// Задача 31045
334$(document).ready(function() {
335    if ($('.card-detail').length) {
336        $('body').addClass('catalog-detail-b24');
337    }
338});
339// /Задача 31045
340
341

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.