InnerHtml() public method

public InnerHtml ( ) : HtmlTag
return HtmlTag
        protected virtual HtmlTag GetLinkElement()
        {
            var a = new HtmlTag("a")
                    .Id(Id)
                    .Class("bg-" + Style.ToString().ToLower())
                    .Class(CssClass)
                    .Attrs(HtmlProps);

            if (Text != null)
            {
                a.SetInnerText(Text);
            }

            if (Html != null)
            {
                a.InnerHtml(Html);
            }

            if (Title.HasText())
            {
                a.Attr("title", Title);
            }

            if (Href != null)
            {
                a.Attr("href", Href);
            }

            if (!Enabled)
            {
                a.Attr("disabled", "disabled");
            }
            return(a);
        }
        public virtual MvcHtmlString ToHtml(HtmlHelper helper)
        {
            var a = new HtmlTag("a")
                    .Id(Id)
                    .Class("btn")
                    .Class("btn-" + Style.ToString().ToLower())
                    .Class("sf-entity-button")
                    .Class(CssClass)
                    .Attrs(HtmlProps);

            if (Text != null)
            {
                a.SetInnerText(Text);
            }

            if (Html != null)
            {
                a.InnerHtml(Html);
            }

            if (Title.HasText())
            {
                a.Attr("title", Title);
            }

            if (Href != null)
            {
                a.Attr("href", Href);
            }

            if (!Enabled)
            {
                a.Attr("disabled", "disabled");
            }

            var result = new HtmlTag("div").Class("btn-group").InnerHtml(a);

            if (Tooltip.HasText())
            {
                result.Attr("data-toggle", "tooltip");
                result.Attr("data-placement", "bottom");
                result.Attr("title", Tooltip);
            }

            var html = result.ToHtml();

            if (OnClick == null)
            {
                return(html);
            }

            TypeContext.AssertId(this.Id);

            var script = MvcHtmlString.Create("<script>$('#" + Id + "').on('mouseup', function(event){ if(event.which == 3) return; " + OnClick.ToString() + " })</script>");

            return(html.Concat(script));
        }
Esempio n. 3
0
        public virtual MvcHtmlString ToHtml(HtmlHelper helper)
        {
            var a = new HtmlTag("a")
                .Id(Id)
                .Class("btn")
                .Class("btn-" + Style.ToString().ToLower())
                .Class("sf-entity-button")
                .Class(CssClass)
                .Attrs(HtmlProps);

            if (Text != null)
                a.SetInnerText(Text);

            if (Html != null)
                a.InnerHtml(Html);

            if (Title.HasText())
                a.Attr("title", Title);

            if (Href != null)
                a.Attr("href", Href);

            if (!Enabled)
                a.Attr("disabled", "disabled");

            var result = new HtmlTag("div").Class("btn-group").InnerHtml(a);

            if (Tooltip.HasText())
            {
                result.Attr("data-toggle", "tooltip");
                result.Attr("data-placement", "bottom");
                result.Attr("title", Tooltip);
            }

            var html = result.ToHtml();

            if (OnClick == null)
                return html;

            TypeContext.AssertId(this.Id);

            var script = MvcHtmlString.Create("<script>$('#" + Id + "').on('mouseup', function(event){ if(event.which == 3) return; " + OnClick.ToString() + " })</script>");

            return html.Concat(script);
        }
Esempio n. 4
0
        public virtual MvcHtmlString ToHtml(HtmlHelper helper)
        {
            var a = new HtmlTag("a")
                .Id(Id)
                .Class("btn")
                .Class("btn-" + Style.ToString().ToLower())
                .Class("sf-entity-button")
                .Class(CssClass)
                .Attrs(HtmlProps);

            if (Text != null)
                a.SetInnerText(Text);

            if (Html != null)
                a.InnerHtml(Html);

            if (Title.HasText())
                a.Attr("title", Title);

            if (Enabled)
            {
                if (OnClick != null)
                    a.Attr("onclick", OnClick.ToString());

                a.Attr("href", Href.DefaultText("#"));
            }
            else
                a.Attr("disabled", "disabled");

            var result = new HtmlTag("div").Class("btn-group").InnerHtml(a);

            if (Tooltip.HasText())
            {
                result.Attr("data-toggle", "tooltip");
                result.Attr("data-placement", "bottom");
                result.Attr("title", Tooltip);
            }

            return result;
        }
Esempio n. 5
0
        //http://stackoverflow.com/questions/979095/asp-net-mvc-dropdownlist-pre-selected-item-ignored
        public static MvcHtmlString SafeDropDownList(this HtmlHelper html, string idAndName, IEnumerable <SelectListItem> elements, IDictionary <string, object> htmlAttributes = null)
        {
            var select = new HtmlTag("select").IdName(idAndName).Attrs(htmlAttributes);

            HtmlStringBuilder sb = new HtmlStringBuilder();

            foreach (var se in elements)
            {
                var option = new HtmlTag("option").Attr("value", se.Value).SetInnerText(se.Text);

                if (se.Selected)
                {
                    option.Attr("selected", "selected");
                }

                sb.Add(option.ToHtml());
            }

            select.InnerHtml(sb.ToHtml());

            return(select.ToHtml());
        }
