PageSourceSearch

https://www.pinglighting.com/modules/ets_reviews/views/js/list-comments.js

js pinglighting.com collected 2026-10-06 18:27:40 UTC 39,450 bytes, 663 lines download raw bytes

1/**
2 * Copyright ETS Software Technology Co., Ltd
3 *
4 * NOTICE OF LICENSE
5 *
6 * This file is not open source! Each license that you purchased is only available for 1 website only.
7 * If you want to use this file on more websites (or projects), you need to purchase additional licenses.
8 * You are not allowed to redistribute, resell, lease, license, sub-license or offer our resources to any third party.
9 *
10 * DISCLAIMER
11 *
12 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
13 * versions in the future.
14 *
15 * @author ETS Software Technology Co., Ltd
16 * @copyright  ETS Software Technology Co., Ltd
17 * @license    Valid for 1 website (or project) for each purchase of license
18 */
19var commonPCETS = {
20    clearPostForm: function (form) {
21        form.find('input[type="text"]').val('').removeClass('valid error');
22        form.find('textarea').val('').removeClass('valid error');
23        form.find('.criterion-item').removeClass('valid error');
24        if (form.find('.criterion-rating .ets-rv-grade-stars').length > 0) {
25            form.find('.criterion-rating input').val(parseInt(form.find('.criterion-rating .ets-rv-grade-stars').data('grade'))).change();
26        }
27        form.find('input[type=file]').val('');
28        form.find('.ets_rv_upload_photo_wrap').css('background-image', '').attr('title', '').removeClass('selected').parents('.cm_img_uploaded').removeClass('cm_img_uploaded');
29        form.find('.ets_rv_upload_video_wrap').removeClass('selected').parents('.cms_has_video').removeClass('cms_has_video');
30        form.find('.ets_rv_upload_video_wrap').find('.ets_rv_video').html('');
31        form.find('.ets_rv_upload_video_wrap').find('.ets_rv_btn_delete_video').removeAttr('data-product-comment-video-id');
32        form.find('.ets_rv_upload_video_wrap').find('.ets_rv_btn_delete_video').removeAttr('data-product-comment-id');
33        form.find('.ets_rv_error').hide();
34        $('.post-comment-buttons button, .post-question-buttons button').removeClass('active');
35        form.find('input[name=id_product_comment]').val(0);
36        if (form.hasClass('.g-loaded'))
37            reCaptchaETS.reset(form);
38    },
39    showPostedModal: function (prop, message) {
40        $('#ets-rv-post-product-' + prop + '-modal').ETSModal('hide').removeClass('edit');
41        $('#ets-rv-product-' + prop + '-post-error').ETSModal('hide');
42        commonPCETS.clearPostForm($('#ets-rv-post-product-' + prop + '-form'));
43        if (message)
44            $('#ets-rv-product-' + prop + '-posted-modal-message').html(message);
45        $('#ets-rv-product-' + prop + '-posted-modal').ETSModal('show');
46    },
47    showVoucherModal: function (message) {
48        if (message) {
49            $('#general-voucher-modal-message').html(message);
50        }
51        $('#ets-rv-post-product-comment-modal').ETSModal('hide');
52        $('#ets-rv-product-comment-post-error').ETSModal('hide');
53        $('#general-voucher-modal').ETSModal('show');
54    },
55    validateFormData: function (formData, form) {
56        var isValid = true,
57            focus = false,
58            prop = form.data('type')
59        ;
60        formData.forEach(function (formField) {
61            var fieldSelector = form.find('[name="' + formField.name + '"]'),
62                isRating = formField.name.match(/criterion\[\d+\]/);
63            if (isRating)
64                fieldSelector = $(fieldSelector).parents('.criterion-item');
65            if ((!formField.value || isRating && parseInt(formField.value) <= 0 && $(fieldSelector).parents('.ets-pc-criterion.active').length > 0) && (ETS_RV_REQUIRE_TITLE || prop === 'question' || formField.name !== 'comment_title')) {
66                $(fieldSelector).addClass('error');
67                isValid = false;
68                if (!focus) {
69                    focus = true;
70                    $(fieldSelector).focus();
71                }
72            } else {
73                $(fieldSelector).removeClass('error');
74            }
75        });
76        return isValid;
77    },
78    submit: function (prop) {
79        $('#ets-rv-post-product-' + prop + '-form').submit(function (event) {
80            event.preventDefault();
81            var form = $(this),
82                prop = form.attr('id').indexOf('question') !== -1 ? 'question' : 'comment',
83                reCAPTCHA = form.find('.g-recaptcha'),
84                id_product_comment = parseInt(form.find('input[name=id_product_comment]').val()),
85                btn = form.find('.ets-rv-btn-' + prop)
86            ;
87            form.find('.ets_rv_error').hide();
88            if (!ETS_RV_RECAPTCHA_VALID && reCAPTCHA.length > 0) {
89                reCAPTCHA.addClass('error');
90            } else if (ETS_RV_RECAPTCHA_VALID && reCAPTCHA.hasClass('error')) {
91                reCAPTCHA.removeClass('error');
92            }
93            if (!commonPCETS.validateFormData(form.serializeArray(), form)) {
94                return;
95            }
96            var formData = new FormData(form.get(0));
97            if (form.find('input[type="file"]').length > 0 && funcPCETS.isSafari()) {
98                form.find('input[type="file"]').each(function () {
99                    if (document.getElementById($(this).attr('id')).files.length === 0) {
100                        formData.delete($(this).attr('id'));
101                    }
102                });
103            }
104            var post_url = form.attr('action');
105            if (!btn.hasClass('active') && post_url) {
106                btn.addClass('active');
107                $.ajax({
108                    url: post_url,
109                    type: 'POST',
110                    data: formData,
111                    contentType: false,
112                    processData: false,
113                    dataType: 'json',
114                    success: function (jsonData) {
115                        form.find('.ets-rv-btn-comment').removeClass('active');
116                        if (jsonData) {
117                            if (jsonData.success) {
118                                commonPCETS.showPostedModal(prop, jsonData.msg ? jsonData.msg : '');
119                                if (typeof ETS_RV_ADDED_PRODUCT_COMMENT !== "undefined") {
120                                    ETS_RV_ADDED_PRODUCT_COMMENT = true;
121                                }
122                                if (jsonData.product_comment) {
123                                    var result = jsonData.product_comment;
124                                    if (id_product_comment > 0) {
125                                        const $productComment = $('.ets-rv-product-comment-list-item[data-product-comment-id=' + result.id_ets_rv_product_comment + ']');
126                                        const $comment_title = $('.ets-rv-product-comment-title-html', $productComment);
127                                        $comment_title.html(result.title);
128                                        if (!result.title)
129                                            $comment_title.hide();
130                                        else
131                                            $comment_title.show();
132                                        $('.product-comment-content-html', $productComment).html(funcPCETS.n2br(result.content));
133
134                                        if (prop !== 'question') {
135                                            $('.product-comment-image-html', $productComment).html(result.images);
136                                            $('.product-comment-video-html', $productComment).html(result.videos);
137                                            $('.ets_rv_grade_stars', $productComment).attr('data-grade', result.grade.toFixed(1));
138                                            if (parseFloat(result.grade) > 0) {
139                                                $('.ets_rv_grade_stars', $productComment).show();
140                                            } else
141                                                $('.ets_rv_grade_stars', $productComment).hide();
142                                            $('.ets_rv_average_grade_item', $productComment).html(result.grade.toFixed(1));
143                                            if (result.criterion.length > 1) {
144                                                var popover = '';
145                                                result.criterion.forEach(function (item) {
146                                                    popover += '<li class="criterion-item"><span class="criterion-name">' + item.name + ':</span><span class="ets_rv_grade_stars' + (ETS_RV_DESIGN_COLOR1 ? ' color1' : '') + '" data-grade="' + item.grade + '" data-rate-empty="☆☆☆☆☆" data-rate-full="★★★★★"></span> <span class="criterion-grade">(' + item.grade + ')</span></li>';
147                                                });
148                                                if (popover) {
149                                                    $('.popover_wrap', $productComment).length > 0 ? $('.popover_wrap', $productComment).html(popover) : $('.ets_rv_grade_stars', $productComment).append('<ul class="popover_wrap">' + popover + '</ul>');
150                                                }
151                                            }
152                                        }
153                                        if (result.upd_date) {
154                                            $('.review-date-upd', $productComment).show().find('.review-upd-date').html(result.upd_date);
155                                        }
156                                        $('.review-date-add', $productComment).html(result.time_elapsed);
157                                        if (result.customer_name)
158                                            $('.ets-rv-comment-author-name', $productC
158omment).html(result.customer_name);
159                                    } else {
160                                        productCommentsETS.add(result, true);
161                                        if (parseFloat(result.grade) > 0) {
162                                            productCommentsETS.updateCriterion('add', result.nb_rate);
163                                        }
164                                        //sua:
165                                        if (prop !== 'question') {
166                                            if (result.review_allowed) {
167                                                $('#ets-rv-post-product-comment-form').removeClass('hide');
168                                                $('.ets_rv_review_error').addClass('hide');
169                                            } else {
170                                                $('#ets-rv-post-product-comment-form').addClass('hide');
171                                                $('.ets_rv_review_error').removeClass('hide');
172                                            }
173                                        }
174                                        if (result.id_product && result.id_order) {
175                                            let btn = $('a.ets_rv_product_id[data-id-product=' + result.id_product + '][data-id-order=' + result.id_order + ']');
176                                            if (btn.length > 0) {
177                                                btn.parents('tr').remove();
178                                            }
179                                        }
180                                        $('.ets_rv_wrap').show();
181                                        $('.ets-rv-product-comments-additional-info .ets-rv-btn-comment').addClass('ets-rv-hidden');
182                                    }
183                                    $('.ets_rv_tab.active:not(.ets_rv_waiting_for_review), .ets_rv_tab_content.active').removeClass('active');
184                                    $('.ets_rv_tab[data-tab-id=ets-rv-product-' + prop + 's-list]').show().addClass('active');
185                                    $('#ets-rv-product-' + prop + 's-list').addClass('active');
186
187                                    if ($('#ets-rv-product-' + prop + 's-list .ets-rv-product-comment-list-item').length > 0) $('#ets-rv-product-' + prop + 's-list #product-comments-list-footer .ets-rv-' + prop + '.empty').hide();
188                                }
189                                if (jsonData.stats) {
190                                    funcPCETS.stats(jsonData.stats, prop);
191                                    // Change stats and rating:
192                                    var stats = jsonData.stats;
193                                    if (prop === 'comment' && !$('.ets_rv_stats_review, .ets_rv_tab_reviews').is(':visible') && parseFloat(stats.average_grade) > 0 && parseInt(stats.nb_reviews) > 0) {
194                                        $('.ets_rv_tab_reviews:hidden').show().removeClass('ets_rv_hide');
195                                        $('.ets_rv_stats_review:hidden').show().removeClass('ets_rv_hide').next('.ets_rv_modal_review.center').removeClass('center');
196                                    } else if (prop === 'question' && !$('.ets_rv_tab_questions').is(':visible') && parseInt(stats.nb_questions) > 0) {
197                                        $('.ets_rv_tab_questions:hidden').show();
198                                    }
199                                    $('.ets_rv_wrap:hidden').show();
200                                    // End:
201                                    $('.ets-rv-product-comments-additional-info .ets-rv-btn-read-user .ets_rv_grade_stars').attr('data-grade', jsonData.stats.average_grade.toFixed(1));
202                                    $('.ets-rv-product-comments-additional-info .ets-rv-btn-read-user .ets_rv_grade_stars .ets-rv-comments-nb').text('(' + jsonData.stats.nb_reviews + ')');
203                                    if (parseFloat(jsonData.stats.average_grade) > 0)
204                                        $('.ets-rv-product-comments-additional-info .ets-rv-btn-read-user').removeClass('ets-rv-hidden');
205                                    else
206                                        $('.ets-rv-product-comments-additional-info .ets-rv-btn-read-user').addClass('ets-rv-hidden');
207                                }
208                                if (jsonData.voucher) {
209                                    commonPCETS.showVoucherModal(jsonData.voucher);
210                                }
211                                if (jsonData.photos) {
212                                    productCommentsETS.initSlider(jsonData.photos);
213                                }
214                                if (prop === 'question')
215                                    $('.ets_rv_review_photos_wrap').removeClass('active');
216                                else
217                                    $('.ets_rv_review_photos_wrap').addClass('active');
218                            } else {
219                                if (jsonData.errors) {
220                                    var errorList = '<ul>';
221                                    for (var i = 0; i < jsonData.errors.length; ++i) {
222                                        errorList += '<li>' + jsonData.errors[i] + '</li>';
223                                    }
224                                    errorList += '</ul>';
225                                    commonPCETS.showPostErrorModal(errorList, prop);
226                                } else {
227                                    const decodedErrorMessage = $("<div/>").html(jsonData.error).html();
228                                    commonPCETS.showPostErrorModal(decodedErrorMessage, prop);
229                                }
230                            }
231                        } else {
232                            commonPCETS.showPostErrorModal(productCommentPostErrorMessage, prop);
233                        }
234                    },
235                    error: function (jqXHR, textStatus, errorThrown) {
236                        form.find('.ets-rv-btn-comment').removeClass('active');
237                        commonPCETS.showPostErrorModal(productCommentPostErrorMessage, prop);
238                        if (jqXHR.responseText)
239                            console.log(jqXHR.responseText, textStatus, errorThrown);
240                    }
241                });
242            }
243            return false;
244        });
245    },
246    showPostErrorModal: function (errorMessage, prop) {
247        var prop = prop || 'comment', _error = $('#ets-rv-post-product-' + prop + '-form .ets_rv_error');
248        if (_error.length < 1)
249            $('.ets-rv-post_content_footer_modal').before('<div class="bootstrap"><div class="ets_rv_error alert alert-danger"></div></div>');
250        $('#ets-rv-post-product-' + prop + '-form .ets_rv_error').html(errorMessage).show();
251        reCaptchaETS.reset($('#ets-rv-post-product-' + prop + '-form.g-loaded'));
252        $('.post-comment-buttons button, .post-question-buttons button').removeClass('active');
253    },
254    ensurePostModal: function (prop, callback) {
255        var postModal = $('#ets-rv-post-product-' + prop + '-modal');
256        if (postModal.length > 0) {
257            callback();
258            return;
259        }
260        var requestUrl = $('.ets_rv_wrap').data('comment-url') || $('#ets-rv-product-' + prop + 's-list').data('comments-url');
261        if (!requestUrl) {
262            return;
263        }
264        $.ajax({
265            url: requestUrl,
266            type: 'POST',
267            data: 'ajax=1&action=renderTemplateModal&currentUrl=' + encodeURIComponent(window.location.href),
268            dataType: 'json',
269            success: function (json) {
270                if (json && json.html) {
271                    var decodedHtml = funcPCETS.decodeHTMLEntities(json.html);
272                    if ($('.ets_rv_form.ets_rv_modal').length > 0) {
273                        $('.ets_rv_form.ets_rv_modal').replaceWith(decodedHtml);
274                    } else {
275                        $('body').append(decodedHtml);
276                    }
277                    commonPCETS.initForm(prop);
278                }
279                callback();
280            },
281            error: function () {
282                callback();
283            }
284        });
285    },
286    showPostModal: function (prop, action) {
287        var self = this;
288        prop = prop || 'comment';
289        commonPCETS.ensurePostModal(prop, function () {
290            var form = $('#ets-rv-post-product-' + prop + '-form'),
291                postModal = $('#ets-rv-post-product-' + prop + '-modal')
292            ;
293            if (form.length < 1 || postModal.length < 1) {
294                return;
295            }
296            $('#ets-rv-post-product-' + prop + '-form .ets_rv_error').remove();
297            $('#ets-rv-post-product-' + prop + '-form .ets-rv-modal-header h2, #ets-rv-post-product-' + prop + '-form button.btn-' + prop + ' span.title').html(function () {
298                return $(this).data(action + '-title');
299            });
300            $('#ets-rv-product-' + prop + '-posted-modal').ETSModal('hide');
301            $('#ets-rv-product-' + prop + '-post-error').ETSModal('hide');
302            postModal.ETSModal('show');
303            if (action === 'edit') {
304                postModal.addClass('edit');
305            } else
306                postModal.removeClass('edit');
307            $('.ets_rv_upload_photos .ets_rv_upload_photo_item:not(:first)', form).remove();
308            if (!form.hasClass('g-loaded')) {
309                reCaptchaETS.onLoad(form);
310            } else {
311                reCaptchaETS.reset(form);
312            }
313            self.initRate(prop);
314            if (action === 'add') {
315                self.setDefaultRate(prop, 5);
316            }
317        });
318    },
319    setDefaultRate: function (prop, grade) {
320        if (prop === 'question') {
321            return;
322        }
323        var ratingGrade = parseInt(grade, 10) || 5;
324        var form = $('#ets-rv-post-product-' + prop + '-form');
325        $('.criterion-item:not(.template) .ets-rv-grade-stars', form).each(function () {
326            $(this).attr('data-grade', ratingGrade).etsRating({grade: ratingGrade});
327        });
328        $('.criterion-item:not(.template) .criterion-rating input', form).val(ratingGrade).change();
329    },
330    filter: function (ele, sortBy, grade, prop) {
331        const commentsList = $('#ets-rv-product-' + prop + 's-list');
332        if (!ele.hasClass('loading') && commentsList.data('comments-url') !== '') {
333            ele.addClass('loading');
334            $.ajax({
335                url: commentsList.data('comments-url'),
336                type: 'POST',
337                data: '__ac=list_product_comment&sort_by=' + sortBy.data('sort') + (prop !== 'question' ? '&grade=' + grade.data('grade') : ''),
338                dataType: 'json',
339                success: function (json) {
340                    ele.removeClass('loading');
341                    if (json) {
342                        productCommentsETS.populate(json.comments, prop);
343                        var btn = $('.ets_rv_product_comment_load_more', commentsList);
344                        const rest = parseInt(json.reviews_nb) - parseInt(json.begin);
345                        if (parseInt(json.begin) >= parseInt(json.reviews_nb) || parseInt(json.reviews_per_page) <= 0)
346                            btn.hide();
347                        else if (json.success) {
348                            btn.show().attr({
349                                'data-begin': json.begin,
350                                'data-reviews-per-page': json.reviews_per_page,
351                                'data-rest': rest,
352                            });
353                            if (parseInt(rest) > parseInt(json.reviews_per_page)) {
354                                btn.html(function () {
355                                    return (rest > 1 ? $(this).data('multi-text-rest') : $(this).data('text-rest')).replace(/%1s/g, json.reviews_per_page).replace(/%2s/g, rest);
356                                });
357                            } else {
358                                btn.html(function () {
359                                    return (rest > 1 ? $(this).data('multi-text') : $(this).data('text')).replace(/%1s/g, rest);
360                                });
361                            }
362                        }
363                    }
364                },
365                error: function () {
366                    ele.removeClass('loading');
367                }
368            });
369        }
370    },
371    tabFilter: function (el) {
372        var currentUrl = window.location.href,
373            matches = currentUrl.match(/\#(.+)$/i),
374            selectedTab = $('.ets_rv_filter .ets_rv_tab').first(),
375            tabCollection = ['review', 'question']
376        ;
377        if (matches !== null && typeof matches[1] !== "undefined" && tabCollection.indexOf(matches[1]) !== -1) {
378            selectedTab = $('.ets_rv_filter .ets_rv_tab_' + matches[1] + 's');
379        }
380        var choiceTab = el || selectedTab;
381        if (!choiceTab.is(':visible')) {
382            choiceTab = $('.ets_rv_filter .ets_rv_tab:visible').eq(0);
383        }
384        $('.ets_rv_filter .ets_rv_tab.active, .ets_rv_tabs .ets_rv_tab_content').removeClass('active');
385        choiceTab.addClass('active');
386        $('#' + choiceTab.data('tab-id')).addClass('active');
387        $('.ets_rv_tab:not(.active) .ets_rv_selection').html(function () {
388            return $(this).attr('data-default');
389        });
390        if (choiceTab.hasClass('ets_rv_tab_questions')) {
391            $('.ets_rv_sort_by.question').addClass('active');
392            $('.ets_rv_sort_by.review').removeClass('active');
393            $('.ets_rv_review_photos_wrap').removeClass('active');
394        } else {
395            $('.ets_rv_sort_by.review').addClass('active');
396            $('.ets_rv_sort_by.question').removeClass('active');
397            $('.ets_rv_review_photos_wrap').addClass('active');
398        }
399    },
400    initRate: function (prop) {
401        if (prop !== 'question') {
402            productCommentsETS.updateCriterion();
403            $('#ets-rv-post-product-' + prop + '-modal .criterion-item.custom').remove();
404            $('#ets-rv-post-product-' + prop + '-modal .criterion-item:not(.template) .ets-rv-grade-stars').etsRating();
405        }
406    },
407    initModal: function (prop) {
408        this.initRate(prop);
409        commonPCETS.submit(prop);
410    },
411    initForm: function (prop) {
412        $('#ets-rv-post-product-' + prop + '-modal').on('hidden.bs.ets-rv-modal', function () {
413            $('.ets_rv_form.ets_rv_modal #ets-rv-post-product-' + prop + '-modal').remove();
414            commonPCETS.clearPostForm($('#ets-rv-post-product-' + prop + '-form'));
415        }).ETSModal('hide');
416
417        commonPCETS.initModal(prop);
418    },
419    init: function (prop) {
420        if (!ETS_RV_REVIEW_ENABLED && prop === 'comment' || !ETS_RV_QUESTION_ENABLED && prop === 'question')
421            return;
422        commonPCETS.initForm(prop);
423        productCommentsETS.paginate({page: 1}, prop);
424    },
425    initialize: function () {
426        if ($('body#product').length > 0) {
427            var bootstrapReviews = function () {
428                ['comment', 'question'].forEach(commonPCETS.init);
429                commonPCETS.loginBack();
430            };
431            if ($('.ets_speed_dynamic_hook .ets_rv_wrap').length < 1) {
432                $.ajax({
433                    url: $('.ets_rv_wrap').data('comment-url'),
434                    type: 'POST',
435                    data: 'ajax=1&action=renderTemplateModal&currentUrl=' + encodeURIComponent(window.location.href),
436                    dataType: 'json',
437                    success: function (json) {
438                if (json) {
439                    if (json.html)
440                        $('body').append(funcPCETS.decodeHTMLEntities(json.html));
441                }
442                bootstrapReviews();
443                    },
444                    error: function () {
445                        bootstrapReviews();
446                    }
447                });
448            } else {
449                bootstrapReviews();
450            }
451            commonPCETS.tabFilter();
452        } else if ($('body#comment').length > 0 || $('body[id$=comment]').length > 0) {
453            commonPCETS.initForm('comment');
454        }
455    },
456    loginBack: function () {
457        if (!/\?back\s*=\s*http(s|):\/\//i.test(window.location.href)) {
458            var refreshURL = null;
459            if (/(\?|&)ets_rv_add_review\s*=\s*1/i.test(window.location.href) && $('button.ets-rv-post-product-comment').length > 0) {
460                refreshURL = 'review';
461            } else if (/(\?|&)ets_rv_add_question\s*=\s*1/i.test(window.location.href) && $('button.ets-rv-post-product-question').length > 0) {
462                refreshURL = 'question';
463            }
464            if (refreshURL !== null) {
465                var prop = refreshURL;
466                refreshURL = window.location.protocol + "//" + window.location.host + window.location.pathname + '#' + refreshURL;
467                window.history.pushState({path: refreshURL}, '', refreshURL);
468                if ($('a[data-tab="' + prop + '"]').length > 0)
469                    $('a[data-tab="' + prop + '"]').trigger('click');
470                commonPCETS.showPostModal((prop === 'review' ? 'comment' : 'question'), 'add');
471            }
472        }
473    }
474};
475
476$(document).ready(function () {
477
478    commonPCETS.initialize();
479
480    $(document).on('click', 'a[data-tab="review"]', function () {
481        $('.ets_rv_filter .ets_rv_tab, #ets-rv-product-comments-list, #ets-rv-product-questions-list').removeClass('active');
482        $('.ets_rv_tab.ets_rv_tab_reviews, #ets-rv-product-comments-list').addClass('active');
483    });
484
485    $(document).on('click', '.ets-rv-write-review', function () {
486        $('a[data-tab="review"]').trigger('click');
487        $('.ets-rv-post-product-comment').trigger('click');
488    });
489
490    $(document).on('click', '.ets-rv-grade-stars.ets-rv-small-stars', function () {
491        $('a[data-tab="review"]').trigger('click');
492        $('html,body').animate({
493            scrollTop: $('.tabs.ets-ept-list-tabs-more-info').offset().top - 50
494        }, 'slow');
495    });
496
497    $(document).on('click', '.ets-rv-post-product-comment, .ets-rv-write-rewrite', function (event) {
498        event.preventDefault();
499        commonPCETS.showPostModal('comment', 'add');
500    });
501
502    $(document).on('click', '.ets-rv-post-product-question, .ets-rv-ask-question', function (event) {
503        event.preventDefault();
504        commonPCETS.showPostModal('question', 'add');
505    });
506
507    $(document).on('click', '.ets_rv_ul_dropdown .ets_rv_li_dropdown', function () {
508        var ele = $(this);
509        ele.parent('.ets_rv_ul_dropdown').find('.ets_rv_li_dropdown.active').removeClass('active');
510        ele.addClass('active');
511        ele.parents('.ets_rv_bulk_actions').removeClass('open').find('.ets_rv_selection').html($(this).html());
512
513        //Filter
514        if ($('#ets-rv-product-comments-list-header li.ets_rv_sort_by.active').length > 0) {
515            commonPCETS.filter(ele, $('.ets_rv_sort_by.active .ets_rv_li_dropdown.active'), $('.ets_rv_tab_reviews .ets_rv_li_dropdown.active').length > 0 ? $('.ets_rv_tab_reviews .ets_rv_li_dropdown.active') : 0, $('.ets_rv_tab.ets_rv_tab_questions.active').length > 0 ? 'question' : 'comment');
516        }
517    });
518
519    $(document).on('click', '.ets_rv_filter .ets_rv_tab', function () {
520        var ele = $(this);
521        var prop = ele.hasClass('ets_rv_tab_reviews') ? 'review' : 'question';
522        var refresh = window.location.protocol + "//" + window.location.host + window.location.pathname + '#' + prop;
523        window.history.pushState({path: refresh}, '', refresh);
524
525        commonPCETS.tabFilter(ele);
526        if (!ele.hasClass('active') && $('.ets_rv_all_review:not(.active)').length > 0) {
527            $('.ets_rv_tab_reviews .ets_rv_li_dropdown.active').removeClass('active');
528            $('.ets_rv_all_review').addClass('active');
529            var refreshFilter = $('.ets_rv_all_review.active');
530            commonPCETS.filter(refreshFilter, $('.ets_rv_sort_by.active .ets_rv_li_dropdown.active'), refreshFilter, $('.ets_rv_tab.ets_rv_tab_questions.active').length > 0 ? 'question' : 'comment');
531        }
532
533        return false;
534    });
535
536    $(document).on('click', '.ets_rv_btn_edit.product-comment', function (ev) {
537        ev.preventDefault();
538        var ele = $(this),
539            productComment = ele.parents('.ets-rv-product-comment-list-item').eq(0),
540            commentList = productComment.parents('.ets_rv_tab_content').eq(0),
541            prop = commentList.attr('id') && commentList.attr('id') === 'ets-rv-product-questions-list' ? 'question' : 'comment',
542            form = $('#ets-rv-post-product-' + prop + '-form')
543        ;
544        if (!ele.hasClass('active') && commentList.data('comments-url')) {
545            ele.addClass('active');
546            $.ajax({
547                url: commentList.data('comments-url'),
548                type: 'post',
549                data: '__ac=list_product_comment&first=1&object=1&id_product_comment=' + productComment.data('product-comment-id') + '&id_product=' + productComment.data('product-id'),
550                dataType: 'json',
551                success: function (json) {
552                    ele.removeClass('active');
553                    if (json) {
554                        commonPCETS.showPostModal(prop, 'edit');
555                        if (json.comments) {
556                            // Guest
557                            if (parseInt(json.comments.id_guest) > 0 && json.comments.customer_name) {
558                                form.find('input[name=customer_name]').val(funcPCETS.decodeHTMLEntities(json.comments.customer_name));
559                                form.find('input[name=email]').val(funcPCETS.decodeHTMLEntities(json.comments.email));
560                            }
561                            form.find('input[name=id_product_comment]').val(json.comments.id_ets_rv_product_comment);
562                            form.find('input[name=comment_title]').val(json.comments.title);
563                            form.find('textarea[name=comment_content]').val(json.comments.content);
564                            if (prop !== 'question') {
565                                if (form.find('#criterions_list').length > 0 && json.comments.criterion.length > 0) {
566                                    form.find('.ets-pc-criterion').show();
567                                    var criterion = json.comments.criterion;
568                                    // Reset rateValue:
569                                    $('.criterion-item:not(.template) .ets-rv-grade-stars[data-input^=criterion]', form).etsRating({grade: 0});
570                                    // Load rateValue:
571                                    criterion.forEach(function (item, index) {
572                                        var rating = $('.ets-rv-grade-stars[data-input="criterion[' + item.id_ets_rv_product_comment_criterion + ']"]', form);
573                                        if (rating.length > 0) {
574                                            rating.etsRating({grade: parseInt(item.grade)});
575                                        } else {
576                                            var initRate = $('.criterion-item.template', form).clone();
577                                            initRate.removeClass('template').addClass('custom');
578                                            initRate.find('label').html(item.name);
579                                            if (initRate.find('p.desc_error').length > 0)
580                                                initRate.find('p.desc_error').html(initRate.find('p.desc_error').html().replace(/%s/g, item.name));
581                                            initRate.find('.ets-rv-grade-stars').attr({
582                                                'data-grade': item.grade,
583                                                'data-input': 'criterion[' + item.id_ets_rv_product_comment_criterion + ']'
584                                            });
585                                            $('.criterion-item:eq(' + index + ')', form).before(initRate);
586                                            $('.ets-rv-grade-stars[data-input="criterion[' + item.id_ets_rv_product_comment_criterion + ']"]', form).etsRating({grade: parseInt(item.grade)});
587                                        }
588                                    });
589                                } else
590                                    form.find('.ets-pc-criterion').hide();
591                            }
592                            if (json.comments.images) {
593                                $('.ets_rv_upload_photos .ets_rv_upload_photo_item:not(:first)', form).remove();
594                                var photos_wrap = $('.ets_rv_upload_photos', form),
595                                    maximum_of_photo = parseInt(photos_wrap.data('photos')),
596                                    count = photos_wrap.find('.ets_rv_upload_photo_item').length
597                                ;
598                                for (var i = 0; i < json.comments.images.length; i++) {
599                                    let currentPhoto = photos_wrap.find('.ets_rv_upload_photo_item').eq(i);
600                                    if (i < maximum_of_photo) {
601                                        if (i >= count - 1 && count < maximum_of_photo) {
602                                            var addPhoto = currentPhoto.clone(true, true),
603                                                randomSize = Math.random().toString(36).slice(-8)
604                                            ;
605                                            addPhoto
606                                                .find('input[type=file]')
607                                                .attr({
608                                                    id: 'image_' + randomSize,
609                                                    name: 'image[' + randomSize + ']'
610                                                });
611                                            photos_wrap.append(addPhoto);
612                                            count++;
613                                        }
614                                        currentPhoto
615                                            .find('.ets_rv_upload_photo_wrap')
616                                            .addClass('selected')
617                                            .css('background-image', 'url("' + json.comments.images[i].url + '")')
618                                            .children('.ets_rv_btn_delete_photo')
619                                            .attr({
620                                                'data-product-comment-image-id': json.comments.images[i].id_ets_rv_product_comment_image,
621                                                'data-product-comment-id': json.comments.images[i].id_ets_rv_product_comment,
622                                            });
623                                    }
624                                }
625                            }
626                            if (json.comments.videos) {
627                                json.comments.videos.forEach(function (video, i) {
628                                    var __this = $('.ets_rv_upload_video_item .ets_rv_upload_video_wrap').eq(i);
629                                    __this.parents('.ets_rv_upload_video_item').addClass('cms_has_video');
630                                    __this
631                                        .addClass('selected')
632                                        .children('.ets_rv_video')
633                                        .html('<video controls><source src="' + video.url + '" type="' + video.type + '"/></video>')
634                                        .children('.ets_rv_btn_delete_video')
635                                        .attr({
636                                            'data-product-comment-video-id': video.id_ets_rv_product_comment_video,
637                                            'data-product-comment-id': video.id_ets_rv_product_comment,
638                                        }).parents('.ets_rv_upload_video_item').addClass('cms_has_video');
639                                    __this
640                                        .children('.ets_rv_btn_delete_video')
641                                        .attr({
642                                            'data-product-comment-video-id': video.id_ets_rv_product_comment_video,
643                                            'data-product-comment-id': video.id_ets_rv_product_comment,
644                                        });
645                                });
646                            }
647                        }
648                    }
649                },
650                error: function () {
651                    ele.removeClass('active');
652                }
653            });
654        }
655    });
656
657    // fix1.6
658    if (typeof baseDir !== "undefined" && baseDir) {
659        $(document).on('click', '.ets-rv-modal[role=dialog], button[data-dismiss=modal]', function () {
660            $(this).parents('.ets-rv-modal[role=dialog]').ETSModal('hide').removeClass('edit');
661        });
662    }
663});

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.