if ( window.XDomainRequest ) { jQuery.ajaxTransport(function( s ) { if ( s.crossDomain /*&& s.async*/ ) { if ( s.timeout ) { s.xdrTimeout = s.timeout; delete s.timeout; } var xdr; return { send: function( _, complete ) { function callback( status, statusText, responses, responseHeaders ) { xdr.onload = xdr.onerror = xdr.ontimeout = jQuery.noop; xdr = undefined; complete( status, statusText, responses, responseHeaders ); } xdr = new XDomainRequest(); xdr.onload = function() { callback( 200, "OK", { text: xdr.responseText }, "Content-Type: " + xdr.contentType ); }; xdr.onerror = function() { callback( 404, "Not Found" ); }; xdr.onprogress = jQuery.noop; xdr.ontimeout = function() { callback( 0, "timeout" ); }; xdr.timeout = s.xdrTimeout || Number.MAX_VALUE; xdr.open( s.type, s.url ); xdr.send( ( s.hasContent && s.data ) || null ); }, abort: function() { if ( xdr ) { xdr.onerror = jQuery.noop; xdr.abort(); } } }; } }); } var vn_sessionid = ''; if(vn_sessionid==''){ var jqXHR=$.ajax({ type: 'get', url: 'http://edicola.liberoquotidiano.it/vnlibero/webservice/shop/getSession.jsp', data: { _: new Date().getTime() }, xhrFields: { withCredentials: true }, crossDomain: true, dataType: 'json', async: false, success: function(json){ vn_sessionid=json.jsessionid; $.ajax({ type: 'get', url: '/webservices/saveVnSession.jsp', data: { jsessionid: vn_sessionid } }) } }); } simpleCart.checkoutTo="Custom"; simpleCart.currency= 'EUR'; //$.support.cors = true; CartItem.prototype._link = function(outputValue){ return ''+outputValue+''; }; var timeout_hoverCart; function toggleCart(){ if(simpleCart.quantity===0){ $('.cartInfo').hide(); $('.hoverCart').hide(); }else{ $('.cartInfo').show(); } } function getProductInfo(_productId, callback){ $.ajax({ type: 'get', url: 'http://edicola.liberoquotidiano.it/vnlibero/webservice/getProductInfo.jsp;jsessionid='+vn_sessionid, data: { productId: _productId, _: new Date().getTime() }, dataType:'json', cache: false, success: function(json){ callback(json); } }); } function getBundleInfo(_bundleId, callback){ $.ajax({ type: 'get', url: 'http://edicola.liberoquotidiano.it/vnlibero/webservice/getProductInfo.jsp;jsessionid='+vn_sessionid, data: { showOffers: true, limit: 0, offerId: _bundleId, _: new Date().getTime() }, dataType:'json', cache: false, success: function(json){ callback(json); } }); } function getProductsChildInfo(_productId, callback){ $.ajax({ type: 'get', url: 'http://edicola.liberoquotidiano.it/vnlibero/webservice/getProductChildsInfo.jsp;jsessionid='+vn_sessionid, data: { parentId: _productId, _: new Date().getTime() }, dataType:'json', cache: false, success: function(json){ callback(json); } }); } function saveVnChart(json){ $.ajax({ url: '/actions/saveVnChart.jsp', dataType: 'json', type: 'post', data: { chart: JSON.stringify(json) } }); } function send_stats(productId, event, label){ if(typeof typeof push_stats != 'undefined' ){ push_stats('Libero Quotidiano', event, label); } } function popolateCart(items){ simpleCart.clear(); function setMedia(media){ $(items).each( function() { if(media.id == this.product.issues.replace('MEDIA-', '')){ this.product.productName = media.title + ' - '+this.product.productName; this.product.imageAbsoluteLink = media.image_link; } }); } var mediaIds = []; $.each( items, function(index, prod){ var mediaId=prod.product.issues.replace('MEDIA-', ''); if(prod.product.issues.indexOf('MEDIA-')!=-1){ if(mediaId && mediaId!=''){ if(mediaIds.indexOf(mediaId)==-1) mediaIds.push(mediaId); } } }); if(mediaIds.length > 0 ){ $.ajax({ url: '/actions/getMedia.jsp', dataType: 'json', data: { id: mediaIds }, success: function( medias ){ $.each( medias, function(index, media){ setMedia(media) }); $.each( items, function(index, prodotto){ simpleCartAdd(prodotto,prodotto.cartQuantity); }); } }); }else{ $.each( items, function(index, prodotto){ simpleCartAdd(prodotto,prodotto.cartQuantity); }); } } function addBundle(bundleId){ $.ajax({ type: 'get', url: 'http://edicola.liberoquotidiano.it/vnlibero/webservice/shop/cartAdd.jsp;jsessionid='+vn_sessionid, data: { offerId: bundleId, _: new Date().getTime() }, xhrFields: { withCredentials: true }, crossDomain: true, dataType: 'json', success: function(json) { if(json.success){ popolateCart(json.cart.items); saveVnChart(json); if(typeof stats != 'undefined' ){ getBundleInfo(bundleId, function(json){ try{ send_stats(bundleId, stats.event.addBundle, json[0].name); }catch(e){} }); } $('.hoverCart').show(); timeout_hoverCart=window.setTimeout(function(){ $('.hoverCart').hide() },5000); } } }); } function addProduct(item, disable_alert){ var dataParameters = { productId: item.productid, _: new Date().getTime() }; if(item.issues){ dataParameters.elementId = item.issues; } $.ajax({ type: 'get', url: 'http://edicola.liberoquotidiano.it/vnlibero/webservice/shop/cartAdd.jsp;jsessionid='+vn_sessionid, data: dataParameters, xhrFields: { withCredentials: true }, crossDomain: true, dataType: 'json', success: function(json) { if(json.success){ //aggiungo var prodotto; $.each(json.cart.items, function(index, _prodotto){ if( parseInt(_prodotto.product.productId,10) == item.productid ){ prodotto=_prodotto; return false; } }); if(typeof prodotto !== 'undefined'){ if(!disable_alert){ } popolateCart(json.cart.items) saveVnChart(json); if(typeof stats != 'undefined' ){ send_stats(item.productid, stats.event.addProduct, prodotto.product.productName); } $('.hoverCart').show(); timeout_hoverCart=window.setTimeout(function(){ $('.hoverCart').hide() },5000); } }else{ var errorMessage = json.errorMessage; $.confirm({ 'title' : '', 'message' : errorMessage, 'buttons' : {'Ok':{'class':'blue'}} }); } } }); } var removingProduct=false; function removeProduct(item,removeAll){ if(removingProduct) return; removingProduct=true; $.ajax({ type: 'get', url: 'http://edicola.liberoquotidiano.it/vnlibero/webservice/shop/cartRemove.jsp;jsessionid='+vn_sessionid, data: { productId: item.productid, removeAll: (removeAll), _: new Date().getTime(), elementId: item.issues }, xhrFields: { withCredentials: true }, crossDomain: true, dataType: 'json', success: function(json) { popolateCart(json.cart.items); saveVnChart(json); if(typeof stats != 'undefined' ){ getProductInfo(item.productid, function(prodotto){ send_stats(item.productid, stats.event.removeProduct, prodotto[0].productName); }); } if(removeAll){ $('.add_simpleCart.simpleCartItemAdded').removeClass('simpleCartItemAdded'); }else if(item.productid){ $('.add_simpleCart[productid="'+item.productid+'"]').removeClass('simpleCartItemAdded'); } removingProduct=false; } }); } function simpleCartAdd(prodotto,quantity){ var image = ''; if(prodotto.product.imageAbsoluteLink){ image=prodotto.product.imageAbsoluteLink; }else if(prodotto.product.imageLink){ image='http://www.liberoquotidiano.it/resizer_ext.jsp?w=100&h=-1&maximize=true&img='+encodeURIComponent(prodotto.product.imageLink); } simpleCart.add('productid='+prodotto.product.productId, 'issues='+prodotto.product.issues, 'quantity='+(typeof quantity === "undefined"?1:quantity), 'price='+prodotto.singlePrice, 'descrizione='+prodotto.product.productName.replace(new RegExp('\n', 'g'),'
') , 'immagine='+image ); $('.add_simpleCart[productid="'+prodotto.product.productId+'"]').addClass('simpleCartItemAdded'); } // refreshCart window.setInterval(function(){ var currentItems = {}; simpleCart.each(function(item){ currentItems[item.id] = {}; simpleCart.each( item , function( value , x , name ){ if( name !== "id" ){ currentItems[item.id][name] = value; } }); }); currentItems = escape( JSON.stringify( currentItems ) ); simpleCart.load(); simpleCart.updateTotals(); if(localStorage.getItem('sc_simpleCart_items') !== currentItems){ simpleCart.update(); } toggleCart(); }, 1000); simpleCart.bind('afterAdd', function(){ toggleCart(); }); simpleCart.bind('afterRemove', function(){ toggleCart(); }); simpleCart.bind('beforeIncrement', function(item){ addProduct(item, true); return false; }); simpleCart.bind('beforeDecrement', function(item){ removeProduct(item, false); }); simpleCart.bind('beforeRemove', function(item){ removeProduct(item,true); }); simpleCart.bind('afterEmpty', function(){ toggleCart(); $.ajax({ type: 'get', url: 'http://edicola.liberoquotidiano.it/vnlibero/webservice/shop/cartRemove.jsp;jsessionid='+vn_sessionid, data: { clearCart: true, _: new Date().getTime() }, xhrFields: { withCredentials: true }, crossDomain: true, dataType: 'json', success: function(json) { saveVnChart(json); } }); }); simpleCart.bind('customCheckout', function(){ location.href= '/widget/shop/pre_checkout.jsp?cartUrl='+encodeURIComponent(location.href)+(typeof checkoutParameters != 'undefined'?'&'+checkoutParameters:''); }); simpleCart.ready(function(){ $.ajax({ type: 'get', url: '/actions/getVnChart.jsp', dataType: 'json', success: function(json) { simpleCart.clear(); if(json) popolateCart(json.cart.items); } }); }); $(function(){ toggleCart(); $('.cartInfo').bind('mouseenter mouseover click',function(){ try{ window.clearTimeout(timeout_hoverCart); }catch(e){} $('.cartInfo').bind('mouseleave mouseout ',function(){ $('.hoverCart').hide(); }); $('.hoverCart').show(); }); $('.hoverCart').bind('mouseenter mouseover click',function(){ try{ window.clearTimeout(timeout_hoverCart); }catch(e){} $('.hoverCart').show(); $('.cartInfo').unbind('mouseleave mouseout'); $('.hoverCart').bind('mouseleave mouseout',function(){ $('.hoverCart').hide(); }); }); //evento aggiunta carrello $(document).on('click','.add_simpleCart[productid]',function(){ var productId=parseInt($(this).attr('productid'),10); var productType=parseInt($(this).data('type'),10); var mediaId=$(this).attr('mediaid'); var item={}; item.productid = productId; if(mediaId){ item.issues = 'MEDIA-'+mediaId; } if(productType==0 || isNaN(productType)) addProduct(item, false); else addBundle(productId); }); //evento oggetto non disponibile $(document).on('click','.disponibilita_0[productid]',function(){ $.confirm({ 'title' : '', 'message' : 'Prodotto non disponibile', 'buttons' : {'Ok':{'class':'blue'}} }); }); });