diff --git a/jquery.autosize-min.js b/jquery.autosize-min.js
index 9392650..ef02a25 100644
--- a/jquery.autosize-min.js
+++ b/jquery.autosize-min.js
@@ -1,7 +1,7 @@
/*!
jQuery Autosize v1.16.15
(c) 2013 Jack Moore - jacklmoore.com
- updated: 2013-06-07
+ updated: 2013-06-11
license: http://www.opensource.org/licenses/mit-license.php
*/
-(function(e){var t,o={className:"autosizejs",append:"",callback:!1,resizeDelay:10},i="hidden",n="border-box",s="lineHeight",a='',r=["fontFamily","fontSize","fontWeight","fontStyle","letterSpacing","textTransform","wordSpacing","textIndent"],l="oninput",c="onpropertychange",h=e(a).data("autosize",!0)[0];h.style.lineHeight="99px","99px"===e(h).css(s)&&r.push(s),h.style.lineHeight="",e.fn.autosize=function(s){return s=e.extend({},o,s||{}),h.parentNode!==document.body&&e(document.body).append(h),this.each(function(){function o(){if(t=w,h.className=s.className,p=parseInt(f.css("maxHeight"),10),e.each(r,function(e,t){h.style[t]=f.css(t)}),l in w){var o=w.style.width;w.style.width="0px",w.offsetWidth,w.style.width=o}}function a(){var e,n,a;t!==w&&o(),h.value=w.value+s.append,h.style.overflowY=w.style.overflowY,a=parseInt(w.style.height,10),h.style.width=Math.max(f.width(),0)+"px",h.scrollTop=0,h.scrollTop=9e4,e=h.scrollTop,p&&e>p?(e=p,n="scroll"):d>e&&(e=d),e+=b,w.style.overflowY=n||i,a!==e&&(w.style.height=e+"px",z&&s.callback.call(w,w))}var d,p,u,w=this,f=e(w),b=0,z=e.isFunction(s.callback);if(!f.data("autosize")){if((f.css("box-sizing")===n||f.css("-moz-box-sizing")===n||f.css("-webkit-box-sizing")===n)&&(b=f.outerHeight()-f.height()),d=Math.max(parseInt(f.css("minHeight"),10)-b||0,f.height()),u="none"===f.css("resize")||"vertical"===f.css("resize")?"none":"horizontal",f.css({overflow:i,overflowY:i,wordWrap:"break-word",resize:u}).data("autosize",!0),c in w?l in w?w[l]=w.onkeyup=a:w[c]=function(){"value"===event.propertyName&&a()}:w[l]=a,s.resizeDelay!==!1){var x,y=e(w).width();e(window).on("resize.autosize",function(){clearTimeout(x),x=setTimeout(function(){e(w).width()!==y&&a()},parseInt(s.resizeDelay,10))})}f.on("autosize",a),a()}})}})(window.jQuery||window.Zepto);
\ No newline at end of file
+(function(t){var e,i,o={className:"autosizejs",append:"",callback:!1,resizeDelay:10},n="hidden",s="border-box",a="lineHeight",r='',l=["fontFamily","fontSize","fontWeight","fontStyle","letterSpacing","textTransform","wordSpacing","textIndent"],c="oninput",d="onpropertychange",h=t(r).data("autosize",!0)[0];h.style.lineHeight="99px","99px"===t(h).css(a)&&l.push(a),h.style.lineHeight="",e=void 0!==h.getBoundingClientRect().width,t.fn.autosize=function(a){return a=t.extend({},o,a||{}),h.parentNode!==document.body&&t(document.body).append(h),this.each(function(){function o(){if(i=w,h.className=a.className,u=parseInt(f.css("maxHeight"),10),t.each(l,function(t,e){h.style[e]=f.css(e)}),c in w){var e=w.style.width;w.style.width="0px",w.offsetWidth,w.style.width=e}}function r(){var s,r,l,c;i!==w&&o(),h.value=w.value+a.append,h.style.overflowY=w.style.overflowY,l=parseInt(w.style.height,10),e?(c=w.getBoundingClientRect().width,t.each(t(w).css(["paddingLeft","paddingRight","borderLeftWidth","borderRightWidth"]),function(){c-=parseInt(this,10)}),h.style.width=c+"px"):h.style.width=Math.max(f.width(),0)+"px",h.scrollTop=0,h.scrollTop=9e4,s=h.scrollTop,u&&s>u?(s=u,r="scroll"):p>s&&(s=p),s+=b,w.style.overflowY=r||n,l!==s&&(w.style.height=s+"px",x&&a.callback.call(w,w))}var p,u,g,w=this,f=t(w),b=0,x=t.isFunction(a.callback);if(!f.data("autosize")){if((f.css("box-sizing")===s||f.css("-moz-box-sizing")===s||f.css("-webkit-box-sizing")===s)&&(b=f.outerHeight()-f.height()),p=Math.max(parseInt(f.css("minHeight"),10)-b||0,f.height()),g="none"===f.css("resize")||"vertical"===f.css("resize")?"none":"horizontal",f.css({overflow:n,overflowY:n,wordWrap:"break-word",resize:g}).data("autosize",!0),d in w?c in w?w[c]=w.onkeyup=r:w[d]=function(){"value"===event.propertyName&&r()}:w[c]=r,a.resizeDelay!==!1){var y,z=t(w).width();t(window).on("resize.autosize",function(){clearTimeout(y),y=setTimeout(function(){t(w).width()!==z&&r()},parseInt(a.resizeDelay,10))})}f.on("autosize",r),r()}})}})(window.jQuery||window.Zepto);
\ No newline at end of file
diff --git a/jquery.autosize.js b/jquery.autosize.js
index 2634a59..05a417b 100644
--- a/jquery.autosize.js
+++ b/jquery.autosize.js
@@ -1,7 +1,7 @@
/*!
jQuery Autosize v1.16.15
(c) 2013 Jack Moore - jacklmoore.com
- updated: 2013-06-07
+ updated: 2013-06-11
license: http://www.opensource.org/licenses/mit-license.php
*/
(function ($) {
@@ -15,6 +15,7 @@
hidden = 'hidden',
borderBox = 'border-box',
lineHeight = 'lineHeight',
+ useSubpixels,
// border:0 is unnecessary, but avoids a bug in FireFox on OSX
copy = '',
@@ -46,6 +47,9 @@
}
mirror.style.lineHeight = '';
+ // test for subpixel rendering
+ useSubpixels = mirror.getBoundingClientRect().width !== undefined;
+
$.fn.autosize = function (options) {
options = $.extend({}, defaults, options || {});
@@ -111,7 +115,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, overflow, original;
+ var height, overflow, original, width;
if (mirrored !== ta) {
initMirror();
@@ -121,9 +125,17 @@
mirror.style.overflowY = ta.style.overflowY;
original = parseInt(ta.style.height,10);
- // Update the width in case the original textarea width has changed
- // A floor of 0 is needed because IE8 returns a negative value for hidden textareas, raising an error.
- mirror.style.width = Math.max($ta.width(), 0) + 'px';
+ if (useSubpixels) {
+ // The mirror width much exactly match the textarea width, so using getBoundingClientRect because it doesn't round the subpixel value.
+ width = ta.getBoundingClientRect().width;
+ $.each($(ta).css(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth']), function(){
+ width -= parseInt(this, 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;
diff --git a/readme.md b/readme.md
index fa22c3b..13cd26e 100644
--- a/readme.md
+++ b/readme.md
@@ -4,6 +4,9 @@ Small jQuery plugin to allow dynamic resizing of textarea height, so that it gro
## Changelog
+### v1.16.16 - 2013/6/11
+* Fixed an issue where the calculated height might be slightly off in modern browsers when the width of the textarea has a subpixel value.
+
### v1.16.15 - 2013/6/7
* Reduced how frequently autosize is triggered when resizing the window. Added resizeDelay property so that the frequency can be adjusted or disabled.