Sha256: e611491f7c88716516e8715873da1456dc4b8e638168b386f67d4d71000ca622
Contents?: true
Size: 1.82 KB
Versions: 7
Compression:
Stored size: 1.82 KB
Contents
<% # much of this paging code adopted from will_paginate plugin for view total_pages = (@hits / @batch_size) total_pages += 1 unless (@hits % @batch_size == 0) if total_pages > 1 # Arguments for paging actions, just add 'page' args= params.clone # Need to take out that annoying legacy journal key, sorry. args.delete('journal') inner_window ||= 2 #how many links are shown on each side of current page outer_window ||= 2 #how many links are around the first and the last page min = @page - inner_window max = @page + inner_window # adjust lower or upper limit if other is out of bounds if max > total_pages min -= max - total_pages elsif min < 1 max += 1 - min end current = min..max beginning = 1..(1 + outer_window) tail = (total_pages - outer_window)..total_pages visible = [beginning, current, tail].map(&:to_a).flatten.sort.uniq links, prev = [], 0 visible.each do |n| next if n < 1 break if n > total_pages unless n - prev > 1 prev = n if ( n != @page ) links << (content_tag :li, (link_to n, args.merge({'page' => n })), :class => "hidden-phone") else links << (content_tag :li, (content_tag :span, n) ) end else # ellipsis represents the gap between windows prev = n - 1 links << (content_tag :li, (content_tag :span, "…".html_safe), :class => "hidden-phone") redo end end # Next and previous buttons links.unshift( content_tag :li, (link_to('Previous', args.merge({'page' => @page -1 })))) if @page > 1 links.push( content_tag :li, (link_to('Next', args.merge({'page' => @page + 1})))) if @page < total_pages %> <%= content_tag :ul, links.join(' ').html_safe %> <% end %>
Version data entries
7 entries across 7 versions & 1 rubygems