protected virtual string RenderItemLink(HtmlTextWriter writer, Tab item, int index)
        {
            string temp          = "";
            string loadedTabName = null;

            // <li [class="active [hide]"]><a href="#{id}" data-toggle="tab">{text}</a></li>
            item.HtmlAttributes.AppendCssClass("nav-item"); // .active for BS2

            if (!item.Selected && !item.Visible)
            {
                item.HtmlAttributes.AppendCssClass("d-none");
            }

            if (item.Pull == TabPull.Right)
            {
                item.HtmlAttributes.AppendCssClass("float-right");
            }

            writer.AddAttributes(item.HtmlAttributes);

            writer.RenderBeginTag("li");
            {
                var itemId = "#" + BuildItemId(item, index);

                writer.AddAttribute("class", "nav-link" + (item.Selected ? " active" : ""));

                if (item.Content != null)
                {
                    writer.AddAttribute("href", itemId);
                    writer.AddAttribute("data-toggle", "tab");
                    writer.AddAttribute("data-loaded", "true");
                    loadedTabName = GetTabName(item) ?? itemId;
                }
                else
                {
                    // no content, create real link instead
                    var url = item.GenerateUrl(base.ViewContext.RequestContext).NullEmpty();

                    if (url == null)
                    {
                        writer.AddAttribute("href", "#");
                    }
                    else
                    {
                        if (item.Ajax)
                        {
                            writer.AddAttribute("href", itemId);
                            writer.AddAttribute("data-ajax-url", url);
                            writer.AddAttribute("data-toggle", "tab");
                        }
                        else
                        {
                            writer.AddAttribute("href", url);
                        }
                    }
                }

                if (item.BadgeText.HasValue())
                {
                    item.LinkHtmlAttributes.AppendCssClass("clearfix");
                }

                writer.AddAttributes(item.LinkHtmlAttributes);
                writer.RenderBeginTag("a");
                {
                    // Tab Icon
                    if (item.Icon.HasValue())
                    {
                        writer.AddAttribute("class", item.Icon);
                        writer.RenderBeginTag("i");
                        writer.RenderEndTag();                         // i
                    }
                    else if (item.ImageUrl.HasValue())
                    {
                        var url = new UrlHelper(this.ViewContext.RequestContext);
                        writer.AddAttribute("src", url.Content(item.ImageUrl));
                        writer.AddAttribute("alt", "Icon");
                        writer.RenderBeginTag("img");
                        writer.RenderEndTag();                         // img
                    }

                    // Caption
                    writer.AddAttribute("class", "tab-caption");
                    writer.RenderBeginTag("span");
                    writer.WriteEncodedText(item.Text);
                    writer.RenderEndTag();

                    // Badge
                    if (item.BadgeText.HasValue())
                    {
                        // Label/badge
                        temp  = "ml-2 badge";
                        temp += " badge-" + item.BadgeStyle.ToString().ToLower();
                        if (base.Component.Position == TabsPosition.Left)
                        {
                            temp += " float-right";                             // looks nicer
                        }
                        writer.AddAttribute("class", temp);
                        writer.RenderBeginTag("span");
                        writer.WriteEncodedText(item.BadgeText);
                        writer.RenderEndTag();                         // span > badge
                    }

                    // Nav link short summary for collapsed state
                    if (this.Component.IsResponsive && item.Summary.HasValue())
                    {
                        writer.AddAttribute("class", "nav-link-summary");
                        writer.RenderBeginTag("span");
                        writer.WriteEncodedText(item.Summary);
                        writer.RenderEndTag();
                    }

                    writer.RenderEndTag();             // a
                }
                writer.RenderEndTag();                 // li
            }

            return(loadedTabName);
        }
Example #2
0
        protected virtual string RenderItemLink(HtmlTextWriter writer, Tab item, int index)
        {
            string temp          = "";
            string loadedTabName = null;

            // <li [class="active [hide]"]><a href="#{id}" data-toggle="tab">{text}</a></li>
            if (item.Selected)
            {
                item.HtmlAttributes.AppendCssClass("active");
            }
            else
            {
                if (!item.Visible)
                {
                    item.HtmlAttributes.AppendCssClass("hide");
                }
            }

            if (item.Pull == TabPull.Right)
            {
                item.HtmlAttributes.AppendCssClass("pull-right");
            }

            writer.AddAttributes(item.HtmlAttributes);

            writer.RenderBeginTag("li");
            {
                var itemId = "#" + BuildItemId(item, index);

                if (item.Content != null)
                {
                    writer.AddAttribute("href", itemId);
                    writer.AddAttribute("data-toggle", "tab");
                    writer.AddAttribute("data-loaded", "true");
                    loadedTabName = GetTabName(item) ?? itemId;
                }
                else
                {
                    // no content, create real link instead
                    var url = item.GenerateUrl(base.ViewContext.RequestContext).NullEmpty();

                    if (url == null)
                    {
                        writer.AddAttribute("href", "#");
                    }
                    else
                    {
                        if (item.Ajax)
                        {
                            writer.AddAttribute("href", itemId);
                            writer.AddAttribute("data-ajax-url", url);
                            writer.AddAttribute("data-toggle", "tab");
                        }
                        else
                        {
                            writer.AddAttribute("href", url);
                        }
                    }
                }

                if (item.BadgeText.HasValue())
                {
                    item.LinkHtmlAttributes.AppendCssClass("clearfix");
                }

                writer.AddAttributes(item.LinkHtmlAttributes);
                writer.RenderBeginTag("a");
                {
                    // Tab Icon
                    if (item.Icon.HasValue())
                    {
                        writer.AddAttribute("class", item.Icon);
                        writer.RenderBeginTag("i");
                        writer.RenderEndTag();                         // i
                    }
                    else if (item.ImageUrl.HasValue())
                    {
                        var url = new UrlHelper(this.ViewContext.RequestContext);
                        writer.AddAttribute("src", url.Content(item.ImageUrl));
                        writer.AddAttribute("alt", "Icon");
                        writer.RenderBeginTag("img");
                        writer.RenderEndTag();                         // img
                    }
                    //writer.WriteEncodedText(item.Text);

                    // Badge
                    if (item.BadgeText.HasValue())
                    {
                        //writer.Write("&nbsp;");

                        // caption
                        writer.AddAttribute("class", "tab-caption");
                        writer.RenderBeginTag("span");
                        writer.WriteEncodedText(item.Text);
                        writer.RenderEndTag();                         // span > badge

                        // label
                        temp = "label";
                        if (item.BadgeStyle != BadgeStyle.Default)
                        {
                            temp += " label-" + item.BadgeStyle.ToString().ToLower();
                        }
                        if (base.Component.Position == TabsPosition.Left)
                        {
                            temp += " pull-right";                             // looks nicer
                        }
                        writer.AddAttribute("class", temp);
                        writer.RenderBeginTag("span");
                        writer.WriteEncodedText(item.BadgeText);
                        writer.RenderEndTag();                         // span > badge
                    }
                    else
                    {
                        writer.WriteEncodedText(item.Text);
                    }
                    writer.RenderEndTag();             // a
                }
                writer.RenderEndTag();                 // li
            }

            return(loadedTabName);
        }