Skip to content

Commit

Permalink
Allow correct width calculation of hidden textarea elements, when the…
Browse files Browse the repository at this point in the history
…y have a specified width. Fixes jackmoore#134

(fixes minor issues with nealbowers’ commit.)
  • Loading branch information
jackmoore committed Jan 11, 2014
1 parent ec26d7c commit f8daa27
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion autosize.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "autosize",
"title": "Autosize",
"description": "Automatically adjust textarea height based on user input.",
"version": "1.18.2",
"version": "1.18.3",
"dependencies": {
"jquery": ">=1.7"
},
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jquery-autosize",
"description": "Automatically adjust textarea height based on user input.",
"version": "1.18.2",
"version": "1.18.3",
"dependencies": {
"jquery": ">=1.7"
},
Expand Down
19 changes: 11 additions & 8 deletions jquery.autosize.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
Autosize v1.18.2 - 2014-01-06
Autosize v1.18.3 - 2014-01-10
Automatically adjust textarea height based on user input.
(c) 2014 Jack Moore - http://www.jacklmoore.com/autosize
license: http://www.opensource.org/licenses/mit-license.php
Expand Down Expand Up @@ -91,24 +91,27 @@
});

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

if (style) {

width = ta.getBoundingClientRect().width;

if (width === 0) {
width = parseInt(style.width,10);
}

$.each(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'], function(i,val){
width -= parseInt(style[val],10);
});
} else {
width = Math.max($ta.width(), 0);
}
if (!style || width == 0) {
// window.getComputedStyle, getBoundingClientRect returning a width are unsupported and unneeded in IE8 and lower.
// In some situations, if the element is offscreen, then the above approach will result in 0 width,
// but the approach below works.
mirror.style.width = Math.max($ta.width(), 0);
}
mirror.style.width = width + 'px';

mirror.style.width = width + 'px';
}

function initMirror() {
Expand Down
4 changes: 2 additions & 2 deletions jquery.autosize.min.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jquery-autosize",
"description": "Automatically adjust textarea height based on user input.",
"version": "1.18.2",
"version": "1.18.3",
"dependencies": {},
"keywords": [
"form",
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Small jQuery plugin to allow dynamic resizing of textarea height, so that it gro

## Changelog

### v1.18.3 - 2014/1/10
* Allow correct width calculation of hidden textarea elements, when they have a specified width. Fixes #134

### v1.18.2 - 2014/1/6
* Checked getComputedStyle return value to avoid potential error exception. Fixes #133

Expand Down

0 comments on commit f8daa27

Please sign in to comment.