autosize-rails 1.16.7 → 1.18.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/autosize/rails/version.rb +1 -1
- data/vendor/assets/javascripts/jquery.autosize.js +153 -87
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86f89d5b7043e402c0d4cec470c9ad28b8914ed9
|
4
|
+
data.tar.gz: c3ae91447c4a3b063735041ce7b1b7098cf8580e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e2a474b13428f72a8f0bcac0dd2d0d26cb7dae5ee1e0c9ac6f80de6d56a8f10e529b20e090d474a8b0135b00c2ffb0b6e45a6bd85d8014717e918dd650065c5
|
7
|
+
data.tar.gz: fb442139c603cb4beb653dbfacf3919b4cf354355d811c1227762d91333ada9971f4ada356d1c9685e9de485d7ed77fa720b3428a48cabd9acaf18da695a7873
|
@@ -1,28 +1,31 @@
|
|
1
1
|
/*!
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
Autosize v1.18.0 - 2013-10-20
|
3
|
+
Automatically adjust textarea height based on user input.
|
4
|
+
(c) 2013 Jack Moore - http://www.jacklmoore.com/autosize
|
5
5
|
license: http://www.opensource.org/licenses/mit-license.php
|
6
6
|
*/
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
(function (factory) {
|
8
|
+
if (typeof define === 'function' && define.amd) {
|
9
|
+
// AMD. Register as an anonymous module.
|
10
|
+
define(['jquery'], factory);
|
11
|
+
} else {
|
12
|
+
// Browser globals: jQuery or jQuery-like library, such as Zepto
|
13
|
+
factory(window.jQuery || window.$);
|
14
|
+
}
|
15
|
+
}(function ($) {
|
10
16
|
var
|
11
17
|
defaults = {
|
12
18
|
className: 'autosizejs',
|
13
19
|
append: '',
|
14
|
-
callback: false
|
20
|
+
callback: false,
|
21
|
+
resizeDelay: 10
|
15
22
|
},
|
16
|
-
hidden = 'hidden',
|
17
|
-
borderBox = 'border-box',
|
18
|
-
lineHeight = 'lineHeight',
|
19
|
-
supportsScrollHeight,
|
20
23
|
|
21
|
-
// border:0 is unnecessary, but avoids a bug in FireFox on OSX
|
22
|
-
copy = '<textarea tabindex="-1" style="position:absolute; top:-999px; left:0; right:auto; bottom:auto; border: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;"/>',
|
24
|
+
// border:0 is unnecessary, but avoids a bug in FireFox on OSX
|
25
|
+
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;"/>',
|
23
26
|
|
24
27
|
// line-height is conditionally included because IE7/IE8/old Opera do not return the correct value.
|
25
|
-
|
28
|
+
typographyStyles = [
|
26
29
|
'fontFamily',
|
27
30
|
'fontSize',
|
28
31
|
'fontWeight',
|
@@ -32,8 +35,6 @@
|
|
32
35
|
'wordSpacing',
|
33
36
|
'textIndent'
|
34
37
|
],
|
35
|
-
oninput = 'oninput',
|
36
|
-
onpropertychange = 'onpropertychange',
|
37
38
|
|
38
39
|
// to keep track which textarea is being mirrored when adjust() is called.
|
39
40
|
mirrored,
|
@@ -43,150 +44,215 @@
|
|
43
44
|
|
44
45
|
// test that line-height can be accurately copied.
|
45
46
|
mirror.style.lineHeight = '99px';
|
46
|
-
if ($(mirror).css(lineHeight) === '99px') {
|
47
|
-
|
47
|
+
if ($(mirror).css('lineHeight') === '99px') {
|
48
|
+
typographyStyles.push('lineHeight');
|
48
49
|
}
|
49
50
|
mirror.style.lineHeight = '';
|
50
51
|
|
51
52
|
$.fn.autosize = function (options) {
|
53
|
+
if (!this.length) {
|
54
|
+
return this;
|
55
|
+
}
|
56
|
+
|
52
57
|
options = $.extend({}, defaults, options || {});
|
53
58
|
|
54
59
|
if (mirror.parentNode !== document.body) {
|
55
60
|
$(document.body).append(mirror);
|
56
|
-
|
57
|
-
mirror.value = "\n\n\n";
|
58
|
-
mirror.scrollTop = 9e4;
|
59
|
-
supportsScrollHeight = mirror.scrollHeight === mirror.scrollTop + mirror.clientHeight;
|
60
61
|
}
|
61
62
|
|
62
63
|
return this.each(function () {
|
63
64
|
var
|
64
65
|
ta = this,
|
65
66
|
$ta = $(ta),
|
67
|
+
maxHeight,
|
66
68
|
minHeight,
|
67
|
-
active,
|
68
|
-
resize,
|
69
69
|
boxOffset = 0,
|
70
|
-
callback = $.isFunction(options.callback)
|
70
|
+
callback = $.isFunction(options.callback),
|
71
|
+
originalStyles = {
|
72
|
+
height: ta.style.height,
|
73
|
+
overflow: ta.style.overflow,
|
74
|
+
overflowY: ta.style.overflowY,
|
75
|
+
wordWrap: ta.style.wordWrap,
|
76
|
+
resize: ta.style.resize
|
77
|
+
},
|
78
|
+
timeout,
|
79
|
+
width = $ta.width();
|
71
80
|
|
72
81
|
if ($ta.data('autosize')) {
|
73
82
|
// exit if autosize has already been applied, or if the textarea is the mirror element.
|
74
83
|
return;
|
75
84
|
}
|
85
|
+
$ta.data('autosize', true);
|
76
86
|
|
77
|
-
if ($ta.css('box-sizing') ===
|
87
|
+
if ($ta.css('box-sizing') === 'border-box' || $ta.css('-moz-box-sizing') === 'border-box' || $ta.css('-webkit-box-sizing') === 'border-box'){
|
78
88
|
boxOffset = $ta.outerHeight() - $ta.height();
|
79
89
|
}
|
80
90
|
|
81
|
-
|
82
|
-
|
83
|
-
resize = ($ta.css('resize') === 'none' || $ta.css('resize') === 'vertical') ? 'none' : 'horizontal';
|
91
|
+
// IE8 and lower return 'auto', which parses to NaN, if no min-height is set.
|
92
|
+
minHeight = Math.max(parseInt($ta.css('minHeight'), 10) - boxOffset || 0, $ta.height());
|
84
93
|
|
85
94
|
$ta.css({
|
86
|
-
overflow: hidden,
|
87
|
-
overflowY: hidden,
|
88
|
-
wordWrap: 'break-word',
|
89
|
-
resize: resize
|
90
|
-
})
|
95
|
+
overflow: 'hidden',
|
96
|
+
overflowY: 'hidden',
|
97
|
+
wordWrap: 'break-word', // horizontal overflow is hidden, so break-word is necessary for handling words longer than the textarea width
|
98
|
+
resize: ($ta.css('resize') === 'none' || $ta.css('resize') === 'vertical') ? 'none' : 'horizontal'
|
99
|
+
});
|
100
|
+
|
101
|
+
// The mirror width must exactly match the textarea width, so using getBoundingClientRect because it doesn't round the sub-pixel value.
|
102
|
+
function setWidth() {
|
103
|
+
var style, width;
|
104
|
+
|
105
|
+
if ('getComputedStyle' in window) {
|
106
|
+
style = window.getComputedStyle(ta, null);
|
107
|
+
width = ta.getBoundingClientRect().width;
|
108
|
+
|
109
|
+
$.each(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'], function(i,val){
|
110
|
+
width -= parseInt(style[val],10);
|
111
|
+
});
|
112
|
+
|
113
|
+
mirror.style.width = width + 'px';
|
114
|
+
}
|
115
|
+
else {
|
116
|
+
// window.getComputedStyle, getBoundingClientRect returning a width are unsupported and unneeded in IE8 and lower.
|
117
|
+
mirror.style.width = Math.max($ta.width(), 0) + 'px';
|
118
|
+
}
|
119
|
+
}
|
91
120
|
|
92
121
|
function initMirror() {
|
122
|
+
var styles = {};
|
123
|
+
|
93
124
|
mirrored = ta;
|
94
125
|
mirror.className = options.className;
|
126
|
+
maxHeight = parseInt($ta.css('maxHeight'), 10);
|
95
127
|
|
96
128
|
// mirror is a duplicate textarea located off-screen that
|
97
129
|
// is automatically updated to contain the same text as the
|
98
130
|
// original textarea. mirror always has a height of 0.
|
99
131
|
// This gives a cross-browser supported way getting the actual
|
100
132
|
// height of the text, through the scrollTop property.
|
101
|
-
$.each(
|
102
|
-
|
133
|
+
$.each(typographyStyles, function(i,val){
|
134
|
+
styles[val] = $ta.css(val);
|
103
135
|
});
|
136
|
+
$(mirror).css(styles);
|
137
|
+
|
138
|
+
setWidth();
|
139
|
+
|
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.
|
143
|
+
if (window.chrome) {
|
144
|
+
var width = ta.style.width;
|
145
|
+
ta.style.width = '0px';
|
146
|
+
var ignore = ta.offsetWidth;
|
147
|
+
ta.style.width = width;
|
148
|
+
}
|
104
149
|
}
|
105
150
|
|
106
151
|
// Using mainly bare JS in this function because it is going
|
107
152
|
// to fire very often while typing, and needs to very efficient.
|
108
153
|
function adjust() {
|
109
|
-
var height,
|
154
|
+
var height, original;
|
110
155
|
|
111
156
|
if (mirrored !== ta) {
|
112
157
|
initMirror();
|
158
|
+
} else {
|
159
|
+
setWidth();
|
113
160
|
}
|
114
161
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
active = true;
|
119
|
-
mirror.value = ta.value + options.append;
|
120
|
-
mirror.style.overflowY = ta.style.overflowY;
|
121
|
-
original = parseInt(ta.style.height,10);
|
162
|
+
mirror.value = ta.value + options.append;
|
163
|
+
mirror.style.overflowY = ta.style.overflowY;
|
164
|
+
original = parseInt(ta.style.height,10);
|
122
165
|
|
123
|
-
|
124
|
-
|
125
|
-
mirror.style.width = Math.max($ta.width(), 0) + 'px';
|
166
|
+
// Setting scrollTop to zero is needed in IE8 and lower for the next step to be accurately applied
|
167
|
+
mirror.scrollTop = 0;
|
126
168
|
|
127
|
-
|
128
|
-
height = mirror.scrollHeight;
|
129
|
-
} else { // IE6 & IE7
|
130
|
-
mirror.scrollTop = 0;
|
131
|
-
mirror.scrollTop = 9e4;
|
132
|
-
height = mirror.scrollTop;
|
133
|
-
}
|
169
|
+
mirror.scrollTop = 9e4;
|
134
170
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
171
|
+
// Using scrollTop rather than scrollHeight because scrollHeight is non-standard and includes padding.
|
172
|
+
height = mirror.scrollTop;
|
173
|
+
|
174
|
+
if (maxHeight && height > maxHeight) {
|
175
|
+
ta.style.overflowY = 'scroll';
|
176
|
+
height = maxHeight;
|
177
|
+
} else {
|
178
|
+
ta.style.overflowY = 'hidden';
|
179
|
+
if (height < minHeight) {
|
142
180
|
height = minHeight;
|
143
181
|
}
|
144
|
-
|
145
|
-
ta.style.overflowY = overflow || hidden;
|
182
|
+
}
|
146
183
|
|
147
|
-
|
148
|
-
ta.style.height = height + 'px';
|
149
|
-
if (callback) {
|
150
|
-
options.callback.call(ta);
|
151
|
-
}
|
152
|
-
}
|
184
|
+
height += boxOffset;
|
153
185
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
}
|
186
|
+
if (original !== height) {
|
187
|
+
ta.style.height = height + 'px';
|
188
|
+
if (callback) {
|
189
|
+
options.callback.call(ta,ta);
|
190
|
+
}
|
159
191
|
}
|
160
192
|
}
|
161
193
|
|
162
|
-
|
163
|
-
|
194
|
+
function resize () {
|
195
|
+
clearTimeout(timeout);
|
196
|
+
timeout = setTimeout(function(){
|
197
|
+
var newWidth = $ta.width();
|
198
|
+
|
199
|
+
if (newWidth !== width) {
|
200
|
+
width = newWidth;
|
201
|
+
adjust();
|
202
|
+
}
|
203
|
+
}, parseInt(options.resizeDelay,10));
|
204
|
+
}
|
205
|
+
|
206
|
+
if ('onpropertychange' in ta) {
|
207
|
+
if ('oninput' in ta) {
|
164
208
|
// Detects IE9. IE9 does not fire onpropertychange or oninput for deletions,
|
165
|
-
// so binding to onkeyup to catch most of those
|
209
|
+
// so binding to onkeyup to catch most of those occasions. There is no way that I
|
166
210
|
// know of to detect something like 'cut' in IE9.
|
167
|
-
ta
|
211
|
+
$ta.on('input.autosize keyup.autosize', adjust);
|
168
212
|
} else {
|
169
213
|
// IE7 / IE8
|
170
|
-
ta
|
214
|
+
$ta.on('propertychange.autosize', function(){
|
215
|
+
if(event.propertyName === 'value'){
|
216
|
+
adjust();
|
217
|
+
}
|
218
|
+
});
|
171
219
|
}
|
172
220
|
} else {
|
173
221
|
// Modern Browsers
|
174
|
-
ta
|
222
|
+
$ta.on('input.autosize', adjust);
|
175
223
|
}
|
176
224
|
|
177
|
-
|
178
|
-
|
225
|
+
// Set options.resizeDelay to false if using fixed-width textarea elements.
|
226
|
+
// Uses a timeout and width check to reduce the amount of times adjust needs to be called after window resize.
|
227
|
+
|
228
|
+
if (options.resizeDelay !== false) {
|
229
|
+
$(window).on('resize.autosize', resize);
|
230
|
+
}
|
231
|
+
|
232
|
+
// Event for manual triggering if needed.
|
233
|
+
// Should only be needed when the value of the textarea is changed through JavaScript rather than user input.
|
234
|
+
$ta.on('autosize.resize', adjust);
|
235
|
+
|
236
|
+
// Event for manual triggering that also forces the styles to update as well.
|
237
|
+
// Should only be needed if one of typography styles of the textarea change, and the textarea is already the target of the adjust method.
|
238
|
+
$ta.on('autosize.resizeIncludeStyle', function() {
|
239
|
+
mirrored = null;
|
179
240
|
adjust();
|
180
241
|
});
|
181
242
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
243
|
+
$ta.on('autosize.destroy', function(){
|
244
|
+
mirrored = null;
|
245
|
+
clearTimeout(timeout);
|
246
|
+
$(window).off('resize', resize);
|
247
|
+
$ta
|
248
|
+
.off('autosize')
|
249
|
+
.off('.autosize')
|
250
|
+
.css(originalStyles)
|
251
|
+
.removeData('autosize');
|
186
252
|
});
|
187
253
|
|
188
254
|
// Call adjust in case the textarea already contains text.
|
189
255
|
adjust();
|
190
256
|
});
|
191
257
|
};
|
192
|
-
}
|
258
|
+
}));
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autosize-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caleb Thompson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
91
|
rubyforge_project:
|
92
|
-
rubygems_version: 2.0.
|
92
|
+
rubygems_version: 2.0.5
|
93
93
|
signing_key:
|
94
94
|
specification_version: 4
|
95
95
|
summary: A plugin to enable automatic height for textarea elements.
|