Revision 6c0aa046
Von Sven Schöling vor etwa 13 Jahren hinzugefügt
SL/DB/Helper/Paginated.pm | ||
---|---|---|
6 | 6 |
our @ISA = qw(Exporter); |
7 | 7 |
our @EXPORT = qw(paginate); |
8 | 8 |
|
9 |
use List::MoreUtils qw(any); |
|
10 |
|
|
9 | 11 |
sub paginate { |
10 | 12 |
my ($self, %params) = @_; |
11 | 13 |
my $page = $params{page} || 1; |
... | ... | |
47 | 49 |
my ($cur, $max) = @_; |
48 | 50 |
return [ |
49 | 51 |
map { |
50 |
active => $_ != $cur, |
|
51 |
page => $_, |
|
52 |
active => $_ != $cur, |
|
53 |
page => $_, |
|
54 |
visible => |
|
52 | 55 |
}, 1 .. $max |
53 | 56 |
]; |
54 | 57 |
} |
55 | 58 |
|
59 |
sub calc_visibility { |
|
60 |
my ($cur, $max, $this) = @_; |
|
61 |
any { $_ } abs($cur - $this) < 5, |
|
62 |
$cur <= 3, |
|
63 |
$cur == $max, |
|
64 |
any { ! abs ($cur - $this) % $_ } 10, 50, 100, 500, 1000, 5000; |
|
65 |
} |
|
66 |
|
|
56 | 67 |
1; |
57 | 68 |
|
58 | 69 |
__END__ |
templates/webpages/common/paginate.html | ||
---|---|---|
1 | 1 |
[%- IF pages.max > 1 %] |
2 |
[%- IF pages.cur > 1 %]<a href='[% base_url _ "&page=" _ (pages.cur - 1) %]'>«</a> [%- END %]
|
|
2 |
[%- IF pages.cur > 1 %]<a href='[% base_url _ "&page=" _ (pages.cur - 1) %]'>«</a> [% ELSE %]<b>«</b> [% END %]
|
|
3 | 3 |
[%- FOR p = pages.common %] |
4 |
[%- IF p.active %]<a href="[% base_url _ "&page=" _ p.page %]">[% p.page %]</a> |
|
5 |
[%- ELSE %]<b>[% p.page %]</b> |
|
6 |
[%- END %] |
|
7 |
[%- ' ' UNLESS loop.last %] |
|
4 |
[%- NEXT UNLESS p.visible %] |
|
5 |
[%- IF p.active %]<a href="[% base_url _ "&page=" _ p.page %]">[% p.page %]</a> [% ELSE %]<b>[% p.page %]</b> [%- END %] |
|
8 | 6 |
[%- END %] |
9 |
[%- IF pages.cur < pages.max %] <a href='[% base_url _ "&page=" _ (pages.cur + 1) %]'>»</a>[%- END %]
|
|
7 |
[%- IF pages.cur < pages.max %]<a href='[% base_url _ "&page=" _ (pages.cur + 1) %]'>»</a>[% ELSE %]<b>»</b>[%- END %]
|
|
10 | 8 |
[%- END %] |
Auch abrufbar als: Unified diff
Paginating Sanity:
Nur Seiten anzeigen die...
- Erste oder letzte Seite sind
- In der Nähe der aktuellen Seite (+
3)
10,50,100,500,1000,5000 Seiten von der aktuellen entfernt sind