Skip to content
Snippets Groups Projects
Commit d9337939 authored by Guillaume Delhumeau's avatar Guillaume Delhumeau
Browse files

XWIKI-13337: Dropdown menus don't open in some conditions.

parent 270f619f
No related branches found
No related tags found
No related merge requests found
......@@ -3,19 +3,22 @@ require(['jquery', 'bootstrap'], 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
$(document).on('shown.bs.dropdown', function (event, data) {
var toggle = $(data.relatedTarget);
$(document).on('shown.bs.dropdown', function (event) {
var toggle = $(event.relatedTarget);
var menu = toggle.next('.dropdown-menu');
var menuWidth = menu.outerWidth();
// if the right corner of the menu is after the end of the screen
if (menu.offset().left + menuWidth > $(document.body).outerWidth()) {
// we put that corner at the same place than the toggle's right corner
var newLocation = toggle.offset().left + toggle.outerWidth() - menuWidth;
// but don't put it negative, or the user will have to scroll to the left!
if (newLocation < 0) {
newLocation = 0;
// The menu might be not found if it is not located where it is expected.
if (menu.length > 0) {
var menuWidth = menu.outerWidth();
// if the right corner of the menu is after the end of the screen
if (menu.offset().left + menuWidth > $(document.body).outerWidth()) {
// we put that corner at the same place than the toggle's right corner
var newLocation = toggle.offset().left + toggle.outerWidth() - menuWidth;
// but don't put it negative, or the user will have to scroll to the left!
if (newLocation < 0) {
newLocation = 0;
}
menu.offset({'left': newLocation});
}
menu.offset({'left': newLocation});
}
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment