Skip to content

Commit

Permalink
changed mind about removing width calc.
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmoore committed Aug 22, 2013
1 parent 682328d commit 6cc075b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
38 changes: 23 additions & 15 deletions jquery.autosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@
resize: ($ta.css('resize') === 'none' || $ta.css('resize') === 'vertical') ? 'none' : 'horizontal'
});

// The mirror width must exactly match the textarea width, so using getBoundingClientRect because it doesn't round the sub-pixel value.
function setWidth() {
var style, width;

if ('getComputedStyle' in window) {
style = window.getComputedStyle(ta);
width = ta.getBoundingClientRect().width;

$.each(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'], function(i,val){
width -= parseInt(style[val],10);
});

mirror.style.width = width + 'px';
}
else {
// window.getComputedStyle, getBoundingClientRect returning a width are unsupported and unneeded in IE8 and lower.
mirror.style.width = Math.max($ta.width(), 0) + 'px';
}
}

function initMirror() {
var styles = {};

Expand All @@ -111,21 +131,7 @@
});
$(mirror).css(styles);

// window.getComputedStyle, getBoundingClientRect returning a width are unsupported/unneeded in IE8 and lower.
// The mirror width must exactly match the textarea width, so using getBoundingClientRect because it doesn't round the sub-pixel value.
if ('getComputedStyle' in window) {
var style = window.getComputedStyle(ta);
var width = ta.getBoundingClientRect().width;

$.each(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'], function(i,val){
width -= parseInt(style[val],10);
});

mirror.style.width = width + 'px';
}
else {
mirror.style.width = Math.max($ta.width(), 0) + 'px';
}
setWidth();

// This code block fixes a Chrome-specific issue:
// The textarea overflow is probably now hidden, but Chrome doesn't reflow the text to account for the
Expand All @@ -145,6 +151,8 @@

if (mirrored !== ta) {
initMirror();
} else {
setWidth();
}

mirror.value = ta.value + options.append;
Expand Down
2 changes: 1 addition & 1 deletion jquery.autosize.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Small jQuery plugin to allow dynamic resizing of textarea height, so that it gro

### v1.17.4 - 2013/8/22
* Improved speed of editing large blocks of text in FireFox.
* No longer accounts for changes in width for a textarea while typing in order to improve performance.

### v1.17.3 - 2013/8/2013
* Resolved an issue that was causing slowing down initialization for large blocks of text in Chrome.
Expand Down

0 comments on commit 6cc075b

Please sign in to comment.