active_scaffold 3.1.7 → 3.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1276 @@
1
+ /*
2
+ * jQuery timepicker addon
3
+ * By: Trent Richardson [http://trentrichardson.com]
4
+ * Version 0.9.7
5
+ * Last Modified: 10/02/2011
6
+ *
7
+ * Copyright 2011 Trent Richardson
8
+ * Dual licensed under the MIT and GPL licenses.
9
+ * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt
10
+ * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt
11
+ *
12
+ * HERES THE CSS:
13
+ * .ui-timepicker-div .ui-widget-header { margin-bottom: 8px; }
14
+ * .ui-timepicker-div dl { text-align: left; }
15
+ * .ui-timepicker-div dl dt { height: 25px; }
16
+ * .ui-timepicker-div dl dd { margin: -25px 10px 10px 65px; }
17
+ * .ui-timepicker-div td { font-size: 90%; }
18
+ * .ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; }
19
+ */
20
+
21
+ (function($) {
22
+
23
+ $.extend($.ui, { timepicker: { version: "0.9.7" } });
24
+
25
+ /* Time picker manager.
26
+ Use the singleton instance of this class, $.timepicker, to interact with the time picker.
27
+ Settings for (groups of) time pickers are maintained in an instance object,
28
+ allowing multiple different settings on the same page. */
29
+
30
+ function Timepicker() {
31
+ this.regional = []; // Available regional settings, indexed by language code
32
+ this.regional[''] = { // Default regional settings
33
+ currentText: 'Now',
34
+ closeText: 'Done',
35
+ ampm: false,
36
+ amNames: ['AM', 'A'],
37
+ pmNames: ['PM', 'P'],
38
+ timeFormat: 'hh:mm tt',
39
+ timeSuffix: '',
40
+ timeOnlyTitle: 'Choose Time',
41
+ timeText: 'Time',
42
+ hourText: 'Hour',
43
+ minuteText: 'Minute',
44
+ secondText: 'Second',
45
+ millisecText: 'Millisecond',
46
+ timezoneText: 'Time Zone'
47
+ };
48
+ this._defaults = { // Global defaults for all the datetime picker instances
49
+ showButtonPanel: true,
50
+ timeOnly: false,
51
+ showHour: true,
52
+ showMinute: true,
53
+ showSecond: false,
54
+ showMillisec: false,
55
+ showTimezone: false,
56
+ showTime: true,
57
+ stepHour: 0.05,
58
+ stepMinute: 0.05,
59
+ stepSecond: 0.05,
60
+ stepMillisec: 0.5,
61
+ hour: 0,
62
+ minute: 0,
63
+ second: 0,
64
+ millisec: 0,
65
+ timezone: '+0000',
66
+ hourMin: 0,
67
+ minuteMin: 0,
68
+ secondMin: 0,
69
+ millisecMin: 0,
70
+ hourMax: 23,
71
+ minuteMax: 59,
72
+ secondMax: 59,
73
+ millisecMax: 999,
74
+ minDateTime: null,
75
+ maxDateTime: null,
76
+ onSelect: null,
77
+ hourGrid: 0,
78
+ minuteGrid: 0,
79
+ secondGrid: 0,
80
+ millisecGrid: 0,
81
+ alwaysSetTime: true,
82
+ separator: ' ',
83
+ altFieldTimeOnly: true,
84
+ showTimepicker: true,
85
+ timezoneIso8609: false,
86
+ timezoneList: null
87
+ };
88
+ $.extend(this._defaults, this.regional['']);
89
+ }
90
+
91
+ $.extend(Timepicker.prototype, {
92
+ $input: null,
93
+ $altInput: null,
94
+ $timeObj: null,
95
+ inst: null,
96
+ hour_slider: null,
97
+ minute_slider: null,
98
+ second_slider: null,
99
+ millisec_slider: null,
100
+ timezone_select: null,
101
+ hour: 0,
102
+ minute: 0,
103
+ second: 0,
104
+ millisec: 0,
105
+ timezone: '+0000',
106
+ hourMinOriginal: null,
107
+ minuteMinOriginal: null,
108
+ secondMinOriginal: null,
109
+ millisecMinOriginal: null,
110
+ hourMaxOriginal: null,
111
+ minuteMaxOriginal: null,
112
+ secondMaxOriginal: null,
113
+ millisecMaxOriginal: null,
114
+ ampm: '',
115
+ formattedDate: '',
116
+ formattedTime: '',
117
+ formattedDateTime: '',
118
+ timezoneList: null,
119
+
120
+ /* Override the default settings for all instances of the time picker.
121
+ @param settings object - the new settings to use as defaults (anonymous object)
122
+ @return the manager object */
123
+ setDefaults: function(settings) {
124
+ extendRemove(this._defaults, settings || {});
125
+ return this;
126
+ },
127
+
128
+ //########################################################################
129
+ // Create a new Timepicker instance
130
+ //########################################################################
131
+ _newInst: function($input, o) {
132
+ var tp_inst = new Timepicker(),
133
+ inlineSettings = {};
134
+
135
+ for (var attrName in this._defaults) {
136
+ var attrValue = $input.attr('time:' + attrName);
137
+ if (attrValue) {
138
+ try {
139
+ inlineSettings[attrName] = eval(attrValue);
140
+ } catch (err) {
141
+ inlineSettings[attrName] = attrValue;
142
+ }
143
+ }
144
+ }
145
+ tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, {
146
+ beforeShow: function(input, dp_inst) {
147
+ if ($.isFunction(o.beforeShow))
148
+ o.beforeShow(input, dp_inst, tp_inst);
149
+ },
150
+ onChangeMonthYear: function(year, month, dp_inst) {
151
+ // Update the time as well : this prevents the time from disappearing from the $input field.
152
+ tp_inst._updateDateTime(dp_inst);
153
+ if ($.isFunction(o.onChangeMonthYear))
154
+ o.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst);
155
+ },
156
+ onClose: function(dateText, dp_inst) {
157
+ if (tp_inst.timeDefined === true && $input.val() != '')
158
+ tp_inst._updateDateTime(dp_inst);
159
+ if ($.isFunction(o.onClose))
160
+ o.onClose.call($input[0], dateText, dp_inst, tp_inst);
161
+ },
162
+ timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
163
+ });
164
+ tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) { return val.toUpperCase() });
165
+ tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) { return val.toUpperCase() });
166
+
167
+ if (tp_inst._defaults.timezoneList === null) {
168
+ var timezoneList = [];
169
+ for (var i = -11; i <= 12; i++)
170
+ timezoneList.push((i >= 0 ? '+' : '-') + ('0' + Math.abs(i).toString()).slice(-2) + '00');
171
+ if (tp_inst._defaults.timezoneIso8609)
172
+ timezoneList = $.map(timezoneList, function(val) {
173
+ return val == '+0000' ? 'Z' : (val.substring(0, 3) + ':' + val.substring(3));
174
+ });
175
+ tp_inst._defaults.timezoneList = timezoneList;
176
+ }
177
+
178
+ tp_inst.hour = tp_inst._defaults.hour;
179
+ tp_inst.minute = tp_inst._defaults.minute;
180
+ tp_inst.second = tp_inst._defaults.second;
181
+ tp_inst.millisec = tp_inst._defaults.millisec;
182
+ tp_inst.ampm = '';
183
+ tp_inst.$input = $input;
184
+
185
+ if (o.altField)
186
+ tp_inst.$altInput = $(o.altField)
187
+ .css({ cursor: 'pointer' })
188
+ .focus(function(){ $input.trigger("focus"); });
189
+
190
+ if(tp_inst._defaults.minDate==0 || tp_inst._defaults.minDateTime==0)
191
+ {
192
+ tp_inst._defaults.minDate=new Date();
193
+ }
194
+ if(tp_inst._defaults.maxDate==0 || tp_inst._defaults.maxDateTime==0)
195
+ {
196
+ tp_inst._defaults.maxDate=new Date();
197
+ }
198
+
199
+ // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime..
200
+ if(tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date)
201
+ tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime());
202
+ if(tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date)
203
+ tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime());
204
+ if(tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date)
205
+ tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime());
206
+ if(tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date)
207
+ tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime());
208
+ return tp_inst;
209
+ },
210
+
211
+ //########################################################################
212
+ // add our sliders to the calendar
213
+ //########################################################################
214
+ _addTimePicker: function(dp_inst) {
215
+ var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ?
216
+ this.$input.val() + ' ' + this.$altInput.val() :
217
+ this.$input.val();
218
+
219
+ this.timeDefined = this._parseTime(currDT);
220
+ this._limitMinMaxDateTime(dp_inst, false);
221
+ this._injectTimePicker();
222
+ },
223
+
224
+ //########################################################################
225
+ // parse the time string from input value or _setTime
226
+ //########################################################################
227
+ _parseTime: function(timeString, withDate) {
228
+ var regstr = this._defaults.timeFormat.toString()
229
+ .replace(/h{1,2}/ig, '(\\d?\\d)')
230
+ .replace(/m{1,2}/ig, '(\\d?\\d)')
231
+ .replace(/s{1,2}/ig, '(\\d?\\d)')
232
+ .replace(/l{1}/ig, '(\\d?\\d?\\d)')
233
+ .replace(/t{1,2}/ig, this._getPatternAmpm())
234
+ .replace(/z{1}/ig, '(z|[-+]\\d\\d:?\\d\\d)?')
235
+ .replace(/\s/g, '\\s?') + this._defaults.timeSuffix + '$',
236
+ order = this._getFormatPositions(),
237
+ ampm = '',
238
+ treg;
239
+
240
+ if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]);
241
+
242
+ if (withDate || !this._defaults.timeOnly) {
243
+ // the time should come after x number of characters and a space.
244
+ // x = at least the length of text specified by the date format
245
+ var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat');
246
+ // escape special regex characters in the seperator
247
+ var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g");
248
+ regstr = '.{' + dp_dateFormat.length + ',}' + this._defaults.separator.replace(specials, "\\$&") + regstr;
249
+ }
250
+
251
+ treg = timeString.match(new RegExp(regstr, 'i'));
252
+
253
+ if (treg) {
254
+ if (order.t !== -1) {
255
+ if (treg[order.t] === undefined || treg[order.t].length === 0) {
256
+ ampm = '';
257
+ this.ampm = '';
258
+ } else {
259
+ ampm = $.inArray(treg[order.t].toUpperCase(), this.amNames) !== -1 ? 'AM' : 'PM';
260
+ this.ampm = this._defaults[ampm == 'AM' ? 'amNames' : 'pmNames'][0];
261
+ }
262
+ }
263
+
264
+ if (order.h !== -1) {
265
+ if (ampm == 'AM' && treg[order.h] == '12')
266
+ this.hour = 0; // 12am = 0 hour
267
+ else if (ampm == 'PM' && treg[order.h] != '12')
268
+ this.hour = (parseFloat(treg[order.h]) + 12).toFixed(0); // 12pm = 12 hour, any other pm = hour + 12
269
+ else this.hour = Number(treg[order.h]);
270
+ }
271
+
272
+ if (order.m !== -1) this.minute = Number(treg[order.m]);
273
+ if (order.s !== -1) this.second = Number(treg[order.s]);
274
+ if (order.l !== -1) this.millisec = Number(treg[order.l]);
275
+ if (order.z !== -1 && treg[order.z] !== undefined) {
276
+ var tz = treg[order.z].toUpperCase();
277
+ switch (tz.length) {
278
+ case 1: // Z
279
+ tz = this._defaults.timezoneIso8609 ? 'Z' : '+0000';
280
+ break;
281
+ case 5: // +hhmm
282
+ if (this._defaults.timezoneIso8609)
283
+ tz = tz.substring(1) == '0000'
284
+ ? 'Z'
285
+ : tz.substring(0, 3) + ':' + tz.substring(3);
286
+ break;
287
+ case 6: // +hh:mm
288
+ if (!this._defaults.timezoneIso8609)
289
+ tz = tz == 'Z' || tz.substring(1) == '00:00'
290
+ ? '+0000'
291
+ : tz.replace(/:/, '');
292
+ else if (tz.substring(1) == '00:00')
293
+ tz = 'Z';
294
+ break;
295
+ }
296
+ this.timezone = tz;
297
+ }
298
+
299
+ return true;
300
+
301
+ }
302
+ return false;
303
+ },
304
+
305
+ //########################################################################
306
+ // pattern for standard and localized AM/PM markers
307
+ //########################################################################
308
+ _getPatternAmpm: function() {
309
+ var markers = [];
310
+ o = this._defaults;
311
+ if (o.amNames)
312
+ $.merge(markers, o.amNames);
313
+ if (o.pmNames)
314
+ $.merge(markers, o.pmNames);
315
+ markers = $.map(markers, function(val) { return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&') });
316
+ return '(' + markers.join('|') + ')?';
317
+ },
318
+
319
+ //########################################################################
320
+ // figure out position of time elements.. cause js cant do named captures
321
+ //########################################################################
322
+ _getFormatPositions: function() {
323
+ var finds = this._defaults.timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z)/g),
324
+ orders = { h: -1, m: -1, s: -1, l: -1, t: -1, z: -1 };
325
+
326
+ if (finds)
327
+ for (var i = 0; i < finds.length; i++)
328
+ if (orders[finds[i].toString().charAt(0)] == -1)
329
+ orders[finds[i].toString().charAt(0)] = i + 1;
330
+
331
+ return orders;
332
+ },
333
+
334
+ //########################################################################
335
+ // generate and inject html for timepicker into ui datepicker
336
+ //########################################################################
337
+ _injectTimePicker: function() {
338
+ var $dp = this.inst.dpDiv,
339
+ o = this._defaults,
340
+ tp_inst = this,
341
+ // Added by Peter Medeiros:
342
+ // - Figure out what the hour/minute/second max should be based on the step values.
343
+ // - Example: if stepMinute is 15, then minMax is 45.
344
+ hourMax = (o.hourMax - ((o.hourMax - o.hourMin) % o.stepHour)).toFixed(0),
345
+ minMax = (o.minuteMax - ((o.minuteMax - o.minuteMin) % o.stepMinute)).toFixed(0),
346
+ secMax = (o.secondMax - ((o.secondMax - o.secondMin) % o.stepSecond)).toFixed(0),
347
+ millisecMax = (o.millisecMax - ((o.millisecMax - o.millisecMin) % o.stepMillisec)).toFixed(0),
348
+ dp_id = this.inst.id.toString().replace(/([^A-Za-z0-9_])/g, '');
349
+
350
+ // Prevent displaying twice
351
+ //if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0) {
352
+ if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0 && o.showTimepicker) {
353
+ var noDisplay = ' style="display:none;"',
354
+ html = '<div class="ui-timepicker-div" id="ui-timepicker-div-' + dp_id + '"><dl>' +
355
+ '<dt class="ui_tpicker_time_label" id="ui_tpicker_time_label_' + dp_id + '"' +
356
+ ((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</dt>' +
357
+ '<dd class="ui_tpicker_time" id="ui_tpicker_time_' + dp_id + '"' +
358
+ ((o.showTime) ? '' : noDisplay) + '></dd>' +
359
+ '<dt class="ui_tpicker_hour_label" id="ui_tpicker_hour_label_' + dp_id + '"' +
360
+ ((o.showHour) ? '' : noDisplay) + '>' + o.hourText + '</dt>',
361
+ hourGridSize = 0,
362
+ minuteGridSize = 0,
363
+ secondGridSize = 0,
364
+ millisecGridSize = 0,
365
+ size;
366
+
367
+ // Hours
368
+ if (o.showHour && o.hourGrid > 0) {
369
+ html += '<dd class="ui_tpicker_hour">' +
370
+ '<div id="ui_tpicker_hour_' + dp_id + '"' + ((o.showHour) ? '' : noDisplay) + '></div>' +
371
+ '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>';
372
+
373
+ for (var h = o.hourMin; h <= hourMax; h += parseInt(o.hourGrid,10)) {
374
+ hourGridSize++;
375
+ var tmph = (o.ampm && h > 12) ? h-12 : h;
376
+ if (tmph < 10) tmph = '0' + tmph;
377
+ if (o.ampm) {
378
+ if (h == 0) tmph = 12 +'a';
379
+ else if (h < 12) tmph += 'a';
380
+ else tmph += 'p';
381
+ }
382
+ html += '<td>' + tmph + '</td>';
383
+ }
384
+
385
+ html += '</tr></table></div>' +
386
+ '</dd>';
387
+ } else html += '<dd class="ui_tpicker_hour" id="ui_tpicker_hour_' + dp_id + '"' +
388
+ ((o.showHour) ? '' : noDisplay) + '></dd>';
389
+
390
+ html += '<dt class="ui_tpicker_minute_label" id="ui_tpicker_minute_label_' + dp_id + '"' +
391
+ ((o.showMinute) ? '' : noDisplay) + '>' + o.minuteText + '</dt>';
392
+
393
+ // Minutes
394
+ if (o.showMinute && o.minuteGrid > 0) {
395
+ html += '<dd class="ui_tpicker_minute ui_tpicker_minute_' + o.minuteGrid + '">' +
396
+ '<div id="ui_tpicker_minute_' + dp_id + '"' +
397
+ ((o.showMinute) ? '' : noDisplay) + '></div>' +
398
+ '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>';
399
+
400
+ for (var m = o.minuteMin; m <= minMax; m += parseInt(o.minuteGrid,10)) {
401
+ minuteGridSize++;
402
+ html += '<td>' + ((m < 10) ? '0' : '') + m + '</td>';
403
+ }
404
+
405
+ html += '</tr></table></div>' +
406
+ '</dd>';
407
+ } else html += '<dd class="ui_tpicker_minute" id="ui_tpicker_minute_' + dp_id + '"' +
408
+ ((o.showMinute) ? '' : noDisplay) + '></dd>';
409
+
410
+ // Seconds
411
+ html += '<dt class="ui_tpicker_second_label" id="ui_tpicker_second_label_' + dp_id + '"' +
412
+ ((o.showSecond) ? '' : noDisplay) + '>' + o.secondText + '</dt>';
413
+
414
+ if (o.showSecond && o.secondGrid > 0) {
415
+ html += '<dd class="ui_tpicker_second ui_tpicker_second_' + o.secondGrid + '">' +
416
+ '<div id="ui_tpicker_second_' + dp_id + '"' +
417
+ ((o.showSecond) ? '' : noDisplay) + '></div>' +
418
+ '<div style="padding-left: 1px"><table><tr>';
419
+
420
+ for (var s = o.secondMin; s <= secMax; s += parseInt(o.secondGrid,10)) {
421
+ secondGridSize++;
422
+ html += '<td>' + ((s < 10) ? '0' : '') + s + '</td>';
423
+ }
424
+
425
+ html += '</tr></table></div>' +
426
+ '</dd>';
427
+ } else html += '<dd class="ui_tpicker_second" id="ui_tpicker_second_' + dp_id + '"' +
428
+ ((o.showSecond) ? '' : noDisplay) + '></dd>';
429
+
430
+ // Milliseconds
431
+ html += '<dt class="ui_tpicker_millisec_label" id="ui_tpicker_millisec_label_' + dp_id + '"' +
432
+ ((o.showMillisec) ? '' : noDisplay) + '>' + o.millisecText + '</dt>';
433
+
434
+ if (o.showMillisec && o.millisecGrid > 0) {
435
+ html += '<dd class="ui_tpicker_millisec ui_tpicker_millisec_' + o.millisecGrid + '">' +
436
+ '<div id="ui_tpicker_millisec_' + dp_id + '"' +
437
+ ((o.showMillisec) ? '' : noDisplay) + '></div>' +
438
+ '<div style="padding-left: 1px"><table><tr>';
439
+
440
+ for (var l = o.millisecMin; l <= millisecMax; l += parseInt(o.millisecGrid,10)) {
441
+ millisecGridSize++;
442
+ html += '<td>' + ((l < 10) ? '0' : '') + s + '</td>';
443
+ }
444
+
445
+ html += '</tr></table></div>' +
446
+ '</dd>';
447
+ } else html += '<dd class="ui_tpicker_millisec" id="ui_tpicker_millisec_' + dp_id + '"' +
448
+ ((o.showMillisec) ? '' : noDisplay) + '></dd>';
449
+
450
+ // Timezone
451
+ html += '<dt class="ui_tpicker_timezone_label" id="ui_tpicker_timezone_label_' + dp_id + '"' +
452
+ ((o.showTimezone) ? '' : noDisplay) + '>' + o.timezoneText + '</dt>';
453
+ html += '<dd class="ui_tpicker_timezone" id="ui_tpicker_timezone_' + dp_id + '"' +
454
+ ((o.showTimezone) ? '' : noDisplay) + '></dd>';
455
+
456
+ html += '</dl></div>';
457
+ $tp = $(html);
458
+
459
+ // if we only want time picker...
460
+ if (o.timeOnly === true) {
461
+ $tp.prepend(
462
+ '<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' +
463
+ '<div class="ui-datepicker-title">' + o.timeOnlyTitle + '</div>' +
464
+ '</div>');
465
+ $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide();
466
+ }
467
+
468
+ this.hour_slider = $tp.find('#ui_tpicker_hour_'+ dp_id).slider({
469
+ orientation: "horizontal",
470
+ value: this.hour,
471
+ min: o.hourMin,
472
+ max: hourMax,
473
+ step: o.stepHour,
474
+ slide: function(event, ui) {
475
+ tp_inst.hour_slider.slider( "option", "value", ui.value);
476
+ tp_inst._onTimeChange();
477
+ }
478
+ });
479
+
480
+ // Updated by Peter Medeiros:
481
+ // - Pass in Event and UI instance into slide function
482
+ this.minute_slider = $tp.find('#ui_tpicker_minute_'+ dp_id).slider({
483
+ orientation: "horizontal",
484
+ value: this.minute,
485
+ min: o.minuteMin,
486
+ max: minMax,
487
+ step: o.stepMinute,
488
+ slide: function(event, ui) {
489
+ // update the global minute slider instance value with the current slider value
490
+ tp_inst.minute_slider.slider( "option", "value", ui.value);
491
+ tp_inst._onTimeChange();
492
+ }
493
+ });
494
+
495
+ this.second_slider = $tp.find('#ui_tpicker_second_'+ dp_id).slider({
496
+ orientation: "horizontal",
497
+ value: this.second,
498
+ min: o.secondMin,
499
+ max: secMax,
500
+ step: o.stepSecond,
501
+ slide: function(event, ui) {
502
+ tp_inst.second_slider.slider( "option", "value", ui.value);
503
+ tp_inst._onTimeChange();
504
+ }
505
+ });
506
+
507
+ this.millisec_slider = $tp.find('#ui_tpicker_millisec_'+ dp_id).slider({
508
+ orientation: "horizontal",
509
+ value: this.millisec,
510
+ min: o.millisecMin,
511
+ max: millisecMax,
512
+ step: o.stepMillisec,
513
+ slide: function(event, ui) {
514
+ tp_inst.millisec_slider.slider( "option", "value", ui.value);
515
+ tp_inst._onTimeChange();
516
+ }
517
+ });
518
+
519
+ this.timezone_select = $tp.find('#ui_tpicker_timezone_'+ dp_id).append('<select></select>').find("select");
520
+ $.fn.append.apply(this.timezone_select,
521
+ $.map(o.timezoneList, function(val, idx) {
522
+ return $("<option />")
523
+ .val(typeof val == "object" ? val.value : val)
524
+ .text(typeof val == "object" ? val.label : val);
525
+ })
526
+ );
527
+ this.timezone_select.val((typeof this.timezone != "undefined" && this.timezone != null && this.timezone != "") ? this.timezone : o.timezone);
528
+ this.timezone_select.change(function() {
529
+ tp_inst._onTimeChange();
530
+ });
531
+
532
+ // Add grid functionality
533
+ if (o.showHour && o.hourGrid > 0) {
534
+ size = 100 * hourGridSize * o.hourGrid / (hourMax - o.hourMin);
535
+
536
+ $tp.find(".ui_tpicker_hour table").css({
537
+ width: size + "%",
538
+ marginLeft: (size / (-2 * hourGridSize)) + "%",
539
+ borderCollapse: 'collapse'
540
+ }).find("td").each( function(index) {
541
+ $(this).click(function() {
542
+ var h = $(this).html();
543
+ if(o.ampm) {
544
+ var ap = h.substring(2).toLowerCase(),
545
+ aph = parseInt(h.substring(0,2), 10);
546
+ if (ap == 'a') {
547
+ if (aph == 12) h = 0;
548
+ else h = aph;
549
+ } else if (aph == 12) h = 12;
550
+ else h = aph + 12;
551
+ }
552
+ tp_inst.hour_slider.slider("option", "value", h);
553
+ tp_inst._onTimeChange();
554
+ tp_inst._onSelectHandler();
555
+ }).css({
556
+ cursor: 'pointer',
557
+ width: (100 / hourGridSize) + '%',
558
+ textAlign: 'center',
559
+ overflow: 'hidden'
560
+ });
561
+ });
562
+ }
563
+
564
+ if (o.showMinute && o.minuteGrid > 0) {
565
+ size = 100 * minuteGridSize * o.minuteGrid / (minMax - o.minuteMin);
566
+ $tp.find(".ui_tpicker_minute table").css({
567
+ width: size + "%",
568
+ marginLeft: (size / (-2 * minuteGridSize)) + "%",
569
+ borderCollapse: 'collapse'
570
+ }).find("td").each(function(index) {
571
+ $(this).click(function() {
572
+ tp_inst.minute_slider.slider("option", "value", $(this).html());
573
+ tp_inst._onTimeChange();
574
+ tp_inst._onSelectHandler();
575
+ }).css({
576
+ cursor: 'pointer',
577
+ width: (100 / minuteGridSize) + '%',
578
+ textAlign: 'center',
579
+ overflow: 'hidden'
580
+ });
581
+ });
582
+ }
583
+
584
+ if (o.showSecond && o.secondGrid > 0) {
585
+ $tp.find(".ui_tpicker_second table").css({
586
+ width: size + "%",
587
+ marginLeft: (size / (-2 * secondGridSize)) + "%",
588
+ borderCollapse: 'collapse'
589
+ }).find("td").each(function(index) {
590
+ $(this).click(function() {
591
+ tp_inst.second_slider.slider("option", "value", $(this).html());
592
+ tp_inst._onTimeChange();
593
+ tp_inst._onSelectHandler();
594
+ }).css({
595
+ cursor: 'pointer',
596
+ width: (100 / secondGridSize) + '%',
597
+ textAlign: 'center',
598
+ overflow: 'hidden'
599
+ });
600
+ });
601
+ }
602
+
603
+ if (o.showMillisec && o.millisecGrid > 0) {
604
+ $tp.find(".ui_tpicker_millisec table").css({
605
+ width: size + "%",
606
+ marginLeft: (size / (-2 * millisecGridSize)) + "%",
607
+ borderCollapse: 'collapse'
608
+ }).find("td").each(function(index) {
609
+ $(this).click(function() {
610
+ tp_inst.millisec_slider.slider("option", "value", $(this).html());
611
+ tp_inst._onTimeChange();
612
+ tp_inst._onSelectHandler();
613
+ }).css({
614
+ cursor: 'pointer',
615
+ width: (100 / millisecGridSize) + '%',
616
+ textAlign: 'center',
617
+ overflow: 'hidden'
618
+ });
619
+ });
620
+ }
621
+
622
+ var $buttonPanel = $dp.find('.ui-datepicker-buttonpane');
623
+ if ($buttonPanel.length) $buttonPanel.before($tp);
624
+ else $dp.append($tp);
625
+
626
+ this.$timeObj = $tp.find('#ui_tpicker_time_'+ dp_id);
627
+
628
+ if (this.inst !== null) {
629
+ var timeDefined = this.timeDefined;
630
+ this._onTimeChange();
631
+ this.timeDefined = timeDefined;
632
+ }
633
+
634
+ //Emulate datepicker onSelect behavior. Call on slidestop.
635
+ var onSelectDelegate = function() {
636
+ tp_inst._onSelectHandler();
637
+ };
638
+ this.hour_slider.bind('slidestop',onSelectDelegate);
639
+ this.minute_slider.bind('slidestop',onSelectDelegate);
640
+ this.second_slider.bind('slidestop',onSelectDelegate);
641
+ this.millisec_slider.bind('slidestop',onSelectDelegate);
642
+ }
643
+ },
644
+
645
+ //########################################################################
646
+ // This function tries to limit the ability to go outside the
647
+ // min/max date range
648
+ //########################################################################
649
+ _limitMinMaxDateTime: function(dp_inst, adjustSliders){
650
+ var o = this._defaults,
651
+ dp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay);
652
+
653
+ if(!this._defaults.showTimepicker) return; // No time so nothing to check here
654
+
655
+ if($.datepicker._get(dp_inst, 'minDateTime') !== null && $.datepicker._get(dp_inst, 'minDateTime') !== undefined && dp_date){
656
+ var minDateTime = $.datepicker._get(dp_inst, 'minDateTime'),
657
+ minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0);
658
+
659
+ if(this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null || this.millisecMinOriginal === null){
660
+ this.hourMinOriginal = o.hourMin;
661
+ this.minuteMinOriginal = o.minuteMin;
662
+ this.secondMinOriginal = o.secondMin;
663
+ this.millisecMinOriginal = o.millisecMin;
664
+ }
665
+
666
+ if(dp_inst.settings.timeOnly || minDateTimeDate.getTime() == dp_date.getTime()) {
667
+ this._defaults.hourMin = minDateTime.getHours();
668
+ if (this.hour <= this._defaults.hourMin) {
669
+ this.hour = this._defaults.hourMin;
670
+ this._defaults.minuteMin = minDateTime.getMinutes();
671
+ if (this.minute <= this._defaults.minuteMin) {
672
+ this.minute = this._defaults.minuteMin;
673
+ this._defaults.secondMin = minDateTime.getSeconds();
674
+ } else if (this.second <= this._defaults.secondMin){
675
+ this.second = this._defaults.secondMin;
676
+ this._defaults.millisecMin = minDateTime.getMilliseconds();
677
+ } else {
678
+ if(this.millisec < this._defaults.millisecMin)
679
+ this.millisec = this._defaults.millisecMin;
680
+ this._defaults.millisecMin = this.millisecMinOriginal;
681
+ }
682
+ } else {
683
+ this._defaults.minuteMin = this.minuteMinOriginal;
684
+ this._defaults.secondMin = this.secondMinOriginal;
685
+ this._defaults.millisecMin = this.millisecMinOriginal;
686
+ }
687
+ }else{
688
+ this._defaults.hourMin = this.hourMinOriginal;
689
+ this._defaults.minuteMin = this.minuteMinOriginal;
690
+ this._defaults.secondMin = this.secondMinOriginal;
691
+ this._defaults.millisecMin = this.millisecMinOriginal;
692
+ }
693
+ }
694
+
695
+ if($.datepicker._get(dp_inst, 'maxDateTime') !== null && $.datepicker._get(dp_inst, 'maxDateTime') !== undefined && dp_date){
696
+ var maxDateTime = $.datepicker._get(dp_inst, 'maxDateTime'),
697
+ maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0);
698
+
699
+ if(this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null){
700
+ this.hourMaxOriginal = o.hourMax;
701
+ this.minuteMaxOriginal = o.minuteMax;
702
+ this.secondMaxOriginal = o.secondMax;
703
+ this.millisecMaxOriginal = o.millisecMax;
704
+ }
705
+
706
+ if(dp_inst.settings.timeOnly || maxDateTimeDate.getTime() == dp_date.getTime()){
707
+ this._defaults.hourMax = maxDateTime.getHours();
708
+ if (this.hour >= this._defaults.hourMax) {
709
+ this.hour = this._defaults.hourMax;
710
+ this._defaults.minuteMax = maxDateTime.getMinutes();
711
+ if (this.minute >= this._defaults.minuteMax) {
712
+ this.minute = this._defaults.minuteMax;
713
+ this._defaults.secondMax = maxDateTime.getSeconds();
714
+ } else if (this.second >= this._defaults.secondMax) {
715
+ this.second = this._defaults.secondMax;
716
+ this._defaults.millisecMax = maxDateTime.getMilliseconds();
717
+ } else {
718
+ if(this.millisec > this._defaults.millisecMax) this.millisec = this._defaults.millisecMax;
719
+ this._defaults.millisecMax = this.millisecMaxOriginal;
720
+ }
721
+ } else {
722
+ this._defaults.minuteMax = this.minuteMaxOriginal;
723
+ this._defaults.secondMax = this.secondMaxOriginal;
724
+ this._defaults.millisecMax = this.millisecMaxOriginal;
725
+ }
726
+ }else{
727
+ this._defaults.hourMax = this.hourMaxOriginal;
728
+ this._defaults.minuteMax = this.minuteMaxOriginal;
729
+ this._defaults.secondMax = this.secondMaxOriginal;
730
+ this._defaults.millisecMax = this.millisecMaxOriginal;
731
+ }
732
+ }
733
+
734
+ if(adjustSliders !== undefined && adjustSliders === true){
735
+ var hourMax = (this._defaults.hourMax - ((this._defaults.hourMax - this._defaults.hourMin) % this._defaults.stepHour)).toFixed(0),
736
+ minMax = (this._defaults.minuteMax - ((this._defaults.minuteMax - this._defaults.minuteMin) % this._defaults.stepMinute)).toFixed(0),
737
+ secMax = (this._defaults.secondMax - ((this._defaults.secondMax - this._defaults.secondMin) % this._defaults.stepSecond)).toFixed(0),
738
+ millisecMax = (this._defaults.millisecMax - ((this._defaults.millisecMax - this._defaults.millisecMin) % this._defaults.stepMillisec)).toFixed(0);
739
+
740
+ if(this.hour_slider)
741
+ this.hour_slider.slider("option", { min: this._defaults.hourMin, max: hourMax }).slider('value', this.hour);
742
+ if(this.minute_slider)
743
+ this.minute_slider.slider("option", { min: this._defaults.minuteMin, max: minMax }).slider('value', this.minute);
744
+ if(this.second_slider)
745
+ this.second_slider.slider("option", { min: this._defaults.secondMin, max: secMax }).slider('value', this.second);
746
+ if(this.millisec_slider)
747
+ this.millisec_slider.slider("option", { min: this._defaults.millisecMin, max: millisecMax }).slider('value', this.millisec);
748
+ }
749
+
750
+ },
751
+
752
+
753
+ //########################################################################
754
+ // when a slider moves, set the internal time...
755
+ // on time change is also called when the time is updated in the text field
756
+ //########################################################################
757
+ _onTimeChange: function() {
758
+ var hour = (this.hour_slider) ? this.hour_slider.slider('value') : false,
759
+ minute = (this.minute_slider) ? this.minute_slider.slider('value') : false,
760
+ second = (this.second_slider) ? this.second_slider.slider('value') : false,
761
+ millisec = (this.millisec_slider) ? this.millisec_slider.slider('value') : false,
762
+ timezone = (this.timezone_select) ? this.timezone_select.val() : false,
763
+ o = this._defaults;
764
+
765
+ if (typeof(hour) == 'object') hour = false;
766
+ if (typeof(minute) == 'object') minute = false;
767
+ if (typeof(second) == 'object') second = false;
768
+ if (typeof(millisec) == 'object') millisec = false;
769
+ if (typeof(timezone) == 'object') timezone = false;
770
+
771
+ if (hour !== false) hour = parseInt(hour,10);
772
+ if (minute !== false) minute = parseInt(minute,10);
773
+ if (second !== false) second = parseInt(second,10);
774
+ if (millisec !== false) millisec = parseInt(millisec,10);
775
+
776
+ var ampm = o[hour < 12 ? 'amNames' : 'pmNames'][0];
777
+
778
+ // If the update was done in the input field, the input field should not be updated.
779
+ // If the update was done using the sliders, update the input field.
780
+ var hasChanged = (hour != this.hour || minute != this.minute
781
+ || second != this.second || millisec != this.millisec
782
+ || (this.ampm.length > 0
783
+ && (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1))
784
+ || timezone != this.timezone);
785
+
786
+ if (hasChanged) {
787
+
788
+ if (hour !== false)this.hour = hour;
789
+ if (minute !== false) this.minute = minute;
790
+ if (second !== false) this.second = second;
791
+ if (millisec !== false) this.millisec = millisec;
792
+ if (timezone !== false) this.timezone = timezone;
793
+
794
+ if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]);
795
+
796
+ this._limitMinMaxDateTime(this.inst, true);
797
+ }
798
+ if (o.ampm) this.ampm = ampm;
799
+
800
+ this._formatTime();
801
+ if (this.$timeObj) this.$timeObj.text(this.formattedTime + o.timeSuffix);
802
+ this.timeDefined = true;
803
+ if (hasChanged) this._updateDateTime();
804
+ },
805
+
806
+ //########################################################################
807
+ // call custom onSelect.
808
+ // bind to sliders slidestop, and grid click.
809
+ //########################################################################
810
+ _onSelectHandler: function() {
811
+ var onSelect = this._defaults.onSelect;
812
+ var inputEl = this.$input ? this.$input[0] : null;
813
+ if (onSelect && inputEl) {
814
+ onSelect.apply(inputEl, [this.formattedDateTime, this]);
815
+ }
816
+ },
817
+
818
+ //########################################################################
819
+ // format the time all pretty...
820
+ //########################################################################
821
+ _formatTime: function(time, format, ampm) {
822
+ if (ampm == undefined) ampm = this._defaults.ampm;
823
+ time = time || { hour: this.hour, minute: this.minute, second: this.second, millisec: this.millisec, ampm: this.ampm, timezone: this.timezone };
824
+ var tmptime = (format || this._defaults.timeFormat).toString();
825
+
826
+ var hour = parseInt(time.hour, 10);
827
+ if (ampm) {
828
+ if (!$.inArray(time.ampm.toUpperCase(), this.amNames) !== -1)
829
+ hour = hour % 12;
830
+ if (hour === 0)
831
+ hour = 12;
832
+ }
833
+ tmptime = tmptime.replace(/(?:hh?|mm?|ss?|[tT]{1,2}|[lz])/g, function(match) {
834
+ switch (match.toLowerCase()) {
835
+ case 'hh': return ('0' + hour).slice(-2);
836
+ case 'h': return hour;
837
+ case 'mm': return ('0' + time.minute).slice(-2);
838
+ case 'm': return time.minute;
839
+ case 'ss': return ('0' + time.second).slice(-2);
840
+ case 's': return time.second;
841
+ case 'l': return ('00' + time.millisec).slice(-3);
842
+ case 'z': return time.timezone;
843
+ case 't': case 'tt':
844
+ if (ampm) {
845
+ var _ampm = time.ampm;
846
+ if (match.length == 1)
847
+ _ampm = _ampm.charAt(0);
848
+ return match.charAt(0) == 'T' ? _ampm.toUpperCase() : _ampm.toLowerCase();
849
+ }
850
+ return '';
851
+ }
852
+ });
853
+
854
+ if (arguments.length) return tmptime;
855
+ else this.formattedTime = tmptime;
856
+ },
857
+
858
+ //########################################################################
859
+ // update our input with the new date time..
860
+ //########################################################################
861
+ _updateDateTime: function(dp_inst) {
862
+ dp_inst = this.inst || dp_inst,
863
+ dt = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay),
864
+ dateFmt = $.datepicker._get(dp_inst, 'dateFormat'),
865
+ formatCfg = $.datepicker._getFormatConfig(dp_inst),
866
+ timeAvailable = dt !== null && this.timeDefined;
867
+ this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg);
868
+ var formattedDateTime = this.formattedDate;
869
+ if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0))
870
+ return;
871
+
872
+ if (this._defaults.timeOnly === true) {
873
+ formattedDateTime = this.formattedTime;
874
+ } else if (this._defaults.timeOnly !== true && (this._defaults.alwaysSetTime || timeAvailable)) {
875
+ formattedDateTime += this._defaults.separator + this.formattedTime + this._defaults.timeSuffix;
876
+ }
877
+
878
+ this.formattedDateTime = formattedDateTime;
879
+
880
+ if(!this._defaults.showTimepicker) {
881
+ this.$input.val(this.formattedDate);
882
+ } else if (this.$altInput && this._defaults.altFieldTimeOnly === true) {
883
+ this.$altInput.val(this.formattedTime);
884
+ this.$input.val(this.formattedDate);
885
+ } else if(this.$altInput) {
886
+ this.$altInput.val(formattedDateTime);
887
+ this.$input.val(formattedDateTime);
888
+ } else {
889
+ this.$input.val(formattedDateTime);
890
+ }
891
+
892
+ this.$input.trigger("change");
893
+ }
894
+
895
+ });
896
+
897
+ $.fn.extend({
898
+ //########################################################################
899
+ // shorthand just to use timepicker..
900
+ //########################################################################
901
+ timepicker: function(o) {
902
+ o = o || {};
903
+ var tmp_args = arguments;
904
+
905
+ if (typeof o == 'object') tmp_args[0] = $.extend(o, { timeOnly: true });
906
+
907
+ return $(this).each(function() {
908
+ $.fn.datetimepicker.apply($(this), tmp_args);
909
+ });
910
+ },
911
+
912
+ //########################################################################
913
+ // extend timepicker to datepicker
914
+ //########################################################################
915
+ datetimepicker: function(o) {
916
+ o = o || {};
917
+ var $input = this,
918
+ tmp_args = arguments;
919
+
920
+ if (typeof(o) == 'string'){
921
+ if(o == 'getDate')
922
+ return $.fn.datepicker.apply($(this[0]), tmp_args);
923
+ else
924
+ return this.each(function() {
925
+ var $t = $(this);
926
+ $t.datepicker.apply($t, tmp_args);
927
+ });
928
+ }
929
+ else
930
+ return this.each(function() {
931
+ var $t = $(this);
932
+ $t.datepicker($.timepicker._newInst($t, o)._defaults);
933
+ });
934
+ }
935
+ });
936
+
937
+ //########################################################################
938
+ // the bad hack :/ override datepicker so it doesnt close on select
939
+ // inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378
940
+ //########################################################################
941
+ $.datepicker._base_selectDate = $.datepicker._selectDate;
942
+ $.datepicker._selectDate = function (id, dateStr) {
943
+ var inst = this._getInst($(id)[0]),
944
+ tp_inst = this._get(inst, 'timepicker');
945
+
946
+ if (tp_inst) {
947
+ tp_inst._limitMinMaxDateTime(inst, true);
948
+ inst.inline = inst.stay_open = true;
949
+ //This way the onSelect handler called from calendarpicker get the full dateTime
950
+ this._base_selectDate(id, dateStr);
951
+ inst.inline = inst.stay_open = false;
952
+ this._notifyChange(inst);
953
+ this._updateDatepicker(inst);
954
+ }
955
+ else this._base_selectDate(id, dateStr);
956
+ };
957
+
958
+ //#############################################################################################
959
+ // second bad hack :/ override datepicker so it triggers an event when changing the input field
960
+ // and does not redraw the datepicker on every selectDate event
961
+ //#############################################################################################
962
+ $.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker;
963
+ $.datepicker._updateDatepicker = function(inst) {
964
+
965
+ // don't popup the datepicker if there is another instance already opened
966
+ var input = inst.input[0];
967
+ if($.datepicker._curInst &&
968
+ $.datepicker._curInst != inst &&
969
+ $.datepicker._datepickerShowing &&
970
+ $.datepicker._lastInput != input) {
971
+ return;
972
+ }
973
+
974
+ if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {
975
+
976
+ this._base_updateDatepicker(inst);
977
+
978
+ // Reload the time control when changing something in the input text field.
979
+ var tp_inst = this._get(inst, 'timepicker');
980
+ if(tp_inst) tp_inst._addTimePicker(inst);
981
+ }
982
+ };
983
+
984
+ //#######################################################################################
985
+ // third bad hack :/ override datepicker so it allows spaces and colon in the input field
986
+ //#######################################################################################
987
+ $.datepicker._base_doKeyPress = $.datepicker._doKeyPress;
988
+ $.datepicker._doKeyPress = function(event) {
989
+ var inst = $.datepicker._getInst(event.target),
990
+ tp_inst = $.datepicker._get(inst, 'timepicker');
991
+
992
+ if (tp_inst) {
993
+ if ($.datepicker._get(inst, 'constrainInput')) {
994
+ var ampm = tp_inst._defaults.ampm,
995
+ dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
996
+ datetimeChars = tp_inst._defaults.timeFormat.toString()
997
+ .replace(/[hms]/g, '')
998
+ .replace(/TT/g, ampm ? 'APM' : '')
999
+ .replace(/Tt/g, ampm ? 'AaPpMm' : '')
1000
+ .replace(/tT/g, ampm ? 'AaPpMm' : '')
1001
+ .replace(/T/g, ampm ? 'AP' : '')
1002
+ .replace(/tt/g, ampm ? 'apm' : '')
1003
+ .replace(/t/g, ampm ? 'ap' : '') +
1004
+ " " +
1005
+ tp_inst._defaults.separator +
1006
+ tp_inst._defaults.timeSuffix +
1007
+ (tp_inst._defaults.showTimezone ? tp_inst._defaults.timezoneList.join('') : '') +
1008
+ (tp_inst._defaults.amNames.join('')) +
1009
+ (tp_inst._defaults.pmNames.join('')) +
1010
+ dateChars,
1011
+ chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
1012
+ return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1);
1013
+ }
1014
+ }
1015
+
1016
+ return $.datepicker._base_doKeyPress(event);
1017
+ };
1018
+
1019
+ //#######################################################################################
1020
+ // Override key up event to sync manual input changes.
1021
+ //#######################################################################################
1022
+ $.datepicker._base_doKeyUp = $.datepicker._doKeyUp;
1023
+ $.datepicker._doKeyUp = function (event) {
1024
+ var inst = $.datepicker._getInst(event.target),
1025
+ tp_inst = $.datepicker._get(inst, 'timepicker');
1026
+
1027
+ if (tp_inst) {
1028
+ if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) {
1029
+ try {
1030
+ $.datepicker._updateDatepicker(inst);
1031
+ }
1032
+ catch (err) {
1033
+ $.datepicker.log(err);
1034
+ }
1035
+ }
1036
+ }
1037
+
1038
+ return $.datepicker._base_doKeyUp(event);
1039
+ };
1040
+
1041
+ //#######################################################################################
1042
+ // override "Today" button to also grab the time.
1043
+ //#######################################################################################
1044
+ $.datepicker._base_gotoToday = $.datepicker._gotoToday;
1045
+ $.datepicker._gotoToday = function(id) {
1046
+ var inst = this._getInst($(id)[0]),
1047
+ $dp = inst.dpDiv;
1048
+ this._base_gotoToday(id);
1049
+ var now = new Date();
1050
+ var tp_inst = this._get(inst, 'timepicker');
1051
+ if (tp_inst._defaults.showTimezone && tp_inst.timezone_select) {
1052
+ var tzoffset = now.getTimezoneOffset(); // If +0100, returns -60
1053
+ var tzsign = tzoffset > 0 ? '-' : '+';
1054
+ tzoffset = Math.abs(tzoffset);
1055
+ var tzmin = tzoffset % 60
1056
+ tzoffset = tzsign + ('0' + (tzoffset - tzmin) / 60).slice(-2) + ('0' + tzmin).slice(-2);
1057
+ if (tp_inst._defaults.timezoneIso8609)
1058
+ tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3);
1059
+ tp_inst.timezone_select.val(tzoffset);
1060
+ }
1061
+ this._setTime(inst, now);
1062
+ $( '.ui-datepicker-today', $dp).click();
1063
+ };
1064
+
1065
+ //#######################################################################################
1066
+ // Disable & enable the Time in the datetimepicker
1067
+ //#######################################################################################
1068
+ $.datepicker._disableTimepickerDatepicker = function(target, date, withDate) {
1069
+ var inst = this._getInst(target),
1070
+ tp_inst = this._get(inst, 'timepicker');
1071
+ $(target).datepicker('getDate'); // Init selected[Year|Month|Day]
1072
+ if (tp_inst) {
1073
+ tp_inst._defaults.showTimepicker = false;
1074
+ tp_inst._updateDateTime(inst);
1075
+ }
1076
+ };
1077
+
1078
+ $.datepicker._enableTimepickerDatepicker = function(target, date, withDate) {
1079
+ var inst = this._getInst(target),
1080
+ tp_inst = this._get(inst, 'timepicker');
1081
+ $(target).datepicker('getDate'); // Init selected[Year|Month|Day]
1082
+ if (tp_inst) {
1083
+ tp_inst._defaults.showTimepicker = true;
1084
+ tp_inst._addTimePicker(inst); // Could be disabled on page load
1085
+ tp_inst._updateDateTime(inst);
1086
+ }
1087
+ };
1088
+
1089
+ //#######################################################################################
1090
+ // Create our own set time function
1091
+ //#######################################################################################
1092
+ $.datepicker._setTime = function(inst, date) {
1093
+ var tp_inst = this._get(inst, 'timepicker');
1094
+ if (tp_inst) {
1095
+ var defaults = tp_inst._defaults,
1096
+ // calling _setTime with no date sets time to defaults
1097
+ hour = date ? date.getHours() : defaults.hour,
1098
+ minute = date ? date.getMinutes() : defaults.minute,
1099
+ second = date ? date.getSeconds() : defaults.second,
1100
+ millisec = date ? date.getMilliseconds() : defaults.millisec;
1101
+
1102
+ //check if within min/max times..
1103
+ if ((hour < defaults.hourMin || hour > defaults.hourMax) || (minute < defaults.minuteMin || minute > defaults.minuteMax) || (second < defaults.secondMin || second > defaults.secondMax) || (millisec < defaults.millisecMin || millisec > defaults.millisecMax)) {
1104
+ hour = defaults.hourMin;
1105
+ minute = defaults.minuteMin;
1106
+ second = defaults.secondMin;
1107
+ millisec = defaults.millisecMin;
1108
+ }
1109
+
1110
+ tp_inst.hour = hour;
1111
+ tp_inst.minute = minute;
1112
+ tp_inst.second = second;
1113
+ tp_inst.millisec = millisec;
1114
+
1115
+ if (tp_inst.hour_slider) tp_inst.hour_slider.slider('value', hour);
1116
+ if (tp_inst.minute_slider) tp_inst.minute_slider.slider('value', minute);
1117
+ if (tp_inst.second_slider) tp_inst.second_slider.slider('value', second);
1118
+ if (tp_inst.millisec_slider) tp_inst.millisec_slider.slider('value', millisec);
1119
+
1120
+ tp_inst._onTimeChange();
1121
+ tp_inst._updateDateTime(inst);
1122
+ }
1123
+ };
1124
+
1125
+ //#######################################################################################
1126
+ // Create new public method to set only time, callable as $().datepicker('setTime', date)
1127
+ //#######################################################################################
1128
+ $.datepicker._setTimeDatepicker = function(target, date, withDate) {
1129
+ var inst = this._getInst(target),
1130
+ tp_inst = this._get(inst, 'timepicker');
1131
+
1132
+ if (tp_inst) {
1133
+ this._setDateFromField(inst);
1134
+ var tp_date;
1135
+ if (date) {
1136
+ if (typeof date == "string") {
1137
+ tp_inst._parseTime(date, withDate);
1138
+ tp_date = new Date();
1139
+ tp_date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
1140
+ }
1141
+ else tp_date = new Date(date.getTime());
1142
+ if (tp_date.toString() == 'Invalid Date') tp_date = undefined;
1143
+ this._setTime(inst, tp_date);
1144
+ }
1145
+ }
1146
+
1147
+ };
1148
+
1149
+ //#######################################################################################
1150
+ // override setDate() to allow setting time too within Date object
1151
+ //#######################################################################################
1152
+ $.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker;
1153
+ $.datepicker._setDateDatepicker = function(target, date) {
1154
+ var inst = this._getInst(target),
1155
+ tp_date = (date instanceof Date) ? new Date(date.getTime()) : date;
1156
+
1157
+ this._updateDatepicker(inst);
1158
+ this._base_setDateDatepicker.apply(this, arguments);
1159
+ this._setTimeDatepicker(target, tp_date, true);
1160
+ };
1161
+
1162
+ //#######################################################################################
1163
+ // override getDate() to allow getting time too within Date object
1164
+ //#######################################################################################
1165
+ $.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker;
1166
+ $.datepicker._getDateDatepicker = function(target, noDefault) {
1167
+ var inst = this._getInst(target),
1168
+ tp_inst = this._get(inst, 'timepicker');
1169
+
1170
+ if (tp_inst) {
1171
+ this._setDateFromField(inst, noDefault);
1172
+ var date = this._getDate(inst);
1173
+ if (date && tp_inst._parseTime($(target).val(), tp_inst.timeOnly)) date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
1174
+ return date;
1175
+ }
1176
+ return this._base_getDateDatepicker(target, noDefault);
1177
+ };
1178
+
1179
+ //#######################################################################################
1180
+ // override parseDate() because UI 1.8.14 throws an error about "Extra characters"
1181
+ // An option in datapicker to ignore extra format characters would be nicer.
1182
+ //#######################################################################################
1183
+ $.datepicker._base_parseDate = $.datepicker.parseDate;
1184
+ $.datepicker.parseDate = function(format, value, settings) {
1185
+ var date;
1186
+ try {
1187
+ date = this._base_parseDate(format, value, settings);
1188
+ } catch (err) {
1189
+ // Hack! The error message ends with a colon, a space, and
1190
+ // the "extra" characters. We rely on that instead of
1191
+ // attempting to perfectly reproduce the parsing algorithm.
1192
+ date = this._base_parseDate(format, value.substring(0,value.length-(err.length-err.indexOf(':')-2)), settings);
1193
+ }
1194
+ return date;
1195
+ };
1196
+
1197
+ //#######################################################################################
1198
+ // override formatDate to set date with time to the input
1199
+ //#######################################################################################
1200
+ $.datepicker._base_formatDate=$.datepicker._formatDate;
1201
+ $.datepicker._formatDate = function(inst, day, month, year){
1202
+ var tp_inst = this._get(inst, 'timepicker');
1203
+ if(tp_inst)
1204
+ {
1205
+ if(day)
1206
+ var b = this._base_formatDate(inst, day, month, year);
1207
+ tp_inst._updateDateTime();
1208
+ return tp_inst.$input.val();
1209
+ }
1210
+ return this._base_formatDate(inst);
1211
+ }
1212
+
1213
+ //#######################################################################################
1214
+ // override options setter to add time to maxDate(Time) and minDate(Time). MaxDate
1215
+ //#######################################################################################
1216
+ $.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker;
1217
+ $.datepicker._optionDatepicker = function(target, name, value) {
1218
+ var inst = this._getInst(target),
1219
+ tp_inst = this._get(inst, 'timepicker');
1220
+ if (tp_inst) {
1221
+ var min,max,onselect;
1222
+ if (typeof name == 'string') { // if min/max was set with the string
1223
+ if (name==='minDate' || name==='minDateTime' )
1224
+ min = value;
1225
+ else if (name==='maxDate' || name==='maxDateTime')
1226
+ max = value;
1227
+ else if (name==='onSelect')
1228
+ onselect=value;
1229
+ } else if (typeof name == 'object') { //if min/max was set with the JSON
1230
+ if(name.minDate)
1231
+ min = name.minDate;
1232
+ else if (name.minDateTime)
1233
+ min = name.minDateTime;
1234
+ else if (name.maxDate)
1235
+ max = name.maxDate;
1236
+ else if (name.maxDateTime)
1237
+ max = name.maxDateTime;
1238
+ }
1239
+ if(min){ //if min was set
1240
+ if(min==0)
1241
+ min=new Date();
1242
+ else
1243
+ min= new Date(min);
1244
+
1245
+ tp_inst._defaults.minDate = min;
1246
+ tp_inst._defaults.minDateTime = min;
1247
+ } else if (max){ //if max was set
1248
+ if(max==0)
1249
+ max=new Date();
1250
+ else
1251
+ max= new Date(max);
1252
+ tp_inst._defaults.maxDate = max;
1253
+ tp_inst._defaults.maxDateTime = max;
1254
+ }
1255
+ else if (onselect)
1256
+ tp_inst._defaults.onSelect=onselect;
1257
+ }
1258
+ this._base_optionDatepicker(target, name, value);
1259
+ };
1260
+
1261
+ //#######################################################################################
1262
+ // jQuery extend now ignores nulls!
1263
+ //#######################################################################################
1264
+ function extendRemove(target, props) {
1265
+ $.extend(target, props);
1266
+ for (var name in props)
1267
+ if (props[name] === null || props[name] === undefined)
1268
+ target[name] = props[name];
1269
+ return target;
1270
+ }
1271
+
1272
+ $.timepicker = new Timepicker(); // singleton instance
1273
+ $.timepicker.version = "0.9.7";
1274
+
1275
+ })(jQuery);
1276
+