diff --git a/jquery.autosize.js b/jquery.autosize.js
index 3fe9ce1..5d3a77d 100644
--- a/jquery.autosize.js
+++ b/jquery.autosize.js
@@ -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 = {};
@@ -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
@@ -145,6 +151,8 @@
if (mirrored !== ta) {
initMirror();
+ } else {
+ setWidth();
}
mirror.value = ta.value + options.append;
diff --git a/jquery.autosize.min.js b/jquery.autosize.min.js
index 0446e6d..dc68468 100644
--- a/jquery.autosize.min.js
+++ b/jquery.autosize.min.js
@@ -4,4 +4,4 @@
(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='',n=["fontFamily","fontSize","fontWeight","fontStyle","letterSpacing","textTransform","wordSpacing","textIndent"],s=e(i).data("autosize",!0)[0];s.style.lineHeight="99px","99px"===e(s).css("lineHeight")&&n.push("lineHeight"),s.style.lineHeight="",e.fn.autosize=function(i){return i=e.extend({},o,i||{}),s.parentNode!==document.body&&e(document.body).append(s),this.each(function(){function o(){var o={};if(t=u,s.className=i.className,l=parseInt(h.css("maxHeight"),10),e.each(n,function(e,t){o[t]=h.css(t)}),e(s).css(o),"getComputedStyle"in window){var a=window.getComputedStyle(u),r=u.getBoundingClientRect().width;e.each(["paddingLeft","paddingRight","borderLeftWidth","borderRightWidth"],function(e,t){r-=parseInt(a[t],10)}),s.style.width=r+"px"}else s.style.width=Math.max(h.width(),0)+"px";if("oninput"in u&&"setSelectionRange"in u){var c=u.selectionStart;u.value+=" ",u.value=u.value.slice(0,-1),u.setSelectionRange(c,c)}}function a(){var e,n;t!==u&&o(),s.value=u.value+i.append,s.style.overflowY=u.style.overflowY,n=parseInt(u.style.height,10),s.scrollTop=0,s.scrollTop=9e4,e=s.scrollTop,l&&e>l?(u.style.overflowY="scroll",e=l):(u.style.overflowY="hidden",c>e&&(e=c)),e+=p,n!==e&&(u.style.height=e+"px",f&&i.callback.call(u,u))}function r(){clearTimeout(d),d=setTimeout(function(){var e=h.width();e!==z&&(z=e,a())},parseInt(i.resizeDelay,10))}var l,c,d,u=this,h=e(u),p=0,f=e.isFunction(i.callback),w={height:u.style.height,overflow:u.style.overflow,overflowY:u.style.overflowY,wordWrap:u.style.wordWrap,resize:u.style.resize},z=h.width();h.data("autosize")||(h.data("autosize",!0),("border-box"===h.css("box-sizing")||"border-box"===h.css("-moz-box-sizing")||"border-box"===h.css("-webkit-box-sizing"))&&(p=h.outerHeight()-h.height()),c=Math.max(parseInt(h.css("minHeight"),10)-p||0,h.height()),h.css({overflow:"hidden",overflowY:"hidden",wordWrap:"break-word",resize:"none"===h.css("resize")||"vertical"===h.css("resize")?"none":"horizontal"}),"onpropertychange"in u?"oninput"in u?h.on("input.autosize keyup.autosize",a):h.on("propertychange.autosize",function(){"value"===event.propertyName&&a()}):h.on("input.autosize",a),i.resizeDelay!==!1&&e(window).on("resize.autosize",r),h.on("autosize.resize",a),h.on("autosize.resizeIncludeStyle",function(){t=null,a()}),h.on("autosize.destroy",function(){t=null,clearTimeout(d),e(window).off("resize",r),h.off("autosize").off(".autosize").css(w).removeData("autosize")}),a())})}});
\ No newline at end of file
+(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='',n=["fontFamily","fontSize","fontWeight","fontStyle","letterSpacing","textTransform","wordSpacing","textIndent"],s=e(i).data("autosize",!0)[0];s.style.lineHeight="99px","99px"===e(s).css("lineHeight")&&n.push("lineHeight"),s.style.lineHeight="",e.fn.autosize=function(i){return i=e.extend({},o,i||{}),s.parentNode!==document.body&&e(document.body).append(s),this.each(function(){function o(){var t,o;"getComputedStyle"in window?(t=window.getComputedStyle(h),o=h.getBoundingClientRect().width,e.each(["paddingLeft","paddingRight","borderLeftWidth","borderRightWidth"],function(e,i){o-=parseInt(t[i],10)}),s.style.width=o+"px"):s.style.width=Math.max(p.width(),0)+"px"}function a(){var a={};if(t=h,s.className=i.className,c=parseInt(p.css("maxHeight"),10),e.each(n,function(e,t){a[t]=p.css(t)}),e(s).css(a),o(),"oninput"in h&&"setSelectionRange"in h){var r=h.selectionStart;h.value+=" ",h.value=h.value.slice(0,-1),h.setSelectionRange(r,r)}}function r(){var e,n;t!==h?a():o(),s.value=h.value+i.append,s.style.overflowY=h.style.overflowY,n=parseInt(h.style.height,10),s.scrollTop=0,s.scrollTop=9e4,e=s.scrollTop,c&&e>c?(h.style.overflowY="scroll",e=c):(h.style.overflowY="hidden",d>e&&(e=d)),e+=f,n!==e&&(h.style.height=e+"px",w&&i.callback.call(h,h))}function l(){clearTimeout(u),u=setTimeout(function(){var e=p.width();e!==g&&(g=e,r())},parseInt(i.resizeDelay,10))}var c,d,u,h=this,p=e(h),f=0,w=e.isFunction(i.callback),z={height:h.style.height,overflow:h.style.overflow,overflowY:h.style.overflowY,wordWrap:h.style.wordWrap,resize:h.style.resize},g=p.width();p.data("autosize")||(p.data("autosize",!0),("border-box"===p.css("box-sizing")||"border-box"===p.css("-moz-box-sizing")||"border-box"===p.css("-webkit-box-sizing"))&&(f=p.outerHeight()-p.height()),d=Math.max(parseInt(p.css("minHeight"),10)-f||0,p.height()),p.css({overflow:"hidden",overflowY:"hidden",wordWrap:"break-word",resize:"none"===p.css("resize")||"vertical"===p.css("resize")?"none":"horizontal"}),"onpropertychange"in h?"oninput"in h?p.on("input.autosize keyup.autosize",r):p.on("propertychange.autosize",function(){"value"===event.propertyName&&r()}):p.on("input.autosize",r),i.resizeDelay!==!1&&e(window).on("resize.autosize",l),p.on("autosize.resize",r),p.on("autosize.resizeIncludeStyle",function(){t=null,r()}),p.on("autosize.destroy",function(){t=null,clearTimeout(u),e(window).off("resize",l),p.off("autosize").off(".autosize").css(z).removeData("autosize")}),r())})}});
\ No newline at end of file
diff --git a/readme.md b/readme.md
index d1b800d..f7e62d7 100644
--- a/readme.md
+++ b/readme.md
@@ -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.