aboutsummaryrefslogtreecommitdiff
path: root/templates/macros
diff options
context:
space:
mode:
Diffstat (limited to 'templates/macros')
-rw-r--r--templates/macros/macros.html53
1 files changed, 41 insertions, 12 deletions
diff --git a/templates/macros/macros.html b/templates/macros/macros.html
index 454854a..e4fcf73 100644
--- a/templates/macros/macros.html
+++ b/templates/macros/macros.html
@@ -23,21 +23,50 @@
{%- macro pagination(paginator)%}
{%- if paginator.number_pagers > 1 %}
+ {%- if paginator.number_pagers <= 5 %} {# 5 or less pager is simple, just display all 5 #}
+ {%- set start = 1 %}
+ {%- set end = paginator.number_pagers %}
+ {%- endif %}
+
+ {%- if paginator.number_pagers > 5 %}
+
+ {%- if paginator.current_index >= 3 %} {# Check if the first number will be 1 or not #}
+ {%- set start = paginator.current_index - 2 %} {# Set the start number #}
+ {%- if paginator.number_pagers - paginator.current_index < 2 %} {# the last two pages your no longer centered with equal pages start and end #}
+ {%- set difference = paginator.number_pagers - paginator.current_index %}
+ {%- set compensation = 1 - difference %}
+ {%- set start = paginator.current_index - 3 - compensation %} {# however many pages are missing on the end, add offset to start #}
+ {%- endif %}
+ {%- else %}
+ {%- set start = 1 %}
+ {%- endif %}
+
+ {%- if paginator.number_pagers >= paginator.current_index + 2 %} {# Check if the last page is beyond our range #}
+ {%- set end = paginator.current_index + 2 %} {# End is beyond our range so we can safely set it to our range #}
+ {%- if paginator.current_index <= 3 %} {# check offset start, if on page 1 or 2 then set the end to page 5 #}
+ {%- set end = 5 %}
+ {%- endif %}
+ {%- else %}
+ {%- set end = paginator.number_pagers %}
+ {%- endif %}
+ {%- endif %}
<nav>
<ul>
- {%- if paginator.previous %}<li><a href="{{ paginator.previous | safe }}">&#60; Previous</a></li>{% endif %}
- {%- for i in range(start=1, end=paginator.number_pagers+1) %}
- <li>
- {%- if i == paginator.current_index %}
- <a class="cnav" href="#">{{i}}</a>
- {%- elif i > 1 %}
- <a href="{{paginator.base_url | safe }}{{i ~ '/'}}">{{i}}</a>
- {%- else %}
- <a href="{{paginator.first | safe }}">{{i}}</a>
- {%- endif %}
- </li>
+ {%- if paginator.previous %}<li><a href="{{ paginator.first | safe }}">&#124; &#60;</a></li>{% else %}<li><span class="off">&#124; &#60;</span></li>{% endif %}
+ {%- if paginator.previous %}<li><a href="{{ paginator.previous | safe }}">&#60;</a></li>{% else %}<li><span class="off">&#60;</span></li>{% endif %}
+ {%- for i in range(start=start, end=end+1) %}
+ <li>
+ {%- if i == paginator.current_index %}
+ <a class="cnav" href="#">{{i}}</a>
+ {%- elif i > 1 %}
+ <a href="{{ paginator.base_url | safe }}{{ i ~ '/' }}">{{i}}</a>
+ {%- else %}
+ <a href="{{ paginator.first | safe }}">{{ i }}</a>
+ {%- endif %}
+ </li>
{%- endfor %}
- {%- if paginator.next %}<li><a href="{{ paginator.next | safe }}">Next &#62;</a></li>{% endif %}
+ {%- if paginator.next %}<li><a href="{{ paginator.next | safe }}">&#62;</a></li>{% else %}<li><span class="off">&#62;</span></li>{% endif %}
+ {%- if paginator.next %}<li><a href="{{ paginator.last | safe }}">&#62; &#124;</a></li>{% else %}<li><span class="off">&#62; &#124;</span></li>{% endif %}
</ul>
</nav>
{%- endif %}