-
Notifications
You must be signed in to change notification settings - Fork 0
/
_InputElement.js
43 lines (40 loc) · 1014 Bytes
/
_InputElement.js
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
var compose = require('ksf/utils/compose');
var FocusableElement = require('./FocusableElement');
module.exports = compose(FocusableElement.prototype, function(args) {
FocusableElement.call(this, 'input');
this._asYouType = args && args.asYouType;
// callbacks mapping
this._inputCbMap = [];
}, {
value: function(value) {
if (arguments.length) {
this._setValue(value);
return this;
} else {
return this._getValue();
}
},
onInput: function(cb) {
var self = this;
var inputCb = function() {
cb(self._getValue());
};
this.on(this._asYouType ? 'input' : 'change', inputCb);
this._inputCbMap.push([cb, inputCb]);
return this;
},
offInput: function(cb) {
var inputCb;
var inputCbMap = this._inputCbMap
// TODO: replace with ES6 Map?
inputCbMap.some(function(couple, index) {
if (couple[0] === cb) {
inputCb = couple[1];
inputCbMap.splice(index, 1);
return true;
}
});
this.off(this._asYouType ? 'input' : 'change', inputCb);
return this;
},
});