cirandas.net

ref: master

public/javascripts/vendor/jquery-timepicker-addon/src/docs/examples.html


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<!-- ############################################################################# -->
<!-- Examples
<!-- ############################################################################# -->
<div id="tp-examples">
	<h2>Examples</h2>

	<ul>
		<li><a href="#basic_examples" title="Basic Initializations">Basic Initializations</a></li>
		<li><a href="#timezone_examples" title="Using Timezones">Using Timezones</a></li>
		<li><a href="#slider_examples" title="Slider Modifications">Slider Modifications</a></li>
		<li><a href="#alt_examples" title="Alternate Field">Alternate Fields</a></li>
		<li><a href="#rest_examples" title="Time Restraints">Time Restraints</a></li>
		<li><a href="#utility_examples" title="Utilities">Utilities</a></li>
	</ul>

	<h3 id="basic_examples">Basic Initializations</h3>

	<!-- ============= example -->
	<div class="example-container">
		<p>Add a simple datetimepicker to jQuery UI's datepicker</p>
		<div>
	 		<input type="text" name="basic_example_1" id="basic_example_1" value="" />
		</div>					
<pre>
$('#basic_example_1').datetimepicker();
</pre>
	</div>


	<!-- ============= example -->
	<div class="example-container">
		<p>Add only a timepicker:</p>
		<div>
	 		<input type="text" name="basic_example_2" id="basic_example_2" value="" />
		</div>					
<pre>
$('#basic_example_2').timepicker();
</pre>
	</div>

	<!-- ============= example -->
	<div class="example-container">
		<p>Format the time:</p>
		<div>
	 		<input type="text" name="basic_example_3" id="basic_example_3" value="" />
		</div>					
<pre>
$('#basic_example_3').datetimepicker({
	timeFormat: "hh:mm tt"
});
</pre>
	</div>

	<h3 id="timezone_examples">Using Timezones</h3>

	<!-- ============= example -->
	<div class="example-container">
		<p>Simplest timezone usage:</p>
		<div>
	 		<input type="text" name="timezone_example_1" id="timezone_example_1" value="" />
		</div>					
<pre>
$('#timezone_example_1').datetimepicker({
	timeFormat: 'hh:mm tt z'
});
</pre>
	</div>

	<!-- ============= example -->
	<div class="example-container">
		<p>Define your own timezone options:</p>
		<div>
	 		<input type="text" name="timezone_example_2" id="timezone_example_2" value="" />
		</div>					
<pre>
$('#timezone_example_2').datetimepicker({
	timeFormat: 'HH:mm z',
	timezoneList: [ 
			{ value: -300, label: 'Eastern'}, 
			{ value: -360, label: 'Central' }, 
			{ value: -420, label: 'Mountain' }, 
			{ value: -480, label: 'Pacific' } 
		]
});
</pre>
	</div>

	<!-- ============= example -->
	<div class="example-container">
		<p>You may also use timezone string abbreviations for values.  This should be used with caution.  Computing accurate javascript Date objects may not be possible when trying to retrieve or set the date from timepicker (see setDate and getDate examples below).  For simple input values however this should work.</p>
		<div>
	 		<input type="text" name="timezone_example_3" id="timezone_example_3" value="" />
		</div>					
<pre>
$('#timezone_example_3').datetimepicker({
	timeFormat: 'HH:mm z',
	timezone: 'MT',
	timezoneList: [ 
			{ value: 'ET', label: 'Eastern'}, 
			{ value: 'CT', label: 'Central' }, 
			{ value: 'MT', label: 'Mountain' }, 
			{ value: 'PT', label: 'Pacific' } 
		]
});

</pre>
	</div>

	<h3 id="slider_examples">Slider Modifications</h3>

	<!-- ============= example -->
	<div class="example-container">
		<p>Add a grid to each slider:</p>
		<div>
	 		<input type="text" name="slider_example_1" id="slider_example_1" value="" />
		</div>					
<pre>
$('#slider_example_1').timepicker({
	hourGrid: 4,
	minuteGrid: 10,
	timeFormat: 'hh:mm tt'
});
</pre>
	</div>

	<!-- ============= example -->
	<div class="example-container">
		<p>Set the interval step of sliders:</p>
		<div>
	 		<input type="text" name="slider_example_2" id="slider_example_2" value="" />
		</div>					
<pre>
$('#slider_example_2').datetimepicker({
	timeFormat: 'HH:mm:ss',
	stepHour: 2,
	stepMinute: 10,
	stepSecond: 10
});
</pre>
	</div>

	<!-- ============= example -->
	<div class="example-container">
		<p>Add sliderAccess plugin for touch devices:</p>
		<div>
	 		<input type="text" name="slider_example_3" id="slider_example_3" value="" />
		</div>					
