The AspMenu used by MOSS 2007 and wss 3.0 is based on the .Net 2.0 AspMenu control but has some enhancements built in. The problem is that apparently the SharePoint team sealed the class so you can’t extend the control for yourself.
What they did now is post the sourcecode for their enhanced mossmenu online here. You can just add it as a usercontrol to your masterpage and replace the Sharepoint:AspMenu tag by your custom control, which you can then extend even further.
I used this myself because I wanted to change the logic which menuItem is selected in a certain project. My first goal was to have multiple selected items in my menu but apparently this isn’t allowed by the control. Only 1 menuItem can be set selected = true.
What I did then was have the parentItem of my currentItem selected in my customMenu:
// if no menu item is presently selected, we need to work our way up from the current
// node until we can find a node in the menu item dictionary
while (selectedMenuItem == null && currentNode != null)
{
this.menuItemDictionary.TryGetValue(currentNode.Url, out selectedMenuItem);
// if we found an item to select, go ahead and select (highlight) it
if (selectedMenuItem != null && selectedMenuItem.Selectable)
{
selectedMenuItem.Selected = true;
}
currentNode = currentNode.ParentNode;
}
if (this.selectStaticItemsOnly)
{
// only static items may be selected, keep moving up until we find an item
// that falls within the static range
while (selectedMenuItem != null && selectedMenuItem.Depth >= this.StaticDisplayLevels)
{
selectedMenuItem = selectedMenuItem.Parent;
// if we found an item to select, go ahead and select (highlight) it
if (selectedMenuItem != null && selectedMenuItem.Selectable)
{
selectedMenuItem.Selected = true;
}
}
}
}
After this I could highlight the current node (of which I know the url) in javascript:
function ChangeClassSelectedNodes() {
//Select all links with a href att
$('a[href]').each(function(idx, item) {
//Get the current url
var url = window.location.href.toUpperCase();
//Get each items href in upperCase
var href = item.href.toUpperCase();
//If our current Url contains the items href then change it's class to your SelectedClass
if (url == href) {
item.parentNode.parentNode.className = 'TopMenuSelectedLevel1';
}
});
So after this I’d have my current node selected in my Dynamic flyout menu’s en the highest level parentNode selected in my static menu level.
Gr