var lottie, animations; // Return a promise that resolves to true once animation is loaded async function animationLoaded(animation) { if(animation.isLoaded) { return true } return new Promise((resolve, reject) => { animation.addEventListener('DOMLoaded', () => { resolve(true) }) }) } // Return a promise that resolves to true once all animations are loaded async function waitForAnimationsLoaded(animations) { await Promise.all(animations.map(animationLoaded)) } async function initAnimations() { lottie = Webflow.require('lottie').lottie animations = lottie.getRegisteredAnimations(); animations.forEach(item => { const lottieName = item.wrapper.getAttribute('data-w-id'); item.name = lottieName; }); await waitForAnimationsLoaded(animations) } // Wait for Webflow to load window.Webflow ||= []; window.Webflow.push(async () => { initAnimations() .then(() => { const hoverContainers = document.querySelectorAll('[data-wim-interaction="hover"]'); hoverContainers.forEach((item) => { const lottieElement = item.querySelector('[data-animation-type="lottie"]').getAttribute('data-w-id'); item.addEventListener('mouseenter', () => { lottie.goToAndStop(0, true, lottieElement); lottie.play(lottieElement); }) }) const toggleContainers = document.querySelectorAll('[data-wim-interaction="toggle"]'); toggleContainers.forEach((item) => { const lottieElement = item.querySelector('[data-animation-type="lottie"]').getAttribute('data-w-id'); lottie.goToAndStop(0, true, lottieElement); item.addEventListener('click', () => { item = !item; if (item) { lottie.setDirection(-1); lottie.play(lottieElement); } else { lottie.setDirection(1); lottie.play(lottieElement); } }) }) }) })