Files
Falcon-PrestaShop-9/falcon/_dev/js/theme/index.js

114 lines
3.5 KiB
JavaScript

import $ from "jquery";
import "@js/theme/vendors/bootstrap/bootstrap-imports";
import "bootstrap-touchspin";
import "jquery-hoverintent";
import "@js/theme/components/dynamic-bootstrap-components";
import bsCustomFileInput from "bs-custom-file-input";
import "@js/theme/components/selectors";
import "@js/theme/components/sliders";
import "@js/theme/components/responsive";
import "@js/theme/components/customer";
import "@js/theme/components/quickview";
import "@js/theme/components/product";
import "@js/theme/components/cart/cart";
import "@js/theme/components/cart/block-cart";
import usePasswordPolicy from "@js/theme/components/usePasswordPolicy";
import prestashop from "prestashop";
import EventEmitter from "events";
import Form from "@js/theme/components/form";
import TopMenu from "@js/theme/components/TopMenu";
import PageLazyLoad from "@js/theme/components/Lazyload";
import PageLoader from "@js/theme/components/PageLoader";
import useStickyElement from "@js/theme/components/useStickyElement";
/* eslint-disable */
// "inherit" EventEmitter
for (const i in EventEmitter.prototype) {
prestashop[i] = EventEmitter.prototype[i];
}
/* eslint-enable */
prestashop.pageLazyLoad = new PageLazyLoad({
selector: ".lazyload",
});
prestashop.pageLoader = new PageLoader();
function accLinksTriggerActive() {
const currentUrl = window.location.pathname + window.location.search;
$(".js-customer-links a").each((i, el) => {
const $el = $(el);
const linkHref = $el.attr("href");
let linkPath = linkHref;
try {
const linkUrl = new URL(linkHref, window.location.origin);
linkPath = linkUrl.pathname + linkUrl.search;
} catch (e) {}
if (
currentUrl === linkPath ||
(linkPath !== "/" && currentUrl.startsWith(linkPath))
) {
$el.addClass("active");
}
});
}
function initStickyHeader() {
const header = document.querySelector(".js-header-top");
const headerWrapper = document.querySelector(".js-header-top-wrapper");
if (header && headerWrapper) {
useStickyElement(header, headerWrapper);
}
}
// Sync product thumbs height with main images height
function syncThumbsHeight() {
const mainImages = document.querySelector(".product-main-images");
const thumbs = document.querySelector(".product-thumbs.swiper");
// Only apply if Swiper is vertical
if (mainImages && thumbs && thumbs.classList.contains("swiper-vertical")) {
thumbs.style.maxHeight = mainImages.offsetHeight + "px";
thumbs.style.height = mainImages.offsetHeight + "px";
} else {
return;
}
}
window.addEventListener("load", syncThumbsHeight);
window.addEventListener("resize", syncThumbsHeight);
$(() => {
initStickyHeader();
accLinksTriggerActive();
Form.init();
bsCustomFileInput.init();
const topMenu = new TopMenu("#_desktop_top_menu .js-main-menu");
usePasswordPolicy(".field-password-policy");
topMenu.init();
$(".js-select-link").on("change", ({ target }) => {
window.location.href = $(target).val();
});
// Postcode input formatting
const $postCodeInput = $("input[name='postcode']");
$postCodeInput.on("input", function () {
let value = $(this).val();
// Match 4 digits followed by 2 letters (e.g., 1234AB)
const match = value.match(/^(\d{4})([a-zA-Z]{2})$/);
if (match) {
// Add space between numbers and letters
const formatted = `${match[1]} ${match[2]}`;
$(this).val(formatted);
}
});
});