Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A11y: add functionality for prefers-reduced-motion to the timeline #876

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/js/timeline/Timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,23 @@ class Timeline {

}

//Check prefered-reduced-motion - Accessibility to reduce motion if enabled in Operationg System
reducedMotionEnabled() {
const isReduced =
window.matchMedia(`(prefers-reduced-motion: reduce)`) === true ||
window.matchMedia(`(prefers-reduced-motion: reduce)`).matches ===
true
// Change duration for speed in which slides/timenav move
if(isReduced){
this._updateDisplay(this._timenav.options.height, true, 1);
this._timenav.options.duration = 1
}
else {
// revert time nav option duration back to 1000
this._timenav.options.duration = 1000
}
}

_initEvents() {
// TimeNav Events
this._timenav.on('change', this._onTimeNavChange, this);
Expand All @@ -487,6 +504,7 @@ class Timeline {
}

_onSlideChange(e) {
this.reducedMotionEnabled()
if (this.current_id != e.unique_id) {
this.current_id = e.unique_id;
this._timenav.goToId(this.current_id);
Expand All @@ -495,6 +513,7 @@ class Timeline {
}

_onTimeNavChange(e) {
this.reducedMotionEnabled()
if (this.current_id != e.unique_id) {
this.current_id = e.unique_id;
this._storyslider.goToId(this.current_id);
Expand Down Expand Up @@ -555,10 +574,12 @@ class Timeline {
}

_onStorySliderNext(e) {
this.reducedMotionEnabled()
this.fire("nav_next", e);
}

_onStorySliderPrevious(e) {
this.reducedMotionEnabled()
this.fire("nav_previous", e);
}

Expand Down