]> git.wh0rd.org - tt-rss.git/blob - lib/dijit/form/NumberSpinner.js
upgrade Dojo to 1.6.1
[tt-rss.git] / lib / dijit / form / NumberSpinner.js
1 /*
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
5 */
6
7
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");
13
14
15 dojo.declare("dijit.form.NumberSpinner",
16 [dijit.form._Spinner, dijit.form.NumberTextBoxMixin],
17 {
18 // summary:
19 // Extends NumberTextBox to add up/down arrows and pageup/pagedown for incremental change to the value
20 //
21 // description:
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
25 // accelerate.
26 //
27 // example:
28 // | new dijit.form.NumberSpinner({ constraints:{ max:300, min:100 }}, "someInput");
29
30 adjust: function(/*Object*/ val, /*Number*/ delta){
31 // summary:
32 // Change Number val by the given amount
33 // tags:
34 // protected
35
36 var tc = this.constraints,
37 v = isNaN(val),
38 gotMax = !isNaN(tc.max),
39 gotMin = !isNaN(tc.min)
40 ;
41 if(v && delta != 0){ // blank or invalid value and they want to spin, so create defaults
42 val = (delta > 0) ?
43 gotMin ? tc.min : gotMax ? tc.max : 0 :
44 gotMax ? this.constraints.max : gotMin ? tc.min : 0
45 ;
46 }
47 var newval = val + delta;
48 if(v || isNaN(newval)){ return val; }
49 if(gotMax && (newval > tc.max)){
50 newval = tc.max;
51 }
52 if(gotMin && (newval < tc.min)){
53 newval = tc.min;
54 }
55 return newval;
56 },
57
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);
64 }
65 // eat home or end key whether we change the value or not
66 dojo.stopEvent(e);
67 }
68 }
69 });
70
71 }