Exemplo n.º 1
0
        protected override void RenderItem(HtmlTextWriter writer, PagerItem item)
        {
            var attrs = new RouteValueDictionary();

            if (item.State == PagerItemState.Disabled)
            {
                //writer.AddAttribute("class", "disabled");
                AppendCssClass(attrs, "disabled");
            }
            else if (item.State == PagerItemState.Selected)
            {
                //writer.AddAttribute("class", "active");
                AppendCssClass(attrs, "active");
            }

            if (item.Type == PagerItemType.Text)
            {
                AppendCssClass(attrs, "shrinked");
            }

            if (Component.Style == PagerStyle.Blog && item.IsNavButton)
            {
                AppendCssClass(attrs, (item.Type == PagerItemType.PreviousPage || item.Type == PagerItemType.FirstPage) ? "previous" : "next");
            }

            writer.AddAttributes(attrs);
            writer.RenderBeginTag("li");

            if (item.Type == PagerItemType.Page || item.IsNavButton)
            {
                // write anchor
                writer.AddAttribute("href", item.Url);
                if (item.IsNavButton)
                {
                    writer.AddAttribute("title", item.Text.AttributeEncode());
                    if (Component.Style != PagerStyle.Blog)
                    {
                        writer.AddAttribute("rel", "tooltip");
                        writer.AddAttribute("class", "pager-nav");
                    }
                }
                else
                {
                    var formatStr = Component.ItemTitleFormatString;
                    if (!string.IsNullOrEmpty(formatStr))
                    {
                        writer.AddAttribute("title", string.Format(formatStr, item.Text).AttributeEncode());
                        writer.AddAttribute("rel", "tooltip");
                    }
                }
                writer.RenderBeginTag("a");
            }
            else
            {
                // write span
                writer.RenderBeginTag("span");
            }

            this.RenderItemInnerContent(writer, item);

            writer.RenderEndTag(); // a || span

            writer.RenderEndTag(); // li
        }
Exemplo n.º 2
0
        protected List <PagerItem> CreateItemList()
        {
            var pager = base.Component;

            if (!pager.ShowPaginator || pager.Model.TotalPages <= 1)
            {
                return(new List <PagerItem>());
            }

            var pageNumber = pager.Model.PageNumber;
            var pageCount  = pager.Model.TotalPages;

            var results = new List <PagerItem>();

            PagerItem item;

            // first link
            if (pager.ShowFirst && pageNumber > 1)
            {
                item       = new PagerItem(pager.FirstButtonText, GenerateUrl(1), PagerItemType.FirstPage);
                item.State = (pageNumber > 1) ? PagerItemState.Normal : PagerItemState.Disabled;
                results.Add(item);
            }

            // previous link
            if (pager.ShowPrevious && pageNumber > 1)
            {
                item       = new PagerItem(pager.PreviousButtonText, GenerateUrl(pageNumber - 1), PagerItemType.PreviousPage);
                item.State = (pageNumber > 1) ? PagerItemState.Normal : PagerItemState.Disabled;
                results.Add(item);
            }

            // add the page number items
            if (pager.MaxPagesToDisplay > 0)
            {
                this.AddPageItemsList(results);
            }

            // next link
            var hasNext = false;

            if (pager.ShowNext && pageNumber < pageCount)
            {
                item       = new PagerItem(pager.NextButtonText, GenerateUrl(pageNumber + 1), PagerItemType.NextPage);
                item.State = (pageNumber == pageCount) ? PagerItemState.Disabled : PagerItemState.Normal;
                results.Add(item);
                hasNext = true;
            }

            // last link
            if (pager.ShowLast && pageNumber < pageCount)
            {
                item       = new PagerItem(pager.LastButtonText, GenerateUrl(pageCount), PagerItemType.LastPage);
                item.State = (pageNumber == pageCount) ? PagerItemState.Disabled : PagerItemState.Normal;
                if (pager.Style == PagerStyle.Pagination || !hasNext)
                {
                    results.Add(item);
                }
                else
                {
                    // BlogStyle Last-Item is right-aligned, so shift left
                    results.Insert(results.Count - 1, item);
                }
            }

            return(results);
        }