Merge branch 'MDL-53678_master' of https://github.com/StudiUM/moodle

This commit is contained in:
David Monllao 2016-04-26 10:45:40 +08:00
commit e1f9593de4
2 changed files with 31 additions and 6 deletions

File diff suppressed because one or more lines are too long

View File

@ -258,16 +258,41 @@ define(['jquery'], function($) {
Menubar.prototype.setOpenDirection = function() {
var pos = this.menuRoot.offset();
var isRTL = $(document.body).hasClass('dir-rtl');
var menuMinWidth = 160;
var openLeft = false;
var heightmenuRoot = this.rootMenus.outerHeight();
var widthmenuRoot = this.rootMenus.outerWidth();
// Sometimes the menuMinWidth is not enough to figure out if menu exceeds the window width.
// So we have to calculate the real menu width.
var subMenuContainer = this.rootMenus.find('ul.tool-lp-sub-menu');
// Reset margins.
subMenuContainer.css('margin-right', '');
subMenuContainer.css('margin-left', '');
subMenuContainer.css('margin-top', '');
subMenuContainer.attr('aria-hidden', false);
var menuRealWidth = subMenuContainer.outerWidth(),
menuRealHeight = subMenuContainer.outerHeight();
var margintop = null,
marginright = null,
marginleft = null;
var top = pos.top - $(window).scrollTop();
// Top is the same for RTL and LTR.
if (top + menuRealHeight > $(window).height()) {
margintop = menuRealHeight + heightmenuRoot;
subMenuContainer.css('margin-top', '-' + margintop + 'px');
}
if (isRTL) {
if (pos.left - menuMinWidth < 0) {
openLeft = true;
if (pos.left - menuRealWidth < 0) {
marginright = menuRealWidth - widthmenuRoot;
subMenuContainer.css('margin-right', '-' + marginright + 'px');
}
} else {
if (pos.left + menuMinWidth > $( window ).width()) {
openLeft = true;
if ( pos.left + menuRealWidth > $(window).width()) {
marginleft = menuRealWidth - widthmenuRoot;
subMenuContainer.css('margin-left', '-' + marginleft + 'px');
}
}