Tuesday, January 1, 2008

SharePoint 2003 Menus (MSOWebPartPage_OpenMenu)

As we were attempting to add custom menus to SharePoint 2003 we discovered that is was actually pretty easy using a built in JavaScript function provided (and utilitized) by SharePoint. The function name is MSOWebPartPage_OpenMenu and the problem was that the posts we found discussing how to do it with SharePoint seemed to indicate that the function allowed some optional parameters but we couldn't seem to locate an online reference describing the function in detail. Since we're not SharePoint 'gurus' we did a search of our server which indicated that it was getting pulled from the IE55UP.js file.


function MSOWebPartPage_OpenMenu(MenuToOpen,SourceElement,WebPart,InConnectionsMode)
{
if(WebPart)
{
MenuWebPart = WebPart
MenuWebPartID = WebPart.WebPartID;
var minOption = MenuToOpen.all.item('MSOMenu_Minimize');
var restoreOption = MenuToOpen.all.item('MSOMenu_Restore');
var closeOption = MenuToOpen.all.item('MSOMenu_Close');
var deleteOption = MenuToOpen.all.item('MSOMenu_Delete');
var exportOption = MenuToOpen.all.item('MSOMenu_Export');
var resetPersOption = MenuToOpen.all.item('MSOMenu_RestorePartDefaults');
var helpOption = MenuToOpen.all.item('MSOMenu_Help');
var connectionOption = MenuToOpen.all.item('MSOMenu_Connections');
if(minOption)
{
minOption.style.display = (WebPart.allowMinimize == 'false' || WebPart.style.display == 'none') ? 'none' : '';
}
if(restoreOption)
{
restoreOption.style.display = (WebPart.allowMinimize == 'false' || WebPart.style.display != 'none') ? 'none' : '';
}
if(closeOption)
{
closeOption.style.display = (WebPart.allowRemove == 'false') ? 'none' : '';
}
if(deleteOption)
{
deleteOption.style.display = (MSOLayout_inDesignMode && WebPart.allowDelete != 'false') ? '' : 'none';
}
if(exportOption)
{
exportOption.style.display = (WebPart.allowExport == 'false') ? 'none' : '';
}
if(helpOption)
{
helpOption.style.display = (WebPart.helpLink == null) ? 'none' : "";
}
if(resetPersOption)
{
resetPersOption.style.display = (MSOLayout_inDesignMode && WebPart.HasPers == 'true' && WebPart.OnlyForMePart != 'true') ? '' : 'none';
}
if(connectionOption)
{
connectionOption.style.display = (MSOLayout_inDesignMode ? '' : 'none');
}
if(InConnectionsMode != 'False')
{
var connMenu = document.all.item('MSOMenu_Connections'+WebPart.id);
if(connectionOption != null && connMenu != null)
{
connectionOption.outerHTML = connMenu.innerHTML;
}
}
}
try
{
if (!MenuToOpen.isOpen()) MenuToOpen.show(SourceElement, true);
}
catch(e)
{
}
}


In case you're looking for how to build a menu in SharePoint see these links:
SharePoint Menus - roll your own
WSS Navigation