Skip to content

Instantly share code, notes, and snippets.

@autioch
Created July 29, 2016 12:01
Show Gist options
  • Save autioch/61c085ec8da883d23438e3301e359a9d to your computer and use it in GitHub Desktop.
Save autioch/61c085ec8da883d23438e3301e359a9d to your computer and use it in GitHub Desktop.
Ellipsing rows
module.exports = function ellipseRow(el) {
var maxLines = parseInt(el.getAttribute('max-rows'), 10);
var lineHeight = parseInt(getComputedStyle(el, null).getPropertyValue('line-height'), 10);
var padding = parseInt(getComputedStyle(el, null).getPropertyValue('padding'), 10);
var maxHeight = lineHeight * maxLines + 2 * padding;
var hiddenBrandCount = 0;
while (el.offsetHeight > maxHeight) {
hiddenBrandCount++;
el.textContent = el.textContent.substring(0, el.textContent.lastIndexOf(', '));
el.textContent += ' and ' + hiddenBrandCount + 'more';
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment