2015-01-23 13:09:30 +00:00
|
|
|
Htk.Spin = new Class
|
|
|
|
({
|
2016-01-15 12:31:08 +00:00
|
|
|
Extends: Htk.Field
|
2015-01-23 13:09:30 +00:00
|
|
|
,Tag: 'htk-spin'
|
|
|
|
|
|
|
|
,initialize: function (props)
|
|
|
|
{
|
2016-01-15 12:31:08 +00:00
|
|
|
var input = this.createElement ('input');
|
|
|
|
//setInputTypeNumber (input);
|
|
|
|
this.node.type = 'number';
|
|
|
|
input.addEventListener ('change', this._onChange.bind (this));
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
this.unit = null;
|
|
|
|
this.digits = 0;
|
2015-11-09 08:14:33 +00:00
|
|
|
this.parent (props);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 12:31:08 +00:00
|
|
|
,_onChange: function ()
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
2015-03-15 12:44:57 +00:00
|
|
|
var newValue = (this.node.value == '') ? null : parseFloat (this.node.value);
|
|
|
|
this.node.value = newValue;
|
2016-01-15 12:31:08 +00:00
|
|
|
this.valueChanged (newValue);
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2015-03-15 12:44:57 +00:00
|
|
|
,putValue: function (value)
|
2015-01-23 13:09:30 +00:00
|
|
|
{
|
|
|
|
var text;
|
|
|
|
|
|
|
|
if (value != null)
|
|
|
|
{
|
|
|
|
text = (new Number (value)).toFixed (this.digits);
|
|
|
|
|
|
|
|
if (this.unit != null)
|
|
|
|
text += ' ' + this.unit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
text = '';
|
|
|
|
|
2016-01-15 12:31:08 +00:00
|
|
|
this.node.value = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
,setEditable: function (editable)
|
|
|
|
{
|
|
|
|
this.node.readOnly = !editable;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
});
|