summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrandon Aaron <brandon.aaron@gmail.com>2013-04-03 13:14:58 -0500
committerBrandon Aaron <brandon.aaron@gmail.com>2013-04-03 13:14:58 -0500
commit2c1d38b9021c6a93262cc320260088e529ea0260 (patch)
treeef240fecd54b254a34169e4c4801afca94ee4bfd
parent44390d5f7af419c334797930010117164f6d9ed4 (diff)
downloadjquery-expandable-2c1d38b9021c6a93262cc320260088e529ea0260.zip
jquery-expandable-2c1d38b9021c6a93262cc320260088e529ea0260.tar.gz
jquery-expandable-2c1d38b9021c6a93262cc320260088e529ea0260.tar.bz2
Add update event that can be triggered to force a recheck of the textarea. Prevent re-running the plugin multiple times for one textarea. Bump version 1.1.4.HEAD1.1.4origin/masterorigin/HEADmaster
-rw-r--r--README.markdown9
-rw-r--r--expandable.jquery.json2
-rw-r--r--jquery.expandable.js21
3 files changed, 27 insertions, 5 deletions
diff --git a/README.markdown b/README.markdown
index b5096f1..8874fbe 100644
--- a/README.markdown
+++ b/README.markdown
@@ -15,6 +15,15 @@ The expandable plugin has 5 settings:
* `maxRows` - The maximum number of rows the textarea can be expanded to. Default is false which will allow the textarea to keep expanding.
+## Dynamic Updating
+
+If you need, you can trigger an update to the textarea by doing the following:
+
+ $('textarea').trigger('update');
+
+This is useful if you are injecting content into the textarea via JavaScript.
+
+
## License
The expandable plugin is licensed under the MIT License (LICENSE.txt).
diff --git a/expandable.jquery.json b/expandable.jquery.json
index 616575a..b104ad8 100644
--- a/expandable.jquery.json
+++ b/expandable.jquery.json
@@ -6,7 +6,7 @@
"expandable",
"textarea"
],
- "version": "1.1.3",
+ "version": "1.1.4",
"author": {
"name": "Brandon Aaron",
"url": "http://brandonaaron.net"
diff --git a/jquery.expandable.js b/jquery.expandable.js
index ba7f44e..f4179a6 100644
--- a/jquery.expandable.js
+++ b/jquery.expandable.js
@@ -1,7 +1,7 @@
/*! Copyright (c) 2013 Brandon Aaron (http://brandonaaron.net)
* Licensed under the MIT License (LICENSE.txt).
*
- * Version 1.1.3
+ * Version 1.1.4
*
* Contributions by:
* - Karl Swedberg
@@ -30,8 +30,14 @@
}, givenOptions);
return this.filter('textarea').each(function() {
- var $this = $(this).css({ display: 'block', overflow: 'hidden' }),
- minHeight = $this.height(),
+ var $this = $(this);
+
+ if ($this.data('expandable') === true) { return; } // already setup this textarea
+
+ // Set some initial style requirements
+ $this.css({ display: 'block', overflow: 'hidden' });
+
+ var minHeight = $this.height(),
heightDiff = this.offsetHeight - minHeight,
rowSize = ( parseInt($this.css('lineHeight'), 10) || parseInt($this.css('fontSize'), 10) ),
// $mirror is used for determining the height of the text within the textarea
@@ -48,8 +54,15 @@
// copy styles from textarea to mirror to mirror the textarea as best possible
mirror($this, $mirror);
- // setup events
$this
+ // set data so we know we've already setup on this
+ .data('expandable', true)
+ // setup events
+ // custom event to force a recheck programatically
+ // use by calling $('textarea').trigger('update');
+ .bind('update.expandable', function(event) {
+ check();
+ })
.bind('mouseup', function(event) {
// check if width has changed
if ($this.width() !== $mirror.width()) {