2019-12-09 10:09:09 -05:00
|
|
|
mixin pagination(pages, page_path, max_btns)
|
2018-07-27 16:50:20 -04:00
|
|
|
//- @param pages.current_page the current page viewed
|
|
|
|
//- @param pages.total_pages previously calculated,
|
|
|
|
//- based on total entries and entries per page
|
|
|
|
//- @param page_path the relative path, minus a trailing slash and page param
|
|
|
|
//- @param max_btns max number of buttons on either side of the current page
|
|
|
|
//- button and excludes first, prev, next, last
|
|
|
|
|
2019-12-09 10:09:09 -05:00
|
|
|
if pages && pages.current_page && pages.total_pages && pages.total_pages > 1
|
2018-07-27 16:50:20 -04:00
|
|
|
- var max_btns = max_btns || 4
|
|
|
|
- var prev_page = Math.max(parseInt(pages.current_page, 10) - max_btns, 1)
|
|
|
|
- var next_page = parseInt(pages.current_page, 10) + 1
|
|
|
|
- var next_index = 0;
|
|
|
|
- var full_page_path = page_path + "/page/"
|
|
|
|
|
2024-10-07 09:16:06 -04:00
|
|
|
nav(role="navigation" aria-label=(translate("pagination_navigation")))
|
2018-07-27 16:50:20 -04:00
|
|
|
ul.pagination
|
|
|
|
if pages.current_page > 1
|
|
|
|
li
|
|
|
|
a(
|
2024-10-07 09:16:06 -04:00
|
|
|
aria-label=translate("go_to_first_page")
|
2018-07-27 16:50:20 -04:00
|
|
|
href=page_path
|
2024-10-07 09:16:06 -04:00
|
|
|
)
|
|
|
|
span(aria-hidden="true") <<
|
|
|
|
|
|
|
|
|
| First
|
2018-07-27 16:50:20 -04:00
|
|
|
li
|
|
|
|
a(
|
2024-10-07 09:16:06 -04:00
|
|
|
aria-label=translate("go_to_previous_page")
|
2018-07-27 16:50:20 -04:00
|
|
|
href=full_page_path + (parseInt(pages.current_page, 10) - 1)
|
|
|
|
rel="prev"
|
2024-10-07 09:16:06 -04:00
|
|
|
)
|
|
|
|
span(aria-hidden="true") <
|
|
|
|
|
|
|
|
|
| Prev
|
2018-07-27 16:50:20 -04:00
|
|
|
|
|
|
|
if pages.current_page - max_btns > 1
|
2024-10-07 09:16:06 -04:00
|
|
|
li(aria-hidden="true")
|
2018-07-27 16:50:20 -04:00
|
|
|
span …
|
|
|
|
|
|
|
|
while prev_page < pages.current_page
|
|
|
|
li
|
|
|
|
a(
|
2024-10-07 09:16:06 -04:00
|
|
|
aria-label=translate("go_to_page_x", {page: prev_page})
|
2018-07-27 16:50:20 -04:00
|
|
|
href=full_page_path + prev_page
|
|
|
|
) #{prev_page}
|
|
|
|
- prev_page++
|
|
|
|
|
|
|
|
li(class="active")
|
|
|
|
span(
|
2024-10-07 09:16:06 -04:00
|
|
|
aria-label=translate("current_page_page", {page: pages.current_page})
|
2018-07-27 16:50:20 -04:00
|
|
|
aria-current="true"
|
|
|
|
) #{pages.current_page}
|
|
|
|
|
|
|
|
if pages.current_page < pages.total_pages
|
|
|
|
while next_page <= pages.total_pages && next_index < max_btns
|
|
|
|
li
|
|
|
|
a(
|
2024-10-07 09:16:06 -04:00
|
|
|
aria-label=translate("go_to_page_x", {page: next_page})
|
2018-07-27 16:50:20 -04:00
|
|
|
href=full_page_path + next_page
|
|
|
|
) #{next_page}
|
|
|
|
- next_page++
|
|
|
|
- next_index++
|
|
|
|
|
|
|
|
if next_page <= pages.total_pages
|
2024-10-07 09:16:06 -04:00
|
|
|
li.ellipses(aria-hidden="true")
|
2018-07-27 16:50:20 -04:00
|
|
|
span …
|
|
|
|
|
|
|
|
li
|
|
|
|
a(
|
2024-10-07 09:16:06 -04:00
|
|
|
aria-label=translate("go_to_next_page")
|
2018-07-27 16:50:20 -04:00
|
|
|
href=full_page_path + (parseInt(pages.current_page, 10) + 1)
|
|
|
|
rel="next"
|
2024-10-07 09:16:06 -04:00
|
|
|
)
|
|
|
|
| Next
|
|
|
|
|
|
|
|
|
span(aria-hidden="true") >
|
2018-07-27 16:50:20 -04:00
|
|
|
|
|
|
|
li
|
|
|
|
a(
|
2024-10-07 09:16:06 -04:00
|
|
|
aria-label=translate("go_to_last_page")
|
2018-07-27 16:50:20 -04:00
|
|
|
href=full_page_path + pages.total_pages
|
2024-10-07 09:16:06 -04:00
|
|
|
)
|
|
|
|
| Last
|
|
|
|
|
|
|
|
|
span(aria-hidden="true") >>
|