]>
Commit | Line | Data |
---|---|---|
2f01fe57 | 1 | /* |
81bea17a | 2 | Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. |
2f01fe57 AD |
3 | Available via Academic Free License >= 2.1 OR the modified BSD license. |
4 | see: http://dojotoolkit.org/license for details | |
5 | */ | |
6 | ||
7 | ||
81bea17a AD |
8 | if(!dojo._hasResource["dijit.form._Spinner"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. |
9 | dojo._hasResource["dijit.form._Spinner"] = true; | |
2f01fe57 AD |
10 | dojo.provide("dijit.form._Spinner"); |
11 | dojo.require("dijit.form.ValidationTextBox"); | |
81bea17a AD |
12 | |
13 | ||
14 | dojo.declare( | |
15 | "dijit.form._Spinner", | |
16 | dijit.form.RangeBoundTextBox, | |
17 | { | |
18 | // summary: | |
19 | // Mixin for validation widgets with a spinner. | |
20 | // description: | |
21 | // This class basically (conceptually) extends `dijit.form.ValidationTextBox`. | |
22 | // It modifies the template to have up/down arrows, and provides related handling code. | |
23 | ||
24 | // defaultTimeout: Number | |
25 | // Number of milliseconds before a held arrow key or up/down button becomes typematic | |
26 | defaultTimeout: 500, | |
27 | ||
28 | // minimumTimeout: Number | |
29 | // minimum number of milliseconds that typematic event fires when held key or button is held | |
30 | minimumTimeout: 10, | |
31 | ||
32 | // timeoutChangeRate: Number | |
33 | // Fraction of time used to change the typematic timer between events. | |
34 | // 1.0 means that each typematic event fires at defaultTimeout intervals. | |
35 | // < 1.0 means that each typematic event fires at an increasing faster rate. | |
36 | timeoutChangeRate: 0.90, | |
37 | ||
38 | // smallDelta: Number | |
39 | // Adjust the value by this much when spinning using the arrow keys/buttons | |
40 | smallDelta: 1, | |
41 | ||
42 | // largeDelta: Number | |
43 | // Adjust the value by this much when spinning using the PgUp/Dn keys | |
44 | largeDelta: 10, | |
45 | ||
46 | templateString: dojo.cache("dijit.form", "templates/Spinner.html", "<div class=\"dijit dijitReset dijitInlineTable dijitLeft\"\n\tid=\"widget_${id}\" role=\"presentation\"\n\t><div class=\"dijitReset dijitButtonNode dijitSpinnerButtonContainer\"\n\t\t><input class=\"dijitReset dijitInputField dijitSpinnerButtonInner\" type=\"text\" tabIndex=\"-1\" readonly=\"readonly\" role=\"presentation\"\n\t\t/><div class=\"dijitReset dijitLeft dijitButtonNode dijitArrowButton dijitUpArrowButton\"\n\t\t\tdojoAttachPoint=\"upArrowNode\"\n\t\t\t><div class=\"dijitArrowButtonInner\"\n\t\t\t\t><input class=\"dijitReset dijitInputField\" value=\"▲\" type=\"text\" tabIndex=\"-1\" readonly=\"readonly\" role=\"presentation\"\n\t\t\t\t\t${_buttonInputDisabled}\n\t\t\t/></div\n\t\t></div\n\t\t><div class=\"dijitReset dijitLeft dijitButtonNode dijitArrowButton dijitDownArrowButton\"\n\t\t\tdojoAttachPoint=\"downArrowNode\"\n\t\t\t><div class=\"dijitArrowButtonInner\"\n\t\t\t\t><input class=\"dijitReset dijitInputField\" value=\"▼\" type=\"text\" tabIndex=\"-1\" readonly=\"readonly\" role=\"presentation\"\n\t\t\t\t\t${_buttonInputDisabled}\n\t\t\t/></div\n\t\t></div\n\t></div\n\t><div class='dijitReset dijitValidationContainer'\n\t\t><input class=\"dijitReset dijitInputField dijitValidationIcon dijitValidationInner\" value=\"Χ\" type=\"text\" tabIndex=\"-1\" readonly=\"readonly\" role=\"presentation\"\n\t/></div\n\t><div class=\"dijitReset dijitInputField dijitInputContainer\"\n\t\t><input class='dijitReset dijitInputInner' dojoAttachPoint=\"textbox,focusNode\" type=\"${type}\" dojoAttachEvent=\"onkeypress:_onKeyPress\"\n\t\t\trole=\"spinbutton\" autocomplete=\"off\" ${!nameAttrSetting}\n\t/></div\n></div>\n"), | |
47 | ||
48 | baseClass: "dijitTextBox dijitSpinner", | |
49 | ||
50 | // Set classes like dijitUpArrowButtonHover or dijitDownArrowButtonActive depending on | |
51 | // mouse action over specified node | |
52 | cssStateNodes: { | |
53 | "upArrowNode": "dijitUpArrowButton", | |
54 | "downArrowNode": "dijitDownArrowButton" | |
55 | }, | |
56 | ||
57 | adjust: function(/*Object*/ val, /*Number*/ delta){ | |
58 | // summary: | |
59 | // Overridable function used to adjust a primitive value(Number/Date/...) by the delta amount specified. | |
60 | // The val is adjusted in a way that makes sense to the object type. | |
61 | // tags: | |
62 | // protected extension | |
63 | return val; | |
64 | }, | |
65 | ||
66 | _arrowPressed: function(/*Node*/ nodePressed, /*Number*/ direction, /*Number*/ increment){ | |
67 | // summary: | |
68 | // Handler for arrow button or arrow key being pressed | |
69 | if(this.disabled || this.readOnly){ return; } | |
70 | this._setValueAttr(this.adjust(this.get('value'), direction*increment), false); | |
71 | dijit.selectInputText(this.textbox, this.textbox.value.length); | |
72 | }, | |
73 | ||
74 | _arrowReleased: function(/*Node*/ node){ | |
75 | // summary: | |
76 | // Handler for arrow button or arrow key being released | |
77 | this._wheelTimer = null; | |
78 | if(this.disabled || this.readOnly){ return; } | |
79 | }, | |
80 | ||
81 | _typematicCallback: function(/*Number*/ count, /*DOMNode*/ node, /*Event*/ evt){ | |
82 | var inc=this.smallDelta; | |
83 | if(node == this.textbox){ | |
84 | var k=dojo.keys; | |
85 | var key = evt.charOrCode; | |
86 | inc = (key == k.PAGE_UP || key == k.PAGE_DOWN) ? this.largeDelta : this.smallDelta; | |
87 | node = (key == k.UP_ARROW || key == k.PAGE_UP) ? this.upArrowNode : this.downArrowNode; | |
88 | } | |
89 | if(count == -1){ this._arrowReleased(node); } | |
90 | else{ this._arrowPressed(node, (node == this.upArrowNode) ? 1 : -1, inc); } | |
91 | }, | |
92 | ||
93 | _wheelTimer: null, | |
94 | _mouseWheeled: function(/*Event*/ evt){ | |
95 | // summary: | |
96 | // Mouse wheel listener where supported | |
97 | ||
98 | dojo.stopEvent(evt); | |
99 | // FIXME: Safari bubbles | |
100 | ||
101 | // be nice to DOH and scroll as much as the event says to | |
102 | var scrollAmount = evt.detail ? (evt.detail * -1) : (evt.wheelDelta / 120); | |
103 | if(scrollAmount !== 0){ | |
104 | var node = this[(scrollAmount > 0 ? "upArrowNode" : "downArrowNode" )]; | |
105 | ||
106 | this._arrowPressed(node, scrollAmount, this.smallDelta); | |
107 | ||
108 | if(!this._wheelTimer){ | |
109 | clearTimeout(this._wheelTimer); | |
110 | } | |
111 | this._wheelTimer = setTimeout(dojo.hitch(this,"_arrowReleased",node), 50); | |
112 | } | |
113 | ||
114 | }, | |
115 | ||
116 | postCreate: function(){ | |
117 | this.inherited(arguments); | |
118 | ||
119 | // extra listeners | |
120 | this.connect(this.domNode, !dojo.isMozilla ? "onmousewheel" : 'DOMMouseScroll', "_mouseWheeled"); | |
121 | this._connects.push(dijit.typematic.addListener(this.upArrowNode, this.textbox, {charOrCode:dojo.keys.UP_ARROW,ctrlKey:false,altKey:false,shiftKey:false,metaKey:false}, this, "_typematicCallback", this.timeoutChangeRate, this.defaultTimeout, this.minimumTimeout)); | |
122 | this._connects.push(dijit.typematic.addListener(this.downArrowNode, this.textbox, {charOrCode:dojo.keys.DOWN_ARROW,ctrlKey:false,altKey:false,shiftKey:false,metaKey:false}, this, "_typematicCallback", this.timeoutChangeRate, this.defaultTimeout, this.minimumTimeout)); | |
123 | this._connects.push(dijit.typematic.addListener(this.upArrowNode, this.textbox, {charOrCode:dojo.keys.PAGE_UP,ctrlKey:false,altKey:false,shiftKey:false,metaKey:false}, this, "_typematicCallback", this.timeoutChangeRate, this.defaultTimeout, this.minimumTimeout)); | |
124 | this._connects.push(dijit.typematic.addListener(this.downArrowNode, this.textbox, {charOrCode:dojo.keys.PAGE_DOWN,ctrlKey:false,altKey:false,shiftKey:false,metaKey:false}, this, "_typematicCallback", this.timeoutChangeRate, this.defaultTimeout, this.minimumTimeout)); | |
125 | } | |
126 | }); | |
127 | ||
2f01fe57 | 128 | } |