-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.expander.js
More file actions
30 lines (29 loc) · 904 Bytes
/
jquery.expander.js
File metadata and controls
30 lines (29 loc) · 904 Bytes
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
/**
* Expander jquery plugin
* Author: Pham Loc
* admin@taigame.org
*
* Add 'read more...' link to a content block
* Styles for content block: position: relative, overflow: none, max-height: {custom max height}
*/
(function( $ ){
$.fn.expander = function(options) {
var settings = $.extend({
moreText: 'Xem thêm...',
click: null // callback function on clicking "show more"
}, options );
return this.each(function() {
var el = this;
if ($(el)[0].offsetHeight < $(el)[0].scrollHeight) {
$('<div class="expander-more"><a href="javascript:;">'+settings.moreText+'</a></div>').appendTo(this).find('a').click(function() {
if (settings.click === null) {
$(this).parent().hide();
$(el).css('max-height', 'none');
} else if (typeof(settings.click) === 'function') {
settings.click.call(el);
}
});
}
});
};
})( jQuery );