hedera-web/web/js/htk/field/spin.js

60 lines
1.0 KiB
JavaScript
Executable File

Htk.Spin = new Class
({
Extends: Htk.Entry
,Tag: 'htk-spin'
,initialize: function (props)
{
this.unit = null;
this.digits = 0;
this.parent (props);
}
,changed: function ()
{
var newValue = (this.node.value == '') ? null : parseFloat (this.node.value);
this.node.value = newValue;
this.realValue = value;
this.signalEmit ('changed');
}
,setEditable: function (editable)
{
if (editable)
{
var input = document.createElement ('input');
input.style.textAlign = 'right';
input.style.width = '100%';
setInputTypeNumber (input);
input.addEventListener ('change', this.changed.bind (this));
this.node.appendChild (input);
this.entry = input;
}
else
{
removeChilds (this.node);
this.entry = null;
}
}
,putValue: function (value)
{
var text;
if (value != null)
{
text = (new Number (value)).toFixed (this.digits);
if (this.unit != null)
text += ' ' + this.unit;
}
else
text = '';
if (!this.editable)
setText (this.node, text);
else
this.entry.value = text;
}
});