Text clamping JS-style. Largely inspired by Joseph Schmitt's $clamp, but largely simplified to avoid the issues that library has.
Initialize a Clamp
instance on an element containing a single text node:
new Clamp(HTMLElement, optionsObject);
Renders clamp based on current layout. Can be used to relayout if layout changes, such as on resize
.
Resets text node to contain original content
Probably the most important option. Specify how many lines you want.
Defines characters to split in prioritized order. Defaults to sentences (periods), hypens, en-dashes, em-dashes, and words (spaces).
Character to append to truncated string. Defaults to a simple ellipsis.
All code here is either created by me or shamelessly stolen from other great libraries. I've tried to attribute authors whenever relevant. Contribute by simply forking your own repository and commit away.
I will review pull requests as quickly as I can.
If anything leaves a bad taste in your mouth, contact info can be found at ljd.dk.
Clamp is licensed under WTFPL.