Divinity Megazord Menu Accessibility helper
The snippet can be accessed without any authentication.
Authored by
Joel Crawford-Smith
This will add the aria-expanded attributes to the menu. It will keep the attribute's value (true/false) to accurately describe the visibility of the submenu.
It should be in a document.ready like all jQuery code. You can change the jQuery prefix to $ if you want. Its just using the jQuery prefix so it works if you paste it in the browsers console.
megazord-a11y-helper.js 491 B
jQuery('#menuzord-menu > li > a').attr('aria-expanded', 'false').attr('role', 'button');
jQuery('#menuzord-menu > li > a').bind('click', function (e) {
var expandedState = jQuery(this).attr('aria-expanded');
if (expandedState == 'true') {
jQuery(this).attr('aria-expanded', 'false');
}
if (expandedState == 'false') {
jQuery(this).attr('aria-expanded', 'true');
jQuery(this).parent().siblings().find('> a').attr('aria-expanded', 'false');
}
});
Please register or sign in to comment