1318 |
alexandre_ |
1 |
/*
|
|
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
|
|
3 |
All Rights Reserved.
|
|
|
4 |
|
|
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
|
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
|
|
7 |
|
|
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
|
|
9 |
*/
|
|
|
10 |
|
1422 |
alexandre_ |
11 |
|
|
|
12 |
|
1318 |
alexandre_ |
13 |
dojo.provide("dojo.widget.Spinner");
|
|
|
14 |
dojo.require("dojo.io.*");
|
|
|
15 |
dojo.require("dojo.lfx.*");
|
|
|
16 |
dojo.require("dojo.html.*");
|
|
|
17 |
dojo.require("dojo.html.layout");
|
|
|
18 |
dojo.require("dojo.string");
|
|
|
19 |
dojo.require("dojo.widget.*");
|
|
|
20 |
dojo.require("dojo.widget.IntegerTextbox");
|
|
|
21 |
dojo.require("dojo.widget.RealNumberTextbox");
|
|
|
22 |
dojo.require("dojo.widget.DateTextbox");
|
|
|
23 |
dojo.require("dojo.experimental");
|
|
|
24 |
dojo.declare("dojo.widget.Spinner", null, {_typamaticTimer:null, _typamaticFunction:null, _currentTimeout:this.defaultTimeout, _eventCount:0, defaultTimeout:500, timeoutChangeRate:0.9, templateString:"<span _=\"weird end tag formatting is to prevent whitespace from becoming \"\n\tstyle='float:${this.htmlfloat};'\n\t><table cellpadding=0 cellspacing=0 class=\"dojoSpinner\">\n\t\t<tr>\n\t\t\t<td\n\t\t\t\t><input\n\t\t\t\t\tdojoAttachPoint='textbox' type='${this.type}'\n\t\t\t\t\tdojoAttachEvent='onblur;onfocus;onkey:_handleKeyEvents;onKeyUp:_onSpinnerKeyUp;onresize:_resize'\n\t\t\t\t\tid='${this.widgetId}' name='${this.name}' size='${this.size}' maxlength='${this.maxlength}'\n\t\t\t\t\tvalue='${this.value}' class='${this.className}' autocomplete=\"off\"\n\t\t\t></td>\n\t\t\t<td\n\t\t\t\t><img dojoAttachPoint=\"upArrowNode\"\n\t\t\t\t\tdojoAttachEvent=\"onDblClick: _upArrowDoubleClicked; onMouseDown: _upArrowPressed; onMouseUp: _arrowReleased; onMouseOut: _arrowReleased; onMouseMove: _discardEvent;\"\n\t\t\t\t\tsrc=\"${this.incrementSrc}\" style=\"width: ${this.buttonSize.width}px; height: ${this.buttonSize.height}px;\"\n\t\t\t\t><img dojoAttachPoint=\"downArrowNode\"\n\t\t\t\t\tdojoAttachEvent=\"onDblClick: _downArrowDoubleClicked; onMouseDown: _downArrowPressed; onMouseUp: _arrowReleased; onMouseOut: _arrowReleased; onMouseMove: _discardEvent;\"\n\t\t\t\t\tsrc=\"${this.decrementSrc}\" style=\"width: ${this.buttonSize.width}px; height: ${this.buttonSize.height}px;\"\n\t\t\t></td>\n\t\t</tr>\n\t</table\n\t><span dojoAttachPoint='invalidSpan' class='${this.invalidClass}'>${this.messages.invalidMessage}</span\n\t><span dojoAttachPoint='missingSpan' class='${this.missingClass}'>${this.messages.missingMessage}</span\n\t><span dojoAttachPoint='rangeSpan' class='${this.rangeClass}'>${this.messages.rangeMessage}</span\n></span>\n", templateCssString:"/* inline the table holding the <input> and buttons (method varies by browser) */\n.ie .dojoSpinner, .safari .dojoSpinner {\n\tdisplay: inline;\n}\n\n.moz .dojoSpinner {\n\tdisplay: -moz-inline-box;\n}\n\n.opera .dojoSpinner {\n\tdisplay: inline-table;\n}\n\n/* generic stuff for the table */\n.dojoSpinner td {\n\tpadding:0px;\n\tmargin:0px;\n\tvertical-align: middle;\n}\ntable.dojoSpinner {\n\tborder:0px;\n\tborder-spacing:0px;\n\tline-height:0px;\n\tpadding:0px;\n\tmargin: 0px;\n\tvertical-align: middle;\n}\n\n/* the buttons */\n.dojoSpinner img {\n\tdisplay: block;\n\tborder-width:0px 1px 1px 0px;\n\tborder-style:outset;\n}\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/Spinner.css"), incrementSrc:dojo.uri.moduleUri("dojo.widget", "templates/images/spinnerIncrement.gif"), decrementSrc:dojo.uri.moduleUri("dojo.widget", "templates/images/spinnerDecrement.gif"), _handleKeyEvents:function (evt) {
|
|
|
25 |
if (!evt.key) {
|
|
|
26 |
return;
|
|
|
27 |
}
|
|
|
28 |
if (!evt.ctrlKey && !evt.altKey) {
|
|
|
29 |
switch (evt.key) {
|
|
|
30 |
case evt.KEY_DOWN_ARROW:
|
|
|
31 |
dojo.event.browser.stopEvent(evt);
|
|
|
32 |
this._downArrowPressed(evt);
|
|
|
33 |
return;
|
|
|
34 |
case evt.KEY_UP_ARROW:
|
|
|
35 |
dojo.event.browser.stopEvent(evt);
|
|
|
36 |
this._upArrowPressed(evt);
|
|
|
37 |
return;
|
|
|
38 |
}
|
|
|
39 |
}
|
|
|
40 |
this._eventCount++;
|
|
|
41 |
}, _onSpinnerKeyUp:function (evt) {
|
|
|
42 |
this._arrowReleased(evt);
|
|
|
43 |
this.onkeyup(evt);
|
|
|
44 |
}, _resize:function () {
|
|
|
45 |
var inputSize = dojo.html.getBorderBox(this.textbox);
|
|
|
46 |
this.buttonSize = {width:inputSize.height / 2, height:inputSize.height / 2};
|
|
|
47 |
if (this.upArrowNode) {
|
|
|
48 |
dojo.html.setMarginBox(this.upArrowNode, this.buttonSize);
|
|
|
49 |
dojo.html.setMarginBox(this.downArrowNode, this.buttonSize);
|
|
|
50 |
}
|
|
|
51 |
}, _pressButton:function (node) {
|
|
|
52 |
node.style.borderWidth = "1px 0px 0px 1px";
|
|
|
53 |
node.style.borderStyle = "inset";
|
|
|
54 |
}, _releaseButton:function (node) {
|
|
|
55 |
node.style.borderWidth = "0px 1px 1px 0px";
|
|
|
56 |
node.style.borderStyle = "outset";
|
|
|
57 |
}, _arrowPressed:function (evt, direction) {
|
|
|
58 |
var nodePressed = (direction == -1) ? this.downArrowNode : this.upArrowNode;
|
|
|
59 |
var nodeReleased = (direction == +1) ? this.downArrowNode : this.upArrowNode;
|
|
|
60 |
if (typeof evt != "number") {
|
|
|
61 |
if (this._typamaticTimer != null) {
|
|
|
62 |
if (this._typamaticNode == nodePressed) {
|
|
|
63 |
return;
|
|
|
64 |
}
|
|
|
65 |
dojo.lang.clearTimeout(this._typamaticTimer);
|
|
|
66 |
}
|
|
|
67 |
this._releaseButton(nodeReleased);
|
|
|
68 |
this._eventCount++;
|
|
|
69 |
this._typamaticTimer = null;
|
|
|
70 |
this._currentTimeout = this.defaultTimeout;
|
|
|
71 |
} else {
|
|
|
72 |
if (evt != this._eventCount) {
|
|
|
73 |
this._releaseButton(nodePressed);
|
|
|
74 |
return;
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
this._pressButton(nodePressed);
|
|
|
78 |
this._setCursorX(this.adjustValue(direction, this._getCursorX()));
|
|
|
79 |
this._typamaticNode = nodePressed;
|
|
|
80 |
this._typamaticTimer = dojo.lang.setTimeout(this, "_arrowPressed", this._currentTimeout, this._eventCount, direction);
|
|
|
81 |
this._currentTimeout = Math.round(this._currentTimeout * this.timeoutChangeRate);
|
|
|
82 |
}, _downArrowPressed:function (evt) {
|
|
|
83 |
return this._arrowPressed(evt, -1);
|
|
|
84 |
}, _downArrowDoubleClicked:function (evt) {
|
|
|
85 |
var rc = this._downArrowPressed(evt);
|
|
|
86 |
dojo.lang.setTimeout(this, "_arrowReleased", 50, null);
|
|
|
87 |
return rc;
|
|
|
88 |
}, _upArrowPressed:function (evt) {
|
|
|
89 |
return this._arrowPressed(evt, +1);
|
|
|
90 |
}, _upArrowDoubleClicked:function (evt) {
|
|
|
91 |
var rc = this._upArrowPressed(evt);
|
|
|
92 |
dojo.lang.setTimeout(this, "_arrowReleased", 50, null);
|
|
|
93 |
return rc;
|
|
|
94 |
}, _arrowReleased:function (evt) {
|
|
|
95 |
this.textbox.focus();
|
|
|
96 |
if (evt != null && typeof evt == "object" && evt.keyCode && evt.keyCode != null) {
|
|
|
97 |
var keyCode = evt.keyCode;
|
|
|
98 |
var k = dojo.event.browser.keys;
|
|
|
99 |
switch (keyCode) {
|
|
|
100 |
case k.KEY_DOWN_ARROW:
|
|
|
101 |
case k.KEY_UP_ARROW:
|
|
|
102 |
dojo.event.browser.stopEvent(evt);
|
|
|
103 |
break;
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
this._releaseButton(this.upArrowNode);
|
|
|
107 |
this._releaseButton(this.downArrowNode);
|
|
|
108 |
this._eventCount++;
|
|
|
109 |
if (this._typamaticTimer != null) {
|
|
|
110 |
dojo.lang.clearTimeout(this._typamaticTimer);
|
|
|
111 |
}
|
|
|
112 |
this._typamaticTimer = null;
|
|
|
113 |
this._currentTimeout = this.defaultTimeout;
|
|
|
114 |
}, _mouseWheeled:function (evt) {
|
|
|
115 |
var scrollAmount = 0;
|
|
|
116 |
if (typeof evt.wheelDelta == "number") {
|
|
|
117 |
scrollAmount = evt.wheelDelta;
|
|
|
118 |
} else {
|
|
|
119 |
if (typeof evt.detail == "number") {
|
|
|
120 |
scrollAmount = -evt.detail;
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
if (scrollAmount > 0) {
|
|
|
124 |
this._upArrowPressed(evt);
|
|
|
125 |
this._arrowReleased(evt);
|
|
|
126 |
} else {
|
|
|
127 |
if (scrollAmount < 0) {
|
|
|
128 |
this._downArrowPressed(evt);
|
|
|
129 |
this._arrowReleased(evt);
|
|
|
130 |
}
|
|
|
131 |
}
|
|
|
132 |
}, _discardEvent:function (evt) {
|
|
|
133 |
dojo.event.browser.stopEvent(evt);
|
|
|
134 |
}, _getCursorX:function () {
|
|
|
135 |
var x = -1;
|
|
|
136 |
try {
|
|
|
137 |
this.textbox.focus();
|
|
|
138 |
if (typeof this.textbox.selectionEnd == "number") {
|
|
|
139 |
x = this.textbox.selectionEnd;
|
|
|
140 |
} else {
|
|
|
141 |
if (document.selection && document.selection.createRange) {
|
|
|
142 |
var range = document.selection.createRange().duplicate();
|
|
|
143 |
if (range.parentElement() == this.textbox) {
|
|
|
144 |
range.moveStart("textedit", -1);
|
|
|
145 |
x = range.text.length;
|
|
|
146 |
}
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
catch (e) {
|
|
|
151 |
}
|
|
|
152 |
return x;
|
|
|
153 |
}, _setCursorX:function (x) {
|
|
|
154 |
try {
|
|
|
155 |
this.textbox.focus();
|
|
|
156 |
if (!x) {
|
|
|
157 |
x = 0;
|
|
|
158 |
}
|
|
|
159 |
if (typeof this.textbox.selectionEnd == "number") {
|
|
|
160 |
this.textbox.selectionEnd = x;
|
|
|
161 |
} else {
|
|
|
162 |
if (this.textbox.createTextRange) {
|
|
|
163 |
var range = this.textbox.createTextRange();
|
|
|
164 |
range.collapse(true);
|
|
|
165 |
range.moveEnd("character", x);
|
|
|
166 |
range.moveStart("character", x);
|
|
|
167 |
range.select();
|
|
|
168 |
}
|
|
|
169 |
}
|
|
|
170 |
}
|
|
|
171 |
catch (e) {
|
|
|
172 |
}
|
|
|
173 |
}, _spinnerPostMixInProperties:function (args, frag) {
|
|
|
174 |
var inputNode = this.getFragNodeRef(frag);
|
|
|
175 |
var inputSize = dojo.html.getBorderBox(inputNode);
|
|
|
176 |
this.buttonSize = {width:inputSize.height / 2 - 1, height:inputSize.height / 2 - 1};
|
|
|
177 |
}, _spinnerPostCreate:function (args, frag) {
|
|
|
178 |
if (this.textbox.addEventListener) {
|
|
|
179 |
this.textbox.addEventListener("DOMMouseScroll", dojo.lang.hitch(this, "_mouseWheeled"), false);
|
|
|
180 |
} else {
|
|
|
181 |
dojo.event.connect(this.textbox, "onmousewheel", this, "_mouseWheeled");
|
|
|
182 |
}
|
|
|
183 |
}});
|
|
|
184 |
dojo.widget.defineWidget("dojo.widget.IntegerSpinner", [dojo.widget.IntegerTextbox, dojo.widget.Spinner], {delta:"1", postMixInProperties:function (args, frag) {
|
|
|
185 |
dojo.widget.IntegerSpinner.superclass.postMixInProperties.apply(this, arguments);
|
|
|
186 |
this._spinnerPostMixInProperties(args, frag);
|
|
|
187 |
}, postCreate:function (args, frag) {
|
|
|
188 |
dojo.widget.IntegerSpinner.superclass.postCreate.apply(this, arguments);
|
|
|
189 |
this._spinnerPostCreate(args, frag);
|
|
|
190 |
}, adjustValue:function (direction, x) {
|
|
|
191 |
var val = this.getValue().replace(/[^\-+\d]/g, "");
|
|
|
192 |
if (val.length == 0) {
|
|
|
193 |
return;
|
|
|
194 |
}
|
|
|
195 |
var num = Math.min(Math.max((parseInt(val) + (parseInt(this.delta) * direction)), (this.flags.min ? this.flags.min : -Infinity)), (this.flags.max ? this.flags.max : +Infinity));
|
|
|
196 |
val = num.toString();
|
|
|
197 |
if (num >= 0) {
|
|
|
198 |
val = ((this.flags.signed == true) ? "+" : " ") + val;
|
|
|
199 |
}
|
|
|
200 |
if (this.flags.separator.length > 0) {
|
|
|
201 |
for (var i = val.length - 3; i > 1; i -= 3) {
|
|
|
202 |
val = val.substr(0, i) + this.flags.separator + val.substr(i);
|
|
|
203 |
}
|
|
|
204 |
}
|
|
|
205 |
if (val.substr(0, 1) == " ") {
|
|
|
206 |
val = val.substr(1);
|
|
|
207 |
}
|
|
|
208 |
this.setValue(val);
|
|
|
209 |
return val.length;
|
|
|
210 |
}});
|
|
|
211 |
dojo.widget.defineWidget("dojo.widget.RealNumberSpinner", [dojo.widget.RealNumberTextbox, dojo.widget.Spinner], function () {
|
|
|
212 |
dojo.experimental("dojo.widget.RealNumberSpinner");
|
|
|
213 |
}, {delta:"1e1", postMixInProperties:function (args, frag) {
|
|
|
214 |
dojo.widget.RealNumberSpinner.superclass.postMixInProperties.apply(this, arguments);
|
|
|
215 |
this._spinnerPostMixInProperties(args, frag);
|
|
|
216 |
}, postCreate:function (args, frag) {
|
|
|
217 |
dojo.widget.RealNumberSpinner.superclass.postCreate.apply(this, arguments);
|
|
|
218 |
this._spinnerPostCreate(args, frag);
|
|
|
219 |
}, adjustValue:function (direction, x) {
|
|
|
220 |
var val = this.getValue().replace(/[^\-+\.eE\d]/g, "");
|
|
|
221 |
if (!val.length) {
|
|
|
222 |
return;
|
|
|
223 |
}
|
|
|
224 |
var num = parseFloat(val);
|
|
|
225 |
if (isNaN(num)) {
|
|
|
226 |
return;
|
|
|
227 |
}
|
|
|
228 |
var delta = this.delta.split(/[eE]/);
|
|
|
229 |
if (!delta.length) {
|
|
|
230 |
delta = [1, 1];
|
|
|
231 |
} else {
|
|
|
232 |
delta[0] = parseFloat(delta[0].replace(/[^\-+\.\d]/g, ""));
|
|
|
233 |
if (isNaN(delta[0])) {
|
|
|
234 |
delta[0] = 1;
|
|
|
235 |
}
|
|
|
236 |
if (delta.length > 1) {
|
|
|
237 |
delta[1] = parseInt(delta[1]);
|
|
|
238 |
}
|
|
|
239 |
if (isNaN(delta[1])) {
|
|
|
240 |
delta[1] = 1;
|
|
|
241 |
}
|
|
|
242 |
}
|
|
|
243 |
val = this.getValue().split(/[eE]/);
|
|
|
244 |
if (!val.length) {
|
|
|
245 |
return;
|
|
|
246 |
}
|
|
|
247 |
var numBase = parseFloat(val[0].replace(/[^\-+\.\d]/g, ""));
|
|
|
248 |
if (val.length == 1) {
|
|
|
249 |
var numExp = 0;
|
|
|
250 |
} else {
|
|
|
251 |
var numExp = parseInt(val[1].replace(/[^\-+\d]/g, ""));
|
|
|
252 |
}
|
|
|
253 |
if (x <= val[0].length) {
|
|
|
254 |
x = 0;
|
|
|
255 |
numBase += delta[0] * direction;
|
|
|
256 |
} else {
|
|
|
257 |
x = Number.MAX_VALUE;
|
|
|
258 |
numExp += delta[1] * direction;
|
|
|
259 |
if (this.flags.eSigned == false && numExp < 0) {
|
|
|
260 |
numExp = 0;
|
|
|
261 |
}
|
|
|
262 |
}
|
|
|
263 |
num = Math.min(Math.max((numBase * Math.pow(10, numExp)), (this.flags.min ? this.flags.min : -Infinity)), (this.flags.max ? this.flags.max : +Infinity));
|
|
|
264 |
if ((this.flags.exponent == true || (this.flags.exponent != false && x != 0)) && num.toExponential) {
|
|
|
265 |
if (isNaN(this.flags.places) || this.flags.places == Infinity) {
|
|
|
266 |
val = num.toExponential();
|
|
|
267 |
} else {
|
|
|
268 |
val = num.toExponential(this.flags.places);
|
|
|
269 |
}
|
|
|
270 |
} else {
|
|
|
271 |
if (num.toFixed && num.toPrecision) {
|
|
|
272 |
if (isNaN(this.flags.places) || this.flags.places == Infinity) {
|
|
|
273 |
val = num.toPrecision((1 / 3).toString().length - 1);
|
|
|
274 |
} else {
|
|
|
275 |
val = num.toFixed(this.flags.places);
|
|
|
276 |
}
|
|
|
277 |
} else {
|
|
|
278 |
val = num.toString();
|
|
|
279 |
}
|
|
|
280 |
}
|
|
|
281 |
if (num >= 0) {
|
|
|
282 |
if (this.flags.signed == true) {
|
|
|
283 |
val = "+" + val;
|
|
|
284 |
}
|
|
|
285 |
}
|
|
|
286 |
val = val.split(/[eE]/);
|
|
|
287 |
if (this.flags.separator.length > 0) {
|
|
|
288 |
if (num >= 0 && val[0].substr(0, 1) != "+") {
|
|
|
289 |
val[0] = " " + val[0];
|
|
|
290 |
}
|
|
|
291 |
var i = val[0].lastIndexOf(".");
|
|
|
292 |
if (i >= 0) {
|
|
|
293 |
i -= 3;
|
|
|
294 |
} else {
|
|
|
295 |
i = val[0].length - 3;
|
|
|
296 |
}
|
|
|
297 |
for (; i > 1; i -= 3) {
|
|
|
298 |
val[0] = val[0].substr(0, i) + this.flags.separator + val[0].substr(i);
|
|
|
299 |
}
|
|
|
300 |
if (val[0].substr(0, 1) == " ") {
|
|
|
301 |
val[0] = val[0].substr(1);
|
|
|
302 |
}
|
|
|
303 |
}
|
|
|
304 |
if (val.length > 1) {
|
|
|
305 |
if ((this.flags.eSigned == true) && (val[1].substr(0, 1) != "+")) {
|
|
|
306 |
val[1] = "+" + val[1];
|
|
|
307 |
} else {
|
|
|
308 |
if ((!this.flags.eSigned) && (val[1].substr(0, 1) == "+")) {
|
|
|
309 |
val[1] = val[1].substr(1);
|
|
|
310 |
} else {
|
|
|
311 |
if ((!this.flags.eSigned) && (val[1].substr(0, 1) == "-") && (num.toFixed && num.toPrecision)) {
|
|
|
312 |
if (isNaN(this.flags.places)) {
|
|
|
313 |
val[0] = num.toPrecision((1 / 3).toString().length - 1);
|
|
|
314 |
} else {
|
|
|
315 |
val[0] = num.toFixed(this.flags.places).toString();
|
|
|
316 |
}
|
|
|
317 |
val[1] = "0";
|
|
|
318 |
}
|
|
|
319 |
}
|
|
|
320 |
}
|
|
|
321 |
val[0] += "e" + val[1];
|
|
|
322 |
}
|
|
|
323 |
this.setValue(val[0]);
|
|
|
324 |
if (x > val[0].length) {
|
|
|
325 |
x = val[0].length;
|
|
|
326 |
}
|
|
|
327 |
return x;
|
|
|
328 |
}});
|
|
|
329 |
dojo.widget.defineWidget("dojo.widget.TimeSpinner", [dojo.widget.TimeTextbox, dojo.widget.Spinner], function () {
|
|
|
330 |
dojo.experimental("dojo.widget.TimeSpinner");
|
|
|
331 |
}, {postMixInProperties:function (args, frag) {
|
|
|
332 |
dojo.widget.TimeSpinner.superclass.postMixInProperties.apply(this, arguments);
|
|
|
333 |
this._spinnerPostMixInProperties(args, frag);
|
|
|
334 |
}, postCreate:function (args, frag) {
|
|
|
335 |
dojo.widget.TimeSpinner.superclass.postCreate.apply(this, arguments);
|
|
|
336 |
this._spinnerPostCreate(args, frag);
|
|
|
337 |
}, adjustValue:function (direction, x) {
|
|
|
338 |
var val = this.getValue();
|
|
|
339 |
var format = (this.flags.format && this.flags.format.search(/[Hhmst]/) >= 0) ? this.flags.format : "hh:mm:ss t";
|
|
|
340 |
if (direction == 0 || !val.length || !this.isValid()) {
|
|
|
341 |
return;
|
|
|
342 |
}
|
|
|
343 |
if (!this.flags.amSymbol) {
|
|
|
344 |
this.flags.amSymbol = "AM";
|
|
|
345 |
}
|
|
|
346 |
if (!this.flags.pmSymbol) {
|
|
|
347 |
this.flags.pmSymbol = "PM";
|
|
|
348 |
}
|
|
|
349 |
var re = dojo.regexp.time(this.flags);
|
|
|
350 |
var qualifiers = format.replace(/H/g, "h").replace(/[^hmst]/g, "").replace(/([hmst])\1/g, "$1");
|
|
|
351 |
var hourPos = qualifiers.indexOf("h") + 1;
|
|
|
352 |
var minPos = qualifiers.indexOf("m") + 1;
|
|
|
353 |
var secPos = qualifiers.indexOf("s") + 1;
|
|
|
354 |
var ampmPos = qualifiers.indexOf("t") + 1;
|
|
|
355 |
var cursorFormat = format;
|
|
|
356 |
var ampm = "";
|
|
|
357 |
if (ampmPos > 0) {
|
|
|
358 |
ampm = val.replace(new RegExp(re), "$" + ampmPos);
|
|
|
359 |
cursorFormat = cursorFormat.replace(/t+/, ampm.replace(/./g, "t"));
|
|
|
360 |
}
|
|
|
361 |
var hour = 0;
|
|
|
362 |
var deltaHour = 1;
|
|
|
363 |
if (hourPos > 0) {
|
|
|
364 |
hour = val.replace(new RegExp(re), "$" + hourPos);
|
|
|
365 |
if (dojo.lang.isString(this.delta)) {
|
|
|
366 |
deltaHour = this.delta.replace(new RegExp(re), "$" + hourPos);
|
|
|
367 |
}
|
|
|
368 |
if (isNaN(deltaHour)) {
|
|
|
369 |
deltaHour = 1;
|
|
|
370 |
} else {
|
|
|
371 |
deltaHour = parseInt(deltaHour);
|
|
|
372 |
}
|
|
|
373 |
if (hour.length == 2) {
|
|
|
374 |
cursorFormat = cursorFormat.replace(/([Hh])+/, "$1$1");
|
|
|
375 |
} else {
|
|
|
376 |
cursorFormat = cursorFormat.replace(/([Hh])+/, "$1");
|
|
|
377 |
}
|
|
|
378 |
if (isNaN(hour)) {
|
|
|
379 |
hour = 0;
|
|
|
380 |
} else {
|
|
|
381 |
hour = parseInt(hour.replace(/^0(\d)/, "$1"));
|
|
|
382 |
}
|
|
|
383 |
}
|
|
|
384 |
var min = 0;
|
|
|
385 |
var deltaMin = 1;
|
|
|
386 |
if (minPos > 0) {
|
|
|
387 |
min = val.replace(new RegExp(re), "$" + minPos);
|
|
|
388 |
if (dojo.lang.isString(this.delta)) {
|
|
|
389 |
deltaMin = this.delta.replace(new RegExp(re), "$" + minPos);
|
|
|
390 |
}
|
|
|
391 |
if (isNaN(deltaMin)) {
|
|
|
392 |
deltaMin = 1;
|
|
|
393 |
} else {
|
|
|
394 |
deltaMin = parseInt(deltaMin);
|
|
|
395 |
}
|
|
|
396 |
cursorFormat = cursorFormat.replace(/m+/, min.replace(/./g, "m"));
|
|
|
397 |
if (isNaN(min)) {
|
|
|
398 |
min = 0;
|
|
|
399 |
} else {
|
|
|
400 |
min = parseInt(min.replace(/^0(\d)/, "$1"));
|
|
|
401 |
}
|
|
|
402 |
}
|
|
|
403 |
var sec = 0;
|
|
|
404 |
var deltaSec = 1;
|
|
|
405 |
if (secPos > 0) {
|
|
|
406 |
sec = val.replace(new RegExp(re), "$" + secPos);
|
|
|
407 |
if (dojo.lang.isString(this.delta)) {
|
|
|
408 |
deltaSec = this.delta.replace(new RegExp(re), "$" + secPos);
|
|
|
409 |
}
|
|
|
410 |
if (isNaN(deltaSec)) {
|
|
|
411 |
deltaSec = 1;
|
|
|
412 |
} else {
|
|
|
413 |
deltaSec = parseInt(deltaSec);
|
|
|
414 |
}
|
|
|
415 |
cursorFormat = cursorFormat.replace(/s+/, sec.replace(/./g, "s"));
|
|
|
416 |
if (isNaN(sec)) {
|
|
|
417 |
sec = 0;
|
|
|
418 |
} else {
|
|
|
419 |
sec = parseInt(sec.replace(/^0(\d)/, "$1"));
|
|
|
420 |
}
|
|
|
421 |
}
|
|
|
422 |
if (isNaN(x) || x >= cursorFormat.length) {
|
|
|
423 |
x = cursorFormat.length - 1;
|
|
|
424 |
}
|
|
|
425 |
var cursorToken = cursorFormat.charAt(x);
|
|
|
426 |
switch (cursorToken) {
|
|
|
427 |
case "t":
|
|
|
428 |
if (ampm == this.flags.amSymbol) {
|
|
|
429 |
ampm = this.flags.pmSymbol;
|
|
|
430 |
} else {
|
|
|
431 |
if (ampm == this.flags.pmSymbol) {
|
|
|
432 |
ampm = this.flags.amSymbol;
|
|
|
433 |
}
|
|
|
434 |
}
|
|
|
435 |
break;
|
|
|
436 |
default:
|
|
|
437 |
if (hour >= 1 && hour < 12 && ampm == this.flags.pmSymbol) {
|
|
|
438 |
hour += 12;
|
|
|
439 |
}
|
|
|
440 |
if (hour == 12 && ampm == this.flags.amSymbol) {
|
|
|
441 |
hour = 0;
|
|
|
442 |
}
|
|
|
443 |
switch (cursorToken) {
|
|
|
444 |
case "s":
|
|
|
445 |
sec += deltaSec * direction;
|
|
|
446 |
while (sec < 0) {
|
|
|
447 |
min--;
|
|
|
448 |
sec += 60;
|
|
|
449 |
}
|
|
|
450 |
while (sec >= 60) {
|
|
|
451 |
min++;
|
|
|
452 |
sec -= 60;
|
|
|
453 |
}
|
|
|
454 |
case "m":
|
|
|
455 |
if (cursorToken == "m") {
|
|
|
456 |
min += deltaMin * direction;
|
|
|
457 |
}
|
|
|
458 |
while (min < 0) {
|
|
|
459 |
hour--;
|
|
|
460 |
min += 60;
|
|
|
461 |
}
|
|
|
462 |
while (min >= 60) {
|
|
|
463 |
hour++;
|
|
|
464 |
min -= 60;
|
|
|
465 |
}
|
|
|
466 |
case "h":
|
|
|
467 |
case "H":
|
|
|
468 |
if (cursorToken == "h" || cursorToken == "H") {
|
|
|
469 |
hour += deltaHour * direction;
|
|
|
470 |
}
|
|
|
471 |
while (hour < 0) {
|
|
|
472 |
hour += 24;
|
|
|
473 |
}
|
|
|
474 |
while (hour >= 24) {
|
|
|
475 |
hour -= 24;
|
|
|
476 |
}
|
|
|
477 |
break;
|
|
|
478 |
default:
|
|
|
479 |
return;
|
|
|
480 |
}
|
|
|
481 |
if (hour >= 12) {
|
|
|
482 |
ampm = this.flags.pmSymbol;
|
|
|
483 |
if (format.indexOf("h") >= 0 && hour >= 13) {
|
|
|
484 |
hour -= 12;
|
|
|
485 |
}
|
|
|
486 |
} else {
|
|
|
487 |
ampm = this.flags.amSymbol;
|
|
|
488 |
if (format.indexOf("h") >= 0 && hour == 0) {
|
|
|
489 |
hour = 12;
|
|
|
490 |
}
|
|
|
491 |
}
|
|
|
492 |
}
|
|
|
493 |
cursorFormat = format;
|
|
|
494 |
if (hour >= 0 && hour < 10 && format.search(/[hH]{2}/) >= 0) {
|
|
|
495 |
hour = "0" + hour.toString();
|
|
|
496 |
}
|
|
|
497 |
if (hour >= 10 && cursorFormat.search(/[hH]{2}/) < 0) {
|
|
|
498 |
cursorFormat = cursorFormat.replace(/(h|H)/, "$1$1");
|
|
|
499 |
}
|
|
|
500 |
if (min >= 0 && min < 10 && cursorFormat.search(/mm/) >= 0) {
|
|
|
501 |
min = "0" + min.toString();
|
|
|
502 |
}
|
|
|
503 |
if (min >= 10 && cursorFormat.search(/mm/) < 0) {
|
|
|
504 |
cursorFormat = cursorFormat.replace(/m/, "$1$1");
|
|
|
505 |
}
|
|
|
506 |
if (sec >= 0 && sec < 10 && cursorFormat.search(/ss/) >= 0) {
|
|
|
507 |
sec = "0" + sec.toString();
|
|
|
508 |
}
|
|
|
509 |
if (sec >= 10 && cursorFormat.search(/ss/) < 0) {
|
|
|
510 |
cursorFormat = cursorFormat.replace(/s/, "$1$1");
|
|
|
511 |
}
|
|
|
512 |
x = cursorFormat.indexOf(cursorToken);
|
|
|
513 |
if (x == -1) {
|
|
|
514 |
x = format.length;
|
|
|
515 |
}
|
|
|
516 |
format = format.replace(/[hH]+/, hour);
|
|
|
517 |
format = format.replace(/m+/, min);
|
|
|
518 |
format = format.replace(/s+/, sec);
|
|
|
519 |
format = format.replace(/t/, ampm);
|
|
|
520 |
this.setValue(format);
|
|
|
521 |
if (x > format.length) {
|
|
|
522 |
x = format.length;
|
|
|
523 |
}
|
|
|
524 |
return x;
|
|
|
525 |
}});
|
|
|
526 |
|