antonydoyle
4/22/2016 - 10:58 AM

Foundation drilldown menu in razor

Foundation drilldown menu in razor

@using Contensis.Framework.Web
@using System.Collections.ObjectModel
@using Contensis.Framework.Web.Search
@{
    
	var folderID = 1;

	var folderlist = Properties.TopLevel != null ? Properties.TopLevel : 1;

    CurrentContext.Page.Scripts.RegisterJQuery();
    NodeFactory nf = new NodeFactory();
  
  	// And now, we get the parentFolder to use to set the menu later
  	FolderNode parentFolder = CurrentNode.Parent;
  
<div class="off-canvas position-right" id="offCanvas" data-off-canvas data-position="right" aria-hidden="false">  
  	<nav class="drilldown-menu" data-ajaxpage="drilldown-menu">
        <div class="is-drilldown" style="height: 575.625px; width: 250px;">
            <ul class="vertical menu offCanvasNav" data-drilldown role="menubar">

    
                @foreach (var fnode in folderlist)
                    {
      					int fId = fnode.Folder.ID;
    					FolderNode rootFolder = (FolderNode)nf.LoadById(fId);
						
      					int childFCount = rootFolder.Children<FolderNode>().Count();
      					int childPCount = rootFolder.Children<ContentNode>().Count();
      					<li role="menuitem" class="offCanvasNav__level1">
                            <a class="sys_16 offCanvasNav__level1Link" href="@rootFolder.Path"  data-folderid="@rootFolder.ID">@rootFolder.MenuName</a>
 
                              @DoNextLevel(rootFolder)
   						</li>
                    }
            </ul>
        </div>
    </nav>


</div>
}



@helper DoNextLevel(FolderNode folderId)
{
  NodeFactory nf = new NodeFactory();
  int childFCount = folderId.Children<FolderNode>().Count();
  int childPCount = folderId.Children<ContentNode>().Count();
  if (childFCount != 0 || childPCount != 0) {
    <ul class="nested vertical menu" data-submen>
      @foreach (var subPage in folderId.Children<ContentNode>().Where(sP => sP.IncludeInMenu == true).OrderBy(sP => sP.MenuOrder)) {

         <li class="offCanvasNav__level2">
           <a class="offCanvasNav__level1Link" href="@subPage.Path">@subPage.MenuName</a>
         </li>

      }
      @foreach (var subFolder in folderId.Children<FolderNode>().Where(sP => sP.IncludeInMenu == true && sP.Descendants().Count() > 0).OrderBy(sP => sP.MenuOrder)) {
		FolderNode nextFolder = (FolderNode)nf.LoadById(subFolder.ID);
        if (childFCount != 0 && childPCount != 0 && subFolder.MenuName.ToString().ToLower() != "images" ) {
          <li class="offCanvasNav__level2">
            <a class="offCanvasNav__level1Link" href="@subFolder.Path">@subFolder.MenuName</a>

            @DoNextLevel(nextFolder)
          </li>
        }
      }
    </ul>
  }
}

@{
  
       
  
}

@if (parentFolder.ID != 2) {
  
  	var currentPage = CurrentNode.FullPath;
  	var currentDepth = CurrentNode.Depth;
    //This will step through all the elements and add the is-active class.
    <script>      
    	$('.drilldown-menu a[href="@currentPage"]').parentsUntil($( "ul.offCanvasNav" )).addClass('is-active');
    </script>
  
}