Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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