PageSourceSearch

https://www.yodeyma.com/belgium/themes/yodeyma/js/modules/blockcart/ajax-cart.js

js yodeyma.com collected 2026-09-26 17:32:49 UTC 33,381 bytes, 928 lines download raw bytes

1/*
2* 2007-2014 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-2014 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	ajaxCart.overrideButtonsInThePage();
27
28	$(document).on('click', '.block_cart_collapse', function(e){
29		e.preventDefault();
30		ajaxCart.collapse();
31	});
32	$(document).on('click', '.block_cart_expand', function(e){
33		e.preventDefault();
34		ajaxCart.expand();
35	});
36
37	var cart_qty = 0;
38	var current_timestamp = parseInt(new Date().getTime() / 1000);
39
40	if (typeof $('.ajax_cart_quantity').html() == 'undefined' || (typeof generated_date != 'undefined' && generated_date != null && (parseInt(generated_date) + 30) < current_timestamp))
41		ajaxCart.refresh();
42	else
43		cart_qty = parseInt($('.ajax_cart_quantity').html());
44
45	/* roll over cart */
46	var cart_block = new HoverWatcher('#header .cart_block');
47	var shopping_cart = new HoverWatcher('#header .shopping_cart');
48
49	
50
51	if (is_touch_device())
52	{
53		$('.shopping_cart > a:first').on('click', function(e){
54			e.preventDefault();
55		});
56
57		$('#header').on('touchstart', '.shopping_cart a:first', function(){
58			if ($(this).next('.cart_block:visible').length)
59				$("#header .cart_block").stop(true, true).fadeOut(450);
60			else
61				$("#header .cart_block").stop(true, true).fadeIn(450);
62	
63		});
64	}
65	else {
66
67		//console.log( ajaxCart.nb_total_products, cart_qty );
68		$("#header .shopping_cart a:first").hover(
69			function(){
70				if (ajaxCart.nb_total_products > 0 || cart_qty > 0){
71					$("#header .cart_block").stop(true, true).fadeIn(450);
72				}
73			},
74			function(){
75				setTimeout(function(){
76					if (!shopping_cart.isHoveringOver() && !cart_block.isHoveringOver())
77						$("#header .cart_block").stop(true, true).fadeOut(450);
78						
79				}, 200);
80			}
81		);
82
83	}
84
85	$("#header .cart_block").hover(
86		function(){
87		},
88		function(){
89			setTimeout(function(){
90				if (!shopping_cart.isHoveringOver())
91					$("#header .cart_block").stop(true, true).fadeOut(450);
92			}, 200);
93		}
94	);
95
96	$(document).on('click', '.delete_voucher', function(e){
97		e.preventDefault();
98		$.ajax({
99			type: 'POST',
100			headers: { "cache-control": "no-cache" },
101			async: false,
102			cache: false,
103			url:$(this).attr('href') + '?rand=' + new Date().getTime()
104		});
105		$(this).parent().parent().remove();
106		if ($('body').attr('id') == 'order' || $('body').attr('id') == 'order-opc')
107		{
108			if (typeof(updateAddressSelection) != 'undefined')
109				updateAddressSelection();
110			else
111				location.reload();
112		}
113	});
114
115	$(document).on('click', '#cart_navigation input', function(e){
116		$(this).prop('disabled', 'disabled').addClass('disabled');
117		$(this).closest("form").get(0).submit();
118	});
119
120	$(document).on('click', '#layer_cart .cross, #layer_cart .continue, .layer_cart_overlay', function(e){
121		e.preventDefault();
122		$('.layer_cart_overlay').hide();
123		$('#layer_cart').fadeOut('fast');
124	});
125	
126	$('#columns #layer_cart, #columns .layer_cart_overlay').detach().prependTo('#columns');
127});
128
129//JS Object : update the cart by ajax actions
130var ajaxCart = {
131	nb_total_products: 0,
132	//override every button in the page in relation to the cart
133	overrideButtonsInThePage : function(){
134		
135		// Fix mas de una vez evento click
136		$(document).off('click', '.ajax_add_to_cart_button');
137		$(document).off('click', '#add_to_cart button');
138		
139		//for every 'add' buttons...
140		$(document).on('click', '.ajax_add_to_cart_button', function(e){
141			e.preventDefault();
142			var idProduct =  $(this).data('id-product');
143			if ($(this).prop('disabled') != 'disabled')
144				ajaxCart.add(idProduct, null, false, this);
145		});
146		//for product page 'add' button...
147		$(document).on('click', '#add_to_cart button', function(e){
148			e.preventDefault();
149			ajaxCart.add( $('#product_page_product_id').val(), $('#idCombination').val(), true, null, $('#quantity_wanted').val(), null);
150		});
151
152		//for 'delete' buttons in the cart block...
153		$(document).on('click', '.cart_block_list .ajax_cart_block_remove_link', function(e){
154			e.preventDefault();
155			// Customized product management
156			var customizationId = 0;
157			var productId = 0;
158			var productAttributeId = 0;
159			var customizableProductDiv = $($(this).parent().parent()).find("div[data-id^=deleteCustomizableProduct_]");
160			var idAddressDelivery = false;
161
162			if (customizableProductDiv && $(customizableProductDiv).length)
163			{
164				var ids = customizableProductDiv.data('id').split('_');
165				if (typeof(ids[1]) != 'undefined')
166				{
167					customizationId = parseInt(ids[1]);
168					productId = parseInt(ids[2]);
169					if (typeof(ids[3]) != 'undefined')
170						productAttributeId = parseInt(ids[3]);
171					if (typeof(ids[4]) != 'undefined')
172						idAddressDelivery = parseInt(ids[4]);
173				}
174			}
175
176			// Common product management
177			if (!customizationId)
178			{
179				//retrieve idProduct and idCombination from the displayed product in the block cart
180				var firstCut = $(this).parent().parent().data('id').replace('cart_block_product_', '');
181				firstCut = firstCut.replace('deleteCustomizableProduct_', '');
182				ids = firstCut.split('_');
183				productId = parseInt(ids[0]);
184
185				if (typeof(ids[1]) != 'undefined')
186					productAttributeId = parseInt(ids[1]);
187				if (typeof(ids[2]) != 'undefined')
188					idAddressDelivery = parseInt(ids[2]);
189			}
190
191			// Removing product from the cart
192			ajaxCart.remove(productId, productAttributeId, customizationId, idAddressDelivery);
193		});
194	},
195
196	// try to expand the cart
197	expand : function(){
198		if ($('.cart_block_list').hasClass('collapsed'))
199		{
200			$('.cart_block_list.collapsed').slideDown({
201				duration: 450,
202				complete: function(){
203					$(this).addClass('expanded').removeClass('collapsed');
204				}
205			});
206
207			// save the expand statut in the user cookie
208			$.ajax({
209				type: 'POST',
210				headers: { "cache-control": "no-cache" },
211				url: baseDir + 'modules/blockcart/blockcart-set-collapse.php' + '?rand=' + new Date().getTime(),
212				async: false,
213				cache: false,
214				data: 'ajax_blockcart_display=expand',
215				complete: function(){
216					$('.block_cart_expand').fadeOut('fast', function(){
217						$('.block_cart_collapse').fadeIn('fast');
218					});
219				}			
220			});
221		}
222	},
223
224	// try to collapse the cart
225	collapse : function(){
226		if ($('.cart_block_list').hasClass('expanded'))
227		{
228			$('.cart_block_list.expanded').slideUp('slow', function(){
229				$(this).addClass('collapsed').removeClass('expanded');
230			});
231
232			// save the expand statut in the user cookie
233			$.ajax({
234				type: 'POST',
235				headers: { "cache-control": "no-cache" },
236				url: baseDir + 'modules/blockcart/blockcart-set-collapse.php' + '?rand=' + new Date().getTime(),
237				async: false,
238				cache: false,
239				data: 'ajax_blockcart_display=collapse' + '&rand=' + new Date().getTime(),
240				complete: function(){
241					$('.block_cart_collapse').fadeOut('fast', function(){
242						$('.block_cart_expand').fadeIn('fast');
243					});
244				}
245			});
246		}
247	},
248	// Fix display when using back and previous browsers buttons
249	refresh : function(){
250		$.ajax({
251			type: 'POST',
252			headers: { "cache-control": "no-cache" },
253			url: baseUri + '?rand=' + new Date().getTime(),
254			async: false,
255			cache: false,
256			dataType : "json",
257			data: 'controller=cart&ajax=true&token=' + static_token,
258			success: function(jsonData)
259			{
260				ajaxCart.updateCart(jsonData);
261			}
262		});
263	},
264
265	// Update the cart information
266	updateCartInformation : function (jsonData, addedFromProductPage){
267		ajaxCart.updateCart(jsonData);
268		//reactive the button when adding has finished
269		if (addedFromProductPage) 
270		{
271			$('#add_to_cart button').removeProp('disabled').removeClass('disabled');
272			if (!jsonData.hasError || jsonData.hasError == false)
273				$('#add_to_cart button').addClass('added');
274			else
275				$('#add_to_cart button').removeClass('added');
276		}
277		else
278			$('.ajax_add_to_cart_button').removeProp('disabled');
279	},
280	// close fancybox
281	updateFancyBox : function (){},
282	// add a product in the cart via ajax
283	add : function(idProduct, idCombination, addedFromProductPage, callerElement, quantity, whishlist){
284		if (addedFromProductPage && !checkCustomizations())
285		{
286			if (!!$.prototype.fancybox)
287			    $.fancybox.open([
288			        {
289			            type: 'inline',
290			            autoScale: true,
291			            minHeight: 30,
292			            content: '<p class="fancybox-error">' + fieldRequired + '</p>'
293			        }
294			    ], {
295			        padding: 0
296			    });
297			else
298			    alert(fieldRequired);
299            return;
300		}
301		emptyCustomizations();
302		//disabled the button when adding to not double add if user double click
303		if (addedFromProductPage)
304		{
305			$('#add_to_cart button').prop('disabled', 'disabled').addClass('disabled');
306			$('.filled').removeClass('filled');
307
308		}
309		else
310			$(callerElement).prop('disabled', 'disabled');
311
312		if ($('.cart_block_list').hasClass('collapsed'))
313			this.expand();
314		//send the ajax request to the server
315		$.ajax({
316			type: 'POST',
317			headers: { "cache-control": "no-cache" },
318			url: baseUri + '?rand=' + new Date().getTime(),
319			async: false,
320			cache: false,
321			dataType : "json",
322			data: 'controller=cart&add=1&ajax=true&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ( (parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination): ''),
323			success: function(jsonData,textStatus,jqXHR)
324			{
325				// add appliance to whishlist module
326				if (whishlist && !jsonData.errors)
327					WishlistAddProductCart(whishlist[0], idProduct, idCombination, whishlist[1]);
328				
329				if (!jsonData.hasError)
330				{
331					if (contentOnly)
332						window.parent.ajaxCart.updateCartInformation(jsonData, addedFromProductPage);
333					else
334						ajaxCart.updateCartInformation(jsonData, addedFromProductPage);
335
336					if (jsonData.crossSelling)
337						$('.crossseling').html(jsonData.crossSelling);
338
339					if (idCombination)
340						$(jsonData.products).each(function(){
341							if (this.id != undefined && this.id == parseInt(idProduct) && this.idCombination == parseInt(idCombination))
342								if (contentOnly)
343									window.parent.ajaxCart.updateLayer(this);	
344								else
345									ajaxCart.updateLayer(this);
346						});
347					else
348						$(jsonData.products).each(function(){
349							if (this.id != undefined && this.id == parseInt(idProduct))
350								if (contentOnly)
351									window.parent.ajaxCart.updateLayer(this);
352								else
353									ajaxCart.updateLayer(this);					
354						});
355					if (contentOnly)
356						parent.$.fancybox.close();
357				}
358				else 
359				{
360					if (contentOnly)
361						window.parent.ajaxCart.updateCart(jsonData);
362					else
363						ajaxCart.updateCart(jsonData);	
364					if (addedFromProductPage)
365						$('#add_to_cart button').removeProp('disabled').removeClass('disabled');
366					else
367						$(callerElement).removeProp('disabled');
368				}
369
370			},
371			error: function(XMLHttpRequest, textStatus, errorThrown)
372			{
373				var error = "Impossible to add the product to the cart.<br/>textStatus: '" + textStatus + "'<br/>errorThrown: '" + errorThrown + "'<br/>responseText:<br/>" + XMLHttpRequest.responseText;
374				if (!!$.prototype.fancybox)
375				    $.fancybox.open([
376				    {
377				        type: 'inline',
378				        autoScale: true,
379				        minHeight: 30,
380				        content: '<p class="fancybox-error">' + error + '</p>'
381				    }],
382					{
383				        padding: 0
384				    });
385				else
386				    alert(error);
387				//reactive the button when adding has finished
388				if (addedFromProductPage)
389					$('#add_to_cart button').removeProp('disabled').removeClass('disabled');
390				else
391					$(callerElement).removeProp('disabled');
392			}
393		});
394	},
395
396	//remove a product from the cart via ajax
397	remove : function(idProduct, idCombination, customizationId, idAddressDelivery){
398		//send the ajax request to the server
399		$.ajax({
400			type: 'POST',
401			headers: { "cache-control": "no-cache" },
402			url: baseUri + '?rand=' + new Date().getTime(),
403			async: false,
404			cache: false,
405			dataType : "json",
406			data: 'controller=cart&delete=1&id_product=' + idProduct + '&ipa=' + ((idCombination != null && parseInt(idCombination)) ? idCombination : '') + ((customizationId && customizationId != null) ? '&id_customization=' + customizationId : '') + '&id_address_delivery=' + idAddressDelivery + '&token=' + static_token + '&ajax=true',
407			success: function(jsonData)	{
408				ajaxCart.updateCart(jsonData);
409				if ($('body').attr('id') == 'order' || $('body').attr('id') == 'order-opc')
410					deleteProductFromSummary(idProduct+'_'+idCombination+'_'+customizationId+'_'+idAddressDelivery);
411			},
412			error: function()
413            {
414				var error = 'ERROR: unable to delete the product';
415				if (!!$.prototype.fancybox)
416				{
417				    $.fancybox.open([
418				        {
419				            type: 'inline',
420				            autoScale: true,
421				            minHeight: 30,
422				            content: error
423				        }
424				    ], {
425				        padding: 0
426				    });
427				}
428				else
429				    alert(error);
430            }
431		});
432	},
433
434	//hide the products displayed in the page but no more in the json data
435	hideOldProducts : function(jsonData){
436		//delete an eventually removed product of the displayed cart (only if cart is not empty!)		
437		if ($('.cart_block_list:first dl.products').length > 0)
438		{			
439			var removedProductId = null;
440			var removedProductData = null;
441			var removedProductDomId = null;
442			//look for a product to delete...
443			$('.cart_block_list:first dl.products dt').each(function(){
444				//retrieve idProduct and idCombination from the displayed product in the block cart
445				var domIdProduct = $(this).data('id');
446				var firstCut = domIdProduct.replace('cart_block_product_', '');
447				var ids = firstCut.split('_');
448
449				//try to know if the current product is still in the new list
450				var stayInTheCart = false;
451				for (aProduct in jsonData.products)
452				{
453					//we've called the variable aProduct because IE6 bug if this variable is called product
454					//if product has attributes
455					if (jsonData.products[aProduct]['id'] == ids[0] && (!ids[1] || jsonData.products[aProduct]['idCombination'] == ids[1]))
456					{
457						stayInTheCart = true;
458						// update the product customization display (when the product is still in the cart)
459						ajaxCart.hideOldProductCustomizations(jsonData.products[aProduct], domIdProduct);
460					}
461				}
462				//remove product if it's no more in the cart
463				console.log(stayInTheCart);
464				if (!stayInTheCart)
465				{
466					removedProductId = $(this).data('id');
467					if (removedProductId != null)
468					{
469						var firstCut =  removedProductId.replace('cart_block_product_', '');
470						var ids = firstCut.split('_');
471
472						$('dt[data-id="' + removedProductId + '"]').addClass('strike').fadeTo('slow', 0, function(){
473							$(this).slideUp('slow', function(){
474								$(this).remove();
475								// If the cart is now empty, show the 'no product in the cart' message and close detail
476								if($('.cart_block:first dl.products dt').length == 0)
477								{
478									$("#header .cart_block").stop(true, true).fadeOut(200);
479									$('.cart_block_no_products:hidden').slideDown(450);
480									$('.cart_block dl.products').remove();
481								}
482							});
483						});
484						$('dd[data-id="cart_block_combination_of_' + ids[0] + (ids[1] ? '_'+ids[1] : '') + (ids[2] ? '_'+ids[2] : '') + '"]').fadeTo('fast', 0, function(){
485							$(this).slideUp('fast', function(){
486								$(this).remove();
487							});
488						});
489					}
490				}
491				
492				//Remueve el prodcuto 
493				
494			});
495		}
496	},
497
498	hideOldProductCustomizations : function (product, domIdProduct){
499		var customizationList = $('ul[data-id="customization_' + product['id'] + '_' + product['idCombination'] + '"]');
500		if(customizationList.length > 0)
501		{
502			$(customizationList).find("li").each(function(){
503				$(this).find("div").each(function(){
504					var customizationDiv = $(this).data('id');
505					var tmp = customizationDiv.replace('deleteCustomizableProduct_', '');
506					var ids = tmp.split('_');
507					if ((parseInt(product.idCombination) == parseInt(ids[2])) && !ajaxCart.doesCustomizationStillExist(product, ids[0]))
508						$('div[data-id="' + customizationDiv + '"]').parent().addClass('strike').fadeTo('slow', 0, function(){
509							$(this).slideUp('slow');
510							$(this).remove();
511						});
512				});
513			});
514		}
515
516		var removeLinks = $('.deleteCustomizableProduct[data-id="' + domIdProduct + '"]').find('.ajax_cart_block_remove_link');
517		if (!product.hasCustomizedDatas && !removeLinks.length)
518			$('div[data-id="' + domIdProduct + '"]' + ' span.remove_link').html('<a class="ajax_cart_block_remove_link" rel="nofollow" href="' + baseUri + '?controller=cart&amp;delete=1&amp;id_product=' + product['id'] + '&amp;ipa=' + product['idCombination'] + '&amp;
518token=' + static_token + '"> </a>');
519		if (product.is_gift)
520			$('div[data-id="' + domIdProduct + '"]' + ' span.remove_link').html('');
521	},
522
523	doesCustomizationStillExist : function (product, customizationId){
524		var exists = false;
525
526		$(product.customizedDatas).each(function(){
527			if (this.customizationId == customizationId)
528			{
529				exists = true;
530				// This return does not mean that we found nothing but simply break the loop
531				return false;
532			}
533		});
534		return (exists);
535	},
536
537	//refresh display of vouchers (needed for vouchers in % of the total)
538	refreshVouchers : function (jsonData){
539		if (typeof(jsonData.discounts) == 'undefined' || jsonData.discounts.length == 0)
540			$('.vouchers').hide();
541		else
542		{
543			$('.vouchers tbody').html('');
544
545			for (i=0;i<jsonData.discounts.length;i++)
546			{
547				if (parseFloat(jsonData.discounts[i].price_float) > 0)
548				{
549					var delete_link = '';
550					if (jsonData.discounts[i].code.length)
551						delete_link = '<a class="delete_voucher" href="'+jsonData.discounts[i].link+'" title="'+delete_txt+'"><i class="icon-remove-sign"></i></a>';
552					$('.vouchers tbody').append($(
553						'<tr class="bloc_cart_voucher" data-id="bloc_cart_voucher_'+jsonData.discounts[i].id+'">'
554						+'	<td class="quantity">1x</td>'
555						+'	<td class="name" title="'+jsonData.discounts[i].description+'">'+jsonData.discounts[i].name+'</td>'
556						+'	<td class="price">-'+jsonData.discounts[i].price+'</td>'
557						+'	<td class="delete">' + delete_link + '</td>'
558						+'</tr>'
559					));
560				}
561			}
562			$('.vouchers').show();
563		}
564
565	},
566
567	// Update product quantity
568	updateProductQuantity : function (product, quantity){
569		$('dt[data-id=cart_block_product_' + product.id + '_' + (product.idCombination ? product.idCombination : '0')+ '_' + (product.idAddressDelivery ? product.idAddressDelivery : '0') + '] .quantity').fadeTo('fast', 0, function(){
570			$(this).text(quantity);
571			$(this).fadeTo('fast', 1, function(){
572				$(this).fadeTo('fast', 0, function(){
573					$(this).fadeTo('fast', 1, function(){
574						$(this).fadeTo('fast', 0, function(){
575							$(this).fadeTo('fast', 1);
576						});
577					});
578				});
579			});
580		});
581	},
582
583	//display the products witch are in json data but not already displayed
584	displayNewProducts : function(jsonData){
585		//add every new products or update displaying of every updated products
586		$(jsonData.products).each(function(){
587			//fix ie6 bug (one more item 'undefined' in IE6)
588			if (this.id != undefined)
589			{
590				//create a container for listing the products and hide the 'no product in the cart' message (only if the cart was empty)
591
592				if ($('.cart_block:first dl.products').length == 0)
593				{
594					$('.cart_block_no_products').before('<dl class="products"></dl>');
595					$('.cart_block_no_products').hide();
596				}
597				//if product is not in the displayed cart, add a new product's line
598				var domIdProduct = this.id + '_' + (this.idCombination ? this.idCombination : '0') + '_' + (this.idAddressDelivery ? this.idAddressDelivery : '0');
599				var domIdProductAttribute = this.id + '_' + (this.idCombination ? this.idCombination : '0');
600
601				if ($('dt[data-id="cart_block_product_' + domIdProduct + '"]').length == 0)
602				{
603					var productId = parseInt(this.id);
604					var productAttributeId = (this.hasAttributes ? parseInt(this.attributes) : 0);
605					var content =  '<dt class="unvisible" data-id="cart_block_product_' + domIdProduct + '">';
606					var name = $.trim($('<span />').html(this.name).text());
607					name = (name.length > 12 ? name.substring(0, 10) + '...' : name);
608					content += '<a class="cart-images" href="' + this.link + '" title="' + name + '"><img  src="' + this.image_cart + '" alt="' + this.name +'"></a>';
609					content += '<div class="cart-info"><div class="product-name">' + '<span class="quantity-formated"><span class="quantity">' + this.quantity + '</span>&nbsp;x&nbsp;</span><a href="' + this.link + '" title="' + this.name + '" class="cart_block_product_name">' + name + '</a></div>';
610					if (this.hasAttributes)
611						  content += '<div class="product-atributes"><a href="' + this.link + '" title="' + this.name + '">' + this.attributes + '</a></div>';
612					if (typeof(freeProductTranslation) != 'undefined')
613						content += '<span class="price">' + (parseFloat(this.price_float) > 0 ? this.priceByLine : freeProductTranslation) + '</span></div>';
614
615					if (typeof(this.is_gift) == 'undefined' || this.is_gift == 0)
616						content += '<span class="remove_link"><a rel="nofollow" class="ajax_cart_block_remove_link" href="' + baseUri + '?controller=cart&amp;delete=1&amp;id_product=' + productId + '&amp;
616token=' + static_token + (this.hasAttributes ? '&amp;ipa=' + parseInt(this.idCombination) : '') + '"> </a></span>';
617					else
618						content += '<span class="remove_link"></span>';
619					content += '</dt>';
620					if (this.hasAttributes)
621						content += '<dd data-id="cart_block_combination_of_' + domIdProduct + '" class="unvisible">';
622					if (this.hasCustomizedDatas)
623						content += ajaxCart.displayNewCustomizedDatas(this);
624					if (this.hasAttributes) content += '</dd>';
625
626					$('.cart_block dl.products').append(content);
627				}
628				//else update the product's line
629				else
630				{
631					var jsonProduct = this;
632					if($.trim($('dt[data-id="cart_block_product_' + domIdProduct + '"] .quantity').html()) != jsonProduct.quantity || $.trim($('dt[data-id="cart_block_product_' + domIdProduct + '"] .price').html()) != jsonProduct.priceByLine)
633					{
634						// Usual product
635						if (!this.is_gift)
636							$('dt[data-id="cart_block_product_' + domIdProduct + '"] .price').text(jsonProduct.priceByLine);
637						else
638							$('dt[data-id="cart_block_product_' + domIdProduct + '"] .price').html(freeProductTranslation);
639						ajaxCart.updateProductQuantity(jsonProduct, jsonProduct.quantity);
640
641						// Customized product
642						if (jsonProduct.hasCustomizedDatas)
643						{
644							customizationFormatedDatas = ajaxCart.displayNewCustomizedDatas(jsonProduct);
645							if (!$('ul[data-id="customization_' + domIdProductAttribute + '"]').length)
646							{
647								if (jsonProduct.hasAttributes)
648									$('dd[data-id="cart_block_combination_of_' + domIdProduct + '"]').append(customizationFormatedDatas);
649								else
650									$('.cart_block dl.products').append(customizationFormatedDatas);
651							}
652							else
653							{
654								$('ul[data-id="customization_' + domIdProductAttribute + '"]').html('');
655								$('ul[data-id="customization_' + domIdProductAttribute + '"]').append(customizationFormatedDatas);
656							}
657						}
658					}
659				}
660				$('.cart_block dl.products .unvisible').slideDown(450).removeClass('unvisible');
661
662			var removeLinks = $('dt[data-id="cart_block_product_' + domIdProduct + '"]').find('a.ajax_cart_block_remove_link');
663			if (this.hasCustomizedDatas && removeLinks.length)
664				$(removeLinks).each(function(){
665					$(this).remove();
666				});
667			}
668		});
669	},
670
671	displayNewCustomizedDatas : function(product){
672		var content = '';
673		var productId = parseInt(product.id);
674		var productAttributeId = typeof(product.idCombination) == 'undefined' ? 0 : parseInt(product.idCombination);
675		var hasAlreadyCustomizations = $('ul[data-id="customization_' + productId + '_' + productAttributeId + '"]').length;
676
677		if (!hasAlreadyCustomizations)
678		{
679			if (!product.hasAttributes)
680				content += '<dd data-id="cart_block_combination_of_' + productId + '" class="unvisible">';
681			if ($('ul[data-id="customization_' + productId + '_' + productAttributeId + '"]').val() == undefined)
682				content += '<ul class="cart_block_customizations" data-id="customization_' + productId + '_' + productAttributeId + '">';
683		}
684
685		$(product.customizedDatas).each(function(){
686			var done = 0;
687			customizationId = parseInt(this.customizationId);
688			productAttributeId = typeof(product.idCombination) == 'undefined' ? 0 : parseInt(product.idCombination);
689			content += '<li name="customization"><div class="deleteCustomizableProduct" data-id="deleteCustomizableProduct_' + customizationId + '_' + productId + '_' + (productAttributeId ?  productAttributeId : '0') + '"><a rel="nofollow" class="ajax_cart_block_remove_link" href="' + baseUri + '?controller=cart&amp;delete=1&amp;id_product=' + productId + '&amp;ipa=' + productAttributeId + '&amp;id_customization=' + customizationId + '&amp;
689token=' + static_token + '"></a></div>';
690
691			// Give to the customized product the first textfield value as name
692			$(this.datas).each(function(){
693				if (this['type'] == CUSTOMIZE_TEXTFIELD)
694				{
695					$(this.datas).each(function(){
696						if (this['index'] == 0)
697						{
698							content += ' ' + this.truncatedValue.replace(/<br \/>/g, ' ');
699							done = 1;
700							return false;
701						}
702					})
703				}
704			});
705
706			// If the customized product did not have any textfield, it will have the customizationId as name
707			if (!done)
708				content += customizationIdMessage + customizationId;
709			if (!hasAlreadyCustomizations) content += '</li>';
710			// Field cleaning
711			if (customizationId)
712			{
713				$('#uploadable_files li div.customizationUploadBrowse img').remove();
714				$('#text_fields input').attr('value', '');
715			}
716		});
717
718		if (!hasAlreadyCustomizations)
719		{
720			content += '</ul>';
721			if (!product.hasAttributes) content += '</dd>';
722		}
723		return (content);
724	},
725
726	updateLayer : function(product){
727		if(ajax_popup){
728		$('#layer_cart_product_title').text(product.name);
729		$('#layer_cart_product_attributes').text('');
730		if (product.hasAttributes && product.hasAttributes == true)
731			$('#layer_cart_product_attributes').html(product.attributes);
732		$('#layer_cart_product_price').text(product.price);
733		$('#layer_cart_product_quantity').text(product.quantity);
734		$('.layer_cart_img').html('<img class="layer_cart_img img-responsive" src="' + product.image + '" alt="' + product.name + '" title="' + product.name + '" />');
735
736		
737		var n = parseInt($(window).scrollTop()) + 'px';
738
739		$('.layer_cart_overlay').css('width','100%');
740		$('.layer_cart_overlay').css('height','100%');
741		$('.layer_cart_overlay').show();
742		$('#layer_cart').css({'top': n}).fadeIn('fast');
743		crossselling_serialScroll();
744		}
745		else
746			$('body,html').animate({scrollTop:0},400);
747	},
748
749	//genarally update the display of the cart
750	updateCart : function(jsonData){
751		//user errors display
752		if (jsonData.hasError)
753		{
754			var errors = '';
755			for (error in jsonData.errors)
756				//IE6 bug fix
757				if (error != 'indexOf')
758					errors += $('<div />').html(jsonData.errors[error]).text() + "\n";
759			if (!!$.prototype.fancybox)
760			    $.fancybox.open([
761			        {
762			            type: 'inline',
763			            autoScale: true,
764			            minHeight: 30,
765			            content: '<p class="fancybox-error">' + errors + '</p>'
766			        }
767			    ], {
768			        padding: 0
769			    });
770			else
771			    alert(errors);
772		}
773		else
774		{
775			ajaxCart.updateCartEverywhere(jsonData);
776			ajaxCart.hideOldProducts(jsonData);
777			ajaxCart.displayNewProducts(jsonData);
778			ajaxCart.refreshVouchers(jsonData);
779
780			//update 'first' and 'last' item classes
781			$('.cart_block .products dt').removeClass('first_item').removeClass('last_item').removeClass('item');
782			$('.cart_block .products dt:first').addClass('first_item');
783			$('.cart_block .products dt:not(:first,:last)').addClass('item');
784			$('.cart_block .products dt:last').addClass('last_item');
785		}
786	},
787
788	//update general cart informations everywhere in the page
789	updateCartEverywhere : function(jsonData){
790		$('.ajax_cart_total').text($.trim(jsonData.productTotal));
791
792		if (parseFloat(jsonData.shippingCostFloat) > 0)
793			$('.ajax_cart_shipping_cost').text(jsonData.shippingCost);
794		else if (typeof(freeShippingTranslation) != 'undefined')
795				$('.ajax_cart_shipping_cost').html(freeShippingTranslation);
796
797		$('.ajax_cart_tax_cost').text(jsonData.taxCost);
798		$('.cart_block_wrapping_cost').text(jsonData.wrappingCost);
799		$('.ajax_block_cart_total').text(jsonData.total);
800		$('.ajax_block_cart_total_euro').text(jsonData.totalEuro);
801		$('.ajax-subtotal-euro').text(jsonData.subtotalEuro);
802		$('.ajax-total-euro').text(jsonData.totalEuro);
803		$('.ajax-resume-euro').text(jsonData.totalEuro);
804		$('.ajax_block_products_total').text(jsonData.productTotal);
805        $('.ajax_total_price_wt').text(jsonData.total_price_wt);
806
807		if (parseFloat(jsonData.freeShippingFloat) > 0)
808		{
809			$('.ajax_cart_free_shipping').html(jsonData.freeShipping);
810			$('.freeshipping').fadeIn(0);
811		}
812		else if (parseFloat(jsonData.freeShippingFloat) == 0)
813			$('.freeshipping').fadeOut(0);
814
815		this.nb_total_products = jsonData.nbTotalProducts;
816
817		if (parseInt(jsonData.nbTotalProducts) > 0)
818		{
819			$('.ajax_cart_no_product').hide();
820			$('.ajax_cart_quantity').text(jsonData.nbTotalProducts);
821			$('.ajax_cart_quantity').fadeIn('slow');
822			$('.ajax_cart_total').fadeIn('slow');
823
824			if (parseInt(jsonData.nbTotalProducts) > 1)
825			{
826				$('.ajax_cart_product_txt').each( function (){
827					$(this).hide();
828				});
829
830				$('.ajax_cart_product_txt_s').each( function (){
831					$(this).show();
832				});
833			}
834			else
835			{
836				$('.ajax_cart_product_txt').each( function (){
837					$(this).show();
838				});
839
840				$('.ajax_cart_product_txt_s').each( function (){
841					$(this).hide();
842				});
843			}
844		}
845		else
846		{
847			/*$('.ajax_cart_quantity, .ajax_cart_product_txt_s, .ajax_cart_product_txt, .ajax_cart_total').each(function(){
848				$(this).hide();
849			});*/
850			$('.ajax_cart_product_txt_s, .ajax_cart_product_txt, .ajax_cart_total').each(function(){
851				$(this).hide();
852			});
853			$('.ajax_cart_no_product').show('slow');
854		}
855	}
856};
857
858function HoverWatcher(selector)
859{
860	this.hovering = false;
861	var self = this;
862
863	this.isHoveringOver = function(){
864		return self.hovering;
865	}
866
867	$(selector).hover(function(){
868		self.hovering = true;
869	}, function(){
870		self.hovering = false;
871	})
872}
873
874function crossselling_serialScroll()
875{
876	var selector = "#crossseling_popup_products_slider"
877	$(document).ready(function(){
878
879		var flexmincross = 1;
880		var flexmaxcross = 5;
881			if($('#layer_cart .crossseling-content').width()<=280){ flexmincross = 1;  flexmaxcross = 1; }
882			else if($('#layer_cart .crossseling-content').width()<=440){ flexmincross = 2; flexmaxcross = 2;}
883			else if($('#layer_cart .crossseling-content').width()<980){ flexmincross = 3; flexmaxcross = 3;}
884			else if($('#layer_cart .crossseling-content').width()>=1240){ flexmincross = 5; flexmaxcross = 5;}
885			else if($('#layer_cart .crossseling-content').width()>=980){ flexmincross = 4; flexmaxcross = 4;}
886
887		var checkforloadedcats = [];
888		var firstImage = $(selector).find('img').filter(':first');
889		if(firstImage.length > 0){
890		checkforloadedcats[selector] = setInterval(function() {
891			var image = firstImage.get(0);
892			if (image.complete || image.readyState == 'complete' || image.readyState == 4) {
893				clearInterval(checkforloadedcats[selector]);
894				$(selector).flexslider({
895					namespace: "",
896					animation: "slide",
897					easing: "easeInQuart",
898					slideshow: false,
899					animationLoop: false,
900					animationSpeed: 700,
901					pauseOnHover: true,
902					controlNav: false,
903					itemWidth:  238, 
904					minItems: flexmincross,                   
905					maxItems: flexmaxcross, 
906					move: 0		});	
907			}
908
909		}, 20);
910		}
911
912
913		$(window).resize(function() {
914			try {
915				$(selector).flexslider(0);
916			if($('#layer_cart .crossseling-content').width()<=280){ $(selector).data('flexslider').setOpts({minItems: 1, maxItems: 1});}
917			else if($('#layer_cart .crossseling-content').width()<=440){ $(selector).data('flexslider').setOpts({minItems: grid_size_ms, maxItems: grid_size_ms});}
918			else if($('#layer_cart .crossseling-content').width()<963){ $(selector).data('flexslider').setOpts({minItems: grid_size_sm, maxItems: grid_size_sm});}
919			else if($('#layer_cart .crossseling-content').width()>=1240){ $(selector).data('flexslider').setOpts({minItems: grid_size_lg, maxItems: grid_size_lg});}
920			else if($('#layer_cart .crossseling-content').width()>=963){ $(selector).data('flexslider').setOpts({minItems: grid_size_md, maxItems: grid_size_md});}
921
922		} catch(e) {
923            // handle all your exceptions here
924        }
925
926    });
927	});
928}

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.