aboutsummaryrefslogtreecommitdiff
path: root/views/default
diff options
context:
space:
mode:
Diffstat (limited to 'views/default')
-rw-r--r--views/default/css/screen.php87
-rw-r--r--views/default/navigation/pagination.php151
2 files changed, 100 insertions, 138 deletions
diff --git a/views/default/css/screen.php b/views/default/css/screen.php
index 6092aa5aa..1e9c41391 100644
--- a/views/default/css/screen.php
+++ b/views/default/css/screen.php
@@ -796,82 +796,37 @@ li.navigation-more ul li {
/* ***************************************
PAGINATION
*************************************** */
-.pagination {
- margin:5px 0 5px 0;
- padding:5px 0;
-}
-.pagination .pagination-number {
- display:block;
- float:left;
- background:#ffffff;
- border:1px solid #4690d6;
+.elgg-pagination {
+ margin: 10px 0;
+ display: block;
text-align: center;
- color:#4690d6;
- font-size: 12px;
- font-weight: normal;
- margin:0 6px 0 0;
- padding:0px 4px;
- cursor: pointer;
- -webkit-border-radius: 4px;
- -moz-border-radius: 4px;
}
-.pagination .pagination-number:hover {
- background:#4690d6;
- color:white;
- text-decoration: none;
-}
-.pagination .pagination-more {
- display:block;
- float:left;
- background:#ffffff;
- border:1px solid #ffffff;
+.elgg-pagination li {
+ display: inline;
+ margin: 0 6px 0 0;
text-align: center;
- color:#4690d6;
- font-size: 12px;
- font-weight: normal;
- margin:0 6px 0 0;
- padding:0px 4px;
- -webkit-border-radius: 4px;
- -moz-border-radius: 4px;
}
-.pagination .pagination-previous,
-.pagination .pagination-next {
- display:block;
- float:left;
- border:1px solid #cccccc;
- color:#4690d6;
- text-align: center;
- font-size: 12px;
- font-weight: normal;
- margin:0 6px 0 0;
- padding:0px 4px;
- cursor: pointer;
+.elgg-pagination a, .elgg-pagination span {
+ padding: 2px 6px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
+ color: #4690d6;
+ border: 1px solid #4690d6;
+ font-size: 12px;
}
-.pagination .pagination-previous:hover,
-.pagination .pagination-next:hover {
- background:#4690d6;
- border:1px solid #4690d6;
- color:white;
+.elgg-pagination a:hover {
+ background: #4690d6;
+ color: white;
text-decoration: none;
}
-.pagination .pagination-currentpage {
- display:block;
- float:left;
- background:#4690d6;
- border:1px solid #4690d6;
- text-align: center;
- color:white;
- font-size: 12px;
- font-weight: bold;
- margin:0 6px 0 0;
- padding:0px 4px;
- cursor: pointer;
- -webkit-border-radius: 4px;
- -moz-border-radius: 4px;
+.elgg-pagination .inactive {
+ color: #CCCCCC;
+ border-color: #CCCCCC;
+}
+.elgg-pagination .active {
+ color: #555555;
+ border-color: #555555;
}
-
/* ***************************************
ELGG TABBED PAGE NAVIGATION
diff --git a/views/default/navigation/pagination.php b/views/default/navigation/pagination.php
index fc15470bc..9fcd8153e 100644
--- a/views/default/navigation/pagination.php
+++ b/views/default/navigation/pagination.php
@@ -12,99 +12,106 @@
* @uses string $vars['baseurl'] Base URL to use in links
*/
-$offset = (int) elgg_get_array_value('offset', $vars, 0);
+if (elgg_in_context('widget')) {
+ // widgets do not show pagination
+ return true;
+}
+
+$offset = abs((int) elgg_get_array_value('offset', $vars, 0));
// because you can say $vars['limit'] = 0
if (!$limit = (int) elgg_get_array_value('limit', $vars, 10)) {
$limit = 10;
}
+
$count = (int) elgg_get_array_value('count', $vars, 0);
$word = elgg_get_array_value('word', $vars, 'offset');
-$baseurl = elgg_get_array_value('baseurl', $vars, current_page_url());
+$base_url = elgg_get_array_value('baseurl', $vars, current_page_url());
+
+$num_pages = elgg_get_array_value('num_pages', $vars, 10);
+$delta = ceil($num_pages / 2);
-$totalpages = ceil($count / $limit);
-$currentpage = ceil($offset / $limit) + 1;
+if ($count <= $limit && $offset == 0) {
+ // no need for pagination
+ return true;
+}
-//only display if there is content to paginate through or if we already have an offset
-if (($count > $limit || $offset > 0) && elgg_get_context() != 'widget') {
+$total_pages = ceil($count / $limit);
+$current_page = ceil($offset / $limit) + 1;
+
+$pages = new stdClass();
+$pages->prev = array(
+ 'text' => '&laquo; ' . elgg_echo('previous'),
+ 'href' => '',
+);
+$pages->next = array(
+ 'text' => elgg_echo('next') . ' &raquo;',
+ 'href' => '',
+);
+$pages->items = array();
+
+// Add pages before the current page
+if ($current_page > 1) {
+ $prev_offset = $offset - $limit;
+ if ($prev_offset < 0) {
+ $prev_offset = 0;
+ }
- ?>
+ $pages->prev['href'] = elgg_http_add_url_query_elements($base_url, array($word => $prev_offset));
- <div class="pagination clearfix">
- <?php
+ $first_page = $current_page - $delta;
+ if ($first_page < 1) {
+ $first_page = 1;
+ }
- if ($offset > 0) {
+ $pages->items = range($first_page, $current_page - 1);
+}
- $prevoffset = $offset - $limit;
- if ($prevoffset < 0) {
- $prevoffset = 0;
- }
- $prevurl = elgg_http_add_url_query_elements($baseurl, array($word => $prevoffset));
+$pages->items[] = $current_page;
- echo "<a href=\"{$prevurl}\" class='pagination-previous'>&laquo; ". elgg_echo("previous") ."</a> ";
+
+// add pages after the current one
+if ($current_page < $total_pages) {
+ $next_offset = $offset + $limit;
+ if ($next_offset >= $count) {
+ $next_offset--;
}
- if ($offset > 0 || $offset < ($count - $limit)) {
-
- $currentpage = round($offset / $limit) + 1;
- $allpages = ceil($count / $limit);
-
- $i = 1;
- $pagesarray = array();
- while ($i <= $allpages && $i <= 4) {
- $pagesarray[] = $i;
- $i++;
- }
- $i = $currentpage - 2;
- while ($i <= $allpages && $i <= ($currentpage + 2)) {
- if ($i > 0 && !in_array($i,$pagesarray)) {
- $pagesarray[] = $i;
- }
- $i++;
- }
- $i = $allpages - 3;
- while ($i <= $allpages) {
- if ($i > 0 && !in_array($i,$pagesarray)) {
- $pagesarray[] = $i;
- }
- $i++;
- }
-
- sort($pagesarray);
-
- $prev = 0;
- foreach($pagesarray as $i) {
- if (($i - $prev) > 1) {
- echo "<span class='pagination-more'>...</span>";
- }
-
- $curoffset = (($i - 1) * $limit);
- $counturl = elgg_http_add_url_query_elements($baseurl, array($word => $curoffset));
-
- if ($curoffset != $offset) {
- echo " <a href=\"{$counturl}\" class='pagination-number'>{$i}</a> ";
- } else {
- echo "<span class='pagination-currentpage'>{$i}</span>";
- }
- $prev = $i;
-
- }
+ $pages->next['href'] = elgg_http_add_url_query_elements($base_url, array($word => $next_offset));
+
+ $last_page = $current_page + $delta;
+ if ($last_page > $total_pages) {
+ $last_page = $total_pages;
}
- if ($offset < ($count - $limit)) {
+ $pages->items = array_merge($pages->items, range($current_page + 1, $last_page));
+}
- $nextoffset = $offset + $limit;
- if ($nextoffset >= $count) {
- $nextoffset--;
- }
- $nexturl = elgg_http_add_url_query_elements($baseurl, array($word => $nextoffset));
+echo '<ul class="elgg-pagination">';
- echo " <a href=\"{$nexturl}\" class='pagination-next'>" . elgg_echo("next") . " &raquo;</a>";
+if ($pages->prev['href']) {
+ $link = elgg_view('output/url', $pages->prev);
+ echo "<li>$link</li>";
+} else {
+ echo "<li><span class=\"inactive\">{$pages->prev['text']}</span></li>";
+}
+foreach ($pages->items as $page) {
+ if ($page == $current_page) {
+ echo "<li><span class=\"active\">$page</span></li>";
+ } else {
+ $page_offset = (($page - 1) * $limit);
+ $url = elgg_http_add_url_query_elements($base_url, array($word => $page_offset));
+ echo "<li><a href=\"$url\">$page</a></li>";
}
+}
+
+if ($pages->next['href']) {
+ $link = elgg_view('output/url', $pages->next);
+ echo "<li>$link</li>";
+} else {
+ echo "<li><span class=\"inactive\">{$pages->next['text']}</span></li>";
+}
- ?>
- </div>
- <?php
-} // end of pagination check if statement
+echo '</ul>';