<commit_before>this.GobiertoAdmin.DirtyFormsComponent = (function() {
  var isDirty;

  function DirtyFormsComponent() {}

  DirtyFormsComponent.prototype.handle = function(message) {
    $(document).on("turbolinks:load", _handleDirtyFlag);

    $(document).on("turbolinks:before-visit", function() {
      if (isDirty) { return confirm(message); }
    });

    $(window).on("beforeunload", function() {
      if (isDirty) { return message; }
    });
  };

  function _handleDirtyFlag() {
    isDirty = false;

    var checkingForm = $("form:not(.skip-dirty-check)");

    checkingForm.on("submit", _unsetDirty);
    checkingForm.on("change", "input, select, textarea", _setDirty);
    checkingForm.on("trix-change", _setDirty);
    checkingForm.on("datepicker-change", _setDirty);
  }

  function _setDirty(e) {
    console.log('_setDirty', e);
    isDirty = true;
  }

  function _unsetDirty() {
    isDirty = false;
  }

  return DirtyFormsComponent;
})();

this.GobiertoAdmin.dirty_forms_component = new GobiertoAdmin.DirtyFormsComponent;
<commit_msg>Consider events only from the first second<commit_after>this.GobiertoAdmin.DirtyFormsComponent = (function() {
  var isDirty;
  var t1, t2;

  function DirtyFormsComponent() {}

  DirtyFormsComponent.prototype.handle = function(message) {
    $(document).on("turbolinks:load", _handleDirtyFlag);

    $(document).on("turbolinks:before-visit", function() {
      if (isDirty) { return confirm(message); }
    });

    $(window).on("beforeunload", function() {
      if (isDirty) { return message; }
    });
  };

  function _handleDirtyFlag() {
    isDirty = false;
    var date = new Date();
    t1 = date.getTime();

    var checkingForm = $("form:not(.skip-dirty-check)");

    checkingForm.on("submit", _unsetDirty);
    checkingForm.on("change", "input, select, textarea", _setDirty);
    checkingForm.on("trix-change", _setDirty);
    checkingForm.on("datepicker-change", _setDirty);
  }

  function _setDirty(e) {
    var date = new Date();
    t2 = date.getTime();
    // For some reason, when the WYSIWYG has an image, it triggers a trix-change event.
    // Here, we check if the time difference between the load and the event is big than 1 sec.
    if(t2 - t1 > 1000) {
      isDirty = true;
    }
  }

  function _unsetDirty() {
    isDirty = false;
  }

  return DirtyFormsComponent;
})();

this.GobiertoAdmin.dirty_forms_component = new GobiertoAdmin.DirtyFormsComponent;

{'fraction_non_alphanumeric': 0.1430327868852459, 'fraction_numerical': 0.004508196721311476, 'mean_word_length': 3.767578125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '5904864', 'n_tokens_mistral': 835, 'n_tokens_neox': 805, 'n_words': 164}