Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blog's page read-more button implemented #5449

Merged
merged 1 commit into from Apr 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 39 additions & 1 deletion app/views/tag/blog2.html.erb
Expand Up @@ -10,7 +10,7 @@
This is basic html layout
</h3>
<hr>
<p>
<p class="more">
Here is the lorem ipsum content
<br>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
Expand Down Expand Up @@ -80,4 +80,42 @@
margin-right:1em;
margin-left:1em;
}
.more-content span {
display: none;
}
.more-link {
width: 150px;
}
.more-button{
text-align: center;
margin: 20px;
}
</style>
<script>
$(document).ready(function() {
var showChar = 300; // How many characters are shown by default
var moretext = "Read more";
var lesstext = "Read less";
$('.more').each(function() {
var content = $(this).html();
if(content.length > showChar) {
var c = content.substr(0, showChar);
var h = content.substr(showChar, content.length - showChar);
var html = c + '<span class="moreellipses">' + '</span><span class="more-content"><span>' + h + '</span>&nbsp;&nbsp;<div class="more-button"><a class="btn btn-default more-link">' + moretext + '</a></div></span>';
$(this).html(html);
}
});
$(".more-link").click(function(){
if($(this).hasClass("less")) {
$(this).removeClass("less");
$(this).html(moretext);
} else {
$(this).addClass("less");
$(this).html(lesstext);
}
$(this).parent().prev().toggle();
$(this).prev().toggle();
return false;
});
});
</script>