Created
July 29, 2016 12:01
-
-
Save autioch/61c085ec8da883d23438e3301e359a9d to your computer and use it in GitHub Desktop.
Ellipsing rows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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