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

Added hysteresis to length, clickable "…more" #440

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

stibinator
Copy link

I added some hysteresis to the cutoff length to avoid the situation where a block of text that is one word longer than the cutoff gets truncated. By making the cutoff say, 1.5 times the length of the final text you can only truncate text that is significantly longer than the cutoff. So if your length is 60 you'll end up with text from 60-90 chars in length, and any that are over 90 get truncated to 60. This gives a much more pleasing result.

Example, using the three sentence below:
source

Let's say the length was 30 chars.
the previous sentence would lose just last word because it is 31 chars long.
This one wouldn't.

default way

Let's say the length was 30…
the previous sentence would be…
This one wouldn't.

my way

Let's say the length was 30 chars.
the previous sentence would be…
This one wouldn't.

Also I added a clickable …more tag at the truncation point, that toggles the visibility of the truncated text. This is a bit^h^h^h^h totally kludgy, I'm not a web designer, but it works for my use.

@DataTables
Copy link
Collaborator

Interesting idea - thanks for posting this. I wonder if one option would be to give the developer the option of specifying two parameters - the point at which truncation would being, and what it would be cut down to? In this case, you could specify a truncation point of 60 and have it cut down to 30?

@stibinator
Copy link
Author

For backwards compatibility you could have an optional second parameter, so if there's one parameter it's a hard cut off, and the second parameter would define the soft cut off.

@stibinator
Copy link
Author

I added the second cutoff parameter, but for backwards compatibility it should probably go at the end of the parameter list.
I also de-kludgified the clickable …more link, so that it actually works. I read a bit about how the DOM works and used nextSibling instead of trying to synthesis an id for the hidden text.

@DataTables
Copy link
Collaborator

Nice one thanks! I'll get this reviewed before the next release.

@DataTables
Copy link
Collaborator

Btw - are you happy for this to be included under the MIT license?

@stibinator
Copy link
Author

Sure thing.

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

Successfully merging this pull request may close these issues.

2 participants