-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathread_more.js
29 lines (29 loc) · 1.04 KB
/
read_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
$(function() {
$(".content_bio").each(function() {
var $this = $(this);
var originalText = $this.html();
var prefixedOriginalText = "<strong>Bio:</strong> " + originalText;
var shortenedText = prefixedOriginalText.substring(0, 204) + "...";
if (originalText.length > 200) {
$this.data('originalText', prefixedOriginalText);
$this.data('shortenedText', shortenedText);
$this.html(shortenedText);
$this.after("<span class='toggle_text' style='color: blue; cursor: pointer;font-size: 0.8em;'>Read More</span>");
} else {
$this.html(prefixedOriginalText);
}
});
$(document).on("click", ".toggle_text", function() {
var $this = $(this);
var $content = $this.prev(".content_bio");
var originalText = $content.data('originalText');
var shortenedText = $content.data('shortenedText');
if ($content.html() === shortenedText) {
$content.html(originalText);
$this.text('Read Less');
} else {
$content.html(shortenedText);
$this.text('Read More');
}
});
});