<commit_before>/**
Easily and unobtrusively truncate long blocks of text with a more link.
Simply add a data-truncate attribute to any element you would like to truncate.
<NAME> - www.nicholasjohnson.com
for
Streetbank - www.streetbank.com
*/
(function () {
  $.fn.truncate = function () {
    this.each(function (length) {

      length = length || 50;

      var el = $(this),
        content = el.html(),
        split = _.filter(content.split(" "), function (i) {
          return i;
        }),
        truncated,
        moreLink;

      if (split.length > length) {
        truncated = split.slice(0, length).join(" ");
        moreLink = $('<a href="#"> more...</a>');
        el.html(truncated);
        el.find('> :last-child').append(moreLink);
        moreLink.click(function (e) {
          el.html(content);
          e.preventDefault();
        });
      }
    });
  };
}());

$(function () {
  $('[data-truncate]').each(function () {
    var el = $(this),
      length = parseInt(el.attr('[data-truncate]'), 10);
    el.truncate(length);
  });
});
<commit_msg>Correctly pulls the truncation length out of the DOM. Also returns this.<commit_after>/**
Easily and unobtrusively truncate long blocks of text with a more link.
Simply add a data-truncate attribute to any element you would like to truncate.
<NAME> - www.nicholasjohnson.com
for
Streetbank - www.streetbank.com
*/
(function () {
  $.fn.truncate = function (length) {
    this.each(function () {

      length = length || 50;

      var el = $(this),
        content = el.html(),
        split = _.filter(content.split(" "), function (i) {
          return i;
        }),
        truncated,
        moreLink;

      if (split.length > length) {
        truncated = split.slice(0, length).join(" ");
        moreLink = $('<a href="#"> more...</a>');
        el.html(truncated);
        el.find('> :last-child').append(moreLink);
        moreLink.click(function (e) {
          el.html(content);
          e.preventDefault();
        });
      }
    });
    return this;
  };
}());

$(function () {
  $('[data-truncate]').each(function () {
    var el = $(this),
      length = parseInt(el.attr('data-truncate'), 10);
    el.truncate(length);
  });
});

{'fraction_non_alphanumeric': 0.1720575022461815, 'fraction_numerical': 0.004492362982929021, 'mean_word_length': 2.3139880952380953, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '5722329', 'n_tokens_mistral': 731, 'n_tokens_neox': 698, 'n_words': 169}