summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrandon Aaron <brandon.aaron@gmail.com>2013-02-08 15:22:06 -0600
committerBrandon Aaron <brandon.aaron@gmail.com>2013-02-08 15:22:06 -0600
commit9d3fcc6282df207a8d310746be77c820b615e9d2 (patch)
treece7fc24ad9e0acdbeed57e930a5bea5b4a180ca6
parent8d835d10d7ab6ee6ed6aa88f982a3ee3cf74c860 (diff)
downloadjquery-expandable-9d3fcc6282df207a8d310746be77c820b615e9d2.zip
jquery-expandable-9d3fcc6282df207a8d310746be77c820b615e9d2.tar.gz
jquery-expandable-9d3fcc6282df207a8d310746be77c820b615e9d2.tar.bz2
maxRows feature is off by default. when maxRows is reached allow the textarea to scroll
-rw-r--r--README.markdown2
-rw-r--r--jquery.expandable.js19
2 files changed, 15 insertions, 6 deletions
diff --git a/README.markdown b/README.markdown
index 3b395ab..4078888 100644
--- a/README.markdown
+++ b/README.markdown
@@ -12,7 +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.
+* `maxRows` - The maximum number of rows the textarea can be expanded to. Default is false which will allow the textarea to keep expanding.
## License
diff --git a/jquery.expandable.js b/jquery.expandable.js
index 4b7b50a..022ea11 100644
--- a/jquery.expandable.js
+++ b/jquery.expandable.js
@@ -16,7 +16,7 @@ $.fn.extend({
interval: 750,
within: 1,
by: 2,
- maxRows: 20,
+ maxRows: false,
init: false
}, givenOptions);
@@ -29,8 +29,13 @@ $.fn.extend({
// it isn't perfect but is pretty close
// white-space rules from: http://petesbloggerama.blogspot.com/2007/02/firefox-ie-word-wrap-word-break-tables.html
$mirror = $('<div style="position:absolute;top:-999px;left:-999px;border-color:#000;border-style:solid;overflow-x:hidden;visibility:hidden;z-index:0;white-space: pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word;" />').appendTo('body'),
+ maxHeight = false,
interval;
+ if ( options.maxRows ) {
+ maxHeight = options.maxRows * rowSize;
+ }
+
// copy styles from textarea to mirror to mirror the textarea as best possible
$.each('borderTopWidth borderRightWidth borderBottomWidth borderLeftWidth paddingTop paddingRight paddingBottom paddingLeft fontSize fontFamily fontWeight fontStyle fontStretch fontVariant wordSpacing lineHeight width'.split(' '), function(i,prop) {
$mirror.css(prop, $this.css(prop));
@@ -56,13 +61,17 @@ $.fn.extend({
usedRows = Math.floor(usedHeight / rowSize);
availableRows = Math.floor((height / rowSize) - usedRows);
+ if ( usedHeight >= maxHeight ) {
+ $this.css({ display: 'auto', overflow: 'auto' });
+ return;
+ }
+
// adjust height if needed by either growing or shrinking the text area to within the specified bounds
if ( availableRows <= options.within ) {
- var numRows = usedRows + Math.max(availableRows, 0) + options.by;
- if( numRows > options.maxRows ) {
- numRows = options.maxRows;
+ newHeight = rowSize * (usedRows + Math.max(availableRows, 0) + options.by);
+ if ( maxHeight ) {
+ newHeight = Math.min(newHeight, maxHeight);
}
- 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 );