jQuery(function(r){if("undefined"==typeof kkart_cart_params)return!1;var a=function(t){return kkart_cart_params.kkart_ajax_url.toString().replace("%%endpoint%%",t)},i=function(t){return t.is(".processing")||t.parents(".processing").length},n=function(t){i(t)||t.addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},s=function(t){t.removeClass("processing").unblock()},o=function(t,e){var o=r.parseHTML(t),c=r(".kkart-cart-form",o),i=r(".cart_totals",o),t=r(".kkart-error, .kkart-message, .kkart-info",o);if(0!==r(".kkart-cart-form").length){if(e||r(".kkart-error, .kkart-message, .kkart-info").remove(),0===c.length){if(r(".kkart-checkout").length)return void window.location.reload();o=r(".cart-empty",o).closest(".kkart");r(".kkart-cart-form__contents").closest(".kkart").replaceWith(o),0 a",this.item_remove_clicked),r(document).on("click",".kkart-cart .restore-item",this.item_restore_clicked),r(document).on("change input",".kkart-cart-form .cart_item :input",this.input_changed),r('.kkart-cart-form :input[name="update_cart"]').prop("disabled",!0).attr("aria-disabled",!0)},input_changed:function(){r('.kkart-cart-form :input[name="update_cart"]').prop("disabled",!1).attr("aria-disabled",!1)},update_cart:function(e){var t=r(".kkart-cart-form");n(t),n(r("div.cart_totals")),r.ajax({type:t.attr("method"),url:t.attr("action"),data:t.serialize(),dataType:"html",success:function(t){o(t,e)},complete:function(){s(t),s(r("div.cart_totals")),r.scroll_to_notices(r('[role="alert"]'))}})},update_cart_totals:function(){n(r("div.cart_totals")),r.ajax({url:a("get_cart_totals"),dataType:"html",success:function(t){p(t)},complete:function(){s(r("div.cart_totals"))}})},input_keypress:function(t){if(13===t.keyCode){var e=r(t.currentTarget).parents("form");try{e[0].checkValidity()&&(t.preventDefault(),this.cart_submit(t))}catch(o){t.preventDefault(),this.cart_submit(t)}}},cart_submit:function(t){var e=r(document.activeElement),o=r(":input[type=submit][clicked=true]"),c=r(t.currentTarget);if(c.is("form")||(c=r(t.currentTarget).parents("form")),0!==c.find(".kkart-cart-form__contents").length)return!i(c)&&void(o.is(':input[name="update_cart"]')||e.is("input.qty")?(t.preventDefault(),this.quantity_update(c)):(o.is(':input[name="apply_coupon"]')||e.is("#coupon_code"))&&(t.preventDefault(),this.apply_coupon(c)))},submit_click:function(t){r(":input[type=submit]",r(t.target).parents("form")).removeAttr("clicked"),r(t.target).attr("clicked","true")},apply_coupon:function(t){n(t);var e=this,o=r("#coupon_code"),c=o.val(),i={security:kkart_cart_params.apply_coupon_nonce,coupon_code:c};r.ajax({type:"POST",url:a("apply_coupon"),data:i,dataType:"html",success:function(t){r(".kkart-error, .kkart-message, .kkart-info").remove(),m(t),r(document.body).trigger("applied_coupon",[c])},complete:function(){s(t),o.val(""),e.update_cart(!0)}})},remove_coupon_clicked:function(t){t.preventDefault();var e=this,o=r(t.currentTarget).closest(".cart_totals"),c=r(t.currentTarget).attr("data-coupon");n(o);t={security:kkart_cart_params.remove_coupon_nonce,coupon:c};r.ajax({type:"POST",url:a("remove_coupon"),data:t,dataType:"html",success:function(t){r(".kkart-error, .kkart-message, .kkart-info").remove(),m(t),r(document.body).trigger("removed_coupon",[c]),s(o)},complete:function(){e.update_cart(!0)}})},quantity_update:function(t){n(t),n(r("div.cart_totals")),r("").attr("type","hidden").attr("name","update_cart").attr("value","Update Cart").appendTo(t),r.ajax({type:t.attr("method"),url:t.attr("action"),data:t.serialize(),dataType:"html",success:function(t){o(t)},complete:function(){s(t),s(r("div.cart_totals")),r.scroll_to_notices(r('[role="alert"]'))}})},item_remove_clicked:function(t){t.preventDefault();var t=r(t.currentTarget),e=t.parents("form");n(e),n(r("div.cart_totals")),r.ajax({type:"GET",url:t.attr("href"),dataType:"html",success:function(t){o(t)},complete:function(){s(e),s(r("div.cart_totals")),r.scroll_to_notices(r('[role="alert"]'))}})},item_restore_clicked:function(t){t.preventDefault();var t=r(t.currentTarget),e=r("form.kkart-cart-form");n(e),n(r("div.cart_totals")),r.ajax({type:"GET",url:t.attr("href"),dataType:"html",success:function(t){o(t)},complete:function(){s(e),s(r("div.cart_totals"))}})}};({init:function(t){this.cart=t,this.toggle_shipping=this.toggle_shipping.bind(this),this.shipping_method_selected=this.shipping_method_selected.bind(this),this.shipping_calculator_submit=this.shipping_calculator_submit.bind(this),r(document).on("click",".shipping-calculator-button",this.toggle_shipping),r(document).on("change","select.shipping_method, :input[name^=shipping_method]",this.shipping_method_selected),r(document).on("submit","form.kkart-shipping-calculator",this.shipping_calculator_submit),r(".shipping-calculator-form").hide()},toggle_shipping:function(){return r(".shipping-calculator-form").slideToggle("slow"),r(document.body).trigger("country_to_state_changed"),!1},shipping_method_selected:function(){var t={};r("select.shipping_method, :input[name^=shipping_method][type=radio]:checked, :input[name^=shipping_method][type=hidden]").each(function(){t[r(this).data("index")]=r(this).val()}),n(r("div.cart_totals"));var e={security:kkart_cart_params.update_shipping_method_nonce,shipping_method:t};r.ajax({type:"post",url:a("update_shipping_method"),data:e,dataType:"html",success:function(t){p(t)},complete:function(){s(r("div.cart_totals")),r(document.body).trigger("updated_shipping_method")}})},shipping_calculator_submit:function(t){t.preventDefault();var e=r(t.currentTarget);n(r("div.cart_totals")),n(e),r("").attr("type","hidden").attr("name","calc_shipping").attr("value","x").appendTo(e),r.ajax({type:e.attr("method"),url:e.attr("action"),data:e.serialize(),dataType:"html",success:function(t){o(t)},complete:function(){s(e),s(r("div.cart_totals"))}})}}).init(t),t.init()});