PageSourceSearch

https://etronixcenter.com/themes/zro03/js/products-comparison.js

js etronixcenter.com collected 2026-10-05 01:02:51 UTC 4,351 bytes, 143 lines download raw bytes

1/*
2* 2007-2017 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-2017 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*/
25$(document).ready(function(){
26	$(document).on('click', '.add_to_compare', function(e){
27		e.preventDefault();
28		if (typeof addToCompare != 'undefined')
29			addToCompare(parseInt($(this).data('id-product')));
30	});
31
32	reloadProductComparison();
33	compareButtonsStatusRefresh();
34	totalCompareButtons();
35});
36
37function addToCompare(productId)
38{
39	var totalValueNow = parseInt($('.bt_compare').next('.compare_product_count').val());
40	var action, totalVal;
41	if ($.inArray(parseInt(productId),comparedProductsIds) === -1)
42		action = 'add';
43	else
44		action = 'remove';
45
46	$.ajax({
47		url: baseUri + '?controller=products-comparison&ajax=1&action=' + action + '&id_product=' + productId,
48		async: true,
49		cache: false,
50		success: function(data) {
51			if (action === 'add' && comparedProductsIds.length < comparator_max_item) {
52				comparedProductsIds.push(parseInt(productId)),
53				compareButtonsStatusRefresh(),
54				totalVal = totalValueNow +1,
55				$('.bt_compare').next('.compare_product_count').val(totalVal),
56				totalValue(totalVal);
57			}
58			else if (action === 'remove') {
59				comparedProductsIds.splice($.inArray(parseInt(productId), comparedProductsIds), 1),
60				compareButtonsStatusRefresh(),
61				totalVal = totalValueNow -1,
62				$('.bt_compare').next('.compare_product_count').val(totalVal),
63				totalValue(totalVal);
64			}
65			else
66			{
67				if (!!$.prototype.fancybox)
68					$.fancybox.open([{
69						type: 'inline',
70						autoScale: true,
71						minHeight: 30,
72						content: '<p class="fancybox-error">' + max_item + '</p>'
73					}], {
74						padding: 0
75					});
76				else
77					alert(max_item);
78			}
79			totalCompareButtons();
80		},
81		error: function(){}
82	});
83}
84
85function reloadProductComparison()
86{
87	$(document).on('click', 'a.cmp_remove', function(e){
88		e.preventDefault();
89		var idProduct = parseInt($(this).data('id-product'));
90		$.ajax({
91			url: baseUri + '?controller=products-comparison&ajax=1&action=remove&id_product=' + idProduct,
92			async: false,
93			cache: false
94		});
95		$('td.product-' + idProduct).fadeOut(600);
96
97		var compare_product_list = get('compare_product_list');
98		var bak = compare_product_list;
99		var new_compare_product_list = [];
100		compare_product_list = decodeURIComponent(compare_product_list).split('|');
101		for (var i in compare_product_list)
102			if (parseInt(compare_product_list[i]) != idProduct)
103				new_compare_product_list.push(compare_product_list[i]);
104		if (new_compare_product_list.length)
105			window.location.search = window.location.search.replace(bak, new_compare_product_list.join(encodeURIComponent('|')));
106	});
107};
108
109function compareButtonsStatusRefresh()
110{
111	$('.add_to_compare').each(function() {
112		if ($.inArray(parseInt($(this).data('id-product')), comparedProductsIds) !== -1)
113			$(this).addClass('checked');
114		else
115			$(this).removeClass('checked');
116	});
117}
118
119function totalCompareButtons()
120{
121	var totalProductsToCompare = parseInt($('.bt_compare .total-compare-val').html());
122	if (typeof totalProductsToCompare !== "number" || totalProductsToCompare === 0)
123		$('.bt_compare').attr("disabled",true);
124	else
125		$('.bt_compare').attr("disabled",false);
126}
127
128function totalValue(value)
129{
130	$('.bt_compare').find('.total-compare-val').html(value);
131}
132
133function get(name)
134{
135	var regexS = "[\\?&]" + name + "=([^&#]*)";
136	var regex = new RegExp(regexS);
137	var results = regex.exec(window.location.search);
138
139	if (results == null)
140		return "";
141	else
142		return results[1];
143}

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.