PageSourceSearch

https://www.bruschet.fr/aixam/themes/webstore-v3/js/products-comparison.js

js bruschet.fr collected 2026-10-09 18:08:20 UTC 6,614 bytes, 180 lines download raw bytes

1/*
2 * 2007-2015 PrestaShop
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-2015 PrestaShop SA
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 */
25var comparing = false;
26$(document).ready(function () {
27    $(document).on('click', '.add_to_compare', function (e) {
28        e.preventDefault();
29        e.stopPropagation();
30        if (typeof addToCompare != 'undefined')
31            addToCompare(parseInt($(this).data('product')));
32    });
33
34    reloadProductComparison();
35    compareButtonsStatusRefresh();
36    totalCompareButtons();
37    if (typeof getAllProductsCompare == 'function')
38        getAllProductsCompare(false, true);
39    if (typeof wishlistRefreshStatus == 'function')
40        wishlistRefreshStatus();
41});
42
43function addToCompare(productId)
44{
45    if (!comparing)
46        comparing = true;
47    else
48        return;
49    var totalValueNow = parseInt($('.bt_compare').next('.compare_product_count').val());
50    var action, totalVal;
51    if ($.inArray(parseInt(productId), comparedProductsIds) === -1)
52        action = 'add';
53    else
54        action = 'remove';
55    $.ajax({
56        url: baseUri + '?controller=products-comparison&ajax=1&action=' + action + '&id_product=' + productId,
57        async: true,
58        cache: false,
59        success: function (data) {
60            if (typeof comparedProductsIds == 'undefined')
61                comparedProductsIds = [];
62            if (action === 'add' && comparedProductsIds.length < comparator_max_item) {
63                comparedProductsIds.push(parseInt(productId)),
64                        compareButtonsStatusRefresh(),
65                        totalVal = totalValueNow + 1,
66                        $('.bt_compare').next('.compare_product_count').val(totalVal),
67                        totalValue(totalVal);
68                        $("#bottom-comparator .collapsed").addClass("color-compare");
69                /* CUSTOM POUR COMPARATOR BOTTOM */
70                if ($("#bottom-comparator").length > 0)
71                {
72                    addFirstLiEmpty(parseInt(productId));
73                    getAllProductsCompare(true, false);
74                    displayNavBar();
75                }
76
77            } else if (action === 'remove') {
78                comparedProductsIds.splice($.inArray(parseInt(productId), comparedProductsIds), 1),
79                        compareButtonsStatusRefresh(),
80                        totalVal = totalValueNow - 1,
81                        $('.bt_compare').next('.compare_product_count').val(totalVal),
82                        totalValue(totalVal);
83                        $("#bottom-comparator .collapsed").removeClass("color-compare");
84                /* CUSTOM POUR COMPARATOR BOTTOM */
85                if ($("#bottom-comparator").length > 0)
86                {
87                    $("#bottom-comparator .list_products_compare div#itemcompare-" + parseInt(productId)).remove();
88                    reloadUlCompareBottom();
89                    getAllProductsCompare(false, true);
90                    displayNavBar();
91                }
92            } else
93            {
94                toastr["error"](max_item);
95            }
96            totalCompareButtons();
97            comparing = false;
98        },
99        error: function () {
100            comparing = false;
101        }
102    });
103}
104
105function reloadProductComparison()
106{
107    $(document).on('click', 'a.cmp_remove', function (e) {
108        e.preventDefault();
109        var idProduct = parseInt($(this).data('id-product'));
110        $.ajax({
111            url: baseUri + '?controller=products-comparison&ajax=1&action=remove&id_product=' + idProduct,
112            async: false,
113            cache: false,
114            success: function (data) {
115                toastr["success"](delete_vehicule_label);
116                $('th.product-' + idProduct).fadeOut(600).remove();
117                $('td.product-' + idProduct).fadeOut(600).remove();
118                /* If empty results */
119                if ($('.ajax_block_product').length <= 0) {
120                    $('#product_comparison').remove();
121                    $('h1').after('<p class="alert alert-warning">' + empty_comparator + '</p>');
122                }
123            },
124            error: function (data) {
125                toastr["error"](error_label);
126            }
127        });
128    });
129}
130
131function removeParam(key, sourceURL) {
132    var rtn = sourceURL.split("?")[0], param, params_arr = [], queryString = (sourceURL.indexOf("?") !== -1) ? sourceURL.split("?")[1] : "";
133    if (queryString !== "") {
134        params_arr = queryString.split("&");
135        for (var i = params_arr.length - 1; i >= 0; i -= 1) {
136            param = params_arr[i].split("=")[0];
137            if (param === key) {
138                params_arr.splice(i, 1);
139            }
140        }
141        rtn = rtn + (params_arr.length > 0 ? "?" + params_arr.join("&") : "");
142    }
143    return rtn;
144}
145
146function compareButtonsStatusRefresh()
147{
148    $('.add_to_compare').each(function () {
149        if ($.inArray(parseInt($(this).data('id-product')), comparedProductsIds) !== -1)
150            $(this).addClass('checked');
151        else
152            $(this).removeClass('checked');
153    });
154}
155
156function totalCompareButtons()
157{
158    var totalProductsToCompare = parseInt($('.bt_compare .total-compare-val').html());
159    if (typeof totalProductsToCompare !== "number" || totalProductsToCompare === 0)
160        $('.bt_compare').attr("disabled", true);
161    else
162        $('.bt_compare').attr("disabled", false);
163}
164
165function totalValue(value)
166{
167    $('.bt_compare').find('.total-compare-val').html(value);
168}
169
170function get(name)
171{
172    var regexS = "[\\?&]" + name + "=([^&#]*)";
173    var regex = new RegExp(regexS);
174    var results = regex.exec(window.location.search);
175
176    if (results == null)
177        return "";
178    else
179        return results[1];
180}

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.