]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/form/NumberSpinner.js
2 Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo
._hasResource
["dijit.form.NumberSpinner"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo
._hasResource
["dijit.form.NumberSpinner"] = true;
10 dojo
.provide("dijit.form.NumberSpinner");
11 dojo
.require("dijit.form._Spinner");
12 dojo
.require("dijit.form.NumberTextBox");
15 dojo
.declare("dijit.form.NumberSpinner",
16 [dijit
.form
._Spinner
, dijit
.form
.NumberTextBoxMixin
],
19 // Extends NumberTextBox to add up/down arrows and pageup/pagedown for incremental change to the value
22 // A `dijit.form.NumberTextBox` extension to provide keyboard accessible value selection
23 // as well as icons for spinning direction. When using the keyboard, the typematic rules
24 // apply, meaning holding the key will gradually increase or decrease the value and
28 // | new dijit.form.NumberSpinner({ constraints:{ max:300, min:100 }}, "someInput");
30 adjust: function(/*Object*/ val
, /*Number*/ delta
){
32 // Change Number val by the given amount
36 var tc
= this.constraints
,
38 gotMax
= !isNaN(tc
.max
),
39 gotMin
= !isNaN(tc
.min
)
41 if(v
&& delta
!= 0){ // blank or invalid value and they want to spin, so create defaults
43 gotMin
? tc
.min
: gotMax
? tc
.max
: 0 :
44 gotMax
? this.constraints
.max
: gotMin
? tc
.min
: 0
47 var newval
= val
+ delta
;
48 if(v
|| isNaN(newval
)){ return val
; }
49 if(gotMax
&& (newval
> tc
.max
)){
52 if(gotMin
&& (newval
< tc
.min
)){
58 _onKeyPress: function(e
){
59 if((e
.charOrCode
== dojo
.keys
.HOME
|| e
.charOrCode
== dojo
.keys
.END
) && !(e
.ctrlKey
|| e
.altKey
|| e
.metaKey
)
60 && typeof this.get('value') != 'undefined' /* gibberish, so HOME and END are default editing keys*/){
61 var value
= this.constraints
[(e
.charOrCode
== dojo
.keys
.HOME
? "min" : "max")];
62 if(typeof value
== "number"){
63 this._setValueAttr(value
, false);
65 // eat home or end key whether we change the value or not