Added hysteresis to length, clickable "…more"#440
Added hysteresis to length, clickable "…more"#440stibinator wants to merge 2 commits intoDataTables:masterfrom
Conversation
|
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? |
|
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. |
|
I added the second cutoff parameter, but for backwards compatibility it should probably go at the end of the parameter list. |
|
Nice one thanks! I'll get this reviewed before the next release. |
|
Btw - are you happy for this to be included under the MIT license? |
|
Sure thing. |
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
default way
my way
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.