162 lines
		
	
	
	
		
			5.9 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			162 lines
		
	
	
	
		
			5.9 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
| {{- $validFormats := slice "default" "terse" }}
 | |
| {{- $validAlignments := slice "begin" "center" "end" }}
 | |
| 
 | |
| {{- $msg1 := "When passing a map to the internal pagination template, one of the elements must be named 'page', and it must be set to the context of the current page." }}
 | |
| {{- $msg2 := "The 'format' specified in the map passed to the internal pagination template is invalid. Valid choices are: %s." }}
 | |
| {{- $msg3 := "The 'align' specified in the map passed to the internal pagination template is invalid. Valid choices are: %s." }}
 | |
| 
 | |
| {{- $page := . }}
 | |
| {{- $format := "default" }}
 | |
| {{- $align := "begin" }}
 | |
| 
 | |
| {{- if reflect.IsMap . }}
 | |
|   {{- with .page }}
 | |
|     {{- $page = . }}
 | |
|   {{- else }}
 | |
|     {{- errorf $msg1 }}
 | |
|   {{- end }}
 | |
|   {{- with .format }}
 | |
|     {{- $format = lower . }}
 | |
|   {{- end }}
 | |
|   {{- with .align }}
 | |
|     {{- $align = lower . }}
 | |
|   {{- end }}
 | |
| {{- end }}
 | |
| 
 | |
| {{- if not (in $validFormats $format) }}
 | |
|     {{- errorf $msg2 (delimit $validFormats ", ") }}
 | |
| {{- else if not (in $validFormats $format) }}
 | |
|     {{- errorf $msg3 (delimit $validAlignments ", ") }}
 | |
| {{- else }}
 | |
|     {{- if gt $page.Paginator.TotalPages 1 }}
 | |
|     <ul class="pagination pagination-{{ $format }}">
 | |
|       {{- partial (printf "partials/pagination/%s" $format) $page }}
 | |
|     </ul>
 | |
|   {{- end }}
 | |
| {{- end -}}
 | |
| 
 | |
| {{/* Format: default
 | |
| {{/* --------------------------------------------------------------------- */}}
 | |
| {{- define "partials/pagination/default" }}
 | |
|   {{- with .Paginator }}
 | |
|     {{- $currentPageNumber := .PageNumber }}
 | |
| 
 | |
|     {{- with .First }}
 | |
|       {{- if ne $currentPageNumber .PageNumber }}
 | |
|       <li class="page-item">
 | |
|         <a href="{{ .URL }}" aria-label="First" class="page-link" role="button"><span aria-hidden="true">««</span></a>
 | |
|       </li>
 | |
|       {{- else }}
 | |
|       <li class="page-item disabled">
 | |
|         <a aria-disabled="true" aria-label="First" class="page-link" role="button" tabindex="-1"><span aria-hidden="true">««</span></a>
 | |
|       </li>
 | |
|       {{- end }}
 | |
|     {{- end }}
 | |
| 
 | |
|     {{- with .Prev }}
 | |
|       <li class="page-item">
 | |
|         <a href="{{ .URL }}" aria-label="Previous" class="page-link" role="button"><span aria-hidden="true">«</span></a>
 | |
|       </li>
 | |
|     {{- else }}
 | |
|       <li class="page-item disabled">
 | |
|         <a aria-disabled="true" aria-label="Previous" class="page-link" role="button" tabindex="-1"><span aria-hidden="true">«</span></a>
 | |
|       </li>
 | |
|     {{- end }}
 | |
| 
 | |
|     {{- $slots := 5 }}
 | |
|     {{- $start := math.Max 1 (sub .PageNumber (math.Floor (div $slots 2))) }}
 | |
|     {{- $end := math.Min .TotalPages (sub (add $start $slots) 1) }}
 | |
|     {{- if lt (add (sub $end $start) 1) $slots }}
 | |
|       {{- $start = math.Max 1 (add (sub $end $slots) 1) }}
 | |
|     {{- end }}
 | |
| 
 | |
|     {{- range $k := seq $start $end }}
 | |
|       {{- if eq $.Paginator.PageNumber $k }}
 | |
|       <li class="page-item active">
 | |
|         <a aria-current="page" aria-label="Page {{ $k }}" class="page-link" role="button">{{ $k }}</a>
 | |
|       </li>
 | |
|       {{- else }}
 | |
|       <li class="page-item">
 | |
