]> git.mxchange.org Git - friendica.git/blob - view/theme/smoothly/js/jquery.autogrow.textarea.js
new file: view/theme/smoothly/bottom.tpl
[friendica.git] / view / theme / smoothly / js / jquery.autogrow.textarea.js
1 (function($) {
2
3     /*
4      * Auto-growing textareas; technique ripped from Facebook
5      */
6     $.fn.autogrow = function(options) {
7         
8         this.filter('textarea').each(function() {
9             
10             var $this       = $(this),
11                 minHeight   = $this.height(),
12                 lineHeight  = $this.css('lineHeight');
13             
14             var shadow = $('<div></div>').css({
15                 position:   'absolute',
16                 top:        -10000,
17                 left:       -10000,
18                 width:      $(this).width(),
19                 fontSize:   $this.css('fontSize'),
20                 fontFamily: $this.css('fontFamily'),
21                 lineHeight: $this.css('lineHeight'),
22                 resize:     'none'
23             }).appendTo(document.body);
24             
25             var update = function() {
26                 
27                 var val = this.value.replace(/</g, '&lt;')
28                                     .replace(/>/g, '&gt;')
29                                     .replace(/&/g, '&amp;')
30                                     .replace(/\n/g, '<br/>');
31                 
32                 shadow.html(val);
33                 $(this).css('height', Math.max(shadow.height() + 20, minHeight));
34             }
35             
36             $(this).change(update).keyup(update).keydown(update);
37             
38             update.apply(this);
39             
40         });
41         
42         return this;
43         
44     }
45     
46 })(jQuery);