summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPistos <github.pistos@purepistos.net>2012-06-15 13:43:19 -0400
committerPistos <github.pistos@purepistos.net>2012-06-15 13:43:19 -0400
commit8d835d10d7ab6ee6ed6aa88f982a3ee3cf74c860 (patch)
treec7447207f954fb1b0a84fddd90ddfc199593ca11
parented30e90320ee3b4151c178e88c9eafc7242f67a0 (diff)
downloadjquery-expandable-8d835d10d7ab6ee6ed6aa88f982a3ee3cf74c860.zip
jquery-expandable-8d835d10d7ab6ee6ed6aa88f982a3ee3cf74c860.tar.gz
jquery-expandable-8d835d10d7ab6ee6ed6aa88f982a3ee3cf74c860.tar.bz2
maxRows option.
-rw-r--r--README.markdown1
-rw-r--r--jquery.expandable.js9
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 );