summaryrefslogtreecommitdiffstats
path: root/web/js/labitrack.d/39-pagination.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'web/js/labitrack.d/39-pagination.coffee')
-rw-r--r--web/js/labitrack.d/39-pagination.coffee50
1 files changed, 29 insertions, 21 deletions
diff --git a/web/js/labitrack.d/39-pagination.coffee b/web/js/labitrack.d/39-pagination.coffee
index ca50b9b..98311f5 100644
--- a/web/js/labitrack.d/39-pagination.coffee
+++ b/web/js/labitrack.d/39-pagination.coffee
@@ -1,43 +1,51 @@
λ.pagination = (->
- link = (pg) -> '/browse' + (if pg > 1 then '/page/' + pg else '')
class pgs
- constructor: -> @pages = []
+ constructor: (@prefix, @pg, @cnt) -> @pages = []
+ link: (pg) -> @prefix + (if pg > 1 then '/page/' + pg else '')
dots: -> @pages.push { id: 'dots', label: '…', classes: 'disabled' }
page: (pgno) -> @pages.push {
id: pgno
- link: link pgno
+ link: @link pgno
label: pgno
}
first: -> @pages.push {
id: 'first'
- link: link 1
+ link: @link 1
label: '|←'
classes: 'prev'
}
- prev: (pg) -> @pages.push {
- id: 'prev'
- link: link pg
- label: '←'
- }
- next: (pg) -> @pages.push {
- id: 'next'
- link: link pg
- label: '→'
- }
+ prev: (pg) ->
+ i =
+ id: 'prev'
+ link: @link pg
+ label: '←'
+ if @pg is 1
+ i.link = undefined
+ i.classes = 'disabled'
+ @pages.push i
+ next: (pg) ->
+ i =
+ id: 'next'
+ link: @link pg
+ label: '→'
+ if @pg is @cnt
+ i.link = undefined
+ i.classes = 'disabled'
+ @pages.push i
last: (pg) -> @pages.push {
id: 'last'
- link: link pg
+ link: @link pg
label: '→|'
classes: 'next'
}
- return (page, cnt) ->
- p = new pgs
- first = page != 1
- prev = page > 2
- next = page + 1 < cnt
- last = page < cnt
+ return (prefix, page, cnt) ->
+ p = new pgs prefix, page, cnt
+ first = page != 1 and cnt >= 10
+ prev = page > 2 or cnt < 10
+ next = page + 1 < cnt or cnt < 10
+ last = page < cnt and cnt >= 10
slots = 11
left = right = Math.floor(slots / 2)