Skip to content

Instantly share code, notes, and snippets.

@conf
Created July 16, 2014 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conf/07319cb73718a163764c to your computer and use it in GitHub Desktop.
Save conf/07319cb73718a163764c to your computer and use it in GitHub Desktop.
<div class="reviews"data-chars="190" data-more="больше" data-less="скрыть">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Vestibulum laoreet, nunc eget laoreet sagittis,
quam ligula sodales orci, congue imperdiet eros tortor ac lectus.
Duis eget nisl orci. Aliquam mattis purus non mauris
blandit id luctus felis convallis.
Integer varius egestas vestibulum.
Nullam a dolor arcu, ac tempor elit. Donec.
</div>
a {
color: #0254EB
}
a.morelink {
text-decoration:none;
}
.morecontent span {
display: none;
}
$(function() {
var reviews = $('.reviews')
var showChar = reviews.data('chars');
var moretext = reviews.data('more');
var lesstext = reviews.data('less');
var ellipsestext = "...";
reviews.each(function() {
var content = $(this).html();
if(content.length > showChar) {
var c = content.substr(0, showChar);
var h = content.substr(showChar-1, content.length - showChar);
var html = c + '<span>' + ellipsestext + '</span><span class="morecontent"><span>' + h + '</span>&nbsp;<a href="" class="morelink">' + moretext + '</a></span>';
$(this).html(html);
}
});
$(".morelink").click(function(){
if($(this).hasClass("less")) {
$(this).removeClass("less");
$(this).html(moretext).hide().fadeIn(300);
} else {
$(this).addClass("less");
$(this).html(lesstext).hide().fadeIn(300);
}
$(this).parent().prev().toggle();
$(this).prev().toggle();
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment