<commit_before>window.observableCount = 0

textVal = (elem, val) ->
  "Takes a jquery element and gets or sets either val() or text(), depending on what's appropriate for this element type (ie input vs button vs a, etc)"
  if elem.is("input")
    if val? then elem.val val else elem.val()
  else # button or a
    if val? then elem.text(val) else elem.text()

finishAjax = (event, attrName, buttonName) ->
  if event
    t = $(event.target)
    done = t.attr(attrName) or buttonName
    textVal t, done

    func = () =>
      textVal t, event.savedText
      t.removeClass "disabled"
    setTimeout(func, 1500)

$(document).ajaxSuccess((ev, xhr, options) -> finishAjax(xhr.event, "data-success-text", "Saved"))

$(document).ajaxError((ev, xhr, status, errorThrown) ->
  finishAjax(xhr.event, "data-failed-text", "Failed")

  if xhr.responseText.indexOf("<!DOCTYPE") is 0
    notifyError "An unknown error occurred: (#{xhr.status} - #{xhr.statusText})."
  else
    notifyError (xhr.responseText or xhr.statusText)
)

ko.observableArray["fn"].setIndex = (index, newItem) ->
  @valueWillMutate()
  @()[index] = newItem
  @valueHasMutated()

$(document).ajaxSend((ev, xhr, options) ->

  xhr.event = options.event<commit_msg>Make setIndex return the underlying array's return value correctly<commit_after>window.observableCount = 0

textVal = (elem, val) ->
  "Takes a jquery element and gets or sets either val() or text(), depending on what's appropriate for this element type (ie input vs button vs a, etc)"
  if elem.is("input")
    if val? then elem.val val else elem.val()
  else # button or a
    if val? then elem.text(val) else elem.text()

finishAjax = (event, attrName, buttonName) ->
  if event
    t = $(event.target)
    done = t.attr(attrName) or buttonName
    textVal t, done

    func = () =>
      textVal t, event.savedText
      t.removeClass "disabled"
    setTimeout(func, 1500)

$(document).ajaxSuccess((ev, xhr, options) -> finishAjax(xhr.event, "data-success-text", "Saved"))

$(document).ajaxError((ev, xhr, status, errorThrown) ->
  finishAjax(xhr.event, "data-failed-text", "Failed")

  if xhr.responseText.indexOf("<!DOCTYPE") is 0
    notifyError "An unknown error occurred: (#{xhr.status} - #{xhr.statusText})."
  else
    notifyError (xhr.responseText or xhr.statusText)
)

ko.observableArray["fn"].setIndex = (index, newItem) ->
  @valueWillMutate()
  result = @()[index] = newItem
  @valueHasMutated()
  result

$(document).ajaxSend((ev, xhr, options) ->

  xhr.event = options.event
{'fraction_non_alphanumeric': 0.14552683896620278, 'fraction_numerical': 0.004771371769383698, 'mean_word_length': 3.894941634241245, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '1404904', 'n_tokens_mistral': 853, 'n_tokens_neox': 829, 'n_words': 239}