Esempio n. 6
0
        }                                 //is applied to link


        public void Write(HtmlStringBuilder sb, string currentUrl, int depth)
        {
            if (!this.Visible)
            {
                throw new InvalidOperationException("Invisible menu");
            }

            bool isActive = this.Link != null && this.Link.ToString() == currentUrl ||
                            children.HasItems() && children.Any(a => a.Link != null && a.Link.ToString() == currentUrl);

            bool isHeader = IsHeader(depth);

            using (sb.SurroundLine(new HtmlTag("li").Class(isActive ? "active" : null).Class(isHeader ? "dropdown-header" : this.children.HasItems() ? "dropdown" : null)))
            {
                if (Link != null)
                {
                    string link = Link.ToString();

                    if (ManualA != null)
                    {
                        sb.AddLine(ManualA(link, title, " ".CombineIfNotEmpty(Class, "selected")));
                    }
                    else
                    {
                        HtmlTag tbA = new HtmlTag("a")
                                      .Attrs(new { href = link, title = Title, id = Id })
                                      .Class(Class);

                        if (Html != null)
                        {
                            tbA.InnerHtml(Html);
                        }
                        else
                        {
                            tbA.SetInnerText(Text);
                        }

                        sb.AddLine(tbA.ToHtml());
                    }
                }
                else if (this.children.HasItems() && !isHeader)
                {
                    using (sb.SurroundLine(new HtmlTag("a").Attr("href", "#")
                                           .Class("dropdown-toggle")
                                           .Class(Class)
                                           .Attr("data-toggle", "dropdown")))
                    {
                        if (Html != null)
                        {
                            sb.Add(Html);
                        }
                        else
                        {
                            sb.Add(new HtmlTag("span").SetInnerText(Text));
                        }

                        sb.Add(new HtmlTag("b").Class("caret"));
                    }
                }
                else if (Html != null)
                {
                    sb.AddLine(Html);
                }
                else
                {
                    sb.AddLine(new HtmlTag("span").SetInnerText(Text));
                }

                if (this.children.HasItems() && !isHeader)
                {
                    using (sb.SurroundLine(new HtmlTag("ul").Class("dropdown-menu")))
                    {
                        bool lastHeader = false;
                        foreach (WebMenuItem menu in this.children)
                        {
                            if (menu.Visible)
                            {
                                if (lastHeader)
                                {
                                    sb.AddLine(new HtmlTag("li").Class("divider"));
                                }

                                menu.Write(sb, currentUrl, depth + 1);

                                lastHeader = menu.IsHeader(depth + 1);
                            }
                        }
                    }
                }
            }

            if (isHeader)
            {
                foreach (WebMenuItem menu in this.children)
                {
                    if (menu.Visible)
                    {
                        menu.Write(sb, currentUrl, depth + 1);
                    }
                }
            }
        }
Esempio n. 7
0
        protected virtual HtmlTag GetLinkElement()
        {
            var a = new HtmlTag("a")
               .Id(Id)
               .Class("bg-" + Style.ToString().ToLower())
               .Class(CssClass)
               .Attrs(HtmlProps);

            if (Text != null)
                a.SetInnerText(Text);

            if (Html != null)
                a.InnerHtml(Html);

            if (Title.HasText())
                a.Attr("title", Title);

            if (Href != null)
                a.Attr("href", Href);

            if (!Enabled)
                a.Attr("disabled", "disabled");
            return a;
        }
Esempio n. 8
0
        public string Class { get; set; } //is applied to link

     
        public void Write(HtmlStringBuilder sb, string currentUrl, int depth)
        {
            if (!this.Visible)
                throw new InvalidOperationException("Invisible menu");

            bool isActive = this.Link != null && this.Link.ToString() == currentUrl ||
                children.HasItems() && children.Any(a => a.Link != null && a.Link.ToString() == currentUrl);

            bool isHeader = IsHeader(depth);

            using (sb.SurroundLine(new HtmlTag("li").Class(isActive ? "active" : null).Class(isHeader ? "dropdown-header" : this.children.HasItems() ? "dropdown" : null)))
            {
                if (Link != null)
                {
                    string link = Link.ToString();

                    if (ManualA != null)
                        sb.AddLine(ManualA(link, title, " ".CombineIfNotEmpty(Class, "selected")));
                    else
                    {
                        HtmlTag tbA = new HtmlTag("a")
                                .Attrs(new { href = link, title = Title, id = Id })
                                .Class(Class);

                        if (Html != null)
                            tbA.InnerHtml(Html);
                        else
                            tbA.SetInnerText(Text);

                        sb.AddLine(tbA.ToHtml());
                    }
                }
                else if (this.children.HasItems() && !isHeader)
                {
                    using (sb.SurroundLine(new HtmlTag("a").Attr("href", "#")
                        .Class("dropdown-toggle")
                        .Class(Class)
                        .Attr("data-toggle", "dropdown")))
                    {
                        if (Html != null)
                            sb.Add(Html);
                        else 
                            sb.Add(new HtmlTag("span").SetInnerText(Text));

                        sb.Add(new HtmlTag("b").Class("caret"));
                    }
                }
                else if (Html != null)
                    sb.AddLine(Html);
                else
                    sb.AddLine(new HtmlTag("span").SetInnerText(Text));

                if (this.children.HasItems() && !isHeader)
                {
                    using (sb.SurroundLine(new HtmlTag("ul").Class("dropdown-menu")))
                    {
                        bool lastHeader = false;
                        foreach (WebMenuItem menu in this.children)
                        {
                            if (menu.Visible)
                            {
                                if(lastHeader)
                                    sb.AddLine(new HtmlTag("li").Class("divider")); 

                                menu.Write(sb, currentUrl, depth + 1);

                                lastHeader = menu.IsHeader(depth + 1);
                            }
                        }
                    }
                }
            }

            if (isHeader)
            {
                foreach (WebMenuItem menu in this.children)
                {
                    if (menu.Visible)
                        menu.Write(sb, currentUrl, depth + 1);
                }

               
            }
        }