4 * Auto-growing textareas; technique ripped from Facebook
6 $.fn.autogrow = function(options) {
8 this.filter('textarea').each(function() {
11 minHeight = $this.height(),
12 lineHeight = $this.css('lineHeight');
14 var shadow = $('<div></div>').css({
18 width: $(this).width(),
19 fontSize: $this.css('fontSize'),
20 fontFamily: $this.css('fontFamily'),
21 lineHeight: $this.css('lineHeight'),
23 }).appendTo(document.body);
25 var update = function() {
27 var val = this.value.replace(/</g, '<')
28 .replace(/>/g, '>')
29 .replace(/&/g, '&')
30 .replace(/\n/g, '<br/>');
33 $(this).css('height', Math.max(shadow.height() + 20, minHeight));
36 $(this).change(update).keyup(update).keydown(update);