diff --git a/autosize.jquery.json b/autosize.jquery.json index 207466e..103401e 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.17.3", + "version": "1.17.4", "dependencies": { "jquery": ">=1.7" }, diff --git a/bower.json b/bower.json index d088b46..f2bf6b9 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.17.3", + "version": "1.17.4", "dependencies": { "jquery": ">=1.7" }, diff --git a/jquery.autosize.js b/jquery.autosize.js index 18d537d..3fe9ce1 100644 --- a/jquery.autosize.js +++ b/jquery.autosize.js @@ -1,5 +1,5 @@ /*! - Autosize v1.17.3 - 2013-08-21 + Autosize v1.17.4 - 2013-08-22 Automatically adjust textarea height based on user input. (c) 2013 Jack Moore - http://www.jacklmoore.com/autosize license: http://www.opensource.org/licenses/mit-license.php @@ -111,6 +111,23 @@ }); $(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'; + } + + // 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 // new space made available by removing the scrollbars. This workaround causes Chrome to reflow the text. if ('oninput' in ta && 'setSelectionRange' in ta) { @@ -124,7 +141,7 @@ // Using mainly bare JS in this function because it is going // to fire very often while typing, and needs to very efficient. function adjust() { - var height, original, width, style; + var height, original; if (mirrored !== ta) { initMirror(); @@ -134,22 +151,6 @@ mirror.style.overflowY = ta.style.overflowY; original = parseInt(ta.style.height,10); - // window.getComputedStyle, getBoundingClientRect returning a width are unsupported 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) { - 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 { - mirror.style.width = Math.max($ta.width(), 0) + 'px'; - } - // Needed for IE8 and lower to reliably return the correct scrollTop mirror.scrollTop = 0; @@ -181,7 +182,10 @@ function resize () { clearTimeout(timeout); timeout = setTimeout(function(){ - if ($ta.width() !== width) { + var newWidth = $ta.width(); + + if (newWidth !== width) { + width = newWidth; adjust(); } }, parseInt(options.resizeDelay,10)); diff --git a/jquery.autosize.min.js b/jquery.autosize.min.js index 9fdf4c6..0446e6d 100644 --- a/jquery.autosize.min.js +++ b/jquery.autosize.min.js @@ -1,7 +1,7 @@ /*! - Autosize v1.17.3 - 2013-08-21 + Autosize v1.17.4 - 2013-08-22 Automatically adjust textarea height based on user input. (c) 2013 Jack Moore - http://www.jacklmoore.com/autosize license: http://www.opensource.org/licenses/mit-license.php */ -(function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e(window.jQuery||window.$)})(function(e){var t,o={className:"autosizejs",append:"",callback:!1,resizeDelay:10},i='