-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextOverflow.js
More file actions
27 lines (24 loc) · 1.42 KB
/
textOverflow.js
File metadata and controls
27 lines (24 loc) · 1.42 KB
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
jQuery(document).ready(function ($) {
(function textOverflow() {
$.each($('p[overflow]'), function(key, value){
var longText = $(value).html();
var overflowLength = $(value).attr('overflow');
var newText = longText;
if (longText.length > 100) {
var newTextList = new Array();
var hiddenTextList = new Array();
$.each(longText.split(' '), function (key, value) {
if (newTextList.join(" ").length < 100) {
newTextList.push(value);
} else {
hiddenTextList.push(value);
}
});
newText = "<span>" + newTextList.join(" ") + "</span> <span action='showmore' class='text_overflow'>more..</span>";
$('.text_overflow').click(function () { $(this).html(hiddenTextList.join(" ")); $(this).unbind('click'); $(this).removeClass('text_overflow'); });
}
$(value).html(newText);
$(value).find('[action~=showmore]').click(function () { $(this).html(hiddenTextList.join(" ")); $(this).unbind('click'); $(this).removeClass('text_overflow'); });
});
}).call(this);
});