|         <a href="{{ (index $.Paginator.Pagers (sub $k 1)).URL }}" aria-label="Page {{ $k }}" class="page-link" role="button">{{ $k }}</a>
 | |
|       </li>
 | |
|       {{- end }}
 | |
|     {{- end }}
 | |
| 
 | |
|     {{- with .Next }}
 | |
|       <li class="page-item">
 | |
|         <a href="{{ .URL }}" aria-label="Next" class="page-link" role="button"><span aria-hidden="true">»</span></a>
 | |
|       </li>
 | |
|     {{- else }}
 | |
|       <li class="page-item disabled">
 | |
|         <a aria-disabled="true" aria-label="Next" class="page-link" role="button" tabindex="-1"><span aria-hidden="true">»</span></a>
 | |
|       </li>
 | |
|     {{- end }}
 | |
| 
 | |
|     {{- with .Last }}
 | |
|       {{- if ne $currentPageNumber .PageNumber }}
 | |
|       <li class="page-item">
 | |
|         <a href="{{ .URL }}" aria-label="Last" class="page-link" role="button"><span aria-hidden="true">»»</span></a>
 | |
|       </li>
 | |
|       {{- else }}
 | |
|       <li class="page-item disabled">
 | |
|         <a aria-disabled="true" aria-label="Last" class="page-link" role="button" tabindex="-1"><span aria-hidden="true">»»</span></a>
 | |
|       </li>
 | |
|       {{- end }}
 | |
|     {{- end }}
 | |
|   {{- end }}
 | |
| {{- end -}}
 | |
| 
 | |
| {{/* Format: terse
 | |
| {{/* --------------------------------------------------------------------- */}}
 | |
| {{- define "partials/pagination/terse" }}
 | |
|   {{- with .Paginator }}
 | |
|     {{- $currentPageNumber := .PageNumber }}
 | |
| 
 | |
|     {{- with .First }}
 | |
|       {{- if ne $currentPageNumber .PageNumber }}
 | |
|       <li class="page-item">
 | |
|         <a href="{{ .URL }}" aria-label="First" class="page-link" role="button"><span aria-hidden="true">««</span></a>
 | |
|       </li>
 | |
|       {{- end }}
 | |
|     {{- end }}
 | |
| 
 | |
|     {{- with .Prev }}
 | |
|       <li class="page-item">
 | |
|         <a href="{{ .URL }}" aria-label="Previous" class="page-link" role="button"><span aria-hidden="true">«</span></a>
 | |
|       </li>
 | |
|     {{- end }}
 | |
| 
 | |
|     {{- $slots := 3 }}
 | |
|     {{- $start := math.Max 1 (sub .PageNumber (math.Floor (div $slots 2))) }}
 | |
|     {{- $end := math.Min .TotalPages (sub (add $start $slots) 1) }}
 | |
|     {{- if lt (add (sub $end $start) 1) $slots }}
 | |
|       {{- $start = math.Max 1 (add (sub $end $slots) 1) }}
 | |
|     {{- end }}
 | |
| 
 | |
|     {{- range $k := seq $start $end }}
 | |
|       {{- if eq $.Paginator.PageNumber $k }}
 | |
|       <li class="page-item active">
 | |
|         <a aria-current="page" aria-label="Page {{ $k }}" class="page-link" role="button">{{ $k }}</a>
 | |
|       </li>
 | |
|       {{- else }}
 | |
|       <li class="page-item">
 | |
|         <a href="{{ (index $.Paginator.Pagers (sub $k 1)).URL }}" aria-label="Page {{ $k }}" class="page-link" role="button">{{ $k }}</a>
 | |
|       </li>
 | |
|       {{- end }}
 | |
|     {{- end }}
 | |
| 
 | |
|     {{- with .Next }}
 | |
|       <li class="page-item">
 | |
|         <a href="{{ .URL }}" aria-label="Next" class="page-link" role="button"><span aria-hidden="true">»</span></a>
 | |
|       </li>
 | |
|     {{- end }}
 | |
| 
 | |
|     {{- with .Last }}
 | |
|       {{- if ne $currentPageNumber .PageNumber }}
 | |
|       <li class="page-item">
 | |
|         <a href="{{ .URL }}" aria-label="Last" class="page-link" role="button"><span aria-hidden="true">»»</span></a>
 | |
|       </li>
 | |
|       {{- end }}
 | |
|     {{- end }}
 | |
|   {{- end }}
 | |
| {{- end -}}
 | 
