Finishes web client desktop menu navigation functionality

This commit is contained in:
BinaryAlley committed 2025-01-02 19:21:38 +02:00
1 parent 62c209bf0c
commit ade2d871af
3 files changed
+130 -22

No files matched your search

@@ -111,8 +111,7 @@
</label>
<nav class="menubar">
<ul>
<li tabindex="0">
<input type="radio" id="account-menu" name="menu">
<li tabindex="0" class="top-level-menuitem">
<label for="account-menu">@_localizer["Account"]</label>
<ul>
@if (User?.Identity?.IsAuthenticated == false)
@@ -136,9 +135,7 @@
{
@if (await _auth.IsInRoleAsync("Admin", CancellationToken.None))
{
<li tabindex="0">
<input type="radio" id="administrator-menu" name="menu">
<li tabindex="1" class="top-level-menuitem">
<label for="administrator-menu">@_localizer["Administrator"]</label>
<ul>
<li><a href="@_urlService.GetAbsoluteUrl("ManageRoles", "Admin")" class="nav-link">@_localizer["ManageRoles"]</a></li>
@@ -146,8 +143,7 @@
</ul>
</li>
}
<li tabindex="0">
<input type="radio" id="library-menu" name="menu">
<li tabindex="2" class="top-level-menuitem">
<label for="library-menu">@_localizer["Library"]</label>
<ul>
<li tabindex="0"><a href="@_urlService.GetAbsoluteUrl("Index", "LibraryManagement")" class="nav-link">@_localizer["ManageLibraries"]</a></li>
@@ -176,8 +172,7 @@
</ul>
</li>
}
<li tabindex="0">
<input type="radio" id="tools-menu" name="menu">
<li tabindex="3" class="top-level-menuitem">
<label for="tools-menu">@_localizer["Tools"]</label>
<ul>
<li class="has-submenu" tabindex="0">
@@ -200,8 +195,7 @@
}
</ul>
</li>
<li tabindex="0">
<input type="radio" id="help-menu" name="menu">
<li tabindex="4" class="top-level-menuitem">
<label for="help-menu">@_localizer["Help"]</label>
<ul>
<li><a href="help/documentation" class="nav-link">@_localizer["Documentation"]</a></li>
@@ -190,6 +190,10 @@
z-index: 900;
}
.menubar li.open > ul {
display: block; /* show submenu when parent has 'open' class */
}
.menubar ul {
list-style-type: none;
margin: 0;
@@ -223,7 +227,7 @@
color: #FFFFFF;
}
.menubar input[type="radio"] {
.menubar input[type="checkbox"] {
display: none;
}
@@ -250,6 +254,11 @@
position: relative;
}
/* show submenus on hover */
.menubar ul ul li.open > ul {
display: block;
}
.menubar ul ul li:first-child {
border-top: 1px solid #000000;
}
@@ -272,13 +281,8 @@
top: 0;
}
.menubar li:focus-within > ul {
display: block;
outline: none;
}
.menubar > ul > li:focus-within > label,
.menubar > ul > li:focus-within > a {
.menubar > ul > li.hovered > label,
.menubar > ul > li.hovered > a {
background-color: #28292B;
background: radial-gradient( 115% 115% at 68% 70%, #30303088 0%, #20202044 50%, #101010 100% );
border: 1px solid #777777;
@@ -299,7 +303,9 @@
}
.menubar .has-submenu:focus-within > label,
.menubar .has-submenu:focus-within > a {
.menubar .has-submenu:focus-within,
.menubar .has-submenu:hover > label,
.menubar .has-submenu:hover > a {
background: linear-gradient( to bottom, #505050 0%, #464646 35%, #404040 55%, #363636 100% );
border: 1px solid #777777;
border-right-color: #000000;
@@ -307,14 +313,18 @@
}
.menubar .has-submenu:focus-within > label::after,
.menubar .has-submenu:focus-within > a::after {
.menubar .has-submenu:focus-within > a::after,
.menubar .has-submenu:hover > label::after,
.menubar .has-submenu:hover > a::after {
content: " ▼";
color: #FF0000;
transform: translateY(-50%) rotate(0deg);
}
.menubar .has-submenu:focus-within > label,
.menubar .has-submenu:focus-within > a {
.menubar .has-submenu:focus-within > a,
.menubar .has-submenu:hover > label,
.menubar .has-submenu:hover > a {
color: #7CACF8;
}
@@ -410,6 +410,109 @@ function updateLanguageUrls() {
});
}
//+======================================================================================+
//| Website menu |
//+======================================================================================+
/**
* Handles the navigation through the website desktop menu bar
*/
function handleWebsiteDesktopMenu() {
const menuBar = document.querySelector('.menubar');
const topLevelItems = menuBar.querySelectorAll('.menubar > ul > li');
const hasSubmenuItems = menuBar.querySelectorAll('.has-submenu');
const submenuNavigationItems = menuBar.querySelectorAll('li:not(.has-submenu):not(.top-level-menuitem)');
function closeAllDropdowns() { // close all top level or submenu dropdowns
topLevelItems.forEach(item => {
item.classList.remove('open');
item.classList.remove('hovered');
});
hasSubmenuItems.forEach(submenu => {
submenu.classList.remove('open');
});
}
// handle clicks on top-level menu items
topLevelItems.forEach(item => {
const labelOrAnchor = item.querySelector('label, a');
labelOrAnchor.addEventListener('click', function (event) {
event.stopPropagation();
// close all menu drop down
const isOpen = item.classList.contains('open');
closeAllDropdowns();
// if the item was not already opened, toggle it (mark it as opened)
if (!isOpen) {
item.classList.add('open');
// immediately add 'hovered' class on click to maintain visual feedback
item.classList.add('hovered');
}
});
// Handle hover on top-level menu items
item.addEventListener('mouseenter', function () {
if (Array.from(topLevelItems).some(li => li.classList.contains('open') && li !== this)) {
closeAllDropdowns();
this.classList.add('open');
this.classList.add('hovered');
}
});
item.addEventListener('mouseleave', function () {
// Remove 'hovered' only if the dropdown is not open
if (!this.classList.contains('open')) {
this.classList.remove('hovered');
}
});
});
// handle hover on submenu items
hasSubmenuItems.forEach(item => {
item.addEventListener('mouseenter', function () {
const parentUl = this.closest('ul');
if (parentUl) {
// if the current menu item has multiple items with subemnus, close them if they are not the hovered one
const otherSubmenus = parentUl.querySelectorAll('.has-submenu.open');
otherSubmenus.forEach(submenu => {
if (submenu !== this && !this.contains(submenu))
submenu.classList.remove('open');
});
}
this.classList.add('open'); // show the current menu item as opened
});
item.addEventListener('mouseleave', function (event) {
// on mouse exit, simplu close menu items
if (!this.contains(event.relatedTarget))
this.classList.remove('open');
});
});
submenuNavigationItems.forEach(item => {
item.addEventListener('click', function (event) {
if (!item.classList.contains('has-submenu'))
closeAllDropdowns();
});
});
// close all menus when clicking outside the menubar
document.addEventListener('click', function (event) {
if (!menuBar.contains(event.target))
closeAllDropdowns();
});
// keep the 'hovered' class on the open menu item, if no other item is hovered
menuBar.addEventListener('mouseleave', function(event) {
if (!menuBar.contains(event.relatedTarget)) {
// if there is an item with a visible drop down, mark it as opened, but not if its the last hovered item
topLevelItems.forEach(item => {
if (item.classList.contains('open'))
item.classList.add('hovered');
else
item.classList.remove('hovered');
});
}
});
}
//+======================================================================================+
//| Common Helper Functions |
//+======================================================================================+
@@ -728,3 +831,4 @@ document.addEventListener('click', function (e) {
});
document.addEventListener('DOMContentLoaded', initializeNavigation);
document.addEventListener('DOMContentLoaded', handleWebsiteDesktopMenu);