-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabelInput.js
More file actions
69 lines (68 loc) · 1.7 KB
/
LabelInput.js
File metadata and controls
69 lines (68 loc) · 1.7 KB
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
var compose = require('ksf/utils/compose');
var _Destroyable = require('ksf/base/_Destroyable');
var FocusableElement = require('./FocusableElement');
var _ContentDelegate = require('./_ContentDelegate');
module.exports = compose(_Destroyable, _ContentDelegate, function(args) {
this.element = this._content = new FocusableElement('input');
this._content.prop('type', args && args.type ? args.type : 'text');
this._asYouType = args && args.asYouType;
}, {
value: function(value) {
if (arguments.length) {
this._content.prop('value', (typeof value === 'string' ? value : ''));
return this;
} else {
return this._content.prop('value');
}
},
onInput: function(cb, key) {
var self = this;
this._content.on(this._asYouType ? 'input' : 'change', function() {
cb(self.value());
});
this._own(cb, key);
return this;
},
offInput: function(key) {
var cb = this._owned[key];
this._unown(key);
this._content.off(this._asYouType ? 'input' : 'change', cb);
return this;
},
placeholder: function(placeholder) {
this._content.prop('placeholder', placeholder);
return this;
},
style: function(style) {
this._content.style(style);
return this;
},
focus: function(focus) {
if (arguments.length) {
this._content.focus(focus);
return this;
} else {
return this._content.focus();
}
},
onFocus: function(cb) {
this._content.onFocus(cb);
return this;
},
offFocus: function(cb) {
this._content.offFocus(cb);
return this;
},
onKeyDown: function(cb) {
this._content.on('keydown', cb);
return this;
},
disabled: function (value) {
if (arguments.length) {
this._content.prop('disabled', value)
return this
} else {
return this._content.prop('disabled')
}
}
});