pvdspek / jquery.autoellipsis

Auto-ellipsis plugin for jQuery
http://pvdspek.github.com/jquery.autoellipsis
MIT License
142 stars 32 forks source link

Improved string shortening for CJK languages. #27

Open jameswilson opened 11 years ago

jameswilson commented 11 years ago

When you are trying to trim a string that contains CJK characters or even a string of western characters that don't have any spaces, then the entire string is stripped.

This pull request adds two bits of functionality:

1) Break words using spaces, dashes, zero-width space characters, and other standard word-break characters that work in most modern browsers.

2) If no word-break is found in the string, fall back to letter removal.

There are a few other minor js lint cleanups (trailing whitespace, empty line at end of file) that my editor cleaned up automatically and included in this commit as well.

Here are two fiddles that demonstrate the issue, and the fix: and the second with the patched code.

jquery.autoellipsis version 1.0.10 without the patch http://jsfiddle.net/jwilson3/XKN9R/1/

jquery.autoellipsis with the patch applied in commit 0298b42 http://jsfiddle.net/jwilson3/XKN9R/3/