1
// Autosize 1.10 - jQuery plugin for textareas
2
// (c) 2012 Jack Moore - jacklmoore.com
3
// license: www.opensource.org/licenses/mit-license.php
8
borderBox = 'border-box',
9
lineHeight = 'lineHeight',
10
copy = '<textarea tabindex="-1" style="position:absolute; top:-9999px; left:-9999px; right:auto; bottom:auto; -moz-box-sizing:content-box; -webkit-box-sizing:content-box; box-sizing:content-box; word-wrap:break-word; height:0 !important; min-height:0 !important; overflow:hidden">',
11
// line-height is omitted because IE7/IE8 doesn't return the correct value.
23
onpropertychange = 'onpropertychange',
26
// For testing support in old FireFox
27
test.setAttribute(oninput, "return");
29
if ($.isFunction(test[oninput]) || onpropertychange in test) {
31
// test that line-height can be accurately copied to avoid
32
// incorrect value reporting in old IE and old Opera
33
$(test).css(lineHeight, '99px');
34
if ($(test).css(lineHeight) === '99px') {
35
copyStyle.push(lineHeight);
38
$.fn.autosize = function (className) {
39
return this.each(function () {
44
minHeight = $ta.height(),
45
maxHeight = parseInt($ta.css('maxHeight'), 10),
51
if ($ta.css('box-sizing') === borderBox || $ta.css('-moz-box-sizing') === borderBox || $ta.css('-webkit-box-sizing') === borderBox){
52
boxOffset = $ta.outerHeight() - $ta.height();
55
if ($ta.data('mirror') || $ta.data('ismirror')) {
56
// if autosize has already been applied, exit.
57
// if autosize is being applied to a mirror element, exit.
60
mirror = $(copy).data('ismirror', true).addClass(className || 'autosizejs')[0];
62
// Changed allowed resize only in edit mode by VTA (31/8/2012)
63
if ($ta.attr('disabled')) {
64
$ta.css('resize', 'none');
66
// Changed horizontal to vertical by VTA (31/8/2012)
67
resize = $ta.css('resize') === 'none' ? 'none' : 'vertical';
69
$ta.data('mirror', $(mirror)).css({
72
wordWrap: 'break-word',
77
// Opera returns '-1px' when max-height is set to 'none'.
78
maxHeight = maxHeight && maxHeight > 0 ? maxHeight : 9e4;
80
// Using mainly bare JS in this function because it is going
81
// to fire very often while typing, and needs to very efficient.
84
// the active flag keeps IE from tripping all over itself. Otherwise
85
// actions in the adjust function will cause IE to call adjust again.
89
mirror.value = ta.value;
91
mirror.style.overflowY = ta.style.overflowY;
93
// Update the width in case the original textarea width has changed
94
mirror.style.width = $ta.css('width');
96
// Needed for IE to reliably return the correct scrollHeight
99
// Set a very high value for scrollTop to be sure the
100
// mirror is scrolled all the way to the bottom.
101
mirror.scrollTop = 9e4;
103
height = mirror.scrollTop;
105
if (height > maxHeight) {
108
} else if (height < minHeight) {
111
ta.style.overflowY = overflow;
113
ta.style.height = height + boxOffset + 'px';
115
// This small timeout gives IE a chance to draw it's scrollbar
116
// before adjust can be run again (prevents an infinite loop).
117
setTimeout(function () {
123
// mirror is a duplicate textarea located off-screen that
124
// is automatically updated to contain the same text as the
125
// original textarea. mirror always has a height of 0.
126
// This gives a cross-browser supported way getting the actual
127
// height of the text, through the scrollTop property.
129
mirror.style[copyStyle[i]] = $ta.css(copyStyle[i]);
132
$('body').append(mirror);
134
if (onpropertychange in ta) {
136
// Detects IE9. IE9 does not fire onpropertychange or oninput for deletions,
137
// so binding to onkeyup to catch most of those occassions. There is no way that I
138
// know of to detect something like 'cut' in IE9.
139
ta[oninput] = ta.onkeyup = adjust;
142
ta[onpropertychange] = adjust;
146
ta[oninput] = adjust;
149
$(window).resize(adjust);
151
// Allow for manual triggering if needed.
152
$ta.bind('autosize', adjust);
154
// Call adjust in case the textarea already contains text.
159
// Makes no changes for older browsers (FireFox3- and Safari4-)
160
$.fn.autosize = function () {
b'\\ No newline at end of file'
2
Autosize v1.18.6 - 2014-03-13
3
Automatically adjust textarea height based on user input.
4
(c) 2014 Jack Moore - http://www.jacklmoore.com/autosize
5
license: http://www.opensource.org/licenses/mit-license.php
10
className: 'autosizejs',
18
// border:0 is unnecessary, but avoids a bug in Firefox on OSX
19
copy = '<textarea tabindex="-1" style="position:absolute; top:-999px; left:0; right:auto; bottom:auto; border:0; padding: 0; -moz-box-sizing:content-box; -webkit-box-sizing:content-box; box-sizing:content-box; word-wrap:break-word; height:0 !important; min-height:0 !important; overflow:hidden; transition:none; -webkit-transition:none; -moz-transition:none;"/>',
21
// line-height is conditionally included because IE7/IE8/old Opera do not return the correct value.
33
// to keep track which textarea is being mirrored when adjust() is called.
36
// the mirror element, which is used to calculate what size the mirrored element should be.
37
mirror = $(copy).data('autosize', true)[0];
39
// test that line-height can be accurately copied.
40
mirror.style.lineHeight = '99px';
41
if ($(mirror).css('lineHeight') === '99px') {
42
typographyStyles.push('lineHeight');
44
mirror.style.lineHeight = '';
46
$.fn.autosize = function (options) {
51
options = $.extend({}, defaults, options || {});
53
if (mirror.parentNode !== document.body) {
54
$(document.body).append(mirror);
57
return this.each(function () {
64
callback = $.isFunction(options.callback),
66
height: ta.style.height,
67
overflow: ta.style.overflow,
68
overflowY: ta.style.overflowY,
69
wordWrap: ta.style.wordWrap,
70
resize: ta.style.resize
75
if ($ta.data('autosize')) {
76
// exit if autosize has already been applied, or if the textarea is the mirror element.
79
$ta.data('autosize', true);
81
if ($ta.css('box-sizing') === 'border-box' || $ta.css('-moz-box-sizing') === 'border-box' || $ta.css('-webkit-box-sizing') === 'border-box'){
82
boxOffset = $ta.outerHeight() - $ta.height();
85
// IE8 and lower return 'auto', which parses to NaN, if no min-height is set.
86
minHeight = Math.max(parseInt($ta.css('minHeight'), 10) - boxOffset || 0, $ta.height());
91
wordWrap: 'break-word', // horizontal overflow is hidden, so break-word is necessary for handling words longer than the textarea width
92
resize: ($ta.css('resize') === 'none' || $ta.css('resize') === 'vertical') ? 'none' : 'horizontal'
95
// The mirror width must exactly match the textarea width, so using getBoundingClientRect because it doesn't round the sub-pixel value.
96
// window.getComputedStyle, getBoundingClientRect returning a width are unsupported, but also unneeded in IE8 and lower.
99
var style = window.getComputedStyle ? window.getComputedStyle(ta, null) : false;
103
width = ta.getBoundingClientRect().width;
106
width = parseInt(style.width,10);
109
$.each(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'], function(i,val){
110
width -= parseInt(style[val],10);
113
width = Math.max($ta.width(), 0);
116
mirror.style.width = width + 'px';
119
function initMirror() {
123
mirror.className = options.className;
124
mirror.id = options.id;
125
maxHeight = parseInt($ta.css('maxHeight'), 10);
127
// mirror is a duplicate textarea located off-screen that
128
// is automatically updated to contain the same text as the
129
// original textarea. mirror always has a height of 0.
130
// This gives a cross-browser supported way getting the actual
131
// height of the text, through the scrollTop property.
132
$.each(typographyStyles, function(i,val){
133
styles[val] = $ta.css(val);
136
$(mirror).css(styles).attr('wrap', $ta.attr('wrap'));
140
// Chrome-specific fix:
141
// When the textarea y-overflow is hidden, Chrome doesn't reflow the text to account for the space
142
// made available by removing the scrollbar. This workaround triggers the reflow for Chrome.
144
var width = ta.style.width;
145
ta.style.width = '0px';
146
var ignore = ta.offsetWidth;
147
ta.style.width = width;
151
// Using mainly bare JS in this function because it is going
152
// to fire very often while typing, and needs to very efficient.
154
var height, original;
156
if (mirrored !== ta) {
162
if (!ta.value && options.placeholder) {
163
// If the textarea is empty, copy the placeholder text into
164
// the mirror control and use that for sizing so that we
165
// don't end up with placeholder getting trimmed.
166
mirror.value = ($ta.attr("placeholder") || '') + options.append;
168
mirror.value = ta.value + options.append;
171
mirror.style.overflowY = ta.style.overflowY;
172
original = parseInt(ta.style.height,10);
174
// Setting scrollTop to zero is needed in IE8 and lower for the next step to be accurately applied
175
mirror.scrollTop = 0;
177
mirror.scrollTop = 9e4;
179
// Using scrollTop rather than scrollHeight because scrollHeight is non-standard and includes padding.
180
height = mirror.scrollTop;
182
if (maxHeight && height > maxHeight) {
183
ta.style.overflowY = 'scroll';
186
ta.style.overflowY = 'hidden';
187
if (height < minHeight) {
194
if (original !== height) {
195
ta.style.height = height + 'px';
197
options.callback.call(ta,ta);
203
clearTimeout(timeout);
204
timeout = setTimeout(function(){
205
var newWidth = $ta.width();
207
if (newWidth !== width) {
211
}, parseInt(options.resizeDelay,10));
214
if ('onpropertychange' in ta) {
215
if ('oninput' in ta) {
216
// Detects IE9. IE9 does not fire onpropertychange or oninput for deletions,
217
// so binding to onkeyup to catch most of those occasions. There is no way that I
218
// know of to detect something like 'cut' in IE9.
219
$ta.on('input.autosize keyup.autosize', adjust);
222
$ta.on('propertychange.autosize', function(){
223
if(event.propertyName === 'value'){
230
$ta.on('input.autosize', adjust);
233
// Set options.resizeDelay to false if using fixed-width textarea elements.
234
// Uses a timeout and width check to reduce the amount of times adjust needs to be called after window resize.
236
if (options.resizeDelay !== false) {
237
$(window).on('resize.autosize', resize);
240
// Event for manual triggering if needed.
241
// Should only be needed when the value of the textarea is changed through JavaScript rather than user input.
242
$ta.on('autosize.resize', adjust);
244
// Event for manual triggering that also forces the styles to update as well.
245
// Should only be needed if one of typography styles of the textarea change, and the textarea is already the target of the adjust method.
246
$ta.on('autosize.resizeIncludeStyle', function() {
251
$ta.on('autosize.destroy', function(){
253
clearTimeout(timeout);
254
$(window).off('resize', resize);
259
.removeData('autosize');
262
// Call adjust in case the textarea already contains text.
266
}(window.jQuery || window.$)); // jQuery or jQuery-like library, such as Zepto