-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #282 from yalesites-org/develop
Release
- Loading branch information
Showing
37 changed files
with
602 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
Drupal.behaviors.animateItems = { | ||
attach(context) { | ||
// Check if animation is active in site settings. | ||
const siteAnimationTheme = context.querySelector('[data-site-animation]'); | ||
|
||
// Set variable to check that the animation theme isn't the default. | ||
const siteAnimationEnabled = | ||
siteAnimationTheme.getAttribute('data-site-animation') !== 'default'; | ||
|
||
// Select all elements with [data-animate-item] attribute | ||
const elementsToAnimate = context.querySelectorAll( | ||
'[data-animate-item="true"]', | ||
); | ||
|
||
// Check if the user prefers reduced motion | ||
const prefersReducedMotionNoPref = window.matchMedia( | ||
'(prefers-reduced-motion: no-preference)', | ||
).matches; | ||
|
||
// Create a new Intersection Observer | ||
const observer = new IntersectionObserver((entries) => { | ||
entries.forEach((entry) => { | ||
const animatedElement = entry.target; | ||
|
||
if (entry.isIntersecting) { | ||
// If the element is in the viewport, add the 'animate' class | ||
animatedElement.classList.add('animate'); | ||
} | ||
}); | ||
}); | ||
// Only add observer if siteAnimationEnabled, there are elements to animate, | ||
// and if user hasn't enabled reduced motion. | ||
if ( | ||
elementsToAnimate && | ||
siteAnimationEnabled && | ||
prefersReducedMotionNoPref | ||
) { | ||
// Observe each .divider element | ||
elementsToAnimate.forEach((animatedElement) => { | ||
observer.observe(animatedElement); | ||
}); | ||
} | ||
// Set each component to data-animate-item false if prefers reduced motion. | ||
if (!prefersReducedMotionNoPref) { | ||
elementsToAnimate.forEach((reducedMotionElement) => { | ||
reducedMotionElement.setAttribute('data-animate-item', 'false'); | ||
}); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.