function QSpinEdit(EditId, minValue, maxValue) { //properties this.EditId = EditId;//deprecated this.ObjectRef = []; this.ObjectId = []; this.ObjectId['Edit'] = EditId; this.ObjectId['UpArrow'] = "up"+EditId; this.ObjectId['DownArrow'] = "down"+EditId; this.DefaultValue = minValue; this.MinValue = minValue; this.MaxValue = maxValue; this.Size = 2; //no effect after WriteControl this.BackgroundColor = 'white'; this.Style = 'vert'; //no effect after WriteControl this.ReadOnly = false; //read-only property this.TimerObj = null; this.Step = -1; //public methods QSpinEdit.prototype.AddSubStep = AddSubStep; QSpinEdit.prototype.WriteControl = WriteControl; QSpinEdit.prototype.GetValue = GetValue; QSpinEdit.prototype.SetValue = SetValue; QSpinEdit.prototype.Validate = Validate; QSpinEdit.prototype.Disable = Disable; QSpinEdit.prototype.Enable = Enable; QSpinEdit.prototype.ResetValue = ResetValue; //internal event handlers; there is not need to call them directly QSpinEdit.prototype.HandleChange = HandleChange; //private function members var FixJSFloatBug = function FixJSFloatBug(n){return Math.round(n*100)/100;} //events QSpinEdit.prototype.OnChange = function OnChange(){}; QSpinEdit.prototype.OnValidateError = function OnValidateError(){}; //----------------------------------------------------------------- function Validate(theValue) { if (theValue === '' || theValue == null || theValue > this.MaxValue || theValue < this.MinValue || isFinite(theValue) == 0 || String(FixJSFloatBug(theValue)).indexOf('.') !=- 1) { this.OnValidateError(); return false; } else { //prevent bug when user enters '07' for example in the edit field this.ObjectRef['Edit'].value = FixJSFloatBug(theValue*1); //little trick to convert to numeric and prevent JS Floating point operation bugs return true; } } function AddSubStep(mode) { if (this.TimerObj) { clearTimeout(this.TimerObj); } if (this.ObjectRef['Edit'].disabled) { return; } var OldValue = this.n; if (this.Step > 0) { this.n = FixJSFloatBug((mode == "add") ? this.n+this.Step : this.n-this.Step); if (this.n < this.MinValue) { this.n = this.MinValue; } else if (this.n > this.MaxValue) { this.n = this.MaxValue; } } else { var i = 0; for (i=0; i<=5; i++) { var tmp = Math.pow(2, i)*10; //10,20,40,80,160 if (this.n == tmp) { this.n = FixJSFloatBug((mode == "add") ? tmp*2 : tmp/2); if (this.n < 10) { this.n = FixJSFloatBug(10); } else if (this.n > 320) { this.n = FixJSFloatBug(320); } break; } else if (this.n < tmp) { if ((tmp == 10) && (mode == "sub")) { this.n = FixJSFloatBug(this.MinValue); } else { this.n = FixJSFloatBug((mode == "add") ? tmp : tmp/2); } break; } } } if (this.n != OldValue) { this.ObjectRef['Edit'].value = this.n; this.OnChange(); } var myObj = this; this.TimerObj = setTimeout(function(){myObj.AddSubStep(mode)}, 200); } function WriteControl(SpinName) { this.n = this.DefaultValue; var readonly_str = ''; if (this.ReadOnly) { readonly_str = 'readonly="readonly"'; } document.write('
| '); document.write(' | '); document.write(' | ||
| '); } else { //horizontal document.write(' | '); document.write(' | '); document.write(' | '); } document.write(' |