return how many lines text has after truncating it
Opened this issue · 0 comments
i'm using trunk8 to shorten the title and the description of items in a listing.
the maximum number of lines of the description is calculated based on the number of lines used for the title.
<div class="trunkItem" data-trunk-depend="true" data-trunk-text="5" data-trunk-title="3" >
<h2>
<span class="trunkTitle">Some very long title that may span several lines</span>
</h2>
<span class="trunkText">
Some description below. Should be shortened depending on lines used for the title.
</span>
</div>
For data-trunk-title="3"
we should get:
Some very long
title that may span
several lines
------------------------
Some description
below. Should
be shortened ...
------------------------
For data-trunk-title="1"
we should get:
Some very long ...
------------------------
Some description
below. Should
be shortened
depending on lines
used for the title.
------------------------
To make this work i need to calculate the number of lines the title uses after trunk8 did it's job.
I can copy the getLineHeight method you're using, but this means to do the (time consuming) calculation twice.
It would be great to have trunk8 return some information after shorting the title. ie:
$('.trunkTitle').trunk8({lines:3});
should return 1
if the text was short enough to fit into 1 line, 2
if it fits into 2 and 3
means it either fitted into 3 lines, or has been truncated.
if it makes more sense to you we could return more information::
// result just 2 lines, no need to truncate
{
truncated: false,
lines: 2
}
// result 3 lines, no need to truncate
{
truncated: false,
lines: 3
}
can this be done w/o breaking the api (which currently returns the jquery object) to support chaining (`$('.trunkTitle').trunk8().toggleClass('foo')```?
maybe by adding a data attribute data-trunk-nr-lines="3"
that allows other scripts to use this information?