From 802a86a276784601e0a952611bfcfb823831608f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Fri, 10 Aug 2012 21:14:52 +0000 Subject: implement search support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Asbjørn Sloth Tønnesen --- web/js/labitrack.d/39-pagination.coffee | 50 +++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'web/js/labitrack.d/39-pagination.coffee') 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) -- cgit v1.2.1