From 3e23a8f62876bb874a97f5198196c0b9afabb50c Mon Sep 17 00:00:00 2001 From: kkrzowski Date: Thu, 20 Nov 2025 14:31:06 +0100 Subject: [PATCH] fix --- index.js | 141 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 59 deletions(-) diff --git a/index.js b/index.js index 75dd477..6db12bf 100644 --- a/index.js +++ b/index.js @@ -1,83 +1,106 @@ -class IdmQuantityPicker{ - constructor({selector , min, max, ref}) { - const container = selector ? document.querySelector(selector) : ref; +class IdmBasketHotspot { + + constructor({ selector, products }) { + const container = document.querySelector(selector); if(!container){ - console.error("IdmQuantityPicker: container not found."); + console.error("IdmBasketHotspotConstructor: container not found.") return; } - this.container=container; - const input = this.container.querySelector(".idm-quantity-picker__input"); - if(!input){ - console.error("IdmQuantityPicker: input not found"); + if(!products){ + console.error("IdmBasketHotspotConstructor: no products") return; } - this.input = input; - - if(typeof min === "undefined"){ - min = this.input.min; - }else{ - this.input.min=min; - } - - if(typeof min === "undefined"){ - max = this.input.max; - }else{ - this.input.max=max; - } - - this.min = min; - this.max = max; - this._value = Number.parseInt(input.value); + this.container = container; + this.products = [...products]; + this.init(); } - updateInput(){ - this.input.value = this._value; + getCard(){ + return `
+
+
+ NAZWA PRODUKTU +
+ +
+

ROYAL CANIN Mini Adult 2x8kg karma sucha dla psów dorosłych, ras małych

+
+
+ 35,66 zł / szt.52,34 zł +
+
44,34 zł - Najniższa cena z ostatnich 30 dni przed obniżką
+
+
+
+ +
+ + +
+ + + +
+ + + +
+ +
`; } - // unused - get value() { - return this._value; - } - set value(newValue) { - if (newValue < this.min || newValue > this.max) return; - - this._value = newValue; - this.updateInput(); - } - - handlePlus(){ - this.value++; + getContent(){ + return ` +
+ do -50% TANIEJ +
+

Skorzystaj z oferty promocyjnej

+

Kup produkt do 50% taniej.

+
+
+
+ ${this.products.map(product => this.getCard(product)).join("")} +
+ ` } - handleMinus(){ - this.value--; + render(){ + this.container.innerHTML = this.getContent(); } initEvents(){ - const minusButton = this.container.querySelector(".idm-quantity-picker__minus"); - const plusButton = this.container.querySelector(".idm-quantity-picker__plus"); - - if(!minusButton){ - console.error("IdmQuantityPicker: minus button not found."); - return; - } - - if(!plusButton){ - console.error("IdmQuantityPicker: plus button not found."); - return; - } - - minusButton.addEventListener("click", () => this.handleMinus()); - plusButton.addEventListener("click", () => this.handlePlus()); + const quantityPickers = this.container.querySelectorAll(".idm-quantity-picker"); + quantityPickers.forEach(picker => new IdmQuantityPicker({ref:picker})); } - init(){ - console.log("IdmQuantityPicker: init."); + + init() { + console.log("IdmBasketHotspot: init."); + this.render(); this.initEvents(); } } \ No newline at end of file