jQuery(function ($) {
// Trigger form submission on orderby change
$(".woocommerce-ordering").on("change", "select.orderby", function () {
$(this).closest("form").trigger("submit");
});
// Ensure quantity is not below minimum value
$("input.qty:not(.product-quantity input.qty)").each(function () {
var min = parseFloat($(this).attr("min"));
if (min >= 0 && parseFloat($(this).val()) < min) {
$(this).val(min);
}
});
// Store notice handling
var noticeId = "store_notice" + ($(".woocommerce-store-notice").data("noticeId") || "");
if (Cookies.get(noticeId) === "hidden") {
$(".woocommerce-store-notice").hide();
} else {
$(".woocommerce-store-notice").show();
}
$(".woocommerce-store-notice__dismiss-link").on("click", function (e) {
Cookies.set(noticeId, "hidden", { path: "/" });
$(".woocommerce-store-notice").hide();
e.preventDefault();
});
// Input wrapper description handling
$(".woocommerce-input-wrapper span.description").length &&
$(document.body).on("click", function () {
$(".woocommerce-input-wrapper span.description:visible")
.prop("aria-hidden", true)
.slideUp(250);
});
$(".woocommerce-input-wrapper").on("click", function (e) {
e.stopPropagation();
});
$(".woocommerce-input-wrapper :input")
.on("keydown", function (e) {
var description = $(this).parent().find("span.description");
if (e.which === 27 && description.length && description.is(":visible")) {
description.prop("aria-hidden", true).slideUp(250);
e.preventDefault();
return false;
}
})
.on("click focus", function () {
var wrapper = $(this).parent();
var description = wrapper.find("span.description");
wrapper.addClass("currentTarget");
$(".woocommerce-input-wrapper:not(.currentTarget) span.description:visible")
.prop("aria-hidden", true)
.slideUp(250);
if (description.length && description.is(":hidden")) {
description.prop("aria-hidden", false).slideDown(250);
}
wrapper.removeClass("currentTarget");
});
// Scroll to notices
$.scroll_to_notices = function (element) {
if (element.length) {
$("html, body").animate(
{
scrollTop: element.offset().top - 100,
},
1000
);
}
};
// Password input visibility toggle
$('.woocommerce form .woocommerce-Input[type="password"]').wrap('');
$(".woocommerce form input")
.filter(":password")
.parent("span")
.addClass("password-input");
$(".password-input").append('');
$(".show-password-input").on("click", function () {
$(this).toggleClass("display-password");
if ($(this).hasClass("display-password")) {
$(this).siblings('input[type="password"]').prop("type", "text");
} else {
$(this).siblings('input[type="text"]').prop("type", "password");
}
});
});