Skip to content

Commit aa6b847

Browse files
committed
Update productPage.js
1 parent fec2706 commit aa6b847

File tree

1 file changed

+59
-46
lines changed

1 file changed

+59
-46
lines changed

assets/js/components/productPage.js

Lines changed: 59 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -684,25 +684,34 @@ function priplatky(setupData, texts) {
684684
}
685685
}
686686

687+
// Otevře akordeon, zachová max 2 otevřená okna (nejstarší zavře), scrolluje na nové
688+
function openNextAccordion($next) {
689+
$next.addClass("active");
690+
const $allOpen = $(
691+
".content-wrap > .position-wrap.active, .content-wrap > .parameter-wrap.active, " +
692+
".upsale-buttons.trunk.active, .upsale-buttons.boxs.active"
693+
);
694+
if ($allOpen.length > 2) {
695+
$allOpen.first().removeClass("active");
696+
}
697+
// Čekáme na dokončení CSS animací předchozích akordeonů, pak teprve počítáme offset
698+
setTimeout(() => {
699+
$("html, body").animate({ scrollTop: $next.offset().top - 80 }, 400);
700+
}, 600);
701+
}
702+
687703
// Single event listener for .upsale-button
688704
$(document).on("click", ".upsale-button", function (e) {
689705
// Check if the clicked element is within .upsale-buttons.trunk
690706
updateUpsale(this, e);
691707

692-
// Po výběru koberce: otevři boxs sekci a zavři trunk
708+
// Po výběru koberce: otevři boxs sekci
693709
const $trunk = $(this).closest(".upsale-buttons.trunk");
694710
if ($trunk.length && !$(this).hasClass("none")) {
695711
setTimeout(() => {
696712
const $boxs = $(".upsale-buttons.boxs");
697713
if ($boxs.is(":visible")) {
698-
// Nejdřív zavři trunk, pak až layout usadí otevři boxs a scrolluj
699-
$trunk.removeClass("active");
700-
setTimeout(() => {
701-
$boxs.addClass("active");
702-
setTimeout(() => {
703-
$("html, body").animate({ scrollTop: $boxs.offset().top - 80 }, 400);
704-
}, 400);
705-
}, 500);
714+
openNextAccordion($boxs);
706715
}
707716
}, 600);
708717
}
@@ -1379,49 +1388,53 @@ $("body").on("click", ".button.option-button", function (e) {
13791388
}
13801389
}, 200);
13811390

1382-
// Auto-postup pro kroky 2+ (kroky 0 a 1 zůstávají na tlačítko)
1391+
// Auto-postup pro všechny wrappy s next-step-button kromě kroku 0 a 1
13831392
const $currentWrap = $(this).closest(".position-wrap, .parameter-wrap");
13841393
const orderNum = parseInt($currentWrap.find(".order").first().text());
1385-
if (!isNaN(orderNum) && orderNum >= 2) {
1386-
const allWraps = $(".content-wrap").children(".position-wrap, .parameter-wrap");
1387-
const currentIndex = allWraps.index($currentWrap);
1388-
if (currentIndex >= 0 && currentIndex < allWraps.length - 1) {
1389-
setTimeout(() => {
1390-
$currentWrap.removeClass("active");
1391-
setTimeout(() => {
1392-
const $next = allWraps.eq(currentIndex + 1);
1393-
$next.addClass("active");
1394-
$("html, body").animate({ scrollTop: $next.offset().top - 80 }, 400);
1395-
}, 600);
1396-
}, 800);
1397-
}
1398-
}
1399-
1400-
if (!$(".goToAction")[0]) {
1401-
console.log("goToAction");
1402-
1403-
// Nejdřív zavři aktuální krok
1404-
$currentWrap.removeClass("active");
1394+
const isStep0or1 = orderNum === 0 || orderNum === 1;
1395+
const hasNextBtn = $currentWrap.find(".next-step-button").length > 0;
1396+
const isInBoxConfig = !!$currentWrap.closest(".config-wrap, .box-config").length;
14051397

1398+
if (hasNextBtn && !isStep0or1 && !isInBoxConfig) {
1399+
// Hledáme next wrap se zpožděním 400ms — dáme čas Shoptetu přidat nové dynamické kroky do DOM
14061400
setTimeout(() => {
1407-
$(".upsale-Banner").fadeIn(400);
1408-
$(".upsale-Banner").show();
1409-
$(".upsale-buttons.position-wrap.parameter-cars.parameter-wrap.boxs").hide();
1410-
1411-
if ($(".upsale-buttons.position-wrap.trunk .upsale-button.radio.active")[0]) {
1412-
$(".upsale-buttons.position-wrap.parameter-cars.parameter-wrap.boxs").show().addClass("active");
1413-
} else {
1414-
// Otevři trunk sekci, scrolluj až po dokončení fadeIn
1415-
const $trunk = $(".upsale-buttons.trunk");
1416-
$trunk.addClass("active");
1417-
setTimeout(() => {
1418-
$("html, body").animate({ scrollTop: $trunk.offset().top - 80 }, 400);
1419-
}, 450);
1401+
const allContentWraps = $(".content-wrap").children(".position-wrap, .parameter-wrap");
1402+
const contentIndex = allContentWraps.index($currentWrap);
1403+
1404+
let $nextWrap = null;
1405+
if (contentIndex >= 0 && contentIndex < allContentWraps.length - 1) {
1406+
$nextWrap = allContentWraps.eq(contentIndex + 1);
1407+
} else if (contentIndex === -1) {
1408+
// Dynamicky přidaný wrap mimo content-wrap — hledej next sibling v tom samém parentu
1409+
const $siblings = $currentWrap.parent().children(".position-wrap, .parameter-wrap");
1410+
const sibIndex = $siblings.index($currentWrap);
1411+
if (sibIndex >= 0 && sibIndex < $siblings.length - 1) {
1412+
$nextWrap = $siblings.eq(sibIndex + 1);
1413+
}
14201414
}
1421-
if (!$(".parameter-id-" + koberce)[0]) {
1422-
$(".upsale-buttons.boxs").show().addClass("active");
1415+
1416+
if ($nextWrap) {
1417+
openNextAccordion($nextWrap);
1418+
} else if (!$(".goToAction")[0]) {
1419+
console.log("goToAction");
1420+
$(".upsale-Banner").fadeIn(400);
1421+
$(".upsale-Banner").show();
1422+
$(".upsale-buttons.position-wrap.parameter-cars.parameter-wrap.boxs").hide();
1423+
1424+
if ($(".upsale-buttons.position-wrap.trunk .upsale-button.radio.active")[0]) {
1425+
const $boxs = $(".upsale-buttons.boxs");
1426+
$boxs.show();
1427+
openNextAccordion($boxs);
1428+
} else {
1429+
openNextAccordion($(".upsale-buttons.trunk"));
1430+
}
1431+
if (!$(".parameter-id-" + koberce)[0]) {
1432+
const $boxs = $(".upsale-buttons.boxs");
1433+
$boxs.show();
1434+
openNextAccordion($boxs);
1435+
}
14231436
}
1424-
}, 800);
1437+
}, 400);
14251438
}
14261439
});
14271440
function priceActualization(e) {

0 commit comments

Comments
 (0)