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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return how many lines text has after truncating it #62

Open
frisi opened this issue Mar 30, 2015 · 0 comments
Open

return how many lines text has after truncating it #62

frisi opened this issue Mar 30, 2015 · 0 comments

Comments

@frisi
Copy link

frisi commented Mar 30, 2015

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant