From 7d43b5cf598dd72c9d0e70c4e561d9a66df5cabe Mon Sep 17 00:00:00 2001 From: hryanjones Date: Fri, 22 Feb 2013 15:42:07 -0800 Subject: [PATCH] Update the textarea mirror if the size of the original has been changed (e.g. via modern browser or jQuery resizeable). --- jquery.expandable.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/jquery.expandable.js b/jquery.expandable.js index 9017b7b..5c94d50 100644 --- a/jquery.expandable.js +++ b/jquery.expandable.js @@ -45,7 +45,7 @@ maxHeight = options.maxRows * rowSize; } - // copy styles from textarea to mirror to mirror the textarea as best possible + // copy styles from textarea to mirror the textarea as best possible $.each('borderTopWidth borderRightWidth borderBottomWidth borderLeftWidth paddingTop paddingRight paddingBottom paddingLeft fontSize fontFamily fontWeight fontStyle fontStretch fontVariant wordSpacing lineHeight width'.split(' '), function(i,prop) { $mirror.css(prop, $this.css(prop)); }); @@ -59,6 +59,12 @@ }); function check() { + //The size of the textarea may have changed because it's resizeable (due to jQuery, + //or allowable by the browser). Update the mirror size in this case. + $.each('borderTopWidth borderRightWidth borderBottomWidth borderLeftWidth width'.split(' '), function(i,prop) { + $mirror.css(prop, $this.css(prop)); + }); + var text = $this.val(), newHeight, height, usedHeight, usedRows, availableRows; // copy textarea value to the $mirror // encode any html passed in and replace new lines with a