PageSourceSearch

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

js gazzettaregionale.it collected 2026-09-24 18:05:39 UTC 21,484 bytes, 627 lines download raw bytes

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

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.