Skip to content

Commit

Permalink
[2204] jQuery.fn.truncate() skips short text
Browse files Browse the repository at this point in the history
If the text is shorter than the max length then the plugin will skip
the element.
  • Loading branch information
aron committed Apr 30, 2012
1 parent 2379ee9 commit 2902818
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ckan/public/scripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ jQuery.fn.truncate = function (max, suffix) {
text = cached.slice(0, length);
expand = jQuery('<a href="#" />').text(suffix || '»');

// Bail early if there is nothing to truncate.
if (cached.length < length) {
return;
}

// Try to truncate to nearest full word.
while ((/\S/).test(text[text.length - 1])) {
text = text.slice(0, text.length - 1);
Expand Down

0 comments on commit 2902818

Please sign in to comment.