Skip to content

Commit

Permalink
Improve second-level display method of smart menus
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanna-lmsace committed Feb 29, 2024
1 parent ab6eeea commit ed15df8
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 147 deletions.
2 changes: 1 addition & 1 deletion amd/build/smartmenu.min.js

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

2 changes: 1 addition & 1 deletion amd/build/smartmenu.min.js.map

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions amd/build/submenu.min.js

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

1 change: 1 addition & 0 deletions amd/build/submenu.min.js.map

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

87 changes: 2 additions & 85 deletions amd/src/smartmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,90 +21,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

define(["jquery", "core/moremenu"], function($) {
/**
* Implement the second level of submenu support.
* Find the submenus inside the dropdown, add an event listener for click event which - on the click - shows the submenu list.
*/
const addSubmenu = () => {
// Fetch the list of submenus from moremenu.
var submenu = document.querySelectorAll('nav.moremenu .dropdown-submenu');
if (submenu !== null) {
submenu.forEach((item) => {
// Add event listener to show the submenu on click.
item.addEventListener('click', (e) => {
var target = e.currentTarget;
// Hide the shown menu.
hideSubmenus(target);
target.classList.toggle('show');
// Prevent hiding the parent menu.
e.stopPropagation();
});
});
}

// Hide the submenus when its parent dropdown is hidden.
$(document).on('hidden.bs.dropdown', e => {
var target = e.relatedTarget.parentNode;
var submenus = target.querySelectorAll('.dropdown-submenu.show');
if (submenus !== null) {
submenus.forEach((e) => e.classList.remove('show'));
}
});

// Provide the third level menu support inside the more menu.
// StopPropagation used in the toggledropdown method on Moremenu.js, It prevents the opening of the third level menus.
// Used the document delegation method to fetch the click on moremenu and submenu.
document.addEventListener('click', (e) => {
var dropdown = e.target.closest('.dropdownmoremenu');
var subMenu = e.target.closest('.dropdown-submenu');
if (dropdown && subMenu !== null) {
// Hide the previously opend submenus. before open the new one.
dropdown.querySelectorAll('.dropdown-submenu.show').forEach((menu) => {
menu.classList.remove('show');
});
subMenu.classList.toggle('show');
}

// Hide the opened menus before open the other menus.
var dropdownMenu = e.target.parentNode.classList.contains('dropdown');
if (dropdown && dropdownMenu) {
dropdown.querySelectorAll('.dropdown-menu.show').forEach((menu) => {
// Hide the opened menus in more menu.
if (menu != e.target.closest('.dropdown-menu')) {
menu.classList.remove('show');
}
});
}

}, true);

// Prevent the closing of dropdown during the click on help icon.
var helpIcon = document.querySelectorAll('.moremenu .dropdown .menu-helpicon');
if (helpIcon !== null) {
helpIcon.forEach((icon) => {
icon.addEventListener('click', (e) => {
e.stopPropagation();
});
});
}
};

/**
* Hide visible submenus before display new submenu.
*
* @param {Selector} target
*/
const hideSubmenus = (target) => {
var visibleMenu = document.querySelectorAll('nav.moremenu .dropdown-submenu.show');
if (visibleMenu !== null) {
visibleMenu.forEach((el) => {
if (el != target) {
el.classList.remove('show');
}
});
}
};
define(["jquery", "core/moremenu", "theme_boost_union/submenu"], function($, MoreMenu, SubMenu) {

/**
* Make the no wrapped card menus scroll using swipe or drag.
Expand Down Expand Up @@ -205,7 +122,7 @@ define(["jquery", "core/moremenu"], function($) {

return {
init: () => {
addSubmenu();
SubMenu.init();
cardScroll();
autoCollapse();
}
Expand Down
Loading

0 comments on commit ed15df8

Please sign in to comment.