Sha256: 120ebb45fa4917c9da01c006152d9a4144ba88605a52d5be02da243aaace2aa9

Contents?: true

Size: 1.93 KB

Versions: 1

Compression:

Stored size: 1.93 KB

Contents

# -----------------------------------------------------------------------------
# LIST PAGINATION
# -----------------------------------------------------------------------------

@listPagination =
  # PRIVATE ===============================================

  _bind_pagination: ->
    if chr.isMobile()
      chr._bind_mobile_scroll()

    else
      @_bind_desktop_scroll()


  _bind_desktop_scroll: ->
    @lastScrollTop = 0
    $viewport      = @$el

    @$items.scroll (e) =>
      scroll_top = @$items.scrollTop()

      # trigger next page loading only when scrolling to bottom
      if @lastScrollTop < scroll_top
        chr._load_next_page($viewport, this, scroll_top)

      @lastScrollTop = scroll_top


chr._bind_mobile_scroll = ->
  if ! @_mobile_scroll_binded
    @lastScrollTop = 0
    $viewport      = $(window)

    $viewport.scroll (e) =>
      if ! @module then return

      if @module.view then return

      scroll_top = $viewport.scrollTop()
      @module.activeList.scrollCache = scroll_top

      # TODO: updated this for iphone (test with no mouse on safari),
      # scenario: list is loaded and do not fill the page size

      # trigger next page loading only when scrolling to bottom
      if @lastScrollTop < scroll_top
        chr._load_next_page($viewport, @module.activeList, scroll_top)

      @lastScrollTop = scroll_top

    @_mobile_scroll_binded = true


chr._load_next_page = ($viewport, list, scroll_top) ->
  $items = list.$items
  store  = list.config.arrayStore

  if store.dataFetchLock then return

  if store.lastPageLoaded then return

  # check if scroll is near bottom of the $viewport
  viewport_height   = $viewport.height()
  list_items_height = 0
  $items.children().each -> list_items_height += $(this).height()

  if list_items_height - scroll_top - 100 > viewport_height
    return

  list.showSpinner()
  store.load false,
    onSuccess: => ;
    onError:   => chr.showAlert("Can't load next page, server error 500.")




Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chr-0.3.5 app/assets/javascripts/chr/core/list_pagination.coffee