|
Server : Apache System : Linux s1230 5.15.0-139-generic #149~20.04.1 SMP Tue Jul 14 11:21:49 UTC 2026 x86_64 User : p141464 ( 418825) PHP Version : 7.4.33.12 Disable Function : NONE Directory : /html/relaunch-kmu/wp-content/plugins/wp-gdpr-compliance/Resources/js/components/ |
Upload File : |
import { isIntersectionObserverEnabled, setupIntersectionObserver } from '../utils/helpers'
const animationsSelector = 'data-animation'
/**
* Get the timeout length of the item (animation duration + delay).
* @param {HTMLElement} item
* @returns {number} Time in ms.
*/
const getItemTimeout = item => {
const style = getComputedStyle(item)
const duration = parseFloat(style.animationDuration)
const delay = parseFloat(style.animationDelay)
return (duration + delay) * 1000
}
/**
* Make an item visible.
* @param {HTMLElement} item
*/
const makeItemVisible = item => {
item.setAttribute(`${animationsSelector}-appearing`, '')
setTimeout(() => {
item.removeAttribute(`${animationsSelector}`)
item.removeAttribute(`${animationsSelector}-appearing`)
item.setAttribute(`${animationsSelector}-complete`, '')
}, getItemTimeout(item))
}
export default () => {
// If we don't have IntersectionObserver, show them all.
if (!isIntersectionObserverEnabled()) {
const items = document.querySelectorAll(`[${animationsSelector}]`)
for (const item of [...items]) {
makeItemVisible(item)
}
return
}
setupIntersectionObserver(
`[${animationsSelector}]`,
target => {
makeItemVisible(target)
},
[0]
)
}