-
Notifications
You must be signed in to change notification settings - Fork 178
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
[MWPW-157116] - Add feature for pause animation on hover for PEP #3485
Changes from 1 commit
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ const CONFIG = { | |
selectors: { prompt: '.appPrompt' }, | ||
delay: 7000, | ||
loaderColor: '#EB1000', | ||
pauseOnHover: 'off', | ||
...DISMISSAL_CONFIG, | ||
}; | ||
|
||
|
@@ -155,7 +156,7 @@ export class AppPrompt { | |
this.parent.prepend(this.template); | ||
this.elements.closeIcon.focus(); | ||
|
||
this.redirectFn = this.initRedirect(); | ||
this.redirectFn = this.initRedirect(this.options['pause-on-hover'] === 'on'); | ||
}; | ||
|
||
doesEntitlementMatch = async () => { | ||
|
@@ -225,10 +226,12 @@ export class AppPrompt { | |
metadata['dismissal-animation-duration'] = parseInt(metadata['dismissal-animation-duration'] ?? CONFIG.animationDuration, 10); | ||
metadata['dismissal-tooltip-message'] ??= CONFIG.tooltipMessage; | ||
metadata['dismissal-tooltip-duration'] = parseInt(metadata['dismissal-tooltip-duration'] ?? CONFIG.tooltipDuration, 10); | ||
metadata['pause-on-hover'] ??= CONFIG.pauseOnHover; | ||
this.options = metadata; | ||
}; | ||
|
||
decorate = () => { | ||
const animationPlayState = this.options['pause-on-hover'] === 'on'; | ||
this.elements.closeIcon = toFragment`<button daa-ll="Close Modal" aria-label="${this.cancel}" class="appPrompt-close"></button>`; | ||
this.elements.cta = toFragment`<button daa-ll="Stay on this page" class="appPrompt-cta appPrompt-cta--close">${this.cancel}</button>`; | ||
this.elements.profile = this.profile | ||
|
@@ -257,7 +260,7 @@ export class AppPrompt { | |
${this.elements.cta} | ||
</div> | ||
<div class="appPrompt-progressWrapper"> | ||
<div class="appPrompt-progress" style="background-color: ${this.options['loader-color']}; animation-duration: ${this.options['loader-duration']}ms;"></div> | ||
<div class="appPrompt-progress" style="background-color: ${this.options['loader-color']}; animation-duration: ${this.options['loader-duration']}ms; ${!animationPlayState && 'animation-play-state: running;'}"></div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't it have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same is handled with adding class and removed |
||
</div> | ||
</div>`; | ||
}; | ||
|
@@ -278,10 +281,35 @@ export class AppPrompt { | |
window.location.assign(url); | ||
} | ||
|
||
initRedirect = () => setTimeout(() => { | ||
this.close({ saveDismissal: false, dismissalActions: false }); | ||
AppPrompt.redirectTo(this.options['redirect-url']); | ||
}, this.options['loader-duration']); | ||
initRedirect = (withPause = false) => { | ||
let timeoutId; | ||
let remainingTime = this.options['loader-duration']; | ||
let startTime; | ||
|
||
const startTimeout = () => { | ||
startTime = Date.now(); | ||
timeoutId = setTimeout(() => { | ||
this.close({ saveDismissal: false, dismissalActions: false }); | ||
AppPrompt.redirectTo(this.options['redirect-url']); | ||
}, remainingTime); | ||
}; | ||
|
||
const stopTimeout = () => { | ||
clearTimeout(timeoutId); | ||
remainingTime -= Date.now() - startTime; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
}; | ||
|
||
if (withPause) { | ||
const appPromptElem = document.querySelector(CONFIG.selectors.prompt); | ||
if (appPromptElem) { | ||
appPromptElem.addEventListener('mouseenter', stopTimeout); | ||
appPromptElem.addEventListener('mouseleave', startTimeout); | ||
} | ||
} | ||
|
||
// Start the timeout initially | ||
startTimeout(); | ||
}; | ||
|
||
isDismissedPrompt = () => AppPrompt.getDismissedPrompts().includes(this.id); | ||
|
||
|
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.
I may be mistaken but, since this class is always on the prompt, the animation will pause even if pause on hover is turned off, right?
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.
I have updated the implementation for this. Now, the class
appPrompt-progressPauseOnHover
is added whenpause-on-hover
is enabled. CSS has been applied specifically to this class, ensuring that the styles are applied only whenpause-on-hover
is enabled.