]> git.wh0rd.org - tt-rss.git/blame - lib/dijit/form/NumberSpinner.js.uncompressed.js
modify dojo rebuild script to remove uncompressed files
[tt-rss.git] / lib / dijit / form / NumberSpinner.js.uncompressed.js
CommitLineData
f0cfe83e
AD
1define("dijit/form/NumberSpinner", [
2 "dojo/_base/declare", // declare
3 "dojo/_base/event", // event.stop
4 "dojo/keys", // keys.END keys.HOME
5 "./_Spinner",
6 "./NumberTextBox"
7], function(declare, event, keys, _Spinner, NumberTextBox){
8
9// module:
10// dijit/form/NumberSpinner
11
12
13return declare("dijit.form.NumberSpinner", [_Spinner, NumberTextBox.Mixin], {
14 // summary:
15 // Extends NumberTextBox to add up/down arrows and pageup/pagedown for incremental change to the value
16 //
17 // description:
18 // A `dijit/form/NumberTextBox` extension to provide keyboard accessible value selection
19 // as well as icons for spinning direction. When using the keyboard, the typematic rules
20 // apply, meaning holding the key will gradually increase or decrease the value and
21 // accelerate.
22 //
23 // example:
24 // | new NumberSpinner({ constraints:{ max:300, min:100 }}, "someInput");
25
26 baseClass: "dijitTextBox dijitSpinner dijitNumberTextBox",
27
28 adjust: function(/*Object*/ val, /*Number*/ delta){
29 // summary:
30 // Change Number val by the given amount
31 // tags:
32 // protected
33
34 var tc = this.constraints,
35 v = isNaN(val),
36 gotMax = !isNaN(tc.max),
37 gotMin = !isNaN(tc.min)
38 ;
39 if(v && delta != 0){ // blank or invalid value and they want to spin, so create defaults
40 val = (delta > 0) ?
41 gotMin ? tc.min : gotMax ? tc.max : 0 :
42 gotMax ? this.constraints.max : gotMin ? tc.min : 0
43 ;
44 }
45 var newval = val + delta;
46 if(v || isNaN(newval)){ return val; }
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 _onKeyPress: function(e){
57 if((e.charOrCode == keys.HOME || e.charOrCode == keys.END) && !(e.ctrlKey || e.altKey || e.metaKey)
58 && typeof this.get('value') != 'undefined' /* gibberish, so HOME and END are default editing keys*/){
59 var value = this.constraints[(e.charOrCode == keys.HOME ? "min" : "max")];
60 if(typeof value == "number"){
61 this._setValueAttr(value, false);
62 }
63 // eat home or end key whether we change the value or not
64 event.stop(e);
65 }
66 }
67});
68
69});