friends_ajax_core 0.0.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/app/assets/images/icons-16/icon-arrow-down-hover.png +0 -0
  3. data/app/assets/images/icons-16/icon-arrow-down.png +0 -0
  4. data/app/assets/images/icons-16/icon-arrow-right-hover.png +0 -0
  5. data/app/assets/images/icons-16/icon-arrow-right.png +0 -0
  6. data/app/assets/images/icons/icon-close.png +0 -0
  7. data/app/assets/images/icons/loader-16.png +0 -0
  8. data/app/assets/images/icons/loader-24.png +0 -0
  9. data/app/assets/images/menu/alpha-bg-60.png +0 -0
  10. data/app/assets/images/menu/alpha-bg-75.png +0 -0
  11. data/app/assets/images/menu/alpha-bg-95.png +0 -0
  12. data/app/assets/images/menu/alpha-bg-99.png +0 -0
  13. data/app/assets/javascripts/ajax_callbacks_core/common.js.erb +83 -0
  14. data/app/assets/javascripts/ajax_callbacks_core/forms.js.erb +27 -0
  15. data/app/assets/javascripts/ajax_callbacks_core/helpers.js.erb +216 -0
  16. data/app/assets/javascripts/ajax_ext_core/colorpicker.js +484 -0
  17. data/app/assets/javascripts/ajax_ext_core/date.js.erb +335 -0
  18. data/app/assets/javascripts/ajax_ext_core/faye.js +2 -0
  19. data/app/assets/javascripts/ajax_ext_core/jquery-json.js +178 -0
  20. data/app/assets/javascripts/ajax_ext_core/jquery-ui-timepicker-addon.js +1923 -0
  21. data/app/assets/javascripts/ajax_ext_core/jquery.hash.js +203 -0
  22. data/app/assets/javascripts/ajax_ext_core/jquery.jsonSuggest.js +25 -0
  23. data/app/assets/javascripts/ajax_ext_core/jquery.mtz.monthpicker.js +271 -0
  24. data/app/assets/javascripts/ajax_ext_core/preload_images.js +56 -0
  25. data/app/assets/javascripts/ajax_ui_core/autocomplete.js.erb +26 -0
  26. data/app/assets/javascripts/ajax_ui_core/datepicker.js.erb +144 -0
  27. data/app/assets/javascripts/ajax_ui_core/friends_ui.js.erb +23 -0
  28. data/app/assets/javascripts/ajax_ui_core/overlay.js.erb +85 -0
  29. data/app/assets/javascripts/ajax_ui_core/slide-down.js +163 -0
  30. data/app/assets/javascripts/friends_ajax_core.js.erb +11 -0
  31. data/app/assets/javascripts/init_ajax_core.js.erb +22 -0
  32. data/app/controllers/friends_ajax_controller.rb +6 -0
  33. data/app/helpers/friends_ajax_helper.rb +176 -0
  34. data/app/views/layouts/_ajax_overlay.html.erb +5 -0
  35. data/app/views/layouts/_info_overlay.html.erb +9 -0
  36. data/app/views/layouts/_invisible_overlay.html.erb +10 -0
  37. data/app/views/layouts/_layout_defaults.html.erb +39 -0
  38. data/app/views/layouts/_overlay_js.html.erb +30 -0
  39. data/app/views/layouts/ajax_overlay.html.erb +5 -0
  40. data/app/views/layouts/info_overlay.html.erb +9 -0
  41. data/config/routes.rb +10 -0
  42. data/lib/friends_ajax_core.rb +117 -0
  43. data/lib/friends_ajax_core/version.rb +4 -0
  44. metadata +143 -0
