| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/keys", |
| 4 |
"./_Spinner", |
| 5 |
"./NumberTextBox" |
| 6 |
], function(declare, keys, _Spinner, NumberTextBox){ |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
return declare("dijit.form.NumberSpinner", [_Spinner, NumberTextBox.Mixin], { |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
baseClass: "dijitTextBox dijitSpinner dijitNumberTextBox", |
| 25 |
|
| 26 |
adjust: function( val, delta){ |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
var tc = this.constraints, |
| 33 |
v = isNaN(val), |
| 34 |
gotMax = !isNaN(tc.max), |
| 35 |
gotMin = !isNaN(tc.min) |
| 36 |
; |
| 37 |
if(v && delta != 0){ |
| 38 |
val = (delta > 0) ? |
| 39 |
gotMin ? tc.min : gotMax ? tc.max : 0 : |
| 40 |
gotMax ? this.constraints.max : gotMin ? tc.min : 0 |
| 41 |
; |
| 42 |
} |
| 43 |
var newval = val + delta; |
| 44 |
if(v || isNaN(newval)){ |
| 45 |
return val; |
| 46 |
} |
| 47 |
if(gotMax && (newval > tc.max)){ |
| 48 |
newval = tc.max; |
| 49 |
} |
| 50 |
if(gotMin && (newval < tc.min)){ |
| 51 |
newval = tc.min; |
| 52 |
} |
| 53 |
return newval; |
| 54 |
}, |
| 55 |
|
| 56 |
_onKeyDown: function(e){ |
| 57 |
if(this.disabled || this.readOnly){ |
| 58 |
return; |
| 59 |
} |
| 60 |
if((e.keyCode == keys.HOME || e.keyCode == keys.END) && !(e.ctrlKey || e.altKey || e.metaKey) |
| 61 |
&& typeof this.get('value') != 'undefined' ){ |
| 62 |
var value = this.constraints[(e.keyCode == keys.HOME ? "min" : "max")]; |
| 63 |
if(typeof value == "number"){ |
| 64 |
this._setValueAttr(value, false); |
| 65 |
} |
| 66 |
|
| 67 |
e.stopPropagation(); |
| 68 |
e.preventDefault(); |
| 69 |
} |
| 70 |
} |
| 71 |
}); |
| 72 |
}); |