<commit_before>;(function ($) {
  'use strict';


  function InplaceEditor(el, options) {
    var self = this;

    this.$el      = $(el);
    this.options  = options;

    this.$el.on('click', function () {
      self.activate();
    });

    this.$el.on('blur', function () {
      self.deactivate();
    });

    if (options.filter) {
      this.update = function () {
        var raw = this.getValue(), clean = options.filter.call(this, raw);
        if (raw !== clean) {
          this.setValue(clean);
        }
      }
    }

    if (options.throttle && _) {
      this._update = this.update;
      this.update = _.throttle(function () {
        self._update();
      }, options.throttle);
    }
  }


  InplaceEditor.prototype.activate = function () {
    var self = this;

    if (!!this.activated) {
      return;
    }

    this.value      = this.getValue();
    this.activated  = true;

    this.$el.on('paste.inplaceEditor, keypress.inplaceEditor, keyup.inplaceEditor', function (event) {
      // ENTER
      if (13 === event.keyCode) {
        self.update()
        self.deactivate();
        return;
      }

      // ESC
      if (27 === event.keyCode) {
        // **NOTICE** Firefox does not fires this event by some reasone
        self.setValue(self.value);
        self.deactivate();
      }

      self.update();
    });

    this.$el.attr('contenteditable', true).focus();
  };


  InplaceEditor.prototype.deactivate = function () {
    var value = this.getValue();

    if (!this.activated) {
      return;
    }

    this.activated = false;

    this.$el.off('.inplaceEditor');
    this.$el.attr('contenteditable', false);

    // call unthrottled update if it exists
    this._update ? this._update() : this.update();

    if (this.value !== value) {
      if (!value && !this.options.allowEmpty) {
        this.setValue(this.value);
      } else {
        this.$el.trigger('change', [this.getValue()]);
      }
    }

    this.$el.blur();
  };


  InplaceEditor.prototype.setValue = function setValue(val) {
    this.$el['html' === this.options.type ? 'html' : 'text'](val);
  };


  InplaceEditor.prototype.getValue = function getValue() {
    return this.$el['html' === this.options.type ? 'html' : 'text']();
  };


  // By default update does nothing
  InplaceEditor.prototype.update = $.noop;


  $.fn.inplaceEditor = function (options) {
    return this.each(function () {<commit_msg>Improve value processing by contentEditable<commit_after>;(function ($) {
  'use strict';


  function InplaceEditor(el, options) {
    var self = this;

    this.$el      = $(el);
    this.options  = options;

    this.$el.on('click', function () {
      self.activate();
    });

    this.$el.on('blur', function () {
      self.deactivate();
    });

    if (options.filter) {
      this.update = function () {
        var raw = this.getValue(), clean = options.filter.call(this, raw);
        if (raw !== clean) {
          this.setValue(clean);
        }
      }
    }

    if (options.throttle && _) {
      this._update = this.update;
      this.update = _.throttle(function () {
        self._update();
      }, options.throttle);
    }
  }


  InplaceEditor.prototype.activate = function () {
    var self = this;

    if (!!this.activated) {
      return;
    }

    this.value      = this.getValue();
    this.activated  = true;

    this.$el.on('paste.inplaceEditor, keypress.inplaceEditor, keyup.inplaceEditor', function (event) {
      // ENTER
      if (13 === event.keyCode) {
        self.deactivate();
        return;
      }

      // ESC
      if (27 === event.keyCode) {
        // **NOTICE** Firefox does not fires this event by some reasone
        self.setValue(self.value);
        self.deactivate();
        return;
      }

      self.update();
    });

    this.$el.attr('contenteditable', true).focus();
  };


  InplaceEditor.prototype.deactivate = function () {
    var value;

    if (!this.activated) {
      return;
    }

    this.activated = false;

    this.$el.off('.inplaceEditor');
    this.$el.attr('contenteditable', false);

    // call unthrottled update if it exists
    this._update ? this._update() : this.update();

    // get new value ONLY after update()
    value = this.getValue();

    if (this.value !== value) {
      if (!value && !this.options.allowEmpty) {
        this.setValue(this.value);
      } else {
        this.$el.trigger('change', [value]);
      }
    }

    this.$el.blur();
  };


  InplaceEditor.prototype.setValue = function setValue(val) {
    this.$el['html' === this.options.type ? 'html' : 'text'](val);
  };


  InplaceEditor.prototype.getValue = function getValue() {
    return this.$el['html' === this.options.type ? 'html' : 'text']();
  };


  // By default update does nothing
  InplaceEditor.prototype.update = $.noop;


  $.fn.inplaceEditor = function (options) {
    return this.each(function () {
{'fraction_non_alphanumeric': 0.16398123597797268, 'fraction_numerical': 0.0016316540893330613, 'mean_word_length': 2.230566534914361, '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': '7308874', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1504, 'n_words': 299}