1 line
4.1 KiB
JavaScript
1 line
4.1 KiB
JavaScript
jQuery(document).ready(function(d){function t(s,o,r){var n,i;return o=o||250,function(){var t=r||this,a=+new Date,e=arguments;n&&a<n+o?(clearTimeout(i),i=setTimeout(function(){n=a,s.apply(t,e)},o)):(n=a,s.apply(t,e))}}var m;function a(){var t,r=d(".woocommerce div.product form.cart");r.closest(".elementor-add-to-cart").length?d(".elementor.product").removeClass("do-quantity-buttons"):(t=d(".cart div.quantity:not(.buttons-added), .cart td.quantity:not(.buttons-added)").find(".qty"))&&d.each(t,function(t,a){var e,s=d(a);"date"!==s.prop("type")&&"hidden"!==s.prop("type")&&(s.parent().addClass("buttons-added").prepend('<a href="javascript:void(0)" class="minus">-</a>'),s.after('<a href="javascript:void(0)" class="plus">+</a>'),d("input.qty:not(.product-quantity input.qty)").each(function(){var t=parseFloat(d(this).attr("min"));t&&0<t&&parseFloat(d(this).val())<t&&d(this).val(t)}),d("body").hasClass("single-product")&&!r.hasClass("grouped_form")&&(e=d(".woocommerce form input[type=number].qty")).on("keyup",function(){var t=d(this).val();e.val(t)}),d(".plus, .minus").off("click"),d(".plus, .minus").on("click",function(){var t=!d("body").hasClass("single-product")||r.hasClass("grouped_form")||r.hasClass("cart_group")?d(this).closest(".quantity").find(".qty"):d(".plus, .minus").closest(".quantity").find(".qty"),a=parseFloat(t.val()),e=parseFloat(t.attr("max")),s=parseFloat(t.attr("min")),o=t.attr("step");a&&""!==a&&"NaN"!==a||(a=0),""!==e&&"NaN"!==e||(e=""),""!==s&&"NaN"!==s||(s=0),"any"!==o&&""!==o&&void 0!==o&&"NaN"!==parseFloat(o)||(o=1),d(this).is(".plus")?e&&(e==a||e<a)?t.val(e):t.val(a+parseFloat(o)):s&&(s==a||a<s)?t.val(s):0<a&&t.val(a-parseFloat(o)),t.trigger("change")}))})}d("body").on("added_to_cart",function(){d(".wc-menu-item").hasClass("has-items")||d(".wc-menu-item").addClass("has-items"),d(".wc-mobile-cart-items").hasClass("has-items")||d(".wc-mobile-cart-items").addClass("has-items")}),d("body").on("removed_from_cart",function(){var t=d(".number-of-items");t.length&&t.hasClass("no-items")&&(d(".wc-menu-item").removeClass("has-items"),d(".wc-mobile-cart-items").removeClass("has-items"))}),generateWooCommerce.addToCartPanel&&(d(document.body).on("added_to_cart",function(){var t=d("#wpadminbar"),a=d(".navigation-stick"),e=0;t.length&&(e=t.outerHeight()),a.length&&"0px"===a.css("top")&&(e+=a.outerHeight()),d(".add-to-cart-panel").addClass("item-added").css({"-webkit-transform":"translateY("+e+"px)","-ms-transform":"translateY("+e+"px)",transform:"translateY("+e+"px)"})}),d(".add-to-cart-panel .continue-shopping").on("click",function(t){t.preventDefault(),d(".add-to-cart-panel").removeClass("item-added").css({"-webkit-transform":"translateY(-100%)","-ms-transform":"translateY(-100%)",transform:"translateY(-100%)"})}),d(window).on("scroll",t(function(){var t=d(".add-to-cart-panel");t.hasClass("item-added")&&t.removeClass("item-added").css({"-webkit-transform":"translateY(-100%)","-ms-transform":"translateY(-100%)",transform:"translateY(-100%)"})},250))),generateWooCommerce.stickyAddToCart&&(m=0,d(window).on("scroll",t(function(){var t=d("#wpadminbar"),a=d(".navigation-stick"),e=0,s=d(window).scrollTop(),o=d(".add-to-cart-panel"),r=o.offset().top+o.outerHeight(),n=d(".single_add_to_cart_button"),i=n.offset().top,l=n.outerHeight(),c=d(".site-footer").offset().top;t.length&&(e=t.outerHeight()),a.length&&(a.hasClass("auto-hide-sticky")?(s<m&&"0px"===a.css("top")&&(e+=a.outerHeight()),m=s):e+=a.outerHeight()),i+l<s&&r<c?o.addClass("show-sticky-add-to-cart").css({"-webkit-transform":"translateY("+e+"px)","-ms-transform":"translateY("+e+"px)",transform:"translateY("+e+"px)"}):o.removeClass("show-sticky-add-to-cart").css({"-webkit-transform":"","-ms-transform":"",transform:""})},250)),d(".go-to-variables").on("click",function(t){t.preventDefault();var a=0,e=d(".navigation-stick"),s=d("#wpadminbar");e.length&&(a=e.outerHeight()),s.length&&(a+=s.outerHeight()),d("html, body").animate({scrollTop:d(".variations").offset().top-a},250)})),d(function(){"use strict";generateWooCommerce.quantityButtons&&a()}),d(document).ajaxComplete(function(){"use strict";generateWooCommerce.quantityButtons&&a()})}); |