Skip to content

Commit

Permalink
Fixed potential memory leak when using autosize.destroy. (Fixes jackm…
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmoore committed Jun 22, 2013
1 parent 27d7538 commit 07df5fa
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion autosize.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"textarea",
"ui"
],
"version": "1.17.0",
"version": "1.17.1",
"author": {
"name": "Jack Moore",
"url": "http://www.jacklmoore.com",
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery-autosize",
"version": "1.17.0",
"version": "1.17.1",
"main": "./jquery.autosize.js",
"dependencies": {
"jquery": ">=1.7"
Expand Down
2 changes: 1 addition & 1 deletion demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}

</style>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js'></script>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'></script>
<script src='jquery.autosize.js'></script>
<script>
$(function(){
Expand Down
6 changes: 3 additions & 3 deletions jquery.autosize-min.js

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

31 changes: 18 additions & 13 deletions jquery.autosize.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
jQuery Autosize v1.17.0
jQuery Autosize v1.17.1
(c) 2013 Jack Moore - jacklmoore.com
updated: 2013-06-19
updated: 2013-06-22
license: http://www.opensource.org/licenses/mit-license.php
*/
(function ($) {
Expand Down Expand Up @@ -62,7 +62,9 @@
overflowY: ta.style.overflowY,
wordWrap: ta.style.wordWrap,
resize: ta.style.resize
};
},
timeout,
width = $ta.width();

if ($ta.data('autosize')) {
// exit if autosize has already been applied, or if the textarea is the mirror element.
Expand Down Expand Up @@ -168,6 +170,15 @@
}
}

function resize () {
clearTimeout(timeout);
timeout = setTimeout(function(){
if ($ta.width() !== width) {
adjust();
}
}, parseInt(options.resizeDelay,10));
}

if ('onpropertychange' in ta) {
if ('oninput' in ta) {
// Detects IE9. IE9 does not fire onpropertychange or oninput for deletions,
Expand All @@ -189,17 +200,9 @@

// Set options.resizeDelay to false if using fixed-width textarea elements.
// Uses a timeout and width check to reduce the amount of times adjust needs to be called after window resize.

if (options.resizeDelay !== false) {
var timeout;
var width = $(ta).width();
$(window).on('resize.autosize', function() {
clearTimeout(timeout);
timeout = setTimeout(function(){
if ($(ta).width() !== width) {
adjust();
}
}, parseInt(options.resizeDelay,10));
});
$(window).on('resize.autosize', resize);
}

// Event for manual triggering if needed.
Expand All @@ -215,6 +218,8 @@

$ta.on('autosize.destroy', function(){
mirrored = null;
clearTimeout(timeout);
$(window).off('resize', resize);
$ta
.off('autosize')
.off('.autosize')
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Small jQuery plugin to allow dynamic resizing of textarea height, so that it gro

## Changelog

### v1.17.1 - 2013/6/22
* Fixed potential memory leak when using autosize.destroy.

### v1.17.0 - 2013/6/19
* Renamed 'autosize' event to 'autosize.resize'
* Renamed 'autosize.includeStyle' event to 'autosize.resizeIncludeStyle'
Expand Down

0 comments on commit 07df5fa

Please sign in to comment.