PageSourceSearch

https://www.mirkrasok.ru/local/templates/mirkrasok_2026v2/components/mk/reviews.add/.default/script.js

js mirkrasok.ru collected 2026-10-03 20:59:40 UTC 7,332 bytes, 229 lines download raw bytes

1$(() => {
2    let starsCount = $('.star.active').length;
3    let star = $('.rev-form__flex .rev-rat__item');
4    let cStars = function (nowPos) {
5
6        // У всех убираем active
7        star.removeClass('active');
8
9        for (var i = 0; nowPos + 1 > i; i++) {
10            star.eq(i).toggleClass('active');
11        }
12
13        $('#star_rating').val(nowPos + 1)
14    }
15
16    // При наведении
17    /*star.hover(function () {
18        cStars($(this).index());
19    });*/
20
21    // При клике
22    star.click(function () {
23        cStars($(this).index());
24        // меняем количество по клику
25        starsCount = $('.star.active').length;
26    });
27
28    // Как только отводим мышку, возвращаем количество активных айтемов, которые были изначально
29    /*star.on('mouseleave', function () {
30        cStars(+starsCount - 1);
31    });*/
32
33    const shopList = $('.shop_list');
34
35    if (shopList.length > 0) {
36        $('.shop_list').select2({
37            placeholder: "Выберите магазин",
38        });
39        $(".shop_list").select2("val", "");
40    }
41
42
43    let fileInput = $('#input-file');
44    let fileList = $('#file-list');
45
46    // Обработчик изменения input[type="file"]
47    fileInput.on('change', function () {
48        // Получаем список выбранных файлов
49        let files = fileInput.get(0).files;
50
51        // Создаем список файлов в HTML-формате
52        let html = '';
53        for (let i = 0; i < files.length; i++) {
54            html += `<div class="file">${files[i].name} <button class="remove-file" data-index="${i}">x</button></div>`;
55        }
56
57        // Добавляем список файлов в div
58        fileList.html(html);
59
60        // Обработчики для кнопок удаления файлов
61        let removeButtons = $('.remove-file');
62        removeButtons.on('click', function () {
63            let index = $(this).data('index');
64            removeFile(files, index);
65        });
66    });
67
68    // Функция для удаления файла из списка файлов
69    function removeFile(files, index) {
70        let arr = Array.from(files);
71        arr.splice(index, 1);
72
73        let dataTransfer = new DataTransfer();
74
75        arr.forEach(file => {
76            dataTransfer.items.add(file);
77        });
78
79        fileInput.get(0).files = dataTransfer.files;
80
81        fileInput.trigger('change');
82    }
83
84    $(document).on('click', '[data-js="trigger_file"]', function (e) {
85        e.preventDefault();
86        fileInput.trigger('click');
87    })
88
89    $(document).on('submit', '[name="iblock_add"]', function (e) {
90        e.preventDefault();
91
92        let formData = new FormData(this);
93        let _this = $(this);
94        _this.block({center: true});
95        BX.ajax.runComponentAction('mk:reviews.add', 'send', {
96            mode: "class",
97            data: formData,
98            dataType: 'json',
99        }).then(function (response) {
100            _this.unblock();
101            if (response.status === 'success') {
102                //$('[name="iblock_apply"]').attr('disabled', true);
103			var ee = setInterval(function () {
104				if (typeof window.ym != 'undefined') {
105					ym(7500958, 'reachGoal', 'form_success_feedback');
106					clearInterval(ee);
107				} else {
108					console.log('Метрика не инициализирована');
109				}
110			}, 500);
111                $('.rev-form__tit')
112                    .text('Отзыв будет опубликован после модерации')
113                    .addClass('added')
114                    .removeClass('error')
115            }
116        }, function (response) {
117            _this.unblock();
118            if (response.errors) {
119                let errorText = '';
120
121                response.errors.forEach(function (error) {
122                    errorText += error.message.replace(/<\/?[a-zA-Z]+>/gi, '') + '\n';
123                });
124
125                $('.rev-form__tit')
126                    .text(errorText)
127                    .addClass('error')
128                    .removeClass('added')
129            }
130        });
131    })
132
133    $(document).on('click', '.rev-form__close', function () {
134        $(this).closest('[data-block="rev-form"]').css('display', 'none');
135        $('[data-js="show-form"]').show();
136    })
137
138    $(document).on('click', '[data-js="show-form"]', function () {
139        $('[data-block="rev-form"]').css('display', 'block');
140        $(this).hide();
141    })
142
143
144    const productInfo = $('#product-info');
145    const inputProductID = $('[name="PRODUCT_ID"]');
146
147    function clearInput($node) {
148        let textInput = 'Товар (укажите код)'
149        $node
150            .attr('placeholder', textInput)
151            .attr('title', textInput)
152            .val('')
153            .removeClass('active')
154    }
155
156    $(document).on('keyup', '[name="FIND_PRODUCT"]', function () {
157        let _this = $(this),
158            code = _this.val();
159
160        if (code.length > 3) {
161            BX.ajax.runComponentAction('mk:reviews.add', 'getProduct', {
162                mode: "class",
163                data: {
164                    code: code
165                },
166                dataType: 'json',
167            }).then(function (response) {
168                if (response.status === 'success') {
169                    let data = response.data;
170                    productInfo.html(`
171                        <div data-js="select-product" data-id="${data.ID}">
172                            <img src="${data.PREVIEW_PICTURE}" alt="">
173                            <div class="title">${data.NAME}</div>
174                        </div>
175                    `);
176
177                    /*$('[name="PRODUCT_ID"]').val(data.ID);
178                    _this.attr('title', data.NAME);*/
179                }
180
181
182            }, function (response) {
183                let errorText = '';
184                inputProductID.val();
185                response.errors.forEach(function (error) {
186                    errorText += error.message.replace(/<\/?[a-zA-Z]+>/gi, '') + '\n';
187                });
188                productInfo.html(`
189                    <div>
190                        <div class="title error">${errorText}</div>
191                    </div>
192                `);
193            });
194        } else {
195            productInfo.empty();
196            inputProductID.val();
197        }
198    });
199
200
201
202    $(document).on('click', '[data-js="select-product"]', function () {
203        let _this = $(this);
204
205        inputProductID.val(_this.data('id'));
206        $('[name="FIND_PRODUCT"]')
207            .attr('placeholder', _this.find('div.title').text())
208            .attr('title', _this.find('div.title').text())
209            .val('')
210            .addClass('active')
211
212        /*$("[data-title]").tooltipster({
213            animation: 'fade',
214            delay: 100,
215            theme: 'tooltipster-light',
216            touchDevices: false,
217            trigger: 'hover'
218        });*/
219    });
220
221    $(document).on('click', '.js-del', () => {
222        //$("[data-title]").tooltipster('destroy');
223        clearInput( $('[name="FIND_PRODUCT"]'));
224        inputProductID.val('');
225        productInfo.empty();
226    });
227
228    $(`[data-js="phone-mask"]`).mask("+7 (999) 999-99-99");
229})

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.