ruhoh / ruhoh.rb

http://ruhoh.com
616 stars 69 forks source link

Paginator, collapsing page links if there are a lot of pages. #247

Open mudasobwa opened 10 years ago

mudasobwa commented 10 years ago

JIC it might be helpful for those who has a lot of pages within collections, I have provided a gist with my code for configurable “clever” paginator: https://gist.github.com/mudasobwa/7718359

It renders a paginator in the following manner: first N pages, dots linked to the middle of hidden range, N pages around current, dots, last N pages.

Paginator at first page

Paginator in the middle page

Configurable through collection → paginator → borders entry in config.yml:

collection:
  …
  paginator:
    borders: 5

Value sets an amount of pages to make link visible for, e. g. for 3 it will display (assuming we are at 15th index page of 128 total):

[1][2][3][…][14][⇒15⇐][16][…][126][127][128]