1 | const EventEmitter = require('events').EventEmitter
|
2 | const inherits = require('inherits')
|
3 | const css = require('dom-css')
|
4 | const autosize = require('autosize');
|
5 | const extend = require('just-extend');
|
6 |
|
7 | module.exports = Textarea
|
8 | inherits(Textarea, EventEmitter)
|
9 |
|
10 | function Textarea (opts) {
|
11 | if (!(this instanceof Textarea)) return new Textarea(opts)
|
12 |
|
13 |
|
14 | let input = opts.container.querySelector('.settings-panel-textarea');
|
15 | if (!input) {
|
16 | input = opts.container.appendChild(document.createElement('textarea'));
|
17 | input.className = 'settings-panel-textarea';
|
18 |
|
19 | this.element = input;
|
20 |
|
21 | setTimeout(() => {
|
22 | this.emit('init', input.value)
|
23 | autosize.update(input);
|
24 | })
|
25 |
|
26 | input.oninput = (data) => {
|
27 | this.emit('input', data.target.value)
|
28 | }
|
29 |
|
30 | autosize(input);
|
31 | }
|
32 |
|
33 | this.update(opts);
|
34 | }
|
35 |
|
36 | Textarea.prototype.update = function (opts) {
|
37 | extend(this, opts);
|
38 |
|
39 | this.element.rows = this.rows || 1;
|
40 | this.element.placeholder = this.placeholder || '';
|
41 | this.element.id = this.id
|
42 |
|
43 | this.element.value = this.value || '';
|
44 |
|
45 | this.element.disabled = !!this.disabled;
|
46 |
|
47 | return this;
|
48 | } |
\ | No newline at end of file |