Skip to content

Commit

Permalink
Use "parseFloat" instead of "parseInt" for when sub-pixel css values …
Browse files Browse the repository at this point in the history
…are used
  • Loading branch information
njam committed Nov 11, 2014
1 parent 6abe756 commit bff4a29
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions jquery.autosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
}

// IE8 and lower return 'auto', which parses to NaN, if no min-height is set.
minHeight = Math.max(parseInt($ta.css('minHeight'), 10) - boxOffset || 0, $ta.height());
minHeight = Math.max(parseFloat($ta.css('minHeight')) - boxOffset || 0, $ta.height());

$ta.css({
overflow: 'hidden',
Expand All @@ -103,17 +103,17 @@
function setWidth() {
var width;
var style = window.getComputedStyle ? window.getComputedStyle(ta, null) : false;

if (style) {

width = ta.getBoundingClientRect().width;

if (width === 0 || typeof width !== 'number') {
width = parseInt(style.width,10);
width = parseFloat(style.width);
}

$.each(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'], function(i,val){
width -= parseInt(style[val],10);
width -= parseFloat(style[val]);
});
} else {
width = $ta.width();
Expand All @@ -128,7 +128,7 @@
mirrored = ta;
mirror.className = options.className;
mirror.id = options.id;
maxHeight = parseInt($ta.css('maxHeight'), 10);
maxHeight = parseFloat($ta.css('maxHeight'));

// mirror is a duplicate textarea located off-screen that
// is automatically updated to contain the same text as the
Expand All @@ -138,7 +138,7 @@
$.each(typographyStyles, function(i,val){
styles[val] = $ta.css(val);
});

$(mirror).css(styles).attr('wrap', $ta.attr('wrap'));

setWidth();
Expand Down Expand Up @@ -166,8 +166,8 @@
}

if (!ta.value && options.placeholder) {
// If the textarea is empty, copy the placeholder text into
// the mirror control and use that for sizing so that we
// If the textarea is empty, copy the placeholder text into
// the mirror control and use that for sizing so that we
// don't end up with placeholder getting trimmed.
mirror.value = ($ta.attr("placeholder") || '');
} else {
Expand All @@ -176,7 +176,7 @@

mirror.value += options.append || '';
mirror.style.overflowY = ta.style.overflowY;
original = parseInt(ta.style.height,10);
original = parseFloat(ta.style.height);

// Setting scrollTop to zero is needed in IE8 and lower for the next step to be accurately applied
mirror.scrollTop = 0;
Expand Down

0 comments on commit bff4a29

Please sign in to comment.