jQuery(document).ready(function(i){i(document).on("click",".product a.compare:not(.added)",function(o){o.preventDefault();var e=i(this),t={action:yith_woocompare.actionadd,id:e.data("product_id"),context:"frontend"},a=i(".yith-woocompare-widget ul.products-list");void 0!==i.fn.block&&(e.block({message:null,overlayCSS:{background:"#fff url("+yith_woocompare.loader+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}}),a.block({message:null,overlayCSS:{background:"#fff url("+yith_woocompare.loader+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}})),i.ajax({type:"post",url:yith_woocompare.ajaxurl.toString().replace("%%endpoint%%",yith_woocompare.actionadd),data:t,dataType:"json",success:function(o){void 0!==i.fn.block&&(e.unblock(),a.unblock()),e.addClass("added").attr("href",o.table_url).text(yith_woocompare.added_label),a.html(o.widget_table),"yes"==yith_woocompare.auto_open&&i("body").trigger("yith_woocompare_open_popup",{response:o.table_url,button:e})}})}),i(document).on("click",".product a.compare.added",function(o){o.preventDefault();var e=this.href;void 0!==e&&i("body").trigger("yith_woocompare_open_popup",{response:e,button:i(this)})}),i("body").on("yith_woocompare_open_popup",function(o,e){var t=e.response;if(768<=i(window).width())i.colorbox({href:t,iframe:!0,width:"90%",height:"90%",className:"yith_woocompare_colorbox",close:yith_woocompare.close_label,onClosed:function(){var e=i(".yith-woocompare-widget ul.products-list"),o={action:yith_woocompare.actionreload,context:"frontend"};void 0!==i.fn.block&&e.block({message:null,overlayCSS:{background:"#fff url("+yith_woocompare.loader+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}}),i.ajax({type:"post",url:yith_woocompare.ajaxurl.toString().replace("%%endpoint%%",yith_woocompare.actionreload),data:o,success:function(o){void 0!==i.fn.block&&e.unblock().html(o),e.html(o)}})}}),i(window).resize(function(){i.colorbox.resize({width:"90%",height:"90%"})});else{var a=t.split("?");if(2<=a.length){for(var r=encodeURIComponent("iframe")+"=",c=a[1].split(/[&;]/g),n=c.length;0<n--;)-1!==c[n].lastIndexOf(r,0)&&c.splice(n,1);t=a[0]+"?"+c.join("&")}window.open(t,yith_woocompare.table_title)}}),i(document).on("click",".remove a",function(o){o.preventDefault();var t=i(this),e={action:yith_woocompare.actionremove,id:t.data("product_id"),context:"frontend"};i("td.product_"+e.id+", th.product_"+e.id);void 0!==i.fn.block&&t.block({message:null,overlayCSS:{background:"#fff url("+yith_woocompare.loader+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}}),i.ajax({type:"post",url:yith_woocompare.ajaxurl.toString().replace("%%endpoint%%",yith_woocompare.actionremove),data:e,dataType:"html",success:function(o){var e=i(o).filter("#yith-woocompare");i("#yith-woocompare").replaceWith(e),i('.compare[data-product_id="'+t.data("product_id")+'"]',window.parent.document).removeClass("added").html(yith_woocompare.button_text),i(window).trigger("yith_woocompare_product_removed")}})}),i(".yith-woocompare-open a, a.yith-woocompare-open").on("click",function(o){o.preventDefault(),i("body").trigger("yith_woocompare_open_popup",{response:function(o,e){o=escape(o),e=escape(e);var t=document.location.search,a=o+"="+e,r=new RegExp("(&|\\?)"+o+"=[^&]*");t=t.replace(r,"$1"+a),RegExp.$1||(t+=(0<t.length?"&":"?")+a);return t}("action",yith_woocompare.actionview)+"&iframe=true"})}),i(".yith-woocompare-widget").on("click","a.compare",function(o){o.preventDefault(),i("body").trigger("yith_woocompare_open_popup",{response:i(this).attr("href")})}).on("click","li a.remove, a.clear-all",function(o){o.preventDefault();var e=i(".yith-woocompare-widget .products-list").data("lang"),t=i(this),a=t.data("product_id"),r={action:yith_woocompare.actionremove,id:a,context:"frontend",responseType:"product_list",lang:e},c=t.parents(".yith-woocompare-widget").find("ul.products-list");void 0!==i.fn.block&&c.block({message:null,overlayCSS:{background:"#fff url("+yith_woocompare.loader+") no-repeat center",backgroundSize:"16px 16px",opacity:.6}}),i.ajax({type:"post",url:yith_woocompare.ajaxurl.toString().replace("%%endpoint%%",yith_woocompare.actionremove),data:r,dataType:"html",success:function(o){"all"==a?i(".compare.added").removeClass("added").html(yith_woocompare.button_text):i('.compare[data-product_id="'+a+'"]').removeClass("added").html(yith_woocompare.button_text),c.html(o),void 0!==i.fn.block&&c.unblock()}})}),i("body").on("added_to_cart",function(o,e,t,a){i(a).closest("table.compare-list").length&&a.hide()})});