diff options
author | Richard Beales <[email protected]> | 2013-03-18 07:32:01 +0000 |
---|---|---|
committer | Richard Beales <[email protected]> | 2013-03-18 07:32:01 +0000 |
commit | 7c97d17aaf373339a8bcd917ad59ca6018148f0d (patch) | |
tree | 5a3c04f0f9529be392c1263d3feb75806eb43797 /lib/dijit/form/NumberSpinner.js.uncompressed.js | |
parent | 70db7424e7068701e60cc5bcdfe8f858be508179 (diff) | |
parent | c670a80ddd9b03bd4ea6d940a9ed682fd26248d7 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'lib/dijit/form/NumberSpinner.js.uncompressed.js')
-rw-r--r-- | lib/dijit/form/NumberSpinner.js.uncompressed.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/dijit/form/NumberSpinner.js.uncompressed.js b/lib/dijit/form/NumberSpinner.js.uncompressed.js new file mode 100644 index 000000000..87b417f40 --- /dev/null +++ b/lib/dijit/form/NumberSpinner.js.uncompressed.js @@ -0,0 +1,69 @@ +define("dijit/form/NumberSpinner", [ + "dojo/_base/declare", // declare + "dojo/_base/event", // event.stop + "dojo/keys", // keys.END keys.HOME + "./_Spinner", + "./NumberTextBox" +], function(declare, event, keys, _Spinner, NumberTextBox){ + +// module: +// dijit/form/NumberSpinner + + +return declare("dijit.form.NumberSpinner", [_Spinner, NumberTextBox.Mixin], { + // 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 NumberSpinner({ constraints:{ max:300, min:100 }}, "someInput"); + + baseClass: "dijitTextBox dijitSpinner dijitNumberTextBox", + + 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 == keys.HOME || e.charOrCode == 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 == keys.HOME ? "min" : "max")]; + if(typeof value == "number"){ + this._setValueAttr(value, false); + } + // eat home or end key whether we change the value or not + event.stop(e); + } + } +}); + +}); |