spree_custom_notifications 0.1

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