summaryrefslogtreecommitdiff
path: root/lib/dijit/form/NumberSpinner.js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2011-11-08 20:40:44 +0400
committerAndrew Dolgov <[email protected]>2011-11-08 20:40:44 +0400
commit81bea17aefb26859f825b9293c7c99192874806e (patch)
treefb244408ca271affa2899adb634788802c9a89d8 /lib/dijit/form/NumberSpinner.js
parent870a70e109ac9e80a88047044530de53d0404ec7 (diff)
upgrade Dojo to 1.6.1
Diffstat (limited to 'lib/dijit/form/NumberSpinner.js')
-rw-r--r--lib/dijit/form/NumberSpinner.js89
1 files changed, 61 insertions, 28 deletions
diff --git a/lib/dijit/form/NumberSpinner.js b/lib/dijit/form/NumberSpinner.js
index 82a3c4024..ba5a782f5 100644
--- a/lib/dijit/form/NumberSpinner.js
+++ b/lib/dijit/form/NumberSpinner.js
@@ -1,38 +1,71 @@
/*
- Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
Available via Academic Free License >= 2.1 OR the modified BSD license.
see: http://dojotoolkit.org/license for details
*/
-if(!dojo._hasResource["dijit.form.NumberSpinner"]){
-dojo._hasResource["dijit.form.NumberSpinner"]=true;
+if(!dojo._hasResource["dijit.form.NumberSpinner"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dijit.form.NumberSpinner"] = true;
dojo.provide("dijit.form.NumberSpinner");
dojo.require("dijit.form._Spinner");
dojo.require("dijit.form.NumberTextBox");
-dojo.declare("dijit.form.NumberSpinner",[dijit.form._Spinner,dijit.form.NumberTextBoxMixin],{adjust:function(_1,_2){
-var tc=this.constraints,v=isNaN(_1),_3=!isNaN(tc.max),_4=!isNaN(tc.min);
-if(v&&_2!=0){
-_1=(_2>0)?_4?tc.min:_3?tc.max:0:_3?this.constraints.max:_4?tc.min:0;
-}
-var _5=_1+_2;
-if(v||isNaN(_5)){
-return _1;
-}
-if(_3&&(_5>tc.max)){
-_5=tc.max;
-}
-if(_4&&(_5<tc.min)){
-_5=tc.min;
-}
-return _5;
-},_onKeyPress:function(e){
-if((e.charOrCode==dojo.keys.HOME||e.charOrCode==dojo.keys.END)&&!(e.ctrlKey||e.altKey||e.metaKey)&&typeof this.get("value")!="undefined"){
-var _6=this.constraints[(e.charOrCode==dojo.keys.HOME?"min":"max")];
-if(typeof _6=="number"){
-this._setValueAttr(_6,false);
-}
-dojo.stopEvent(e);
-}
-}});
+
+
+dojo.declare("dijit.form.NumberSpinner",
+ [dijit.form._Spinner, dijit.form.NumberTextBoxMixin],
+ {
+ // summary:
+ // Extends NumberTextBox to add up/down arrows and pageup/pagedown for incremental change to the value
+ //
+ // description:
+ // A `dijit.form.NumberTextBox` extension to provide keyboard accessible value selection
+ // as well as icons for spinning direction. When using the keyboard, the typematic rules
+ // apply, meaning holding the key will gradually increase or decrease the value and
+ // accelerate.
+ //
+ // example:
+ // | new dijit.form.NumberSpinner({ constraints:{ max:300, min:100 }}, "someInput");
+
+ adjust: function(/*Object*/ val, /*Number*/ delta){
+ // summary:
+ // Change Number val by the given amount
+ // tags:
+ // protected
+
+ var tc = this.constraints,
+ v = isNaN(val),
+ gotMax = !isNaN(tc.max),
+ gotMin = !isNaN(tc.min)
+ ;
+ if(v && delta != 0){ // blank or invalid value and they want to spin, so create defaults
+ val = (delta > 0) ?
+ gotMin ? tc.min : gotMax ? tc.max : 0 :
+ gotMax ? this.constraints.max : gotMin ? tc.min : 0
+ ;
+ }
+ var newval = val + delta;
+ if(v || isNaN(newval)){ return val; }
+ if(gotMax && (newval > tc.max)){
+ newval = tc.max;
+ }
+ if(gotMin && (newval < tc.min)){
+ newval = tc.min;
+ }
+ return newval;
+ },
+
+ _onKeyPress: function(e){
+ if((e.charOrCode == dojo.keys.HOME || e.charOrCode == dojo.keys.END) && !(e.ctrlKey || e.altKey || e.metaKey)
+ && typeof this.get('value') != 'undefined' /* gibberish, so HOME and END are default editing keys*/){
+ var value = this.constraints[(e.charOrCode == dojo.keys.HOME ? "min" : "max")];
+ if(typeof value == "number"){
+ this._setValueAttr(value, false);
+ }
+ // eat home or end key whether we change the value or not
+ dojo.stopEvent(e);
+ }
+ }
+});
+
}