|
79 | 79 | * on the current height of the element and the line-height of the text. |
80 | 80 | */ |
81 | 81 | function getMaxLines(height) { |
82 | | - var availHeight = height || element.clientHeight, |
| 82 | + var availHeight = height || getElemHeight(element), |
83 | 83 | lineHeight = getLineHeight(element); |
84 | 84 |
|
85 | 85 | return Math.max(Math.floor(availHeight / lineHeight), 0); |
|
107 | 107 | return parseInt(lh); |
108 | 108 | } |
109 | 109 |
|
| 110 | + /** |
| 111 | + * Returns the height of an element as an integer (max of scroll/offset/client). |
| 112 | + * Note: inline elements return 0 for scrollHeight and clientHeight |
| 113 | + */ |
| 114 | + function getElemHeight(elem) { |
| 115 | + return Math.max(elem.scrollHeight, elem.offsetHeight, elem.clientHeight); |
| 116 | + } |
| 117 | + |
110 | 118 | // MEAT AND POTATOES (MMMM, POTATOES...) ______________________________________ |
111 | 119 | var splitOnChars = opt.splitOnChars.slice(0), |
112 | 120 | splitChar = splitOnChars[0], |
|
198 | 206 | //Search produced valid chunks |
199 | 207 | if (chunks) { |
200 | 208 | //It fits |
201 | | - if (element.clientHeight <= maxHeight) { |
| 209 | + if (getElemHeight(element) <= maxHeight) { |
202 | 210 | //There's still more characters to try splitting on, not quite done yet |
203 | 211 | if (splitOnChars.length >= 0 && splitChar != "") { |
204 | 212 | applyEllipsis( |
|
252 | 260 |
|
253 | 261 | var clampedText, |
254 | 262 | height = getMaxHeight(clampValue), |
255 | | - isHigher = height < element.clientHeight; |
| 263 | + isHigher = height < getElemHeight(element); |
256 | 264 | if (supportsNativeClamp && opt.useNativeClamp) { |
257 | 265 | sty.overflow = "hidden"; |
258 | 266 | sty.textOverflow = "ellipsis"; |
|
0 commit comments