Skip to content

Commit

Permalink
Improved speed of editing large blocks of text in FireFox.
Browse files Browse the repository at this point in the history
No longer accounts for changes in width for a textarea while typing in order to improve performance.
  • Loading branch information
jackmoore committed Aug 22, 2013
1 parent d4ee099 commit 682328d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion autosize.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -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"
},
Expand Down
42 changes: 23 additions & 19 deletions jquery.autosize.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand All @@ -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;

Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions jquery.autosize.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {},
"keywords": [
"form",
Expand Down
8 changes: 6 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ Small jQuery plugin to allow dynamic resizing of textarea height, so that it gro

## Changelog

### v1.17.3 - 2013/8/21
* Resolved an issue that was causing slowing down initialization for text-intensive textareas in Chrome.
### 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.
* Renamed minified file from jquery.autosize-min.js to jquery.autosize.min.js

### v1.17.2 - 2013/7/28
Expand Down

0 comments on commit 682328d

Please sign in to comment.