I've been looking into making an angular directive that would shorten a paragraph or a div if it has more than a certain number of characters(115 for example).
I haven't been able to find anything that will work for me, I've seen the http://dotdotdot.frebsite.nl/ and that has worked for some people but I am trying to make it using an angular directive and not JQuery.
If there's any help that someone can offer, it would be greatly appreciated, i am essentially tapped out of ideas.
The is the way my view is setup:
<div class="Description"
<div class="Content">
<div data-ng-bind-html="item.Description"></div>
</div>
I had originally made it work by just having it as jquery like so but it wasn't advisable to just jquery and angular
$(function () {
var maxHeight = 115;
var moretext = Localization.Shared.InstitutionProfileStrings.ShowMore();
var lesstext = Localization.Shared.InstitutionProfileStrings.ShowLess();
$('.__Description').each(function () {
var content = $(this).find(".__Content");
var anchor = $(this).find(".morelink");
if ($(content).height() > maxHeight) {
$(this).addClass("less");
$(anchor).html(moretext);
$(anchor).show();
}
else {
$(anchor).hide();
}
});
$(".morelink").click(function (e) {
e.preventDefault();
var parent = this.parentElement;
if ($(parent).hasClass("less")) {
$(parent).removeClass("less");
$(this).html(lesstext);
$(parent).addClass("more");
}
else if ($(parent).hasClass("more")) {
$(parent).removeClass("more");
$(this).html(moretext);
$(parent).addClass("less");
}
return false;
});
});