wireframe (owner)

Revisions

gist: 75088 Download_button fork
public
Description:
jquery plugin to truncate elements based on height instead of number of characters
Public Clone URL: git://gist.github.com/75088.git
Embed All Files: show embed
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
truncates elements that pass a certain height.
adds a "view more" link to display the rest of the content.
 
a different approach than standard truncation which relies on character counting.
character counting may not be desireable when elements have short words, but a
number of line breaks.
 
usage:
  //using defaults
  $('css_expression').summary();
  
  //overriding options
  $('css_expression').summary({maxHeight: 200, className: 'view-more'});
*/
(function($) {
  $.fn.summary = function(options) {
return this.each(function() {
new $.Summary(this, options);
});
};
 
$.Summary = function(e, o) {
var element = $(e);
var options = o || {};
    var maxHeight = options.maxHeight || 100;
    var className = options.className || 'expand';
    var textHeight = e.offsetHeight;
    
    if (textHeight > maxHeight) {
      element.css({overflow: 'hidden'});
      element.height(maxHeight);
 
      var moreLink = $("<a>View More</a>").click(expand).addClass(className);
      element.after(moreLink);
    }
    
function expand() {
element.animate({height: textHeight}, 'fast');
moreLink.hide();
};
};
})(jQuery);