1 // @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt Expat
2 // source https://github.com/jaz303/jquery-grab-bag
6 * Auto-growing textareas; technique ripped from Facebook
8 $.fn.autogrow = function(options) {
10 this.filter('textarea').each(function() {
13 minHeight = $this.height(),
14 lineHeight = $this.css('lineHeight');
16 var shadow = $('<div></div>').css({
20 width: $(this).width(),
21 fontSize: $this.css('fontSize'),
22 fontFamily: $this.css('fontFamily'),
23 lineHeight: $this.css('lineHeight'),
25 }).appendTo(document.body);
27 var update = function() {
29 var val = this.value.replace(/</g, '<')
30 .replace(/>/g, '>')
31 .replace(/&/g, '&')
32 .replace(/\n/g, '<br/>');
35 $(this).css('height', Math.max(shadow.height() + 20, minHeight));
38 $(this).change(update).keyup(update).keydown(update);