Permalink
Browse files

added option to put in bisection links

  • Loading branch information...
daveheitzman committed Sep 5, 2012
1 parent 71f793e commit bf46f952c6ae29c4eda1c7dd679531648942c869
Showing with 29 additions and 2 deletions.
  1. +1 −1 lib/will_paginate/version.rb
  2. +28 −1 lib/will_paginate/view_helpers/link_renderer_base.rb
@@ -2,7 +2,7 @@ module WillPaginate #:nodoc:
module VERSION #:nodoc:
MAJOR = 3
MINOR = 0
- TINY = 3
+ TINY = 4
STRING = [MAJOR, MINOR, TINY].join('.')
end
@@ -60,9 +60,36 @@ def windowed_page_numbers
right = (middle.last + 1)..total_pages
end
- left.to_a + middle.to_a + right.to_a
+ out = left.to_a + middle.to_a + right.to_a
+ return @options[:bisect] ? windowed_page_numbers_bisected( out ) : out
end
+
+ def windowed_page_numbers_bisected(out)
+ bisect_right = ((total_pages + current_page)/2).to_i
+ bisect_left = (current_page/2).to_i
+ inner_window, outer_window = @options[:inner_window].to_i, @options[:outer_window].to_i
+
+ start_at = out.index(current_page)
+ return out unless start_at
+ start_at -= 1 while !out[start_at].is_a?(Symbol) && start_at > 0
+ window_from = start_at
+
+ start_at = out.index(current_page)
+ start_at += 1 while !out[start_at].is_a?(Symbol) && start_at < out.size
+ window_to = start_at
+
+ if !out.include?(bisect_right) && bisect_right < total_pages && bisect_right > 1
+ out[window_to-2] = :gap
+ out[window_to-1] =bisect_right
+ end
+ if !out.include?(bisect_left) && bisect_left > 1
+ out[ window_from + 1 ] = bisect_left
+ out[ window_from + 2 ] = :gap
+ end
+ return out
+ end
+
private
def current_page

0 comments on commit bf46f95

Please sign in to comment.