PluginProbe ʕ •ᴥ•ʔ
FrontBlocks for Gutenberg/GeneratePress / 1.0.2
FrontBlocks for Gutenberg/GeneratePress v1.0.2
trunk 0.2.0 0.2.1 0.2.2 0.2.3 0.2.4 0.2.5 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 ci-artifacts
frontblocks / includes / dist / frontblocks-animations.js
frontblocks / includes / dist Last commit date
frontblocks-advanced-option.js 10 months ago frontblocks-animation-option.js 11 months ago frontblocks-animations-min.js 11 months ago frontblocks-animations.css 11 months ago frontblocks-animations.js 11 months ago frontblocks-carousel-min.js 11 months ago frontblocks-carousel.css 11 months ago frontblocks-carousel.js 11 months ago frontblocks-gallery-min.js 11 months ago frontblocks-gallery-option.js 11 months ago frontblocks-gallery.css 11 months ago frontblocks-gallery.js 11 months ago frontblocks-insert-post-option.js 11 months ago frontblocks-insert-post.css 11 months ago frontblocks-sticky-column-min.js 11 months ago frontblocks-sticky-column-option.js 11 months ago frontblocks-sticky-column.css 11 months ago frontblocks-sticky-column.js 11 months ago glide.min.js 1 year ago masonry.min.js 11 months ago
frontblocks-animations.js
96 lines
1 window.addEventListener('load', (event) => {
2 /**
3 * onIntersection will be triggered each time an observed item is visible in the viewport.
4 *
5 * @param {elements} The list of queried elements
6 * @param {*} Defines the option parameters for the observer API
7 */
8 const onIntersection = (elements, options) => {
9 elements.forEach((element) => {
10 // Check for both old and new animation attribute formats
11 let animationData = element.target.dataset.frontblocks_animation;
12 const hasModernFormat = element.target.classList.contains('animate__animated');
13
14 if (animationData) {
15 // Handle legacy format
16 // Check if the data attribute doesn't include the prefix, and add it otherwise.
17 if (!animationData.includes('animate__')) {
18 animationData = 'animate__'.concat(animationData);
19 }
20
21 // Add the CSS class if the element is visible.
22 if (element.isIntersecting) {
23 element.target.classList.add('animate__animated', animationData);
24 }
25 } else if (hasModernFormat && element.isIntersecting) {
26 // For modern format (added by block attributes)
27 // The classes are already there from the block rendering
28 // Just trigger animation by ensuring animation-play-state is running
29 element.target.style.visibility = 'visible';
30 element.target.style.animationPlayState = 'running';
31
32 // If this element should repeat, set up the animation to repeat
33 // Check multiple possible sources for repeat value
34 const repeatValue = element.target.style.getPropertyValue('--animate-repeat') ||
35 element.target.dataset.animateRepeat ||
36 element.target.getAttribute('data-animate-repeat');
37
38 if (repeatValue === 'infinite') {
39 // For infinite animations, set the iteration count to infinite
40 element.target.style.animationIterationCount = 'infinite';
41 } else if (repeatValue && repeatValue !== '1') {
42 // For numbered repeats, we handle it
43 const repeat = parseInt(repeatValue);
44 if (!isNaN(repeat) && repeat > 1) {
45 // Only add the event listener if it hasn't been added before
46 if (!element.target.dataset.repeatListenerAdded) {
47 element.target.dataset.repeatListenerAdded = 'true';
48 element.target.dataset.currentRepeat = '0';
49
50 element.target.addEventListener('animationend', () => {
51 let currentRepeat = parseInt(element.target.dataset.currentRepeat || 0);
52 if (currentRepeat < repeat - 1) {
53 element.target.dataset.currentRepeat = currentRepeat + 1;
54 // Trigger animation again by restarting it
55 element.target.style.animation = 'none';
56 setTimeout(() => {
57 element.target.style.animation = '';
58 element.target.style.animationPlayState = 'running';
59 }, 10);
60 }
61 });
62 }
63 }
64 }
65 }
66 });
67 }
68
69 /**
70 * Declares an instance of the IntersectionObserver API, which receives a function that will execute each time an observed
71 * item is present in the viewport.
72 */
73 const observer = new IntersectionObserver(onIntersection, {
74 root: null,
75 threshold: 0.2, // Lower threshold to start animation sooner
76 rootMargin: '0px 0px -10% 0px' // Trigger slightly before element is fully in view
77 });
78
79 /**
80 * Gather a list of all the DOM elements which contain animations.
81 * This includes both legacy data-attribute animations and new class-based animations.
82 * Then, observe the presence of each one in the viewport.
83 */
84 const animatedElements = document.querySelectorAll('[data-frontblocks_animation], .animate__animated');
85
86 // For modern animated elements, initially hide them until they're in view
87 document.querySelectorAll('.animate__animated:not([data-frontblocks_animation])').forEach(el => {
88 el.style.visibility = 'hidden';
89 el.style.animationPlayState = 'paused';
90 });
91
92 // Observe all animated elements
93 animatedElements.forEach((element) => {
94 observer.observe(element);
95 });
96 });