Permalink
Browse files

woops, had left out my changes

  • Loading branch information...
daveheitzman committed Sep 5, 2012
1 parent 33b707c commit e38b0e9930eb4e862e09ce35b278bb18b1fc7d4b
Showing with 28 additions and 1 deletion.
  1. +28 −1 lib/will_paginate/view_helpers/link_renderer_base.rb
@@ -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 e38b0e9

Please sign in to comment.