Merge pull request 'Make pagination padding clickable again' (#40) from page-wildcards into master

Reviewed-on: Public/pics#40
This commit is contained in:
Roflin 2023-11-22 16:03:47 +01:00
commit 0eece8ea3c
2 changed files with 31 additions and 2 deletions

View File

@ -74,6 +74,10 @@ a:hover {
.pagination .page-item {
box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.3);
white-space: nowrap;
}
.pagination .wildcard {
cursor: pointer;
}
@media (max-width: 767px) {
@ -88,13 +92,16 @@ a:hover {
.pagination .page-link {
border-radius: var(--bs-pagination-border-radius) !important;
}
.pagination > :first-child, .pagination > :last-child {
.pagination > :first-child, .pagination > :last-child, .pagination .first-wildcard {
display: inline-block;
position: absolute;
}
.pagination > :first-child {
left: 0;
}
.pagination > .first-wildcard {
left: 48%;
}
.pagination > :last-child {
right: 0;
}

View File

@ -11,6 +11,8 @@ class PageIndexWidget extends Template
private $index;
private string $class;
private static $unique_index_count = 0;
public function __construct(PageIndex $index)
{
$this->index = $index;
@ -37,14 +39,22 @@ class PageIndexWidget extends Template
'<a class="page-link"', !empty($page_index['previous']) ? ' href="' . $page_index['previous']['href'] . '"' : '', '>',
'&laquo; previous</a></li>';
$num_wildcards = 0;
foreach ($page_index as $key => $page)
{
if (!is_numeric($key))
continue;
if (!is_array($page))
{
$first_wildcard = $num_wildcards === 0;
$num_wildcards++;
echo '
<li class="page-item page-padding disabled"><a class="page-link">...</a></li>';
<li class="page-item page-padding wildcard',
$first_wildcard ? ' first-wildcard' : '',
'" onclick="javascript:promptGoToPage(',
self::$unique_index_count, ')"><a class="page-link">...</a></li>';
}
else
echo '
<li class="page-item page-number', $page['is_selected'] ? ' active" aria-current="page' : '', '">',
@ -56,5 +66,17 @@ class PageIndexWidget extends Template
'<a class="page-link"', !empty($page_index['next']) ? ' href="' . $page_index['next']['href'] . '"' : '', '>',
'next &raquo;</a></li>
</ul>';
if ($num_wildcards)
{
echo '
<script type="text/javascript">
var page_index_', self::$unique_index_count++, ' = {
wildcard_url: "', $index->getLink("%d"), '",
num_pages: ', $index->getNumberOfPages(), ',
per_page: ', $index->getItemsPerPage(), '
};
</script>';
}
}
}