-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberInput.js
More file actions
39 lines (38 loc) · 1.06 KB
/
NumberInput.js
File metadata and controls
39 lines (38 loc) · 1.06 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
var compose = require('ksf/utils/compose');
var _Destroyable = require('ksf/base/_Destroyable');
var Elmt = require('./Element');
var _ContentDelegate = require('./_ContentDelegate');
module.exports = compose(_Destroyable, _ContentDelegate, function(args) {
this._content = new Elmt('input').styleProp('font', 'inherit');
this._content.prop('type', 'number');
this._asYouType = args && args.asYouType;
}, {
value: function(value) {
if (arguments.length) {
if (value !== undefined) {
this._content.prop('valueAsNumber', value);
}
return this;
} else {
return this._content.prop('valueAsNumber');
}
},
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;
},
});