PageSourceSearch

https://www.gazzettaregionale.it/widget/shop/simpleCartCustom.jsp?v=3

js gazzettaregionale.it collected 2026-10-02 03:41:11 UTC 21,486 bytes, 628 lines download raw bytes

1
2			
3
4			if(window.XDomainRequest){
5				jQuery.ajaxTransport(function(s){
6					if(s.crossDomain){
7						if(s.timeout){
8							s.xdrTimeout = s.timeout;
9							delete s.timeout;
10						}
11						var xdr;
12						return {
13							send: function(_, complete){
14								function callback(status, statusText, responses, responseHeaders){
15									xdr.onload = xdr.onerror = xdr.ontimeout = jQuery.noop;
16									xdr = undefined;
17									complete(status, statusText, responses, responseHeaders);
18								}
19								xdr = new XDomainRequest();
20								xdr.onload = function(){
21								  callback(200, "OK", { text: xdr.responseText }, "Content-Type: " + xdr.contentType);
22								};
23								xdr.onerror = function(){
24								  callback(404, "Not Found");
25								};
26								xdr.onprogress = jQuery.noop;
27								xdr.ontimeout = function(){
28								  callback(0, "timeout");
29								};
30								xdr.timeout = s.xdrTimeout || Number.MAX_VALUE;
31								xdr.open( s.type, s.url );
32								xdr.send((s.hasContent && s.data) || null);
33							},
34							abort: function() {
35								if(xdr){
36									xdr.onerror = jQuery.noop;
37									xdr.abort();
38								}
39							}
40						};
41					}
42				});
43			}
44                        
45			var cart_vn_sessionid = '';
46			var vn_language = 'it';
47			var MYR = 'MYR'; //Additional currencies
48			
49			// reload from the stored cart_vn_sessionid 
50			$.ajax({
51				type: 'get',
52				url: '/webservices/handleVnSession.jsp',
53				success: function(result) {
54					// Parse the result if it is returned as a string
55                                        var parsedResult = typeof result === 'string' ? JSON.parse(result) : result;
56
57                                        if (parsedResult && !parsedResult.sessionIdSet) {
58                                            console.log('Cannot Find VNP Session');
59                                        } else {
60                                            console.log('VNP Session Found: ' + parsedResult.vnSessionId);
61                                            cart_vn_sessionid = parsedResult.vnSessionId;
62                                            // Legacy
63                                            vn_sessionid = parsedResult.vnSessionId;
64                                        }
65				} 
66			}); 
67			
68			simpleCart.checkoutTo = "Custom";
69			simpleCart.currency = 'EUR';
70			
71			CartItem.prototype._link = function(outputValue){
72			  return '<a href="'+this.link+'">'+outputValue+'</a>';
73			};
74			
75			var timeout_hoverCart;
76			
77			function toggleCart(){
78				if(simpleCart.quantity === 0){
79					$('.cartInfo').hide();
80					$('.hoverCart').hide();
81				}else{
82				  $('.cartInfo').show();
83				}
84			}
85			
86			function getProductInfo(_productId, callback){
87				$.ajax({
88					type: 'get',
89					url: 'https://edicola.gazzettaregionale.it/gazzettaregionale/webservice/getProductInfo.jsp;jsessionid='+cart_vn_sessionid,
90					data: { productId: _productId, _: new Date().getTime() },
91					dataType:'json',
92					cache: false,
93					success: function(json){
94					  callback(json);
95					}
96				});
97			}
98			
99			function getBundleInfo(_bundleId, callback){
100				$.ajax({
101					type: 'get',
102					url: 'https://edicola.gazzettaregionale.it/gazzettaregionale/webservice/getProductInfo.jsp;jsessionid='+cart_vn_sessionid,
103					data: { showOffers: true, limit: 0, offerId: _bundleId, _: new Date().getTime() },
104					dataType:'json',
105					cache: false,
106					success: function(json){
107					  callback(json);
108					}
109				});
110			}
111			
112			function getProductsChildInfo(_productId, callback){
113				$.ajax({
114					type: 'get',
115					url: 'https://edicola.gazzettaregionale.it/gazzettaregionale/webservice/getProductChildsInfo.jsp;jsessionid='+cart_vn_sessionid,
116					data: { parentId: _productId, _: new Date().getTime() },
117					dataType:'json',
118					cache: false,
119					success: function(json){
120					  callback(json);
121					}
122				});
123			}
124
125			function send_stats(productId, event, label){
126				if(typeof typeof push_stats != 'undefined'){
127				  push_stats('Gazzetta Regionale', event, label);
128				}
129			}
130
131			function popolateCart(cart){
132				simpleCart.clear();
133				simpleCart.currency = cart.currency;
134
135				$.each( cart.items, function(index, prodotto){
136					if(prodotto.product.custom1){
137						prodotto.product.productName = prodotto.product.custom1 + ' - ' + prodotto.product.productName;
138					}
139					if(prodotto.product.custom2){
140						prodotto.product.imageAbsoluteLink = prodotto.product.custom2;
141					}
142					
143					simpleCartAdd(prodotto,prodotto.cartQuantity);
144				});
145
146				// store a slimmed-down cart into the session: keep only the fields the
147				// payment pages actually read (cart.total and, per item, productId +
148				// cartQuantity + totalPrice). Heavy product fields (name, description,
149				// images, custom, issues) are re-fetched from getProductInfo.jsp, so we
150				// drop them here to keep the payload small. POST instead of GET so the
151				// content travels in the body and never exceeds the URL length limit.
152				var cartjson = '';
153				if (cart !== null) {
154					var slimCart = { total: cart.total, items: [] };
155					if (cart.items) {
156						$.each(cart.items, function(index, prodotto){
157							slimCart.items.push({
158								cartQuantity: prodotto.cartQuantity,
159								totalPrice: prodotto.totalPrice,
160								product: { productId: prodotto.product.productId }
161							});
162						});
163					}
164					cartjson = JSON.stringify({ cart: slimCart });
165				}
166
167				$.ajax({
168					type: 'post',
169					url: '/webservices/saveVnSession.jsp',
170					data: { cart_content: cartjson },
171					success: function(){
172					}
173				});
174			}
175
176			function addBundle(bundleId){
177				$.ajax({
178					type: 'get',
179					url: 'https://edicola.gazzettaregionale.it/gazzettaregionale/webservice/shop/cartAdd.jsp;jsessionid='+cart_vn_sessionid,
180					data: { offerId: bundleId, _: new Date().getTime(), language: vn_language },
181					xhrFields: { withCredentials: true },
182					crossDomain: true,
183					dataType: 'json',
184					success: function(json){
185						if(json.success){
186							popolateCart(json.cart);
187							
188							if(typeof stats != 'undefined'){
189								getBundleInfo(bundleId, function(json){
190									try{
191										send_stats(bundleId, stats.event.addBundle, json[0].name);
192									}catch(e){}
193								});
194							}
195							
196							$('.hoverCart').show();
197							timeout_hoverCart=window.setTimeout(function(){
198							  $('.hoverCart').hide()
199							},5000);
200						}
201					}
202				});
203			}
204			
205			//show added article message
206			var showMessageAfterSuccess = false;
207			
208			function addProduct(item, disable_alert){
209				var dataParameters = {
210					productId: item.productid,
211					_: new Date().getTime(),
212					language: vn_language,
213					fromCMS: true
214				};
215
216        if(item.issues !== undefined) dataParameters.elementId = item.issues;
217        if(item.custom1 !== undefined) dataParameters.custom1 = item.custom1;
218        if(item.custom2 !== undefined) dataParameters.custom2 = item.custom2;
219        if(item.custom3 !== undefined) dataParameters.custom3 = item.custom3;
220        if(item.custom4 !== undefined) dataParameters.custom4 = item.custom4;
221        if(item.custom5 !== undefined) dataParameters.custom5 = item.custom5;
222        if(item.quantity !== undefined) {
223			dataParameters.quantity = item.quantity + 1;
224		}
225				
226				function _addProduct(){
227					$.ajax({
228						type: 'get',
229						url: 'https://edicola.gazzettaregionale.it/gazzettaregionale/webservice/shop/cartAdd.jsp;jsessionid='+cart_vn_sessionid,
230						data: dataParameters,
231						xhrFields: { withCredentials: true },
232						crossDomain: true,
233						dataType: 'json',
234						success: function(json){
235						  if(json.success){
236								//aggiungo
237								var prodotto;
238								$.each(json.cart.items, function(index, _prodotto){
239									if(parseInt(_prodotto.product.productId,10) === Number(item.productid)){
240										prodotto = _prodotto;
241										return false;
242									}
243								});
244
245								if(typeof prodotto !== 'undefined'){
246								  if(!disable_alert){
247											if(showMessageAfterSuccess){
248											  if($.isFunction(showAddedArticleMessage)){
249											    showMessageAfterSuccess = false;
250											    showAddedArticleMessage();
251											  }
252											}
253								  }else{
254								    if(showMessageAfterSuccess){
255								      if($.isFunction(myfunc)){
256								        showMessageAfterSuccess = false;
257								        showAddedArticleMessage();
258								      }
259								    }
260								  }
261								  
262								  popolateCart(json.cart)
263									if(typeof stats != 'undefined'){
264									  send_stats(item.productid, stats.event.addProduct, prodotto.product.productName);
265									}
266								 
267									$('.hoverCart').show();
268									timeout_hoverCart=window.setTimeout(function(){
269									  $('.hoverCart').hide()
270									},5000);
271								}
272						  }else{
273						    var errorMessage = json.errorMessage;
274								$.confirm({
275									'title'		: '',
276									'message'	: errorMessage,
277									'buttons'	: {'Ok':{'class':'blue'}}
278								});
279						  }
280						}
281					});
282				}
283	
284				if(item.mediaId){
285					$.ajax({
286						url: '/actions/getMedia.jsp',
287						dataType: 'json',
288						data: { 'id[]': item.mediaId },
289						success: function( medias ){
290							var media = medias[0];
291							dataParameters['custom1['+item.productid+']'] = media.title;
292							dataParameters['custom2['+item.productid+']'] = media.image_link;
293							_addProduct();
294						}
295					});
296				}else{
297					_addProduct();
298				}
299			}
300			
301			var removingProduct = false;
302			function removeProduct(item,removeAll){
303				if(removingProduct) return;
304				removingProduct = true;
305				$.ajax({
306					type: 'get',
307					url: 'https://edicola.gazzettaregionale.it/gazzettaregionale/webservice/shop/cartRemove.jsp;jsessionid='+cart_vn_sessionid,
308					data: { productId: item.productid, removeAll: (removeAll), _: new Date().getTime(), elementId: item.issues },
309					xhrFields: { withCredentials: true },
310					crossDomain: true,
311					dataType: 'json',
312					success: function(json){
313						popolateCart(json.cart);
314						
315						if(typeof stats != 'undefined'){
316							getProductInfo(item.productid, function(prodotto){
317							  send_stats(item.productid, stats.event.removeProduct, prodotto[0].productName);
318							});
319						}
320						
321						if(removeAll){
322						  $('.add_simpleCart.simpleCartItemAdded').removeClass('simpleCartItemAdded');
323						}else if(item.productid){
324						  $('.add_simpleCart[data-productid="'+item.productid+'"]').removeClass('simpleCartItemAdded');
325						}
326						removingProduct = false;
327					}
328				});
329			}
330
331			function simpleCartAddProduct(prodotto, quantity, description, image) {
332				simpleCart.add('productid='+prodotto.product.productId,
333					'issues='+prodotto.product.issues,
334					'quantity='+(typeof quantity === "undefined"?1:quantity),
335					'price='+prodotto.singlePrice,
336					'descrizione='+description.replace(new RegExp('\n', 'g'),'<br />') ,
337					'immagine='+image
338				);
339				$('.add_simpleCart[data-productid="'+prodotto.product.productId+'"]').addClass('simpleCartItemAdded');
340			}
341
342			function simpleCartAdd(prodotto,quantity){
343				var image = '';
344
345				if(prodotto.product.imageAbsoluteLink){
346					image = prodotto.product.imageAbsoluteLink;
347				}else if(prodotto.product.imageLink){
348					image = 'https://www.gazzettaregionale.it/resizer_ext.jsp?w=100&h=-1&maximize=true&img='+encodeURIComponent(prodotto.product.imageLink);
349				}
350				var description = '<span class="vcProductTitle">' + prodotto.product.productName + '</span>';
351				if(prodotto.product.productDescription.length > 0){
352				  description += '\n<span class="vcProductDescription">' + prodotto.product.productDescription + '</span>';
353				}
354
355
356				simpleCartAddProduct(prodotto, quantity, description, image);
357
358			}
359
360			// refreshCart
361			window.setInterval(function(){
362                        
363                                // if the cookie exists it re-align the status with vnp (it means vnp has changed the status, usually after a successfull chekout)
364                                if (document.cookie.split('; ').find(row => row.startsWith('cart_status_changed='))) {
365
366                                    console.log("VirtualCms - Re-align VNP cart");
367                                
368                                    $.ajax({
369                                        type: 'get',
370                                        url: 'https://edicola.gazzettaregionale.it/gazzettaregionale/webservice/shop/cart.jsp;jsessionid=' + cart_vn_sessionid,
371                                        xhrFields: { withCredentials: true },
372                                        crossDomain: true,
373                                        dataType: 'json',
374                                        success: function(json){
375                                                simpleCart.clear();
376                                                if (json) popolateCart(json.cart);
377                                        }
378                                    });
379                                    
380                                    var hostnameParts = window.location.hostname.split('.');
381                                    var domain = window.location.hostname;
382
383                                    // at least 2 parts (es. www.miosito.it → ['www','miosito','it'])
384                                    if (hostnameParts.length > 2) {
385                                        domain = hostnameParts.slice(-2).join('.'); // 'miosito.it'
386                                    }
387
388                                    // rimozione cookie
389                                    // set cookie
390                                    document.cookie = "cart_status_changed=; Max-Age=0; path=/; domain=" + domain;
391                                }
392                        
393				var currentItems = {};
394				simpleCart.each(function(item){
395					currentItems[item.id] = {};
396					simpleCart.each( item , function( value , x , name ){
397						if(name !== "id"){
398						  currentItems[item.id][name] = value;
399						}
400					});
401				});
402				currentItems = escape(JSON.stringify(currentItems));
403				simpleCart.load();
404				simpleCart.updateTotals();
405				if(localStorage.getItem('sc_simpleCart_items') !== currentItems){
406				  simpleCart.update();
407				}
408				toggleCart();
409			}, 1000);
410			
411			simpleCart.bind('afterAdd', function(){
412			  toggleCart();
413			});
414			simpleCart.bind('afterRemove', function(){
415			  toggleCart();
416			});
417			simpleCart.bind('beforeIncrement', function(item){
418				addProduct(item, true);
419				return false;
420			});
421			simpleCart.bind('beforeDecrement', function(item){
422			  removeProduct(item, false);
423			});
424			simpleCart.bind('beforeRemove', function(item){
425			  removeProduct(item,true);
426			});
427			simpleCart.bind('afterEmpty', function(){
428				toggleCart();
429				$.ajax({
430					type: 'get',
431					url: 'https://edicola.gazzettaregionale.it/gazzettaregionale/webservice/shop/cartRemove.jsp;jsessionid='+cart_vn_sessionid,
432					data: { clearCart: true, _: new Date().getTime() },
433					xhrFields: { withCredentials: true },
434					crossDomain: true,
435					dataType: 'json',
436					success: function(json){}
437				});
438			});
439
440			/*
441			 * Riduce il carrello VNP ai soli due campi che pre_checkout.jsp legge davvero
442			 * (product.productId e cartQuantity), accorpando le righe con lo stesso
443			 * productId e sommandone le quantita'. La forma del JSON resta identica,
444			 * quindi lato server non cambia nulla: il cartSummary generato e' lo stesso.
445			 * Senza questa riduzione l'intero carrello (descrizioni, url immagini, label)
446			 * finisce in querystring e con poche foto si supera la lunghezza massima
447			 * di url ammessa dalla CDN, che risponde 414.
448			 */
449			function buildPrunedVnpCart(cart){
450				var quantities = {},
451					order = [],
452					items = (cart && cart.cart && Array.isArray(cart.cart.items)) ? cart.cart.items : [];
453
454				items.forEach(function(item){
455					if(!item || !item.product || item.product.productId == null){
456						return;
457					}
458
459					var productId = String(item.product.productId);
460					var quantity = parseInt(item.cartQuantity, 10);
461					if(isNaN(quantity) || quantity <= 0){
462						quantity = 1;
463					}
464
465					if(quantities[productId] === undefined){
466						quantities[productId] = 0;
467						order.push(productId);
468					}
469					quantities[productId] += quantity;
470				});
471
472				var prunedItems = order.map(function(productId){
473					return {
474						product: { productId: parseInt(productId, 10) },
475						cartQuantity: quantities[productId]
476					};
477				});
478
479				return { cart: { items: prunedItems } };
480			}
481
482			simpleCart.bind('customCheckout', function(){
483				// find the items actually into the cart
484				var items = '';
485				simpleCart.each(function(item){
486					items += item.productid + ',';
487				});
488
489				// Base checkout url
490				var checkoutUrl = '/widget/shop/pre_checkout.jsp?cartUrl='+encodeURIComponent(location.href)+(typeof checkoutParameters != 'undefined'?'&'+checkoutParameters:'') + '&items=' + items;
491
492				// Read the VNP cart client-side (browser session) and pass it to pre_checkout.jsp as cartJson,
493				// so the server can build the cartSummary without re-reading cart.jsp under a different session.
494				// Only the fields the server actually reads are sent (see buildPrunedVnpCart), to keep the url short.
495				// If the call fails, checkoutUrl stays without cartJson and pre_checkout.jsp keeps its legacy behavior.
496				try {
497					$.ajax({
498						type: 'get',
499						url: 'https://edicola.gazzettaregionale.it/gazzettaregionale/webservice/shop/cart.jsp;jsessionid=' + cart_vn_sessionid,
500						async: false,
501						xhrFields: { withCredentials: true },
502						crossDomain: true,
503						dataType: 'json',
504						success: function(cart){
505							if(cart){
506								checkoutUrl += '&cartJson=' + encodeURIComponent(JSON.stringify(buildPrunedVnpCart(cart)));
507							}
508						}
509					});
510				} catch(e) {
511					// ignore: fallback to legacy server-side behavior
512				}
513
514				location.href = checkoutUrl;
515			});
516
517			//Override of currency managment in the simpleCart.js script
518			simpleCart.currencySymbol = function() {
519			  switch(simpleCart.currency){
520			    case CHF:
521			      return "CHF&nbsp;";
522					case CZK:
523					  return "CZK&nbsp;";
524					case DKK:
525					  return "DKK&nbsp;";
526					case HUF:
527					  return "HUF&nbsp;";
528					case NOK:
529					  return "NOK&nbsp;";
530					case PLN:
531					  return "PLN&nbsp;";
532					case SEK:
533					  return "SEK&nbsp;";
534					case JPY:
535					  return "&yen;";
536					case EUR:
537					  return "&euro;";
538					case GBP:
539					  return "&pound;";
540					case CHF:
541					  return "CHF&nbsp;";
542					case THB:
543					  return "&#3647;";
544					case MYR:
545					  return "RM&nbsp;";
546					case USD:
547					case CAD:
548					case AUD:
549					case NZD:
550					case HKD:
551					case SGD:
552					  return "&#36;";
553					default:
554					  return "";
555			  }
556			};
557			
558			$(function(){
559			  toggleCart();
560					
561			  $('.cartInfo').bind('mouseenter mouseover click',function(){
562					try{ window.clearTimeout(timeout_hoverCart); }catch(e){}
563					$('.cartInfo').bind('mouseleave mouseout ',function(){
564					  $('.hoverCart').hide();
565					});
566					$('.hoverCart').show();
567			  });
568	
569				$('.hoverCart').bind('mouseenter mouseover click',function(){
570					try{ window.clearTimeout(timeout_hoverCart); }catch(e){}
571					$('.hoverCart').show();
572					$('.cartInfo').unbind('mouseleave mouseout');
573					$('.hoverCart').bind('mouseleave mouseout',function(){
574					  $('.hoverCart').hide();
575					});
576				});
577					
578				//evento aggiunta carrello
579				$(document).on('click','.add_simpleCart[data-productid]',function(){
580					var productId = parseInt($(this).attr('data-productid'),10);
581					var productType = parseInt($(this).data('type'),10);
582					var mediaId = $(this).attr('mediaid');
583					var articlePresetId = $(this).attr('articlepresetid');
584					var downloadLinkArticleId = $(this).attr('downloadlinkarticleid');
585					var item = {};
586					// used only by photomanager to send photographer's name, article title and eyelet to VNP
587					var custom3 = $(this).attr('data-custom3');
588					var custom4 = $(this).attr('data-custom4');
589					var custom5 = $(this).attr('data-custom5');
590
591					if(custom3){
592						item.custom3 = custom3;
593					}
594
595					if(custom4){
596						item.custom4 = custom4;
597					}
598
599					if(custom5){
600						item.custom5 = custom5;
601					}
602
603					item.productid = productId;
604					
605					if(mediaId){
606						item.mediaId = mediaId;
607						item.issues = 'MEDIA-'+mediaId;
608					} else if(articlePresetId){
609						item.issues = 'ARTICLEPRESET-'+articlePresetId;
610					} else if(downloadLinkArticleId){
611						item.issues = 'DOWNLOADLINKARTICLEID-'+downloadLinkArticleId;
612					}
613					
614					if(productType === 0 || isNaN(productType))
615					  addProduct(item, false);
616					else
617					  addBundle(productId);
618				});
619				
620				//evento oggetto non disponibile
621				$(document).on('click','.disponibilita_0[data-productid]',function(){
622					$.confirm({
623						'title'		: '',
624						'message'	: 'Prodotto non disponibile',
625						'buttons'	: {'Ok':{'class':'blue'}}
626					});
627				});
628			});

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.