<commit_before>MAX_LENGTH = 140

jQuery $ ->

  # Turn on JS styles
  $("html").removeClass("no-js").addClass("js")

  # Hide flash messages
  $("#flash .notice").delay(4000).slideUp('slow')

  # Replace images that 404 with the default avatar
  replaceBrokenImages = ->
    $("img").error ->
      $(this).attr("src", "<%= asset_path RstatUs::DEFAULT_AVATAR %>")

  replaceBrokenImages()

  # Use the timeago plugin to convert an update's time to time ago format
  # and update it once a minute
  convertToTimeAgo = ->
    $(".timeago").timeago()

  convertToTimeAgo()

  #########################################
  # Updates
  #########################################

  # PJAX-ify the tabs
  $('#updates-menu a').pjax('#content').click ->
    # Set clicked tab to be given active class when pjax returns
    $('#updates-menu li').removeClass("active")
    $(this).parent().addClass("active")

  $('.pagination a').pjax('#content')

  $("#content")
    .bind("start.pjax", pjaxStart = ->
      loading = $("<div class='loading' />")
      $("#content").append(loading)
      window.scrollTo(0,0))
    .bind("end.pjax", pjaxEnd = ->
      replaceBrokenImages()
      convertToTimeAgo()
    )

  #########################################
  # Update Form
  #########################################
  textarea = $("#update-form textarea")
  update_field = $("#update-form #update-referral")
  userTickiedBox = false

  # Manage update character count
  updateCounter = ->
    remainingLength = MAX_LENGTH - textarea.val().length
    countSpan = $("#update-count .update-count").first()
    if countSpan.length
      countSpan.text(remainingLength)
    else
      $("#update-count").append('<span class="update-count">' + remainingLength + '</span>/' + MAX_LENGTH)
    $("#update-info").toggleClass "negative", remainingLength < 0

  textarea.keypress(updateCounter).keyup(updateCounter)

  textarea.triggeredAutocomplete
    trigger: "@"
    source: "/autocomplete"
    maxLength: 10

  # Validate form on submit
  $("#update-form").submit ->
    false if textarea.val().length <= 0 || textarea.val().length > MAX_LENGTH

  # Helper method for RS messages
  shareText = (update) ->
    "RS @" + $(update).data("name") + ": " + $(update).find(".entry-content").text().trim()

  # Helper method to add text and move cursor to correct position
  focusTextArea = (update) ->
    $(update_field).attr("value", $(update).data("id"))

    length = textarea.text().length
    textarea.keypress()
    textarea[0].setSelectionRange(length, length)
    textarea.focus()
    window.scrollTo(0, $(textarea).position().top)

  # If update form, target when clicking reply and insert appropriate text
  $(".has-update-form .update").each ->
    update = $(this)

    $(this).find(".reply").bind "click", (ev) ->
      ev.preventDefault()
      textarea.text("@" + $(update).data("name") + " ")
      focusTextArea(update)

    $(this).find(".share").bind "click", (ev) ->
      ev.preventDefault()
      textarea.text(shareText(update))
      focusTextArea(update)

  # Manage reply state and service share checkboxes
  updateTickyboxes = ->
    return if(userTickiedBox)

    firstLetter = ""
    if(textarea.val() != "")
      firstLetter = textarea.val()[0]

    enabled = true
    if firstLetter == "@"
      enabled = false

    if( $("#tweet").length > 0)
      $("#tweet").attr('checked', enabled)

  textarea.keypress(updateTickyboxes).keyup(updateTickyboxes)

  recordTickyboxChange = ->
    userTickiedBox = true

  if( $("#tweet").length > 0)
    $("#tweet").change(recordTickyboxChange)

  #########################################
  # Delete account<commit_msg>Fix for issue #691. Sets the original enabled value to the current state of the ticky box.<commit_after>MAX_LENGTH = 140

