diff options
-rw-r--r-- | README.markdown | 1 | ||||
-rw-r--r-- | jquery.expandable.js | 9 |
2 files changed, 8 insertions, 2 deletions
diff --git a/README.markdown b/README.markdown index 421abed..3b395ab 100644 --- a/README.markdown +++ b/README.markdown @@ -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 diff --git a/jquery.expandable.js b/jquery.expandable.js index 3c38d0c..4b7b50a 100644 --- a/jquery.expandable.js +++ b/jquery.expandable.js @@ -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() { @@ -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 ); |