tmplimpl: Add support for ellipsed paginator

Fixes #3466
This commit is contained in:
Bjørn Erik Pedersen 2017-05-16 10:53:40 +03:00
parent 6e2f2dd8d3
commit b6ea492b7a

View file

@ -123,32 +123,47 @@ func (t *templateHandler) embedTemplates() {
`) `)
t.addInternalTemplate("", "pagination.html", `{{ $pag := $.Paginator }} t.addInternalTemplate("", "pagination.html", `{{ $pag := $.Paginator }}
{{ if gt $pag.TotalPages 1 }} {{ if gt $pag.TotalPages 1 }}
<ul class="pagination"> <ul class="pagination">
{{ with $pag.First }} {{ with $pag.First }}
<li> <li>
<a href="{{ .URL }}" aria-label="First"><span aria-hidden="true">&laquo;&laquo;</span></a> <a href="{{ .URL }}" aria-label="First"><span aria-hidden="true">&laquo;&laquo;</span></a>
</li> </li>
{{ end }} {{ end }}
<li <li
{{ if not $pag.HasPrev }}class="disabled"{{ end }}> {{ if not $pag.HasPrev }}class="disabled"{{ end }}>
<a href="{{ if $pag.HasPrev }}{{ $pag.Prev.URL }}{{ end }}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a> <a href="{{ if $pag.HasPrev }}{{ $pag.Prev.URL }}{{ end }}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a>
</li> </li>
{{ range $pag.Pagers }} {{ $.Scratch.Set "__paginator.ellipsed" false }}
<li {{ range $pag.Pagers }}
{{ if eq . $pag }}class="active"{{ end }}><a href="{{ .URL }}">{{ .PageNumber }}</a></li> {{ $right := sub .TotalPages .PageNumber }}
{{ end }} {{ $showNumber := or (le .PageNumber 3) (eq $right 0) }}
<li {{ $showNumber := or $showNumber (and (gt .PageNumber (sub $pag.PageNumber 2)) (lt .PageNumber (add $pag.PageNumber 2))) }}
{{ if not $pag.HasNext }}class="disabled"{{ end }}> {{ if $showNumber }}
<a href="{{ if $pag.HasNext }}{{ $pag.Next.URL }}{{ end }}" aria-label="Next"><span aria-hidden="true">&raquo;</span></a> {{ $.Scratch.Set "__paginator.ellipsed" false }}
</li> {{ $.Scratch.Set "__paginator.shouldEllipse" false }}
{{ with $pag.Last }} {{ else }}
<li> {{ $.Scratch.Set "__paginator.shouldEllipse" (not ($.Scratch.Get "__paginator.ellipsed") ) }}
<a href="{{ .URL }}" aria-label="Last"><span aria-hidden="true">&raquo;&raquo;</span></a> {{ $.Scratch.Set "__paginator.ellipsed" true }}
</li> {{ end }}
{{ end }} {{ if $showNumber }}
</ul> <li
{{ end }}`) {{ if eq . $pag }}class="active"{{ end }}><a href="{{ .URL }}">{{ .PageNumber }}</a></li>
{{ else if ($.Scratch.Get "__paginator.shouldEllipse") }}
<li class="disabled"><span aria-hidden="true">&hellip;</span></li>
{{ end }}
{{ end }}
<li
{{ if not $pag.HasNext }}class="disabled"{{ end }}>
<a href="{{ if $pag.HasNext }}{{ $pag.Next.URL }}{{ end }}" aria-label="Next"><span aria-hidden="true">&raquo;</span></a>
</li>
{{ with $pag.Last }}
<li>
<a href="{{ .URL }}" aria-label="Last"><span aria-hidden="true">&raquo;&raquo;</span></a>
</li>
{{ end }}
</ul>
{{ end }}`)
t.addInternalTemplate("", "disqus.html", `{{ if .Site.DisqusShortname }}<div id="disqus_thread"></div> t.addInternalTemplate("", "disqus.html", `{{ if .Site.DisqusShortname }}<div id="disqus_thread"></div>
<script type="text/javascript"> <script type="text/javascript">