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

#41, Add RTL keyboard navigation support #42

Open
wants to merge 1 commit 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
9 changes: 7 additions & 2 deletions js/jquery-accessibleMegaMenu.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ limitations under the License.
(function ($, window, document) {
"use strict";
var pluginName = "accessibleMegaMenu",
isRtl = ($('html').attr('dir') === 'rtl'),
defaults = {
uuidPrefix: "accessible-megamenu", // unique ID's are required to indicate aria-owns, aria-controls and aria-labelledby
menuClass: "accessible-megamenu", // default css class used to define the megamenu styling
Expand Down Expand Up @@ -125,6 +126,10 @@ limitations under the License.
190: "."
}
};

defaults.prevKey = isRtl ? Keyboard.RIGHT : Keyboard.LEFT,
defaults.nextKey = isRtl ? Keyboard.LEFT : Keyboard.RIGHT;

/**
* @desc Creates a new accessible mega menu instance.
* @param {jquery} element
Expand Down Expand Up @@ -489,7 +494,7 @@ limitations under the License.
found = ($(':tabbable:lt(' + $(':tabbable').index(target) + '):first').focus().length === 1);
}
break;
case Keyboard.RIGHT:
case defaults.nextKey:
event.preventDefault();
if (isTopNavItem) {
found = (topnavitems.filter(':gt(' + topnavitems.index(topli) + '):first').find(':tabbable:first').focus().length === 1);
Expand All @@ -504,7 +509,7 @@ limitations under the License.
}
}
break;
case Keyboard.LEFT:
case defaults.prevKey:
event.preventDefault();
if (isTopNavItem) {
found = (topnavitems.filter(':lt(' + topnavitems.index(topli) + '):last').find(':tabbable:first').focus().length === 1);
Expand Down