···11+/* eslint-disable function-paren-newline */
12import 'focus-within-polyfill';
2333-import './global/jquery-migrate';
44+import carousel from './common/carousel';
45import './common/select-option-plugin';
55-import PageManager from './page-manager';
66-import quickSearch from './global/quick-search';
66+import calculatorDropdown from './custom/calculatorDropdown';
77+import descriptionTabs from './custom/descriptionTabs';
88+import cartPreview from './global/cart-preview';
99+import privacyCookieNotification from './global/cookieNotification';
710import currencySelector from './global/currency-selector';
1111+import foundation from './global/foundation';
1212+import './global/jquery-migrate';
1313+import menu from './global/menu';
814import mobileMenuToggle from './global/mobile-menu-toggle';
99-import menu from './global/menu';
1010-import foundation from './global/foundation';
1515+import quickSearch from './global/quick-search';
1116import quickView from './global/quick-view';
1212-import cartPreview from './global/cart-preview';
1313-import privacyCookieNotification from './global/cookieNotification';
1414-import carousel from './common/carousel';
1517import svgInjector from './global/svg-injector';
1616-import calculatorDropdown from './custom/calculatorDropdown';
1717-import descriptionTabs from './custom/descriptionTabs';
1818-import common from './custom/common';
1818+import PageManager from './page-manager';
19192020export default class Global extends PageManager {
2121 onReady() {
···3232 svgInjector();
3333 descriptionTabs();
3434 calculatorDropdown();
3535-36353737- $(document).ready(function() {
3636+ $(() => {
3837 function handleImageVisibility() {
3939- var windowWidth = $(window).width();
4040- var $contentImage = $('#contentImage');
4141-4242- if (windowWidth >= 768) {
4343- var desktopSrc = $contentImage.data('desktop-src');
4444- $contentImage.attr('src', desktopSrc);
4545- } else {
4646- var mobileSrc = $contentImage.data('mobile-src');
4747- $contentImage.attr('src', mobileSrc);
4848- }
3838+ const windowWidth = $(window).width();
3939+ const $contentImage = $('#contentImage');
4040+4141+ if (windowWidth >= 768) {
4242+ const desktopSrc = $contentImage.data('desktop-src');
4343+ $contentImage.attr('src', desktopSrc);
4444+ } else {
4545+ const mobileSrc = $contentImage.data('mobile-src');
4646+ $contentImage.attr('src', mobileSrc);
4747+ }
4948 }
5050-4949+5150 // Initial visibility check
5251 handleImageVisibility();
5353-5252+5453 // Handle visibility on window resize
5555- $(window).resize(function() {
5656- handleImageVisibility();
5454+ $(window).on('resize', () => {
5555+ handleImageVisibility();
5756 });
5858- });
5959- common();
6060-// Function to hide all ".quick-add-to-cart" elements except for the specified card
6161-function hideOtherAddToCartElements(currentCard) {
6262- var allCards = document.querySelectorAll(".card");
6363-6464- allCards.forEach(function (card) {
6565- if (card !== currentCard) {
6666- var addToCartWrapper = card.querySelector(".quick-add-to-cart");
6767-6868- // Check if addToCartWrapper is not null before accessing its style property
6969- if (addToCartWrapper) {
7070- addToCartWrapper.style.display = "none";
7171- }
7272- }
7373- });
7474-}
7575-// Function to hide all ".quick-add-to-cart" elements except for the specified card
7676-function hideOtherAddToCartElements(currentCard) {
7777- var allCards = document.querySelectorAll(".card");
7878-7979- allCards.forEach(function (card) {
8080- if (card !== currentCard) {
8181- var addToCartWrapper = card.querySelector(".quick-add-to-cart");
8282-8383- // Check if addToCartWrapper is not null and does not contain the clicked element
8484- if (addToCartWrapper && !addToCartWrapper.contains(event.target)) {
8585- addToCartWrapper.style.display = "none";
8686- }
8787- }
8888- });
8989-}
9090-9191-// Get all elements with class "quick-cart"
9292-var quickCartElements = document.querySelectorAll(".quick-cart");
9393-9494-// Loop through each "quick-cart" element
9595-quickCartElements.forEach(function (quickCart) {
9696- // Add click event listener to each "quick-cart"
9797- quickCart.addEventListener("click", function (event) {
9898- // Find the parent ".card" element
9999- var card = quickCart.closest(".card");
100100-101101- // Find the ".quick-add-to-cart" within the same card
102102- var addToCartWrapper = card.querySelector(".quick-add-to-cart");
5757+ });
10358104104- // Check if addToCartWrapper is not null before accessing its style property
105105- if (addToCartWrapper) {
106106- // Toggle the visibility of ".quick-add-to-cart"
107107- addToCartWrapper.style.display = addToCartWrapper.style.display === "none" ? "block" : "none";
5959+ $(document).on('click', '.quick-cart', (event) => {
6060+ event.stopPropagation();
6161+ const addToCartWrapper = $(event.currentTarget)
6262+ .closest('.card')
6363+ .find('.quick-add-to-cart');
6464+ addToCartWrapper.toggle();
6565+ });
10866109109- // Hide ".quick-add-to-cart" elements of other cards
110110- hideOtherAddToCartElements(card);
111111- }
6767+ // Add click event listener to the document body to hide ".quick-add-to-cart" when clicking outside
6868+ document.body.addEventListener('click', (event) => {
6969+ const allCards = document.querySelectorAll('.card');
11270113113- // Prevent the click event from propagating to the document body
114114- event.stopPropagation();
115115- });
116116-});
7171+ allCards.forEach((card) => {
7272+ const addToCartWrapper =
7373+ card.querySelector('.quick-add-to-cart');
11774118118-// Add click event listener to the document body to hide ".quick-add-to-cart" when clicking outside
119119-document.body.addEventListener("click", function (event) {
120120- var allCards = document.querySelectorAll(".card");
121121-122122- allCards.forEach(function (card) {
123123- var addToCartWrapper = card.querySelector(".quick-add-to-cart");
7575+ // Check if addToCartWrapper is not null and does not contain the clicked element
7676+ if (
7777+ addToCartWrapper &&
7878+ !addToCartWrapper.contains(event.target)
7979+ ) {
8080+ addToCartWrapper.style.display = 'none';
8181+ }
8282+ });
8383+ });
12484125125- // Check if addToCartWrapper is not null and does not contain the clicked element
126126- if (addToCartWrapper && !addToCartWrapper.contains(event.target)) {
127127- addToCartWrapper.style.display = "none";
128128- }
129129- });
130130-});
131131-132132-// Function to handle the click event on add-quantity buttons
133133-function handleAddQuantityButtonClick() {
134134- // Get all elements with class "add-quantity"
135135- var addQuantityButtons = document.querySelectorAll(".add-quantity span");
136136-137137- // Loop through each "add-quantity" button
138138- addQuantityButtons.forEach(function (button) {
139139- // Add click event listener to each button
140140- button.addEventListener("click", function () {
8585+ $(document).on('click', '.add-quantity span', (event) => {
8686+ event.stopImmediatePropagation();
14187 // Remove the "active" class from all spans
142142- addQuantityButtons.forEach(function (span) {
143143- span.classList.remove("active");
144144- });
8888+ $('.add-quantity span').removeClass('active');
1458914690 // Add the "active" class to the clicked span
147147- button.classList.add("active");
9191+ $(event.currentTarget).addClass('active');
1489214993 // Find the parent ".card" element
150150- var card = button.closest(".card");
9494+ const card = $(event.currentTarget).closest('.card');
1519515296 // Find the related input with class "form-input--incrementTotal"
153153- var incrementTotalInput = card.querySelector(".form-input--incrementTotal");
9797+ const incrementTotalInput = card.find(
9898+ // eslint-disable-next-line comma-dangle
9999+ '.form-input--incrementTotal'
100100+ );
154101155102 // Update the value of the input with the HTML content of the span
156156- incrementTotalInput.value = button.innerHTML;
103103+ incrementTotalInput.val($(event.currentTarget).html());
157104 });
158158- });
159159-}
160160-161161-// Function to reload the script
162162-function reloadScriptIfPageChanged() {
163163- // Reload the script if the page URL contains "?page="
164164- if (window.location.href.indexOf('?page=') > -1) {
165165- handleAddQuantityButtonClick();
166166- }
167167-}
168168-169169-// Call the function on document ready
170170-jQuery(document).ready(function ($) {
171171- handleAddQuantityButtonClick();
172172-173173- // Check for page changes using the popstate event
174174- window.addEventListener('popstate', reloadScriptIfPageChanged);
175175-176176- // Optionally, you can also check for changes on initial load
177177- reloadScriptIfPageChanged();
178178-});
179179-180180-181105 }
182106}