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