123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
'use strict';
modulum('SpinEditMobileWidget', ['SpinEditWidgetBase', 'WidgetFactory'],
function(context, cls) {
cls.SpinEditMobileWidget = context.oo.Class(cls.SpinEditWidgetBase, function($super) {
return {
__name: 'SpinEditMobileWidget',
_initElement: function() {
$super._initElement.call(this);
this.getElement().on('touchstart.SpinEditMobileWidget', this._onTouch.bind(this));
},
destroy: function() {
this.getElement().off('touchstart.SpinEditMobileWidget');
$super.destroy.call(this);
},
_onTouch: function(event) {
if (this.isEnabled()) {
this._inputElement.setAttribute("placeholder", this._inputElement.value);
this._inputElement.value = "";
}
this._onRequestFocus(event);
},
_onInput: function() {
$super._onInput.call(this);
var curVal = this.getValue();
if (this._max && curVal > this._max) {
this.setValue(this._max);
}
if (this._min && curVal < this._min) {
this.setValue(this._min);
}
},
getValue: function() {
var value = parseInt(this._inputElement.value, 10);
var isDefined = Object.isNumber(value) && !Object.isNaN(value);
return isDefined ? value : this._oldValue;
},
loseFocus: function() {
if (this._inputElement.value === "") {
this._inputElement.value = this._oldValue;
}
}
};
});
});