From f8daa2717660d19f2dfdcbded60d9b3e77c6f902 Mon Sep 17 00:00:00 2001 From: Jack Moore Date: Fri, 10 Jan 2014 21:26:56 -0500 Subject: [PATCH] =?UTF-8?q?Allow=20correct=20width=20calculation=20of=20hi?= =?UTF-8?q?dden=20textarea=20elements,=20when=20they=20have=20a=20specifie?= =?UTF-8?q?d=20width.=20=20Fixes=20#134=20(fixes=20minor=20issues=20with?= =?UTF-8?q?=20nealbowers=E2=80=99=20commit.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- autosize.jquery.json | 2 +- bower.json | 2 +- jquery.autosize.js | 19 +++++++++++-------- jquery.autosize.min.js | 4 ++-- package.json | 2 +- readme.md | 3 +++ 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/autosize.jquery.json b/autosize.jquery.json index 38dd13c..02d94c8 100644 --- a/autosize.jquery.json +++ b/autosize.jquery.json @@ -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" }, diff --git a/bower.json b/bower.json index 88eb522..0111da5 100644 --- a/bower.json +++ b/bower.json @@ -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" }, diff --git a/jquery.autosize.js b/jquery.autosize.js index 8b31a7e..f478a82 100644 --- a/jquery.autosize.js +++ b/jquery.autosize.js @@ -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 @@ -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() { diff --git a/jquery.autosize.min.js b/jquery.autosize.min.js index b22a242..3f7375f 100644 --- a/jquery.autosize.min.js +++ b/jquery.autosize.min.js @@ -1,7 +1,7 @@ /*! - 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 */ -(function(e){var t,o={className:"autosizejs",append:"",callback:!1,resizeDelay:10},i='