Skip to content

Commit 9c10d9c

Browse files
committed
fix(welcomepage): add back 0s transition handle
1 parent 9a6e370 commit 9c10d9c

3 files changed

Lines changed: 49 additions & 4 deletions

File tree

playground/local-dev/config.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ export default {
6262
logger.debug("Resetting top scroll format");
6363
}
6464
},
65+
{
66+
format: AdvantageFormatName.WelcomePage,
67+
// uncomment to show/hide UI elements
68+
options: {
69+
closeButtonAnimationDuration: 0,
70+
},
71+
setup: (wrapper, ad) => {
72+
console.log(wrapper, ad);
73+
return new Promise<void>((resolve, reject) => {
74+
resolve();
75+
});
76+
},
77+
close: () => {
78+
logger.debug("Closing welcome page format");
79+
},
80+
reset: () => {
81+
logger.debug("Resetting welcome page format");
82+
}
83+
},
6584
{
6685
format: AdvantageFormatName.DoubleMidscroll,
6786
options: {

playground/local-dev/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
</head>
1818

1919
<body>
20-
<advantage-wrapper id="allowed-formats-wrapper">
20+
<advantage-wrapper>
2121
<div slot="advantage-ad-slot">
2222
<iframe
23-
src="./topscroll/topscroll.html"
23+
src="./welcomepage/welcomepage.html"
2424
title="advantage-ad"
2525
style="border: 0; width: 0; height: 0"
2626
scrolling="no"

src/advantage/formats/welcomepage.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export const welcomePage: AdvantageFormat = {
3434
if (ad) {
3535
setDimensionsUntilAdvantageAdSlot(ad);
3636
}
37+
if (config.closeButtonAnimationDuration !== undefined) {
38+
wrapper.style.setProperty(
39+
"--adv-wp-transition-duration",
40+
`${config.closeButtonAnimationDuration}s`
41+
);
42+
}
3743

3844
// Change the content of the UI layer
3945
const uiContainer = document.createElement("div");
@@ -123,8 +129,11 @@ export const welcomePage: AdvantageFormat = {
123129
resetDimensionsUntilAdvantageAdSlot(ad);
124130
}
125131
wrapper.resetCSS();
132+
wrapper.style.removeProperty("--adv-wp-transition-duration");
126133
},
127134
close: (wrapper) => {
135+
const container = wrapper.shadowRoot?.getElementById("container");
136+
128137
function handleTransitionEnd() {
129138
wrapper.style.display = "none";
130139
// Remove the event listener after it has been executed
@@ -134,8 +143,25 @@ export const welcomePage: AdvantageFormat = {
134143
);
135144
}
136145

137-
const container = wrapper.shadowRoot?.getElementById("container");
138-
container?.addEventListener("transitionend", handleTransitionEnd);
146+
if (container) {
147+
const computedStyle = window.getComputedStyle(container);
148+
const transitionProperty = computedStyle.transitionProperty;
149+
const transitionDuration = computedStyle.transitionDuration;
150+
151+
const hasTransition =
152+
transitionProperty !== "none" &&
153+
transitionDuration.split(",").some((d) => parseFloat(d) > 0);
154+
155+
if (!hasTransition) {
156+
wrapper.style.display = "none";
157+
wrapper.classList.remove("show");
158+
wrapper.style.height = "0px";
159+
return;
160+
}
161+
162+
container.addEventListener("transitionend", handleTransitionEnd);
163+
}
164+
139165
wrapper.classList.remove("show");
140166
wrapper.style.height = "0px";
141167
}

0 commit comments

Comments
 (0)