From f937e602a76dfc4aaba95a796f99345e4dc627db Mon Sep 17 00:00:00 2001 From: Benjamin Vray Date: Mon, 12 Oct 2020 15:16:00 +0000 Subject: [PATCH] [FIX] website: fix menu direction of header dropdowns Before this commit, the menu direction of header dropdowns was related to the window width but it was wrong because of the right panel. We also enable it in editor mode. task-2312878 closes odoo/odoo#59846 X-original-commit: ced500e9bcbb5c84033463689d135ad4c7dc4f39 Signed-off-by: Quentin Smetz (qsm) --- addons/website/static/src/js/content/menu.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/website/static/src/js/content/menu.js b/addons/website/static/src/js/content/menu.js index 88f0dd7b268..34900c380d3 100644 --- a/addons/website/static/src/js/content/menu.js +++ b/addons/website/static/src/js/content/menu.js @@ -466,6 +466,7 @@ publicWidget.registry.autohideMenu = publicWidget.Widget.extend({ */ publicWidget.registry.menuDirection = publicWidget.Widget.extend({ selector: 'header .navbar .nav', + disabledInEditableMode: false, events: { 'show.bs.dropdown': '_onDropdownShow', }, @@ -488,12 +489,13 @@ publicWidget.registry.menuDirection = publicWidget.Widget.extend({ * @param {integer} liOffset * @param {integer} liWidth * @param {integer} menuWidth + * @param {integer} pageWidth * @returns {boolean} */ - _checkOpening: function (alignment, liOffset, liWidth, menuWidth, windowWidth) { + _checkOpening: function (alignment, liOffset, liWidth, menuWidth, pageWidth) { if (alignment === 'left') { // Check if ok to open the dropdown to the right (no window overflow) - return (liOffset + menuWidth <= windowWidth); + return (liOffset + menuWidth <= pageWidth); } else { // Check if ok to open the dropdown to the left (no window overflow) return (liOffset + liWidth - menuWidth >= 0); @@ -513,7 +515,7 @@ publicWidget.registry.menuDirection = publicWidget.Widget.extend({ var liOffset = $li.offset().left; var liWidth = $li.outerWidth(); var menuWidth = $menu.outerWidth(); - var windowWidth = $(window).outerWidth(); + var pageWidth = $('#wrapwrap').outerWidth(); $menu.removeClass('dropdown-menu-left dropdown-menu-right'); @@ -524,10 +526,10 @@ publicWidget.registry.menuDirection = publicWidget.Widget.extend({ } // If can't open in the current direction because it would overflow the - // window, change the direction. But if the other direction would do the + // page, change the direction. But if the other direction would do the // same, change back the direction. for (var i = 0; i < 2; i++) { - if (!this._checkOpening(alignment, liOffset, liWidth, menuWidth, windowWidth)) { + if (!this._checkOpening(alignment, liOffset, liWidth, menuWidth, pageWidth)) { alignment = (alignment === 'left' ? 'right' : 'left'); } }