Esempio n. 1
0
        /// <summary>
        ///   Create a icon only link
        /// </summary>
        /// <param name="html">Current HTML helper object</param>
        /// <param name="icon">Icon to display</param>
        /// <param name="result">Link action</param>
        /// <param name="htmlAttributes">[Optional] Extra HTML attributes</param>
        /// <returns>A icon only link</returns>
        public static IExtendedHtmlString Hyperlink(this HtmlHelper html, EBootstrapIcon icon, ActionResult result,
                                                    object htmlAttributes = null)
        {
            string link = WebExtrasMvcUtilT4.GetUrl(html, result);

            return(new BootstrapIconlink(icon, link, htmlAttributes));
        }
        /// <summary>
        ///   Add an icon
        /// </summary>
        /// <typeparam name="T">Generic type to be used. This type must implement IExtendedHtmlString</typeparam>
        /// <param name="html">Current html element</param>
        /// <param name="icon">Icon to be rendered</param>
        /// <param name="htmlAttributes">[Optional] Extra html attributes</param>
        /// <returns>Html element with icon added</returns>
        /// <exception cref="BootstrapVersionException">
        ///   Thrown when a valid Bootstrap version
        ///   is not selected
        /// </exception>
        public static T AddIcon <T>(this T html, EBootstrapIcon icon, object htmlAttributes = null)
            where T : IExtendedHtmlString
        {
            html = AddIcon(html, new[] { icon.GetStringValue() }, htmlAttributes);

            return(html);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a Bootstrap icon
        /// </summary>
        /// <param name="icon">Icon to be created</param>
        /// <param name="htmlAttributes">[Optional] Any extra HTML attributes</param>
        /// <returns>A Bootstrap icon</returns>
        public static IHtmlComponent CreateIcon(EBootstrapIcon icon, object htmlAttributes = null)
        {
            NameValueCollection htmlAttribs = WebExtrasUtil.AnonymousObjectToHtmlAttributes(htmlAttributes);

            List <string> cssClasses = new List <string>();

            if (htmlAttribs.ContainsKey("class"))
            {
                cssClasses.AddRange(htmlAttribs["class"].Split(' '));
                htmlAttribs.Remove("class");
            }

            switch (WebExtrasSettings.BootstrapVersion)
            {
            case EBootstrapVersion.V2:
                cssClasses.Add("icon-" + icon.ToString().ToLowerInvariant().Replace("_", "-"));
                break;

            case EBootstrapVersion.V3:
                cssClasses.Add("glyphicon glyphicon-" + icon.ToString().ToLowerInvariant().Replace("_", "-"));
                break;

            default:
                throw new BootstrapVersionException();
            }

            HtmlComponent i = new HtmlComponent(EHtmlTag.I);

            i.CssClasses.AddRange(cssClasses);
            return(i);
        }
Esempio n. 4
0
        /// <summary>
        ///   Constructor
        /// </summary>
        /// <param name="icon">Icon to be displayed as the hypelink</param>
        /// <param name="url">Link URL</param>
        /// <param name="htmlAttributes">[Optional Extra HTML attributes</param>
        public BootstrapIconlink(EBootstrapIcon icon, string url, object htmlAttributes = null) :
            base(string.Empty, url, htmlAttributes)
        {
            CssClasses.Add("icon-only-link");
            IHtmlComponent iconElement = BootstrapUtil.CreateIcon(icon);

            PrependTags.Add(iconElement);
        }
        /// <summary>
        ///   Add a white icon
        /// </summary>
        /// <typeparam name="T">Generic type to be used. This type must implement IExtendedHtmlString</typeparam>
        /// <param name="html">Current html element</param>
        /// <param name="icon">Icon to be rendered</param>
        /// <param name="htmlAttributes">[Optional] Extra html attributes</param>
        /// <returns>Html element with a white icon added</returns>
        /// <exception cref="BootstrapVersionException">
        ///   Thrown when a valid Bootstrap version
        ///   is not selected
        /// </exception>
        public static T AddWhiteIcon <T>(this T html, EBootstrapIcon icon, object htmlAttributes = null)
            where T : IExtendedHtmlString
        {
            switch (WebExtrasSettings.BootstrapVersion)
            {
            case EBootstrapVersion.V2:
                break;

            case EBootstrapVersion.V3:
                throw new InvalidOperationException(
                          "Since Bootstrap v3, all icons are font based. Therefore, you must use CSS styling to control icon color");

            default:
                throw new BootstrapVersionException();
            }

            html = AddIcon(html, new[] { "icon-white " + icon.GetStringValue() }, htmlAttributes);

            return(html);
        }
 /// <summary>
 ///   Renders a Bootstrap icon
 /// </summary>
 /// <param name="html">Current Html helper object</param>
 /// <param name="icon">Icon to be rendered</param>
 /// <param name="htmlAttributes">[Optional] Extra HTML attributes</param>
 /// <returns>A Bootstrap icon</returns>
 /// <exception cref="BootstrapVersionException">
 ///   Thrown when a valid Bootstrap version
 ///   is not selected
 /// </exception>
 public static IExtendedHtmlStringLegacy Icon(this HtmlHelper html, EBootstrapIcon icon, object htmlAttributes = null)
 {
     return(BootstrapUtil.CreateIcon(icon, htmlAttributes).ToHtmlElement());
 }
 /// <summary>
 ///   Create a icon only link
 /// </summary>
 /// <param name="html">Current HTML helper object</param>
 /// <param name="icon">Icon to display</param>
 /// <param name="url">Link action</param>
 /// <param name="htmlAttributes">[Optional] Extra HTML attributes</param>
 /// <returns>A icon only link</returns>
 public static IExtendedHtmlString Hyperlink(this HtmlHelper html, EBootstrapIcon icon, string url,
                                             object htmlAttributes = null)
 {
     return(new BootstrapIconlink(icon, url, htmlAttributes));
 }