-
Notifications
You must be signed in to change notification settings - Fork 1
fix: handle 0s transition duration in close animations and improve st… #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
75f1d15
11d96f0
e6abe73
0abdce6
219e7ae
92b7c31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>WelcomePage Test (No Animation)</title> | ||
| <script src="https://cdn.tailwindcss.com"></script> | ||
| <style> | ||
| html { | ||
| overflow-x: hidden; | ||
| } | ||
| </style> | ||
| <script> | ||
| window.advantageCmdQueue = window.advantageCmdQueue || []; | ||
| </script> | ||
| <script type="module" src="./welcomepage-test.ts"></script> | ||
| </head> | ||
| <body> | ||
| <div class="container mx-auto px-4 py-4"> | ||
| <h1 class="text-2xl font-bold mb-4">WelcomePage Test</h1> | ||
| <p class="mb-4"> | ||
| This page tests the WelcomePage format with | ||
| <code>closeButtonAnimationDuration: 0</code>. | ||
| </p> | ||
| <p class="mb-4"> | ||
| Click the "To [Site Title]" button in the ad to close it. It | ||
| should close immediately without getting stuck. | ||
| </p> | ||
|
|
||
| <!-- The wrapper that will load the WelcomePage ad --> | ||
| <advantage-wrapper> | ||
| <div slot="advantage-ad-slot"> | ||
| <!-- Pointing to the existing welcomepage creative --> | ||
| <iframe | ||
| src="./welcomepage/welcomepage.html" | ||
| title="advantage-ad" | ||
| style="border: 0; width: 100vw; height: 100%" | ||
| scrolling="no" | ||
| ></iframe> | ||
| </div> | ||
| </advantage-wrapper> | ||
|
|
||
| <div class="mt-8"> | ||
| <p>Content below the ad...</p> | ||
| <p> | ||
| Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed | ||
| do eiusmod tempor incididunt ut labore et dolore magna | ||
| aliqua. | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { Advantage } from "@src/advantage"; | ||
| import { AdvantageFormatName } from "@src/types"; | ||
| import logger from "@src/utils/logging"; | ||
|
|
||
| const advantage = Advantage.getInstance(); | ||
|
|
||
| advantage.configure({ | ||
| formatIntegrations: [ | ||
| { | ||
| format: AdvantageFormatName.WelcomePage, | ||
| options: { | ||
| // Set to 0 to test the fix for no-animation close | ||
| closeButtonAnimationDuration: 0, | ||
| autoCloseDuration: 0 // Disable auto-close for manual testing | ||
| }, | ||
| setup: () => { | ||
| return new Promise<void>((resolve) => { | ||
| logger.debug("Setting up WelcomePage format integration"); | ||
| resolve(); | ||
| }); | ||
| }, | ||
| close: () => { | ||
| logger.debug("Closing WelcomePage format"); | ||
| }, | ||
| reset: () => { | ||
| logger.debug("Resetting WelcomePage format"); | ||
| } | ||
| } | ||
| ] | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,9 +30,12 @@ export const welcomePage: AdvantageFormat = { | |
| return new Promise((resolve) => { | ||
| // Inser the CSS for the top scroll format | ||
| wrapper.insertCSS(varsCSS.concat(welcomepageCSS)); | ||
| // Set the styles for the ad iframe | ||
| if (ad) { | ||
| setDimensionsUntilAdvantageAdSlot(ad); | ||
|
|
||
| if (config.closeButtonAnimationDuration !== undefined) { | ||
| wrapper.style.setProperty( | ||
| "--adv-wp-transition-duration", | ||
| `${config.closeButtonAnimationDuration}s` | ||
| ); | ||
| } | ||
|
|
||
| // Change the content of the UI layer | ||
|
|
@@ -123,8 +126,11 @@ export const welcomePage: AdvantageFormat = { | |
| resetDimensionsUntilAdvantageAdSlot(ad); | ||
| } | ||
| wrapper.resetCSS(); | ||
| wrapper.style.removeProperty("--adv-wp-transition-duration"); | ||
| }, | ||
| close: (wrapper) => { | ||
| const container = wrapper.shadowRoot?.getElementById("container"); | ||
|
|
||
| function handleTransitionEnd() { | ||
| wrapper.style.display = "none"; | ||
| // Remove the event listener after it has been executed | ||
|
|
@@ -134,8 +140,25 @@ export const welcomePage: AdvantageFormat = { | |
| ); | ||
| } | ||
|
|
||
| const container = wrapper.shadowRoot?.getElementById("container"); | ||
| container?.addEventListener("transitionend", handleTransitionEnd); | ||
| if (container) { | ||
| const computedStyle = window.getComputedStyle(container); | ||
| const transitionProperty = computedStyle.transitionProperty; | ||
| const transitionDuration = computedStyle.transitionDuration; | ||
|
|
||
| const hasTransition = | ||
| transitionProperty !== "none" && | ||
| transitionDuration.split(",").some((d) => parseFloat(d) > 0); | ||
|
|
||
| if (!hasTransition) { | ||
| wrapper.style.display = "none"; | ||
| wrapper.classList.remove("show"); | ||
| wrapper.style.height = "0px"; | ||
| return; | ||
| } | ||
|
Comment on lines
+142
to
+156
|
||
|
|
||
| container.addEventListener("transitionend", handleTransitionEnd); | ||
| } | ||
|
|
||
|
Comment on lines
+142
to
+160
|
||
| wrapper.classList.remove("show"); | ||
| wrapper.style.height = "0px"; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -463,6 +463,27 @@ export class AdvantageWrapper extends HTMLElement implements IAdvantageWrapper { | |
|
|
||
| animateClose(callback?: () => void) { | ||
| this.classList.add("animate"); | ||
|
|
||
| const computedStyle = window.getComputedStyle(this); | ||
| const transitionProperty = computedStyle.transitionProperty; | ||
| const transitionDuration = computedStyle.transitionDuration; | ||
|
|
||
| // Check if there are any active transitions | ||
| // We need to handle multiple values (e.g. "0.5s, 1s") and check if any are > 0 | ||
| const hasTransition = | ||
| transitionProperty !== "none" && | ||
| transitionDuration.split(",").some((d) => parseFloat(d) > 0); | ||
|
|
||
| if (!hasTransition) { | ||
| this.classList.remove("animate"); | ||
| this.style.height = "0px"; | ||
| this.style.display = "none"; | ||
|
Comment on lines
+477
to
+480
|
||
| if (callback) { | ||
| callback(); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| this.addEventListener( | ||
| "transitionend", | ||
| () => { | ||
|
|
@@ -471,6 +492,7 @@ export class AdvantageWrapper extends HTMLElement implements IAdvantageWrapper { | |
| return; | ||
| } | ||
| this.style.display = "none"; | ||
| this.classList.remove("animate"); | ||
| if (callback) { | ||
| callback(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to
setDimensionsUntilAdvantageAdSlot(ad)was removed from the setup function. All other formats (topscroll.ts line 51, midscroll.ts line 15, multi-midscroll-base.ts line 69) call this function during setup, and welcomepage.ts still callsresetDimensionsUntilAdvantageAdSlot(ad)in its reset function (line 126). This removal appears unintentional and could break the ad dimensions setup for the WelcomePage format. The function call should be restored.