<commit_before>(function ($, window, undefined) {

/*
# mode: textonly/richtext / disable b/i/u/enter + strip on paste
# pasteOnlyText: true
# maxlength: 123
# multiline: true / disable enter + strip on paste
# placeholder: 'some placeholder'
#
*/

  var pluginName = 'enableObjectResizingShim',
  defaults = {
    debug: false
  }

  function Plugin(element, options) {
    this.element    = element
    this.$element   = $(element)

    this.options    = $.extend({}, defaults, options)

    this._defaults  = defaults
    this._name      = pluginName

    this.isActive    = false

    // only run if needed
    if (!document.queryCommandSupported('enableObjectResizing')) {
      this.init()
    }
  }

  Plugin.prototype.init = function () {
    this.bindEvents()
  }

  Plugin.prototype.bindEvents = function () {
    this.$element.on('focus', 'img', this.addResizeHandles.bind(this))
    this.$element.on('blur', 'img', this.removeResizeHandles.bind(this))
    this.$element.on('mousedown', '.enableObjectResizingShim-handle', this.startResize.bind(this))
  }

  Plugin.prototype.addResizeHandles = function (event) {
    if(this.isActive) return
    var $img = $(event.currentTarget)
    var $holder = $('<div class="enableObjectResizingShim" contenteditable="false"></div>')
    $img.wrap($holder)

    for (var i=0; i<4; i++) {
      $img.before('<div class="enableObjectResizingShim-handle"></div>')
    }

    this.isActive = true
  }

  Plugin.prototype.removeResizeHandles = function (event) {
    console.log("removeResizeHandles")
    if(this.isResizing) return
    var $img = this.$element.find('.enableObjectResizingShim img')
    $img.siblings().remove()
    $img.unwrap()
    this.isActive = false
  }

  Plugin.prototype.startResize = function (event) {
    $(document).on('mousemove.enableObjectResizing', this.resize.bind(this))
    $(document).on('mouseup.enableObjectResizing', this.resizeEnd.bind(this))
    var $handle = $(event.currentTarget)
    this.resizeCorner = $handle.index()
    this.$img = this.$element.find('.enableObjectResizingShim img')
    this.startX = event.pageX
    this.startWidth = this.$img.width()
    this.$clone = this.$img.clone().css({width: '', height: ''}).addClass('enableObjectResizingShim-clone enableObjectResizingShim-clone--'+ this.resizeCorner)
    this.$img.after(this.$clone)
    this.isResizing = true
  }

  Plugin.prototype.resize = function (event) {
    event.preventDefault()
    var dx = event.pageX - this.startX
    this.$clone.css('width', this.startWidth + dx)
  }

  Plugin.prototype.resizeEnd = function (event) {
    $(document).off('mousemove.enableObjectResizing')
    $(document).off('mouseup.enableObjectResizing')

    this.$img.css({
      width: this.$clone.width(),
      height: this.$clone.height()
    })
    this.$clone.remove()
    this.isResizing = false
  }

  $.fn[pluginName] = function (options) {
    return this.each(function () {
      if (!$.data(this, 'plugin_' + pluginName)) {
        $.data(this, 'plugin_' + pluginName, new Plugin(this, options))
      }
    });
  }

}(jQuery, window));<commit_msg>enableObjectResizingShim: fix deselect & allow delete<commit_after>(function ($, window, undefined) {

/*
# mode: textonly/richtext / disable b/i/u/enter + strip on paste
# pasteOnlyText: true
# maxlength: 123
# multiline: true / disable enter + strip on paste
# placeholder: 'some placeholder'
#
*/

  var pluginName = 'enableObjectResizingShim',
  defaults = {
    debug: false
  }

  function Plugin(element, options) {
    this.element    = element
    this.$element   = $(element)

    this.options    = $.extend({}, defaults, options)

    this._defaults  = defaults
    this._name      = pluginName

    // only run if needed
    if (!document.queryCommandSupported('enableObjectResizing')) {
      this.bindEvents()
    }
  }

  Plugin.prototype.bindEvents = function () {
    this.$element.on('click', 'img', this.createEditor.bind(this))
    this.$element.on('click', this.destroyEditors.bind(this))
  }

  Plugin.prototype.createEditor = function (event) {
    event.stopPropagation()
    this.destroyEditors()
    var $img = $(event.currentTarget)

    if (!$img.hasClass('objectResizingEditorActive')) {
      new Editor($img)
    }
  }

  Plugin.prototype.destroyEditors = function () {
    this.$element.find('img.objectResizingEditorActive').each(function(i, img){
      editor = $(img).data('objectResizingEditor')
      if(editor){
        editor.destroy()
      }
    })
  }



  /*

    Resize Editor

  */

  function Editor($element) {
    this.$element = $element
    this.isResizing = false

    this.$element.data('objectResizingEditor', this)
    this.$element.addClass('objectResizingEditorActive')
    this.$element.wrap('<div class="enableObjectResizingShim" contenteditable="false"></div>')

    for (var i=0; i<4; i++) {
      this.$element.before('<div class="enableObjectResizingShim-handle"></div>')
    }

    $(document).one('click.objectResizingEditor', this.destroy.bind(this))
    $(document).one('keydown.objectResizingEditor', this.onKeydown.bind(this))
    this.$element.on('click.objectResizingEditor', this.stopPropagation.bind(this))
    this.$element.parent().find('.enableObjectResizingShim-handle').on('mousedown', this.startResize.bind(this))
  }

  Editor.prototype.onKeydown = function (event) {
    this.destroy()

    switch (event.keyCode) {
      case 8: // backspace
        this.$element.remove()
        break
      default:
        event.stopPropagation()
        break
    }
  }

  Editor.prototype.stopPropagation = function (event) {
    event.stopPropagation()
  }

  Editor.prototype.destroy = function (event) {
    if(this.isResizing) return
    this.$element.off('click.objectResizingEditor')
    $(document).off('click.objectResizingEditor')
    $(document).off('keydown.objectResizingEditor')
    this.$element.removeClass('objectResizingEditorActive')
    this.$element.siblings().remove()
    this.$element.unwrap()
  }

  Editor.prototype.startResize = function (event) {
    var $handle = $(event.currentTarget)
    this.resizeCorner = $handle.index()
    this.resizeDir = this.resizeCorner == 0 || this.resizeCorner == 3 ? -1 : 1
    this.startX = event.pageX
    this.startWidth = this.$element.width()
    this.$clone = this.$element.clone().css({width: '', height: ''}).addClass('enableObjectResizingShim-clone enableObjectResizingShim-clone--'+ this.resizeCorner)
    this.$element.after(this.$clone)
    this.isResizing = true
    $(document).on('mousemove.enableObjectResizing', this.resize.bind(this))
    $(document).on('mouseup.enableObjectResizing', this.resizeEnd.bind(this))
  }

  Editor.prototype.resize = function (event) {
    event.preventDefault()
    var dx = event.pageX - this.startX
    this.$clone.css('width', this.startWidth + (this.resizeDir * dx))
  }

  Editor.prototype.resizeEnd = function (event) {
    $(document).off('mousemove.enableObjectResizing')
    $(document).off('mouseup.enableObjectResizing')

    this.$element.css({
      width: this.$clone.width(),
      height: this.$clone.height()
    })
    this.$clone.remove()

    // reset isResizing with a delay to prevent a mouseup in the editor to trigger a editor-destroy
    setTimeout(function(){
      this.isResizing = false
    }.bind(this))
  }




  $.fn[pluginName] = function (options) {
    return this.each(function () {
      if (!$.data(this, 'plugin_' + pluginName)) {
        $.data(this, 'plugin_' + pluginName, new Plugin(this, options))
      }
    });
  }

}(jQuery, window));
{'fraction_non_alphanumeric': 0.15331747290510178, 'fraction_numerical': 0.0019825535289452814, 'mean_word_length': 3.4695806261075015, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '1919542', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2328, 'n_words': 406}