123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479 |
- function RadMenuItem(domElement)
- {
- if (domElement)
- {
- this.SetDomElement(domElement);
- }
- else
- {
- this.ClientSide = true;
- }
-
- this.IsSeparator = false;
- this.AnimationContainer = null;
- this.OpenedItem = null;
- this.FocusedItem = null;
- this.Items = [];
- this.Attributes = {};
- this.Index = -1;
- this.Level = -1;
- this.Parent = null;
- this.Menu = null;
- this.GroupSettings = {};
- this.TimeoutPointer = null;
- this.Templated = false;
- this.NavigateAfterClick = true;
-
- // css classes, load from the server
- this.FocusedCssClass = "focused";
- this.ClickedCssClass = "clicked";
- this.ExpandedCssClass = "expanded";
- this.DisabledCssClass = "disabled";
- this.CssClass = "";
-
- // state flags
- this.State = RadMenuItemState.Closed;
- this.Focused = false;
- this.Clicked = false;
- this.Enabled = true;
-
- this.Initialized = false;
- }
- RadMenuItem.prototype.SetDomElement = function(domElement)
- {
- this.DomElement = domElement;
-
- this.LinkElement = RadMenu.GetFirstChildByTagName(this.DomElement, "a");
-
- if (this.LinkElement == null)
- {
-
- this.ID = this.DomElement.id;
- this.TextElement = RadMenu.GetFirstChildByTagName(this.DomElement, "span");
- this.NavigateUrl = "";
- }
- else
- {
- this.ID = this.LinkElement.id;
- this.TextElement = RadMenu.GetFirstChildByTagName(this.LinkElement, "span");
- this.NavigateUrl = this.LinkElement.href;
- }
- }
- RadMenuItem.prototype.PostInitializeItems = function ()
- {
- for (var i = 0; i < this.Items.length; i ++)
- {
- this.Items[i].PostInitialize();
- }
- }
- RadMenuItem.prototype.SetText = function (text)
- {
- this.PostInitialize();
- this.TextElement.innerHTML = text;
- this.Text = text;
- this.RecordState();
- }
- RadMenuItem.prototype.SetNavigateUrl = function (url)
- {
- this.PostInitialize();
- this.LinkElement.setAttribute("href", url);
- this.NavigateUrl = url;
- this.RecordState();
- }
- RadMenuItem.prototype.SetValue = function (value)
- {
- this.PostInitialize();
- this.Value = value;
- this.RecordState();
- }
- RadMenuItem.prototype.InitializeDomElements = function()
- {
- if (!this.Templated)
- {
- this.AnimationContainer = RadMenu.GetFirstChildByTagName(this.DomElement, "div");
- this.ImageElement = RadMenu.GetFirstChildByTagName(this.LinkElement || this.DomElement, "img");
- if (this.ImageElement)
- {
- this.ImageUrl = this.ImageElement.src;
- }
- }
- else
- {
- this.TextElement = RadMenu.GetFirstChildByTagName(this.DomElement, "div");
- this.AnimationContainer = this.TextElement.nextSibling;
- }
-
- if (this.AnimationContainer)
- {
- var ul = this.AnimationContainer.getElementsByTagName("ul")[0];
-
- this.ChildItemList = ul;
-
- if (this.ChildItemList.parentNode != this.AnimationContainer)
- {
- this.ScrollWrap = this.ChildItemList.parentNode;
- }
- }
- }
- RadMenuItem.prototype.InitializeAnimation = function()
- {
- this.DetermineExpandDirection();
-
- if (!this.AnimationContainer)
- {
- return;
- }
-
- this.Ease = new RadControlsNamespace.Ease(
- this.ScrollWrap || this.ChildItemList,
- this.Menu,
- this.GroupSettings.OffsetX,
- this.GroupSettings.OffsetY,
- this,
- true
- );
- if (this.Ease.Overlay.Shim && this.LinkElement)
- {
- this.Ease.Overlay.Shim.id = this.LinkElement.id + "IframeOverlay";
- }
- var expandDirection = this.GroupSettings.ExpandDirection;
- var easeProperty = RadMenuNamespace.ExpandDirectionPropertyName[expandDirection];
-
- this.Ease.SetSide(easeProperty);
- this.TextElement.className = "text expand" + this.Ease.GetSide();
- this.AnimationContainer.style.zIndex = this.GlobalIndex + 10;
- this.ChildItemList.style.zIndex = this.GlobalIndex + 10;
- if (this.ScrollWrap)
- {
- this.CreateScroll();
- }
- }
- RadMenuItem.prototype.Initialize = function ()
- {
- RadControlsNamespace.DomEventMixin.Initialize(this);
- this.LoadConfiguration();
- this.InitializeDomElements();
- if (this.TextElement && this.TextElement.firstChild)
- {
-
- this.Text = this.TextElement.firstChild.nodeValue;
- }
-
- this.OriginalZIndex = Math.max(this.DomElement.style.zIndex, this.Menu.OriginalZIndex);
-
- };
- RadMenuItem.prototype.PostInitialize = function ()
- {
- if (this.Initialized)
- {
- return;
- }
- this.InitializeAnimation();
- this.AttachEventHandlers();
- this.RenderAccessKey();
- RadMenu.CreateState(this);
- this.UpdateCssClass();
- this.Initialized = true;
- }
- RadMenuItem.prototype.RenderAccessKey = function ()
- {
- if (this.IsSeparator || this.Templated)
- {
- return;
- }
-
- var accessKey = this.LinkElement.accessKey.toLowerCase();
-
- // If accessKey is not set
- if (!accessKey)
- {
- return;
- }
- var text = this.TextElement.firstChild.nodeValue;
- var indexOfAccessKey = text.toLowerCase().indexOf(accessKey);
-
- // If accesKey is not found
- if (indexOfAccessKey == -1)
- {
- return;
- }
-
- this.TextElement.innerHTML =
- text.substr(0, indexOfAccessKey) +
- "<u>" +
- text.substr(indexOfAccessKey, 1) +
- "</u>" +
- text.substr(indexOfAccessKey + 1, text.length);
- }
- RadMenuItem.prototype.CreateScroll = function ()
- {
- this.ScrollWrap.style.zIndex = this.GlobalIndex + 10;
- this.BuildScrollObject(false);
- }
- RadMenuItem.prototype.BuildScrollObject = function (wrapNeeded)
- {
- var isVertical = RadMenuNamespace.ItemFlow.Vertical == this.GroupSettings.Flow;
- var options = {PerTabScrolling : false, ScrollButtonsPosition : 1, ScrollPosition : 0};
- this.Scroll = new RadControlsNamespace.Scroll(this.ChildItemList, isVertical, options);
- this.Scroll.ScrollOnHover = true;
- this.Scroll.LeaveGapsForArrows = false;
- this.Scroll.WrapNeeded = wrapNeeded;
- if (this.GroupSettings.Flow == RadMenuNamespace.ItemFlow.Vertical)
- {
- this.Scroll.LeftArrowClass = "topArrow";
- this.Scroll.LeftArrowClassDisabled = "topArrowDisabled";
- this.Scroll.RightArrowClass = "bottomArrow";
- this.Scroll.RightArrowClassDisabled = "bottomArrowDisabled";
- }
- }
- RadMenuItem.prototype.CreateRuntimeScroll = function (height)
- {
- if (this.Scroll)
- {
- this.Scroll.SetHeight(height);
- return;
- }
-
- this.BuildScrollObject(true);
- this.Scroll.Initialize()
-
- this.ScrollWrap = this.ChildItemList.parentNode;
- this.Ease.Element = this.ScrollWrap;
- this.Ease.Overlay.Element = this.ScrollWrap;
- this.ScrollWrap.className = "scrollWrap " + this.ChildItemList.className;
- this.ChildItemList.className = this.ChildItemList.className.replace("group", "");
- this.Scroll.SetHeight(height);
- }
- RadMenuItem.prototype.Dispose = function ()
- {
- if (!this.Initialized) return;
- this.DisposeDomEventHandlers();
- if (this.Ease)
- {
- this.Ease.Dispose();
- }
- this.DomElement = null;
- this.LinkElement = null;
- this.AnimationContainer = null;
- }
- RadMenuItem.prototype.Focus = function ()
- {
- if (!this.CanFocus())
- {
- return;
- }
-
- this.PostInitializeItems();
-
- if (this.Parent.OpenedItem && this.Parent.OpenedItem != this)
- {
- this.Parent.OpenedItem.Close();
- }
-
- if (this.Parent.State != RadMenuItemState.Open && this.Parent.Open)
- {
- this.Parent.Open();
- }
- this.Parent.FocusedItem = this;
-
- if (!this.Focused && this.LinkElement)
- {
- this.LinkElement.focus();
- }
-
- this.UpdateCssClass();
-
- this.RaiseEvent("OnClientItemFocus");
- }
- RadMenuItem.prototype.Hide = function()
- {
- if (this.LinkElement)
- {
- this.LinkElement.style.display = "none";
- }
- else
- {
- this.TextElement.style.display = "none";
- }
-
- if (this.Parent.Flow == RadMenuNamespace.ItemFlow.Vertical)
- {
- var siblings = this.Parent.Items;
- for (var i = 0; i < siblings.length; i++)
- {
- if (siblings[i] != this)
- {
- if (siblings[i].LinkElement)
- {
- siblings[i].LinkElement.style.width = "auto";
- }
- }
- }
- if (RadControlsNamespace.Browser.IsSafari)
- {
- this.Parent.ChildItemList.style.width = "auto";
- }
-
- this.Menu.WidthFixed = false;
-
- if (this.Parent.DomElement.offsetWidth > 0)
- {
- this.Menu.FixItemWidth(this.Parent);
- }
- }
- }
- RadMenuItem.prototype.IsVisible = function()
- {
- if (!this.LinkElement)
- {
- return this.TextElement.style.display != "none";
- }
-
- return this.LinkElement.style.display != "none";
- }
- RadMenuItem.prototype.Show = function()
- {
- if (this.LinkElement)
- {
- this.LinkElement.style.display = "";
- }
- else
- {
- this.TextElement.style.display = "";
- }
-
- if (this.Parent.Flow == RadMenuNamespace.ItemFlow.Vertical)
- {
- this.Menu.WidthFixed = false;
-
- if (this.Parent.DomElement.offsetWidth > 0)
- {
- this.Menu.FixItemWidth(this.Parent);
- }
- }
- }
- RadMenuItem.prototype.Blur = function ()
- {
- if (this.IsSeparator)
- {
- return;
- }
-
- if (this.Focused)
- {
- this.LinkElement.blur();
- }
-
- this.Parent.FocusedItem = null;
- this.UpdateCssClass();
- this.RaiseEvent("OnClientItemBlur");
- }
-
- RadMenuItem.prototype.GetEaseSide = function ()
- {
- var expandDirection = this.GroupSettings.ExpandDirection;
- return RadMenuNamespace.ExpandDirectionPropertyName[expandDirection];
- }
- RadMenuItem.prototype.RaiseEvent = function(eventName)
- {
- return this.Menu.RaiseEvent(eventName, {Item:this});
- }
- RadMenuItem.prototype.UpdateCssClass = function ()
- {
- if (this.IsSeparator || this.Templated)
- {
- return;
- }
-
- var cssClass = "link " + this.CssClass;
-
- if (this.Focused)
- {
- cssClass = cssClass + " " + this.FocusedCssClass;
- }
- if (this.State == RadMenuItemState.Open)
- {
- cssClass = cssClass + " " + this.ExpandedCssClass;
- }
- if (this.Clicked)
- {
- cssClass = cssClass + " " + this.ClickedCssClass;
- }
- if (!this.Enabled)
- {
- cssClass = cssClass + " " + this.DisabledCssClass;
- }
- this.LinkElement.className = cssClass;
- this.UpdateImageUrl();
- }
- RadMenuItem.prototype.UpdateImageUrl = function ()
- {
- if (!this.ImageElement) return;
- var newUrl = this.ImageUrl;
- if (this.Hovered && this.ImageOverUrl)
- {
- newUrl = this.ImageOverUrl;
- }
- if (this.State == RadMenuItemState.Open && this.ExpandedImageUrl)
- {
- newUrl = this.ExpandedImageUrl;
- }
-
- if (!this.Enabled && this.DisabledImageUrl)
- {
- newUrl = this.DisabledImageUrl;
- }
-
- if (this.Clicked && this.ImageClickedUrl)
- {
- newUrl = this.ImageClickedUrl;
- }
-
-
- newUrl = newUrl.replace(/&/ig, "&");
-
- if (newUrl != this.ImageElement.src)
- {
- this.ImageElement.src = newUrl;
- }
- }
- RadMenuItem.prototype.Enable = function ()
- {
- if (this.IsSeparator || this.Templated)
- {
- return;
- }
-
- this.LinkElement.disabled = "";
-
- if (this.ImageElement)
- {
- this.ImageElement.disabled = "";
- }
-
- this.Enabled = true;
- this.EnableDomEventHandling();
- this.UpdateCssClass();
- }
- RadMenuItem.prototype.Disable = function ()
- {
- if (this.IsSeparator || this.Templated)
- {
- return;
- }
-
- this.LinkElement.disabled = "disabled";
-
- if (this.ImageElement)
- {
- this.ImageElement.disabled = "disabled";
- }
- this.Enabled = false;
- this.DisableDomEventHandling();
- this.UpdateCssClass();
- }
-
- RadMenuItem.prototype.OnCollapseComplete = function()
- {
- this.RaiseEvent("OnClientItemClose");
- }
- RadMenuItem.prototype.HideChildren = function ()
- {
- for (var i = 0; i < this.Items.length; i++)
- {
- if (this.Items[i].AnimationContainer)
- {
- this.Items[i].AnimationContainer.style.display = "none";
- }
- }
- }
- RadMenuItem.prototype.CalculateScrollWrapSize = function ()
- {
- if (!this.ScrollWrap)
- {
- return;
- }
- if (!this.ScrollWrap.style.height)
- {
- this.ScrollWrap.style.height = this.ChildItemList.offsetHeight + "px";
- }
- var isVertical = RadMenuNamespace.ItemFlow.Vertical == this.Flow;
- if (isVertical)
- {
- this.ScrollWrap.style.width = this.ChildItemList.offsetWidth + "px";
- }
- };
- RadMenuItem.prototype.OnEase = function(newValue)
- {
- var isVertical = RadMenuNamespace.ItemFlow.Vertical == this.Flow;
-
- if (!isVertical) return;
- if (this.ChildrenDetached && this.Scroll)
- {
- //Hack for IE6 - arrows disappear after scrolling
- this.Scroll.RightArrow.style.cssText = this.Scroll.RightArrow.style.cssText;
- this.Scroll.LeftArrow.style.cssText = this.Scroll.LeftArrow.style.cssText;
- }
- }
- /**
- * Event handlers
- */
- RadMenuItem.prototype.AttachEventHandlers = function ()
- {
- this.AttachDomEvent(this.DomElement, "mouseover", "MouseOverHandler");
- this.AttachDomEvent(this.DomElement, "mouseout", "MouseOutHandler");
-
- if (this.IsSeparator || this.Templated)
- {
- return;
- }
-
- this.AttachDomEvent(this.LinkElement, "click", "ClickHandler", true);
- this.AttachDomEvent(this.LinkElement, "mouseout", "HRefMouseOutHandler");
- this.AttachDomEvent(this.LinkElement, "mouseover", "HRefMouseOverHandler");
-
- this.AttachDomEvent(this.LinkElement, "mousedown", "MouseDownHandler");
- this.AttachDomEvent(this.LinkElement, "mouseup", "MouseUpHandler");
-
- this.AttachDomEvent(this.LinkElement, "blur", "BlurHandler");
- this.AttachDomEvent(this.LinkElement, "focus", "FocusHandler");
-
- this.AttachDomEvent(this.LinkElement, "keydown", "KeyDownHandler");
- };
- RadMenuItem.prototype.MouseDownHandler = function (e)
- {
- this.Clicked = true;
- this.UpdateCssClass();
- }
- RadMenuItem.prototype.MouseUpHandler = function (e)
- {
- this.Clicked = false;
- this.UpdateCssClass();
- }
- RadMenuItem.prototype.HRefMouseOutHandler = function (e)
- {
- var to = RadControlsNamespace.DomEvent.GetRelatedTarget(e);
-
- if (this.Menu.IsChildOf(this.LinkElement, to) || to == this.LinkElement)
- {
- return;
- }
- this.Hovered = false;
-
- this.UpdateImageUrl();
-
- this.RaiseEvent("OnClientMouseOut");
- }
- RadMenuItem.prototype.HRefMouseOverHandler = function (e)
- {
- var from = RadControlsNamespace.DomEvent.GetRelatedTarget(e);
- if (this.Menu.IsChildOf(this.LinkElement, from) || this.LinkElement == from)
- {
- return;
- }
-
- this.Hovered = true;
-
- this.UpdateImageUrl();
-
- this.RaiseEvent("OnClientMouseOver");
- }
- RadMenuItem.prototype.KeyDownHandler = function (e)
- {
- var arrows = {left : 37, up : 38, right : 39, down : 40, esc : 27 };
-
- var keyCode = RadControlsNamespace.DomEvent.GetKeyCode(e);
-
- if (keyCode == arrows.right)
- {
- if (this.Menu.RightToLeft)
- {
- this.HandleLeftArrow();
- }
- else
- {
- this.HandleRightArrow();
- }
- }
- else if (keyCode == arrows.left)
- {
- if (this.Menu.RightToLeft)
- {
- this.HandleRightArrow();
- }
- else
- {
- this.HandleLeftArrow();
- }
- }
- else if (keyCode == arrows.up)
- {
- this.HandleUpArrow();
- }
- else if (keyCode == arrows.down)
- {
- this.HandleDownArrow();
- }
-
- else if (keyCode == arrows.esc)
- {
- if (this.Parent == this.Menu)
- {
- this.Blur();
- }
- else
- {
- this.Parent.Close();
- this.Parent.Focus();
- }
- }
- else
- {
- return;
- }
-
- RadControlsNamespace.DomEvent.PreventDefault(e);
- }
- RadMenuItem.prototype.FocusHandler = function (e)
- {
- this.Focused = true;
- this.Focus();
- }
- RadMenuItem.prototype.BlurHandler = function (e)
- {
- this.Focused = false;
- //Korchev: Causes problem when second level item is clicked - the item cannot be open after that
- //this.Menu.Clicked = false;
-
- this.Blur();
- }
- RadMenuItem.prototype.NavigatesToURL = function ()
- {
- if (location.href + "#" == this.NavigateUrl || location.href == this.NavigateUrl)
- {
- return false;
- }
- return (new RegExp("//")).test(this.LinkElement.href);
- }
- RadMenuItem.prototype.Validate = function ()
- {
- if (!this.Menu.CausesValidation || this.NavigatesToURL())
- {
- return true;
- }
-
- if (typeof (Page_ClientValidate) != 'function')
- {
- return true;
- }
-
- return Page_ClientValidate(this.Menu.ValidationGroup);
- }
- RadMenuItem.prototype.ClickHandler = function (e)
- {
- if (!this.Enabled)
- {
- return RadControlsNamespace.DomEvent.PreventDefault(e);
- }
- if (!this.RaiseEvent("OnClientItemClicking"))
- {
- return RadControlsNamespace.DomEvent.PreventDefault(e);
- }
- if (!this.Validate())
- {
- return RadControlsNamespace.DomEvent.PreventDefault(e);
- }
-
- var returnValue = true;
-
- if (!this.Menu.ClickToOpen)
- {
- returnValue = true;
- }
- else if (this.Level > 1) // only first level items toggle this
- {
- returnValue = true;
- }
- else
- {
- if (!this.Menu.Clicked)
- {
- this.Open();
- }
- else
- {
- this.Close();
- }
-
- this.Menu.Clicked = !this.Menu.Clicked;
- }
-
- this.RaiseEvent("OnClientItemClicked");
- if (!this.NavigateAfterClick || !returnValue)
- {
- RadControlsNamespace.DomEvent.PreventDefault(e);
- }
- }
- RadMenuItem.prototype.PreventClose = function()
- {
- if (this.State == RadMenuItemState.AboutToClose)
- {
- this.ClearTimeout();
- this.State = RadMenuItemState.Open;
- this.Parent.OpenedItem = this;
- }
- if (this.Parent.PreventClose)
- {
- this.Parent.PreventClose();
- }
- }
- RadMenuItem.prototype.Open = function ()
- {
- this.PostInitializeItems();
- this.Menu.AboutToCollapse = false;
-
- if (this.Parent != this.Menu && this.Parent.State != RadMenuItemState.Open)
- {
- this.Parent.Open();
- }
-
- if (!this.AnimationContainer) return;
-
- this.Parent.OpenedItem = this;
-
- this.State = RadMenuItemState.Open;
-
- var documentSize = RadControlsNamespace.Screen.GetViewPortSize();
-
- this.ChildItemList.style.display = "block";
-
- this.Ease.ShowElements();
- if (this.GroupSettings.Flow == RadMenuNamespace.ItemFlow.Vertical)
- {
- this.Menu.FixItemWidth(this);
- }
- else
- {
- this.Menu.FixListWidth(this);
- }
-
- if (this.Menu.EnableAutoScroll && this.ChildItemList.offsetHeight > documentSize.height)
- {
- if (!this.ScrollWrap || this.ScrollWrap.offsetHeight > documentSize.height)
- {
- this.CreateRuntimeScroll(documentSize.height + "px");
- this.Ease.ShowElements();
- this.Ease.UpdateContainerSize();
- }
- }
-
- this.Ease.SetSide(this.GetEaseSide());
- this.Ease.UpdateContainerSize();
-
- if (this.Scroll)
- {
- this.CalculateScrollWrapSize();
- this.Scroll.Initialize();
- }
-
- this.PositionChildContainer(documentSize);
-
-
- this.Ease.In();
- this.UpdateCssClass();
-
- this.DomElement.style.zIndex = this.OriginalZIndex + 1000;
-
- if (!RadControlsNamespace.Browser.IsNetscape)
- {
- this.Menu.DomElement.style.zIndex = this.Menu.OriginalZIndex + 1000;
- }
-
- this.RaiseEvent("OnClientItemOpen");
- };
- RadMenuItem.prototype.MouseOverHandler = function (e)
- {
- this.PreventClose();
-
- if (this.Menu.ClickToOpen && !this.Menu.Clicked)
- {
- return;
- }
-
- if (this.State == RadMenuItemState.Open || this.State == RadMenuItemState.AboutToOpen)
- {
- return;
- }
-
- if (this.Parent.OpenedItem != this && this.Parent.OpenedItem)
- {
- var openedItem = this.Parent.OpenedItem;
- if (openedItem.TimeoutPointer)
- {
- openedItem.ClearTimeout();
- }
- openedItem.State = RadMenuItemState.AboutToClose;
- openedItem.SetTimeout(function() {
- openedItem.Close();
- openedItem.TimeoutPointer = null;
- }, this.Menu.ExpandDelay);
- }
-
- if (this.Items.length < 1)
- return;
-
- this.Menu.LastOpenedItem = this;
- this.State = RadMenuItemState.AboutToOpen;
- var instance = this;
- this.SetTimeout(function () {
- instance.Open();
- instance.TimeoutPointer = null;
- }, this.Menu.ExpandDelay);
- }
- RadMenuItem.prototype.Close = function ()
- {
- if (this.IsSeparator)
- {
- return;
- }
-
- if (this.State == RadMenuItemState.Closed)
- {
- return;
- }
-
- if (this.OpenedItem)
- {
- this.OpenedItem.Close();
- }
-
- this.Parent.OpenedItem = null;
-
- if (!this.AnimationContainer) return;
-
- this.State = RadMenuItemState.Closed;
-
- if (this.Level == 1)
- {
- this.Menu.AboutToCollapse = true;
- }
-
- this.Ease.Out();
-
- this.UpdateCssClass();
-
- this.DomElement.style.zIndex = this.OriginalZIndex;
- if (!RadControlsNamespace.Browser.IsNetscape)
- {
- if (this.Level == 1)
- {
- this.Menu.DomElement.style.zIndex = this.Menu.OriginalZIndex;
- }
- }
- this.HideChildren ();
- }
- RadMenuItem.prototype.MouseOutHandler = function (e)
- {
- var to = RadControlsNamespace.DomEvent.GetRelatedTarget(e);
-
- if ((!to) || this.Menu.IsChildOf(this.DomElement, to) || to == this.DomElement)
- {
- return;
- }
-
- if (this.ChildrenDetached)
- {
- if (this.Menu.IsChildOf(this.Parent.AnimationContainer, to))
- {
- return;
- }
- }
-
- try
- {
- //Fix FireFox "_moz_editor_bogus_node" problem.
- var bogusNode = to.parentNode;
- }catch (e)
- {
- return;
- }
-
- if (this.State == RadMenuItemState.Closed || this.State == RadMenuItemState.AboutToClose)
- {
- return;
- }
-
- if (this.State == RadMenuItemState.AboutToOpen)
- {
- this.ClearTimeout();
- this.State = RadMenuItemState.Closed;
- this.Parent.OpenedItem = null;
- return;
- }
-
- if (this.Menu.ClickToOpen)
- {
- return;
- }
-
- this.State = RadMenuItemState.AboutToClose;
- var instance = this;
- this.SetTimeout(function () {
- instance.Close();
- instance.TimeoutPointer = null;
- }, this.Menu.CollapseDelay);
- }
- RadMenuItem.prototype.SetTimeout = function (closure, delay)
- {
- this.TimeoutPointer = setTimeout(closure, delay);
- }
- RadMenuItem.prototype.ClearTimeout = function()
- {
- if (this.TimeoutPointer)
- {
- clearTimeout(this.TimeoutPointer);
- this.TimeoutPointer = null;
- }
- }
- RadMenuItem.prototype.PositionChildContainer = function (documentSize)
- {
- var top = 0;
- var left = 0;
- var expandDirection = this.GroupSettings.ExpandDirection;
- var easeProperty = RadMenuNamespace.ExpandDirectionPropertyName[expandDirection];
-
- var ownerBox = this.DomElement;
-
- var itemHeight = RadControlsNamespace.Box.GetOuterHeight(ownerBox);
- var itemWidth = RadControlsNamespace.Box.GetOuterWidth(ownerBox);
-
- var itemBox = this.AnimationContainer;
-
- //itemBox.style.border = "1px solid red";
- var childItemsHeight = RadControlsNamespace.Box.GetOuterHeight(itemBox);
- var childItemsWidth = RadControlsNamespace.Box.GetOuterWidth(itemBox);
-
-
- if (expandDirection == RadMenuNamespace.ExpandDirection.Down)
- {
- top = itemHeight;
- }
- else if (expandDirection == RadMenuNamespace.ExpandDirection.Right)
- {
- left = itemWidth;
- }
-
- this.SetContainerPosition(left, top);
- var childItemsPosition = RadControlsNamespace.Screen.GetElementPosition(itemBox);
- if (this.Menu.RightToLeft)
- {
- left = itemWidth - childItemsWidth;
- }
- if (!this.Menu.EnableScreenBoundaryDetection)
- {
- this.Ease.SetSide(easeProperty);
- this.TextElement.className = "text expand" + this.Ease.GetSide();
- return;
- }
- // Screen boundary detection
-
-
-
- if (
- RadControlsNamespace.Screen.ElementOverflowsRight(documentSize, itemBox) &&
- expandDirection == RadMenuNamespace.ExpandDirection.Right
- )
- {
- expandDirection = RadMenuNamespace.ExpandDirection.Left;
- easeProperty = "right";
- left = 0;
- }
-
- else if (childItemsPosition.x - childItemsWidth < 0 && expandDirection == RadMenuNamespace.ExpandDirection.Left)
- {
- expandDirection = RadMenuNamespace.ExpandDirection.Right;
- easeProperty = "left";
- left = itemWidth;
- }
-
- else if (childItemsPosition.y - childItemsHeight < 0 && expandDirection == RadMenuNamespace.ExpandDirection.Up)
- {
- expandDirection = RadMenuNamespace.ExpandDirection.Down;
- easeProperty = "top";
- top = itemHeight;
- }
-
- else if (
- RadControlsNamespace.Screen.ElementOverflowsBottom(documentSize, itemBox) &&
- expandDirection == RadMenuNamespace.ExpandDirection.Down
- )
- {
- //Check if there is enough space to invert the expand direction
- var itemBox = RadControlsNamespace.Screen.GetElementPosition(this.DomElement);
- if (itemBox.y > this.AnimationContainer.offsetHeight)
- {
- expandDirection = RadMenuNamespace.ExpandDirection.Up;
- easeProperty = "bottom";
- top = itemHeight;
- }
- }
-
- // Side offset
-
- if ( RadControlsNamespace.Screen.ElementOverflowsRight(documentSize, itemBox) &&
- (expandDirection == RadMenuNamespace.ExpandDirection.Down ||
- expandDirection == RadMenuNamespace.ExpandDirection.Up)
- )
- {
- if (!this.Menu.RightToLeft)
- {
- left = documentSize.width - (childItemsPosition.x + childItemsWidth);
- }
- }
- else if (RadControlsNamespace.Screen.ElementOverflowsBottom(documentSize, itemBox))
- {
- if (expandDirection == RadMenuNamespace.ExpandDirection.Left ||
- expandDirection == RadMenuNamespace.ExpandDirection.Right)
- {
- top = documentSize.height - (childItemsPosition.y + childItemsHeight);
- //alert(top);
- }
- }
-
- this.SetContainerPosition(left, top);
-
-
- this.Ease.SetSide(easeProperty);
- this.TextElement.className = "text expand" + this.Ease.GetSide();
- };
- RadMenuItem.prototype.SetContainerPosition = function(left, top)
- {
- var y = top + this.GroupSettings.OffsetY;
- if (this.Parent.ScrollWrap)
- {
- if (this.Parent == this.Menu && this.Menu.IsContext)
- {
- this.Parent.AnimationContainer = this.Menu.DomElement;
- }
-
- if (this.Parent.AnimationContainer)
- {
- this.ChildrenDetached = true;
- this.Parent.AnimationContainer.appendChild(this.AnimationContainer);
- }
-
- y += this.DomElement.offsetTop;
-
- var childListTop = parseInt(this.Parent.ChildItemList.style.top);
-
- if (isNaN(childListTop))
- {
- childListTop = 0;
- }
-
- if (this.GroupSettings.OffsetY == 0)
- {
- // Compensate for the scroll offset only if there is no group offset Y set.
- y += childListTop;
- }
- }
-
- this.AnimationContainer.style.top = y + "px";
- this.AnimationContainer.style.left = (left + this.GroupSettings.OffsetX) + "px";
- }
- RadMenuItem.prototype.SetAttribute = function (name, value)
- {
- this.PostInitialize();
- this.Attributes[name] = value;
- this.RecordState();
- }
- RadMenuItem.prototype.SetImageUrl = function (src)
- {
- this.PostInitialize();
- this.ImageUrl = src;
- this.ImageElement.src = src;
- this.RecordState();
- }
- RadMenuItem.prototype.SetImageOverUrl = function (src)
- {
- this.PostInitialize();
- this.ImageOverUrl = src;
- this.RecordState();
- }
- RadMenuItem.prototype.GetAttribute = function (name)
- {
- return this.Attributes[name];
- }
- RadMenuItem.prototype.DetermineExpandDirection = function ()
- {
- if (this.GroupSettings.ExpandDirection != RadMenuNamespace.ExpandDirection.Auto)
- {
- return;
- }
-
- if (this.Parent.Flow == RadMenuNamespace.ItemFlow.Vertical)
- {
- if (this.Menu.RightToLeft)
- {
- this.GroupSettings.ExpandDirection = RadMenuNamespace.ExpandDirection.Left;
- }
- else
- {
- this.GroupSettings.ExpandDirection = RadMenuNamespace.ExpandDirection.Right;
- }
- }
- else
- {
- this.GroupSettings.ExpandDirection = RadMenuNamespace.ExpandDirection.Down;
- }
- }
- RadMenuItem.prototype.LoadConfiguration = function ()
- {
- if (this.Menu.ItemData[this.ID])
- {
- for (var property in this.Menu.ItemData[this.ID])
- {
- this[property] = this.Menu.ItemData[this.ID][property];
- }
- }
-
- var defaultSettings = this.Menu.DefaultGroupSettings;
-
- // default settings for nested config objects
- if (typeof this.GroupSettings.Flow == 'undefined')
- {
- this.GroupSettings.Flow = defaultSettings.Flow;
- }
-
- this.Flow = this.GroupSettings.Flow;
-
-
-
- if (typeof this.GroupSettings.ExpandDirection == 'undefined')
- {
- this.GroupSettings.ExpandDirection = defaultSettings.ExpandDirection;
- }
-
- if (typeof this.GroupSettings.OffsetX == 'undefined')
- {
- this.GroupSettings.OffsetX = defaultSettings.OffsetX;
- }
-
- if (typeof this.GroupSettings.OffsetY == 'undefined')
- {
- this.GroupSettings.OffsetY = defaultSettings.OffsetY;
- }
-
- if (!this.Enabled)
- {
- this.Disable();
- }
- };
- /**
- * Keyboard handlers
- */
- RadMenuItem.prototype.HandleRightArrow = function ()
- {
- if (this.Parent.Flow == RadMenuNamespace.ItemFlow.Horizontal)
- {
- this.FocusNextItem();
- }
- else
- {
- if (this.Items.length && this.GroupSettings.ExpandDirection == RadMenuNamespace.ExpandDirection.Right)
- {
- this.FocusFirstChild();
- }
- else if (this.Parent.GroupSettings &&
- this.Parent.GroupSettings.ExpandDirection == RadMenuNamespace.ExpandDirection.Left)
- {
- this.Parent.Focus();
- }
- else
- {
- if (this.Menu.OpenedItem)
- {
- this.Menu.OpenedItem.GetNextItem().Focus();
- }
- }
- }
- }
- RadMenuItem.prototype.HandleLeftArrow = function ()
- {
- if (this.Parent.Flow == RadMenuNamespace.ItemFlow.Horizontal)
- {
- this.FocusPreviousItem();
- }
- else
- {
- if (this.Items.length && this.GroupSettings.ExpandDirection == RadMenuNamespace.ExpandDirection.Left)
- {
- this.FocusFirstChild();
- }
- else if (this.Parent.GroupSettings &&
- this.Parent.GroupSettings.ExpandDirection == RadMenuNamespace.ExpandDirection.Right)
- {
- this.Parent.Focus();
- }
- else
- {
- if (this.Menu.OpenedItem)
- {
- this.Menu.OpenedItem.GetPreviousItem().Focus();
- }
- }
- }
- }
- RadMenuItem.prototype.HandleUpArrow = function ()
- {
- if (this.Parent.Flow == RadMenuNamespace.ItemFlow.Vertical)
- {
- this.FocusPreviousItem();
- }
- else
- {
- this.FocusLastChild();
- }
- }
- RadMenuItem.prototype.HandleDownArrow = function ()
- {
- if (this.Parent.Flow == RadMenuNamespace.ItemFlow.Vertical)
- {
- this.FocusNextItem();
- }
- else
- {
- this.FocusFirstChild();
- }
- }
- RadMenuItem.prototype.GetNextItem = function ()
- {
- if (this.Index == this.Parent.Items.length - 1)
- {
- return this.Parent.Items[0];
- }
-
- return this.Parent.Items[this.Index + 1];
- }
- RadMenuItem.prototype.GetPreviousItem = function ()
- {
- if (this.Index == 0)
- {
- return this.Parent.Items[this.Parent.Items.length - 1];
- }
-
- return this.Parent.Items[this.Index - 1];
- }
- RadMenuItem.prototype.CanFocus = function ()
- {
- return (!this.IsSeparator) && this.Enabled;
- }
- RadMenuItem.prototype.FocusFirstChild = function ()
- {
- if (!this.Items.length)
- {
- return;
- }
-
- var item = this.Items[0];
-
- while (!item.CanFocus())
- {
-
- item = item.GetNextItem();
- if (item == this.Items[0])
- {
- return; // no items to focus
- }
- }
-
- item.Focus();
- }
- RadMenuItem.prototype.FocusLastChild = function ()
- {
- if (!this.Items.length)
- {
- return;
- }
-
- var item = this.Items[this.Items.length - 1];
-
- while (!item.CanFocus())
- {
- item = item.GetPreviousItem();
- if (this.Items.length - 1)
- {
- return; // no items to focus
- }
- }
- item.Focus();
- }
- RadMenuItem.prototype.FocusNextItem = function ()
- {
- var item = this.GetNextItem();
-
- while (!item.CanFocus())
- {
- item = item.GetNextItem();
- }
- item.Focus();
- }
- RadMenuItem.prototype.FocusPreviousItem = function ()
- {
- var item = this.GetPreviousItem();
-
- while (!item.CanFocus())
- {
- item = item.GetPreviousItem();
- }
- item.Focus();
- }
- RadMenuItem.prototype.RecordState = function (forceSerialize)
- {
- if (this.ClientSide && !forceSerialize)
- {
- return;
- }
- var serialized = RadControlsNamespace.JSON.stringify(this, this.InitialState, RadMenu.JSONIncludeDeep);
- if (serialized == "{}")
- {
- this.Menu.ItemState[this.ID] = "";
- }
- else
- {
- this.Menu.ItemState[this.ID] = "\"" + this.ID + "\":" + serialized;
- }
-
- this.Menu.RecordState();
- }
- RadMenuItem.prototype.AddItem = function()
- {
- this.Menu.AddItem.apply(this, arguments);
- this.Menu.FixItemWidth(this);
- }
- //BEGIN_ATLAS_NOTIFY
- if (typeof(Sys) != "undefined")
- {
- if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
- {
- Sys.Application.notifyScriptLoaded();
- }
- }
- //END_ATLAS_NOTIFY
|