Skip to content

Commit 0ca1afa

Browse files
committed
Removed duplicate ")" suffix. Added calculation for prefix and suffix to actual max length.
1 parent 577f404 commit 0ca1afa

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

README.markdown

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ The available options are:
5454

5555
Note that the ` (…more)` bit counts towards the max length – so a max length of 10 would truncate `1234567890` to `12 (…more)`.
5656

57+
## Customizations in this Fork
58+
59+
Removed extra ")" that is appended to more text. Included link prefix and suffix in max length calculation (before, was only including more text).
60+
5761
## Credits and license
5862

5963
By [Henrik Nyh](http://henrik.nyh.se/) under the MIT license:

jquery.truncator.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
var content_length = $.trim(squeeze($(this).text())).length;
1616
if (content_length <= opts.max_length)
1717
return; // bail early if not overlong
18+
19+
// include more text, link prefix, and link suffix in max length
20+
var actual_max_length = opts.max_length - opts.more.length - opts.link_prefix.length - opts.link_suffix.length;
1821

19-
var actual_max_length = opts.max_length - opts.more.length - 3; // 3 for " ()"
2022
var truncated_node = recursivelyTruncate(this, actual_max_length);
2123
var full_node = $(this).hide();
2224

2325
truncated_node.insertAfter(full_node);
2426

25-
findNodeForMore(truncated_node).append(opts.link_prefix+'<a href="#more" class="'+opts.css_more_class+'">'+opts.more+'</a>)'+opts.link_suffix);
27+
findNodeForMore(truncated_node).append(opts.link_prefix+'<a href="#more" class="'+opts.css_more_class+'">'+opts.more+'</a>'+opts.link_suffix);
2628
findNodeForLess(full_node).append(opts.link_prefix+'<a href="#less" class="'+opts.css_less_class+'">'+opts.less+'</a>'+opts.link_suffix);
2729

2830
truncated_node.find('a:last').click(function() {

0 commit comments

Comments
 (0)