<commit_before># does Rails-style flash message/error boxes that drop down from the top of the screen
define [
  'i18n!shared.flash_notices'
  'jquery'
  'underscore'
  'compiled/fn/preventDefault'
  'str/htmlEscape'
  'jqueryui/effects/drop'
  'vendor/jquery.cookie'
], (I18n, $, _, preventDefault, htmlEscape) ->
  $holder = []
  $screenreader_holder = []

  initFlashContainer = ->
    $holder = $("#flash_message_holder")
    return if $holder.length == 0 # not defined yet; call $.initFlashContainer later
    $screenreader_holder = $("#flash_screenreader_holder")
    $holder.on 'click', '.close_link', preventDefault(->)
    $holder.on 'click', 'li', ->
      $this = $(this)
      return if $this.hasClass('no_close')
      $.cookie('unsupported_browser_dismissed', '1') if $this.hasClass('unsupported_browser')
      $this.stop(true, true).remove()
  initFlashContainer() # look for the container on script load

  ###
  xsslint safeString.function escapeContent
  ###
  escapeContent = (content) ->
    if content.hasOwnProperty('html') then content.html else htmlEscape(content)

  screenReaderFlashBox = (type, content) ->
    $screenreader_node = $("""
      <span>#{escapeContent(content)}</span>
    """)

    $screenreader_node.appendTo($screenreader_holder)
    # By not removing these in a timely manner, they can stack up and become repetitive
    window.setTimeout((-> $screenreader_node.remove()), 1000)

  flashBox = (type, content, timeout, cssOptions = {}) ->
    $node = $("""
      <li class="ic-flash-#{htmlEscape(type)}">
        <i></i>
        #{escapeContent(content)}
        <a href="#" class="close_link icon-end">#{htmlEscape I18n.t("close", "Close")}</a>
      </li>
    """)

    $node.appendTo($holder).
      css(_.extend(zIndex: 1, cssOptions)).
      show('drop', direction: "up", 'fast', -> $(this).css('z-index', 2)).
      delay(timeout || 7000).
      animate({'z-index': 1}, 0).
      fadeOut('slow', -> $(this).slideUp('fast', -> $(this).remove()))

    setTimeout((-> screenReaderFlashBox(type, content)), 100)

  # Pops up a small notification box at the top of the screen.
  $.flashMessage = (content, timeout = 3000) ->
    flashBox("success", content, timeout)

  # Pops up a small error box at the top of the screen.
  $.flashError = (content, timeout) ->
    flashBox("error", content, timeout)

  # Pops up a small warning box at the top of the screen.
  $.flashWarning = (content, timeout = 3000) ->
    flashBox("warning", content, timeout)<commit_msg>stop error messages from interrupting themselves when removed<commit_after># does Rails-style flash message/error boxes that drop down from the top of the screen
define [
  'i18n!shared.flash_notices'
  'jquery'
  'underscore'
  'compiled/fn/preventDefault'
  'str/htmlEscape'
  'jqueryui/effects/drop'
  'vendor/jquery.cookie'
], (I18n, $, _, preventDefault, htmlEscape) ->
  $holder = []
  $screenreader_holder = []

  initFlashContainer = ->
    $holder = $("#flash_message_holder")
    return if $holder.length == 0 # not defined yet; call $.initFlashContainer later
    $screenreader_holder = $("#flash_screenreader_holder")
    $holder.on 'click', '.close_link', preventDefault(->)
    $holder.on 'click', 'li', ->
      $this = $(this)
      return if $this.hasClass('no_close')
      $.cookie('unsupported_browser_dismissed', '1') if $this.hasClass('unsupported_browser')
      $this.stop(true, true).remove()
  initFlashContainer() # look for the container on script load

  ###
  xsslint safeString.function escapeContent
  ###
  escapeContent = (content) ->
    if content.hasOwnProperty('html') then content.html else htmlEscape(content)

  screenReaderFlashBox = (type, content) ->
    $screenreader_node = $("""
      <span>#{escapeContent(content)}</span>
    """)

    $screenreader_node.appendTo($screenreader_holder)
    # we're hiding these instead of removing them, since calling .remove() on a
    # DOM node contained in an 'assertive' live region causes another alert that
    # interrupts whatever alert message(s) are in progress
    window.setTimeout((-> $screenreader_node.attr('aria-hidden', 'true')), 1000)

  flashBox = (type, content, timeout, cssOptions = {}) ->
    $node = $("""
      <li class="ic-flash-#{htmlEscape(type)}">
        <i></i>
        #{escapeContent(content)}
        <a href="#" class="close_link icon-end">#{htmlEscape I18n.t("close", "Close")}</a>
      </li>
    """)

    $node.appendTo($holder).
      css(_.extend(zIndex: 1, cssOptions)).
      show('drop', direction: "up", 'fast', -> $(this).css('z-index', 2)).
      delay(timeout || 7000).
      animate({'z-index': 1}, 0).
      fadeOut('slow', -> $(this).slideUp('fast', -> $(this).remove()))

    setTimeout((-> screenReaderFlashBox(type, content)), 100)

  # Pops up a small notification box at the top of the screen.
  $.flashMessage = (content, timeout = 3000) ->
    flashBox("success", content, timeout)

  # Pops up a small error box at the top of the screen.
  $.flashError = (content, timeout) ->
    flashBox("error", content, timeout)

  # Pops up a small warning box at the top of the screen.
  $.flashWarning = (content, timeout = 3000) ->
    flashBox("warning", content, timeout)
{'fraction_non_alphanumeric': 0.1606287138202032, 'fraction_numerical': 0.011884224650182096, 'mean_word_length': 3.6798206278026906, 'pattern_counts': {'":': 0, '<': 19, '<?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': '2493084', 'n_tokens_mistral': 1682, 'n_tokens_neox': 1599, 'n_words': 421}