<commit_before>//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_self

$ ->
  $(".topbar").dropdown()

  # Needs to be bound to all calls wanting a JSON response
  $(".alert-message a").bind "ajax:beforeSend", (xhr, settings) ->
    settings.setRequestHeader 'Accept', 'application/json'

  $(".flag-link").live "ajax:success", (xhr, data, status) ->
    $(data).appendTo($("body")).modal(backdrop: true, show: true).bind('hidden', ->
      $(this).remove()
    ).find(".btn.secondary").click( (e) ->
      $(".modal").modal('hide')
      e.preventDefault()
    )

  $("#new_flag").live "ajax:success", (xhr, data, status) ->
    if data.status is "ok"
      $(".modal").modal('hide')
      pop = $(".flag-link").attr("title", "Thanks").attr("data-content", data.message).popover(
        trigger: 'manual'
      ).popover('show').data('popover').$tip
      pop.click ->
        $(".flag-link").popover('hide')
    else
      $(".modal").modal('hide')
      pop = $(".flag-link").attr("title", "Whoops").attr("data-content", data.errors.flaggable[0]).popover(
        trigger: 'manual'
      ).popover('show').data('popover').$tip
      pop.click ->
        $(".flag-link").popover('hide')

  # /***************/
  $(".vote-form").live "ajax:success", (xhr, data, status) ->
    if $.isEmptyObject(data.errors)
      if data.vote.value is 1
       active = $(this).find('.upvote .vote-active').removeClass('vote-active');
       $(this).find('.upvote .vote-inactive').removeClass('vote-inactive').addClass('vote-active');
       active.addClass('vote-inactive');
      else
       active = $(this).find('.downvote .vote-active').removeClass('vote-active');
       $(this).find('.downvote .vote-inactive').removeClass('vote-inactive').addClass('vote-active');
       active.addClass('vote-inactive'); 
    else
      # $(this).popover(data.errors.voteable[0]);

  $(".alert-message a").bind "ajax:success", (xhr, data, status) ->
    $("#notification-" + data.dismiss).fadeOut 'fast', ->
      $(this).remove();

$.fn.fadeOutAndRemove = (speed) ->
  if speed == undefined
    speed = 'fast'
  return this.each -><commit_msg>Refactored flag popover creation<commit_after>//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_self

$ ->
  $(".topbar").dropdown()

  # Needs to be bound to all calls wanting a JSON response
  $(".alert-message a").bind "ajax:beforeSend", (xhr, settings) ->
    settings.setRequestHeader 'Accept', 'application/json'

  $(".flag-link").live "ajax:success", (xhr, data, status) ->
    $(data).appendTo($("body")).modal(backdrop: true, show: true).bind('hidden', ->
      $(this).remove()
    ).find(".btn.secondary").click( (e) ->
      $(".modal").modal('hide')
      e.preventDefault()
    )

  $("#new_flag").live "ajax:success", (xhr, data, status) ->
    if data.status is "ok"
      $(".modal").modal('hide')
      pop = $(".flag-link").attr("title", "Thanks").attr("data-content", data.message).qaPopover()
    else
      $(".modal").modal('hide')
      pop = $(".flag-link").attr("title", "Whoops").attr("data-content", data.errors.flaggable[0]).qaPopover()

  # /***************/
  $(".vote-form").live "ajax:success", (xhr, data, status) ->
    if $.isEmptyObject(data.errors)
      if data.vote.value is 1
       active = $(this).find('.upvote .vote-active').removeClass('vote-active');
       $(this).find('.upvote .vote-inactive').removeClass('vote-inactive').addClass('vote-active');
       active.addClass('vote-inactive');
      else
       active = $(this).find('.downvote .vote-active').removeClass('vote-active');
       $(this).find('.downvote .vote-inactive').removeClass('vote-inactive').addClass('vote-active');
       active.addClass('vote-inactive'); 
    else
      # $(this).popover(data.errors.voteable[0]);

  $(".alert-message a").bind "ajax:success", (xhr, data, status) ->
    $("#notification-" + data.dismiss).fadeOut 'fast', ->
      $(this).remove();

$.fn.qaPopover = (options) ->
  pop = this.popover(
    trigger: 'manual'
  ).popover('show').data('popover').$tip
  pop.click =>
    this.popover('hide')
  this

$.fn.fadeOutAndRemove = (speed) ->
  if speed == undefined
    speed = 'fast'
  return this.each ->
{'fraction_non_alphanumeric': 0.23024136299100806, 'fraction_numerical': 0.001419782300047326, 'mean_word_length': 3.3220858895705523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '7310479', 'n_tokens_mistral': 1360, 'n_tokens_neox': 1344, 'n_words': 237}