| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/keys", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/sniff", |
| 6 |
"dojo/mouse", |
| 7 |
"dojo/on", |
| 8 |
"../typematic", |
| 9 |
"./RangeBoundTextBox", |
| 10 |
"dojo/text!./templates/Spinner.html", |
| 11 |
"./_TextBoxMixin" |
| 12 |
], function(declare, keys, lang, has, mouse, on, typematic, RangeBoundTextBox, template, _TextBoxMixin){ |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
return declare("dijit.form._Spinner", RangeBoundTextBox, { |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
defaultTimeout: 500, |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
minimumTimeout: 10, |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
timeoutChangeRate: 0.90, |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
smallDelta: 1, |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
largeDelta: 10, |
| 45 |
|
| 46 |
templateString: template, |
| 47 |
|
| 48 |
baseClass: "dijitTextBox dijitSpinner", |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
cssStateNodes: { |
| 53 |
"upArrowNode": "dijitUpArrowButton", |
| 54 |
"downArrowNode": "dijitDownArrowButton" |
| 55 |
}, |
| 56 |
|
| 57 |
adjust: function(val ){ |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
return val; |
| 66 |
}, |
| 67 |
|
| 68 |
_arrowPressed: function( nodePressed, direction, increment){ |
| 69 |
|
| 70 |
|
| 71 |
if(this.disabled || this.readOnly){ |
| 72 |
return; |
| 73 |
} |
| 74 |
this._setValueAttr(this.adjust(this.get('value'), direction * increment), false); |
| 75 |
_TextBoxMixin.selectInputText(this.textbox, this.textbox.value.length); |
| 76 |
}, |
| 77 |
|
| 78 |
_arrowReleased: function( ){ |
| 79 |
|
| 80 |
|
| 81 |
this._wheelTimer = null; |
| 82 |
}, |
| 83 |
|
| 84 |
_typematicCallback: function( count, node, evt){ |
| 85 |
var inc = this.smallDelta; |
| 86 |
if(node == this.textbox){ |
| 87 |
var key = evt.keyCode; |
| 88 |
inc = (key == keys.PAGE_UP || key == keys.PAGE_DOWN) ? this.largeDelta : this.smallDelta; |
| 89 |
node = (key == keys.UP_ARROW || key == keys.PAGE_UP) ? this.upArrowNode : this.downArrowNode; |
| 90 |
} |
| 91 |
if(count == -1){ |
| 92 |
this._arrowReleased(node); |
| 93 |
} |
| 94 |
else{ |
| 95 |
this._arrowPressed(node, (node == this.upArrowNode) ? 1 : -1, inc); |
| 96 |
} |
| 97 |
}, |
| 98 |
|
| 99 |
_wheelTimer: null, |
| 100 |
_mouseWheeled: function( evt){ |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
if(!this.focused){ |
| 105 |
|
| 106 |
return; |
| 107 |
} |
| 108 |
|
| 109 |
evt.stopPropagation(); |
| 110 |
evt.preventDefault(); |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
var wheelDelta = evt.wheelDelta / 120; |
| 115 |
if(Math.floor(wheelDelta) != wheelDelta){ |
| 116 |
|
| 117 |
|
| 118 |
wheelDelta = evt.wheelDelta > 0 ? 1 : -1; |
| 119 |
} |
| 120 |
var scrollAmount = evt.detail ? (evt.detail * -1) : wheelDelta; |
| 121 |
if(scrollAmount !== 0){ |
| 122 |
var node = this[(scrollAmount > 0 ? "upArrowNode" : "downArrowNode" )]; |
| 123 |
|
| 124 |
this._arrowPressed(node, scrollAmount, this.smallDelta); |
| 125 |
|
| 126 |
if(this._wheelTimer){ |
| 127 |
this._wheelTimer.remove(); |
| 128 |
} |
| 129 |
this._wheelTimer = this.defer(function(){ |
| 130 |
this._arrowReleased(node); |
| 131 |
}, 50); |
| 132 |
} |
| 133 |
}, |
| 134 |
|
| 135 |
_setConstraintsAttr: function( constraints){ |
| 136 |
this.inherited(arguments); |
| 137 |
if(this.focusNode){ |
| 138 |
if(this.constraints.min !== undefined){ |
| 139 |
this.focusNode.setAttribute("aria-valuemin", this.constraints.min); |
| 140 |
}else{ |
| 141 |
this.focusNode.removeAttribute("aria-valuemin"); |
| 142 |
} |
| 143 |
if(this.constraints.max !== undefined){ |
| 144 |
this.focusNode.setAttribute("aria-valuemax", this.constraints.max); |
| 145 |
}else{ |
| 146 |
this.focusNode.removeAttribute("aria-valuemax"); |
| 147 |
} |
| 148 |
} |
| 149 |
}, |
| 150 |
|
| 151 |
_setValueAttr: function( value, priorityChange){ |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
this.focusNode.setAttribute("aria-valuenow", value); |
| 156 |
this.inherited(arguments); |
| 157 |
}, |
| 158 |
|
| 159 |
postCreate: function(){ |
| 160 |
this.inherited(arguments); |
| 161 |
|
| 162 |
|
| 163 |
this.own( |
| 164 |
on(this.domNode, mouse.wheel, lang.hitch(this, "_mouseWheeled")), |
| 165 |
typematic.addListener(this.upArrowNode, this.textbox, {keyCode: keys.UP_ARROW, ctrlKey: false, altKey: false, shiftKey: false, metaKey: false}, this, "_typematicCallback", this.timeoutChangeRate, this.defaultTimeout, this.minimumTimeout), |
| 166 |
typematic.addListener(this.downArrowNode, this.textbox, {keyCode: keys.DOWN_ARROW, ctrlKey: false, altKey: false, shiftKey: false, metaKey: false}, this, "_typematicCallback", this.timeoutChangeRate, this.defaultTimeout, this.minimumTimeout), |
| 167 |
typematic.addListener(this.upArrowNode, this.textbox, {keyCode: keys.PAGE_UP, ctrlKey: false, altKey: false, shiftKey: false, metaKey: false}, this, "_typematicCallback", this.timeoutChangeRate, this.defaultTimeout, this.minimumTimeout), |
| 168 |
typematic.addListener(this.downArrowNode, this.textbox, {keyCode: keys.PAGE_DOWN, ctrlKey: false, altKey: false, shiftKey: false, metaKey: false}, this, "_typematicCallback", this.timeoutChangeRate, this.defaultTimeout, this.minimumTimeout) |
| 169 |
); |
| 170 |
} |
| 171 |
}); |
| 172 |
}); |