Esempio n. 1
0
        /// <summary>
        /// 注册脚本
        /// </summary>
        private void RegistScript(string id, Global_TabMenu menus)
        {
            Client.RegistScripts("/Scripts/Common/Tabselect/tabselect.js");
            var config = string.Format("beginIndex: {0}, tabEvent: \"{1}\", checkMenuClass: \"{2}\", checkContentClass: \"{3}\",menuChildSel: \"{4}\"", menus.BeginIndex, menus.TabEvent, menus.CheckMenuClass, menus.CheckContentClass, menus.MenuChildSel);

            Client.RegistScriptBlock("$(\"#" + id + " ul\").tabselecter({" + config + "});");
        }
Esempio n. 2
0
        /// <summary>
        /// 选项卡
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="menus"></param>
        /// <param name="style"></param>
        /// <param name="htmlAttributes"></param>
        /// <returns></returns>
        public static MvcHtmlString TabMenu(this HtmlHelper htmlHelper, Global_TabMenu menus, TabMenuStyle style = TabMenuStyle.TabMenu_OrangeYellow, object htmlAttributes = null)
        {
            if (menus.Options.Count < 2)
            {
                throw new Exception("选项卡至少包含两个选项");
            }
            string styleString = Enum.GetName(typeof(TabMenuStyle), style);

            return(new TabBuilder().TabMenu(menus, styleString, htmlAttributes));
        }
Esempio n. 3
0
        /// <summary>
        /// 生成选项卡结构
        /// </summary>
        /// <param name="styleName"></param>
        /// <param name="htmlAttributes"></param>
        /// <returns></returns>
        public MvcHtmlString TabMenu(Global_TabMenu menus, string styleName, object htmlAttributes = null)
        {
            //外层DIV
            var divBuilder = new TagBuilder("div");

            divBuilder.AddCssClass(styleName);
            divBuilder.MergeAttribute("data-type", "cms-tabselect", true);
            divBuilder.MergeAttributes(HtmlExtensionsTools.ObjectToHtmlAttributes(htmlAttributes), true);
            var id = Guid.NewGuid().ToString("N");

            //divBuilder.GenerateId();有BUG,有时页面没有生成ID
            divBuilder.MergeAttribute("id", id, true);
            //UL
            var ulBuilder = new TagBuilder("ul");
            var options   = menus.Options.ToArray();

            for (int i = 0; i < options.Length; i++)
            {
                var option = options[i];
                if (string.IsNullOrEmpty(option.TargetSelecter))
                {
                    throw new Exception(string.Format("第{0}个选项目标选择器不能为空", i + 1));
                }
                if (string.IsNullOrEmpty(option.Value))
                {
                    throw new Exception(string.Format("第{0}个选项值不能为空", i + 1));
                }
                var optionBuilder = new TagBuilder("li");
                optionBuilder.MergeAttribute("data-href", option.TargetSelecter, true);
                optionBuilder.SetInnerText(option.Value);
                optionBuilder.MergeAttributes(option.HtmlAttributes, true);
                ulBuilder.InnerHtml += optionBuilder.ToString();
            }
            divBuilder.InnerHtml = ulBuilder.ToString();
            RegistScript(id, menus);
            return(new MvcHtmlString(divBuilder.ToString()));
        }