Esempio n. 1
0
        public static MvcHtmlString ImageButton(this HtmlHelper html, string imageUrl, string text,
                                                string onClickAction        = null,
                                                bool showTextAfterImage     = false,
                                                string additionalClasses    = "",
                                                string defaultButtonClasses = "t-emsg-image-button k-button k-button-icon",
                                                string defaultImageClasses  = "k-icon-image"
                                                )
        {
            var builder = new FluentTagBuilder("a");

            builder.AddCssClass(defaultButtonClasses);

            foreach (var addClass in (additionalClasses ?? string.Empty).Split(new [] { " " }, StringSplitOptions.RemoveEmptyEntries))
            {
                builder.AddCssClass(addClass);
            }
            builder.AddAttribute("title", text);
            builder.AddAttribute("tabindex", "0");
            if (!string.IsNullOrEmpty(onClickAction))
            {
                builder.AddAttribute("onclick", onClickAction);
            }
            builder.AddToInnerHtml(new FluentTagBuilder("img")
                                   .AddAttribute("alt", text)
                                   .AddAttribute("src", imageUrl)
                                   .AddCssClass(defaultImageClasses)
                                   .ToString(TagRenderMode.SelfClosing));

            if (showTextAfterImage)
            {
                builder.AddToInnerHtml(new FluentTagBuilder("span").AddCssClass("imageButtonText").AddToInnerHtml(text));
            }

            return(new MvcHtmlString(builder.ToString()));
        }
Esempio n. 2
0
        public static MvcHtmlString UnobtrusiveImageButton(this HtmlHelper html, string imageUrl, string text, bool showTextAfterImage = false, string additionalClasses = "", Action <FluentTagBuilder> customizeButtonAnchor = null)
        {
            var anchorBuilder = new FluentTagBuilder("a");

            anchorBuilder.AddCssClass("t-emsg-image-button k-button k-button-icon");

            foreach (var addClass in (additionalClasses ?? string.Empty).Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries))
            {
                anchorBuilder.AddCssClass(addClass);
            }

            anchorBuilder.AddAttribute("title", text);
            anchorBuilder.AddAttribute("tabindex", "0");

            anchorBuilder.AddToInnerHtml(new FluentTagBuilder("img")
                                         .AddAttribute("alt", text)
                                         .AddAttribute("src", imageUrl)
                                         .AddCssClass("k-icon-image")
                                         .ToString(TagRenderMode.SelfClosing));

            if (showTextAfterImage)
            {
                anchorBuilder.AddToInnerHtml(new FluentTagBuilder("span").AddCssClass("imageButtonText").AddToInnerHtml(text));
            }

            if (customizeButtonAnchor != null)
            {
                customizeButtonAnchor(anchorBuilder);
            }

            return(new MvcHtmlString(anchorBuilder.ToString()));
        }
Esempio n. 3
0
        public static MvcHtmlString ActionLinkButton(this HtmlHelper helper, string text, [AspMvcAction] string action)
        {
            var builder = new FluentTagBuilder("a");

            builder.AddCssClass("t-emsg-button k-button");
            builder.AddToInnerHtml(new FluentTagBuilder("span").AddToInnerHtml(text));
            builder.AddAttribute("href", helper.ToUrlHelper().Action(action));

            return(new MvcHtmlString(builder.ToString()));
        }
Esempio n. 4
0
        public static MvcHtmlString Button(this HtmlHelper helper, string text, string onClickFunction = null, string additionalCssClasses = null)
        {
            var builder = new FluentTagBuilder("a");

            builder.AddCssClass("t-emsg-button k-button");
            builder.AddAttribute("type", "button");
            builder.AddAttribute("title", text);

            foreach (var addClass in (additionalCssClasses ?? string.Empty).Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries))
            {
                builder.AddCssClass(addClass);
            }

            builder.AddToInnerHtml(new FluentTagBuilder("span").AddToInnerHtml(text));

            if (!string.IsNullOrEmpty(onClickFunction))
            {
                builder.AddAttribute("onclick", onClickFunction);
            }

            return(new MvcHtmlString(builder.ToString()));
        }