Beispiel #1
0
        protected override void OnStart(TextWriter writer)
        {
            // Check if we're in a navbar, and if so, make sure we're in a navbar nav
            if (GetComponent <Navbar>() != null && GetComponent <NavbarNav>() == null)
            {
                GetHelper().NavbarNav().Component.Start(writer);
            }

            // Check if we're in a nav
            if (GetComponent <Nav>(true) != null || GetComponent <NavbarNav>(true) != null)
            {
                TagName = "li";
                Link link = GetHelper().Link(null).Component;
                link.AddCss(Css.DropdownToggle);
                link.MergeAttribute("data-toggle", "dropdown");
                _toggle = link;
            }
            else
            {
                // Create a button and copy over any button classes and text
                Button button = GetHelper().Button().Component;
                button.RemoveCss(Css.BtnDefault);
                button.AddCss(Css.DropdownToggle);
                button.MergeAttribute("data-toggle", "dropdown");
                foreach (string buttonClass in CssClasses.Where(x => x.StartsWith("btn")))
                {
                    button.CssClasses.Add(buttonClass);
                }
                _toggle = button;
            }
            CssClasses.RemoveWhere(x => x.StartsWith("btn"));

            // Add the text and caret
            if (TextContent != null)
            {
                _toggle.AddChild(GetHelper().Content(TextContent));
                _toggle.AddChild(GetHelper().Content(" "));
            }
            else
            {
                Element element = GetHelper().Element("span").AddCss(Css.SrOnly).Component;
                element.AddChild(GetHelper().Content("Toggle Dropdown"));
                _toggle.AddChild(element);
            }
            TextContent = null;
            if (Caret)
            {
                _toggle.AddChild(GetHelper().Caret());
            }

            // Check if we're in a InputGroupButton, then
            // Check if we're in a button group, and if so change the outer CSS class
            // Do this after copying over the btn classes so this doesn't get copied
            if (GetComponent <InputGroupButton>(true) != null)
            {
                _inputGroupButton = true;
            }
            else if (GetComponent <ButtonGroup>(true) != null)
            {
                ToggleCss(Css.BtnGroup, true, Css.Dropdown);
            }

            // Create the list
            _list = GetHelper().List(ListType.Unordered).Component;
            _list.AddCss(Css.DropdownMenu);
            _list.MergeAttribute("role", "menu");
            if (MenuRight)
            {
                _list.AddCss(Css.DropdownMenuRight);
            }
            if (MenuLeft)
            {
                _list.AddCss(Css.DropdownMenuLeft);
            }
            if (Scrollable)
            {
                _list.AddCss(Css.PreScrollable);
            }

            // Start this component
            base.OnStart(_inputGroupButton ? new SuppressOutputWriter() : writer);

            // Output the button
            _toggle.StartAndFinish(writer);

            // Output the start of the list
            _list.Start(writer);
        }
Beispiel #2
0
        protected override void OnStart(TextWriter writer)
        {
            // Check if we're in a navbar, and if so, make sure we're in a navbar nav
            if (GetComponent <INavbar>() != null && GetComponent <INavbarNav>() == null)
            {
                new NavbarNav <THelper>(Helper).Start(writer);
            }

            // Check if we're in a nav
            if (GetComponent <INav>(true) != null || GetComponent <INavbarNav>(true) != null)
            {
                TagName = "li";
                Link <THelper> link = Helper.Link(null);
                link.AddCss(Css.DropdownToggle);
                link.AddAttribute("data-toggle", "dropdown");
                _toggle = link;
            }
            else
            {
                // Create a button and copy over any button classes and text
                Button <THelper> button = Helper.Button();
                button.RemoveCss(Css.BtnDefault);
                button.AddCss(Css.DropdownToggle);
                button.AddAttribute("data-toggle", "dropdown");
                foreach (string buttonClass in CssClasses.Where(x => x.StartsWith("btn")))
                {
                    button.CssClasses.Add(buttonClass);
                }
                _toggle = button;
            }
            CssClasses.RemoveWhere(x => x.StartsWith("btn"));

            // Add the text and caret
            if (!string.IsNullOrWhiteSpace(TextContent))
            {
                _toggle.AddChild(new Content <THelper>(Helper, TextContent + " "));
            }
            else
            {
                Element <THelper> element = new Element <THelper>(Helper, "span").AddCss(Css.SrOnly);
                element.AddChild(new Content <THelper>(Helper, "Toggle Dropdown"));
                _toggle.AddChild(element);
            }
            TextContent = null;
            if (_caret)
            {
                _toggle.AddChild(Helper.Caret());
            }

            // Check if we're in a IDropdownButton or IInputGroupButton, then
            // Check if we're in a button group, and if so change the outer CSS class
            // Do this after copying over the btn classes so this doesn't get copied
            if (GetComponent <IDropdownButton>(true) != null || GetComponent <IInputGroupButton>(true) != null)
            {
                _dropdownButton = true;
            }
            else if (GetComponent <IButtonGroup>(true) != null)
            {
                ToggleCss(Css.BtnGroup, true, Css.Dropdown);
            }

            // Create the list
            _list = Helper.List(ListType.Unordered);
            _list.AddCss(Css.DropdownMenu);
            _list.MergeAttribute("role", "menu");
            if (_menuRight)
            {
                _list.AddCss(Css.DropdownMenuRight);
            }
            if (_menuLeft)
            {
                _list.AddCss(Css.DropdownMenuLeft);
            }

            // Start this component
            base.OnStart(_dropdownButton ? new SuppressOutputWriter() : writer);

            // Output the button
            _toggle.StartAndFinish(writer);

            // Output the start of the list
            _list.Start(writer);
        }