Skip to content

Commit

Permalink
Add prev/next links to compact Bootstrap nav and improve HTML semanti…
Browse files Browse the repository at this point in the history
…cs (#21)
  • Loading branch information
cseelus authored and ddnexus committed May 29, 2018
1 parent f764cc1 commit dbc5a05
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/pagy/extras/compact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ def pagy_nav_compact(pagy, id=caller(1,1)[0].hash)
# Compact pagination for bootstrap: it returns the html with the series of links to the pages
# we use a numeric input tag to set the page and the PagyCompact javascript to navigate
def pagy_nav_bootstrap_compact(pagy, id=caller(1,1)[0].hash)
tags = ''; link = pagy_link_proc(pagy, 'class="btn btn-primary"')
tags = ''; link = pagy_link_proc(pagy)

tags << %(<nav id="pagy-nav-#{id}" class="pagy-nav-bootstrap-compact pagination" role="navigation" aria-label="pager">)

tags << link.call(MARKER, '', %(style="display: none;" ))

tags << %(<div class="btn-group" role="group">)
tags << (pagy.prev ? link.call(pagy.prev, pagy_t('pagy.nav.prev'.freeze), 'aria-label="previous"'.freeze)
: %(<a class="btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.prev'.freeze)}</a>))
tags << (pagy.prev ? link.call(pagy.prev, pagy_t('pagy.nav.prev'.freeze), 'aria-label="previous" class="prev btn btn-primary"'.freeze)
: %(<a class="prev btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.prev'.freeze)}</a>))

input = %(<input type="number" min="1" max="#{pagy.last}" value="#{pagy.page}" style="padding: 0; border: none; text-align: center; width: #{pagy.pages.to_s.length+1}rem;">)
tags << %(<button type="button" class="pagy-compact-input btn btn-primary disabled">#{pagy_t('pagy.compact.page'.freeze)} #{input} #{pagy_t('pagy.compact.of'.freeze)} #{pagy.pages}</button>)
tags << %(<div class="pagy-compact-input btn btn-primary disabled">#{pagy_t('pagy.compact.page'.freeze)} #{input} #{pagy_t('pagy.compact.of'.freeze)} #{pagy.pages}</div>)

tags << (pagy.next ? link.call(pagy.next, pagy_t('pagy.nav.next'.freeze), 'aria-label="next"'.freeze)
: %(<a class="btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.next'.freeze)}</a>))
tags << (pagy.next ? link.call(pagy.next, pagy_t('pagy.nav.next'.freeze), 'aria-label="next" class="next btn btn-primary"'.freeze)
: %(<a class="next btn btn-primary disabled" href="#">#{pagy_t('pagy.nav.next'.freeze)}</a>))

tags << %(</div></nav><script>PagyCompact('#{id}', '#{MARKER}', '#{pagy.page}');</script>)
end
Expand Down

0 comments on commit dbc5a05

Please sign in to comment.