diff options
-rw-r--r-- | README.markdown | 9 | ||||
-rw-r--r-- | expandable.jquery.json | 2 | ||||
-rw-r--r-- | jquery.expandable.js | 21 |
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()) { |