Skip to content

Commit

Permalink
XWIKI-18007: Drawer menu improvements for accessibility
Browse files Browse the repository at this point in the history
Moved the code responsible for drawer to the flamingo.js file
Fixed formatting
  • Loading branch information
wthrajat committed Feb 13, 2023
1 parent df79bd8 commit 0e06788
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
require(['jquery', 'bootstrap'], function($) {
$(function() {

// Fix the bad location of the dropdown menu when the trigger is close to the end of the screen.
// See: http://jira.xwiki.org/browse/XWIKI-12609
/* Fix the bad location of the dropdown menu when the trigger is close to the end of the screen.
See: http://jira.xwiki.org/browse/XWIKI-12609 */
$(document).on('shown.bs.dropdown', function (event) {
var toggle = $(event.relatedTarget);
var menu = toggle.next('.dropdown-menu');
Expand Down Expand Up @@ -51,3 +51,23 @@ require(['jquery', 'bootstrap'], function($) {
translateButton.attr('title', translateButton.attr('data-title')).popover();
});
});
require(['jquery', 'iscroll', 'drawer'], function($, IScroll) {
// Unfortunately drawer doesn't declare the dependency on iscroll and expects it to be defined as a global variable.
window.IScroll = IScroll;
$(function() {
/* Note that the 'drawer-open' and 'drawer-close' CSS classes are added before the open and close animations end
which prevents us from using them in automated tests. We need something more reliable so we listen to
'drawer.opened' and 'drawer.closed' events and add our own markers. */
$('.drawer-nav').closest('body').drawer().on('drawer.opened', function(event) {
$('#tmDrawerActivator').attr('aria-expanded', 'true');
}).on('drawer.closed', function(event) {
$('#tmDrawerActivator').attr('aria-expanded', 'false');
});
});
// Drawer can be closed by pressing the ESC key, regardless of how it was opened, whether by keyboard or clicking.
$(document).on('keydown', function (event) {
if (event.key === 'Escape') {
$('.drawer-nav').closest('body').drawer('close');
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,6 @@ if (window.Prototype && Prototype.BrowserFeatures.ElementExtensions) {
disablePrototypeJS('hide', pluginsToDisable);
});
}
require(['jquery', 'iscroll', 'drawer'], function($, IScroll) {
// Unfortunately drawer doesn't declare the dependency on iscroll and expects it to be defined as a global variable.
window.IScroll = IScroll;
$(function() {
// Note that the 'drawer-open' and 'drawer-close' CSS classes are added before the open and close animations end
// which prevents us from using them in automated tests. We need something more reliable so we listen to
// 'drawer.opened' and 'drawer.closed' events and add our own markers.
$('.drawer-nav').closest('body').drawer().on('drawer.opened', function(event) {
$('#tmDrawerActivator').attr('aria-expanded', 'true');
}).on('drawer.closed', function(event) {
$('#tmDrawerActivator').attr('aria-expanded', 'false');
});
});
});
##
## Pass useful contextual information from the server to the client using the global XWiki object.
##
Expand Down

0 comments on commit 0e06788

Please sign in to comment.