Skip to content

Commit

Permalink
Merge branch 'MDL-53678_master' of https://github.com/StudiUM/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed Apr 26, 2016
2 parents 4db87b5 + ee0ca65 commit e1f9593
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion admin/tool/lp/amd/build/menubar.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 30 additions & 5 deletions admin/tool/lp/amd/src/menubar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

Expand Down

0 comments on commit e1f9593

Please sign in to comment.