<commit_before>jQuery.fn.fitsTruncationSpecs = (content,maxHeight,settings) ->

  old = if settings.html then @html() else @text()

  truncateWrapper = @html("<span class='jquery-truncate' style='display: block; float: none;'></span>").find('span.jquery-truncate')

  if settings.html
    truncateWrapper.html(content)
  else
    truncateWrapper.text(content)

  itFits = truncateWrapper.height() <= maxHeight

  if settings.html then @html(old) else @text(old)

  return itFits

jQuery.fn.performTruncation = (text,width,lheight,maxHeight,settings) ->

  @text("")

  characters = text.split("")

  hasNotYetExceededSpecs = true
  workingText = ""
  currentText = workingText

  for character in characters
    do (character) =>
      if hasNotYetExceededSpecs
        workingText += character
        textToTest = workingText + settings.omission
        if @fitsTruncationSpecs(textToTest,maxHeight,settings)
          currentText = textToTest
        else
          hasNotYetExceededSpecs = false

  if settings.html
    @html(currentText)
  else
    @text(currentText)



jQuery.fn.truncate = (options) ->

  options ||= {}

  settings =
    omission: '...'
    rows: 1
    html: false

  jQuery.extend(settings, options)

  $.each @, (i,el) ->

    # Set up some current state variables
    text = $(el).text()
    width = $(el).width()

    if el.currentStyle
      _lheight = el.currentStyle['line-height']
    else
      _lheight = document.defaultView.getComputedStyle(el, null).getPropertyValue('line-height')  if window.getComputedStyle

    lheight = if parseInt(_lheight,18) then parseInt(_lheight,18) else 18

    maxHeight = lheight * settings.rows

    $(el).performTruncation(text,width,lheight,maxHeight,settings) unless $(el).fitsTruncationSpecs(text,maxHeight,settings)
<commit_msg>Use the improved jQuery truncate from the pull request on my repo.<commit_after>(function() {
  var _rtrim = function(s) {
      return s.replace(/\s+$/g, "");
  };

  jQuery.fn.fitsTruncationSpecs = function(content, maxHeight, settings) {
    var itFits, oldHTML, oldText;
    if (settings.html) {
      oldHTML = this.html();
      this.html(content);
      itFits = this.height() <= maxHeight;
      this.html(oldHTML);
    } else {
      oldText = this.text();
      this.text(content);
      itFits = this.height() <= maxHeight;
      this.text(oldText);
    }
    return itFits;
  };
  jQuery.fn.performTruncation = function(text, width, lheight, maxHeight, settings) {
    this.text("");
    var top = text.length, bottom = 0, self = this;
    function _fn(s) {
        if (self.fitsTruncationSpecs(_rtrim(s) + settings.omission , maxHeight, settings)) {
            bottom = s.length;
        } else {
            top = s.length;
        }

        if (top > bottom + 1) {
            return _fn(text.substr(0,(top + bottom)/2));
        }

        return _rtrim(text.substr(0, bottom)) + settings.omission;
    };

    return this[settings.html? 'html': 'text'](_fn(text.substr(0, text.length / 2)));
  };
  jQuery.fn.truncate = function(options) {
    var settings;
    options || (options = {});
    settings = {
      omission: '...',
      rows: 1,
      html: false
    };
    jQuery.extend(settings, options);
    return $.each(this, function(i, el) {
      var lheight, maxHeight, text, width;
      text = $(el).text();
      width = $(el).width();
      lheight = $(el).css('line-height') ? parseInt($(el).css('line-height').match(/\d+/)[0]) : 0;
      maxHeight = lheight * settings.rows;
      if (!$(el).fitsTruncationSpecs(text, maxHeight, settings)) {
        return $(el).performTruncation(text, width, lheight, maxHeight, settings);
      }
    });
  };
}).call(this);

{'fraction_non_alphanumeric': 0.14471192859074924, 'fraction_numerical': 0.004598322964565864, 'mean_word_length': 2.9806243272335844, 'pattern_counts': {'":': 0, '<': 8, '<?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': '1787964', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1175, 'n_words': 245}