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

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

    if(destroy) {
      container.siblings(".abracadabra").remove();
    } else {
      if(valueChanged == true) {
        value = container.find(".abracadabra-input").val();        
      } else {
        value = container.find(".abracadabra-input").data("original-value");
      }
      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, true);
      nextAbracadabra.click();
    } else {
      closeAbracadabra(element, false, true);
    }
  }

  $("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, 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, false);
    }
  });

  $("body").on("blur", ".abracadabra-input", function() {
    if(abracadabraSubmissionInProgress == false && abracadabraDeleteMousedown == false) {
      if($(this).data("submit-on-blur") == true) {
        $(this.form).submit();
      } else {
        closeAbracadabra(this, false, 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();
      }
    }
    /* /Press Tab to submit (same function as Enter key) */

    /* Press Escape to cancel */
    if (e.keyCode == 27)
    {
      e.preventDefault();
      if(abracadabraSubmissionInProgress == false) {
        closeAbracadabra(this, false, false);
      }
    }
    /* /Press Escape to cancel */
  });


  $("body").on("confirm:complete", ".abracadabra-delete", function(e, response) {
    /* If cancel is clicked in the deletable_confirm dialog, focus on the input */
    if(response == false) {
      input = $(this).parents(".abracadabra-delete-container").siblings();
      inputValue = input.val();
      input.focus().val("").val(inputValue);
    }
    /* /If cancel is clicked in the deletable_confirm dialog, focus on the input */
  });
  
  $(".abracadabra").on("click", function() {
    link = $(this);
    link.hide();
    path = link.data("path");
    attribute = link.data("attribute");
    formMethod = link.data("method");
    remote = ((link.data("remote") == true) ? " data-remote=\"true\"" : "");

    /* Check if button classes have been manually overridden elsewhere */
    if(typeof abracadabraSubmitIcon == "undefined") {
      abracadabraSubmitIcon = "fa fa-check";
    }

    if(typeof abracadabraCancelIcon == "undefined") {
      abracadabraCancelIcon = "fa fa-times";
    }

    if(typeof abracadabraDeleteIcon == "undefined") {
      abracadabraDeleteIcon = "fa fa-times-circle-o";
    }
    /* /Check if button classes have been manually overridden elsewhere */

    /* AJAX? */
    if(remote == "") {
      authToken = "<input name=\"authenticity_token\" type=\"hidden\" value=\"" + $("meta[name=\"csrf-token\"]").attr("content") + "\">";
      type = "";
      deletableType = "";
    } else {
      authToken = "";
      type = " data-type=\"" + link.data("type") + "\"";
      deletableType = " data-type=\"" + link.data("deletable-type") + "\"";
    }<commit_msg>Fixing issue where if escape key was pressed, it would prevent any other forms from being submitted<commit_after>$(function() {
  abracadabraSubmissionInProgress = false;
  abracadabraDeleteMousedown = false;
  abracadabraEscapeKeydown = true;

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

    if(destroy) {
      container.siblings(".abracadabra").remove();
    } else {
      if(valueChanged == true) {
        value = container.find(".abracadabra-input").val();        
      } else {
        value = container.find(".abracadabra-input").data("original-value");
      }
      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, true);
      nextAbracadabra.click();
    } else {
      closeAbracadabra(element, false, true);
    }
  }

  $("body").on("submit", ".abracadabra-form", function(e) {
    if(abracadabraSubmissionInProgress == true || abracadabraEscapeKeydown == true) {
      e.preventDefault();
      abracadabraEscapeKeydown = false;
      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, 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, false);
    }
  });

  $("body").on("blur", ".abracadabra-input", function() {
    if(abracadabraSubmissionInProgress == false && abracadabraDeleteMousedown == false) {
      if($(this).data("submit-on-blur") == true) {
        $(this.form).submit();
      } else {
        closeAbracadabra(this, false, 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();
      }
    }
    /* /Press Tab to submit (same function as Enter key) */

    /* Press Escape to cancel */
    if (e.keyCode == 27)
    {
      abracadabraEscapeKeydown = true;
      e.preventDefault();
      if(abracadabraSubmissionInProgress == false) {
        closeAbracadabra(this, false, false);
      }
    }
    /* /Press Escape to cancel */
  });


  $("body").on("confirm:complete", ".abracadabra-delete", function(e, response) {
    /* If cancel is clicked in the deletable_confirm dialog, focus on the input */
    if(response == false) {
      input = $(this).parents(".abracadabra-delete-container").siblings();
      inputValue = input.val();
      input.focus().val("").val(inputValue);
    }
    /* /If cancel is clicked in the deletable_confirm dialog, focus on the input */
  });
  
  $(".abracadabra").on("click", function() {
    if($(".abracadabra-container:visible").length) {
      return false;
    }

    link = $(this);
    link.hide();
    path = link.data("path");
    attribute = link.data("attribute");
    formMethod = link.data("method");
    remote = ((link.data("remote") == true) ? " data-remote=\"true\"" : "");

    /* Check if button classes have been manually overridden elsewhere */
    if(typeof abracadabraSubmitIcon == "undefined") {
      abracadabraSubmitIcon = "fa fa-check";
    }

    if(typeof abracadabraCancelIcon == "undefined") {
      abracadabraCancelIcon = "fa fa-times";
    }

    if(typeof abracadabraDeleteIcon == "undefined") {
      abracadabraDeleteIcon = "fa fa-times-circle-o";
    }
    /* /Check if button classes have been manually overridden elsewhere */

    /* AJAX? */
    if(remote == "") {
      authToken = "<input name=\"authenticity_token\" type=\"hidden\" value=\"" + $("meta[name=\"csrf-token\"]").attr("content") + "\">";
      type = "";
      deletableType = "";
    } else {
      authToken = "";
      type = " data-type=\"" + link.data("type") + "\"";
      deletableType = " data-type=\"" + link.data("deletable-type") + "\"";
    }
{'fraction_non_alphanumeric': 0.16249329279198713, 'fraction_numerical': 0.0008942944017170453, 'mean_word_length': 2.9754710273729117, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4107545', 'n_tokens_mistral': 3698, 'n_tokens_neox': 3623, 'n_words': 689}