-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathjquery.show-more.js
65 lines (46 loc) · 2.38 KB
/
jquery.show-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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(function ( $ ) {
/*
Plugin: ShowMore
author: dtasic@gmail.com
*/
$.fn.showMore = function (options) {
"use strict";
var currentelem = 1;
this.each(function(){
var currentid = '';
var element = $(this);
var auto = parseInt(element.innerHeight())/2;
var fullheight = element.innerHeight();
var maxWidth = element.css('width');
var settings = $.extend({
minheight: auto,
buttontxtmore: "show more",
buttontxtless: "show less",
buttoncss: "showmore-button",
animationspeed: auto
}, options );
element.attr('id') != undefined ? currentid = element.attr('id') : currentid = currentelem;
element.wrap( "<div id='showmore-"+currentid+"' data-showmore"+(maxWidth == '0px' ? "" : " style='max-width:"+maxWidth+";'")+"></div>" );
if (element.parent().not('[data-showmore]')) {
if (fullheight > settings.minheight) {
element.css('min-height', settings.minheight).css('max-height', settings.minheight).css('overflow', 'hidden');
var showMoreButton = $("<div />", {
id: "showmore-button-"+currentid,
"class": settings.buttoncss,
click: function() {
if (element.css('max-height') != 'none') {
element.css('height', settings.minheight).css('max-height', '').animate({height:fullheight}, settings.animationspeed, function () { showMoreButton.html(settings.buttontxtless); });
} else {
element.animate({height:settings.minheight}, settings.animationspeed, function () { showMoreButton.html(settings.buttontxtmore); element.css('max-height', settings.minheight); });
}
},
html: settings.buttontxtmore
});
element.after(showMoreButton);
}
currentelem++;
}
});
return this;
};
}(jQuery));