Skip to content

Instantly share code, notes, and snippets.

@joelhsmith
Created June 18, 2018 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelhsmith/f10d8d2f03b5da778cb0cf55a69263a0 to your computer and use it in GitHub Desktop.
Save joelhsmith/f10d8d2f03b5da778cb0cf55a69263a0 to your computer and use it in GitHub Desktop.
Accessibility Drupal Flexslider Fix.
// # Info about Flexslider in Drupal:
// Requires jquery_update to 1.7
// Requires latest verion of Flexslider in your /libraries folder
// # Tips
// If you are using the module flexslider, this might be helpful: drupal.org/project/flexslider/issues/1580902#comment-12363103
// If you are using the module flexslider_view_slideshow, you might need this patch: drupal.org/project/flexslider/issues/1580902#comment-12363103
// If the module gives you the option to turn of aria-live, do it. Even using aria-live="polite" on a slideshow is like flipping someone off.
Drupal.behaviors.flexslider_a11y_fixes = {
attach: function (context) {
// Function sets the aria attibute correctly by spying on the opacity property
function setAria(el) {
var $flexsliderObjectSlides = $(el).find('.slides > li');
$flexsliderObjectSlides.each(function () {
if ($(this).attr('style').indexOf("opacity: 0") !== -1) {
$(this).attr('aria-hidden', 'true');
} else {
$(this).attr('aria-hidden', 'false');
}
});
}
// Use Flexsider APIs 'start' callback for our setAria function when the slider loads
$('.flexslider').bind('start', function (e, slider) {
$flexsliderObject = $(this);
setAria($flexsliderObject);
$(this).find('.slides > li:first-child').attr('aria-hidden', 'false'); // make 100% sure aria is correct on first slide
});
// Use Flexsider APIs after' callback for our setAria() function when each slide advance
$('.flexslider').bind('after', function (e, slider) {
$flexsliderObject = $(this);
setAria($flexsliderObject);
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment