Ejemplo n.º 1
0
 public static WebAnchor GetNavigationAnchor(WebNavigationItemArgs args)
 {
     if (args == null)
     {
         throw new ArgumentNullException("args");
     }
     return(ControlFinder.Instance.FindFirstControlOnType(args.NavigationItem, typeof(WebAnchor)) as WebAnchor);
 }
Ejemplo n.º 2
0
        protected virtual void OnItemDataBound(RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                // Cast dataitem
                var pageData = ((INavigationPage)e.Item.DataItem);
                var navItems = ((NavigationPageCollection)rptNavigation.DataSource);

                // check if selected
                var isSelected           = IsPageSelected(this.RootPage, pageData, this.SelectedNavigationPage);
                var isInSelectedPath     = IsPageInSelectedPath(this.RootPage, pageData, this.SelectedNavigationPage);
                var isChildOfRemovedNode = this.IncludeChildrenOfRemovedNodesMode > IncludeChildrenOfRemovedNodesMode.Never &&
                                           (this.IncludeChildrenOfRemovedNodesMode.Equals(IncludeChildrenOfRemovedNodesMode.Always) || isInSelectedPath) &&
                                           this.IsPageChildOfRemovedNode(this.RootPage, pageData);
                var liListItem = this.GetNavigationItemDelegate(e);

                if ((isSelected && this.hideSelectedPage) || (!isInSelectedPath && this.ShowOnlyPagesInPath))
                {
                    liListItem.Visible = false;
                }
                else
                {
                    var expandingLevel = this.NumberOfLevels != 0 && (!pageData.Id.Equals(this.RootPage.Id) || this.IncludeRootLevelInList) && (this.ExpandAll || isInSelectedPath);

                    if (expandingLevel)
                    {
                        var subNavigationPlaceHolder = new PlaceHolder();
                        liListItem.Controls.Add(subNavigationPlaceHolder);
                        var args = new WebNavigationItemArgs(liListItem,
                                                             this,
                                                             pageData,
                                                             isSelected,
                                                             isInSelectedPath,
                                                             e.Item.ItemIndex,
                                                             e.Item.ItemIndex == 0,
                                                             e.Item.ItemIndex == (navItems.Count - 1),
                                                             expandingLevel,
                                                             isChildOfRemovedNode,
                                                             null);
                        var subNavigation = this.CreateWebNavigationControlDelegate(args);
                        subNavigationPlaceHolder.Controls.Add(subNavigation);
                        args.SubNavigation = subNavigation;
                        this.PopulateSubNavigation(subNavigation, pageData);

                        this.PopulateNavigationItemDelegate(args);

                        subNavigation.DataBind();
                        this.visibleLevels      += subNavigation.VisibleLevels;
                        this.visibleDescendants += subNavigation.VisibleDescendants;
                        this.selectedNavigationPath.AddRange(subNavigation.selectedNavigationPath);
                    }
                    else
                    {
                        this.PopulateNavigationItemDelegate(new WebNavigationItemArgs(liListItem, this, pageData, isSelected, isInSelectedPath, e.Item.ItemIndex, e.Item.ItemIndex == 0, e.Item.ItemIndex == (navItems.Count - 1), expandingLevel, isChildOfRemovedNode, null));
                    }
                    this.visibleChildren++;
                    this.visibleDescendants++;
                    if (isInSelectedPath)
                    {
                        this.selectedNavigationPath.Insert(0, pageData);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static void PopulateNavigationItem(WebNavigationItemArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            var liClass = string.Empty;
            var aClass  = string.Empty;

            if (args.IsSelected || args.IsInSelectedPath)
            {
                aClass = liClass = args.IsSelected ? "selected" : "selected-path";
            }

            if (args.IsFirstItem)
            {
                liClass = liClass + (liClass.Length > 0 ? " " : string.Empty) + "first-item";
            }
            if (args.IsLastItem)
            {
                liClass = liClass + (liClass.Length > 0 ? " " : string.Empty) + "last-item";
            }
            if (args.IsChildOfRemovedNode)
            {
                liClass = liClass + (liClass.Length > 0 ? " " : string.Empty) + "child-of-removed-node";
            }

            if (args.ParentNavigation.IndicateIfNodeHasChildren)
            {
                var children        = args.ParentNavigation.GetChildren(args.NavigationPage);
                var removedChildren = args.ParentNavigation.IncludeChildrenOfRemovedNodesMode > IncludeChildrenOfRemovedNodesMode.Never ?
                                      new NavigationPageCollection() : null;
                children = args.ParentNavigation.FilterNavigation(children, removedChildren);

                if (args.ParentNavigation.IncludeChildrenOfRemovedNodesMode > IncludeChildrenOfRemovedNodesMode.Never)
                {
                    var nonRemovedDescendants = args.ParentNavigation.GetNonRemovedDescendants(removedChildren);
                    if (args.ParentNavigation.IncludeChildrenOfRemovedNodesMode.Equals(IncludeChildrenOfRemovedNodesMode.OnlyInSelectedPath))
                    {
                        foreach (var descendant in nonRemovedDescendants)
                        {
                            if (args.ParentNavigation.IsPageInSelectedPath(args.ParentNavigation.RootPage, descendant, args.ParentNavigation.SelectedNavigationPage))
                            {
                                children.Add(descendant);
                            }
                        }
                    }
                    else
                    {
                        children.AddRange(nonRemovedDescendants);
                    }
                }
                if (children.Count > 0)
                {
                    liClass = liClass + (liClass.Length > 0 ? " " : string.Empty) + "has-children";
                    aClass  = aClass + (aClass.Length > 0 ? " " : string.Empty) + "has-children";
                }
            }

            var li = args.NavigationItem as WebGenericControl;

            if (liClass.Trim().Length > 0 && li != null)
            {
                li.CssClass = liClass;
            }

            // Find UI Control
            var ancNavigationItem = args.ParentNavigation.GetNavigationAnchorDelegate(args);

            if (ancNavigationItem == null)
            {
                throw new HttpException("The default implementation of PopulateNavigationItem requires at least one WebAnchor inside the ItemTemplate.");
            }
            ancNavigationItem.Visible   = true;
            ancNavigationItem.CssClass += " " + aClass;
            if (string.IsNullOrEmpty(ancNavigationItem.Text))
            {
                ancNavigationItem.Text = args.ParentNavigation.GetNavigationItemNameDelegate(args);
            }
            if (!args.IsSelected || (args.IsSelected && args.ParentNavigation.SelectedPageClickable) || args.ParentNavigation.RootLevelNotClickable)
            {
                if (string.IsNullOrEmpty(ancNavigationItem.NavigateUrl))
                {
                    if (args.ExpandingLevel && args.ParentNavigation.RootLevelNotClickable && args.SubNavigation != null)
                    {
                        args.NavigationItem.ID = HttpUtility.UrlEncode(args.SubNavigation.ClientID.Replace("_", string.Empty) + "Li");
                        if (li != null)
                        {
                            li.RenderId = true;
                        }
                        ancNavigationItem.NavigateUrl = "#" + args.NavigationItem.ID;
                        ancNavigationItem.Attributes.Add("onmousedown", "this.href=this.href+':stop';return true;");
                        ancNavigationItem.Attributes.Add("onclick", "if(this.href.substring(this.href.length - 5,this.href.length)==':stop'){this.href=this.href.substring(0,this.href.length-5);return false;}else{return true;}");
                    }
                    else
                    {
                        ancNavigationItem.NavigateUrl = args.ParentNavigation.GetNavigationItemLinkDelegate(args);
                    }
                }
                if (args.ParentNavigation.AlwaysPlaceSpanAroundNavItem)
                {
                    var gnrNavigationItem = new WebGenericControl("span");
                    args.NavigationItem.Controls.AddAt(0, gnrNavigationItem);
                    gnrNavigationItem.Controls.Add(ancNavigationItem);
                }
                else
                {
                    args.NavigationItem.Controls.AddAt(0, ancNavigationItem);
                }
            }
            else
            {
                ancNavigationItem.InnerSpan = true;
                ancNavigationItem.NoLink    = true;
                args.NavigationItem.Controls.AddAt(0, ancNavigationItem);
            }
        }
Ejemplo n.º 4
0
 public abstract WebNavigation CreateWebNavigationControl(WebNavigationItemArgs args);