<commit_before>VoteButton = require './VoteButton.coffee'

init = (el)->
  $feeds = $(el)
  $btnReload = $('#btn-reload-feeds')
  $tipLoading = $('#feeds-loading-tip')
  $tipLoaded = $('#feeds-loaded-tip')
  pages = parseInt $feeds.data('pages')
  loading = false
  page = 1

  load = ()->
    loading = true
    $.ajax
      data:
        page: page
        target: el
      success: (html)->
        $tipLoading.before html
        VoteButton.init el
        if page >= pages
          $tipLoading.hide()
          $tipLoaded.show()
        else
          $tipLoaded.hide()
        setTimeout ()->
          loading = false
        , 1000
      error: (res)->
        $tipLoading.addClass 'has-error'

  checkLoad = ()->
    $last = $feeds.find('.feed').last()
    scrollTop = $(window).scrollTop() + $(window).height()
    if scrollTop < $last.offset().top - $last.height() * 2
      return
    if loading or page >= pages
      return
    page += 1
    load()

  if isNaN pages
    return console.error 'invalid data-pages attribute'
  VoteButton.init el
  $(window).on 'scroll', checkLoad
  $btnReload.on 'click', ()->
    $tipLoading.removeClass 'has-error'
    load()
  checkLoad()

module.exports = init: init
<commit_msg>Update feed list load check<commit_after>VoteButton = require './VoteButton.coffee'

init = (el)->
  $feeds = $(el)
  $btnReload = $('#btn-reload-feeds')
  $tipLoading = $('#feeds-loading-tip')
  $tipLoaded = $('#feeds-loaded-tip')
  pages = parseInt $feeds.data('pages')
  loading = false
  page = 1

  load = ()->
    loading = true
    $.ajax
      data:
        page: page
        target: el
      success: (html)->
        $tipLoading.before html
        VoteButton.init el
        if page >= pages
          $tipLoading.hide()
          $tipLoaded.show()
        else
          $tipLoaded.hide()
        setTimeout ()->
          loading = false
        , 500
      error: (res)->
        $tipLoading.addClass 'has-error'

  checkLoad = ()->
    $last = $feeds.find('.feed').last()
    scrollTop = $(window).scrollTop() + $(window).height()
    if scrollTop < $last.offset().top - $last.height()
      return
    if loading or page >= pages
      return
    page += 1
    load()

  if isNaN pages
    return console.error 'invalid data-pages attribute'
  VoteButton.init el
  $(window).on 'scroll', checkLoad
  $btnReload.on 'click', ()->
    $tipLoading.removeClass 'has-error'
    load()
  checkLoad()

module.exports = init: init

{'fraction_non_alphanumeric': 0.15269339813689753, 'fraction_numerical': 0.004860267314702308, 'mean_word_length': 2.2203389830508473, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2134273', 'n_tokens_mistral': 793, 'n_tokens_neox': 778, 'n_words': 189}