From 07f556e789c37ca9b7e01cbf292d56b1ea94e85c Mon Sep 17 00:00:00 2001 From: Domizio Demichelis Date: Sun, 8 Jul 2018 17:17:17 +0200 Subject: [PATCH] fix for "area" typos in bulma extra (#62) and consistency improvement across responsive helpers --- lib/pagy/extras/bulma.rb | 18 ++---- lib/pagy/extras/javascripts/pagy.js | 9 ++- lib/pagy/extras/responsive.rb | 34 ++++++----- lib/pagy/extras/templates/nav_bulma.html.erb | 4 +- lib/pagy/extras/templates/nav_bulma.html.haml | 4 +- lib/pagy/extras/templates/nav_bulma.html.slim | 4 +- test/pagy/extras/bulma_test.rb | 58 +++++++++---------- test/pagy/extras/responsive_test.rb | 35 ++++------- 8 files changed, 74 insertions(+), 92 deletions(-) diff --git a/lib/pagy/extras/bulma.rb b/lib/pagy/extras/bulma.rb index 67eb930a9..12e33d216 100644 --- a/lib/pagy/extras/bulma.rb +++ b/lib/pagy/extras/bulma.rb @@ -14,24 +14,14 @@ def pagy_nav_bulma(pagy) : %(#{pagy_t('pagy.nav.next')})) html << '' %() end - private - - def pagy_nav_bulma_item(link, item) - if item.is_a?(Integer) # page link - aria = %( area-label="goto page #{item}") - %(
  • #{link.call item, item, 'class="pagination-link"' + aria}
  • ) - elsif item.is_a?(String) # active page - aria = %( area-label="page #{item}" area-current="page") - %(
  • #{link.call item, item, 'class="pagination-link is-current"' + aria}
  • ) - elsif item == :gap # page gap - %(
  • #{pagy_t('pagy.nav.gap')}
  • ) - end - end end end diff --git a/lib/pagy/extras/javascripts/pagy.js b/lib/pagy/extras/javascripts/pagy.js index eaaa39762..3d39e750a 100644 --- a/lib/pagy/extras/javascripts/pagy.js +++ b/lib/pagy/extras/javascripts/pagy.js @@ -46,18 +46,17 @@ Pagy.items = function(id, marker, from){ Pagy.responsive = function(id, tags, widths, series){ var pagyNav = document.getElementById('pagy-nav-'+id), - pagyBox = pagyNav.firstChild || pagyNav, pagyParent = pagyNav.parentElement, lastWidth = undefined, render = function(){ var parentWidth = parseInt(pagyParent.clientWidth), width = widths.find(function(w){return parentWidth > w}); if (width !== lastWidth) { - while (pagyBox.firstChild) { pagyBox.removeChild(pagyBox.firstChild) } - var html = tags['prev']; + while (pagyNav.firstChild) { pagyNav.removeChild(pagyNav.firstChild) } + var html = tags['before']; series[width].forEach(function(item){html += tags[item]}); - html += tags['next']; - pagyBox.insertAdjacentHTML('beforeend', html); + html += tags['after']; + pagyNav.insertAdjacentHTML('beforeend', html); lastWidth = width; } }.bind(this); diff --git a/lib/pagy/extras/responsive.rb b/lib/pagy/extras/responsive.rb index 298a1d747..a7da4c57a 100644 --- a/lib/pagy/extras/responsive.rb +++ b/lib/pagy/extras/responsive.rb @@ -36,16 +36,16 @@ module Frontend def pagy_nav_responsive(pagy, id=caller(1,1)[0].hash) tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive - tags['prev'] = (p_prev ? %(#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'} ) - : %(#{pagy_t('pagy.nav.prev')} )) + tags['before'] = (p_prev ? %(#{link.call p_prev, pagy_t('pagy.nav.prev'), 'aria-label="previous"'} ) + : %(#{pagy_t('pagy.nav.prev')} )) responsive[:items].each do |item| # series example: [1, :gap, 7, 8, "9", 10, 11, :gap, 36] tags[item.to_s] = if item.is_a?(Integer); %(#{link.call item} ) # page link elsif item.is_a?(String) ; %(#{item} ) # current page elsif item == :gap ; %(#{pagy_t('pagy.nav.gap')} ) # page gap end end - tags['next'] = (p_next ? %(#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}) - : %(#{pagy_t('pagy.nav.next')})) + tags['after'] = (p_next ? %(#{link.call p_next, pagy_t('pagy.nav.next'), 'aria-label="next"'}) + : %(#{pagy_t('pagy.nav.next')})) script = %() %(#{script}) end @@ -55,18 +55,20 @@ def pagy_nav_responsive(pagy, id=caller(1,1)[0].hash) def pagy_nav_responsive_bootstrap(pagy, id=caller(1,1)[0].hash) tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy, 'class="page-link"'), pagy.prev, pagy.next, pagy.responsive - tags['prev'] = (p_prev ? %() - : %()) + tags['before'] = +'' script = %() - %(#{script}) + %(#{script}) end # Responsive pagination for Bulma: it returns the html with the series of links to the pages @@ -74,16 +76,18 @@ def pagy_nav_responsive_bootstrap(pagy, id=caller(1,1)[0].hash) def pagy_nav_responsive_bulma(pagy, id=caller(1,1)[0].hash) tags, link, p_prev, p_next, responsive = {}, pagy_link_proc(pagy), pagy.prev, pagy.next, pagy.responsive - tags['prev'] = (p_prev ? %(#{link.call(p_prev, pagy_t('pagy.nav.prev'), 'class="pagination-previous" aria-label="previous page"')}' script = %() %(#{script}) end diff --git a/lib/pagy/extras/templates/nav_bulma.html.erb b/lib/pagy/extras/templates/nav_bulma.html.erb index 6c9a57eeb..1b4926a17 100644 --- a/lib/pagy/extras/templates/nav_bulma.html.erb +++ b/lib/pagy/extras/templates/nav_bulma.html.erb @@ -15,8 +15,8 @@ <% end -%> <%# -%>