|
2 | 2 | // by Henrik Nyh <http://henrik.nyh.se> 2008-02-28. |
3 | 3 | // Free to modify and redistribute with credit. |
4 | 4 |
|
5 | | -(function($) { |
| 5 | +(function ($) { |
6 | 6 |
|
7 | 7 | var trailing_whitespace = true; |
8 | 8 |
|
9 | | - $.fn.truncate = function(options) { |
| 9 | + $.fn.truncate = function (options) { |
10 | 10 |
|
11 | 11 | var opts = $.extend({}, $.fn.truncate.defaults, options); |
12 | | - |
13 | | - $(this).each(function() { |
| 12 | + |
| 13 | + $(this).each(function () { |
14 | 14 |
|
15 | 15 | var content_length = $.trim(squeeze($(this).text())).length; |
16 | 16 | if (content_length <= opts.max_length) |
|
22 | 22 |
|
23 | 23 | truncated_node.insertAfter(full_node); |
24 | 24 |
|
25 | | - findNodeForMore(truncated_node).append(' (<a href="#show more content">'+opts.more+'</a>)'); |
26 | | - findNodeForLess(full_node).append(' (<a href="#show less content">'+opts.less+'</a>)'); |
| 25 | + findNodeForMore(truncated_node).append(' (<a href="#show more content">' + '...more' + '</a>)'); |
| 26 | + findNodeForLess(full_node).append(' (<a href="#show less content">' + ' less' + '</a>)'); |
27 | 27 |
|
28 | | - truncated_node.find('a:last').click(function() { |
| 28 | + truncated_node.find('a:last').click(function () { |
29 | 29 | truncated_node.hide(); full_node.show(); return false; |
30 | 30 | }); |
31 | | - full_node.find('a:last').click(function() { |
| 31 | + full_node.find('a:last').click(function () { |
32 | 32 | truncated_node.show(); full_node.hide(); return false; |
33 | 33 | }); |
34 | 34 |
|
|
51 | 51 | var node = $(node); |
52 | 52 | var new_node = node.clone().empty(); |
53 | 53 | var truncatedChild; |
54 | | - node.contents().each(function() { |
| 54 | + node.contents().each(function () { |
55 | 55 | var remaining_length = max_length - new_node.text().length; |
56 | 56 | if (remaining_length == 0) return; // breaks the loop |
57 | 57 | truncatedChild = recursivelyTruncate(this, remaining_length); |
|
76 | 76 | function squeeze(string) { |
77 | 77 | return string.replace(/\s+/g, ' '); |
78 | 78 | } |
79 | | - |
| 79 | + |
80 | 80 | // Finds the last, innermost block-level element |
81 | 81 | function findNodeForMore(node) { |
82 | 82 | var $node = $(node); |
83 | 83 | var last_child = $node.children(":last"); |
84 | 84 | if (!last_child) return node; |
85 | 85 | var display = last_child.css('display'); |
86 | | - if (!display || display=='inline') return $node; |
| 86 | + if (!display || display == 'inline') return $node; |
87 | 87 | return findNodeForMore(last_child); |
88 | 88 | }; |
89 | 89 |
|
|
0 commit comments