jQuery $ ->

  # Turn on JS styles
  $("html").removeClass("no-js").addClass("js")

  # Hide flash messages
  $("#flash .notice").delay(4000).slideUp('slow')

  # Replace images that 404 with the default avatar
  replaceBrokenImages = ->
    $("img").error ->
      $(this).attr("src", "<%= asset_path RstatUs::DEFAULT_AVATAR %>")

  replaceBrokenImages()

  # Use the timeago plugin to convert an update's time to time ago format
  # and update it once a minute
  convertToTimeAgo = ->
    $(".timeago").timeago()

  convertToTimeAgo()

  #########################################
  # Updates
  #########################################

  # PJAX-ify the tabs
  $('#updates-menu a').pjax('#content').click ->
    # Set clicked tab to be given active class when pjax returns
    $('#updates-menu li').removeClass("active")
    $(this).parent().addClass("active")

  $('.pagination a').pjax('#content')

  $("#content")
    .bind("start.pjax", pjaxStart = ->
      loading = $("<div class='loading' />")
      $("#content").append(loading)
      window.scrollTo(0,0))
    .bind("end.pjax", pjaxEnd = ->
      replaceBrokenImages()
      convertToTimeAgo()
    )

  #########################################
  # Update Form
  #########################################
  textarea = $("#update-form textarea")
  update_field = $("#update-form #update-referral")
  userTickiedBox = false

  # Manage update character count
  updateCounter = ->
    remainingLength = MAX_LENGTH - textarea.val().length
    countSpan = $("#update-count .update-count").first()
    if countSpan.length
      countSpan.text(remainingLength)
    else
      $("#update-count").append('<span class="update-count">' + remainingLength + '</span>/' + MAX_LENGTH)
    $("#update-info").toggleClass "negative", remainingLength < 0

  textarea.keypress(updateCounter).keyup(updateCounter)

  textarea.triggeredAutocomplete
    trigger: "@"
    source: "/autocomplete"
    maxLength: 10

  # Validate form on submit
  $("#update-form").submit ->
    false if textarea.val().length <= 0 || textarea.val().length > MAX_LENGTH

  # Helper method for RS messages
  shareText = (update) ->
    "RS @" + $(update).data("name") + ": " + $(update).find(".entry-content").text().trim()

  # Helper method to add text and move cursor to correct position
  focusTextArea = (update) ->
    $(update_field).attr("value", $(update).data("id"))

    length = textarea.text().length
    textarea.keypress()
    textarea[0].setSelectionRange(length, length)
    textarea.focus()
    window.scrollTo(0, $(textarea).position().top)

  # If update form, target when clicking reply and insert appropriate text
  $(".has-update-form .update").each ->
    update = $(this)

    $(this).find(".reply").bind "click", (ev) ->
      ev.preventDefault()
      textarea.text("@" + $(update).data("name") + " ")
      focusTextArea(update)

    $(this).find(".share").bind "click", (ev) ->
      ev.preventDefault()
      textarea.text(shareText(update))
      focusTextArea(update)

  # Manage reply state and service share checkboxes
  updateTickyboxes = ->
    return if(userTickiedBox)

    firstLetter = ""
    if(textarea.val() != "")
      firstLetter = textarea.val()[0]

    enabled = $("#tweet").attr('checked')
    if firstLetter == "@"
      enabled = false

    if( $("#tweet").length > 0)
      $("#tweet").attr('checked', enabled)

  textarea.keypress(updateTickyboxes).keyup(updateTickyboxes)

  recordTickyboxChange = ->
    userTickiedBox = true

  if( $("#tweet").length > 0)
    $("#tweet").change(recordTickyboxChange)

  #########################################
  # Delete account
{'fraction_non_alphanumeric': 0.21434348881100027, 'fraction_numerical': 0.00606632515502831, 'mean_word_length': 3.6310861423220975, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 49, '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': '1873862', 'n_tokens_mistral': 2277, 'n_tokens_neox': 2146, 'n_words': 477}