rviscomi / trunk8

jQuery Truncation Plugin -- THIS PROJECT IS NO LONGER MAINTAINED
MIT License
703 stars 95 forks source link

Adds css class to trunk8ed element (if really too long) #33

Closed simonferndriger closed 11 years ago

simonferndriger commented 11 years ago

This enables you to style your trunk8ed text differently than non trunk8ed text by adding a css class to the options. The css class is removed after restoring the text to original. My use case: This makes it possible to add a cursor:pointer to the text when trunk8ed to signal that the text can be clicked to show the full text.

rviscomi commented 11 years ago

This is doable without modifying the core trunk8 module.

For example:

$('.too-long').trunk8().addClass('some-class');
// ...
$('.too-long').trunk8('revert').removeClass('some-class');
simonferndriger commented 11 years ago

Actually, no. Because, if the text is NOT too long and does NOT get cut, the class will be added anyway. But I only want to add the class IN CASE the string was actually cut. At least that is the outcome when I tried it out. Also - if it would only give back the elment IN CASE the text was actually cut, it would be inconsistent with the general presumtion that every jQuery method gives back the element (in ANY case).

Or did I miss something?

rviscomi commented 11 years ago

Your pull request does not do what you're describing. It does what I wrote earlier: always adds the class on trunk8 and always removes the class on revert.

trunk8 always returns this to maintain chainability unless otherwise noted in the documentation.

simonferndriger commented 11 years ago

Oh, shoot. You are right. Sorry, I made a mistake when testing it. Unfortunately, I think there would be an additional variable needed to indicate whether the text was cut - nor not. Can you perhaps point out how this could be done the easiest way?

It would also make sense to also only add the title attribute when the text was cut. Otherwise it is not necessary (I was assuming this would already be the case, sorry).