;(function(o){"use strict";var i={body:o("body"),modal:o("#woolentor-quickview-modal"),modalbody:o(".woolentor-quickview-modal-body"),init:function(){this.wrapperHeight();o(document).on("click.WooLentorQuickView","a.woolentor-quickview-btn,.woolentorquickview",this.openQuickView).on("click.WooLentorQuickView",".woolentor-quickview-modal-close",this.closeQuickView).on("click.WooLentorQuickView",".woolentor-quickview-overlay",this.closeQuickView);o(document).keyup(this.closeKeyUp);if(woolentorQuickView.optionData["enableAjaxCart"]==="on"){o(document).on("click.WooLentorQuickView",".woolentor-quickview-modal-content .woolentorquickview-content-template:not(.external) .single_add_to_cart_button:not(.disabled)",this.addToCart)}},openQuickView:function(e){e.preventDefault();var t=o(this),a=t.data("product_id");i.modalbody.html("");i.body.addClass("woolentor-quickview-loader");t.addClass("loading");i.modal.addClass("loading");o.ajax({url:woolentorQuickView.ajaxUrl,data:{action:"woolentor_quickview",id:a,nonce:woolentorQuickView.ajaxNonce},method:"POST",success:function(e){if(e){i.body.removeClass("woolentor-quickview-loader");i.modal.removeClass("loading").addClass("woolentor-quickview-open");t.removeClass("loading");i.modalbody.html(e);i.variation(i.modalbody);o(document).trigger("woolentor_quick_view_rendered");if(woolentorQuickView.optionData["thumbnailLayout"]==="slider"){i.imageSlider()}}else{console.log("Something wrong loading fetching product data")}},error:function(o){console.log("Something wrong with AJAX response.")},complete:function(){t.removeClass("loading")}})},variation:function(e){var t=e.find(".variations_form");t.each(function(){o(this).wc_variation_form()});t.trigger("check_variations");t.trigger("reset_image");if(typeof o.fn.wc_product_gallery!=="undefined"){e.find(".woocommerce-product-gallery").each(function(){o(this).wc_product_gallery()})}if(woolentorQuickView.optionData["thumbnailLayout"]==="slider"){i.variationData(e)}},variationData:function(i){o(".single_variation_wrap").on("show_variation",function(o,e){i.find(".woolentor-quickview-main-image-slider").slick("slickGoTo",0)})},closeQuickView:function(o){o.preventDefault();i.modal.removeClass("woolentor-quickview-open")},closeKeyUp:function(o){if(o.keyCode===27){i.modal.removeClass("woolentor-quickview-open")}},wrapperHeight:function(){var i=o(window).width(),e=o(window).height();o(".woolentor-quickview-modal-wrapper").css({"max-height":e-150+"px"})},MainImageSlider:function(){o(".woolentor-quickview-main-image-slider").slick({slidesToShow:1,slidesToScroll:1,arrows:true,fade:true,asNavFor:".woolentor-quickview-thumbnail-slider",prevArrow:'',nextArrow:''})},ThumbnailSlider:function(){o(".woolentor-quickview-thumbnail-slider").slick({slidesToShow:4,slidesToScroll:1,asNavFor:".woolentor-quickview-main-image-slider",dots:false,arrows:true,focusOnSelect:true,prevArrow:'',nextArrow:''})},imageSlider:function(){this.MainImageSlider();this.ThumbnailSlider()},addToCart:function(i){i.preventDefault();var e=o(this),t=e.closest("form.cart"),a=t.serialize(),n=t.find("input[name=quantity]").val()||1,r=t.find("input[name=product_id]").val()||e.val(),l=t.find("input[name=variation_id]").val()||0;var c={},d=t.find("select[name^=attribute]");if(!d.length){d=t.find("[name^=attribute]:checked")}if(!d.length){d=t.find("input[name^=attribute]")}d.each(function(){var i=o(this),e=i.attr("name"),t=i.val(),a,n;i.removeClass("error");if(t.length===0){a=e.lastIndexOf("_");n=e.substring(a+1);i.addClass("required error")}else{c[e]=t}});var s={product_id:r,product_sku:"",quantity:n,variation_id:l,variations:c,all_data:a};var u=s.all_data+"&product_id="+s.product_id+"&product_sku="+s.product_sku+"&quantity="+s.quantity+"&variation_id="+s.variation_id+"&variations="+JSON.stringify(s.variations)+"&action=woolentor_quickview_insert_to_cart"+"&nonce="+woolentorQuickView.ajaxNonce;o(document.body).trigger("adding_to_cart",[e,s]);o.ajax({type:"POST",url:woolentorQuickView.ajaxUrl,data:u,beforeSend:function(o){e.removeClass("added").addClass("loading")},complete:function(o){e.addClass("added").removeClass("loading")},success:function(i){if(i.error&i.product_url){window.location=i.product_url;return}else{o(document.body).trigger("wc_fragment_refresh");o(document.body).trigger("added_to_cart",[i.fragments,i.cart_hash,e])}}})}};o(document).ready(function(){i.init();o(window).on("resize",i.wrapperHeight)})})(jQuery);