<pre>
$('#slider_example_3').datetimepicker({
	addSliderAccess: true,
	sliderAccessArgs: { touchonly: false }
});</pre>
	</div>

	<!-- ============= example -->
	<div class="example-container">
		<p>Use dropdowns instead of sliders.  By default if slider is not available dropdowns will be used.</p>
		<div>
	 		<input type="text" name="slider_example_4" id="slider_example_4" value="" />
		</div>					
<pre>
$('#slider_example_4').datetimepicker({
	controlType: 'select',
	timeFormat: 'hh:mm tt'
});</pre>
	</div>

	<!-- ============= example -->
	<div class="example-container">
		<p>Create your own control by implementing the create, options, and value methods. If you want to use your new control for all instances use the $.timepicker.setDefaults({controlType:myControl}). Here we implement jQueryUI's spinner control (jQueryUI 1.9+).</p>
		<div>
			<input type="text" name="slider_example_5" id="slider_example_5" value="" />
		</div>					
<pre>var myControl=  {
	create: function(tp_inst, obj, unit, val, min, max, step){
		$('&lt;input class="ui-timepicker-input" value="'+val+'" style="width:50%"&gt;')
			.appendTo(obj)
			.spinner({
				min: min,
				max: max,
				step: step,
				change: function(e,ui){ // key events
						// don't call if api was used and not key press
						if(e.originalEvent !== undefined)
							tp_inst._onTimeChange();
						tp_inst._onSelectHandler();
					},
				spin: function(e,ui){ // spin events
						tp_inst.control.value(tp_inst, obj, unit, ui.value);
						tp_inst._onTimeChange();
						tp_inst._onSelectHandler();
					}
			});
		return obj;
	},
	options: function(tp_inst, obj, unit, opts, val){
		if(typeof(opts) == 'string' && val !== undefined)
			return obj.find('.ui-timepicker-input').spinner(opts, val);
		return obj.find('.ui-timepicker-input').spinner(opts);
	},
	value: function(tp_inst, obj, unit, val){
		if(val !== undefined)
			return obj.find('.ui-timepicker-input').spinner('value', val);
		return obj.find('.ui-timepicker-input').spinner('value');
	}
};

$('#slider_example_5').datetimepicker({
	controlType: myControl
});</pre>
	</div>

	<h3 id="alt_examples">Alternate Fields</h3>

	<!-- ============= example -->
	<div class="example-container">
		<p>Alt field in the simplest form:</p>
		<div>
			<input type="text" name="alt_example_1" id="alt_example_1" value="09/15/2012" />
			<input type="text" name="alt_example_1_alt" id="alt_example_1_alt" value="10:15" />
		</div>					
<pre>
$('#alt_example_1').datetimepicker({
	altField: "#alt_example_1_alt"
});
</pre>
	</div>

	<!-- ============= example -->
	<div class="example-container">
		<p>With datetime in both:</p>
		<div>
			<input type="text" name="alt_example_2" id="alt_example_2" value="" />
			<input type="text" name="alt_example_2_alt" id="alt_example_2_alt" value="" />
		</div>					
<pre>
$('#alt_example_2').datetimepicker({
	altField: "#alt_example_2_alt",
	altFieldTimeOnly: false
});
</pre>
	</div>

	<!-- ============= example -->
	<div class="example-container">
		<p>Format the altField differently:</p>
		<div>
			<input type="text" name="alt_example_3" id="alt_example_3" value="" />
			<input type="text" name="alt_example_3_alt" id="alt_example_3_alt" value="" />
		</div>					
<pre>
$('#alt_example_3').datetimepicker({
	altField: "#alt_example_3_alt",
	altFieldTimeOnly: false,
	altFormat: "yy-mm-dd",
	altTimeFormat: "h:m t",
	altSeparator: " @ "
});
</pre>
	</div>

	<!-- ============= example -->
	<div class="example-container">
		<p>With inline mode using altField:</p>
		<div>
	 		<input type="text" name="alt_example_4_alt" id="alt_example_4_alt" value="" />
	 		<span id="alt_example_4" ></span>
		</div>					
<pre>
$('#alt_example_4').datetimepicker({
	altField: "#alt_example_4_alt",
	altFieldTimeOnly: false
});
</pre>
	</div>

	<h3 id="rest_examples">Time Restraints</h3>

	<!-- ============= example -->
	<div class="example-container">
		<p>Set the min/max hour of every date:</p>
		<div>
	 		<input type="text" name="rest_example_1" id="rest_example_1" value="" />
		</div>					
<pre>
$('#rest_example_1').timepicker({
	hourMin: 8,
	hourMax: 16
});
</pre>
	</div>

	<!-- ============= example -->
	<div class="example-container">
		<p>Set the min/max date numerically:</p>
		<div>
	 		<input type="text" name="rest_example_2" id="rest_example_2" value="" />
		</div>					
<pre>
$('#rest_example_2').datetimepicker({
	numberOfMonths: 2,
	minDate: 0,
	maxDate: 30
});
</pre>
	</div>					

	<!-- ============= example -->
	<div class="example-container">
		<p>Set the min/max date and time with a Date object:</p>
		<div>
	 		<input type="text" name="rest_example_3" id="rest_example_3" value="" />
		</div>					
