UNPKG

1.07 kBJavaScriptView Raw
1const EventEmitter = require('events').EventEmitter
2const inherits = require('inherits')
3const css = require('dom-css')
4const num = require('input-number');
5const extend = require('just-extend');
6
7module.exports = Text
8inherits(Text, EventEmitter)
9
10function Text (opts) {
11 if (!(this instanceof Text)) return new Text(opts)
12
13 let element = opts.container.querySelector('.settings-panel-text');
14
15 if (!element) {
16 element = opts.container.appendChild(document.createElement('input'));
17 element.className = 'settings-panel-text';
18 num(element);
19
20 if (opts.placeholder) element.placeholder = opts.placeholder;
21
22 this.element = element;
23
24 element.oninput = (data) => {
25 this.emit('input', data.target.value)
26 }
27 setTimeout(() => {
28 this.emit('init', element.value)
29 });
30 }
31
32 this.update(opts);
33}
34
35Text.prototype.update = function (opts) {
36 extend(this, opts);
37 this.element.type = this.type
38 this.element.id = this.id
39 this.element.value = this.value || ''
40 this.element.disabled = !!this.disabled;
41 return this;
42}