pagination.pug 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. mixin pagination(pages, page_path, max_btns)
  2. //- @param pages.current_page the current page viewed
  3. //- @param pages.total_pages previously calculated,
  4. //- based on total entries and entries per page
  5. //- @param page_path the relative path, minus a trailing slash and page param
  6. //- @param max_btns max number of buttons on either side of the current page
  7. //- button and excludes first, prev, next, last
  8. if pages && pages.current_page && pages.total_pages && pages.total_pages > 1
  9. - var max_btns = max_btns || 4
  10. - var prev_page = Math.max(parseInt(pages.current_page, 10) - max_btns, 1)
  11. - var next_page = parseInt(pages.current_page, 10) + 1
  12. - var next_index = 0
  13. - var full_page_path = page_path + '/page/'
  14. nav(role='navigation' aria-label=translate('pagination_navigation'))
  15. ul.pagination
  16. if pages.current_page > 1
  17. li
  18. a(aria-label=translate('go_to_first_page') href=page_path)
  19. span(aria-hidden='true') <<
  20. |
  21. | First
  22. li
  23. a(
  24. aria-label=translate('go_to_previous_page')
  25. href=full_page_path + (parseInt(pages.current_page, 10) - 1)
  26. rel='prev'
  27. )
  28. span(aria-hidden='true') <
  29. |
  30. | Prev
  31. if pages.current_page - max_btns > 1
  32. li(aria-hidden='true')
  33. span …
  34. while prev_page < pages.current_page
  35. li
  36. a(
  37. aria-label=translate('go_to_page_x', {page: prev_page})
  38. href=full_page_path + prev_page
  39. ) #{prev_page}
  40. - prev_page++
  41. li(class='active')
  42. span(
  43. aria-label=translate('current_page_page', {page: pages.current_page})
  44. aria-current='true'
  45. ) #{pages.current_page}
  46. if pages.current_page < pages.total_pages
  47. while next_page <= pages.total_pages && next_index < max_btns
  48. li
  49. a(
  50. aria-label=translate('go_to_page_x', {page: next_page})
  51. href=full_page_path + next_page
  52. ) #{next_page}
  53. - next_page++
  54. - next_index++
  55. if next_page <= pages.total_pages
  56. li.ellipses(aria-hidden='true')
  57. span …
  58. li
  59. a(
  60. aria-label=translate('go_to_next_page')
  61. href=full_page_path + (parseInt(pages.current_page, 10) + 1)
  62. rel='next'
  63. )
  64. | Next
  65. |
  66. span(aria-hidden='true') &gt;
  67. li
  68. a(
  69. aria-label=translate('go_to_last_page')
  70. href=full_page_path + pages.total_pages
  71. )
  72. | Last
  73. |
  74. span(aria-hidden='true') &gt;&gt;