PageSourceSearch

https://www.efisioterapia.net/tienda/modules/productcomments/views/js/productListingComments.js

js efisioterapia.net collected 2026-09-24 20:12:18 UTC 4,862 bytes, 151 lines download raw bytes

1/**
2 * 2007-2019 PrestaShop SA and Contributors
3 *
4 * NOTICE OF LICENSE
5 *
6 * This source file is subject to the Academic Free License (AFL 3.0)
7 * that is bundled with this package in the file LICENSE.txt.
8 * It is also available through the world-wide-web at this URL:
9 * http://opensource.org/licenses/afl-3.0.php
10 * If you did not receive a copy of the license and are unable to
11 * obtain it through the world-wide-web, please send an email
12 * to [email protected] so we can send you a copy immediately.
13 *
14 * DISCLAIMER
15 *
16 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
17 * versions in the future. If you wish to customize PrestaShop for your
18 * needs please refer to http://www.prestashop.com for more information.
19 *
20 * @author    PrestaShop SA <[email protected]>
21 * @copyright 2007-2019 PrestaShop SA and Contributors
22 * @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
23 * International Registered Trademark & Property of PrestaShop SA
24 */
25
26
27$(document).ready(function() {
28    productListingComments.init();
29    productListingComments.load();
30});
31
32
33var productListingComments = (function () {
34
35    var data = {
36        productIDs: [],
37        commentsLoadingInProgress: false,
38        ajaxIDsLimit: 50,
39        ajaxUrl: ''
40    }
41
42    var DOMStrings = {
43        productListReviewsContainer: '.product-list-reviews',
44        productListReviewsNumberOfComments: '.comments-nb',
45        productListReviewsStarsContainer: '.grade-stars',
46        productContainer: '.thumbnail-container'
47    };
48
49    var DOMClasses =  {
50        inProgress: 'reviews-loading',
51        reviewsLoaded: 'reviews-loaded',
52        hasReviews: 'has-reviews'
53    };
54
55    function setEvents() {
56        prestashop.on('updateProductList', function() {
57            addProductsIDs();
58        });
59    }
60
61
62    function setAjaxUrl() {
63        if (data.ajaxUrl !== '')
64            return;
65
66        var url = $(DOMStrings.productListReviewsContainer).first().data('url');
67        data.ajaxUrl = url;
68    }
69
70    function getNewProductsReviewsElements() {
71        var $productListReviews = $(DOMStrings.productContainer)
72            .not('.' + DOMClasses.reviewsLoaded + ', .' + DOMClasses.inProgress)
73            .addClass(DOMClasses.inProgress)
74            .find(DOMStrings.productListReviewsContainer);
75
76        return $productListReviews;
77    }
78
79    function addProductsIDs() {
80
81        var $productsList = getNewProductsReviewsElements(),
82            seenIds = {};
83
84        $productsList.each(function () {
85            var id = $(this).data('id');
86            seenIds[id] = true;
87        });
88
89
90        var IDsArray = Object.keys(seenIds).filter(e => e !== 'undefined');
91        var prevDataIDs = data.productIDs.splice(0);
92        data.productIDs = prevDataIDs.concat(IDsArray);
93
94        if (!data.commentsLoadingInProgress) {
95            loadProductsData();
96        }
97    }
98
99    function loadProductsData() {
100        if (data.productIDs.length === 0)
101            return;
102
103        data.commentsLoadingInProgress = true;
104
105        var dataIDsCopy = data.productIDs.slice(0);
106            selectedProductIDs = dataIDsCopy.splice(0, data.ajaxIDsLimit);
107
108
109        $.get(data.ajaxUrl, { id_products: selectedProductIDs }, function (jsonData) {
110            if (jsonData) {
111                $.each(jsonData.products, function(i, elem) {
112                    var productData = elem;
113                    var $productsReviewsContainer = $('.product-list-reviews[data-id="' + productData.id_product + '"]');
114
115                    $productsReviewsContainer.each(function () {
116                        var $self = $(this);
117
118                        if (productData.comments_nb > 0) {
119                            $self.find(DOMStrings.productListReviewsStarsContainer).rating({ grade: productData.average_grade, starWidth: 16 });
120                            $self.find(DOMStrings.productListReviewsNumberOfComments).text('(' + productData.comments_nb + ')');
121                            $self.closest(DOMStrings.productContainer).addClass(DOMClasses.hasReviews);
122                            $self.css('visibility', 'visible');
123                        }
124
125                        $self.closest(DOMStrings.productContainer).addClass(DOMClasses.reviewsLoaded);
126                        $self.closest(DOMStrings.productContainer).removeClass(DOMClasses.inProgress);
127
128                    });
129                    data.productIDs.shift();
130                });
131
132                data.commentsLoadingInProgress = false;
133                if (data.productIDs.length > 0) {
134                    loadProductsData();
135                }
136
137            }
138        });
139    }
140
141
142    return {
143        load: function () {
144            addProductsIDs();
145        },
146        init: function () {
147            setAjaxUrl();
148            setEvents();
149        }
150    }
151})();

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.