Sha256: feb4cc78e017773f48684bdb6da5e0081c3c2f3668eafcb3951bcdcc51f1c596
Contents?: true
Size: 1.9 KB
Versions: 20
Compression:
Stored size: 1.9 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-xs") else links << (content_tag :li, (content_tag :span, n), :class => "active" ) end else # ellipsis represents the gap between windows prev = n - 1 links << (content_tag :li, (content_tag :span, "…".html_safe), :class => "hidden-xs disabled") redo end end # Next and previous buttons links.unshift( content_tag :li, (link_to(t('umlaut.search.previous'), args.merge({'page' => @page -1 })))) if @page > 1 links.push( content_tag :li, (link_to(t('umlaut.search.next'), args.merge({'page' => @page + 1})))) if @page < total_pages %> <%= content_tag :ul, links.join(' ').html_safe, :class => "pagination" %> <% end %>
Version data entries
20 entries across 20 versions & 1 rubygems