This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from chrismlusk/feature/mega-menu
Feature/mega menu
- Loading branch information
Showing
7 changed files
with
411 additions
and
1 deletion.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
Portals/_default/Skins/CLIENT_CODE/menus/NavMegaMenu/NavMegaMenu.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
@using DotNetNuke.Web.DDRMenu; | ||
@using System.Dynamic; | ||
@inherits DotNetNuke.Web.Razor.DotNetNukeWebPage<dynamic> | ||
@{ var root = Model.Source.root; } | ||
|
||
@helper RenderMegaMenu(IList<MenuNode> nodes) { | ||
if (nodes.Count > 0) { | ||
<ul class="navbar-nav ml-auto mega-menu"> | ||
@foreach (var node in nodes) { | ||
var HasChildren = node.HasChildren(); | ||
|
||
var navItemClasses = new List<string>(); | ||
navItemClasses.Add("nav-item"); | ||
if (HasChildren) { navItemClasses.Add("mega-menu__item"); } | ||
navItemClasses.Add("tab-" + node.TabId); | ||
if (node.Breadcrumb) { navItemClasses.Add("active"); } | ||
|
||
var navItemCss = new HtmlString((navItemClasses.Count == 0) ? "" : ("class=\"" + String.Join(" ", navItemClasses.ToArray()) + "\"")); | ||
<li @navItemCss> | ||
<a | ||
href='@(node.Enabled ? node.Url : "#")' | ||
class='nav-link' | ||
@{ | ||
if (HasChildren) { | ||
<text>id="[email protected]"</text> | ||
<text>data-toggle="dropdown"</text> | ||
<text>aria-haspopup="true"</text> | ||
<text>aria-expanded="false"</text> | ||
} | ||
} | ||
>@node.Text</a> | ||
@RenderSubmenu(node) | ||
</li> | ||
} | ||
</ul> | ||
} | ||
} | ||
|
||
@helper RenderSubmenu(MenuNode node) { | ||
var children = node.Children; | ||
if (children.Count > 0) { | ||
<ul class="mega-menu__dropdown" aria-labelledby="[email protected]"> | ||
@foreach (var child in children) { | ||
var HasChildren = child.HasChildren(); | ||
var HasIcon = !String.IsNullOrEmpty(child.Icon); | ||
|
||
var itemClasses = new List<string>(); | ||
itemClasses.Add("tab-" + child.TabId); | ||
itemClasses.Add("mega-menu__submenu"); | ||
|
||
var itemCss = new HtmlString((itemClasses.Count == 0) ? "" : (" class=\"" + String.Join(" ", itemClasses.ToArray()) + "\"")); | ||
|
||
var linkClasses = new List<string>(); | ||
linkClasses.Add("mega-menu__link"); | ||
linkClasses.Add("mega-menu__submenu__header"); | ||
if (child.Breadcrumb) { linkClasses.Add("active"); } | ||
|
||
var linkCss = new HtmlString((linkClasses.Count == 0) ? "" : (" class=\"" + String.Join(" ", linkClasses.ToArray()) + "\"")); | ||
<li @itemCss> | ||
<a @linkCss href='@(child.Enabled ? child.Url : "#")' target="@(child.Target)"> | ||
<img src='@(HasIcon ? child.Icon : "https://placehold.it/60x60")' alt="@(child.Text)" class="mega-menu__submenu__icon" /> | ||
<span>@child.Text</span> | ||
</a> | ||
@RenderSubmenuList(child) | ||
</li> | ||
} | ||
</ul> | ||
} | ||
} | ||
|
||
@helper RenderSubmenuList(MenuNode node) { | ||
var grandchildren = node.Children; | ||
if (grandchildren.Count > 0) { | ||
<ul class="mega-menu__submenu__list"> | ||
@foreach (var grandchild in grandchildren) { | ||
var linkClasses = new List<string>(); | ||
linkClasses.Add("mega-menu__link"); | ||
if (grandchild.Breadcrumb) { linkClasses.Add("active"); } | ||
|
||
var linkCss = new HtmlString((linkClasses.Count == 0) ? "" : (" class=\"" + String.Join(" ", linkClasses.ToArray()) + "\"")); | ||
<li> | ||
<a @linkCss href='@(grandchild.Enabled ? grandchild.Url : "#")' target="@(grandchild.Target)">@grandchild.Text</a> | ||
</li> | ||
} | ||
</ul> | ||
} else { | ||
var HasDescription = !String.IsNullOrEmpty(node.Description); | ||
|
||
<p class="mega-menu__submenu__description">@(HasDescription ? node.Description : "This is the tab description...")</p> | ||
|
||
} | ||
} | ||
|
||
@RenderMegaMenu(root.Children) |
4 changes: 4 additions & 0 deletions
4
Portals/_default/Skins/CLIENT_CODE/menus/NavMegaMenu/menudef.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<manifest> | ||
<template>NavMegaMenu.cshtml</template> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
Portals/_default/Skins/CLIENT_CODE/src/js/modules/enabled-mega-menu.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// Enable mega menu dropdowns | ||
// ========================== | ||
// | ||
// ... | ||
// ------------------------------------------------------------------------ | ||
|
||
function enableMegaMenu() { | ||
const dropdowns = [...document.querySelectorAll('.mega-menu__item')]; | ||
|
||
function showDropdownMenu(event) { | ||
const navItem = event.target; | ||
const navLink = navItem.firstElementChild; | ||
const dropdownMenu = navLink.nextElementSibling; | ||
|
||
navItem.classList.add('show'); | ||
dropdownMenu.classList.add('show'); | ||
navLink.setAttribute('aria-expanded', true); | ||
} | ||
|
||
function hideDropdownMenu(event) { | ||
const navItem = event.target; | ||
const navLink = navItem.firstElementChild; | ||
const dropdownMenu = navLink.nextElementSibling; | ||
|
||
navItem.classList.remove('show'); | ||
dropdownMenu.classList.remove('show'); | ||
navLink.setAttribute('aria-expanded', false); | ||
} | ||
|
||
function navigateToUrl(event) { | ||
const link = event.target.href; | ||
if (link && link !== '#') { | ||
window.location.assign(link); | ||
} | ||
} | ||
|
||
dropdowns.forEach(d => { | ||
d.addEventListener('mouseenter', showDropdownMenu); | ||
d.addEventListener('mouseleave', hideDropdownMenu); | ||
|
||
d.addEventListener( | ||
'click', | ||
event => { | ||
// Don't execute the function if the user is opening the link | ||
// in a new tab by pressing Control or Command while clicking. | ||
if (event.metaKey || event.ctrlKey) return; | ||
navigateToUrl(event); | ||
}, | ||
false | ||
); | ||
}); | ||
} | ||
|
||
export default enableMegaMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,10 @@ a { | |
// Block | ||
// ===== | ||
|
||
img { | ||
max-width: 100%; | ||
} | ||
|
||
blockquote, | ||
p, | ||
ol, | ||
|
Oops, something went wrong.