(function($){ $.fn.extend({ elastic: function() { var mimics = new Array('paddingTop','paddingRight','paddingBottom','paddingLeft','fontSize','lineHeight','fontFamily','width','fontWeight'); return this.each(function() { if(this.type == 'textarea') { var textarea = $(this); var lineheight = parseInt(textarea.css('lineHeight'),10) || parseInt(textarea.css('fontSize'),'10'); var minheight = parseInt(textarea.css('height'),10) || lineheight*3; var maxheight = parseInt(textarea.css('max-height'),10) || 0; var goalheight = 0; var twin = null; var first = true; if(maxheight < 0) maxheight = 0; if (!twin) { twin = $('
').css({'position': 'absolute','display':'none'}).appendTo(textarea.parent()); $.each(mimics, function(){ twin.css(this.toString(),textarea.css(this.toString())); }); }; function update() { var content = textarea.val().replace(/<|>/g, ' ').replace(/\n/g, '