-
-
Save chaptastic/f2f3869f01f0fbb1554d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- mislav-will_paginate-2.3.7/lib/will_paginate/view_helpers.rb 2009-09-28 16:27:54.000000000 -0400 | |
+++ mislav-will_paginate-mod/lib/will_paginate/view_helpers.rb 2009-12-22 16:17:09.000000000 -0500 | |
@@ -269,8 +269,8 @@ | |
def visible_page_numbers | |
inner_window, outer_window = @options[:inner_window].to_i, @options[:outer_window].to_i | |
window_from = current_page - inner_window | |
- window_to = current_page + inner_window | |
- | |
+ window_to = current_page + inner_window | |
+ | |
# adjust lower or upper limit if other is out of bounds | |
if window_to > total_pages | |
window_from -= window_to - total_pages | |
@@ -282,13 +282,32 @@ | |
window_to = total_pages if window_to > total_pages | |
end | |
- visible = (1..total_pages).to_a | |
- left_gap = (2 + outer_window)...window_from | |
- right_gap = (window_to + 1)...(total_pages - outer_window) | |
- visible -= left_gap.to_a if left_gap.last - left_gap.first > 1 | |
- visible -= right_gap.to_a if right_gap.last - right_gap.first > 1 | |
- | |
- visible | |
+ out_lower_bound = [outer_window + 1, total_pages].min | |
+ out_upper_bound = [total_pages - inner_window, 1].max | |
+ | |
+ # check for ovelap between the three regions in the page list | |
+ # <out_lower> ... <window> ... <out_upper> | |
+ # we adjust the out_lower_bound and out_upper_bound tests | |
+ # to elimiate one-space gaps | |
+ | |
+ merge_lower = (window_from - out_lower_bound) <= 2 | |
+ merge_upper = (out_upper_bound - window_to) <= 1 | |
+ if merge_lower and merge_upper | |
+ # all three ranges overlap | |
+ Range.new(1, total_pages).to_a | |
+ elsif merge_lower | |
+ # lower and window overlap | |
+ visible = Range.new(1, window_to).to_a | |
+ visible += Range.new(out_upper_bound, total_pages).to_a | |
+ elsif merge_upper | |
+ # window and upper overlap | |
+ visible = Range.new(1, out_lower_bound).to_a | |
+ visible += Range.new(window_from, total_pages).to_a | |
+ else | |
+ visible = Range.new(1, out_lower_bound).to_a | |
+ visible += Range.new(window_from, window_to).to_a | |
+ visible += Range.new(out_upper_bound, total_pages).to_a | |
+ end | |
end | |
def page_link_or_span(page, span_class, text = nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment