-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
219 lines (167 loc) · 4.91 KB
/
example.html
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>test--textarea-resize</title>
<style style="display: block; white-space: pre;" contenteditable="true">
button,
textarea {
font-family: inherit;
}
.page {
font-family: 'segoe ui', sans-serif;
}
.page__header {
padding: 0 3%;
}
.examples {
display: inline-block;
width: 100%;
}
.examples__style {
display: block;
font-family: consolas, monospace;
margin: 0 3%;
white-space: pre;
}
.example {
box-sizing: border-box;
float: left;
min-width: 33%;
padding: 1% 3%;
}
.animated {
border: 15px solid red;
display: inline-block;
transition: .2s;
}
.animated__field {
background-color: transparent;
border: 0;
outline: 0;
resize: none;
}
.bscb { box-sizing: content-box; }
.bsbb { box-sizing: border-box; }
.mnh { min-height: 7.3em; }
[hidden] { display: none; }
.added {
display: inline-block;
}
.addedInput {
height: 100px;
}
.addedInputWithMinHeight {
height: auto;
min-height: 100px;
}
</style>
</head>
<body class="page">
<h1 class="page__header">fieldAutosize</h1>
<style id="examplesStyle" class="examples__style" contenteditable="true">textarea {
border: 15px solid red;
padding: 10px;
}</style>
<div class="examples">
<div class="example">
<h4>Стандартные настройки с внутренним отступом и границей</h4>
<textarea rows="3" cols="4" style="width: 10em;"></textarea>
</div>
<div class="example">
<h4>Разнообразные <code>box-sizing</code></h4>
<table><tbody><tr>
<td>
<p><code>content-box</code></p>
<textarea class="bscb"></textarea>
</td>
<td>
<p><code>border-box</code></p>
<textarea class="bsbb"></textarea>
</td>
</tr></tbody></table>
</div>
<div class="example">
<h4>Минимальная высота</h4>
<textarea class="mnh"></textarea>
</div>
<div class="example">
<h4>Анимация</h4>
<div class="animated">
<textarea class="animated__field" rows="1"></textarea>
</div>
</div>
<div class="example">
<h4>Скрытое поле</h4>
<div id="toggleContainer" hidden>
<textarea></textarea>
</div>
<p><button id="toggleShow">Показать поле</button></p>
</div>
<div class="example">
<h4>Исключение поля</h4>
<div class="exclude">
<textarea id="excluded">
бац!
а тут текст
</textarea>
</div>
<p><button id="handle">Выставить верную высоту</button></p>
</div>
<div id="addContainer" class="example">
<h4>Поля, добавляемые динамически</h4>
<p>
<button id="add">Добавить поле</button>
<button id="addWithMinHeight">Добавить с минимальной высотой</button>
<button id="addWithWrapper">Добавить с обёрткой</button>
</p>
</div>
</div>
<script src="fieldAutosize.js"></script>
<script>
document.getElementById('examplesStyle').oninput = function (e) {
fieldAutosize.process();
};
fieldAutosize.exclude = '.exclude textarea';
setTimeout(function () {
document.getElementById('excluded').className += ' test-attr-change';
}, 3000);
document.getElementById('toggleShow').onclick = function () {
var toggleContainer = document.getElementById('toggleContainer');
toggleContainer.hidden = !toggleContainer.hidden;
this.innerHTML.match('Показать') ?
this.innerHTML = this.innerHTML.replace('Показать', 'Скрыть')
: this.innerHTML = this.innerHTML.replace('Скрыть', 'Показать');
};
document.getElementById('handle').onclick = function () {
var textarea = this.parentNode.parentNode.getElementsByTagName('textarea')[0];
fieldAutosize.handle(textarea);
};
document.getElementById('add').onclick = add;
document.getElementById('addWithMinHeight').onclick = add;
document.getElementById('addWithWrapper').onclick = add;
document.addEventListener('fieldAutosize:resize', function (e) {
var obj = e.target.closest('.animated__field');
if (obj) {
var container = obj.closest('.animated');
container.style.height = e.detail.height +'px';
};
});
function add (e) {
var result = document.createElement('textarea');
var wrapper;
result.className = 'addedInput';
if (e.target.id === 'addWithMinHeight') {
result.className += ' addedInputWithMinHeight';
}
else if (e.target.id === 'addWithWrapper') {
wrapper = document.createElement('div');
wrapper.className = 'added';
wrapper.appendChild(result);
result = wrapper;
}
document.getElementById('addContainer').appendChild(result);
}
</script>
</body>
</html>