-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.autoresize.js
42 lines (34 loc) · 1.21 KB
/
jquery.autoresize.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// inspired by https://github.com/jaz303/jquery-grab-bag/raw/master/javascripts/jquery.autogrow-textarea.js
(function ($) {
$.fn.autoresize = function () {
var shadow = $('<div/>').css({ position: 'absolute', top: -10000, left: -10000, resize: 'none' }).appendTo(document.body);
this.filter('textarea').each(function () {
var $this = $(this),
minHeight = 25,
maxHeight = 500,
prevHeight = 0,
nowHeight = 0,
update = function () {
var val = this.value.replace(/[<>&]/g, 'w').replace(/\n$/, '<br/> ').replace(/\n/g, '<br/>');
shadow.html(val);
nowHeight = Math.min(Math.max(shadow.height(), minHeight), maxHeight);
if (nowHeight !== prevHeight) {
$(this).css('height', nowHeight);
EKeyboard.updatePosition($(this));
prevHeight = nowHeight;
}
};
shadow.css({
width: $(this).width() - parseInt($this.css('paddingLeft'), 10) - parseInt($this.css('paddingRight'), 10),
fontSize: $this.css('fontSize'),
fontFamily: $this.css('fontFamily'),
lineHeight: $this.css('lineHeight')
});
$(this).keyup(update).blur(update).focus(update);
update.apply(this);
});
return this;
};
}(jQuery));
window.EFilesLoaded++;
window.ETryInit();