Skip to content

Commit

Permalink
fix: use animationend event (#2770)
Browse files Browse the repository at this point in the history
  • Loading branch information
limonte authored Oct 7, 2024
1 parent c699d6c commit c510323
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 35 deletions.
7 changes: 2 additions & 5 deletions src/instanceMethods/close.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const prepareResolveValue = (resolveValue) => {
const handlePopupAnimation = (instance, popup, innerParams) => {
const container = dom.getContainer()
// If animation is supported, animate
const animationIsSupported = dom.animationEndEvent && dom.hasCssAnimation(popup)
const animationIsSupported = dom.hasCssAnimation(popup)

if (typeof innerParams.willClose === 'function') {
innerParams.willClose(popup)
Expand All @@ -180,17 +180,14 @@ const handlePopupAnimation = (instance, popup, innerParams) => {
* @param {Function} didClose
*/
const animatePopup = (instance, popup, container, returnFocus, didClose) => {
if (!dom.animationEndEvent) {
return
}
globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(
null,
instance,
container,
returnFocus,
didClose
)
popup.addEventListener(dom.animationEndEvent, function (e) {
popup.addEventListener('animationend', function (e) {
if (e.target === popup) {
globalState.swalCloseEventFinishedCallback()
delete globalState.swalCloseEventFinishedCallback
Expand Down
25 changes: 0 additions & 25 deletions src/utils/dom/animationEndEvent.js

This file was deleted.

1 change: 0 additions & 1 deletion src/utils/dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ export * from './domUtils.js'
export * from './init.js'
export * from './getters.js'
export * from './parseHtmlToContainer.js'
export * from './animationEndEvent.js'
export * from './renderers/render.js'
8 changes: 4 additions & 4 deletions src/utils/openPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ export const openPopup = (params) => {
*/
const swalOpenAnimationFinished = (event) => {
const popup = dom.getPopup()
if (event.target !== popup || !dom.animationEndEvent) {
if (event.target !== popup) {
return
}
const container = dom.getContainer()
popup.removeEventListener(dom.animationEndEvent, swalOpenAnimationFinished)
popup.removeEventListener('animationend', swalOpenAnimationFinished)
container.style.overflowY = 'auto'
}

Expand All @@ -65,9 +65,9 @@ const swalOpenAnimationFinished = (event) => {
* @param {HTMLElement} popup
*/
const setScrollingVisibility = (container, popup) => {
if (dom.animationEndEvent && dom.hasCssAnimation(popup)) {
if (dom.hasCssAnimation(popup)) {
container.style.overflowY = 'hidden'
popup.addEventListener(dom.animationEndEvent, swalOpenAnimationFinished)
popup.addEventListener('animationend', swalOpenAnimationFinished)
} else {
container.style.overflowY = 'auto'
}
Expand Down

0 comments on commit c510323

Please sign in to comment.