diff --git a/clamp.js b/clamp.js index f13e8ad..936c8fa 100644 --- a/clamp.js +++ b/clamp.js @@ -86,7 +86,7 @@ */ function getMaxHeight(clmp) { var lineHeight = getLineHeight(element); - return lineHeight * clmp; + return lineHeight * clmp + (parseInt(getComputedStyle(element).paddingTop.split("px")[0], 10) + parseInt(getComputedStyle(element).paddingBottom.split("px")[0], 10)); } /** @@ -99,7 +99,7 @@ // a value between 1.0 and 1.2 of the font size. Using 1.1 to split the diff. lh = parseInt(computeStyle(elem, 'font-size')) * 1.2; } - return parseInt(lh); + return Math.round(parseFloat(lh)); } diff --git a/clamp.min.js b/clamp.min.js index 2d8783a..357ebfe 100644 --- a/clamp.min.js +++ b/clamp.min.js @@ -5,8 +5,4 @@ * 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&&00?r(Array.prototype.slice.call(e.children).pop()):e.lastChild&&e.lastChild.nodeValue&&""!=e.lastChild.nodeValue&&e.lastChild.nodeValue!=h.truncationChar?e.lastChild:(e.lastChild.parentNode.removeChild(e.lastChild),r(t))}function o(e,n){function i(){y=h.splitOnChars.slice(0),H=y[0],v=null,g=null}if(n){var a=e.nodeValue.replace(h.truncationChar,"");if(v||(H=y.length>0?y.shift():"",v=a.split(H)),v.length>1?(g=v.pop(),u(e,v.join(H))):v=null,c&&(e.nodeValue=e.nodeValue.replace(h.truncationChar,""),t.innerHTML=e.nodeValue+" "+c.innerHTML+h.truncationChar),v){if(t.clientHeight<=n){if(y.length<0||""==H)return t.innerHTML;u(e,v.join(H)+H+g),v=null}}else""==H&&(u(e,""),e=r(t),i());return h.animate?void setTimeout(function(){o(e,n)},h.animate===!0?10:h.animate):o(e,n)}}function u(t,e){t.nodeValue=e+h.truncationChar}e=e||{};var c,s=window,h={clamp:e.clamp||2,useNativeClamp:void 0!==e.useNativeClamp?e.useNativeClamp:!0,splitOnChars:e.splitOnChars||[".","-","–","—"," "],animate:e.animate||!1,truncationChar:e.truncationChar||"…",truncationHTML:e.truncationHTML},p=t.style,d=t.innerHTML,C=void 0!==t.style.webkitLineClamp,f=h.clamp,m=f.indexOf&&(f.indexOf("px")>-1||f.indexOf("em")>-1);h.truncationHTML&&(c=document.createElement("span"),c.innerHTML=h.truncationHTML);var v,g,y=h.splitOnChars.slice(0),H=y[0];"auto"==f?f=i():m&&(f=i(parseInt(f)));var M;if(C&&h.useNativeClamp)p.overflow="hidden",p.textOverflow="ellipsis",p.webkitBoxOrient="vertical",p.display="-webkit-box",p.webkitLineClamp=f,m&&(p.height=h.clamp+"px");else{var L=a(f);L>t.clientHeight||(M=o(r(t),L))}return{original:d,clamped:M}}window.$clamp=t}(); \ No newline at end of file