2150 |
mathias |
1 |
if(!dojo._hasResource["dijit.form._Spinner"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dijit.form._Spinner"] = true;
|
|
|
3 |
dojo.provide("dijit.form._Spinner");
|
|
|
4 |
|
|
|
5 |
dojo.require("dijit.form.ValidationTextBox");
|
|
|
6 |
|
|
|
7 |
dojo.declare(
|
|
|
8 |
"dijit.form._Spinner",
|
|
|
9 |
dijit.form.RangeBoundTextBox,
|
|
|
10 |
{
|
|
|
11 |
|
|
|
12 |
// summary: Mixin for validation widgets with a spinner
|
|
|
13 |
// description: This class basically (conceptually) extends dijit.form.ValidationTextBox.
|
|
|
14 |
// It modifies the template to have up/down arrows, and provides related handling code.
|
|
|
15 |
|
|
|
16 |
// defaultTimeout: Number
|
|
|
17 |
// number of milliseconds before a held key or button becomes typematic
|
|
|
18 |
defaultTimeout: 500,
|
|
|
19 |
|
|
|
20 |
// timeoutChangeRate: Number
|
|
|
21 |
// fraction of time used to change the typematic timer between events
|
|
|
22 |
// 1.0 means that each typematic event fires at defaultTimeout intervals
|
|
|
23 |
// < 1.0 means that each typematic event fires at an increasing faster rate
|
|
|
24 |
timeoutChangeRate: 0.90,
|
|
|
25 |
|
|
|
26 |
// smallDelta: Number
|
|
|
27 |
// adjust the value by this much when spinning using the arrow keys/buttons
|
|
|
28 |
smallDelta: 1,
|
|
|
29 |
// largeDelta: Number
|
|
|
30 |
// adjust the value by this much when spinning using the PgUp/Dn keys
|
|
|
31 |
largeDelta: 10,
|
|
|
32 |
|
|
|
33 |
templateString:"<table class=\"dijit dijitReset dijitInlineTable dijitLeft\" cellspacing=\"0\" cellpadding=\"0\"\n\tid=\"widget_${id}\" name=\"${name}\"\n\tdojoAttachEvent=\"onmouseenter:_onMouse,onmouseleave:_onMouse,onkeypress:_onKeyPress\"\n\twaiRole=\"presentation\"\n\t><tr class=\"dijitReset\"\n\t\t><td rowspan=\"2\" class=\"dijitReset dijitStretch dijitInputField\" width=\"100%\"\n\t\t\t><input dojoAttachPoint=\"textbox,focusNode\" type=\"${type}\" dojoAttachEvent=\"onfocus,onkeyup\"\n\t\t\t\twaiRole=\"spinbutton\" autocomplete=\"off\" name=\"${name}\"\n\t\t></td\n\t\t><td rowspan=\"2\" class=\"dijitReset dijitValidationIconField\" width=\"0%\" \n\t\t\t><div dojoAttachPoint='iconNode' class='dijitValidationIcon'></div\n\t\t></td\n\t\t><td class=\"dijitReset dijitRight dijitButtonNode dijitUpArrowButton\" width=\"0%\"\n\t\t\t\tdojoAttachPoint=\"upArrowNode\"\n\t\t\t\tdojoAttachEvent=\"onmousedown:_handleUpArrowEvent,onmouseup:_handleUpArrowEvent,onmouseover:_handleUpArrowEvent,onmouseout:_handleUpArrowEvent\"\n\t\t\t\tstateModifier=\"UpArrow\"\n\t\t\t><div class=\"dijitA11yUpArrow\">▲</div\n\t\t></td\n\t></tr\n\t><tr class=\"dijitReset\"\n\t\t><td class=\"dijitReset dijitRight dijitButtonNode dijitDownArrowButton\" width=\"0%\"\n\t\t\t\tdojoAttachPoint=\"downArrowNode\"\n\t\t\t\tdojoAttachEvent=\"onmousedown:_handleDownArrowEvent,onmouseup:_handleDownArrowEvent,onmouseover:_handleDownArrowEvent,onmouseout:_handleDownArrowEvent\"\n\t\t\t\tstateModifier=\"DownArrow\"\n\t\t\t><div class=\"dijitA11yDownArrow\">▼</div\n\t\t></td\n\t></tr\n></table>\n\n",
|
|
|
34 |
baseClass: "dijitSpinner",
|
|
|
35 |
|
|
|
36 |
adjust: function(/* Object */ val, /*Number*/ delta){
|
|
|
37 |
// summary: user replaceable function used to adjust a primitive value(Number/Date/...) by the delta amount specified
|
|
|
38 |
// the val is adjusted in a way that makes sense to the object type
|
|
|
39 |
return val;
|
|
|
40 |
},
|
|
|
41 |
|
|
|
42 |
_handleUpArrowEvent : function(/*Event*/ e){
|
|
|
43 |
this._onMouse(e, this.upArrowNode);
|
|
|
44 |
},
|
|
|
45 |
|
|
|
46 |
_handleDownArrowEvent : function(/*Event*/ e){
|
|
|
47 |
this._onMouse(e, this.downArrowNode);
|
|
|
48 |
},
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
_arrowPressed: function(/*Node*/ nodePressed, /*Number*/ direction){
|
|
|
52 |
if(this.disabled){ return; }
|
|
|
53 |
dojo.addClass(nodePressed, "dijitSpinnerButtonActive");
|
|
|
54 |
this.setValue(this.adjust(this.getValue(), direction*this.smallDelta), false);
|
|
|
55 |
},
|
|
|
56 |
|
|
|
57 |
_arrowReleased: function(/*Node*/ node){
|
|
|
58 |
if(this.disabled){ return; }
|
|
|
59 |
this._wheelTimer = null;
|
|
|
60 |
dijit.focus(this.textbox);
|
|
|
61 |
dojo.removeClass(node, "dijitSpinnerButtonActive");
|
|
|
62 |
},
|
|
|
63 |
|
|
|
64 |
_typematicCallback: function(/*Number*/ count, /*DOMNode*/ node, /*Event*/ evt){
|
|
|
65 |
if(node == this.textbox){ node = (evt.keyCode == dojo.keys.UP_ARROW) ? this.upArrowNode : this.downArrowNode; }
|
|
|
66 |
if(count == -1){ this._arrowReleased(node); }
|
|
|
67 |
else{ this._arrowPressed(node, (node == this.upArrowNode) ? 1 : -1); }
|
|
|
68 |
},
|
|
|
69 |
|
|
|
70 |
_wheelTimer: null,
|
|
|
71 |
_mouseWheeled: function(/*Event*/ evt){
|
|
|
72 |
dojo.stopEvent(evt);
|
|
|
73 |
var scrollAmount = 0;
|
|
|
74 |
if(typeof evt.wheelDelta == 'number'){ // IE
|
|
|
75 |
scrollAmount = evt.wheelDelta;
|
|
|
76 |
}else if(typeof evt.detail == 'number'){ // Mozilla+Firefox
|
|
|
77 |
scrollAmount = -evt.detail;
|
|
|
78 |
}
|
|
|
79 |
if(scrollAmount > 0){
|
|
|
80 |
var node = this.upArrowNode;
|
|
|
81 |
var dir = +1;
|
|
|
82 |
}else if(scrollAmount < 0){
|
|
|
83 |
var node = this.downArrowNode;
|
|
|
84 |
var dir = -1;
|
|
|
85 |
}else{ return; }
|
|
|
86 |
this._arrowPressed(node, dir);
|
|
|
87 |
if(this._wheelTimer != null){
|
|
|
88 |
clearTimeout(this._wheelTimer);
|
|
|
89 |
}
|
|
|
90 |
var _this = this;
|
|
|
91 |
this._wheelTimer = setTimeout(function(){_this._arrowReleased(node);}, 50);
|
|
|
92 |
},
|
|
|
93 |
|
|
|
94 |
postCreate: function(){
|
|
|
95 |
this.inherited('postCreate', arguments);
|
|
|
96 |
|
|
|
97 |
// extra listeners
|
|
|
98 |
this.connect(this.textbox, dojo.isIE ? "onmousewheel" : 'DOMMouseScroll', "_mouseWheeled");
|
|
|
99 |
dijit.typematic.addListener(this.upArrowNode, this.textbox, {keyCode:dojo.keys.UP_ARROW,ctrlKey:false,altKey:false,shiftKey:false}, this, "_typematicCallback", this.timeoutChangeRate, this.defaultTimeout);
|
|
|
100 |
dijit.typematic.addListener(this.downArrowNode, this.textbox, {keyCode:dojo.keys.DOWN_ARROW,ctrlKey:false,altKey:false,shiftKey:false}, this, "_typematicCallback", this.timeoutChangeRate, this.defaultTimeout);
|
|
|
101 |
}
|
|
|
102 |
});
|
|
|
103 |
|
|
|
104 |
}
|