1 module NumberedPaginationHelper
2 def element_versions_pagination(top_version, active_version: top_version + 1, window_half_size: 50, &)
6 lists << tag.ul(:class => "pagination pagination-sm mt-1") do
7 (1..top_version).each do |v|
8 concat element_versions_pagination_item(v, **yield(v), :active => v == active_version)
12 start_list_versions = 1..(active_version < 3 ? active_version + 1 : 1)
13 end_list_versions = (active_version > top_version - 2 ? active_version - 1 : top_version)..top_version
14 middle_list_versions = Range.new([active_version - window_half_size, start_list_versions.last + 1].max,
15 [active_version + window_half_size, end_list_versions.first - 1].min)
17 lists << tag.ul(:id => "versions-navigation-list-start",
18 :class => "pagination pagination-sm mt-1") do
19 start_list_versions.each do |v|
20 concat element_versions_pagination_item(v, **yield(v), :active => v == active_version,
21 :edge => [false, v == start_list_versions.last],
25 lists << tag.ul(:id => "versions-navigation-list-middle",
27 "pagination pagination-sm",
28 "overflow-x-scroll pb-3", # horizontal scrollbar with reserved space below
29 "pt-1 px-1 mx-n1", # space reserved for focus outlines
30 "position-relative" # required for centering when clicking "Version #n"
32 concat element_versions_pagination_item("...", :edge => [true, false]) if middle_list_versions.first > start_list_versions.last + 1
33 middle_list_versions.each do |v|
34 concat element_versions_pagination_item(v, **yield(v), :active => v == active_version,
35 :edge => [v == start_list_versions.last + 1,
36 v == end_list_versions.first - 1])
38 concat element_versions_pagination_item("...", :edge => [false, true]) if middle_list_versions.last < end_list_versions.first - 1
40 lists << tag.ul(:id => "versions-navigation-list-end",
41 :class => "pagination pagination-sm mt-1") do
42 end_list_versions.each do |v|
43 concat element_versions_pagination_item(v, **yield(v), :active => v == active_version,
44 :edge => [v == end_list_versions.first, false],
50 tag.div safe_join(lists), :class => "d-flex align-items-start"
55 def element_versions_pagination_item(body, href: nil, title: nil, active: false, edge: [false, false], edge_border: false)
56 link_class = ["page-link", { "rounded-start-0" => edge.first,
57 "border-start-0" => edge.first && !edge_border,
58 "rounded-end-0" => edge.last,
59 "border-end-0" => edge.last && !edge_border }]
61 link_to body, href, :class => link_class, :title => title
63 tag.span body, :class => link_class
65 tag.li link, :id => ("versions-navigation-active-page-item" if active),
66 :class => ["page-item", { "disabled" => !href, "active" => active }]