diff --git a/clamp.js b/clamp.js index f13e8ad..777bfe9 100644 --- a/clamp.js +++ b/clamp.js @@ -1,5 +1,5 @@ /*! -* Clamp.js 0.5.1 +* Clamp.js 0.5.2 * * Copyright 2011-2013, Joseph Schmitt http://joe.sh * Released under the WTFPL license @@ -74,7 +74,7 @@ * on the current height of the element and the line-height of the text. */ function getMaxLines(height) { - var availHeight = height || element.clientHeight, + var availHeight = height || getElemHeight(element), lineHeight = getLineHeight(element); return Math.max(Math.floor(availHeight/lineHeight), 0); @@ -101,6 +101,15 @@ } return parseInt(lh); } + + /** + * Returns the height of an element as an integer (max of scroll/offset/client). + * Note: inline elements return 0 for scrollHeight and clientHeight + */ + function getElemHeight(elem) { + return Math.max(elem.scrollHeight, elem.offsetHeight, elem.clientHeight); + } + // MEAT AND POTATOES (MMMM, POTATOES...) ______________________________________ @@ -183,7 +192,7 @@ //Search produced valid chunks if (chunks) { //It fits - if (element.clientHeight <= maxHeight) { + if (getElemHeight(element) <= maxHeight) { //There's still more characters to try splitting on, not quite done yet if (splitOnChars.length >= 0 && splitChar != '') { applyEllipsis(target, chunks.join(splitChar) + splitChar + lastChunk); @@ -246,7 +255,7 @@ } else { var height = getMaxHeight(clampValue); - if (height <= element.clientHeight) { + if (height <= getElemHeight(element)) { clampedText = truncate(getLastChild(element), height); } } diff --git a/clamp.min.js b/clamp.min.js index 2d8783a..334f36a 100644 --- a/clamp.min.js +++ b/clamp.min.js @@ -1,12 +1,12 @@ /*! -* Clamp.js 0.5.1 +* Clamp.js 0.5.2 * * Copyright 2011-2013, Joseph Schmitt http://joe.sh * Released under the WTFPL license * http://sam.zoy.org/wtfpl/ */ -(function(){window.$clamp=function(c,d){function s(a,b){n.getComputedStyle||(n.getComputedStyle=function(a,b){this.el=a;this.getPropertyValue=function(b){var c=/(\-([a-z]){1})/g;"float"==b&&(b="styleFloat");c.test(b)&&(b=b.replace(c,function(a,b,c){return c.toUpperCase()}));return a.currentStyle&&a.currentStyle[b]?a.currentStyle[b]:null};return this});return n.getComputedStyle(a,null).getPropertyValue(b)}function t(a){a=a||c.clientHeight;var b=u(c);return Math.max(Math.floor(a/b),0)}function x(a){return u(c)* -a}function u(a){var b=s(a,"line-height");"normal"==b&&(b=1.2*parseInt(s(a,"font-size")));return parseInt(b)}function l(a){if(a.lastChild.children&&0