PageSourceSearch

https://incanto.eu/local/templates/main/js/js_module/reviews.js?17884178208764

js incanto.eu collected 2026-09-29 11:31:19 UTC 8,764 bytes, 279 lines download raw bytes

1'use strict';
2
3$(function () {
4    Reviews.init();
5});
6
7let Reviews = {
8    isAuth: false,
9    navNextPage: 2,
10    ajaxPathNew: '/local/ajax/add_new_review_form.php',
11    ajaxAddRev: '/local/ajax/add_new_review.php',
12    ajaxPathMore: '/local/ajax/getReviews.php',
13    btnNewReviewSelector: '.js-new-review',
14    reviewFormSelector: '.js-popup-new-review',
15    prettyScrollSelector: '.js-pretty-scroll',
16    showMoreSelector: '.js-show-more-reviews',
17    reviewFormId: 'js-popup-new-review',
18    reviewBlock: '#js-reviews-block',
19    pushTopDataSelector: '.js-push-html-top',
20    pushTopSelector: '#js-reviews-res',
21    reviewsContainerSelector: '#js-reviews-content',
22    startValSelector: '.js-ow-review-vote',
23    startSelector: '.js-ow-reviews-star',
24    formAddRevSelector: '.js-form-add-reviews',
25    revProductId: false,
26    setStart: false,
27
28    init: function () {
29        this.setProductId();
30        this.pushTopStarsHandler()
31        this.checkAuth()
32        this.addReviewHandler()
33        this.showAutoPopup()
34        this.prettyScrollHandler()
35        this.showMoreHandler()
36        this.customHandlers()
37    },
38    pushTopStarsHandler: function () {
39        let data = eval($(this.pushTopDataSelector).data('json'));
40        if (data.html !== undefined)
41            $(this.pushTopSelector).html(data.html)
42        else
43            console.error('Отызывы: Ошибка дублирования блока')
44    },
45    setProductId: function(){
46        this.revProductId = $(this.btnNewReviewSelector).data('id');
47    },
48    checkAuth: function () {
49        return this.isAuth = window.OW.baseUserInfo.IS_AUTHORIZE === true;
50    },
51    showAutoPopup: function(){
52        if(!this.isAuth) return false;
53
54        let needShow = BX.getCookie('authCookie');
55        if(needShow === 'Y')
56        {
57            let _th = this;
58            setTimeout( function(){
59                $(_th.btnNewReviewSelector).trigger('click')
60                BX.setCookie('authCookie', 'Y', {path: location.pathname, expires: -1})
61            }, 2000)
62
63        }
64    },
65    addReviewHandler: function () {
66        let _th = this;
67        $(this.btnNewReviewSelector).off('click');
68        $(this.btnNewReviewSelector).on('click', function (e) {
69            if (_th.isAuth) {
70                let productId = e.currentTarget.dataset.id;
71                _th.addNewReview(productId)
72            } else {
73                _th.openAuthForm()
74            }
75        });
76    },
77    addNewReview: function (productId) {
78
79        if (!this.isAuth)
80            return false;
81
82        let _th = this;
83        let params = {
84            id: productId,
85            OW_SITE_LOCALE: 'ru'
86        };
87        _site.ajax({
88            url: _th.ajaxPathNew,
89            data: params,
90            type: 'post',
91            dataType: 'json',
92            success: response => {
93                _site.ajaxProcess = false;
94                if (response.result === true) {
95
96                    $(_th.reviewFormSelector).html(response.html);
97                    _site.popupOpen(_th.reviewFormId)
98                    _th.submitRevFormHandler();
99
100                } else {
101                    console.log(response)
102                }
103            },
104            error: (a, b, c) => {
105                console.error(b, c)
106            },
107            complete: () => {
108                _site.ajaxProcess = false
109            },
110        })
111    },
112    openAuthForm: function () {
113        BX.setCookie('authCookie', 'Y', {path: location.pathname, expires: 300, SameSite:'Lax'})
114        _site.popupOpen('js-auth-popup')
115    },
116    showMoreHandler: function(){
117        let _th = this;
118        $(this.showMoreSelector).off('click')
119        $(this.showMoreSelector).on('click', function(e){
120            e.preventDefault()
121            _th.showMore()
122        })
123    },
124    showMore: function (){
125        let _th = this;
126
127        let data = {
128            "PAGEN_1": this.navNextPage,
129            "PRODUCT_ID": this.revProductId,
130            "ajax_reviews_call": "Y"
131        }
132
133        console.log(data)
134        _site.ajax({
135            url: _th.ajaxPathMore,
136            data: data,
137            type: 'post',
138            dataType: 'json',
139            success: response => {
140                _site.ajaxProcess = false;
141                if(response.pagen.maxPage > _th.navNextPage)
142                    _th.navNextPage++;
143                else
144                    $(_th.showMoreSelector).parents('.pag').remove();
145
146                $(response.html).appendTo(_th.reviewsContainerSelector);
147            },
148            error: (a, b, c) => {
149                console.error(b, c)
150            },
151            complete: () => {
152                _site.ajaxProcess = false
153            },
154        })
155    },
156    prettyScrollHandler: function(){
157        let _th = this;
158        $(this.prettyScrollSelector).off('click');
159        $(this.prettyScrollSelector).on('click', function(e){
160            e.preventDefault();
161            $('html,body').animate({
162                scrollTop: $(_th.reviewBlock).offset().top
163            }, 900);
164        });
165    },
166    customHandlers: function(){
167        $('.popup .js-default-scroll').on('scroll', function () {
168            let date = document.querySelector('[name=date]');
169
170            if (typeof date !== 'undefined' && date !== null) {
171                pickmeup('[name="date"]').hide();
172            }
173        });
174    },
175    setStar: function(dom){
176        if(this.setStart) return;
177
178        let countActive = $(dom).index() + 1;
179        $(this.startValSelector).val(countActive);
180
181        this.setStart = true;
182    },
183    hoverStar: function(dom){
184
185        if(this.setStart) return;
186
187        let countActive = $(dom).index();
188        let parent = $(dom).parent();
189        let starsAll = parent.find(this.startSelector);
190
191        for(let i=0; i < starsAll.length; i++) {
192            if(i <= countActive)
193                $(starsAll[i]).addClass('is-active');
194            else
195                $(starsAll[i]).removeClass('is-active');
196        }
197    },
198    unHoverStar: function(dom){
199
200        if(this.setStart) return;
201        let parent = $(dom).parent();
202        let starsAll = parent.find(this.startSelector);
203
204        for(let i=0; i < starsAll.length; i++) {
205            $(starsAll[i]).removeClass('is-active');
206        }
207    },
208    submitRevFormHandler: function(e){
209
210        if($(this.formAddRevSelector).hasClass('js-init-form') === false) {
211
212            $(this.formAddRevSelector).attr('novalidate', 'novalidate').addClass('js-init-form');
213            let _th = this;
214            $(this.formAddRevSelector).off('submit')
215            $(this.formAddRevSelector).on('submit', function (event) {
216                event.preventDefault()
217
218                let req = $(this).find('input:required, textarea:required')
219                let requiredSuccess = true;
220
221                for(let i= 0; i < req.length; i++)
222                {
223                    let valItem = req[i].value.toString();
224                    if(valItem.length <= 3) {
225                        req[i].classList.add('error')
226                        requiredSuccess = false;
227                    }
228                }
229
230                if(requiredSuccess)
231                    _th.submitRevForm(event)
232            })
233        }
234    },
235    submitRevForm: function(event){
236        let _th = this;
237        let data = $(this.formAddRevSelector).serialize()
238            data += '&city=' + BX.getCookie('userCityName');
239
240        let dataArray = $(this.formAddRevSelector).serializeArray();
241
242        _site.ajax({
243            url: _th.ajaxAddRev,
244            data: data,
245            type: "post",
246            dataType: "json",
247            success: response => {
248                if(response.result === true) {
249
250                    let params = {};
251                    dataArray.forEach(e => {
252                        if (BX.util.in_array(e.name, ['name', 'email'])) {
253                            params[e.name] = e.value;
254                        }
255                    });
256                    _site?.YM.firstPartyParams({
257                        'first_name': params.name,
258                        'email': params.email
259                    });
260
261                    window.dataLayer = window.dataLayer || [];
262                    window.dataLayer.push({'event': 'write_review'})
263                    _th.closePopup();
264                    _site.showNotice(true, response.title)
265                }
266                else if(response.title) {
267                    _site.showError(true, response.title)
268                }
269            }
270        })
271    },
272    closePopup: function(){
273
274        if($(this.reviewFormSelector).hasClass('is-open') === true)
275            $(this.reviewFormSelector).removeClass('is-open')
276
277        $('body,html').removeClass('is-stunned');
278    }
279}

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.