forked from Public/pics
Allow jumping to random pages through pagination fillers.
This commit is contained in:
parent
29030eade6
commit
df7655e00b
@ -80,7 +80,8 @@ class ViewPhotoAlbum extends HTMLController
|
||||
}
|
||||
|
||||
// Set the canonical url.
|
||||
$this->page->setCanonicalUrl(BASEURL . '/' . (isset($_GET['tag']) ? $_GET['tag'] . '/' : ''));
|
||||
$this->page->setCanonicalUrl(BASEURL . '/' . (isset($_GET['tag']) ? $_GET['tag'] . '/' : '') .
|
||||
($page > 1 ? 'page/' . $page . '/' : ''));
|
||||
}
|
||||
|
||||
public function getPhotoMosaic($id_tag, $page)
|
||||
|
@ -42,7 +42,7 @@ class Dispatcher
|
||||
return new ViewPhotoAlbum();
|
||||
}
|
||||
// Look for particular actions...
|
||||
elseif (preg_match('~^/(?<action>[a-z]+)/?~', $_SERVER['PATH_INFO'], $path) && isset($possibleActions[$path['action']]))
|
||||
elseif (preg_match('~^/(?<action>[a-z]+)(?:/page/(?<page>\d+))?/?~', $_SERVER['PATH_INFO'], $path) && isset($possibleActions[$path['action']]))
|
||||
{
|
||||
$_GET = array_merge($_GET, $path);
|
||||
return new $possibleActions[$path['action']]();
|
||||
|
@ -201,7 +201,7 @@ class GenericTable extends PageIndex
|
||||
}
|
||||
}
|
||||
|
||||
protected function getLink($start = null, $order = null, $dir = null)
|
||||
public function getLink($start = null, $order = null, $dir = null)
|
||||
{
|
||||
if ($start === null)
|
||||
$start = $this->start;
|
||||
|
@ -132,14 +132,14 @@ class PageIndex
|
||||
$this->page_index['next'] = $this->page_index[$this->current_page + 1];
|
||||
}
|
||||
|
||||
protected function getLink($start = null, $order = null, $dir = null)
|
||||
public function getLink($start = null, $order = null, $dir = null)
|
||||
{
|
||||
$url = $this->base_url;
|
||||
$amp = strpos($this->base_url, '?') ? '&' : '?';
|
||||
|
||||
if (!empty($start))
|
||||
{
|
||||
$page = ($start / $this->items_per_page) + 1;
|
||||
$page = $start !== '%d' ? ($start / $this->items_per_page) + 1 : $start;
|
||||
$url .= strtr($this->page_slug, ['%PAGE%' => $page, '%AMP%' => $amp]);
|
||||
$amp = '&';
|
||||
}
|
||||
@ -167,6 +167,21 @@ class PageIndex
|
||||
return $this->page_index;
|
||||
}
|
||||
|
||||
public function getItemsPerPage()
|
||||
{
|
||||
return $this->items_per_page;
|
||||
}
|
||||
|
||||
public function getSortOrder()
|
||||
{
|
||||
return $this->sort_order;
|
||||
}
|
||||
|
||||
public function getSortDirection()
|
||||
{
|
||||
return $this->sort_direction;
|
||||
}
|
||||
|
||||
public function getPageIndexClass()
|
||||
{
|
||||
return $this->index_class;
|
||||
|
@ -134,6 +134,10 @@ ul#nav li a:hover {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.pagination .page-padding {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
|
||||
/* Tiled grid
|
||||
---------------*/
|
||||
|
16
public/js/main.js
Normal file
16
public/js/main.js
Normal file
@ -0,0 +1,16 @@
|
||||
function promptGoToPage(index_no) {
|
||||
var page_no = prompt('Go to which page?');
|
||||
if (page_no === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
var index = window['page_index_' + index_no];
|
||||
page_no = parseInt(page_no);
|
||||
|
||||
if (isNaN(page_no) || page_no < 1 || page_no > index.num_pages) {
|
||||
return alert('Invalid page number.');
|
||||
}
|
||||
|
||||
var offset = index.wildcard_url.indexOf('start=') !== -1 ? (page_no - 1) * index.per_page : page_no;
|
||||
window.location.href = index.wildcard_url.replace('%d', offset)
|
||||
}
|
@ -32,6 +32,7 @@ class MainTemplate extends Template
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">', !empty($this->css) ? '
|
||||
<style type="text/css">' . $this->css . '
|
||||
</style>' : '', $this->header_html, '
|
||||
<script type="text/javascript" src="', BASEURL, '/js/main.js"></script>
|
||||
</head>
|
||||
<body', !empty($this->classes) ? ' class="' . implode(' ', $this->classes) . '"' : '', '>
|
||||
<header>
|
||||
|
@ -3,42 +3,61 @@
|
||||
* Pagination.php
|
||||
* Contains the pagination template.
|
||||
*
|
||||
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
|
||||
* Kabuki CMS (C) 2013-2016, Aaron van Geffen
|
||||
*****************************************************************************/
|
||||
|
||||
class Pagination extends SubTemplate
|
||||
{
|
||||
private $index;
|
||||
private static $unique_index_count = 0;
|
||||
|
||||
public function __construct(PageIndex $index)
|
||||
{
|
||||
$this->index = $index->getPageIndex();
|
||||
$this->index = $index;
|
||||
$this->class = $index->getPageIndexClass();
|
||||
}
|
||||
|
||||
protected function html_content()
|
||||
{
|
||||
$index = $this->index->getPageIndex();
|
||||
|
||||
echo '
|
||||
<div class="table_pagination', !empty($this->class) ? ' ' . $this->class : '', '">
|
||||
<ul>
|
||||
<li class="first"><', !empty($this->index['previous']) ? 'a href="' . $this->index['previous']['href'] . '"' : 'span', '>« previous</', !empty($this->index['previous']) ? 'a' : 'span', '></li>';
|
||||
<li class="first"><', !empty($index['previous']) ? 'a href="' . $index['previous']['href'] . '"' : 'span', '>« previous</', !empty($index['previous']) ? 'a' : 'span', '></li>';
|
||||
|
||||
foreach ($this->index as $key => $page)
|
||||
$num_wildcards = 0;
|
||||
foreach ($index as $key => $page)
|
||||
{
|
||||
if (!is_numeric($key))
|
||||
continue;
|
||||
|
||||
if (!is_array($page))
|
||||
{
|
||||
$num_wildcards++;
|
||||
echo '
|
||||
<li class="page-padding"><span>...</span></li>';
|
||||
<li class="page-padding" onclick="javascript:promptGoToPage(', self::$unique_index_count, ')"><span>...</span></li>';
|
||||
}
|
||||
else
|
||||
echo '
|
||||
<li class="page-number', $page['is_selected'] ? ' active' : '', '"><a href="', $page['href'], '">', $page['index'], '</a></li>';
|
||||
}
|
||||
|
||||
echo '
|
||||
<li class="last"><', !empty($this->index['next']) ? 'a href="' . $this->index['next']['href'] . '"' : 'span', '>next »</', !empty($this->index['next']) ? 'a' : 'span', '></li>
|
||||
<li class="last"><', !empty($index['next']) ? 'a href="' . $index['next']['href'] . '"' : 'span', '>next »</', !empty($index['next']) ? 'a' : 'span', '></li>
|
||||
</ul>
|
||||
</div>';
|
||||
|
||||
if ($num_wildcards)
|
||||
{
|
||||
echo '
|
||||
<script type="text/javascript">
|
||||
var page_index_', self::$unique_index_count++, ' = {
|
||||
wildcard_url: "', $this->index->getLink("%d"), '",
|
||||
num_pages: ', $this->index->getNumberOfPages(), ',
|
||||
per_page: ', $this->index->getItemsPerPage(), '
|
||||
};
|
||||
</script>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user