Only show pagination if it is needed

This commit is contained in:
Aaron Fischer 2017-05-11 21:45:45 +02:00
parent c663ef6d2a
commit b5cbd71b68

View file

@ -27,27 +27,31 @@
(for [p (range from (inc to))] (page p (= p current) "active" p)))
(defn pagination [num current]
(h/html
[:nav.pull-right.clearfix {:aria-label "Page navigation"}
[:ul.pagination.hidden-sm-down
(page (dec current) (= current 1) "disabled" (h/html [:span.fa.fa-arrow-left] " Zurück"))
(cond
(< num 13) (pagelist 1 num current)
(<= current 7) (h/html (pagelist 1 10 current) (dots) (pagelist (- num 1) num current))
(>= current (- num 6)) (h/html (pagelist 1 2 current) (dots) (pagelist (- num 9) num current))
:else (h/html (pagelist 1 2 current) (dots) (pagelist (- current 3) (+ current 3) current) (dots) (pagelist (- num 1) num current)))
(page (inc current) (= current num) "disabled" (h/html "Weiter " [:span.fa.fa-arrow-right]))]]
[:div.clearfix]))
(if (< num 2)
""
(h/html
[:nav.pull-right.clearfix {:aria-label "Page navigation"}
[:ul.pagination.hidden-sm-down
(page (dec current) (= current 1) "disabled" (h/html [:span.fa.fa-arrow-left] " Zurück"))
(cond
(< num 13) (pagelist 1 num current)
(<= current 7) (h/html (pagelist 1 10 current) (dots) (pagelist (- num 1) num current))
(>= current (- num 6)) (h/html (pagelist 1 2 current) (dots) (pagelist (- num 9) num current))
:else (h/html (pagelist 1 2 current) (dots) (pagelist (- current 3) (+ current 3) current) (dots) (pagelist (- num 1) num current)))
(page (inc current) (= current num) "disabled" (h/html "Weiter " [:span.fa.fa-arrow-right]))]]
[:div.clearfix])))
(defn pagination-mobile [num current]
(h/html
[:ul.pagination.justify-content-end.hidden-md-up
(page (dec current) (= current 1) "disabled" (h/html [:span.fa.fa-arrow-left] " Zurück"))
[:form.form-inline
[:select#page-switcher.form-control
(for [p (range 1 (inc num))]
[:option (cond-> {:value p} (= p current) (assoc :selected "selected")) p])]]
(page (inc current) (= current num) "disabled" (h/html "Weiter " [:span.fa.fa-arrow-right]))]))
(if (< num 2)
""
(h/html
[:ul.pagination.justify-content-end.hidden-md-up
(page (dec current) (= current 1) "disabled" (h/html [:span.fa.fa-arrow-left] " Zurück"))
[:form.form-inline
[:select#page-switcher.form-control
(for [p (range 1 (inc num))]
[:option (cond-> {:value p} (= p current) (assoc :selected "selected")) p])]]
(page (inc current) (= current num) "disabled" (h/html "Weiter " [:span.fa.fa-arrow-right]))])))
(defn index-page [current request]
(let [image-count 25