﻿
function RegisterAntaWebMenu(partClientId,settings)
{
InitMenuPrototypes();
var webPart=GetDomData($(partClientId),AntaWebPartKey);
webPart.WebMenu=new AntaWebMenu(webPart,settings);
}
function RegisterAntaWebMenuItem(partClientId,settings)
{
var webPart=GetDomData($(partClientId),AntaWebPartKey);
if(webPart!=null)
{
webPart.WebMenu.AddMenuItem(new AntaWebMenuItem(webPart.WebMenu,settings));
}
}
function InitMenuPrototypes()
{
AntaWebMenu.prototype.RegisterButton=function AntaWebMenu_RegisterButton(buttonProperties)
{
if(buttonProperties.Code=="DeleteMenuItem")
{
buttonProperties.Action.ActionConfirm=AntaSR.MenuItemDeleteConfirm;
}
var button=AttachWebButton(this.WebPart.WebForm.Window,buttonProperties,AntaHandleMenuButtonClick);
button.WebMenu=this;
return button;
};
AntaWebMenu.prototype.HandlePartResize=function AntaWebMenu_HandlePartResize(height)
{
if(this.InSiteAdminMode)
{
var toolBox=AntaGetToolBoxPart().WebToolBox;
if(toolBox!=null)
{
if(toolBox.WebPart.GetToggledButton("PageEditView")=="TogglePageProperties")
{
return;
}
}
}
if(this.Orientation==1&&this.MenuRenderType!=3)
{
this.HandleHorizontalMenuResize();
}
};
AntaWebMenu.prototype.HandleHorizontalMenuResize=function AntaWebMenu_HandleHorizontalMenuResize()
{
this.Rect=this.Window.GetElementRect(this.WebPart.PartNode);
var maxWidth=this.Rect.Width;
var currentWidth=0;
var visible=new Array();
var invisible=new Array();
for(var i=0;i<this.MenuItems.length;i++)
{
var menuItem=this.MenuItems[i];
ShowNode(menuItem.MenuItemNode);
var itemWidth=menuItem.GetWidth(this.Window);
if(invisible.length>0||currentWidth+itemWidth>maxWidth)
{
invisible.push(menuItem);
}
else
{
visible.push(menuItem);
currentWidth+=itemWidth;
}
}
if(IsDefined(typeof(this.MarkedMenuItem)))
{
var item=this.MarkedMenuItem.Item;
item.MenuItemNode.title=this.MarkedMenuItem.OrigTitle;
item.MenuItemNode.style.borderRight=this.MarkedMenuItem.OrigBorderRight;
}
if(this.InSiteAdminMode&&invisible.length>0)
{
{
var lastMenuItem=visible.pop();
if(maxWidth-currentWidth<5)
{
if(lastMenuItem!=null)
{
invisible.push(lastMenuItem);
lastMenuItem=visible.pop();
}
}
if(lastMenuItem!=null)
{
this.MarkedMenuItem={
Item:lastMenuItem,
OrigTitle:lastMenuItem.MenuItemNode.title,
OrigBorderRight:lastMenuItem.MenuItemNode.style.borderRight
};
lastMenuItem.MenuItemNode.style.borderRight="solid 5px red";
lastMenuItem.MenuItemNode.title=AntaSR.NotAllMenuItemsAreVisible;
}
}
}
for(var i=0;i<invisible.length;i++)
{
HideNode(invisible[i].MenuItemNode);
}
for(var i=0;i<visible.length;i++)
{
ShowNode(visible[i].MenuItemNode);
}
if(this.FillOut)
{
var newButtonWidth=0;
if(this.NewButtonNode!=null)
{
ShowNode(this.NewButtonNode);
newButtonWidth=this.Window.GetElementRect(this.NewButtonNode).Width;
this.NewButtonNode.style.width=ToPixels(newButtonWidth);
var margin=this.Window.GetHorizontalMarginPaddingBorder(this.NewButtonNode)-this.Window.GetHorizontalPaddingBorder(this.NewButtonNode);
newButtonWidth+=margin;
}
if(currentWidth+newButtonWidth>maxWidth)
{
HideNode(this.NewButtonNode);
}
else
{
currentWidth+=newButtonWidth;
}
ShowNode(this.FillOutPartNode);
var endWidth=this.Window.GetElementRect(this.FillOutPartEndNode).Width;
var availWidth=maxWidth-currentWidth-endWidth;
if(availWidth>0)
{
this.FillOutPartNode.style.width=ToPixels(availWidth);
}
else
{
HideNode(this.FillOutPartNode);
}
}
};
AntaWebMenu.prototype.CreateMoreMenuItem=function AntaWebMenu_CreateMoreMenuItem()
{
var moreNode=this.Window.MakeNode("div","menuitem notselected firstaccentitem normal menulastitem lastaccentitem");
moreNode.title="Meer...";
moreNode.style.float="left";
var beginNode=this.Window.MakeNode("div","menuitembegin");
moreNode.appendChild(beginNode);
var centerNode=this.Window.MakeNode("span","text menuitemcenter name");
centerNode.innerHTML="Meer...";
moreNode.appendChild(centerNode);
var endNode=this.Window.MakeNode("div","menuitemend");
moreNode.appendChild(endNode);
var lastMenuItemNode=this.MenuItems[this.MenuItems.length-1].MenuItemNode;
lastMenuItemNode.parentNode.insertBefore(moreNode,lastMenuItemNode.nextSibling);
var moreMenuItem=new AntaWebMenuItem(this,{"MenuItemId":moreNode});
moreMenuItem.Rect=this.Window.GetElementRect(moreNode);
moreMenuItem.Rect.Width=this.Window.GetElementRect(beginNode).Width+this.Window.GetElementRect(centerNode).Width+this.Window.GetElementRect(endNode).Width;
moreMenuItem.Rect.Height=this.Window.GetElementRect(centerNode).Height;
return moreMenuItem;
};
AntaWebMenu.prototype.AddMenuItem=function(menuItem)
{
this.MenuItems.push(menuItem);
};
}
function AntaWebMenu(webPart,settings)
{
this.WebPart=webPart;
this.Window=webPart.WebForm.Window;
this.ParentMenuId=settings.ParentMenuId;
this.MenuRenderType=settings.MenuRenderType;
this.Orientation=settings.Orientation;
this.InSiteAdminMode=settings.InSiteAdminMode;
this.MenuItems=new Array();
this.NewButtonNode=null;
if(this.InSiteAdminMode&&IsDefined(settings.NewButtonId))
{
this.NewButtonNode=$(settings.NewButtonId);
}
this.FillOut=false;
if(IsDefined(typeof(settings.FillOutPartId)))
{
this.FillOutPartNode=$(settings.FillOutPartId);
this.FillOutPartEndNode=$(settings.FillOutPartEndId);
this.FillOut=true;
}
webPart.ResizeHandler=this;
}
function AntaHandleMenuButtonClick(button)
{
if(button.Code=="ExpandMenuItem")
{
if(button.Pressed)
{
ShowNode(button.Window.Child(button.ContainerClientId,"T_List"));
}
else
{
HideNode(button.Window.Child(button.ContainerClientId,"T_List"));
}
}
switch(button.Code)
{
case "ExpandMenuItem":
case "DeleteMenuItem":
case "EditMenuItem":
case "NewMenuItem":
case "MoveMenuItemUp":
case "MoveMenuItemDown":
var isCachedClientMenuAction=(button.Code=="DeleteMenuItem"||button.Code=="MoveMenuItemUp"||button.Code=="MoveMenuItemDown");
if(isCachedClientMenuAction)
{
button.WebMenu.CheckClientSideMenu();
}
if(button.Action!=null)
{
button.Action.LongOperation=false;
AntaClearActionParameter(button.Action,"contentitemid");
AntaAddActionParameter(button.Action,"contentitemid",AntaPageMetaInformation.ContentItemId);
AntaClearActionParameter(button.Action,"themeid");
AntaAddActionParameter(button.Action,"themeid",AntaToolboxCurrentTheme.ThemeId);
button.Action.IsAsync=isCachedClientMenuAction;
button.WebMenu.WebPart.ExecuteActionForPart(AntaGetToolBoxPart(),button.Action,button.Action.IsAsync);
}
if(isCachedClientMenuAction)
{
var liNode=FindParentByTag(button.ButtonNode,"li");
if(liNode!=null)
{
switch(button.Code)
{
case "MoveMenuItemUp":
if(liNode.previousSibling!=null)
{
SwapNode(liNode,liNode.previousSibling);
}
break;
case "MoveMenuItemDown":
if(liNode.nextSibling!=null)
{
SwapNode(liNode,liNode.nextSibling);
}
break;
case "DeleteMenuItem":
button.WebMenu.Window.RemoveNode(liNode);
break;
}
}
button.WebMenu.CheckClientSideMenu();
}
break;
}
}
AntaWebMenu.prototype.CheckClientSideMenu=function AntaWebMenu_CheckClientSideMenu()
{
var rootlist=this.WebPart.Child("T_List");
this.IterateChilds(0,rootlist);
};
AntaWebMenu.prototype.IterateChilds=function AntaWebMenu_IterateChilds(n,list)
{
if(list!=null&&list.childNodes!=null&&list.nodeName.IsListTag())
{
var len=list.childNodes.length;
if(len>0)
{
for(var i=0;i<len;i++)
{
var liNode=list.childNodes[i];
var hasChilds=this.IterateChilds(n+1,liNode.lastChild.lastChild);
var prefix=liNode.id.replace("ListItem","");
if(n>0)
{
var upId="MoveMenuItemUp";
var upButtonNode=$(prefix+"ButtonMenuWebPart_"+upId+"_"+upId,this.Window.WindowNode);
var upButton=GetDomEventData(upButtonNode);
AntaClearActionParameter(upButton.Action,"newseqno");
AntaAddActionParameter(upButton.Action,"newseqno",i);
if(i==0)
{
HideNode(upButtonNode);
}
else
{
ShowNode(upButtonNode);
}
var downId="MoveMenuItemDown";
var downButtonNode=$(prefix+"ButtonMenuWebPart_"+downId+"_"+downId,this.Window.WindowNode);
var downButton=GetDomEventData(downButtonNode);
AntaClearActionParameter(downButton.Action,"newseqno");
AntaAddActionParameter(downButton.Action,"newseqno",i+2);
if(i==(len-1))
{
HideNode(downButtonNode);
}
else
{
ShowNode(downButtonNode);
}
var delId="DeleteMenuItem";
var delButtonNode=$(prefix+"ButtonMenuWebPart_"+delId+"_"+delId,this.Window.WindowNode);
var expandId="ExpandMenuItem";
var expandButtonNode=$(prefix+"ButtonMenuWebPart_"+expandId,this.Window.WindowNode);
if(hasChilds)
{
HideNode(delButtonNode);
expandButtonNode.style.visibility='visible';
}
else
{
ShowNode(delButtonNode);
expandButtonNode.style.visibility='hidden';
}
}
}
return true;
}
}
return false;
};
function AntaWebMenuItem(webMenu,settings)
{
this.WebMenu=webMenu;
this.MenuItemNode=$(settings.MenuItemId);
this.AnchorNode=$(settings.AnchorId);
}
AntaWebMenuItem.prototype.GetWidth=function AntaWebMenuItem_GetWidth(win)
{
this.AnchorNode.style.width=ToPixels(win.GetElementRect(this.AnchorNode).Width-win.GetHorizontalPaddingBorder(this.AnchorNode));
return win.GetElementRect(this.MenuItemNode).Width;
};
function AntaDropMenuMouseOver(e)
{
if(!IsDefined(typeof(e))){var e=this.document.parentWindow.event;}
StoreEvent(e);
var dropMenu=GetDomEventData(this);
if(dropMenu!=null)
{
if(!dropMenu.IsOpen)
{
if(dropMenu.CloseTimer!=null)
{
window.clearTimeout(dropMenu.CloseTimer);
dropMenu.CloseTimer=null;
return;
}
dropMenu.Open();
}
}
}
function AntaDropMenuMouseOut(e)
{
if(!IsDefined(typeof(e))){var e=this.document.parentWindow.event;}
StoreEvent(e);
var dropMenu=GetDomEventData(this);
if(dropMenu!=null)
{
if(dropMenu.IsOpen)
{
dropMenu.CloseTimer=window.setTimeout(function()
{
if(dropMenu.IsOpen)
{
if(!PointInRect(AntaEvent.X,AntaEvent.Y,dropMenu.DropNodeRect)&&!PointInRect(AntaEvent.X,AntaEvent.Y,dropMenu.ParentMenuItem.Rect))
{
dropMenu.Close();
}
}
},500);
}
}
}
function AntaDropMenu(parentMenuItem,window)
{
this.ParentMenuItem=parentMenuItem;
this.Window=window;
this.MenuItems=new Array();
this.IsOpen=false;
this.CloseTimer=null;
this.DropRoot=null;
this.DropNode=this.Window.MakeNode("div");
this.DropNode.className="dropmenu";
this.DropNode.style.position="absolute";
var pmn=this.ParentMenuItem.MenuItemNode
SetDomEventData(pmn,this);
SetDomEventData(this.DropNode,this);
this.DropNode.onmouseover=pmn.onmouseover=pmn.onclick=AntaDropMenuMouseOver;
this.DropNode.onmouseout=AntaDropMenuMouseOut;
}
AntaDropMenu.prototype.AddItem=function AntaDropMenu_AddItem(menuItem,addLast)
{
this.MenuItems.push(menuItem);
menuItem.MenuItemNode.style.styleFloat="";
menuItem.MenuItemNode.parentNode.removeChild(menuItem.MenuItemNode);
addLast=(addLast==null||addLast);
if(addLast)
{
this.DropNode.appendChild(menuItem.MenuItemNode);
}
else
{
if(this.DropNode.children[0]==null)
{
this.DropNode.appendChild(menuItem.MenuItemNode);
}
else
{
this.DropNode.insertBefore(menuItem.MenuItemNode,this.DropNode.children[0]);
}
}
};
AntaDropMenu.prototype.Open=function AntaDropMenu_Open()
{
var blocker=this.ScreenBlocker=new AntaScreenBlocker(this.Window);
var eventHandler={DropMenu:this,OnMouseDown:function(){this.DropMenu.Close();},OnKeyDown:function(){if(AntaEvent.KeyCode==27){this.DropMenu.Close();}}};
setTimeout(function(){blocker.MouseDownHandler=blocker.KeyDownHandler=eventHandler;},100);
this.DropRoot=this.Window.MakeNode("div");
var pmn=this.ScreenBlocker.ParentMenuNode=this.Window.MakeNode("div");
this.ScreenBlocker.DropNode=this.Window.MakeNode("div");
this.DropRoot.appendChild(this.ScreenBlocker.ParentMenuNode);
this.DropRoot.appendChild(this.ScreenBlocker.DropNode);
this.Window.AppendBodyNode(this.DropRoot);
SwapNode(this.DropNode,this.ScreenBlocker.DropNode);
var rect=this.ParentMenuItem.Rect;
this.DropNode.style.left=ToPixels(rect.Left);
this.DropNode.style.top=ToPixels(rect.Top+rect.Height);
pmn.style.position="absolute";
pmn.style.left=ToPixels(rect.Left);
pmn.style.top=ToPixels(rect.Top);
pmn.style.width=ToPixels(rect.Width);
pmn.style.height=ToPixels(rect.Height);
pmn.onmouseover=AntaDropMenuMouseOver;
pmn.onmouseout=AntaDropMenuMouseOut;
SetDomEventData(pmn,this);
ShowNode(this.DropNode);
this.DropNodeRect=this.Window.GetElementRect(this.DropNode);
this.IsOpen=true;
};
AntaDropMenu.prototype.Close=function AntaDropMenu_Close()
{
HideNode(this.DropNode);
if(this.ScreenBlocker!=null)
{
this.ScreenBlocker.ParentMenuNode=null;
SwapNode(this.DropNode,this.ScreenBlocker.DropNode);
this.ScreenBlocker.DropNode=null;
this.ScreenBlocker.Close();
if(this.DropRoot!=null)
{
this.Window.RemoveNode(this.DropRoot);
}
}
this.DropRoot=null;
this.CloseTimer=null;
this.IsOpen=false;
};


