Skip to content

Commit

Permalink
maxRows option.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pistos committed Jun 15, 2012
1 parent ed30e90 commit 8d835d1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The expandable plugin has 5 settings:
* `interval` - The interval at which it checks the textarea. Default is 750.
* `within` - The number of rows left before expanding. Default is 1.
* `by` - The number of rows to expand by. Default is 2.
* `maxRows` - The maximum number of rows the textarea can be expanded to. Default is 20.


## License
Expand Down
9 changes: 7 additions & 2 deletions jquery.expandable.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ $.fn.extend({
interval: 750,
within: 1,
by: 2,
init: false
maxRows: 20,
init: false
}, givenOptions);

return this.filter('textarea').each(function() {
Expand Down Expand Up @@ -57,7 +58,11 @@ $.fn.extend({

// adjust height if needed by either growing or shrinking the text area to within the specified bounds
if ( availableRows <= options.within ) {
newHeight = rowSize * (usedRows + Math.max(availableRows, 0) + options.by);
var numRows = usedRows + Math.max(availableRows, 0) + options.by;
if( numRows > options.maxRows ) {
numRows = options.maxRows;
}
newHeight = rowSize * numRows;
$this.stop().animate({ height: newHeight }, options.duration);
} else if ( availableRows > options.by + options.within ) {
newHeight = Math.max( height - (rowSize * (availableRows - (options.by + options.within))), minHeight );
Expand Down

0 comments on commit 8d835d1

Please sign in to comment.