<commit_before>$(function() {
  abracadabraSubmissionInProgress = false;
  abracadabraDeleteMousedown = false;

  function closeAbracadabra(element, destroy) {
    $element = $(element);
    if($element.hasClass("abracadabra-container")) {
      container = $element;
    } else {
      container = $element.parents(".abracadabra-container");
    }

    if(destroy) {
      container.siblings(".abracadabra").remove();
    } else {
      value = container.find(".abracadabra-input").val();
      container.siblings(".abracadabra").text(value).show();
    }

    try {
      container.remove();
    } catch (error) {
      if(error.name != "NotFoundError") {
        throw error;
      }
    }
  }

  function tabToNextAbracadabra(element, selector) {
    if(selector != undefined) {
      nextAbracadabra = $(selector);

      /* If selector isn't an ID, find the element with the class AFTER the current element */
      if (selector.indexOf("#") == -1) {
        abracadabra = $(element).parents(".abracadabra-container").siblings(".abracadabra");
        indexOfAbracadabra = $(selector).index(abracadabra);
        nextAbracadabra = $($(selector)[indexOfAbracadabra + 1]);
      }
      /* /If selector isn't an ID, find the element with the class AFTER the current element */

      closeAbracadabra(element, false);
      nextAbracadabra.click();
    } else {
      closeAbracadabra(element, false);
    }
  }

  $("body").on("submit", ".abracadabra-form", function(e) {
    if(abracadabraSubmissionInProgress == true) {
      e.preventDefault();
      return false;
    }
    abracadabraSubmissionInProgress = true;
  });

  $("body").on("ajax:before", ".abracadabra-delete", function() {
    if(abracadabraSubmissionInProgress == true) {
      e.preventDefault();
      return false;
    }
    abracadabraSubmissionInProgress = true;
  });

  $("body").on("mousedown", ".abracadabra-delete", function() {
    abracadabraDeleteMousedown = true;
  });

  $("body").on("ajax:success", ".abracadabra-form", function(e) {
    input = $(this).find(".abracadabra-input")
    tabToNextSelector = input.data("tab-to-next-selector");
    tabToNextAbracadabra(this, tabToNextSelector);
    abracadabraSubmissionInProgress = false;
    console.log(".abracadabra-form");
  });

  $("body").on("ajax:success", ".abracadabra-delete", function() {
    closeAbracadabra(this, true);
    abracadabraSubmissionInProgress = false;
    abracadabraDeleteMousedown = false;
  });

  $("body").on("click", ".abracadabra-cancel", function() {
    if(abracadabraSubmissionInProgress == false) {
      closeAbracadabra(this, false);
    }
  });

  $("body").on("blur", ".abracadabra-input", function() {
    if(abracadabraSubmissionInProgress == false && abracadabraDeleteMousedown == false) {
      closeAbracadabra(this, false);
    }
  });

  $("body").on("keydown", ".abracadabra-input", function(e) {
    /* Press Tab to submit (same function as Enter key) */
    if (e.keyCode == 9)
    {
      e.preventDefault();
      if(abracadabraSubmissionInProgress == false) {
        $(this.form).submit();
      }<commit_msg>refactoring ajax:success<commit_after>$(function() {
  abracadabraSubmissionInProgress = false;
  abracadabraDeleteMousedown = false;

  function closeAbracadabra(element, destroy) {
    $element = $(element);
    if($element.hasClass("abracadabra-container")) {
      container = $element;
    } else {
      container = $element.parents(".abracadabra-container");
    }

    if(destroy) {
      container.siblings(".abracadabra").remove();
    } else {
      value = container.find(".abracadabra-input").val();
      container.siblings(".abracadabra").text(value).show();
    }

    try {
      container.remove();
    } catch (error) {
      if(error.name != "NotFoundError") {
        throw error;
      }
    }
  }

  function tabToNextAbracadabra(element, selector) {
    if(selector != undefined) {
      nextAbracadabra = $(selector);

      /* If selector isn't an ID, find the element with the class AFTER the current element */
      if (selector.indexOf("#") == -1) {
        abracadabra = $(element).parents(".abracadabra-container").siblings(".abracadabra");
        indexOfAbracadabra = $(selector).index(abracadabra);
        nextAbracadabra = $($(selector)[indexOfAbracadabra + 1]);
      }
      /* /If selector isn't an ID, find the element with the class AFTER the current element */

      closeAbracadabra(element, false);
      nextAbracadabra.click();
    } else {
      closeAbracadabra(element, false);
    }
  }

  $("body").on("submit", ".abracadabra-form", function(e) {
    if(abracadabraSubmissionInProgress == true) {
      e.preventDefault();
      return false;
    }
    abracadabraSubmissionInProgress = true;
  });

  $("body").on("ajax:before", ".abracadabra-delete", function() {
    if(abracadabraSubmissionInProgress == true) {
      e.preventDefault();
      return false;
    }
    abracadabraSubmissionInProgress = true;
  });

  $("body").on("mousedown", ".abracadabra-delete", function() {
    abracadabraDeleteMousedown = true;
  });

  $("body").on("ajax:success", ".abracadabra-form", function(e) {
    target = $(e.target);

    /* If form is a DELETE, remove abracadabra instance, if not, call tabToNextSelector */
    if(target.hasClass("abracadabra-delete")) {
      closeAbracadabra(target, true);
      abracadabraDeleteMousedown = false;
    } else {
      input = $(target).find(".abracadabra-input");
      tabToNextSelector = input.data("tab-to-next-selector");
      tabToNextAbracadabra(target, tabToNextSelector);
    }
    /* /If form is a DELETE, remove abracadabra instance, if not, call tabToNextSelector */

    abracadabraSubmissionInProgress = false;
  });

  $("body").on("click", ".abracadabra-cancel", function() {
    if(abracadabraSubmissionInProgress == false) {
      closeAbracadabra(this, false);
    }
  });

  $("body").on("blur", ".abracadabra-input", function() {
    if(abracadabraSubmissionInProgress == false && abracadabraDeleteMousedown == false) {
      closeAbracadabra(this, false);
    }
  });

  $("body").on("keydown", ".abracadabra-input", function(e) {
    /* Press Tab to submit (same function as Enter key) */
    if (e.keyCode == 9)
    {
      e.preventDefault();
      if(abracadabraSubmissionInProgress == false) {
        $(this.form).submit();
      }
{'fraction_non_alphanumeric': 0.15647114326151912, 'fraction_numerical': 0.0009435445824815223, 'mean_word_length': 3.311864406779661, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '113287', 'n_tokens_mistral': 2179, 'n_tokens_neox': 2125, 'n_words': 351}