-
Notifications
You must be signed in to change notification settings - Fork 0
/
more.js
40 lines (35 loc) · 1.11 KB
/
more.js
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
jQuery.fn.shorten = function(settings) {
var config = {
showChars : 100,
ellipsesText : "...",
moreText : "more",
lessText : "less"
};
if (settings) {
$.extend(config, settings);
}
$('.morelink').live('click', function() {
var $this = $(this);
if ($this.hasClass('less')) {
$this.removeClass('less');
$this.html(config.moreText);
} else {
$this.addClass('less');
$this.html(config.lessText);
}
$this.parent().prev().toggle();
$this.prev().toggle();
return false;
});
return this.each(function() {
var $this = $(this);
var content = $this.html();
if (content.length > config.showChars) {
var c = content.substr(0, config.showChars);
var h = content.substr(config.showChars , content.length - config.showChars);
var html = c + '<span class="moreellipses">' + config.ellipsesText + ' </span><span class="morecontent"><span>' + h + '</span> <a href="javascript://nop/" class="morelink">' + config.moreText + '</a></span>';
$this.html(html);
$(".morecontent span").hide();
}
});
}