hotspot: setHeight + callbackFN
This commit is contained in:
@@ -294,3 +294,28 @@ function idmObserveOnce(element, callback, options = { root: null, rootMargin:
|
|||||||
|
|
||||||
observer.observe(element);
|
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)
|
||||||
|
}
|
||||||
@@ -46,7 +46,6 @@ const idmGeneralHotspotObjData = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Funkcja inicjalizująca wybranego hotspota(addtobasket range - swiper)
|
// Funkcja inicjalizująca wybranego hotspota(addtobasket range - swiper)
|
||||||
async function idmHotspotInit(id, options={}){
|
async function idmHotspotInit(id, options={}){
|
||||||
try{
|
try{
|
||||||
@@ -149,9 +148,20 @@ async function idmHotspotInit(id, options={}){
|
|||||||
});
|
});
|
||||||
await selectedSwiper.init();
|
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){
|
}catch(err){
|
||||||
console.error(idmHotspotTextObject["Wystąpił błąd z inicjalizacją. Proszę odśwież stronę"], err);
|
console.error(idmHotspotTextObject["Wystąpił błąd z inicjalizacją. Proszę odśwież stronę"], err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("init")
|
|
||||||
@@ -94,6 +94,7 @@ async function idmInsertHotspotObject(idmHotspotObj){
|
|||||||
* - true = aktywny
|
* - true = aktywny
|
||||||
* - false = nieaktywny
|
* - false = nieaktywny
|
||||||
* - object = konfiguracja Swiper
|
* - object = konfiguracja Swiper
|
||||||
|
* @property {Function} options.callbackFn - Funkcja callback która dzieje się po wywołaniu wszystkiego włącznie ze swiperem
|
||||||
*
|
*
|
||||||
* @type {Hotspot[]}
|
* @type {Hotspot[]}
|
||||||
*/
|
*/
|
||||||
@@ -120,6 +121,7 @@ async function idmInsertHotspotObject(idmHotspotObj){
|
|||||||
// lazy: false,
|
// lazy: false,
|
||||||
// addToBasket: "range",
|
// addToBasket: "range",
|
||||||
// swiper: true,
|
// swiper: true,
|
||||||
|
// callbackFn: ()=>{console.log("test")}
|
||||||
// // swiper: albo true false - albo obiekt z opcjami swipera
|
// // swiper: albo true false - albo obiekt z opcjami swipera
|
||||||
// }
|
// }
|
||||||
// },
|
// },
|
||||||
|
|||||||
Reference in New Issue
Block a user