@@ -0,0 +1,1923 @@
1
+ /*
2
+ * jQuery timepicker addon
3
+ * By: Trent Richardson [http://trentrichardson.com]
4
+ * Version 1.2
5
+ * Last Modified: 02/02/2013
6
+ *
7
+ * Copyright 2013 Trent Richardson
8
+ * You may use this project under MIT or GPL licenses.
9
+ * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt
10
+ * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt
11
+ */
12
+
13
+ /*jslint evil: true, white: false, undef: false, nomen: false */
14
+
15
+ (function($) {
16
+
17
+ /*
18
+ * Lets not redefine timepicker, Prevent "Uncaught RangeError: Maximum call stack size exceeded"
19
+ */
20
+ $.ui.timepicker = $.ui.timepicker || {};
21
+ if ($.ui.timepicker.version) {
22
+ return;
23
+ }
24
+
25
+ /*
26
+ * Extend jQueryUI, get it started with our version number
27
+ */
28
+ $.extend($.ui, {
29
+ timepicker: {
30
+ version: "1.2"
31
+ }
32
+ });
33
+
34
+ /*
35
+ * Timepicker manager.
36
+ * Use the singleton instance of this class, $.timepicker, to interact with the time picker.
37
+ * Settings for (groups of) time pickers are maintained in an instance object,
38
+ * allowing multiple different settings on the same page.
39
+ */
40
+ var Timepicker = function() {
41
+ this.regional = []; // Available regional settings, indexed by language code
42
+ this.regional[''] = { // Default regional settings
43
+ currentText: 'Now',
44
+ closeText: 'Done',
45
+ amNames: ['AM', 'A'],
46
+ pmNames: ['PM', 'P'],
47
+ timeFormat: 'HH:mm',
48
+ timeSuffix: '',
49
+ timeOnlyTitle: 'Choose Time',
50
+ timeText: 'Time',
51
+ hourText: 'Hour',
52
+ minuteText: 'Minute',
53
+ secondText: 'Second',
54
+ millisecText: 'Millisecond',
55
+ timezoneText: 'Time Zone',
56
+ isRTL: false
57
+ };
58
+ this._defaults = { // Global defaults for all the datetime picker instances
59
+ showButtonPanel: true,
60
+ timeOnly: false,
61
+ showHour: true,
62
+ showMinute: true,
63
+ showSecond: false,
64
+ showMillisec: false,
65
+ showTimezone: false,
66
+ showTime: true,
67
+ stepHour: 1,
68
+ stepMinute: 15,
69
+ stepSecond: 1,
70
+ stepMillisec: 1,
71
+ hour: 0,
72
+ minute: 0,
73
+ second: 0,
74
+ millisec: 0,
75
+ timezone: null,
76
+ useLocalTimezone: false,
77
+ defaultTimezone: "+0000",
78
+ hourMin: 0,
79
+ minuteMin: 0,
80
+ secondMin: 0,
81
+ millisecMin: 0,
82
+ hourMax: 23,
83
+ minuteMax: 59,
84
+ secondMax: 59,
85
+ millisecMax: 999,
86
+ minDateTime: null,
87
+ maxDateTime: null,
88
+ onSelect: null,
89
+ hourGrid: 0,
90
+ minuteGrid: 0,
91
+ secondGrid: 0,
92
+ millisecGrid: 0,
93
+ alwaysSetTime: true,
94
+ separator: ' ',
95
+ altFieldTimeOnly: true,
96
+ altTimeFormat: null,
97
+ altSeparator: null,
98
+ altTimeSuffix: null,
99
+ pickerTimeFormat: null,
100
+ pickerTimeSuffix: null,
101
+ showTimepicker: true,
102
+ timezoneIso8601: false,
103
+ timezoneList: null,
104
+ addSliderAccess: false,
105
+ sliderAccessArgs: null,
106
+ controlType: 'slider',
107
+ defaultValue: null,
108
+ parse: 'strict'
109
+ };
110
+ $.extend(this._defaults, this.regional['']);
111
+ };
112
+
113
+ $.extend(Timepicker.prototype, {
114
+ $input: null,
115
+ $altInput: null,
116
+ $timeObj: null,
117
+ inst: null,
118
+ hour_slider: null,
119
+ minute_slider: null,
120
+ second_slider: null,
121
+ millisec_slider: null,
122
+ timezone_select: null,
123
+ hour: 0,
124
+ minute: 0,
125
+ second: 0,
126
+ millisec: 0,
127
+ timezone: null,
128
+ defaultTimezone: "+0000",
129
+ hourMinOriginal: null,
130
+ minuteMinOriginal: null,
131
+ secondMinOriginal: null,
132
+ millisecMinOriginal: null,
133
+ hourMaxOriginal: null,
134
+ minuteMaxOriginal: null,
135
+ secondMaxOriginal: null,
136
+ millisecMaxOriginal: null,
137
+ ampm: '',
138
+ formattedDate: '',
139
+ formattedTime: '',
140
+ formattedDateTime: '',
141
+ timezoneList: null,
142
+ units: ['hour','minute','second','millisec'],
143
+ control: null,
144
+
145
+ /*
146
+ * Override the default settings for all instances of the time picker.
147
+ * @param settings object - the new settings to use as defaults (anonymous object)
148
+ * @return the manager object
149
+ */
150
+ setDefaults: function(settings) {
151
+ extendRemove(this._defaults, settings || {});
152
+ return this;
153
+ },
154
+
155
+ /*
156
+ * Create a new Timepicker instance
157
+ */
158
+ _newInst: function($input, o) {
159
+ var tp_inst = new Timepicker(),
160
+ inlineSettings = {},
161
+ fns = {},
162
+ overrides, i;
163
+
164
+ for (var attrName in this._defaults) {
165
+ if(this._defaults.hasOwnProperty(attrName)){
166
+ var attrValue = $input.attr('time:' + attrName);
167
+ if (attrValue) {
168
+ try {
169
+ inlineSettings[attrName] = eval(attrValue);
170
+ } catch (err) {
171
+ inlineSettings[attrName] = attrValue;
172
+ }
173
+ }
174
+ }
175
+ }
176
+ overrides = {
177
+ beforeShow: function (input, dp_inst) {
178
+ if ($.isFunction(tp_inst._defaults.evnts.beforeShow)) {
179
+ return tp_inst._defaults.evnts.beforeShow.call($input[0], input, dp_inst, tp_inst);
180
+ }
181
+ },
182
+ onChangeMonthYear: function (year, month, dp_inst) {
183
+ // Update the time as well : this prevents the time from disappearing from the $input field.
184
+ tp_inst._updateDateTime(dp_inst);
185
+ if ($.isFunction(tp_inst._defaults.evnts.onChangeMonthYear)) {
186
+ tp_inst._defaults.evnts.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst);
187
+ }
188
+ },
189
+ onClose: function (dateText, dp_inst) {
190
+ if (tp_inst.timeDefined === true && $input.val() !== '') {
191
+ tp_inst._updateDateTime(dp_inst);
192
+ }
193
+ if ($.isFunction(tp_inst._defaults.evnts.onClose)) {
194
+ tp_inst._defaults.evnts.onClose.call($input[0], dateText, dp_inst, tp_inst);
195
+ }
196
+ }
197
+ };
198
+ for (i in overrides) {
199
+ if (overrides.hasOwnProperty(i)) {
200
+ fns[i] = o[i] || null;
201
+ }
202
+ }
203
+ tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, overrides, {
204
+ evnts:fns,
205
+ timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
206
+ });
207
+ tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) {
208
+ return val.toUpperCase();
209
+ });
210
+ tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) {
211
+ return val.toUpperCase();
212
+ });
213
+
214
+ // controlType is string - key to our this._controls
215
+ if(typeof(tp_inst._defaults.controlType) === 'string'){
216
+ if($.fn[tp_inst._defaults.controlType] === undefined){
217
+ tp_inst._defaults.controlType = 'select';
218
+ }
219
+ tp_inst.control = tp_inst._controls[tp_inst._defaults.controlType];
220
+ }
221
+ // controlType is an object and must implement create, options, value methods
222
+ else{
223
+ tp_inst.control = tp_inst._defaults.controlType;
224
+ }
225
+
226
+ if (tp_inst._defaults.timezoneList === null) {
227
+ var timezoneList = ['-1200', '-1100', '-1000', '-0930', '-0900', '-0800', '-0700', '-0600', '-0500', '-0430', '-0400', '-0330', '-0300', '-0200', '-0100', '+0000',
228
+ '+0100', '+0200', '+0300', '+0330', '+0400', '+0430', '+0500', '+0530', '+0545', '+0600', '+0630', '+0700', '+0800', '+0845', '+0900', '+0930',
229
+ '+1000', '+1030', '+1100', '+1130', '+1200', '+1245', '+1300', '+1400'];
230
+
231
+ if (tp_inst._defaults.timezoneIso8601) {
232
+ timezoneList = $.map(timezoneList, function(val) {
233
+ return val == '+0000' ? 'Z' : (val.substring(0, 3) + ':' + val.substring(3));
234
+ });
235
+ }
236
+ tp_inst._defaults.timezoneList = timezoneList;
237
+ }
238
+
239
+ tp_inst.timezone = tp_inst._defaults.timezone;
240
+ tp_inst.hour = tp_inst._defaults.hour < tp_inst._defaults.hourMin? tp_inst._defaults.hourMin :
241
+ tp_inst._defaults.hour > tp_inst._defaults.hourMax? tp_inst._defaults.hourMax : tp_inst._defaults.hour;
242
+ tp_inst.minute = tp_inst._defaults.minute < tp_inst._defaults.minuteMin? tp_inst._defaults.minuteMin :
243
+ tp_inst._defaults.minute > tp_inst._defaults.minuteMax? tp_inst._defaults.minuteMax : tp_inst._defaults.minute;
244
+ tp_inst.second = tp_inst._defaults.second < tp_inst._defaults.secondMin? tp_inst._defaults.secondMin :
245
+ tp_inst._defaults.second > tp_inst._defaults.secondMax? tp_inst._defaults.secondMax : tp_inst._defaults.second;
246
+ tp_inst.millisec = tp_inst._defaults.millisec < tp_inst._defaults.millisecMin? tp_inst._defaults.millisecMin :
247
+ tp_inst._defaults.millisec > tp_inst._defaults.millisecMax? tp_inst._defaults.millisecMax : tp_inst._defaults.millisec;
248
+ tp_inst.ampm = '';
249
+ tp_inst.$input = $input;
250
+
251
+ if (o.altField) {
252
+ tp_inst.$altInput = $(o.altField).css({
253
+ cursor: 'pointer'
254
+ }).focus(function() {
255
+ $input.trigger("focus");
256
+ });
257
+ }
258
+
259
+ if (tp_inst._defaults.minDate === 0 || tp_inst._defaults.minDateTime === 0) {
260
+ tp_inst._defaults.minDate = new Date();
261
+ }
262
+ if (tp_inst._defaults.maxDate === 0 || tp_inst._defaults.maxDateTime === 0) {
263
+ tp_inst._defaults.maxDate = new Date();
264
+ }
265
+
266
+ // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime..
267
+ if (tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date) {
268
+ tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime());
269
+ }
270
+ if (tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date) {
271
+ tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime());
272
+ }
273
+ if (tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date) {
274
+ tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime());
275
+ }
276
+ if (tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date) {
277
+ tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime());
278
+ }
279
+ tp_inst.$input.bind('focus', function() {
280
+ tp_inst._onFocus();
281
+ });
282
+
283
+ return tp_inst;
284
+ },
285
+
286
+ /*
287
+ * add our sliders to the calendar
288
+ */
289
+ _addTimePicker: function(dp_inst) {
290
+ var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ? this.$input.val() + ' ' + this.$altInput.val() : this.$input.val();
291
+
292
+ this.timeDefined = this._parseTime(currDT);
293
+ this._limitMinMaxDateTime(dp_inst, false);
294
+ this._injectTimePicker();
295
+ },
296
+
297
+ /*
298
+ * parse the time string from input value or _setTime
299
+ */
300
+ _parseTime: function(timeString, withDate) {
301
+ if (!this.inst) {
302
+ this.inst = $.datepicker._getInst(this.$input[0]);
303
+ }
304
+
305
+ if (withDate || !this._defaults.timeOnly) {
306
+ var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat');
307
+ try {
308
+ var parseRes = parseDateTimeInternal(dp_dateFormat, this._defaults.timeFormat, timeString, $.datepicker._getFormatConfig(this.inst), this._defaults);
309
+ if (!parseRes.timeObj) {
310
+ return false;
311
+ }
312
+ $.extend(this, parseRes.timeObj);
313
+ } catch (err) {
314
+ $.timepicker.log("Error parsing the date/time string: " + err +
315
+ "\ndate/time string = " + timeString +
316
+ "\ntimeFormat = " + this._defaults.timeFormat +
317
+ "\ndateFormat = " + dp_dateFormat);
318
+ return false;
319
+ }
320
+ return true;
321
+ } else {
322
+ var timeObj = $.datepicker.parseTime(this._defaults.timeFormat, timeString, this._defaults);
323
+ if (!timeObj) {
324
+ return false;
325
+ }
326
+ $.extend(this, timeObj);
327
+ return true;
328
+ }
329
+ },
330
+
331
+ /*
332
+ * generate and inject html for timepicker into ui datepicker
333
+ */
334
+ _injectTimePicker: function() {
335
+ var $dp = this.inst.dpDiv,
336
+ o = this.inst.settings,
337
+ tp_inst = this,
338
+ litem = '',
339
+ uitem = '',
340
+ max = {},
341
+ gridSize = {},
342
+ size = null;
343
+
344
+ // Prevent displaying twice
345
+ if ($dp.find("div.ui-timepicker-div").length === 0 && o.showTimepicker) {
346
+ var noDisplay = ' style="display:none;"',
347
+ html = '<div class="ui-timepicker-div cf'+ (o.isRTL? ' ui-timepicker-rtl' : '') +'"><ul>' + '<li class="ui_tpicker_time_label"' + ((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</li>' +
348
+ '<li class="ui_tpicker_time"' + ((o.showTime) ? '' : noDisplay) + '></li>';
349
+
350
+ // Create the markup
351
+ for(var i=0,l=this.units.length; i<l; i++){
352
+ litem = this.units[i];
353
+ uitem = litem.substr(0,1).toUpperCase() + litem.substr(1);
354
+ // Added by Peter Medeiros:
355
+ // - Figure out what the hour/minute/second max should be based on the step values.
356
+ // - Example: if stepMinute is 15, then minMax is 45.
357
+ max[litem] = parseInt((o[litem+'Max'] - ((o[litem+'Max'] - o[litem+'Min']) % o['step'+uitem])), 10);
358
+ gridSize[litem] = 0;
359
+
360
+ html += '<li class="ui_tpicker_'+ litem +'">' + o[litem +'Text'] + '<div class="ui_tpicker_'+ litem +'_slider"' + ((o['show'+uitem]) ? '' : noDisplay) + '></div>';
361
+
362
+ if (o['show'+uitem] && o[litem+'Grid'] > 0) {
363
+ html += '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>';
364
+
365
+ if(litem == 'hour'){
366
+ for (var h = o[litem+'Min']; h <= max[litem]; h += parseInt(o[litem+'Grid'], 10)) {
367
+ gridSize[litem]++;
368
+ var tmph = $.datepicker.formatTime(useAmpm(o.pickerTimeFormat || o.timeFormat)? 'hht':'HH', {hour:h}, o);
369
+ html += '<td data-for="'+litem+'">' + tmph + '</td>';
370
+ }
371
+ }
372
+ else{
373
+ for (var m = o[litem+'Min']; m <= max[litem]; m += parseInt(o[litem+'Grid'], 10)) {
374
+ gridSize[litem]++;
375
+ html += '<td data-for="'+litem+'">' + ((m < 10) ? '0' : '') + m + '</td>';
376
+ }
377
+ }
378
+
379
+ html += '</tr></table></div>';
380
+ }
381
+ html += '</li>';
382
+ }
383
+
384
+ // Timezone
385
+ html += '<li class="ui_tpicker_timezone_label"' + ((o.showTimezone) ? '' : noDisplay) + '>' + o.timezoneText + '</li>';
386
+ html += '<li class="ui_tpicker_timezone" ' + ((o.showTimezone) ? '' : noDisplay) + '></li>';
387
+
388
+ // Create the elements from string
389
+ html += '</ul></div>';
390
+ var $tp = $(html);
391
+
392
+ // if we only want time picker...
393
+ if (o.timeOnly === true) {
394
+ $tp.prepend('<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' + '<div class="ui-datepicker-title">' + o.timeOnlyTitle + '</div>' + '</div>');
395
+ $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide();
396
+ }
397
+
398
+ // add sliders, adjust grids, add events
399
+ for(var i=0,l=tp_inst.units.length; i<l; i++){
400
+ litem = tp_inst.units[i];
401
+ uitem = litem.substr(0,1).toUpperCase() + litem.substr(1);
402
+
403
+ // add the slider
404
+ tp_inst[litem+'_slider'] = tp_inst.control.create(tp_inst, $tp.find('.ui_tpicker_'+litem+'_slider'), litem, tp_inst[litem], o[litem+'Min'], max[litem], o['step'+uitem]);
405
+
406
+ // adjust the grid and add click event
407
+ if (o['show'+uitem] && o[litem+'Grid'] > 0) {
408
+ size = 100 * gridSize[litem] * o[litem+'Grid'] / (max[litem] - o[litem+'Min']);
409
+ $tp.find('.ui_tpicker_'+litem+' table').css({
410
+ width: size + "%",
411
+ marginLeft: o.isRTL? '0' : ((size / (-2 * gridSize[litem])) + "%"),
412
+ marginRight: o.isRTL? ((size / (-2 * gridSize[litem])) + "%") : '0',
413
+ borderCollapse: 'collapse'
414
+ }).find("td").click(function(e){
415
+ var $t = $(this),
416
+ h = $t.html(),
417
+ n = parseInt(h.replace(/[^0-9]/g),10),
418
+ ap = h.replace(/[^apm]/ig),
419
+ f = $t.data('for'); // loses scope, so we use data-for
420
+
421
+ if(f == 'hour'){
422
+ if(ap.indexOf('p') !== -1 && n < 12){
423
+ n += 12;
424
+ }
425
+ else{
426
+ if(ap.indexOf('a') !== -1 && n === 12){
427
+ n = 0;
428
+ }
429
+ }
430
+ }
431
+
432
+ tp_inst.control.value(tp_inst, tp_inst[f+'_slider'], litem, n);
433
+
434
+ tp_inst._onTimeChange();
435
+ tp_inst._onSelectHandler();
436
+ })
437
+ .css({
438
+ cursor: 'pointer',
439
+ width: (100 / gridSize[litem]) + '%',
440
+ textAlign: 'center',
441
+ overflow: 'hidden'
442
+ });
443
+ } // end if grid > 0
444
+ } // end for loop
445
+
446
+ // Add timezone options
447
+ this.timezone_select = $tp.find('.ui_tpicker_timezone').append('<select></select>').find("select");
448
+ $.fn.append.apply(this.timezone_select,
449
+ $.map(o.timezoneList, function(val, idx) {
450
+ return $("<option />").val(typeof val == "object" ? val.value : val).text(typeof val == "object" ? val.label : val);
451
+ }));
452
+ if (typeof(this.timezone) != "undefined" && this.timezone !== null && this.timezone !== "") {
453
+ var local_date = new Date(this.inst.selectedYear, this.inst.selectedMonth, this.inst.selectedDay, 12);
454
+ var local_timezone = $.timepicker.timeZoneOffsetString(local_date);
455
+ if (local_timezone == this.timezone) {
456
+ selectLocalTimeZone(tp_inst);
457
+ } else {
458
+ this.timezone_select.val(this.timezone);
459
+ }
460
+ } else {
461
+ if (typeof(this.hour) != "undefined" && this.hour !== null && this.hour !== "") {
462
+ this.timezone_select.val(o.defaultTimezone);
463
+ } else {
464
+ selectLocalTimeZone(tp_inst);
465
+ }
466
+ }
467
+ this.timezone_select.change(function() {
468
+ tp_inst._defaults.useLocalTimezone = false;
469
+ tp_inst._onTimeChange();
470
+ tp_inst._onSelectHandler();
471
+ });
472
+ // End timezone options
473
+
474
+ // inject timepicker into datepicker
475
+ var $buttonPanel = $dp.find('.ui-datepicker-buttonpane');
476
+ if ($buttonPanel.length) {
477
+ $buttonPanel.before($tp);
478
+ } else {
479
+ $dp.append($tp);
480
+ }
481
+
482
+ this.$timeObj = $tp.find('.ui_tpicker_time');
483
+
484
+ if (this.inst !== null) {
485
+ var timeDefined = this.timeDefined;
486
+ this._onTimeChange();
487
+ this.timeDefined = timeDefined;
488
+ }
489
+
490
+ // slideAccess integration: http://trentrichardson.com/2011/11/11/jquery-ui-sliders-and-touch-accessibility/
491
+ if (this._defaults.addSliderAccess) {
492
+ var sliderAccessArgs = this._defaults.sliderAccessArgs,
493
+ rtl = this._defaults.isRTL;
494
+ sliderAccessArgs.isRTL = rtl;
495
+
496
+ setTimeout(function() { // fix for inline mode
497
+ if ($tp.find('.ui-slider-access').length === 0) {
498
+ $tp.find('.ui-slider:visible').sliderAccess(sliderAccessArgs);
499
+
500
+ // fix any grids since sliders are shorter
501
+ var sliderAccessWidth = $tp.find('.ui-slider-access:eq(0)').outerWidth(true);
502
+ if (sliderAccessWidth) {
503
+ $tp.find('table:visible').each(function() {
504
+ var $g = $(this),
505
+ oldWidth = $g.outerWidth(),
506
+ oldMarginLeft = $g.css(rtl? 'marginRight':'marginLeft').toString().replace('%', ''),
507
+ newWidth = oldWidth - sliderAccessWidth,
508
+ newMarginLeft = ((oldMarginLeft * newWidth) / oldWidth) + '%',
509
+ css = { width: newWidth, marginRight: 0, marginLeft: 0 };
510
+ css[rtl? 'marginRight':'marginLeft'] = newMarginLeft;
511
+ $g.css(css);
512
+ });
513
+ }
514
+ }
515
+ }, 10);
516
+ }
517
+ // end slideAccess integration
518
+
519
+ }
520
+ },
521
+
522
+ /*
523
+ * This function tries to limit the ability to go outside the
524
+ * min/max date range
525
+ */
526
+ _limitMinMaxDateTime: function(dp_inst, adjustSliders) {
527
+ var o = this._defaults,
528
+ dp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay);
529
+
530
+ if (!this._defaults.showTimepicker) {
531
+ return;
532
+ } // No time so nothing to check here
533
+
534
+ if ($.datepicker._get(dp_inst, 'minDateTime') !== null && $.datepicker._get(dp_inst, 'minDateTime') !== undefined && dp_date) {
535
+ var minDateTime = $.datepicker._get(dp_inst, 'minDateTime'),
536
+ minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0);
537
+
538
+ if (this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null || this.millisecMinOriginal === null) {
539
+ this.hourMinOriginal = o.hourMin;
540
+ this.minuteMinOriginal = o.minuteMin;
541
+ this.secondMinOriginal = o.secondMin;
542
+ this.millisecMinOriginal = o.millisecMin;
543
+ }
544
+
545
+ if (dp_inst.settings.timeOnly || minDateTimeDate.getTime() == dp_date.getTime()) {
546
+ this._defaults.hourMin = minDateTime.getHours();
547
+ if (this.hour <= this._defaults.hourMin) {
548
+ this.hour = this._defaults.hourMin;
549
+ this._defaults.minuteMin = minDateTime.getMinutes();
550
+ if (this.minute <= this._defaults.minuteMin) {
551
+ this.minute = this._defaults.minuteMin;
552
+ this._defaults.secondMin = minDateTime.getSeconds();
553
+ if (this.second <= this._defaults.secondMin) {
554
+ this.second = this._defaults.secondMin;
555
+ this._defaults.millisecMin = minDateTime.getMilliseconds();
556
+ } else {
557
+ if (this.millisec < this._defaults.millisecMin) {
558
+ this.millisec = this._defaults.millisecMin;
559
+ }
560
+ this._defaults.millisecMin = this.millisecMinOriginal;
561
+ }
562
+ } else {
563
+ this._defaults.secondMin = this.secondMinOriginal;
564
+ this._defaults.millisecMin = this.millisecMinOriginal;
565
+ }
566
+ } else {
567
+ this._defaults.minuteMin = this.minuteMinOriginal;
568
+ this._defaults.secondMin = this.secondMinOriginal;
569
+ this._defaults.millisecMin = this.millisecMinOriginal;
570
+ }
571
+ } else {
572
+ this._defaults.hourMin = this.hourMinOriginal;
573
+ this._defaults.minuteMin = this.minuteMinOriginal;
574
+ this._defaults.secondMin = this.secondMinOriginal;
575
+ this._defaults.millisecMin = this.millisecMinOriginal;
576
+ }
577
+ }
578
+
579
+ if ($.datepicker._get(dp_inst, 'maxDateTime') !== null && $.datepicker._get(dp_inst, 'maxDateTime') !== undefined && dp_date) {
580
+ var maxDateTime = $.datepicker._get(dp_inst, 'maxDateTime'),
581
+ maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0);
582
+
583
+ if (this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null) {
584
+ this.hourMaxOriginal = o.hourMax;
585
+ this.minuteMaxOriginal = o.minuteMax;
586
+ this.secondMaxOriginal = o.secondMax;
587
+ this.millisecMaxOriginal = o.millisecMax;
588
+ }
589
+
590
+ if (dp_inst.settings.timeOnly || maxDateTimeDate.getTime() == dp_date.getTime()) {
591
+ this._defaults.hourMax = maxDateTime.getHours();
592
+ if (this.hour >= this._defaults.hourMax) {
593
+ this.hour = this._defaults.hourMax;
594
+ this._defaults.minuteMax = maxDateTime.getMinutes();
595
+ if (this.minute >= this._defaults.minuteMax) {
596
+ this.minute = this._defaults.minuteMax;
597
+ this._defaults.secondMax = maxDateTime.getSeconds();
598
+ if (this.second >= this._defaults.secondMax) {
599
+ this.second = this._defaults.secondMax;
600
+ this._defaults.millisecMax = maxDateTime.getMilliseconds();
601
+ } else {
602
+ if (this.millisec > this._defaults.millisecMax) {
603
+ this.millisec = this._defaults.millisecMax;
604
+ }
605
+ this._defaults.millisecMax = this.millisecMaxOriginal;
606
+ }
607
+ } else {
608
+ this._defaults.secondMax = this.secondMaxOriginal;
609
+ this._defaults.millisecMax = this.millisecMaxOriginal;
610
+ }
611
+ } else {
612
+ this._defaults.minuteMax = this.minuteMaxOriginal;
613
+ this._defaults.secondMax = this.secondMaxOriginal;
614
+ this._defaults.millisecMax = this.millisecMaxOriginal;
615
+ }
616
+ } else {
617
+ this._defaults.hourMax = this.hourMaxOriginal;
618
+ this._defaults.minuteMax = this.minuteMaxOriginal;
619
+ this._defaults.secondMax = this.secondMaxOriginal;
620
+ this._defaults.millisecMax = this.millisecMaxOriginal;
621
+ }
622
+ }
623
+
624
+ if (adjustSliders !== undefined && adjustSliders === true) {
625
+ var hourMax = parseInt((this._defaults.hourMax - ((this._defaults.hourMax - this._defaults.hourMin) % this._defaults.stepHour)), 10),
626
+ minMax = parseInt((this._defaults.minuteMax - ((this._defaults.minuteMax - this._defaults.minuteMin) % this._defaults.stepMinute)), 10),
627
+ secMax = parseInt((this._defaults.secondMax - ((this._defaults.secondMax - this._defaults.secondMin) % this._defaults.stepSecond)), 10),
628
+ millisecMax = parseInt((this._defaults.millisecMax - ((this._defaults.millisecMax - this._defaults.millisecMin) % this._defaults.stepMillisec)), 10);
629
+
630
+ if (this.hour_slider) {
631
+ this.control.options(this, this.hour_slider, 'hour', { min: this._defaults.hourMin, max: hourMax });
632
+ this.control.value(this, this.hour_slider, 'hour', this.hour - (this.hour % this._defaults.stepHour));
633
+ }
634
+ if (this.minute_slider) {
635
+ this.control.options(this, this.minute_slider, 'minute', { min: this._defaults.minuteMin, max: minMax });
636
+ this.control.value(this, this.minute_slider, 'minute', this.minute - (this.minute % this._defaults.stepMinute));
637
+ }
638
+ if (this.second_slider) {
639
+ this.control.options(this, this.second_slider, 'second', { min: this._defaults.secondMin, max: secMax });
640
+ this.control.value(this, this.second_slider, 'second', this.second - (this.second % this._defaults.stepSecond));
641
+ }
642
+ if (this.millisec_slider) {
643
+ this.control.options(this, this.millisec_slider, 'millisec', { min: this._defaults.millisecMin, max: millisecMax });
644
+ this.control.value(this, this.millisec_slider, 'millisec', this.millisec - (this.millisec % this._defaults.stepMillisec));
645
+ }
646
+ }
647
+
648
+ },
649
+
650
+ /*
651
+ * when a slider moves, set the internal time...
652
+ * on time change is also called when the time is updated in the text field
653
+ */
654
+ _onTimeChange: function() {
655
+ var hour = (this.hour_slider) ? this.control.value(this, this.hour_slider, 'hour') : false,
656
+ minute = (this.minute_slider) ? this.control.value(this, this.minute_slider, 'minute') : false,
657
+ second = (this.second_slider) ? this.control.value(this, this.second_slider, 'second') : false,
658
+ millisec = (this.millisec_slider) ? this.control.value(this, this.millisec_slider, 'millisec') : false,
659
+ timezone = (this.timezone_select) ? this.timezone_select.val() : false,
660
+ o = this._defaults,
661
+ pickerTimeFormat = o.pickerTimeFormat || o.timeFormat,
662
+ pickerTimeSuffix = o.pickerTimeSuffix || o.timeSuffix;
663
+
664
+ if (typeof(hour) == 'object') {
665
+ hour = false;
666
+ }
667
+ if (typeof(minute) == 'object') {
668
+ minute = false;
669
+ }
670
+ if (typeof(second) == 'object') {
671
+ second = false;
672
+ }
673
+ if (typeof(millisec) == 'object') {
674
+ millisec = false;
675
+ }
676
+ if (typeof(timezone) == 'object') {
677
+ timezone = false;
678
+ }
679
+
680
+ if (hour !== false) {
681
+ hour = parseInt(hour, 10);
682
+ }
683
+ if (minute !== false) {
684
+ minute = parseInt(minute, 10);
685
+ }
686
+ if (second !== false) {
687
+ second = parseInt(second, 10);
688
+ }
689
+ if (millisec !== false) {
690
+ millisec = parseInt(millisec, 10);
691
+ }
692
+
693
+ var ampm = o[hour < 12 ? 'amNames' : 'pmNames'][0];
694
+
695
+ // If the update was done in the input field, the input field should not be updated.
696
+ // If the update was done using the sliders, update the input field.
697
+ var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || millisec != this.millisec
698
+ || (this.ampm.length > 0 && (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1))
699
+ || ((this.timezone === null && timezone != this.defaultTimezone) || (this.timezone !== null && timezone != this.timezone)));
700
+
701
+ if (hasChanged) {
702
+
703
+ if (hour !== false) {
704
+ this.hour = hour;
705
+ }
706
+ if (minute !== false) {
707
+ this.minute = minute;
708
+ }
709
+ if (second !== false) {
710
+ this.second = second;
711
+ }
712
+ if (millisec !== false) {
713
+ this.millisec = millisec;
714
+ }
715
+ if (timezone !== false) {
716
+ this.timezone = timezone;
717
+ }
718
+
719
+ if (!this.inst) {
720
+ this.inst = $.datepicker._getInst(this.$input[0]);
721
+ }
722
+
723
+ this._limitMinMaxDateTime(this.inst, true);
724
+ }
725
+ if (useAmpm(o.timeFormat)) {
726
+ this.ampm = ampm;
727
+ }
728
+
729
+ // Updates the time within the timepicker
730
+ this.formattedTime = $.datepicker.formatTime(o.timeFormat, this, o);
731
+ if (this.$timeObj) {
732
+ if(pickerTimeFormat === o.timeFormat){
733
+ this.$timeObj.text(this.formattedTime + pickerTimeSuffix);
734
+ }
735
+ else{
736
+ this.$timeObj.text($.datepicker.formatTime(pickerTimeFormat, this, o) + pickerTimeSuffix);
737
+ }
738
+ }
739
+
740
+ this.timeDefined = true;
741
+ if (hasChanged) {
742
+ this._updateDateTime();
743
+ }
744
+ },
745
+
746
+ /*
747
+ * call custom onSelect.
748
+ * bind to sliders slidestop, and grid click.
749
+ */
750
+ _onSelectHandler: function() {
751
+ var onSelect = this._defaults.onSelect || this.inst.settings.onSelect;
752
+ var inputEl = this.$input ? this.$input[0] : null;
753
+ if (onSelect && inputEl) {
754
+ onSelect.apply(inputEl, [this.formattedDateTime, this]);
755
+ }
756
+ },
757
+
758
+ /*
759
+ * update our input with the new date time..
760
+ */
761
+ _updateDateTime: function(dp_inst) {
762
+ dp_inst = this.inst || dp_inst;
763
+ var dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)),
764
+ dateFmt = $.datepicker._get(dp_inst, 'dateFormat'),
765
+ formatCfg = $.datepicker._getFormatConfig(dp_inst),
766
+ timeAvailable = dt !== null && this.timeDefined;
767
+ this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg);
768
+ var formattedDateTime = this.formattedDate;
769
+
770
+ // if a slider was changed but datepicker doesn't have a value yet, set it
771
+ if(dp_inst.lastVal==""){
772
+ dp_inst.currentYear=dp_inst.selectedYear;
773
+ dp_inst.currentMonth=dp_inst.selectedMonth;
774
+ dp_inst.currentDay=dp_inst.selectedDay;
775
+ }
776
+
777
+ /*
778
+ * remove following lines to force every changes in date picker to change the input value
779
+ * Bug descriptions: when an input field has a default value, and click on the field to pop up the date picker.
780
+ * If the user manually empty the value in the input field, the date picker will never change selected value.
781
+ */
782
+ //if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0)) {
783
+ // return;
784
+ //}
785
+
786
+ if (this._defaults.timeOnly === true) {
787
+ formattedDateTime = this.formattedTime;
788
+ } else if (this._defaults.timeOnly !== true && (this._defaults.alwaysSetTime || timeAvailable)) {
789
+ formattedDateTime += this._defaults.separator + this.formattedTime + this._defaults.timeSuffix;
790
+ }
791
+
792
+ this.formattedDateTime = formattedDateTime;
793
+
794
+ if (!this._defaults.showTimepicker) {
795
+ this.$input.val(this.formattedDate);
796
+ } else if (this.$altInput && this._defaults.altFieldTimeOnly === true) {
797
+ this.$altInput.val(this.formattedTime);
798
+ this.$input.val(this.formattedDate);
799
+ } else if (this.$altInput) {
800
+ this.$input.val(formattedDateTime);
801
+ var altFormattedDateTime = '',
802
+ altSeparator = this._defaults.altSeparator ? this._defaults.altSeparator : this._defaults.separator,
803
+ altTimeSuffix = this._defaults.altTimeSuffix ? this._defaults.altTimeSuffix : this._defaults.timeSuffix;
804
+
805
+ if (this._defaults.altFormat) altFormattedDateTime = $.datepicker.formatDate(this._defaults.altFormat, (dt === null ? new Date() : dt), formatCfg);
806
+ else altFormattedDateTime = this.formattedDate;
807
+ if (altFormattedDateTime) altFormattedDateTime += altSeparator;
808
+ if (this._defaults.altTimeFormat) altFormattedDateTime += $.datepicker.formatTime(this._defaults.altTimeFormat, this, this._defaults) + altTimeSuffix;
809
+ else altFormattedDateTime += this.formattedTime + altTimeSuffix;
810
+ this.$altInput.val(altFormattedDateTime);
811
+ } else {
812
+ this.$input.val(formattedDateTime);
813
+ }
814
+
815
+ this.$input.trigger("change");
816
+ },
817
+
818
+ _onFocus: function() {
819
+ if (!this.$input.val() && this._defaults.defaultValue) {
820
+ this.$input.val(this._defaults.defaultValue);
821
+ var inst = $.datepicker._getInst(this.$input.get(0)),
822
+ tp_inst = $.datepicker._get(inst, 'timepicker');
823
+ if (tp_inst) {
824
+ if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) {
825
+ try {
826
+ $.datepicker._updateDatepicker(inst);
827
+ } catch (err) {
828
+ $.timepicker.log(err);
829
+ }
830
+ }
831
+ }
832
+ }
833
+ },
834
+
835
+ /*
836
+ * Small abstraction to control types
837
+ * We can add more, just be sure to follow the pattern: create, options, value
838
+ */
839
+ _controls: {
840
+ // slider methods
841
+ slider: {
842
+ create: function(tp_inst, obj, unit, val, min, max, step){
843
+ var rtl = tp_inst._defaults.isRTL; // if rtl go -60->0 instead of 0->60
844
+ return obj.prop('slide', null).slider({
845
+ orientation: "horizontal",
846
+ value: rtl? val*-1 : val,
847
+ min: rtl? max*-1 : min,
848
+ max: rtl? min*-1 : max,
849
+ step: step,
850
+ slide: function(event, ui) {
851
+ tp_inst.control.value(tp_inst, $(this), unit, rtl? ui.value*-1:ui.value);
852
+ tp_inst._onTimeChange();
853
+ },
854
+ stop: function(event, ui) {
855
+ tp_inst._onSelectHandler();
856
+ }
857
+ });
858
+ },
859
+ options: function(tp_inst, obj, unit, opts, val){
860
+ if(tp_inst._defaults.isRTL){
861
+ if(typeof(opts) == 'string'){
862
+ if(opts == 'min' || opts == 'max'){
863
+ if(val !== undefined)
864
+ return obj.slider(opts, val*-1);
865
+ return Math.abs(obj.slider(opts));
866
+ }
867
+ return obj.slider(opts);
868
+ }
869
+ var min = opts.min,
870
+ max = opts.max;
871
+ opts.min = opts.max = null;
872
+ if(min !== undefined)
873
+ opts.max = min * -1;
874
+ if(max !== undefined)
875
+ opts.min = max * -1;
876
+ return obj.slider(opts);
877
+ }
878
+ if(typeof(opts) == 'string' && val !== undefined)
879
+ return obj.slider(opts, val);
880
+ return obj.slider(opts);
881
+ },
882
+ value: function(tp_inst, obj, unit, val){
883
+ if(tp_inst._defaults.isRTL){
884
+ if(val !== undefined)
885
+ return obj.slider('value', val*-1);
886
+ return Math.abs(obj.slider('value'));
887
+ }
888
+ if(val !== undefined)
889
+ return obj.slider('value', val);
890
+ return obj.slider('value');
891
+ }
892
+ },
893
+ // select methods
894
+ select: {
895
+ create: function(tp_inst, obj, unit, val, min, max, step){
896
+
897
+ if(unit == 'minute'){
898
+ min = 0; max = 45; step = 15;
899
+ }
900
+
901
+ var sel = '<select class="ui-timepicker-select" data-unit="'+ unit +'" data-min='+ min +' data-max="'+ max +'" data-step="'+ step +'">',
902
+ ul = tp_inst._defaults.timeFormat.indexOf('t') !== -1? 'toLowerCase':'toUpperCase',
903
+ m = 0;
904
+
905
+ for(var i=min; i<=max; i+=step){
906
+ sel += '<option value="'+ i +'"'+ (i==val? ' selected':'') +'>';
907
+ if(unit == 'hour' && useAmpm(tp_inst._defaults.pickerTimeFormat || tp_inst._defaults.timeFormat))
908
+ sel += $.datepicker.formatTime("hh TT", {hour:i}, tp_inst._defaults);
909
+ else if(unit == 'millisec' || i >= 10) sel += i;
910
+ else sel += '0'+ i.toString();
911
+ sel += '</option>';
912
+ }
913
+ sel += '</select>';
914
+
915
+ obj.children('select').remove();
916
+
917
+ $(sel).appendTo(obj).change(function(e){
918
+ tp_inst._onTimeChange();
919
+ tp_inst._onSelectHandler();
920
+ });
921
+
922
+ return obj;
923
+ },
924
+ options: function(tp_inst, obj, unit, opts, val){
925
+ var o = {},
926
+ $t = obj.children('select');
927
+ if(typeof(opts) == 'string'){
928
+ if(val === undefined)
929
+ return $t.data(opts);
930
+ o[opts] = val;
931
+ }
932
+ else o = opts;
933
+ return tp_inst.control.create(tp_inst, obj, $t.data('unit'), $t.val(), o.min || $t.data('min'), o.max || $t.data('max'), o.step || $t.data('step'));
934
+ },
935
+ value: function(tp_inst, obj, unit, val){
936
+ var $t = obj.children('select');
937
+ if(val !== undefined)
938
+ return $t.val(val);
939
+ return $t.val();
940
+ }
941
+ }
942
+ } // end _controls
943
+
944
+ });
945
+
946
+ $.fn.extend({
947
+ /*
948
+ * shorthand just to use timepicker..
949
+ */
950
+ timepicker: function(o) {
951
+ o = o || {};
952
+ var tmp_args = Array.prototype.slice.call(arguments);
953
+
954
+ if (typeof o == 'object') {
955
+ tmp_args[0] = $.extend(o, {
956
+ timeOnly: true
957
+ });
958
+ }
959
+
960
+ return $(this).each(function() {
961
+ $.fn.datetimepicker.apply($(this), tmp_args);
962
+ });
963
+ },
964
+
965
+ /*
966
+ * extend timepicker to datepicker
967
+ */
968
+ datetimepicker: function(o) {
969
+ o = o || {};
970
+ var tmp_args = arguments;
971
+
972
+ if (typeof(o) == 'string') {
973
+ if (o == 'getDate') {
974
+ return $.fn.datepicker.apply($(this[0]), tmp_args);
975
+ } else {
976
+ return this.each(function() {
977
+ var $t = $(this);
978
+ $t.datepicker.apply($t, tmp_args);
979
+ });
980
+ }
981
+ } else {
982
+ return this.each(function() {
983
+ var $t = $(this);
984
+ $t.datepicker($.timepicker._newInst($t, o)._defaults);
985
+ });
986
+ }
987
+ }
988
+ });
989
+
990
+ /*
991
+ * Public Utility to parse date and time
992
+ */
993
+ $.datepicker.parseDateTime = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) {
994
+ var parseRes = parseDateTimeInternal(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings);
995
+ if (parseRes.timeObj) {
996
+ var t = parseRes.timeObj;
997
+ parseRes.date.setHours(t.hour, t.minute, t.second, t.millisec);
998
+ }
999
+
1000
+ return parseRes.date;
1001
+ };
1002
+
1003
+ /*
1004
+ * Public utility to parse time
1005
+ */
1006
+ $.datepicker.parseTime = function(timeFormat, timeString, options) {
1007
+ var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {});
1008
+
1009
+ // Strict parse requires the timeString to match the timeFormat exactly
1010
+ var strictParse = function(f, s, o){
1011
+
1012
+ // pattern for standard and localized AM/PM markers
1013
+ var getPatternAmpm = function(amNames, pmNames) {
1014
+ var markers = [];
1015
+ if (amNames) {
1016
+ $.merge(markers, amNames);
1017
+ }
1018
+ if (pmNames) {
1019
+ $.merge(markers, pmNames);
1020
+ }
1021
+ markers = $.map(markers, function(val) {
1022
+ return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&');
1023
+ });
1024
+ return '(' + markers.join('|') + ')?';
1025
+ };
1026
+
1027
+ // figure out position of time elements.. cause js cant do named captures
1028
+ var getFormatPositions = function(timeFormat) {
1029
+ var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z|'.*?')/g),
1030
+ orders = {
1031
+ h: -1,
1032
+ m: -1,
1033
+ s: -1,
1034
+ l: -1,
1035
+ t: -1,
1036
+ z: -1
1037
+ };
1038
+
1039
+ if (finds) {
1040
+ for (var i = 0; i < finds.length; i++) {
1041
+ if (orders[finds[i].toString().charAt(0)] == -1) {
1042
+ orders[finds[i].toString().charAt(0)] = i + 1;
1043
+ }
1044
+ }
1045
+ }
1046
+ return orders;
1047
+ };
1048
+
1049
+ var regstr = '^' + f.toString()
1050
+ .replace(/([hH]{1,2}|mm?|ss?|[tT]{1,2}|[lz]|'.*?')/g, function (match) {
1051
+ var ml = match.length;
1052
+ switch (match.charAt(0).toLowerCase()) {
1053
+ case 'h': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})';
1054
+ case 'm': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})';
1055
+ case 's': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})';
1056
+ case 'l': return '(\\d?\\d?\\d)';
1057
+ case 'z': return '(z|[-+]\\d\\d:?\\d\\d|\\S+)?';
1058
+ case 't': return getPatternAmpm(o.amNames, o.pmNames);
1059
+ default: // literal escaped in quotes
1060
+ return '(' + match.replace(/\'/g, "").replace(/(\.|\$|\^|\\|\/|\(|\)|\[|\]|\?|\+|\*)/g, function (m) { return "\\" + m; }) + ')?';
1061
+ }
1062
+ })
1063
+ .replace(/\s/g, '\\s?') +
1064
+ o.timeSuffix + '$',
1065
+ order = getFormatPositions(f),
1066
+ ampm = '',
1067
+ treg;
1068
+
1069
+ treg = s.match(new RegExp(regstr, 'i'));
1070
+
1071
+ var resTime = {
1072
+ hour: 0,
1073
+ minute: 0,
1074
+ second: 0,
1075
+ millisec: 0
1076
+ };
1077
+
1078
+ if (treg) {
1079
+ if (order.t !== -1) {
1080
+ if (treg[order.t] === undefined || treg[order.t].length === 0) {
1081
+ ampm = '';
1082
+ resTime.ampm = '';
1083
+ } else {
1084
+ ampm = $.inArray(treg[order.t].toUpperCase(), o.amNames) !== -1 ? 'AM' : 'PM';
1085
+ resTime.ampm = o[ampm == 'AM' ? 'amNames' : 'pmNames'][0];
1086
+ }
1087
+ }
1088
+
1089
+ if (order.h !== -1) {
1090
+ if (ampm == 'AM' && treg[order.h] == '12') {
1091
+ resTime.hour = 0; // 12am = 0 hour
1092
+ } else {
1093
+ if (ampm == 'PM' && treg[order.h] != '12') {
1094
+ resTime.hour = parseInt(treg[order.h], 10) + 12; // 12pm = 12 hour, any other pm = hour + 12
1095
+ } else {
1096
+ resTime.hour = Number(treg[order.h]);
1097
+ }
1098
+ }
1099
+ }
1100
+
1101
+ if (order.m !== -1) {
1102
+ resTime.minute = Number(treg[order.m]);
1103
+ }
1104
+ if (order.s !== -1) {
1105
+ resTime.second = Number(treg[order.s]);
1106
+ }
1107
+ if (order.l !== -1) {
1108
+ resTime.millisec = Number(treg[order.l]);
1109
+ }
1110
+ if (order.z !== -1 && treg[order.z] !== undefined) {
1111
+ var tz = treg[order.z].toUpperCase();
1112
+ switch (tz.length) {
1113
+ case 1:
1114
+ // Z
1115
+ tz = o.timezoneIso8601 ? 'Z' : '+0000';
1116
+ break;
1117
+ case 5:
1118
+ // +hhmm
1119
+ if (o.timezoneIso8601) {
1120
+ tz = tz.substring(1) == '0000' ? 'Z' : tz.substring(0, 3) + ':' + tz.substring(3);
1121
+ }
1122
+ break;
1123
+ case 6:
1124
+ // +hh:mm
1125
+ if (!o.timezoneIso8601) {
1126
+ tz = tz == 'Z' || tz.substring(1) == '00:00' ? '+0000' : tz.replace(/:/, '');
1127
+ } else {
1128
+ if (tz.substring(1) == '00:00') {
1129
+ tz = 'Z';
1130
+ }
1131
+ }
1132
+ break;
1133
+ }
1134
+ resTime.timezone = tz;
1135
+ }
1136
+
1137
+
1138
+ return resTime;
1139
+ }
1140
+ return false;
1141
+ };// end strictParse
1142
+
1143
+ // First try JS Date, if that fails, use strictParse
1144
+ var looseParse = function(f,s,o){
1145
+ try{
1146
+ var d = new Date('2012-01-01 '+ s);
1147
+ if(isNaN(d.getTime())){
1148
+ d = new Date('2012-01-01T'+ s);
1149
+ if(isNaN(d.getTime())){
1150
+ d = new Date('01/01/2012 '+ s);
1151
+ if(isNaN(d.getTime())){
1152
+ throw "Unable to parse time with native Date: "+ s;
1153
+ }
1154
+ }
1155
+ }
1156
+
1157
+ return {
1158
+ hour: d.getHours(),
1159
+ minute: d.getMinutes(),
1160
+ second: d.getSeconds(),
1161
+ millisec: d.getMilliseconds(),
1162
+ timezone: $.timepicker.timeZoneOffsetString(d)
1163
+ };
1164
+ }
1165
+ catch(err){
1166
+ try{
1167
+ return strictParse(f,s,o);
1168
+ }
1169
+ catch(err2){
1170
+ $.timepicker.log("Unable to parse \ntimeString: "+ s +"\ntimeFormat: "+ f);
1171
+ }
1172
+ }
1173
+ return false;
1174
+ }; // end looseParse
1175
+
1176
+ if(typeof o.parse === "function"){
1177
+ return o.parse(timeFormat, timeString, o)
1178
+ }
1179
+ if(o.parse === 'loose'){
1180
+ return looseParse(timeFormat, timeString, o);
1181
+ }
1182
+ return strictParse(timeFormat, timeString, o);
1183
+ };
1184
+
1185
+ /*
1186
+ * Public utility to format the time
1187
+ * format = string format of the time
1188
+ * time = a {}, not a Date() for timezones
1189
+ * options = essentially the regional[].. amNames, pmNames, ampm
1190
+ */
1191
+ $.datepicker.formatTime = function(format, time, options) {
1192
+ options = options || {};
1193
+ options = $.extend({}, $.timepicker._defaults, options);
1194
+ time = $.extend({
1195
+ hour: 0,
1196
+ minute: 0,
1197
+ second: 0,
1198
+ millisec: 0,
1199
+ timezone: '+0000'
1200
+ }, time);
1201
+
1202
+ var tmptime = format,
1203
+ ampmName = options.amNames[0],
1204
+ hour = parseInt(time.hour, 10);
1205
+
1206
+ if (hour > 11) {
1207
+ ampmName = options.pmNames[0];
1208
+ }
1209
+
1210
+ tmptime = tmptime.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[lz]|('.*?'|".*?"))/g, function(match) {
1211
+ switch (match) {
1212
+ case 'HH':
1213
+ return ('0' + hour).slice(-2);
1214
+ case 'H':
1215
+ return hour;
1216
+ case 'hh':
1217
+ return ('0' + convert24to12(hour)).slice(-2);
1218
+ case 'h':
1219
+ return convert24to12(hour);
1220
+ case 'mm':
1221
+ return ('0' + time.minute).slice(-2);
1222
+ case 'm':
1223
+ return time.minute;
1224
+ case 'ss':
1225
+ return ('0' + time.second).slice(-2);
1226
+ case 's':
1227
+ return time.second;
1228
+ case 'l':
1229
+ return ('00' + time.millisec).slice(-3);
1230
+ case 'z':
1231
+ return time.timezone === null? options.defaultTimezone : time.timezone;
1232
+ case 'T':
1233
+ return ampmName.charAt(0).toUpperCase();
1234
+ case 'TT':
1235
+ return ampmName.toUpperCase();
1236
+ case 't':
1237
+ return ampmName.charAt(0).toLowerCase();
1238
+ case 'tt':
1239
+ return ampmName.toLowerCase();
1240
+ default:
1241
+ return match.replace(/\'/g, "") || "'";
1242
+ }
1243
+ });
1244
+
1245
+ tmptime = $.trim(tmptime);
1246
+ return tmptime;
1247
+ };
1248
+
1249
+ /*
1250
+ * the bad hack :/ override datepicker so it doesnt close on select
1251
+ // inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378
1252
+ */
1253
+ $.datepicker._base_selectDate = $.datepicker._selectDate;
1254
+ $.datepicker._selectDate = function(id, dateStr) {
1255
+ var inst = this._getInst($(id)[0]),
1256
+ tp_inst = this._get(inst, 'timepicker');
1257
+
1258
+ if (tp_inst) {
1259
+ tp_inst._limitMinMaxDateTime(inst, true);
1260
+ inst.inline = inst.stay_open = true;
1261
+ //This way the onSelect handler called from calendarpicker get the full dateTime
1262
+ this._base_selectDate(id, dateStr);
1263
+ inst.inline = inst.stay_open = false;
1264
+ this._notifyChange(inst);
1265
+ this._updateDatepicker(inst);
1266
+ } else {
1267
+ this._base_selectDate(id, dateStr);
1268
+ }
1269
+ };
1270
+
1271
+ /*
1272
+ * second bad hack :/ override datepicker so it triggers an event when changing the input field
1273
+ * and does not redraw the datepicker on every selectDate event
1274
+ */
1275
+ $.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker;
1276
+ $.datepicker._updateDatepicker = function(inst) {
1277
+
1278
+ // don't popup the datepicker if there is another instance already opened
1279
+ var input = inst.input[0];
1280
+ if ($.datepicker._curInst && $.datepicker._curInst != inst && $.datepicker._datepickerShowing && $.datepicker._lastInput != input) {
1281
+ return;
1282
+ }
1283
+
1284
+ if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {
1285
+
1286
+ this._base_updateDatepicker(inst);
1287
+
1288
+ // Reload the time control when changing something in the input text field.
1289
+ var tp_inst = this._get(inst, 'timepicker');
1290
+ if (tp_inst) {
1291
+ tp_inst._addTimePicker(inst);
1292
+
1293
+ // if (tp_inst._defaults.useLocalTimezone) { //checks daylight saving with the new date.
1294
+ // var date = new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay, 12);
1295
+ // selectLocalTimeZone(tp_inst, date);
1296
+ // tp_inst._onTimeChange();
1297
+ // }
1298
+ }
1299
+ }
1300
+ };
1301
+
1302
+ /*
1303
+ * third bad hack :/ override datepicker so it allows spaces and colon in the input field
1304
+ */
1305
+ $.datepicker._base_doKeyPress = $.datepicker._doKeyPress;
1306
+ $.datepicker._doKeyPress = function(event) {
1307
+ var inst = $.datepicker._getInst(event.target),
1308
+ tp_inst = $.datepicker._get(inst, 'timepicker');
1309
+
1310
+ if (tp_inst) {
1311
+ if ($.datepicker._get(inst, 'constrainInput')) {
1312
+ var ampm = useAmpm(tp_inst._defaults.timeFormat),
1313
+ dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
1314
+ datetimeChars = tp_inst._defaults.timeFormat.toString()
1315
+ .replace(/[hms]/g, '')
1316
+ .replace(/TT/g, ampm ? 'APM' : '')
1317
+ .replace(/Tt/g, ampm ? 'AaPpMm' : '')
1318
+ .replace(/tT/g, ampm ? 'AaPpMm' : '')
1319
+ .replace(/T/g, ampm ? 'AP' : '')
1320
+ .replace(/tt/g, ampm ? 'apm' : '')
1321
+ .replace(/t/g, ampm ? 'ap' : '') +
1322
+ " " + tp_inst._defaults.separator +
1323
+ tp_inst._defaults.timeSuffix +
1324
+ (tp_inst._defaults.showTimezone ? tp_inst._defaults.timezoneList.join('') : '') +
1325
+ (tp_inst._defaults.amNames.join('')) + (tp_inst._defaults.pmNames.join('')) +
1326
+ dateChars,
1327
+ chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
1328
+ return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1);
1329
+ }
1330
+ }
1331
+
1332
+ return $.datepicker._base_doKeyPress(event);
1333
+ };
1334
+
1335
+ /*
1336
+ * Fourth bad hack :/ override _updateAlternate function used in inline mode to init altField
1337
+ */
1338
+ $.datepicker._base_updateAlternate = $.datepicker._updateAlternate;
1339
+ /* Update any alternate field to synchronise with the main field. */
1340
+ $.datepicker._updateAlternate = function(inst) {
1341
+ var tp_inst = this._get(inst, 'timepicker');
1342
+ if(tp_inst){
1343
+ var altField = tp_inst._defaults.altField;
1344
+ if (altField) { // update alternate field too
1345
+ var altFormat = tp_inst._defaults.altFormat || tp_inst._defaults.dateFormat,
1346
+ date = this._getDate(inst),
1347
+ formatCfg = $.datepicker._getFormatConfig(inst),
1348
+ altFormattedDateTime = '',
1349
+ altSeparator = tp_inst._defaults.altSeparator ? tp_inst._defaults.altSeparator : tp_inst._defaults.separator,
1350
+ altTimeSuffix = tp_inst._defaults.altTimeSuffix ? tp_inst._defaults.altTimeSuffix : tp_inst._defaults.timeSuffix,
1351
+ altTimeFormat = tp_inst._defaults.altTimeFormat !== null ? tp_inst._defaults.altTimeFormat : tp_inst._defaults.timeFormat;
1352
+
1353
+ altFormattedDateTime += $.datepicker.formatTime(altTimeFormat, tp_inst, tp_inst._defaults) + altTimeSuffix;
1354
+ if(!tp_inst._defaults.timeOnly && !tp_inst._defaults.altFieldTimeOnly && date !== null){
1355
+ if(tp_inst._defaults.altFormat)
1356
+ altFormattedDateTime = $.datepicker.formatDate(tp_inst._defaults.altFormat, date, formatCfg) + altSeparator + altFormattedDateTime;
1357
+ else altFormattedDateTime = tp_inst.formattedDate + altSeparator + altFormattedDateTime;
1358
+ }
1359
+ $(altField).val(altFormattedDateTime);
1360
+ }
1361
+ }
1362
+ else{
1363
+ $.datepicker._base_updateAlternate(inst);
1364
+ }
1365
+ };
1366
+
1367
+ /*
1368
+ * Override key up event to sync manual input changes.
1369
+ */
1370
+ $.datepicker._base_doKeyUp = $.datepicker._doKeyUp;
1371
+ $.datepicker._doKeyUp = function(event) {
1372
+ var inst = $.datepicker._getInst(event.target),
1373
+ tp_inst = $.datepicker._get(inst, 'timepicker');
1374
+
1375
+ if (tp_inst) {
1376
+ if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) {
1377
+ try {
1378
+ $.datepicker._updateDatepicker(inst);
1379
+ } catch (err) {
1380
+ $.timepicker.log(err);
1381
+ }
1382
+ }
1383
+ }
1384
+
1385
+ return $.datepicker._base_doKeyUp(event);
1386
+ };
1387
+
1388
+ /*
1389
+ * override "Today" button to also grab the time.
1390
+ */
1391
+ $.datepicker._base_gotoToday = $.datepicker._gotoToday;
1392
+ $.datepicker._gotoToday = function(id) {
1393
+ var inst = this._getInst($(id)[0]),
1394
+ $dp = inst.dpDiv;
1395
+ this._base_gotoToday(id);
1396
+ var tp_inst = this._get(inst, 'timepicker');
1397
+ selectLocalTimeZone(tp_inst);
1398
+ var now = new Date();
1399
+ this._setTime(inst, now);
1400
+ $('.ui-datepicker-today', $dp).click();
1401
+ };
1402
+
1403
+ /*
1404
+ * Disable & enable the Time in the datetimepicker
1405
+ */
1406
+ $.datepicker._disableTimepickerDatepicker = function(target) {
1407
+ var inst = this._getInst(target);
1408
+ if (!inst) {
1409
+ return;
1410
+ }
1411
+
1412
+ var tp_inst = this._get(inst, 'timepicker');
1413
+ $(target).datepicker('getDate'); // Init selected[Year|Month|Day]
1414
+ if (tp_inst) {
1415
+ tp_inst._defaults.showTimepicker = false;
1416
+ tp_inst._updateDateTime(inst);
1417
+ }
1418
+ };
1419
+
1420
+ $.datepicker._enableTimepickerDatepicker = function(target) {
1421
+ var inst = this._getInst(target);
1422
+ if (!inst) {
1423
+ return;
1424
+ }
1425
+
1426
+ var tp_inst = this._get(inst, 'timepicker');
1427
+ $(target).datepicker('getDate'); // Init selected[Year|Month|Day]
1428
+ if (tp_inst) {
1429
+ tp_inst._defaults.showTimepicker = true;
1430
+ tp_inst._addTimePicker(inst); // Could be disabled on page load
1431
+ tp_inst._updateDateTime(inst);
1432
+ }
1433
+ };
1434
+
1435
+ /*
1436
+ * Create our own set time function
1437
+ */
1438
+ $.datepicker._setTime = function(inst, date) {
1439
+ var tp_inst = this._get(inst, 'timepicker');
1440
+ if (tp_inst) {
1441
+ var defaults = tp_inst._defaults;
1442
+
1443
+ // calling _setTime with no date sets time to defaults
1444
+ tp_inst.hour = date ? date.getHours() : defaults.hour;
1445
+ tp_inst.minute = date ? date.getMinutes() : defaults.minute;
1446
+ tp_inst.second = date ? date.getSeconds() : defaults.second;
1447
+ tp_inst.millisec = date ? date.getMilliseconds() : defaults.millisec;
1448
+
1449
+ //check if within min/max times..
1450
+ tp_inst._limitMinMaxDateTime(inst, true);
1451
+
1452
+ tp_inst._onTimeChange();
1453
+ tp_inst._updateDateTime(inst);
1454
+ }
1455
+ };
1456
+
1457
+ /*
1458
+ * Create new public method to set only time, callable as $().datepicker('setTime', date)
1459
+ */
1460
+ $.datepicker._setTimeDatepicker = function(target, date, withDate) {
1461
+ var inst = this._getInst(target);
1462
+ if (!inst) {
1463
+ return;
1464
+ }
1465
+
1466
+ var tp_inst = this._get(inst, 'timepicker');
1467
+
1468
+ if (tp_inst) {
1469
+ this._setDateFromField(inst);
1470
+ var tp_date;
1471
+ if (date) {
1472
+ if (typeof date == "string") {
1473
+ tp_inst._parseTime(date, withDate);
1474
+ tp_date = new Date();
1475
+ tp_date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
1476
+ } else {
1477
+ tp_date = new Date(date.getTime());
1478
+ }
1479
+ if (tp_date.toString() == 'Invalid Date') {
1480
+ tp_date = undefined;
1481
+ }
1482
+ this._setTime(inst, tp_date);
1483
+ }
1484
+ }
1485
+
1486
+ };
1487
+
1488
+ /*
1489
+ * override setDate() to allow setting time too within Date object
1490
+ */
1491
+ $.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker;
1492
+ $.datepicker._setDateDatepicker = function(target, date) {
1493
+ var inst = this._getInst(target);
1494
+ if (!inst) {
1495
+ return;
1496
+ }
1497
+
1498
+ var tp_date = (date instanceof Date) ? new Date(date.getTime()) : date;
1499
+
1500
+ this._updateDatepicker(inst);
1501
+ this._base_setDateDatepicker.apply(this, arguments);
1502
+ this._setTimeDatepicker(target, tp_date, true);
1503
+ };
1504
+
1505
+ /*
1506
+ * override getDate() to allow getting time too within Date object
1507
+ */
1508
+ $.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker;
1509
+ $.datepicker._getDateDatepicker = function(target, noDefault) {
1510
+ var inst = this._getInst(target);
1511
+ if (!inst) {
1512
+ return;
1513
+ }
1514
+
1515
+ var tp_inst = this._get(inst, 'timepicker');
1516
+
1517
+ if (tp_inst) {
1518
+ // if it hasn't yet been defined, grab from field
1519
+ if(inst.lastVal === undefined){
1520
+ this._setDateFromField(inst, noDefault);
1521
+ }
1522
+
1523
+ var date = this._getDate(inst);
1524
+ if (date && tp_inst._parseTime($(target).val(), tp_inst.timeOnly)) {
1525
+ date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
1526
+ }
1527
+ return date;
1528
+ }
1529
+ return this._base_getDateDatepicker(target, noDefault);
1530
+ };
1531
+
1532
+ /*
1533
+ * override parseDate() because UI 1.8.14 throws an error about "Extra characters"
1534
+ * An option in datapicker to ignore extra format characters would be nicer.
1535
+ */
1536
+ $.datepicker._base_parseDate = $.datepicker.parseDate;
1537
+ $.datepicker.parseDate = function(format, value, settings) {
1538
+ var date;
1539
+ try {
1540
+ date = this._base_parseDate(format, value, settings);
1541
+ } catch (err) {
1542
+ // Hack! The error message ends with a colon, a space, and
1543
+ // the "extra" characters. We rely on that instead of
1544
+ // attempting to perfectly reproduce the parsing algorithm.
1545
+ date = this._base_parseDate(format, value.substring(0,value.length-(err.length-err.indexOf(':')-2)), settings);
1546
+ $.timepicker.log("Error parsing the date string: " + err + "\ndate string = " + value + "\ndate format = " + format);
1547
+ }
1548
+ return date;
1549
+ };
1550
+
1551
+ /*
1552
+ * override formatDate to set date with time to the input
1553
+ */
1554
+ $.datepicker._base_formatDate = $.datepicker._formatDate;
1555
+ $.datepicker._formatDate = function(inst, day, month, year) {
1556
+ var tp_inst = this._get(inst, 'timepicker');
1557
+ if (tp_inst) {
1558
+ tp_inst._updateDateTime(inst);
1559
+ return tp_inst.$input.val();
1560
+ }
1561
+ return this._base_formatDate(inst);
1562
+ };
1563
+
1564
+ /*
1565
+ * override options setter to add time to maxDate(Time) and minDate(Time). MaxDate
1566
+ */
1567
+ $.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker;
1568
+ $.datepicker._optionDatepicker = function(target, name, value) {
1569
+ var inst = this._getInst(target),
1570
+ name_clone;
1571
+ if (!inst) {
1572
+ return null;
1573
+ }
1574
+
1575
+ var tp_inst = this._get(inst, 'timepicker');
1576
+ if (tp_inst) {
1577
+ var min = null,
1578
+ max = null,
1579
+ onselect = null,
1580
+ overrides = tp_inst._defaults.evnts,
1581
+ fns = {},
1582
+ prop;
1583
+ if (typeof name == 'string') { // if min/max was set with the string
1584
+ if (name === 'minDate' || name === 'minDateTime') {
1585
+ min = value;
1586
+ } else if (name === 'maxDate' || name === 'maxDateTime') {
1587
+ max = value;
1588
+ } else if (name === 'onSelect') {
1589
+ onselect = value;
1590
+ } else if (overrides.hasOwnProperty(name)) {
1591
+ if (typeof (value) === 'undefined') {
1592
+ return overrides[name];
1593
+ }
1594
+ fns[name] = value;
1595
+ name_clone = {}; //empty results in exiting function after overrides updated
1596
+ }
1597
+ } else if (typeof name == 'object') { //if min/max was set with the JSON
1598
+ if (name.minDate) {
1599
+ min = name.minDate;
1600
+ } else if (name.minDateTime) {
1601
+ min = name.minDateTime;
1602
+ } else if (name.maxDate) {
1603
+ max = name.maxDate;
1604
+ } else if (name.maxDateTime) {
1605
+ max = name.maxDateTime;
1606
+ }
1607
+ for (prop in overrides) {
1608
+ if (overrides.hasOwnProperty(prop) && name[prop]) {
1609
+ fns[prop] = name[prop];
1610
+ }
1611
+ }
1612
+ }
1613
+ for (prop in fns) {
1614
+ if (fns.hasOwnProperty(prop)) {
1615
+ overrides[prop] = fns[prop];
1616
+ if (!name_clone) { name_clone = $.extend({}, name);}
1617
+ delete name_clone[prop];
1618
+ }
1619
+ }
1620
+ if (name_clone && isEmptyObject(name_clone)) { return; }
1621
+ if (min) { //if min was set
1622
+ if (min === 0) {
1623
+ min = new Date();
1624
+ } else {
1625
+ min = new Date(min);
1626
+ }
1627
+ tp_inst._defaults.minDate = min;
1628
+ tp_inst._defaults.minDateTime = min;
1629
+ } else if (max) { //if max was set
1630
+ if (max === 0) {
1631
+ max = new Date();
1632
+ } else {
1633
+ max = new Date(max);
1634
+ }
1635
+ tp_inst._defaults.maxDate = max;
1636
+ tp_inst._defaults.maxDateTime = max;
1637
+ } else if (onselect) {
1638
+ tp_inst._defaults.onSelect = onselect;
1639
+ }
1640
+ }
1641
+ if (value === undefined) {
1642
+ return this._base_optionDatepicker.call($.datepicker, target, name);
1643
+ }
1644
+ return this._base_optionDatepicker.call($.datepicker, target, name_clone || name, value);
1645
+ };
1646
+ /*
1647
+ * jQuery isEmptyObject does not check hasOwnProperty - if someone has added to the object prototype,
1648
+ * it will return false for all objects
1649
+ */
1650
+ var isEmptyObject = function(obj) {
1651
+ var prop;
1652
+ for (prop in obj) {
1653
+ if (obj.hasOwnProperty(obj)) {
1654
+ return false;
1655
+ }
1656
+ }
1657
+ return true;
1658
+ };
1659
+
1660
+ /*
1661
+ * jQuery extend now ignores nulls!
1662
+ */
1663
+ var extendRemove = function(target, props) {
1664
+ $.extend(target, props);
1665
+ for (var name in props) {
1666
+ if (props[name] === null || props[name] === undefined) {
1667
+ target[name] = props[name];
1668
+ }
1669
+ }
1670
+ return target;
1671
+ };
1672
+
1673
+ /*
1674
+ * Determine by the time format if should use ampm
1675
+ * Returns true if should use ampm, false if not
1676
+ */
1677
+ var useAmpm = function(timeFormat){
1678
+ return (timeFormat.indexOf('t') !== -1 && timeFormat.indexOf('h') !== -1);
1679
+ };
1680
+
1681
+ /*
1682
+ * Converts 24 hour format into 12 hour
1683
+ * Returns 12 hour without leading 0
1684
+ */
1685
+ var convert24to12 = function(hour) {
1686
+ if (hour > 12) {
1687
+ hour = hour - 12;
1688
+ }
1689
+
1690
+ if (hour == 0) {
1691
+ hour = 12;
1692
+ }
1693
+
1694
+ return String(hour);
1695
+ };
1696
+
1697
+ /*
1698
+ * Splits datetime string into date ans time substrings.
1699
+ * Throws exception when date can't be parsed
1700
+ * Returns [dateString, timeString]
1701
+ */
1702
+ var splitDateTime = function(dateFormat, dateTimeString, dateSettings, timeSettings) {
1703
+ try {
1704
+ // The idea is to get the number separator occurances in datetime and the time format requested (since time has
1705
+ // fewer unknowns, mostly numbers and am/pm). We will use the time pattern to split.
1706
+ var separator = timeSettings && timeSettings.separator ? timeSettings.separator : $.timepicker._defaults.separator,
1707
+ format = timeSettings && timeSettings.timeFormat ? timeSettings.timeFormat : $.timepicker._defaults.timeFormat,
1708
+ timeParts = format.split(separator), // how many occurances of separator may be in our format?
1709
+ timePartsLen = timeParts.length,
1710
+ allParts = dateTimeString.split(separator),
1711
+ allPartsLen = allParts.length;
1712
+
1713
+ if (allPartsLen > 1) {
1714
+ return [
1715
+ allParts.splice(0,allPartsLen-timePartsLen).join(separator),
1716
+ allParts.splice(0,timePartsLen).join(separator)
1717
+ ];
1718
+ }
1719
+
1720
+ } catch (err) {
1721
+ $.timepicker.log('Could not split the date from the time. Please check the following datetimepicker options' +
1722
+ "\nthrown error: " + err +
1723
+ "\ndateTimeString" + dateTimeString +
1724
+ "\ndateFormat = " + dateFormat +
1725
+ "\nseparator = " + timeSettings.separator +
1726
+ "\ntimeFormat = " + timeSettings.timeFormat);
1727
+
1728
+ if (err.indexOf(":") >= 0) {
1729
+ // Hack! The error message ends with a colon, a space, and
1730
+ // the "extra" characters. We rely on that instead of
1731
+ // attempting to perfectly reproduce the parsing algorithm.
1732
+ var dateStringLength = dateTimeString.length - (err.length - err.indexOf(':') - 2),
1733
+ timeString = dateTimeString.substring(dateStringLength);
1734
+
1735
+ return [$.trim(dateTimeString.substring(0, dateStringLength)), $.trim(dateTimeString.substring(dateStringLength))];
1736
+
1737
+ } else {
1738
+ throw err;
1739
+ }
1740
+ }
1741
+ return [dateTimeString, ''];
1742
+ };
1743
+
1744
+ /*
1745
+ * Internal function to parse datetime interval
1746
+ * Returns: {date: Date, timeObj: Object}, where
1747
+ * date - parsed date without time (type Date)
1748
+ * timeObj = {hour: , minute: , second: , millisec: } - parsed time. Optional
1749
+ */
1750
+ var parseDateTimeInternal = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) {
1751
+ var date;
1752
+ var splitRes = splitDateTime(dateFormat, dateTimeString, dateSettings, timeSettings);
1753
+ date = $.datepicker._base_parseDate(dateFormat, splitRes[0], dateSettings);
1754
+ if (splitRes[1] !== '') {
1755
+ var timeString = splitRes[1],
1756
+ parsedTime = $.datepicker.parseTime(timeFormat, timeString, timeSettings);
1757
+
1758
+ if (parsedTime === null) {
1759
+ throw 'Wrong time format';
1760
+ }
1761
+ return {
1762
+ date: date,
1763
+ timeObj: parsedTime
1764
+ };
1765
+ } else {
1766
+ return {
1767
+ date: date
1768
+ };
1769
+ }
1770
+ };
1771
+
1772
+ /*
1773
+ * Internal function to set timezone_select to the local timezone
1774
+ */
1775
+ var selectLocalTimeZone = function(tp_inst, date) {
1776
+ if (tp_inst && tp_inst.timezone_select) {
1777
+ tp_inst._defaults.useLocalTimezone = true;
1778
+ var now = typeof date !== 'undefined' ? date : new Date();
1779
+ var tzoffset = $.timepicker.timeZoneOffsetString(now);
1780
+ if (tp_inst._defaults.timezoneIso8601) {
1781
+ tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3);
1782
+ }
1783
+ tp_inst.timezone_select.val(tzoffset);
1784
+ }
1785
+ };
1786
+
1787
+ /*
1788
+ * Create a Singleton Insance
1789
+ */
1790
+ $.timepicker = new Timepicker();
1791
+
1792
+ /**
1793
+ * Get the timezone offset as string from a date object (eg '+0530' for UTC+5.5)
1794
+ * @param date
1795
+ * @return string
1796
+ */
1797
+ $.timepicker.timeZoneOffsetString = function(date) {
1798
+ var off = date.getTimezoneOffset() * -1,
1799
+ minutes = off % 60,
1800
+ hours = (off - minutes) / 60;
1801
+ return (off >= 0 ? '+' : '-') + ('0' + (hours * 101).toString()).slice(-2) + ('0' + (minutes * 101).toString()).slice(-2);
1802
+ };
1803
+
1804
+ /**
1805
+ * Calls `timepicker()` on the `startTime` and `endTime` elements, and configures them to
1806
+ * enforce date range limits.
1807
+ * n.b. The input value must be correctly formatted (reformatting is not supported)
1808
+ * @param Element startTime
1809
+ * @param Element endTime
1810
+ * @param obj options Options for the timepicker() call
1811
+ * @return jQuery
1812
+ */
1813
+ $.timepicker.timeRange = function(startTime, endTime, options) {
1814
+ return $.timepicker.handleRange('timepicker', startTime, endTime, options);
1815
+ };
1816
+
1817
+ /**
1818
+ * Calls `datetimepicker` on the `startTime` and `endTime` elements, and configures them to
1819
+ * enforce date range limits.
1820
+ * @param Element startTime
1821
+ * @param Element endTime
1822
+ * @param obj options Options for the `timepicker()` call. Also supports `reformat`,
1823
+ * a boolean value that can be used to reformat the input values to the `dateFormat`.
1824
+ * @param string method Can be used to specify the type of picker to be added
1825
+ * @return jQuery
1826
+ */
1827
+ $.timepicker.dateTimeRange = function(startTime, endTime, options) {
1828
+ $.timepicker.dateRange(startTime, endTime, options, 'datetimepicker');
1829
+ };
1830
+
1831
+ /**
1832
+ * Calls `method` on the `startTime` and `endTime` elements, and configures them to
1833
+ * enforce date range limits.
1834
+ * @param Element startTime
1835
+ * @param Element endTime
1836
+ * @param obj options Options for the `timepicker()` call. Also supports `reformat`,
1837
+ * a boolean value that can be used to reformat the input values to the `dateFormat`.
1838
+ * @param string method Can be used to specify the type of picker to be added
1839
+ * @return jQuery
1840
+ */
1841
+ $.timepicker.dateRange = function(startTime, endTime, options, method) {
1842
+ method = method || 'datepicker';
1843
+ $.timepicker.handleRange(method, startTime, endTime, options);
1844
+ };
1845
+
1846
+ /**
1847
+ * Calls `method` on the `startTime` and `endTime` elements, and configures them to
1848
+ * enforce date range limits.
1849
+ * @param string method Can be used to specify the type of picker to be added
1850
+ * @param Element startTime
1851
+ * @param Element endTime
1852
+ * @param obj options Options for the `timepicker()` call. Also supports `reformat`,
1853
+ * a boolean value that can be used to reformat the input values to the `dateFormat`.
1854
+ * @return jQuery
1855
+ */
1856
+ $.timepicker.handleRange = function(method, startTime, endTime, options) {
1857
+ $.fn[method].call(startTime, $.extend({
1858
+ onClose: function(dateText, inst) {
1859
+ checkDates(this, endTime, dateText);
1860
+ },
1861
+ onSelect: function(selectedDateTime) {
1862
+ selected(this, endTime, 'minDate');
1863
+ }
1864
+ }, options, options.start));
1865
+ $.fn[method].call(endTime, $.extend({
1866
+ onClose: function(dateText, inst) {
1867
+ checkDates(this, startTime, dateText);
1868
+ },
1869
+ onSelect: function(selectedDateTime) {
1870
+ selected(this, startTime, 'maxDate');
1871
+ }
1872
+ }, options, options.end));
1873
+ // timepicker doesn't provide access to its 'timeFormat' option,
1874
+ // nor could I get datepicker.formatTime() to behave with times, so I
1875
+ // have disabled reformatting for timepicker
1876
+ if (method != 'timepicker' && options.reformat) {
1877
+ $([startTime, endTime]).each(function() {
1878
+ var format = $(this)[method].call($(this), 'option', 'dateFormat'),
1879
+ date = new Date($(this).val());
1880
+ if ($(this).val() && date) {
1881
+ $(this).val($.datepicker.formatDate(format, date));
1882
+ }
1883
+ });
1884
+ }
1885
+ checkDates(startTime, endTime, startTime.val());
1886
+
1887
+ function checkDates(changed, other, dateText) {
1888
+ if (other.val() && (new Date(startTime.val()) > new Date(endTime.val()))) {
1889
+ other.val(dateText);
1890
+ }
1891
+ }
1892
+ selected(startTime, endTime, 'minDate');
1893
+ selected(endTime, startTime, 'maxDate');
1894
+
1895
+ function selected(changed, other, option) {
1896
+ if (!$(changed).val()) {
1897
+ return;
1898
+ }
1899
+ var date = $(changed)[method].call($(changed), 'getDate');
1900
+ // timepicker doesn't implement 'getDate' and returns a jQuery
1901
+ if (date.getTime) {
1902
+ $(other)[method].call($(other), 'option', option, date);
1903
+ }
1904
+ }
1905
+ return $([startTime.get(0), endTime.get(0)]);
1906
+ };
1907
+
1908
+ /**
1909
+ * Log error or data to the console during error or debugging
1910
+ * @param Object err pass any type object to log to the console during error or debugging
1911
+ * @return void
1912
+ */
1913
+ $.timepicker.log = function(err){
1914
+ if(window.console)
1915
+ console.log(err);
1916
+ };
1917
+
1918
+ /*
1919
+ * Keep up with the version
1920
+ */
1921
+ $.timepicker.version = "1.2";
1922
+
1923
+ })(jQuery);