Compare commits
2 Commits
1c3c5e8334
...
2d4cb1c44e
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d4cb1c44e | |||
| 49ff211062 |
24
README.md
24
README.md
@@ -96,11 +96,17 @@ new IdmHotspot({
|
|||||||
* @property {string} [source.hotspotType] - Typ hotspotu (np. "promotion").
|
* @property {string} [source.hotspotType] - Typ hotspotu (np. "promotion").
|
||||||
* @property {number[]} [source.productsId] - Tablica ID produktów.
|
* @property {number[]} [source.productsId] - Tablica ID produktów.
|
||||||
* @property {number} [source.productsMenu] - Identyfikator menu produktów.
|
* @property {number} [source.productsMenu] - Identyfikator menu produktów.
|
||||||
|
* @property {number[]} [source.producersId] - Tablica ID producentów.
|
||||||
|
* @property {number[]} [source.seriesId] - Tablica ID serii.
|
||||||
|
* @property {number[]} [source.parametersId] - Tablica ID grup parametrów.
|
||||||
|
* @property {object} [source.priceRange] - Obiekt z ceną od do.
|
||||||
|
* @property {number} [source.priceRange.from] - cena od
|
||||||
|
* @property {number} [source.priceRange.to] - cena do
|
||||||
|
|
||||||
|
|
||||||
* @property {object} query - Dane zapytania, nadpisują source (DEV).
|
* @property {object} [query] - Dane zapytania, nadpisują source (DEV).
|
||||||
* @property {string} query.string - Zapytanie w formacie GraphQL.
|
* @property {string} [query.string] - Zapytanie w formacie GraphQL.
|
||||||
* @property {Function} query.graphFn - Funkcja do pobierania danych.
|
* @property {Function} [query.graphFn] - Funkcja do pobierania danych.
|
||||||
|
|
||||||
|
|
||||||
* @property {object} options - Ustawienia dla hotspotu (required).
|
* @property {object} options - Ustawienia dla hotspotu (required).
|
||||||
@@ -144,9 +150,6 @@ new IdmHotspot({
|
|||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<script>
|
|
||||||
idmInsertHotspotElement(document.getElementByid("idmBlogHotspot1"));
|
|
||||||
</script>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Żeby zmienić resztę ustawień trzeba zmieniać defaultowe ustawienia!
|
Żeby zmienić resztę ustawień trzeba zmieniać defaultowe ustawienia!
|
||||||
@@ -159,9 +162,14 @@ new IdmHotspot({
|
|||||||
* @property {string} id - Identyfikator elementu (np. "idmBlogHotspot1").
|
* @property {string} id - Identyfikator elementu (np. "idmBlogHotspot1").
|
||||||
* @property {string} class - Klasy CSS używane do stylowania.
|
* @property {string} class - Klasy CSS używane do stylowania.
|
||||||
*
|
*
|
||||||
* @attribute {string} data-products-id - Lista ID produktów (rozdzielona przecinkami).
|
|
||||||
* @attribute {number} data-products-menu - Identyfikator menu produktów.
|
|
||||||
* @attribute {string} data-hotspots-type - Typ hotspotu (np. "promotion").
|
* @attribute {string} data-hotspots-type - Typ hotspotu (np. "promotion").
|
||||||
|
* @attribute {number[]} data-products-id - Lista ID produktów (rozdzielona przecinkami).
|
||||||
|
* @attribute {number} data-products-menu - Identyfikator menu produktów.
|
||||||
|
* @attribute {number[]} data-producers-id - Lista id producentów (rozdzielona przecinkami).
|
||||||
|
* @attribute {number[]} data-series-id - Lista id serii (rozdzielona przecinkami).
|
||||||
|
* @attribute {number[]} data-parameters-id - Lista id grup parametrów (rozdzielona przecinkami).
|
||||||
|
* @attribute {number} data-price-from - "cena od" produktów w hotspocie
|
||||||
|
* @attribute {number} data-price-to - "cena do" produktów w hotspocie
|
||||||
* @attribute {boolean} data-lazy - Czy sekcja ma być ładowana w trybie lazy.
|
* @attribute {boolean} data-lazy - Czy sekcja ma być ładowana w trybie lazy.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
|||||||
118
klasa.js
118
klasa.js
@@ -191,6 +191,7 @@ const IDM_PRODUCT_QUERY = `id
|
|||||||
iconSecond
|
iconSecond
|
||||||
iconSmall
|
iconSmall
|
||||||
iconSmallSecond
|
iconSmallSecond
|
||||||
|
link
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
opinion{
|
opinion{
|
||||||
@@ -508,26 +509,44 @@ class IdmHotspot{
|
|||||||
/**
|
/**
|
||||||
* Przygotowuje funkcję i zapytanie GraphQL w zależności od typu danych.
|
* Przygotowuje funkcję i zapytanie GraphQL w zależności od typu danych.
|
||||||
*/
|
*/
|
||||||
getQueryData({productsID, productsMenu, hotspotsType}){
|
getQueryData(){
|
||||||
let graphFn, query;
|
let graphFn, query;
|
||||||
if(productsID){
|
let queryMarkup = "";
|
||||||
graphFn = IDM_PRODUCTS_GQL;
|
|
||||||
query = `searchInput: {productsId: [${productsID}]}`;
|
if(this.source?.hotspotsType){
|
||||||
}else if(productsMenu){
|
|
||||||
graphFn = IDM_PRODUCTS_GQL;
|
|
||||||
query = `searchInput: {navigation: ${productsMenu}}`;
|
|
||||||
}else if(hotspotsType){
|
|
||||||
graphFn = IDM_HOTSPOTS_GQL;
|
graphFn = IDM_HOTSPOTS_GQL;
|
||||||
query = `searchInput: {hotspot: ${hotspotsType}, limit: 16}`;
|
queryMarkup += `hotspot: ${this.source.hotspotsType}, limit: 16`;
|
||||||
|
}else{
|
||||||
|
graphFn = IDM_PRODUCTS_GQL;
|
||||||
|
if(this.source?.productsId){
|
||||||
|
queryMarkup += `productsId: [${this.source.productsId}],`;
|
||||||
}
|
}
|
||||||
|
if(this.source?.productsMenu){
|
||||||
|
queryMarkup += `navigation: ${this.source.productsMenu},`;
|
||||||
|
}
|
||||||
|
if(this.source?.producersId){
|
||||||
|
queryMarkup += `producers: [${this.source.producersId}],`;
|
||||||
|
}
|
||||||
|
if(this.source?.seriesId){
|
||||||
|
queryMarkup += `series: [${this.source.seriesId}],`;
|
||||||
|
}
|
||||||
|
if(this.source?.parametersId){
|
||||||
|
queryMarkup += `parameters: [${this.source.parametersId.reduce((acc,val)=> acc + `{id: ${val}}`,"")}],`;
|
||||||
|
}
|
||||||
|
if(this.source?.priceRange){
|
||||||
|
queryMarkup += `priceRange: {from: ${+this.source.priceRange?.from || 0}, to: ${+this.source.priceRange?.to || 0}},`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
query = `searchInput: { ${queryMarkup} }`
|
||||||
|
|
||||||
return [graphFn, query];
|
return [graphFn, query];
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Ustawia dane zapytania GraphQL wewnątrz instancji.
|
* Ustawia dane zapytania GraphQL wewnątrz instancji.
|
||||||
*/
|
*/
|
||||||
setQueryData(queryObj){
|
setQueryData(){
|
||||||
const [graphFn, queryString] = this.getQueryData(queryObj);
|
const [graphFn, queryString] = this.getQueryData();
|
||||||
this.query.graphFn = graphFn;
|
this.query.graphFn = graphFn;
|
||||||
this.query.string = queryString;
|
this.query.string = queryString;
|
||||||
}
|
}
|
||||||
@@ -597,6 +616,7 @@ class IdmHotspot{
|
|||||||
</strong>
|
</strong>
|
||||||
</a>
|
</a>
|
||||||
<div class="product__content_wrapper">
|
<div class="product__content_wrapper">
|
||||||
|
${this.markupVersions(prod)}
|
||||||
${this.markupOpinions(prod)}
|
${this.markupOpinions(prod)}
|
||||||
<a class="product__name" tabindex="0" href="${prod.link}" title="${prod.name}">${prod.name}</a>
|
<a class="product__name" tabindex="0" href="${prod.link}" title="${prod.name}">${prod.name}</a>
|
||||||
<div class="product__prices mb-auto ${prodExchangedData?.classes?.add?.reduce((acc,val) => acc + " " + val,"")}">
|
<div class="product__prices mb-auto ${prodExchangedData?.classes?.add?.reduce((acc,val) => acc + " " + val,"")}">
|
||||||
@@ -634,6 +654,16 @@ class IdmHotspot{
|
|||||||
</span>`;
|
</span>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
markupVersions(prod){
|
||||||
|
if(!this.options?.selectVersion || !prod.group?.versions || prod.group?.versions?.length === 1 ) return "";
|
||||||
|
|
||||||
|
return `<div class="product__versions">
|
||||||
|
${prod.group.versions.reduce((acc, val)=>{
|
||||||
|
return acc + `<a class="product__version_single" href="${val.link}"><img class="product__version_img" src="${val.icon}" alt="${val.name}"/></a>`;
|
||||||
|
},"")}
|
||||||
|
</div>`
|
||||||
|
}
|
||||||
|
|
||||||
markupImage(prod){
|
markupImage(prod){
|
||||||
let markup = "";
|
let markup = "";
|
||||||
if(prod.iconSmallSecond && prod.iconSecond) markup +=`<picture>
|
if(prod.iconSmallSecond && prod.iconSecond) markup +=`<picture>
|
||||||
@@ -824,16 +854,19 @@ class IdmHotspot{
|
|||||||
<span class="headline"><span class="headline__name" aria-label="${this.title}">${this.title}</span></span>
|
<span class="headline"><span class="headline__name" aria-label="${this.title}">${this.title}</span></span>
|
||||||
</h3>
|
</h3>
|
||||||
` : ""}
|
` : ""}
|
||||||
<div class="products__wrapper swiper">
|
${this.markupHotspotSwiperContainer()}
|
||||||
|
</div>
|
||||||
|
</section>`;
|
||||||
|
}
|
||||||
|
markupHotspotSwiperContainer(productsHTML=""){
|
||||||
|
return `<div class="products__wrapper swiper">
|
||||||
<div class="products hotspot__products swiper-wrapper">
|
<div class="products hotspot__products swiper-wrapper">
|
||||||
|
${productsHTML}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="swiper-button-prev --rounded --edge idm-button-prev"><i class="icon-angle-left"></i></div>
|
<div class="swiper-button-prev --rounded --edge idm-button-prev"><i class="icon-angle-left"></i></div>
|
||||||
<div class="swiper-button-next --rounded --edge idm-button-next"><i class="icon-angle-right"></i></div>
|
<div class="swiper-button-next --rounded --edge idm-button-next"><i class="icon-angle-right"></i></div>
|
||||||
<div class="swiper-pagination"></div>
|
<div class="swiper-pagination"></div>`;
|
||||||
</div>
|
|
||||||
</section>`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================================================
|
// ========================================================
|
||||||
@@ -1131,11 +1164,7 @@ class IdmHotspot{
|
|||||||
this.initExternalFunctions();
|
this.initExternalFunctions();
|
||||||
try{
|
try{
|
||||||
if(!this.products){
|
if(!this.products){
|
||||||
if(!this?.query?.graphFn || !this?.query?.string) this.setQueryData({
|
if(!this?.query?.graphFn || !this?.query?.string) this.setQueryData();
|
||||||
productsID: this?.source?.productsId,
|
|
||||||
productsMenu: this?.source?.productsMenu,
|
|
||||||
hotspotsType: this?.source?.hotspotsType
|
|
||||||
});
|
|
||||||
|
|
||||||
// pobranie danych o produktach
|
// pobranie danych o produktach
|
||||||
await this.getHotspotData();
|
await this.getHotspotData();
|
||||||
@@ -1144,7 +1173,15 @@ class IdmHotspot{
|
|||||||
|
|
||||||
|
|
||||||
// Wstawienie markupa na strone
|
// Wstawienie markupa na strone
|
||||||
this.hotspotEl.querySelector(".products.hotspot__products")?.insertAdjacentHTML("beforeend", this.markup());
|
if(this.hotspotEl.querySelector(".products.hotspot__products")) this.hotspotEl.querySelector(".products.hotspot__products").insertAdjacentHTML("beforeend", this.markup());
|
||||||
|
else if(this.hotspotEl.querySelector(".hotspot")){
|
||||||
|
this.hotspotEl.querySelector(".hotspot")?.insertAdjacentHTML("beforeend", this.markupHotspotSwiperContainer(this.markup()));
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
throw new Error("Nie udało się wstawić produktów! Zła struktura HTML")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
this.hotspotEl.classList.remove("idm-loading");
|
this.hotspotEl.classList.remove("idm-loading");
|
||||||
|
|
||||||
// init swiper + add to basket
|
// init swiper + add to basket
|
||||||
@@ -1407,7 +1444,7 @@ function idmHideTooltip(tooltipEl){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// document.addEventListener("DOMContentLoaded", ()=>{
|
document.addEventListener("DOMContentLoaded", ()=>{
|
||||||
document.body.addEventListener("click", e=>{
|
document.body.addEventListener("click", e=>{
|
||||||
const tooltipEl = e.target.closest(".idm_tooltip");
|
const tooltipEl = e.target.closest(".idm_tooltip");
|
||||||
if(!e.target.closest(".idm_tooltip__info_icon") || !tooltipEl) return;
|
if(!e.target.closest(".idm_tooltip__info_icon") || !tooltipEl) return;
|
||||||
@@ -1415,18 +1452,30 @@ function idmHideTooltip(tooltipEl){
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
idmShowTooltip(tooltipEl);
|
idmShowTooltip(tooltipEl);
|
||||||
});
|
});
|
||||||
// });
|
});
|
||||||
// new IdmHotspot({
|
// new IdmHotspot({
|
||||||
// id: "idmTestHotspot1",
|
// id: "idmTestHotspot1",
|
||||||
// title: "tescik",
|
// title: "tescik",
|
||||||
|
// products: [] // Tablica produktów
|
||||||
// placement: {
|
// placement: {
|
||||||
// selector: "#content",
|
// selector: "#content",
|
||||||
// insert: "beforeend",
|
// insert: "beforeend",
|
||||||
// },
|
// },
|
||||||
// source: {
|
// source: {
|
||||||
// productsMenu: 1649
|
// productsMenu: 1649,
|
||||||
|
// producersId: [],
|
||||||
|
// seriesId: [],
|
||||||
|
// parametersId: [],
|
||||||
|
// priceRange: {
|
||||||
|
// from: 0,
|
||||||
|
// to: 150,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// options: {
|
||||||
|
// lazy: true,
|
||||||
|
// addToBasket: "range",
|
||||||
|
// swiper: true,
|
||||||
// }
|
// }
|
||||||
// products: [] // Tablica produktów
|
|
||||||
// });
|
// });
|
||||||
// {
|
// {
|
||||||
// id: "idmMainHotspot2",
|
// id: "idmMainHotspot2",
|
||||||
@@ -1450,10 +1499,19 @@ async function idmPrepareHotspotObject(selectedContainerEl){
|
|||||||
selectedContainerEl.classList.add("--init");
|
selectedContainerEl.classList.add("--init");
|
||||||
const source = {};
|
const source = {};
|
||||||
|
|
||||||
if(selectedContainerEl?.dataset?.productsId) source.productsId = selectedContainerEl?.dataset?.productsId.split(",");
|
|
||||||
else if(selectedContainerEl?.dataset?.hotspotsType) source.hotspotsType = selectedContainerEl?.dataset?.hotspotsType;
|
if(selectedContainerEl.dataset?.hotspotsType) source.hotspotsType = selectedContainerEl.dataset.hotspotsType;
|
||||||
else if(selectedContainerEl?.dataset?.productsMenu) source.productsMenu = selectedContainerEl?.dataset?.productsMenu;
|
else {
|
||||||
else{
|
if(selectedContainerEl.dataset?.productsId) source.productsId = selectedContainerEl.dataset.productsId.split(",");
|
||||||
|
if(selectedContainerEl.dataset?.productsMenu) source.productsMenu = selectedContainerEl.dataset.productsMenu;
|
||||||
|
if(selectedContainerEl.dataset?.producersId) source.producersId = selectedContainerEl.dataset.producersId;
|
||||||
|
if(selectedContainerEl.dataset?.seriesId) source.seriesId = selectedContainerEl.dataset.seriesId;
|
||||||
|
if(selectedContainerEl.dataset?.parametersId) source.seriesId = selectedContainerEl.dataset.parametersId;
|
||||||
|
if(selectedContainerEl.dataset?.priceFrom && selectedContainerEl.dataset?.priceTo) source.priceRange = {from: +selectedContainerEl.dataset.priceFrom, to: +selectedContainerEl.dataset.priceTo};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(Object.keys(source).length === 0){
|
||||||
console.error();
|
console.error();
|
||||||
selectedContainerEl?.remove();
|
selectedContainerEl?.remove();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ wersja max 5 zdjęć i później + może????
|
|||||||
- Wybór kolorystyczny???
|
- Wybór kolorystyczny???
|
||||||
- AAAAA - banner na hotspocie
|
- AAAAA - banner na hotspocie
|
||||||
- stary szablon
|
- stary szablon
|
||||||
- cena za kg
|
|
||||||
- blokowanie dodawania do koszyka jeśli ilość jest maksymalna
|
- blokowanie dodawania do koszyka jeśli ilość jest maksymalna
|
||||||
- informacje o producencie albo serri gdzieś nad produktem
|
- informacje o producencie albo serri gdzieś nad produktem
|
||||||
- czy zapisywać wszystkie hotspoty do jakiegoś app_shop.fn.idmHotspots = {"#idmMainHotspot1": {}}
|
- czy zapisywać wszystkie hotspoty do jakiegoś app_shop.fn.idmHotspots = {"#idmMainHotspot1": {}}
|
||||||
|
|||||||
34
style.less
34
style.less
@@ -1,7 +1,3 @@
|
|||||||
.idm__hotspot .btn.add_to_basket__link{
|
|
||||||
margin-top: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.idm__hotspot .add_to_basket{
|
.idm__hotspot .add_to_basket{
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
@@ -227,3 +223,33 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// WERSJE
|
||||||
|
.idm__hotspot:has(.product__versions){
|
||||||
|
.product__versions{
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(5, 1fr);
|
||||||
|
gap: 1rem;
|
||||||
|
z-index: 1;
|
||||||
|
background: #fff;
|
||||||
|
clip-path: inset(0% 0 100% 0);
|
||||||
|
padding: 0.3rem 1rem;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
.product__content_wrapper{
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.label_icons, .product__versions{
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
.product:hover{
|
||||||
|
.product__versions, .label_icons{
|
||||||
|
transform: translateY(-100%);
|
||||||
|
}
|
||||||
|
.product__versions{
|
||||||
|
clip-path: inset(0 0 0 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user