<pre>
$('#rest_example_3').datetimepicker({
	minDate: new Date(2010, 11, 20, 8, 30),
	maxDate: new Date(2010, 11, 31, 17, 30)
});
</pre>
	</div>

	<!-- ============= example -->
	<div class="example-container">
		<p>Restrict a start and end date by using onSelect and onClose events for more control over functionality:</p>
		<p>For more examples and advanced usage grab the <a href="http://trentrichardson.com/ebooks/handling-time/" title="Handling Time eBook">Handling Time eBook</a>.</p>
		<div>
	 		<input type="text" name="rest_example_4_start" id="rest_example_4_start" value="" /> 
	 		<input type="text" name="rest_example_4_end" id="rest_example_4_end" value="" />
		</div>					
<pre>
var startDateTextBox = $('#rest_example_4_start');
var endDateTextBox = $('#rest_example_4_end');

startDateTextBox.datetimepicker({ 
	timeFormat: 'HH:mm z',
	onClose: function(dateText, inst) {
		if (endDateTextBox.val() != '') {
			var testStartDate = startDateTextBox.datetimepicker('getDate');
			var testEndDate = endDateTextBox.datetimepicker('getDate');
			if (testStartDate > testEndDate)
				endDateTextBox.datetimepicker('setDate', testStartDate);
		}
		else {
			endDateTextBox.val(dateText);
		}
	},
	onSelect: function (selectedDateTime){
		endDateTextBox.datetimepicker('option', 'minDate', startDateTextBox.datetimepicker('getDate') );
	}
});
endDateTextBox.datetimepicker({ 
	timeFormat: 'HH:mm z',
	onClose: function(dateText, inst) {
		if (startDateTextBox.val() != '') {
			var testStartDate = startDateTextBox.datetimepicker('getDate');
			var testEndDate = endDateTextBox.datetimepicker('getDate');
			if (testStartDate > testEndDate)
				startDateTextBox.datetimepicker('setDate', testEndDate);
		}
		else {
			startDateTextBox.val(dateText);
		}
	},
	onSelect: function (selectedDateTime){
		startDateTextBox.datetimepicker('option', 'maxDate', endDateTextBox.datetimepicker('getDate') );
	}
});
</pre>
	</div>

	<h3 id="utility_examples">Utilities</h3>

	<!-- ============= example -->
	<div class="example-container">
		<p>Get and Set Datetime with the getDate and setDate methods.  This example uses timezone to demonstrate the timepicker regonizes the timezones and computes the offsets when getting and setting.</p>
		<div>
			<input type="text" name="utility_example_1" id="utility_example_1" value="" /> 
			<button id="utility_example_1_setdt" value="1">Set Datetime</button> 
			<button id="utility_example_1_getdt" value="1">Get Datetime</button> 
		</div>
					
<pre>
var ex13 = $('#utility_example_1');

ex13.datetimepicker({
	timeFormat: 'hh:mm tt z',
	separator: ' @ ',
	showTimezone: true
});

$('#utility_example_1_setdt').click(function(){
	ex13.datetimepicker('setDate', (new Date()) );
});

$('#utility_example_1_getdt').click(function(){
	alert(ex13.datetimepicker('getDate'));
});
</pre>
	</div>

	<!-- ============= example -->
	<div class="example-container">
		<p>Use the utility function to format your own time. $.datepicker.formatTime(format, time, options)</p>
		<dl class="defs">
			<dt>format</dt><dd>required - string represenation of the time format to use</dd>
			<dt>time</dt><dd>required - hash: { hour, minute, second, millisecond, timezone }</dd>
			<dt>options</dt><dd>optional - hash of any options in regional translation (ampm, amNames, pmNames..)</dd>
		</dl>
		<p>Returns a time string in the specified format.</p>
		<div>
			<div id="utility_example_2"></div>
		</div>
					
<pre>
$('#utility_example_2').text(
	$.datepicker.formatTime('HH:mm z', { hour: 14, minute: 36, timezone: '+2000' }, {})
);
</pre>
	</div>

	<!-- ============= example -->
	<div class="example-container">
		<p>Use the utility function to parses a formatted time. $.datepicker.parseTime(format, timeString, options)</p>
		<dl class="defs">
			<dt>format</dt><dd>required - string represenation of the time format to use</dd>
			<dt>time</dt><dd>required - time string matching the format given in parameter 1</dd>
			<dt>options</dt><dd>optional - hash of any options in regional translation (ampm, amNames, pmNames..)</dd>
		</dl>
		<p>Returns an object with hours, minutes, seconds, milliseconds, timezone.</p>
		<div>
			<div id="utility_example_3"></div>
		</div>
					
<pre>
$('#utility_example_3').text(JSON.stringify( 
	$.datepicker.parseTime('HH:mm:ss:l z', "14:36:21:765 +2000", {}) 
));
</pre>
	</div>

</div>