[FIX] website: fix dropdown menu closing in edit mode

Before this commit, in edit mode, it was not possible to close an open
dropdown in the header anymore.

This was due to BS5 (merged at [1]). Before, the 'show' class was added
to the dropdown menu element (the element with the 'dropdown' class).
But that changed: the 'show' class is now added on the button (the
element with the 'dropdown-toggle' class). And as in edit mode the
openings/closing of the dropdowns are handled manually in the header, it
no longer worked correctly.

[1]: https://github.com/odoo/odoo/commit/971e5a91aab96d36129a823e03f1f9f1b1293968

task-3001198

closes odoo/odoo#102145

X-original-commit: f3e1dc52356164453f72827e3dc87ad903df3d0e
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
Benjamin Vray
2022-10-05 01:18:59 +02:00
committed by qsm-odoo
parent bdea645949
commit f317dd5bcb
@@ -17,15 +17,14 @@ var snippetsEditor = require('website.snippet.editor');
*/
function toggleDropdown($toggles, show) {
return Promise.all(_.map($toggles, toggle => {
var $toggle = $(toggle);
var $dropdown = $toggle.parent();
var shown = $dropdown.hasClass('show');
const $toggle = $(toggle);
const shown = toggle.classList.contains('show');
if (shown === show) {
return;
}
var toShow = !shown;
const toShow = !shown;
return new Promise(resolve => {
$dropdown.one(
$toggle.parent().one(
toShow ? 'shown.bs.dropdown' : 'hidden.bs.dropdown',
() => resolve()
);