From ad3e6a88e921db359684ff4e04141af35528f37c Mon Sep 17 00:00:00 2001 From: pgaca Date: Wed, 1 Oct 2025 12:51:29 +0200 Subject: [PATCH] hotspot: setHeight + callbackFN --- sklad/2funkcje.js | 25 +++++++++++++++++++++++++ sklad/4init.js | 18 ++++++++++++++---- sklad/5binsertHotspotObject.js | 2 ++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/sklad/2funkcje.js b/sklad/2funkcje.js index 9d7d495..8b0ad12 100644 --- a/sklad/2funkcje.js +++ b/sklad/2funkcje.js @@ -294,3 +294,28 @@ function idmObserveOnce(element, callback, options = { root: null, rootMargin: observer.observe(element); } + + +//////////////////////////////////////////////// +// IDM SET HEIGHT +app_shop.fn.idmSetHeight = options => { + const { selector, selectors, container } = options || {} + if ((!selector && !selectors) || !container) return + + const containerElement = document.querySelector(container) + if (!containerElement) return + + const adjustAllHeights = itemSelector => { + const targets = containerElement.querySelectorAll(itemSelector) + if (!targets.length) return + + targets.forEach(el => (el.style.minHeight = '')) + + const max = Math.max(...[...targets].map(el => el.offsetHeight || 0)) + + targets.forEach(el => (el.style.minHeight = `${max}px`)) + } + + if (selector) adjustAllHeights(selector) + if (selectors?.length) selectors.forEach(adjustAllHeights) +} \ No newline at end of file diff --git a/sklad/4init.js b/sklad/4init.js index f57f5ef..1f9964a 100644 --- a/sklad/4init.js +++ b/sklad/4init.js @@ -46,7 +46,6 @@ const idmGeneralHotspotObjData = { } } - // Funkcja inicjalizująca wybranego hotspota(addtobasket range - swiper) async function idmHotspotInit(id, options={}){ try{ @@ -149,9 +148,20 @@ async function idmHotspotInit(id, options={}){ }); await selectedSwiper.init(); } + + + if(typeof options?.callbackFn === "function") options?.callbackFn(); + + // IDM setHeight + app_shop.fn.idmSetHeight({ + selectors: [ + `#${id} .product__prices`, + `#${id} .product__name`, + ], + container: `#${id} .products__wrapper`, + }); + console.log(`Initialized hotspot #${id}`); }catch(err){ console.error(idmHotspotTextObject["Wystąpił błąd z inicjalizacją. Proszę odśwież stronę"], err); } -} - -console.log("init") \ No newline at end of file +} \ No newline at end of file diff --git a/sklad/5binsertHotspotObject.js b/sklad/5binsertHotspotObject.js index 30e5643..6231e83 100644 --- a/sklad/5binsertHotspotObject.js +++ b/sklad/5binsertHotspotObject.js @@ -94,6 +94,7 @@ async function idmInsertHotspotObject(idmHotspotObj){ * - true = aktywny * - false = nieaktywny * - object = konfiguracja Swiper + * @property {Function} options.callbackFn - Funkcja callback która dzieje się po wywołaniu wszystkiego włącznie ze swiperem * * @type {Hotspot[]} */ @@ -120,6 +121,7 @@ async function idmInsertHotspotObject(idmHotspotObj){ // lazy: false, // addToBasket: "range", // swiper: true, +// callbackFn: ()=>{console.log("test")} // // swiper: albo true false - albo obiekt z opcjami swipera // } // },