-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberInput.js
More file actions
46 lines (46 loc) · 1.12 KB
/
NumberInput.js
File metadata and controls
46 lines (46 loc) · 1.12 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
function NumberInput(node, assignTransformer) {
"use strict";
var that = this;
this._assignTransformer = assignTransformer || (function(i) { return i; });
this._node = node;
this._node.addEventListener('change', function() { that._read(); });
this._onchange = function(val) {};
this._read();
}
NumberInput.prototype={
clear: function() {
"use strict";
var val = this._val;
this._node.value = "";
this._val = null;
return val;
},
minus: function(val) {
"use strict";
return this.plus(-val);
},
plus: function(val) {
"use strict";
return this.val(this._val + val);
},
_read: function() {
"use strict";
this._val = this._assignTransformer(parseInt(this._node.value, 10));
this._onchange(this._val);
},
val: function(val) {
"use strict";
var newval;
if (val || val === 0) {
newval = this._assignTransformer(val);
if (newval !== this._val) {
this._val = newval;
this._onchange(newval);
}
if (newval !== parseInt(this._node.value, 10)) {
this._node.value = newval;
}
}
return this._val;
}
};