Пример #1
0
        /// <summary>
        ///   Constructor
        /// </summary>
        /// <param name="type">Progress bar type</param>
        /// <param name="percent">Percentage of completion for the progress bar</param>
        /// <param name="srText">[Optional] Custom text to be displayed in progress bar. Defaults to percentage complete</param>
        /// <param name="htmlAttributes">[Optional] Extra HTML attributes</param>
        public BootstrapProgressBar(EBootstrapProgressBar type, int percent, string srText = null,
                                    object htmlAttributes = null)
            : base(EHtmlTag.Div, htmlAttributes)
        {
            Percent        = percent;
            this["class"] += "progress";

            HtmlComponent inner = new HtmlComponent(EHtmlTag.Div);

            switch (WebExtrasSettings.BootstrapVersion)
            {
            case EBootstrapVersion.None:
                throw new BootstrapVersionException();

            case EBootstrapVersion.V2:
                inner.Attributes["class"] = string.Format("bar bar-{0}", type.ToString().ToLowerInvariant());
                break;

            case EBootstrapVersion.V3:
                inner.Attributes["class"] =
                    string.Format("progress-bar progress-bar-{0}", type.ToString().ToLowerInvariant());
                inner.Attributes["role"]          = "progressbar";
                inner.Attributes["aria-valuenow"] = percent.ToString(CultureInfo.InvariantCulture);
                inner.Attributes["aria-valuemin"] = "0";
                inner.Attributes["aria-valuemax"] = "100";

                HtmlComponent spanInner = new HtmlComponent(EHtmlTag.Span);
                spanInner.InnerHtml           = string.IsNullOrWhiteSpace(srText) ? percent + "% Complete" : srText;
                spanInner.Attributes["class"] = "sr-only";

                inner.AppendTags.Add(spanInner);
                break;
            }

            Component.AppendTags.Add(inner);

            //this.m_tag.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
        }
Пример #2
0
 /// <summary>
 ///   Create a bootstrap progress bar
 /// </summary>
 /// <param name="html">Current HTML helper object</param>
 /// <param name="type">Progress bar type</param>
 /// <param name="percent">Percentage of completion for the progress bar</param>
 /// <param name="srText">[Optional] Custom text to be displayed in progress bar. Defaults to percentage complete</param>
 /// <param name="htmlAttributes">[Optional] Extra HTML attributes</param>
 /// <returns>A boostrap progress bar</returns>
 public static BootstrapProgressBar ProgressBar(this HtmlHelper html, EBootstrapProgressBar type, int percent,
                                                string srText         = null,
                                                object htmlAttributes = null)
 {
     return(new BootstrapProgressBar(type, percent, srText, htmlAttributes));
 }