-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhide_paragraphs.js
42 lines (37 loc) · 1.11 KB
/
hide_paragraphs.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
41
42
(function($) {
$.fn.hideParagraphs = function(options) {
var defaults = {
show: 1,
show_text: "Show more",
hide_text: "Hide",
link_class: "hp-links",
transition_duration: 400
};
var options = $.extend(defaults, options);
return this.each(
function() {
var paragraphs = $(this).children("p");
if (paragraphs.length <= options.show) {
return;
}
var visible = paragraphs.slice(0, options.show);
var invisible = paragraphs.slice(options.show);
invisible.hide();
var link = $("<a href='#'>" + options.show_text + "</a>").
addClass(options.link_class);
$(this).append(link.wrap("<p></p>").parent());
link.click(function() {
if( $(this).html() == options.show_text ) {
$(this).html(options.hide_text);
invisible.show(options.transition_duration);
}
else {
$(this).html(options.show_text);
invisible.hide(options.transition_duration);
}
return false;
});
}
);
};
})(jQuery);