Sha256: 6d69de630a1998659684aae3cc6088ed78725e9303c1dcd86f924539b7ada711

Contents?: true

Size: 1.28 KB

Versions: 39

Compression:

Stored size: 1.28 KB

Contents

class IuguUI.Paginator extends IuguUI.Base

  layout: "iugu-ui-paginator"

  defaults:
    numberOfPageButtons: 9
    enableAdditionalButtons: true

  events:
    'click a.page': 'gotoPage'
    'click a.next': ->
      @handleEvent 'next'
      false
    'click a.previous': ->
      @handleEvent 'previous'
      false

  initialize: ->
    super

  context: ->
    currentPage: 1
    firstPage: 1
    lastPage: 1
    enableAdditionalButtons: @options.enableAdditionalButtons
    pageButtons: @pageButtonsToShow(10, 1, 10, 1)

  currentPage: 1

  gotoPage: (e) ->
    e.preventDefault()
    return if $(e.target).text() == '...'
    @currentPage = $(e.target).text()
    @handleEvent 'change-page'

  pageButtonsToShow: (numberOfButtons, firstPage, totalPages, currentPage) ->
    return unless totalPages

    if numberOfButtons > totalPages
      return _.range(2, totalPages)

    surrounding = (numberOfButtons - 3) / 2

    begin = currentPage - Math.floor(surrounding)
    end = currentPage + Math.ceil(surrounding)

    if begin <= firstPage + 1
      offset = firstPage + 1 - begin
      begin += offset
      end += offset
    else if end >= totalPages - 1
      offset = totalPages - end - 1
      begin += offset
      end += offset

    _.range(begin, end + 1)

@IuguUI.Paginator = IuguUI.Paginator

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
iugu-ux-1.0.25 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.24 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.23 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.22 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.21 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.20 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.19 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.18 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.17 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.16 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.15 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.14 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.13 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.12 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.11 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.10 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.9 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.8 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.7 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee
iugu-ux-1.0.6 vendor/assets/javascripts/iugu-ux/components/usecode/iugu-ui-paginator.js.coffee