activeadmin-selleo-cms 0.0.18 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/app/admin/active_admin/views_helper.rb +4 -0
  2. data/app/admin/activeadmin_selleo_cms/page.rb +42 -6
  3. data/app/assets/javascripts/activeadmin-selleo-cms/custom.js +35 -0
  4. data/app/assets/javascripts/activeadmin-selleo-cms/jquery-ui-timepicker-addon.js +1902 -0
  5. data/app/assets/javascripts/ckeditor/config.js +12 -1
  6. data/app/assets/stylesheets/activeadmin-selleo-cms/custom.css +5 -1
  7. data/app/assets/stylesheets/activeadmin-selleo-cms/jquery-ui-timepicker-addon.css +10 -0
  8. data/app/controllers/pages_controller.rb +9 -4
  9. data/app/controllers/searches_controller.rb +1 -1
  10. data/app/helpers/pages_helper.rb +9 -5
  11. data/app/models/activeadmin_selleo_cms/asset.rb +7 -1
  12. data/app/models/activeadmin_selleo_cms/attachment.rb +2 -0
  13. data/app/models/activeadmin_selleo_cms/image.rb +21 -0
  14. data/app/models/activeadmin_selleo_cms/layout.rb +27 -3
  15. data/app/models/activeadmin_selleo_cms/page.rb +33 -33
  16. data/app/models/activeadmin_selleo_cms/search.rb +1 -0
  17. data/app/models/activeadmin_selleo_cms/section.rb +33 -1
  18. data/app/views/admin/pages/_form.html.haml +2 -8
  19. data/app/views/admin/pages/_translated_fields.html.haml +52 -15
  20. data/app/views/admin/pages/reorder.html.haml +6 -0
  21. data/app/views/admin/pages/update_positions.js.erb +6 -0
  22. data/app/views/searches/show.html.haml +1 -1
  23. data/config/initializers/active_admin.rb +3 -0
  24. data/config/initializers/formtastic.rb +7 -0
  25. data/config/routes.rb +2 -7
  26. data/db/migrate/20130206173233_change_activeadmin_selleo_cms_searches.rb +29 -0
  27. data/db/migrate/20130207213528_change_activeadmin_selleo_cms_assets.rb +12 -0
  28. data/lib/activeadmin-selleo-cms/version.rb +1 -1
  29. data/lib/generators/activeadmin_selleo_cms/templates/cms.html.erb +7 -3
  30. data/spec/dummy/app/views/layouts/cms.html.erb +1 -1
  31. data/spec/dummy/db/snapshots/test_database.sql +1 -1
  32. data/spec/dummy/log/test.log +79024 -0
  33. data/spec/dummy/tmp/cache/assets/BEF/CA0/sprockets%2F3335c73d91157a627611592700a9654e +0 -0
  34. data/spec/dummy/tmp/cache/assets/C5A/610/sprockets%2Fbe898195780d802c102d152255d9e477 +0 -0
  35. data/spec/dummy/tmp/cache/assets/CB7/190/sprockets%2F136a9350fa75f3336af293952861ed6d +0 -0
  36. data/spec/dummy/tmp/cache/assets/CBA/D70/sprockets%2F8c5e2f7ea6f160a6792a442f01378479 +0 -0
  37. data/spec/dummy/tmp/cache/assets/CCF/2E0/sprockets%2Fde5b2bd811d24557c940a2239b7e3130 +0 -0
  38. data/spec/dummy/tmp/cache/assets/CD3/3E0/sprockets%2F373fa62090ab111ae606b963e1b8c793 +0 -0
  39. data/spec/dummy/tmp/cache/assets/CD6/930/sprockets%2Fb62a24129369fea572b674303a7fa12f +0 -0
  40. data/spec/dummy/tmp/cache/assets/CE2/D80/sprockets%2F28a4d5b1a75700c7579e3773f34ccd71 +0 -0
  41. data/spec/dummy/tmp/cache/assets/CE3/720/sprockets%2F8c9e2817b83ec580831f21b0c352c9c7 +0 -0
  42. data/spec/dummy/tmp/cache/assets/CED/FB0/sprockets%2Fa675d17ed83804639ec0264b624d98ed +0 -0
  43. data/spec/dummy/tmp/cache/assets/D2C/2E0/sprockets%2Fa031c32e27ced12f81d4326f8b52fb23 +0 -0
  44. data/spec/dummy/tmp/cache/assets/D5C/1D0/sprockets%2F0671a22da74f433700c99e13bfaaf0ce +0 -0
  45. data/spec/dummy/tmp/cache/assets/D63/6C0/sprockets%2F1ae1f1cf9d92d0e61b7006171a39fd4d +0 -0
  46. data/spec/dummy/tmp/cache/assets/D64/060/sprockets%2F3b86cba556132a40a7e49a7b4c7e17ad +0 -0
  47. data/spec/dummy/tmp/cache/assets/D92/B20/sprockets%2F871f050bda629a18e11ea8db7c1aca77 +0 -0
  48. data/spec/dummy/tmp/cache/assets/DB2/EA0/sprockets%2Ffead656b8b83fbae9f69435c33b4649d +0 -0
  49. data/spec/dummy/tmp/cache/assets/E37/3E0/sprockets%2F9e6d2d17ed6da64a2f1876d4cdfefcd1 +0 -0
  50. data/spec/dummy/tmp/capybara/capybara-201301312228138539754304.html +152 -0
  51. data/spec/dummy/tmp/capybara/capybara-201301312228185417992211.html +152 -0
  52. data/spec/dummy/tmp/capybara/capybara-201301312228232926906843.html +152 -0
  53. data/spec/dummy/tmp/capybara/capybara-201301312228302851745933.html +176 -0
  54. data/spec/dummy/tmp/capybara/capybara-20130131222835626927814.html +152 -0
  55. data/spec/dummy/tmp/capybara/capybara-201301312228403892930584.html +152 -0
  56. data/spec/dummy/tmp/capybara/capybara-201301312228491329185040.html +152 -0
  57. data/spec/dummy/tmp/capybara/capybara-201301312232412606495803.html +182 -0
  58. data/spec/dummy/tmp/capybara/capybara-201301312232508358940406.html +242 -0
  59. data/spec/dummy/tmp/capybara/capybara-201301312233036556441968.html +182 -0
  60. data/spec/dummy/tmp/capybara/capybara-201301312233093002404474.html +182 -0
  61. data/spec/models/activeadmin_selleo_cms/page_spec.rb +9 -0
  62. data/spec/support/pages_helper.rb +4 -4
  63. metadata +46 -5
  64. data/app/models/activeadmin_selleo_cms/header_image.rb +0 -12
  65. data/app/models/activeadmin_selleo_cms/icon.rb +0 -12
  66. data/app/modules/active_admin/views/index_as_list.rb +0 -28
@@ -8,4 +8,8 @@ def determine_field_type(val)
8
8
  else
9
9
  :string
10
10
  end
11
+ end
12
+
13
+ def general_options(page)
14
+ "General options <i class='fold #{'folded' if page.layout_name}'>Hide</i>"
11
15
  end
@@ -1,8 +1,9 @@
1
1
  ActiveAdmin.register ActiveadminSelleoCms::Page, as: "Page", sort_order: "lft_asc" do
2
2
  config.batch_actions = false
3
3
  #config.paginate = false
4
+ config.clear_action_items!
4
5
 
5
- actions :all, except: :show
6
+ actions :all
6
7
 
7
8
  form :partial => "form"
8
9
 
@@ -35,9 +36,44 @@ ActiveAdmin.register ActiveadminSelleoCms::Page, as: "Page", sort_order: "lft_as
35
36
  end
36
37
  end
37
38
 
38
- #index as: :list, download_links: false do |page|
39
- # render_tree(page)
40
- #end
39
+ show do
40
+ h2 page.title
41
+ attributes_table do
42
+ row :parent do
43
+ page.parent ? link_to(page.parent.title, page.parent.url) : nil
44
+ end
45
+ row :layout_name
46
+ row :is_published
47
+ row :show_in_menu
48
+ row :is_link_url do
49
+ (page.is_link_url ? page.link_url : false)
50
+ end
51
+ row :views
52
+ end
53
+ end
54
+
55
+ action_item only:[:show] do
56
+ link_to "Edit Page", edit_admin_page_path(page.id)
57
+ end
58
+
59
+ action_item only:[:index] do
60
+ link_to "New Page", new_admin_page_path
61
+ end
62
+
63
+ action_item only:[:show,:edit] do
64
+ link_to "View on site", page.url, target: '_blank'
65
+ end
66
+
67
+ action_item only:[:show,:edit] do
68
+ link_to "Delete Page", admin_page_path(page.id), method: 'DELETE', confirm: 'Are you sure?'
69
+ end
70
+
71
+ collection_action :reorder, :method => :get do
72
+ @pages = params[:parent_id] ? ActiveadminSelleoCms::Page.where(parent_id: params[:parent_id]) : ActiveadminSelleoCms::Page.roots
73
+ end
74
+
75
+ collection_action :update_positions, :method => :put do
76
+ end
41
77
 
42
78
  controller do
43
79
  respond_to :html, :js
@@ -48,7 +84,7 @@ ActiveAdmin.register ActiveadminSelleoCms::Page, as: "Page", sort_order: "lft_as
48
84
  render action: :new
49
85
  else
50
86
  create! do |success, failure|
51
- success.html { redirect_to admin_pages_path }
87
+ success.html { redirect_to admin_page_path(@page.id) }
52
88
  failure.html { render action: :new }
53
89
  end
54
90
  end
@@ -61,7 +97,7 @@ ActiveAdmin.register ActiveadminSelleoCms::Page, as: "Page", sort_order: "lft_as
61
97
  render action: :edit
62
98
  else
63
99
  update! do |success, failure|
64
- success.html { redirect_to admin_pages_path }
100
+ success.html { redirect_to admin_page_path(@page.id) }
65
101
  failure.html { render action: :edit }
66
102
  end
67
103
  end
@@ -27,6 +27,15 @@ function delete_asset(page_id, asset_id) {
27
27
  });
28
28
  }
29
29
 
30
+ function update_positions(pagesArray) {
31
+ $('.update-positions-button').attr('disabled', true).attr('value', 'Saving...')
32
+ $.ajax({
33
+ url: '/admin/pages/update_positions.js',
34
+ data: { 'page_ids': pagesArray },
35
+ type: 'PUT'
36
+ });
37
+ }
38
+
30
39
  $(function(){
31
40
  $('#translations.index input').blur(function(evt){
32
41
  $.ajax({
@@ -52,4 +61,30 @@ $(function(){
52
61
  });
53
62
  });
54
63
 
64
+ $(document).ready(function(){
65
+ $('input.ui-datetimepicker').datetimepicker({
66
+ dateFormat: 'yy-mm-dd',
67
+ timeFormat: 'HH:mm:ss'
68
+ });
69
+ });
70
+
71
+ $('i.fold').click(function(){
72
+ var form = $(this).closest('fieldset').find('ol');
73
+ if (form.is(':visible')){
74
+ $(this).text('Show');
75
+ } else {
76
+ $(this).text('Hide');
77
+ }
78
+ $(this).closest('fieldset').find('ol').toggle();
79
+ });
80
+
81
+ // $('i.folded').click();
82
+
83
+ $('input[multiple]').each(function(){
84
+ $(this).attr('name', $(this).attr('name').replace(/\[\]$/, '') );
85
+ });
86
+
87
+ $( ".sortable" ).sortable();
88
+ $( ".sortable" ).disableSelection();
89
+
55
90
  });
@@ -0,0 +1,1902 @@
1
+ /*
2
+ * jQuery timepicker addon
3
+ * By: Trent Richardson [http://trentrichardson.com]
4
+ * Version 1.1.2
5
+ * Last Modified: 01/19/2013
6
+ *
7
+ * Copyright 2012 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.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
+ function Timepicker() {
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: 1,
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
+ $.datepicker.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'+ (o.isRTL? ' ui-timepicker-rtl' : '') +'"><dl>' + '<dt class="ui_tpicker_time_label"' + ((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</dt>' +
348
+ '<dd class="ui_tpicker_time"' + ((o.showTime) ? '' : noDisplay) + '></dd>';
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 += '<dt class="ui_tpicker_'+ litem +'_label"' + ((o['show'+uitem]) ? '' : noDisplay) + '>' + o[litem +'Text'] + '</dt>' +
361
+ '<dd class="ui_tpicker_'+ litem +'"><div class="ui_tpicker_'+ litem +'_slider"' + ((o['show'+uitem]) ? '' : noDisplay) + '></div>';
362
+
363
+ if (o['show'+uitem] && o[litem+'Grid'] > 0) {
364
+ html += '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>';
365
+
366
+ if(litem == 'hour'){
367
+ for (var h = o[litem+'Min']; h <= max[litem]; h += parseInt(o[litem+'Grid'], 10)) {
368
+ gridSize[litem]++;
369
+ var tmph = $.datepicker.formatTime(useAmpm(o.pickerTimeFormat || o.timeFormat)? 'hht':'HH', {hour:h}, o);
370
+ html += '<td data-for="'+litem+'">' + tmph + '</td>';
371
+ }
372
+ }
373
+ else{
374
+ for (var m = o[litem+'Min']; m <= max[litem]; m += parseInt(o[litem+'Grid'], 10)) {
375
+ gridSize[litem]++;
376
+ html += '<td data-for="'+litem+'">' + ((m < 10) ? '0' : '') + m + '</td>';
377
+ }
378
+ }
379
+
380
+ html += '</tr></table></div>';
381
+ }
382
+ html += '</dd>';
383
+ }
384
+
385
+ // Timezone
386
+ html += '<dt class="ui_tpicker_timezone_label"' + ((o.showTimezone) ? '' : noDisplay) + '>' + o.timezoneText + '</dt>';
387
+ html += '<dd class="ui_tpicker_timezone" ' + ((o.showTimezone) ? '' : noDisplay) + '></dd>';
388
+
389
+ // Create the elements from string
390
+ html += '</dl></div>';
391
+ var $tp = $(html);
392
+
393
+ // if we only want time picker...
394
+ if (o.timeOnly === true) {
395
+ $tp.prepend('<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' + '<div class="ui-datepicker-title">' + o.timeOnlyTitle + '</div>' + '</div>');
396
+ $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide();
397
+ }
398
+
399
+ // add sliders, adjust grids, add events
400
+ for(var i=0,l=tp_inst.units.length; i<l; i++){
401
+ litem = tp_inst.units[i];
402
+ uitem = litem.substr(0,1).toUpperCase() + litem.substr(1);
403
+
404
+ // add the slider
405
+ 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]);
406
+
407
+ // adjust the grid and add click event
408
+ if (o['show'+uitem] && o[litem+'Grid'] > 0) {
409
+ size = 100 * gridSize[litem] * o[litem+'Grid'] / (max[litem] - o[litem+'Min']);
410
+ $tp.find('.ui_tpicker_'+litem+' table').css({
411
+ width: size + "%",
412
+ marginLeft: o.isRTL? '0' : ((size / (-2 * gridSize[litem])) + "%"),
413
+ marginRight: o.isRTL? ((size / (-2 * gridSize[litem])) + "%") : '0',
414
+ borderCollapse: 'collapse'
415
+ }).find("td").click(function(e){
416
+ var $t = $(this),
417
+ h = $t.html(),
418
+ n = parseInt(h.replace(/[^0-9]/g),10),
419
+ ap = h.replace(/[^apm]/ig),
420
+ f = $t.data('for'); // loses scope, so we use data-for
421
+
422
+ if(f == 'hour'){
423
+ if(ap.indexOf('p') !== -1 && n < 12){
424
+ n += 12;
425
+ }
426
+ else{
427
+ if(ap.indexOf('a') !== -1 && n === 12){
428
+ n = 0;
429
+ }
430
+ }
431
+ }
432
+
433
+ tp_inst.control.value(tp_inst, tp_inst[f+'_slider'], litem, n);
434
+
435
+ tp_inst._onTimeChange();
436
+ tp_inst._onSelectHandler();
437
+ })
438
+ .css({
439
+ cursor: 'pointer',
440
+ width: (100 / gridSize[litem]) + '%',
441
+ textAlign: 'center',
442
+ overflow: 'hidden'
443
+ });
444
+ } // end if grid > 0
445
+ } // end for loop
446
+
447
+ // Add timezone options
448
+ this.timezone_select = $tp.find('.ui_tpicker_timezone').append('<select></select>').find("select");
449
+ $.fn.append.apply(this.timezone_select,
450
+ $.map(o.timezoneList, function(val, idx) {
451
+ return $("<option />").val(typeof val == "object" ? val.value : val).text(typeof val == "object" ? val.label : val);
452
+ }));
453
+ if (typeof(this.timezone) != "undefined" && this.timezone !== null && this.timezone !== "") {
454
+ var local_date = new Date(this.inst.selectedYear, this.inst.selectedMonth, this.inst.selectedDay, 12);
455
+ var local_timezone = $.timepicker.timeZoneOffsetString(local_date);
456
+ if (local_timezone == this.timezone) {
457
+ selectLocalTimeZone(tp_inst);
458
+ } else {
459
+ this.timezone_select.val(this.timezone);
460
+ }
461
+ } else {
462
+ if (typeof(this.hour) != "undefined" && this.hour !== null && this.hour !== "") {
463
+ this.timezone_select.val(o.defaultTimezone);
464
+ } else {
465
+ selectLocalTimeZone(tp_inst);
466
+ }
467
+ }
468
+ this.timezone_select.change(function() {
469
+ tp_inst._defaults.useLocalTimezone = false;
470
+ tp_inst._onTimeChange();
471
+ tp_inst._onSelectHandler();
472
+ });
473
+ // End timezone options
474
+
475
+ // inject timepicker into datepicker
476
+ var $buttonPanel = $dp.find('.ui-datepicker-buttonpane');
477
+ if ($buttonPanel.length) {
478
+ $buttonPanel.before($tp);
479
+ } else {
480
+ $dp.append($tp);
481
+ }
482
+
483
+ this.$timeObj = $tp.find('.ui_tpicker_time');
484
+
485
+ if (this.inst !== null) {
486
+ var timeDefined = this.timeDefined;
487
+ this._onTimeChange();
488
+ this.timeDefined = timeDefined;
489
+ }
490
+
491
+ // slideAccess integration: http://trentrichardson.com/2011/11/11/jquery-ui-sliders-and-touch-accessibility/
492
+ if (this._defaults.addSliderAccess) {
493
+ var sliderAccessArgs = this._defaults.sliderAccessArgs,
494
+ rtl = this._defaults.isRTL;
495
+ sliderAccessArgs.isRTL = rtl;
496
+
497
+ setTimeout(function() { // fix for inline mode
498
+ if ($tp.find('.ui-slider-access').length === 0) {
499
+ $tp.find('.ui-slider:visible').sliderAccess(sliderAccessArgs);
500
+
501
+ // fix any grids since sliders are shorter
502
+ var sliderAccessWidth = $tp.find('.ui-slider-access:eq(0)').outerWidth(true);
503
+ if (sliderAccessWidth) {
504
+ $tp.find('table:visible').each(function() {
505
+ var $g = $(this),
506
+ oldWidth = $g.outerWidth(),
507
+ oldMarginLeft = $g.css(rtl? 'marginRight':'marginLeft').toString().replace('%', ''),
508
+ newWidth = oldWidth - sliderAccessWidth,
509
+ newMarginLeft = ((oldMarginLeft * newWidth) / oldWidth) + '%',
510
+ css = { width: newWidth, marginRight: 0, marginLeft: 0 };
511
+ css[rtl? 'marginRight':'marginLeft'] = newMarginLeft;
512
+ $g.css(css);
513
+ });
514
+ }
515
+ }
516
+ }, 10);
517
+ }
518
+ // end slideAccess integration
519
+
520
+ }
521
+ },
522
+
523
+ /*
524
+ * This function tries to limit the ability to go outside the
525
+ * min/max date range
526
+ */
527
+ _limitMinMaxDateTime: function(dp_inst, adjustSliders) {
528
+ var o = this._defaults,
529
+ dp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay);
530
+
531
+ if (!this._defaults.showTimepicker) {
532
+ return;
533
+ } // No time so nothing to check here
534
+
535
+ if ($.datepicker._get(dp_inst, 'minDateTime') !== null && $.datepicker._get(dp_inst, 'minDateTime') !== undefined && dp_date) {
536
+ var minDateTime = $.datepicker._get(dp_inst, 'minDateTime'),
537
+ minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0);
538
+
539
+ if (this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null || this.millisecMinOriginal === null) {
540
+ this.hourMinOriginal = o.hourMin;
541
+ this.minuteMinOriginal = o.minuteMin;
542
+ this.secondMinOriginal = o.secondMin;
543
+ this.millisecMinOriginal = o.millisecMin;
544
+ }
545
+
546
+ if (dp_inst.settings.timeOnly || minDateTimeDate.getTime() == dp_date.getTime()) {
547
+ this._defaults.hourMin = minDateTime.getHours();
548
+ if (this.hour <= this._defaults.hourMin) {
549
+ this.hour = this._defaults.hourMin;
550
+ this._defaults.minuteMin = minDateTime.getMinutes();
551
+ if (this.minute <= this._defaults.minuteMin) {
552
+ this.minute = this._defaults.minuteMin;
553
+ this._defaults.secondMin = minDateTime.getSeconds();
554
+ if (this.second <= this._defaults.secondMin) {
555
+ this.second = this._defaults.secondMin;
556
+ this._defaults.millisecMin = minDateTime.getMilliseconds();
557
+ } else {
558
+ if (this.millisec < this._defaults.millisecMin) {
559
+ this.millisec = this._defaults.millisecMin;
560
+ }
561
+ this._defaults.millisecMin = this.millisecMinOriginal;
562
+ }
563
+ } else {
564
+ this._defaults.secondMin = this.secondMinOriginal;
565
+ this._defaults.millisecMin = this.millisecMinOriginal;
566
+ }
567
+ } else {
568
+ this._defaults.minuteMin = this.minuteMinOriginal;
569
+ this._defaults.secondMin = this.secondMinOriginal;
570
+ this._defaults.millisecMin = this.millisecMinOriginal;
571
+ }
572
+ } else {
573
+ this._defaults.hourMin = this.hourMinOriginal;
574
+ this._defaults.minuteMin = this.minuteMinOriginal;
575
+ this._defaults.secondMin = this.secondMinOriginal;
576
+ this._defaults.millisecMin = this.millisecMinOriginal;
577
+ }
578
+ }
579
+
580
+ if ($.datepicker._get(dp_inst, 'maxDateTime') !== null && $.datepicker._get(dp_inst, 'maxDateTime') !== undefined && dp_date) {
581
+ var maxDateTime = $.datepicker._get(dp_inst, 'maxDateTime'),
582
+ maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0);
583
+
584
+ if (this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null) {
585
+ this.hourMaxOriginal = o.hourMax;
586
+ this.minuteMaxOriginal = o.minuteMax;
587
+ this.secondMaxOriginal = o.secondMax;
588
+ this.millisecMaxOriginal = o.millisecMax;
589
+ }
590
+
591
+ if (dp_inst.settings.timeOnly || maxDateTimeDate.getTime() == dp_date.getTime()) {
592
+ this._defaults.hourMax = maxDateTime.getHours();
593
+ if (this.hour >= this._defaults.hourMax) {
594
+ this.hour = this._defaults.hourMax;
595
+ this._defaults.minuteMax = maxDateTime.getMinutes();
596
+ if (this.minute >= this._defaults.minuteMax) {
597
+ this.minute = this._defaults.minuteMax;
598
+ this._defaults.secondMax = maxDateTime.getSeconds();
599
+ if (this.second >= this._defaults.secondMax) {
600
+ this.second = this._defaults.secondMax;
601
+ this._defaults.millisecMax = maxDateTime.getMilliseconds();
602
+ } else {
603
+ if (this.millisec > this._defaults.millisecMax) {
604
+ this.millisec = this._defaults.millisecMax;
605
+ }
606
+ this._defaults.millisecMax = this.millisecMaxOriginal;
607
+ }
608
+ } else {
609
+ this._defaults.secondMax = this.secondMaxOriginal;
610
+ this._defaults.millisecMax = this.millisecMaxOriginal;
611
+ }
612
+ } else {
613
+ this._defaults.minuteMax = this.minuteMaxOriginal;
614
+ this._defaults.secondMax = this.secondMaxOriginal;
615
+ this._defaults.millisecMax = this.millisecMaxOriginal;
616
+ }
617
+ } else {
618
+ this._defaults.hourMax = this.hourMaxOriginal;
619
+ this._defaults.minuteMax = this.minuteMaxOriginal;
620
+ this._defaults.secondMax = this.secondMaxOriginal;
621
+ this._defaults.millisecMax = this.millisecMaxOriginal;
622
+ }
623
+ }
624
+
625
+ if (adjustSliders !== undefined && adjustSliders === true) {
626
+ var hourMax = parseInt((this._defaults.hourMax - ((this._defaults.hourMax - this._defaults.hourMin) % this._defaults.stepHour)), 10),
627
+ minMax = parseInt((this._defaults.minuteMax - ((this._defaults.minuteMax - this._defaults.minuteMin) % this._defaults.stepMinute)), 10),
628
+ secMax = parseInt((this._defaults.secondMax - ((this._defaults.secondMax - this._defaults.secondMin) % this._defaults.stepSecond)), 10),
629
+ millisecMax = parseInt((this._defaults.millisecMax - ((this._defaults.millisecMax - this._defaults.millisecMin) % this._defaults.stepMillisec)), 10);
630
+
631
+ if (this.hour_slider) {
632
+ this.control.options(this, this.hour_slider, 'hour', { min: this._defaults.hourMin, max: hourMax });
633
+ this.control.value(this, this.hour_slider, 'hour', this.hour - (this.hour % this._defaults.stepHour));
634
+ }
635
+ if (this.minute_slider) {
636
+ this.control.options(this, this.minute_slider, 'minute', { min: this._defaults.minuteMin, max: minMax });
637
+ this.control.value(this, this.minute_slider, 'minute', this.minute - (this.minute % this._defaults.stepMinute));
638
+ }
639
+ if (this.second_slider) {
640
+ this.control.options(this, this.second_slider, 'second', { min: this._defaults.secondMin, max: secMax });
641
+ this.control.value(this, this.second_slider, 'second', this.second - (this.second % this._defaults.stepSecond));
642
+ }
643
+ if (this.millisec_slider) {
644
+ this.control.options(this, this.millisec_slider, 'millisec', { min: this._defaults.millisecMin, max: millisecMax });
645
+ this.control.value(this, this.millisec_slider, 'millisec', this.millisec - (this.millisec % this._defaults.stepMillisec));
646
+ }
647
+ }
648
+
649
+ },
650
+
651
+ /*
652
+ * when a slider moves, set the internal time...
653
+ * on time change is also called when the time is updated in the text field
654
+ */
655
+ _onTimeChange: function() {
656
+ var hour = (this.hour_slider) ? this.control.value(this, this.hour_slider, 'hour') : false,
657
+ minute = (this.minute_slider) ? this.control.value(this, this.minute_slider, 'minute') : false,
658
+ second = (this.second_slider) ? this.control.value(this, this.second_slider, 'second') : false,
659
+ millisec = (this.millisec_slider) ? this.control.value(this, this.millisec_slider, 'millisec') : false,
660
+ timezone = (this.timezone_select) ? this.timezone_select.val() : false,
661
+ o = this._defaults,
662
+ pickerTimeFormat = o.pickerTimeFormat || o.timeFormat,
663
+ pickerTimeSuffix = o.pickerTimeSuffix || o.timeSuffix;
664
+
665
+ if (typeof(hour) == 'object') {
666
+ hour = false;
667
+ }
668
+ if (typeof(minute) == 'object') {
669
+ minute = false;
670
+ }
671
+ if (typeof(second) == 'object') {
672
+ second = false;
673
+ }
674
+ if (typeof(millisec) == 'object') {
675
+ millisec = false;
676
+ }
677
+ if (typeof(timezone) == 'object') {
678
+ timezone = false;
679
+ }
680
+
681
+ if (hour !== false) {
682
+ hour = parseInt(hour, 10);
683
+ }
684
+ if (minute !== false) {
685
+ minute = parseInt(minute, 10);
686
+ }
687
+ if (second !== false) {
688
+ second = parseInt(second, 10);
689
+ }
690
+ if (millisec !== false) {
691
+ millisec = parseInt(millisec, 10);
692
+ }
693
+
694
+ var ampm = o[hour < 12 ? 'amNames' : 'pmNames'][0];
695
+
696
+ // If the update was done in the input field, the input field should not be updated.
697
+ // If the update was done using the sliders, update the input field.
698
+ var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || millisec != this.millisec
699
+ || (this.ampm.length > 0 && (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1))
700
+ || ((this.timezone === null && timezone != this.defaultTimezone) || (this.timezone !== null && timezone != this.timezone)));
701
+
702
+ if (hasChanged) {
703
+
704
+ if (hour !== false) {
705
+ this.hour = hour;
706
+ }
707
+ if (minute !== false) {
708
+ this.minute = minute;
709
+ }
710
+ if (second !== false) {
711
+ this.second = second;
712
+ }
713
+ if (millisec !== false) {
714
+ this.millisec = millisec;
715
+ }
716
+ if (timezone !== false) {
717
+ this.timezone = timezone;
718
+ }
719
+
720
+ if (!this.inst) {
721
+ this.inst = $.datepicker._getInst(this.$input[0]);
722
+ }
723
+
724
+ this._limitMinMaxDateTime(this.inst, true);
725
+ }
726
+ if (useAmpm(o.timeFormat)) {
727
+ this.ampm = ampm;
728
+ }
729
+
730
+ // Updates the time within the timepicker
731
+ this.formattedTime = $.datepicker.formatTime(o.timeFormat, this, o);
732
+ if (this.$timeObj) {
733
+ if(pickerTimeFormat === o.timeFormat){
734
+ this.$timeObj.text(this.formattedTime + pickerTimeSuffix);
735
+ }
736
+ else{
737
+ this.$timeObj.text($.datepicker.formatTime(pickerTimeFormat, this, o) + pickerTimeSuffix);
738
+ }
739
+ }
740
+
741
+ this.timeDefined = true;
742
+ if (hasChanged) {
743
+ this._updateDateTime();
744
+ }
745
+ },
746
+
747
+ /*
748
+ * call custom onSelect.
749
+ * bind to sliders slidestop, and grid click.
750
+ */
751
+ _onSelectHandler: function() {
752
+ var onSelect = this._defaults.onSelect || this.inst.settings.onSelect;
753
+ var inputEl = this.$input ? this.$input[0] : null;
754
+ if (onSelect && inputEl) {
755
+ onSelect.apply(inputEl, [this.formattedDateTime, this]);
756
+ }
757
+ },
758
+
759
+ /*
760
+ * update our input with the new date time..
761
+ */
762
+ _updateDateTime: function(dp_inst) {
763
+ dp_inst = this.inst || dp_inst;
764
+ var dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)),
765
+ dateFmt = $.datepicker._get(dp_inst, 'dateFormat'),
766
+ formatCfg = $.datepicker._getFormatConfig(dp_inst),
767
+ timeAvailable = dt !== null && this.timeDefined;
768
+ this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg);
769
+ var formattedDateTime = this.formattedDate;
770
+
771
+ /*
772
+ * remove following lines to force every changes in date picker to change the input value
773
+ * Bug descriptions: when an input field has a default value, and click on the field to pop up the date picker.
774
+ * If the user manually empty the value in the input field, the date picker will never change selected value.
775
+ */
776
+ //if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0)) {
777
+ // return;
778
+ //}
779
+
780
+ if (this._defaults.timeOnly === true) {
781
+ formattedDateTime = this.formattedTime;
782
+ } else if (this._defaults.timeOnly !== true && (this._defaults.alwaysSetTime || timeAvailable)) {
783
+ formattedDateTime += this._defaults.separator + this.formattedTime + this._defaults.timeSuffix;
784
+ }
785
+
786
+ this.formattedDateTime = formattedDateTime;
787
+
788
+ if (!this._defaults.showTimepicker) {
789
+ this.$input.val(this.formattedDate);
790
+ } else if (this.$altInput && this._defaults.altFieldTimeOnly === true) {
791
+ this.$altInput.val(this.formattedTime);
792
+ this.$input.val(this.formattedDate);
793
+ } else if (this.$altInput) {
794
+ this.$input.val(formattedDateTime);
795
+ var altFormattedDateTime = '',
796
+ altSeparator = this._defaults.altSeparator ? this._defaults.altSeparator : this._defaults.separator,
797
+ altTimeSuffix = this._defaults.altTimeSuffix ? this._defaults.altTimeSuffix : this._defaults.timeSuffix;
798
+
799
+ if (this._defaults.altFormat) altFormattedDateTime = $.datepicker.formatDate(this._defaults.altFormat, (dt === null ? new Date() : dt), formatCfg);
800
+ else altFormattedDateTime = this.formattedDate;
801
+ if (altFormattedDateTime) altFormattedDateTime += altSeparator;
802
+ if (this._defaults.altTimeFormat) altFormattedDateTime += $.datepicker.formatTime(this._defaults.altTimeFormat, this, this._defaults) + altTimeSuffix;
803
+ else altFormattedDateTime += this.formattedTime + altTimeSuffix;
804
+ this.$altInput.val(altFormattedDateTime);
805
+ } else {
806
+ this.$input.val(formattedDateTime);
807
+ }
808
+
809
+ this.$input.trigger("change");
810
+ },
811
+
812
+ _onFocus: function() {
813
+ if (!this.$input.val() && this._defaults.defaultValue) {
814
+ this.$input.val(this._defaults.defaultValue);
815
+ var inst = $.datepicker._getInst(this.$input.get(0)),
816
+ tp_inst = $.datepicker._get(inst, 'timepicker');
817
+ if (tp_inst) {
818
+ if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) {
819
+ try {
820
+ $.datepicker._updateDatepicker(inst);
821
+ } catch (err) {
822
+ $.datepicker.log(err);
823
+ }
824
+ }
825
+ }
826
+ }
827
+ },
828
+
829
+ /*
830
+ * Small abstraction to control types
831
+ * We can add more, just be sure to follow the pattern: create, options, value
832
+ */
833
+ _controls: {
834
+ // slider methods
835
+ slider: {
836
+ create: function(tp_inst, obj, unit, val, min, max, step){
837
+ var rtl = tp_inst._defaults.isRTL; // if rtl go -60->0 instead of 0->60
838
+ return obj.prop('slide', null).slider({
839
+ orientation: "horizontal",
840
+ value: rtl? val*-1 : val,
841
+ min: rtl? max*-1 : min,
842
+ max: rtl? min*-1 : max,
843
+ step: step,
844
+ slide: function(event, ui) {
845
+ tp_inst.control.value(tp_inst, $(this), unit, rtl? ui.value*-1:ui.value);
846
+ tp_inst._onTimeChange();
847
+ },
848
+ stop: function(event, ui) {
849
+ tp_inst._onSelectHandler();
850
+ }
851
+ });
852
+ },
853
+ options: function(tp_inst, obj, unit, opts, val){
854
+ if(tp_inst._defaults.isRTL){
855
+ if(typeof(opts) == 'string'){
856
+ if(opts == 'min' || opts == 'max'){
857
+ if(val !== undefined)
858
+ return obj.slider(opts, val*-1);
859
+ return Math.abs(obj.slider(opts));
860
+ }
861
+ return obj.slider(opts);
862
+ }
863
+ var min = opts.min,
864
+ max = opts.max;
865
+ opts.min = opts.max = null;
866
+ if(min !== undefined)
867
+ opts.max = min * -1;
868
+ if(max !== undefined)
869
+ opts.min = max * -1;
870
+ return obj.slider(opts);
871
+ }
872
+ if(typeof(opts) == 'string' && val !== undefined)
873
+ return obj.slider(opts, val);
874
+ return obj.slider(opts);
875
+ },
876
+ value: function(tp_inst, obj, unit, val){
877
+ if(tp_inst._defaults.isRTL){
878
+ if(val !== undefined)
879
+ return obj.slider('value', val*-1);
880
+ return Math.abs(obj.slider('value'));
881
+ }
882
+ if(val !== undefined)
883
+ return obj.slider('value', val);
884
+ return obj.slider('value');
885
+ }
886
+ },
887
+ // select methods
888
+ select: {
889
+ create: function(tp_inst, obj, unit, val, min, max, step){
890
+ var sel = '<select class="ui-timepicker-select" data-unit="'+ unit +'" data-min="'+ min +'" data-max="'+ max +'" data-step="'+ step +'">',
891
+ ul = tp_inst._defaults.timeFormat.indexOf('t') !== -1? 'toLowerCase':'toUpperCase',
892
+ m = 0;
893
+
894
+ for(var i=min; i<=max; i+=step){
895
+ sel += '<option value="'+ i +'"'+ (i==val? ' selected':'') +'>';
896
+ if(unit == 'hour' && useAmpm(tp_inst._defaults.pickerTimeFormat || tp_inst._defaults.timeFormat))
897
+ sel += $.datepicker.formatTime("hh TT", {hour:i}, tp_inst._defaults);
898
+ else if(unit == 'millisec' || i >= 10) sel += i;
899
+ else sel += '0'+ i.toString();
900
+ sel += '</option>';
901
+ }
902
+ sel += '</select>';
903
+
904
+ obj.children('select').remove();
905
+
906
+ $(sel).appendTo(obj).change(function(e){
907
+ tp_inst._onTimeChange();
908
+ tp_inst._onSelectHandler();
909
+ });
910
+
911
+ return obj;
912
+ },
913
+ options: function(tp_inst, obj, unit, opts, val){
914
+ var o = {},
915
+ $t = obj.children('select');
916
+ if(typeof(opts) == 'string'){
917
+ if(val === undefined)
918
+ return $t.data(opts);
919
+ o[opts] = val;
920
+ }
921
+ else o = opts;
922
+ 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'));
923
+ },
924
+ value: function(tp_inst, obj, unit, val){
925
+ var $t = obj.children('select');
926
+ if(val !== undefined)
927
+ return $t.val(val);
928
+ return $t.val();
929
+ }
930
+ }
931
+ } // end _controls
932
+
933
+ });
934
+
935
+ $.fn.extend({
936
+ /*
937
+ * shorthand just to use timepicker..
938
+ */
939
+ timepicker: function(o) {
940
+ o = o || {};
941
+ var tmp_args = Array.prototype.slice.call(arguments);
942
+
943
+ if (typeof o == 'object') {
944
+ tmp_args[0] = $.extend(o, {
945
+ timeOnly: true
946
+ });
947
+ }
948
+
949
+ return $(this).each(function() {
950
+ $.fn.datetimepicker.apply($(this), tmp_args);
951
+ });
952
+ },
953
+
954
+ /*
955
+ * extend timepicker to datepicker
956
+ */
957
+ datetimepicker: function(o) {
958
+ o = o || {};
959
+ var tmp_args = arguments;
960
+
961
+ if (typeof(o) == 'string') {
962
+ if (o == 'getDate') {
963
+ return $.fn.datepicker.apply($(this[0]), tmp_args);
964
+ } else {
965
+ return this.each(function() {
966
+ var $t = $(this);
967
+ $t.datepicker.apply($t, tmp_args);
968
+ });
969
+ }
970
+ } else {
971
+ return this.each(function() {
972
+ var $t = $(this);
973
+ $t.datepicker($.timepicker._newInst($t, o)._defaults);
974
+ });
975
+ }
976
+ }
977
+ });
978
+
979
+ /*
980
+ * Public Utility to parse date and time
981
+ */
982
+ $.datepicker.parseDateTime = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) {
983
+ var parseRes = parseDateTimeInternal(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings);
984
+ if (parseRes.timeObj) {
985
+ var t = parseRes.timeObj;
986
+ parseRes.date.setHours(t.hour, t.minute, t.second, t.millisec);
987
+ }
988
+
989
+ return parseRes.date;
990
+ };
991
+
992
+ /*
993
+ * Public utility to parse time
994
+ */
995
+ $.datepicker.parseTime = function(timeFormat, timeString, options) {
996
+ var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {});
997
+
998
+ // Strict parse requires the timeString to match the timeFormat exactly
999
+ var strictParse = function(f, s, o){
1000
+
1001
+ // pattern for standard and localized AM/PM markers
1002
+ var getPatternAmpm = function(amNames, pmNames) {
1003
+ var markers = [];
1004
+ if (amNames) {
1005
+ $.merge(markers, amNames);
1006
+ }
1007
+ if (pmNames) {
1008
+ $.merge(markers, pmNames);
1009
+ }
1010
+ markers = $.map(markers, function(val) {
1011
+ return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&');
1012
+ });
1013
+ return '(' + markers.join('|') + ')?';
1014
+ };
1015
+
1016
+ // figure out position of time elements.. cause js cant do named captures
1017
+ var getFormatPositions = function(timeFormat) {
1018
+ var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z|'.*?')/g),
1019
+ orders = {
1020
+ h: -1,
1021
+ m: -1,
1022
+ s: -1,
1023
+ l: -1,
1024
+ t: -1,
1025
+ z: -1
1026
+ };
1027
+
1028
+ if (finds) {
1029
+ for (var i = 0; i < finds.length; i++) {
1030
+ if (orders[finds[i].toString().charAt(0)] == -1) {
1031
+ orders[finds[i].toString().charAt(0)] = i + 1;
1032
+ }
1033
+ }
1034
+ }
1035
+ return orders;
1036
+ };
1037
+
1038
+ var regstr = '^' + f.toString()
1039
+ .replace(/([hH]{1,2}|mm?|ss?|[tT]{1,2}|[lz]|'.*?')/g, function (match) {
1040
+ var ml = match.length;
1041
+ switch (match.charAt(0).toLowerCase()) {
1042
+ case 'h': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})';
1043
+ case 'm': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})';
1044
+ case 's': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})';
1045
+ case 'l': return '(\\d?\\d?\\d)';
1046
+ case 'z': return '(z|[-+]\\d\\d:?\\d\\d|\\S+)?';
1047
+ case 't': return getPatternAmpm(o.amNames, o.pmNames);
1048
+ default: // literal escaped in quotes
1049
+ return '(' + match.replace(/\'/g, "").replace(/(\.|\$|\^|\\|\/|\(|\)|\[|\]|\?|\+|\*)/g, function (m) { return "\\" + m; }) + ')?';
1050
+ }
1051
+ })
1052
+ .replace(/\s/g, '\\s?') +
1053
+ o.timeSuffix + '$',
1054
+ order = getFormatPositions(f),
1055
+ ampm = '',
1056
+ treg;
1057
+
1058
+ treg = s.match(new RegExp(regstr, 'i'));
1059
+
1060
+ var resTime = {
1061
+ hour: 0,
1062
+ minute: 0,
1063
+ second: 0,
1064
+ millisec: 0
1065
+ };
1066
+
1067
+ if (treg) {
1068
+ if (order.t !== -1) {
1069
+ if (treg[order.t] === undefined || treg[order.t].length === 0) {
1070
+ ampm = '';
1071
+ resTime.ampm = '';
1072
+ } else {
1073
+ ampm = $.inArray(treg[order.t].toUpperCase(), o.amNames) !== -1 ? 'AM' : 'PM';
1074
+ resTime.ampm = o[ampm == 'AM' ? 'amNames' : 'pmNames'][0];
1075
+ }
1076
+ }
1077
+
1078
+ if (order.h !== -1) {
1079
+ if (ampm == 'AM' && treg[order.h] == '12') {
1080
+ resTime.hour = 0; // 12am = 0 hour
1081
+ } else {
1082
+ if (ampm == 'PM' && treg[order.h] != '12') {
1083
+ resTime.hour = parseInt(treg[order.h], 10) + 12; // 12pm = 12 hour, any other pm = hour + 12
1084
+ } else {
1085
+ resTime.hour = Number(treg[order.h]);
1086
+ }
1087
+ }
1088
+ }
1089
+
1090
+ if (order.m !== -1) {
1091
+ resTime.minute = Number(treg[order.m]);
1092
+ }
1093
+ if (order.s !== -1) {
1094
+ resTime.second = Number(treg[order.s]);
1095
+ }
1096
+ if (order.l !== -1) {
1097
+ resTime.millisec = Number(treg[order.l]);
1098
+ }
1099
+ if (order.z !== -1 && treg[order.z] !== undefined) {
1100
+ var tz = treg[order.z].toUpperCase();
1101
+ switch (tz.length) {
1102
+ case 1:
1103
+ // Z
1104
+ tz = o.timezoneIso8601 ? 'Z' : '+0000';
1105
+ break;
1106
+ case 5:
1107
+ // +hhmm
1108
+ if (o.timezoneIso8601) {
1109
+ tz = tz.substring(1) == '0000' ? 'Z' : tz.substring(0, 3) + ':' + tz.substring(3);
1110
+ }
1111
+ break;
1112
+ case 6:
1113
+ // +hh:mm
1114
+ if (!o.timezoneIso8601) {
1115
+ tz = tz == 'Z' || tz.substring(1) == '00:00' ? '+0000' : tz.replace(/:/, '');
1116
+ } else {
1117
+ if (tz.substring(1) == '00:00') {
1118
+ tz = 'Z';
1119
+ }
1120
+ }
1121
+ break;
1122
+ }
1123
+ resTime.timezone = tz;
1124
+ }
1125
+
1126
+
1127
+ return resTime;
1128
+ }
1129
+ return false;
1130
+ };// end strictParse
1131
+
1132
+ // First try JS Date, if that fails, use strictParse
1133
+ var looseParse = function(f,s,o){
1134
+ try{
1135
+ var d = new Date('2012-01-01 '+ s);
1136
+ if(isNaN(d.getTime())){
1137
+ d = new Date('2012-01-01T'+ s);
1138
+ if(isNaN(d.getTime())){
1139
+ d = new Date('01/01/2012 '+ s);
1140
+ if(isNaN(d.getTime())){
1141
+ throw "Unable to parse time with native Date: "+ s;
1142
+ }
1143
+ }
1144
+ }
1145
+
1146
+ return {
1147
+ hour: d.getHours(),
1148
+ minute: d.getMinutes(),
1149
+ second: d.getSeconds(),
1150
+ millisec: d.getMilliseconds(),
1151
+ timezone: $.timepicker.timeZoneOffsetString(d)
1152
+ };
1153
+ }
1154
+ catch(err){
1155
+ try{
1156
+ return strictParse(f,s,o);
1157
+ }
1158
+ catch(err2){
1159
+ $.datepicker.log("Unable to parse \ntimeString: "+ s +"\ntimeFormat: "+ f);
1160
+ }
1161
+ }
1162
+ return false;
1163
+ }; // end looseParse
1164
+
1165
+ if(typeof o.parse === "function"){
1166
+ return o.parse(timeFormat, timeString, o)
1167
+ }
1168
+ if(o.parse === 'loose'){
1169
+ return looseParse(timeFormat, timeString, o);
1170
+ }
1171
+ return strictParse(timeFormat, timeString, o);
1172
+ };
1173
+
1174
+ /*
1175
+ * Public utility to format the time
1176
+ * format = string format of the time
1177
+ * time = a {}, not a Date() for timezones
1178
+ * options = essentially the regional[].. amNames, pmNames, ampm
1179
+ */
1180
+ $.datepicker.formatTime = function(format, time, options) {
1181
+ options = options || {};
1182
+ options = $.extend({}, $.timepicker._defaults, options);
1183
+ time = $.extend({
1184
+ hour: 0,
1185
+ minute: 0,
1186
+ second: 0,
1187
+ millisec: 0,
1188
+ timezone: '+0000'
1189
+ }, time);
1190
+
1191
+ var tmptime = format,
1192
+ ampmName = options.amNames[0],
1193
+ hour = parseInt(time.hour, 10);
1194
+
1195
+ if (hour > 11) {
1196
+ ampmName = options.pmNames[0];
1197
+ }
1198
+
1199
+ tmptime = tmptime.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[lz]|('.*?'|".*?"))/g, function(match) {
1200
+ switch (match) {
1201
+ case 'HH':
1202
+ return ('0' + hour).slice(-2);
1203
+ case 'H':
1204
+ return hour;
1205
+ case 'hh':
1206
+ return ('0' + convert24to12(hour)).slice(-2);
1207
+ case 'h':
1208
+ return convert24to12(hour);
1209
+ case 'mm':
1210
+ return ('0' + time.minute).slice(-2);
1211
+ case 'm':
1212
+ return time.minute;
1213
+ case 'ss':
1214
+ return ('0' + time.second).slice(-2);
1215
+ case 's':
1216
+ return time.second;
1217
+ case 'l':
1218
+ return ('00' + time.millisec).slice(-3);
1219
+ case 'z':
1220
+ return time.timezone === null? options.defaultTimezone : time.timezone;
1221
+ case 'T':
1222
+ return ampmName.charAt(0).toUpperCase();
1223
+ case 'TT':
1224
+ return ampmName.toUpperCase();
1225
+ case 't':
1226
+ return ampmName.charAt(0).toLowerCase();
1227
+ case 'tt':
1228
+ return ampmName.toLowerCase();
1229
+ default:
1230
+ return match.replace(/\'/g, "") || "'";
1231
+ }
1232
+ });
1233
+
1234
+ tmptime = $.trim(tmptime);
1235
+ return tmptime;
1236
+ };
1237
+
1238
+ /*
1239
+ * the bad hack :/ override datepicker so it doesnt close on select
1240
+ // inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378
1241
+ */
1242
+ $.datepicker._base_selectDate = $.datepicker._selectDate;
1243
+ $.datepicker._selectDate = function(id, dateStr) {
1244
+ var inst = this._getInst($(id)[0]),
1245
+ tp_inst = this._get(inst, 'timepicker');
1246
+
1247
+ if (tp_inst) {
1248
+ tp_inst._limitMinMaxDateTime(inst, true);
1249
+ inst.inline = inst.stay_open = true;
1250
+ //This way the onSelect handler called from calendarpicker get the full dateTime
1251
+ this._base_selectDate(id, dateStr);
1252
+ inst.inline = inst.stay_open = false;
1253
+ this._notifyChange(inst);
1254
+ this._updateDatepicker(inst);
1255
+ } else {
1256
+ this._base_selectDate(id, dateStr);
1257
+ }
1258
+ };
1259
+
1260
+ /*
1261
+ * second bad hack :/ override datepicker so it triggers an event when changing the input field
1262
+ * and does not redraw the datepicker on every selectDate event
1263
+ */
1264
+ $.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker;
1265
+ $.datepicker._updateDatepicker = function(inst) {
1266
+
1267
+ // don't popup the datepicker if there is another instance already opened
1268
+ var input = inst.input[0];
1269
+ if ($.datepicker._curInst && $.datepicker._curInst != inst && $.datepicker._datepickerShowing && $.datepicker._lastInput != input) {
1270
+ return;
1271
+ }
1272
+
1273
+ if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {
1274
+
1275
+ this._base_updateDatepicker(inst);
1276
+
1277
+ // Reload the time control when changing something in the input text field.
1278
+ var tp_inst = this._get(inst, 'timepicker');
1279
+ if (tp_inst) {
1280
+ tp_inst._addTimePicker(inst);
1281
+
1282
+ // if (tp_inst._defaults.useLocalTimezone) { //checks daylight saving with the new date.
1283
+ // var date = new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay, 12);
1284
+ // selectLocalTimeZone(tp_inst, date);
1285
+ // tp_inst._onTimeChange();
1286
+ // }
1287
+ }
1288
+ }
1289
+ };
1290
+
1291
+ /*
1292
+ * third bad hack :/ override datepicker so it allows spaces and colon in the input field
1293
+ */
1294
+ $.datepicker._base_doKeyPress = $.datepicker._doKeyPress;
1295
+ $.datepicker._doKeyPress = function(event) {
1296
+ var inst = $.datepicker._getInst(event.target),
1297
+ tp_inst = $.datepicker._get(inst, 'timepicker');
1298
+
1299
+ if (tp_inst) {
1300
+ if ($.datepicker._get(inst, 'constrainInput')) {
1301
+ var ampm = useAmpm(tp_inst._defaults.timeFormat),
1302
+ dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
1303
+ datetimeChars = tp_inst._defaults.timeFormat.toString()
1304
+ .replace(/[hms]/g, '')
1305
+ .replace(/TT/g, ampm ? 'APM' : '')
1306
+ .replace(/Tt/g, ampm ? 'AaPpMm' : '')
1307
+ .replace(/tT/g, ampm ? 'AaPpMm' : '')
1308
+ .replace(/T/g, ampm ? 'AP' : '')
1309
+ .replace(/tt/g, ampm ? 'apm' : '')
1310
+ .replace(/t/g, ampm ? 'ap' : '') +
1311
+ " " + tp_inst._defaults.separator +
1312
+ tp_inst._defaults.timeSuffix +
1313
+ (tp_inst._defaults.showTimezone ? tp_inst._defaults.timezoneList.join('') : '') +
1314
+ (tp_inst._defaults.amNames.join('')) + (tp_inst._defaults.pmNames.join('')) +
1315
+ dateChars,
1316
+ chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
1317
+ return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1);
1318
+ }
1319
+ }
1320
+
1321
+ return $.datepicker._base_doKeyPress(event);
1322
+ };
1323
+
1324
+ /*
1325
+ * Fourth bad hack :/ override _updateAlternate function used in inline mode to init altField
1326
+ */
1327
+ $.datepicker._base_updateAlternate = $.datepicker._updateAlternate;
1328
+ /* Update any alternate field to synchronise with the main field. */
1329
+ $.datepicker._updateAlternate = function(inst) {
1330
+ var tp_inst = this._get(inst, 'timepicker');
1331
+ if(tp_inst){
1332
+ var altField = tp_inst._defaults.altField;
1333
+ if (altField) { // update alternate field too
1334
+ var altFormat = tp_inst._defaults.altFormat || tp_inst._defaults.dateFormat,
1335
+ date = this._getDate(inst),
1336
+ formatCfg = $.datepicker._getFormatConfig(inst),
1337
+ altFormattedDateTime = '',
1338
+ altSeparator = tp_inst._defaults.altSeparator ? tp_inst._defaults.altSeparator : tp_inst._defaults.separator,
1339
+ altTimeSuffix = tp_inst._defaults.altTimeSuffix ? tp_inst._defaults.altTimeSuffix : tp_inst._defaults.timeSuffix,
1340
+ altTimeFormat = tp_inst._defaults.altTimeFormat !== null ? tp_inst._defaults.altTimeFormat : tp_inst._defaults.timeFormat;
1341
+
1342
+ altFormattedDateTime += $.datepicker.formatTime(altTimeFormat, tp_inst, tp_inst._defaults) + altTimeSuffix;
1343
+ if(!tp_inst._defaults.timeOnly && !tp_inst._defaults.altFieldTimeOnly && date !== null){
1344
+ if(tp_inst._defaults.altFormat)
1345
+ altFormattedDateTime = $.datepicker.formatDate(tp_inst._defaults.altFormat, date, formatCfg) + altSeparator + altFormattedDateTime;
1346
+ else altFormattedDateTime = tp_inst.formattedDate + altSeparator + altFormattedDateTime;
1347
+ }
1348
+ $(altField).val(altFormattedDateTime);
1349
+ }
1350
+ }
1351
+ else{
1352
+ $.datepicker._base_updateAlternate(inst);
1353
+ }
1354
+ };
1355
+
1356
+ /*
1357
+ * Override key up event to sync manual input changes.
1358
+ */
1359
+ $.datepicker._base_doKeyUp = $.datepicker._doKeyUp;
1360
+ $.datepicker._doKeyUp = function(event) {
1361
+ var inst = $.datepicker._getInst(event.target),
1362
+ tp_inst = $.datepicker._get(inst, 'timepicker');
1363
+
1364
+ if (tp_inst) {
1365
+ if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) {
1366
+ try {
1367
+ $.datepicker._updateDatepicker(inst);
1368
+ } catch (err) {
1369
+ $.datepicker.log(err);
1370
+ }
1371
+ }
1372
+ }
1373
+
1374
+ return $.datepicker._base_doKeyUp(event);
1375
+ };
1376
+
1377
+ /*
1378
+ * override "Today" button to also grab the time.
1379
+ */
1380
+ $.datepicker._base_gotoToday = $.datepicker._gotoToday;
1381
+ $.datepicker._gotoToday = function(id) {
1382
+ var inst = this._getInst($(id)[0]),
1383
+ $dp = inst.dpDiv;
1384
+ this._base_gotoToday(id);
1385
+ var tp_inst = this._get(inst, 'timepicker');
1386
+ selectLocalTimeZone(tp_inst);
1387
+ var now = new Date();
1388
+ this._setTime(inst, now);
1389
+ $('.ui-datepicker-today', $dp).click();
1390
+ };
1391
+
1392
+ /*
1393
+ * Disable & enable the Time in the datetimepicker
1394
+ */
1395
+ $.datepicker._disableTimepickerDatepicker = function(target) {
1396
+ var inst = this._getInst(target);
1397
+ if (!inst) {
1398
+ return;
1399
+ }
1400
+
1401
+ var tp_inst = this._get(inst, 'timepicker');
1402
+ $(target).datepicker('getDate'); // Init selected[Year|Month|Day]
1403
+ if (tp_inst) {
1404
+ tp_inst._defaults.showTimepicker = false;
1405
+ tp_inst._updateDateTime(inst);
1406
+ }
1407
+ };
1408
+
1409
+ $.datepicker._enableTimepickerDatepicker = function(target) {
1410
+ var inst = this._getInst(target);
1411
+ if (!inst) {
1412
+ return;
1413
+ }
1414
+
1415
+ var tp_inst = this._get(inst, 'timepicker');
1416
+ $(target).datepicker('getDate'); // Init selected[Year|Month|Day]
1417
+ if (tp_inst) {
1418
+ tp_inst._defaults.showTimepicker = true;
1419
+ tp_inst._addTimePicker(inst); // Could be disabled on page load
1420
+ tp_inst._updateDateTime(inst);
1421
+ }
1422
+ };
1423
+
1424
+ /*
1425
+ * Create our own set time function
1426
+ */
1427
+ $.datepicker._setTime = function(inst, date) {
1428
+ var tp_inst = this._get(inst, 'timepicker');
1429
+ if (tp_inst) {
1430
+ var defaults = tp_inst._defaults;
1431
+
1432
+ // calling _setTime with no date sets time to defaults
1433
+ tp_inst.hour = date ? date.getHours() : defaults.hour;
1434
+ tp_inst.minute = date ? date.getMinutes() : defaults.minute;
1435
+ tp_inst.second = date ? date.getSeconds() : defaults.second;
1436
+ tp_inst.millisec = date ? date.getMilliseconds() : defaults.millisec;
1437
+
1438
+ //check if within min/max times..
1439
+ tp_inst._limitMinMaxDateTime(inst, true);
1440
+
1441
+ tp_inst._onTimeChange();
1442
+ tp_inst._updateDateTime(inst);
1443
+ }
1444
+ };
1445
+
1446
+ /*
1447
+ * Create new public method to set only time, callable as $().datepicker('setTime', date)
1448
+ */
1449
+ $.datepicker._setTimeDatepicker = function(target, date, withDate) {
1450
+ var inst = this._getInst(target);
1451
+ if (!inst) {
1452
+ return;
1453
+ }
1454
+
1455
+ var tp_inst = this._get(inst, 'timepicker');
1456
+
1457
+ if (tp_inst) {
1458
+ this._setDateFromField(inst);
1459
+ var tp_date;
1460
+ if (date) {
1461
+ if (typeof date == "string") {
1462
+ tp_inst._parseTime(date, withDate);
1463
+ tp_date = new Date();
1464
+ tp_date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
1465
+ } else {
1466
+ tp_date = new Date(date.getTime());
1467
+ }
1468
+ if (tp_date.toString() == 'Invalid Date') {
1469
+ tp_date = undefined;
1470
+ }
1471
+ this._setTime(inst, tp_date);
1472
+ }
1473
+ }
1474
+
1475
+ };
1476
+
1477
+ /*
1478
+ * override setDate() to allow setting time too within Date object
1479
+ */
1480
+ $.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker;
1481
+ $.datepicker._setDateDatepicker = function(target, date) {
1482
+ var inst = this._getInst(target);
1483
+ if (!inst) {
1484
+ return;
1485
+ }
1486
+
1487
+ var tp_date = (date instanceof Date) ? new Date(date.getTime()) : date;
1488
+
1489
+ this._updateDatepicker(inst);
1490
+ this._base_setDateDatepicker.apply(this, arguments);
1491
+ this._setTimeDatepicker(target, tp_date, true);
1492
+ };
1493
+
1494
+ /*
1495
+ * override getDate() to allow getting time too within Date object
1496
+ */
1497
+ $.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker;
1498
+ $.datepicker._getDateDatepicker = function(target, noDefault) {
1499
+ var inst = this._getInst(target);
1500
+ if (!inst) {
1501
+ return;
1502
+ }
1503
+
1504
+ var tp_inst = this._get(inst, 'timepicker');
1505
+
1506
+ if (tp_inst) {
1507
+ // if it hasn't yet been defined, grab from field
1508
+ if(inst.lastVal === undefined){
1509
+ this._setDateFromField(inst, noDefault);
1510
+ }
1511
+
1512
+ var date = this._getDate(inst);
1513
+ if (date && tp_inst._parseTime($(target).val(), tp_inst.timeOnly)) {
1514
+ date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
1515
+ }
1516
+ return date;
1517
+ }
1518
+ return this._base_getDateDatepicker(target, noDefault);
1519
+ };
1520
+
1521
+ /*
1522
+ * override parseDate() because UI 1.8.14 throws an error about "Extra characters"
1523
+ * An option in datapicker to ignore extra format characters would be nicer.
1524
+ */
1525
+ $.datepicker._base_parseDate = $.datepicker.parseDate;
1526
+ $.datepicker.parseDate = function(format, value, settings) {
1527
+ var date;
1528
+ try {
1529
+ date = this._base_parseDate(format, value, settings);
1530
+ } catch (err) {
1531
+ // Hack! The error message ends with a colon, a space, and
1532
+ // the "extra" characters. We rely on that instead of
1533
+ // attempting to perfectly reproduce the parsing algorithm.
1534
+ date = this._base_parseDate(format, value.substring(0,value.length-(err.length-err.indexOf(':')-2)), settings);
1535
+ $.datepicker.log("Error parsing the date string: " + err + "\ndate string = " + value + "\ndate format = " + format);
1536
+ }
1537
+ return date;
1538
+ };
1539
+
1540
+ /*
1541
+ * override formatDate to set date with time to the input
1542
+ */
1543
+ $.datepicker._base_formatDate = $.datepicker._formatDate;
1544
+ $.datepicker._formatDate = function(inst, day, month, year) {
1545
+ var tp_inst = this._get(inst, 'timepicker');
1546
+ if (tp_inst) {
1547
+ tp_inst._updateDateTime(inst);
1548
+ return tp_inst.$input.val();
1549
+ }
1550
+ return this._base_formatDate(inst);
1551
+ };
1552
+
1553
+ /*
1554
+ * override options setter to add time to maxDate(Time) and minDate(Time). MaxDate
1555
+ */
1556
+ $.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker;
1557
+ $.datepicker._optionDatepicker = function(target, name, value) {
1558
+ var inst = this._getInst(target),
1559
+ name_clone;
1560
+ if (!inst) {
1561
+ return null;
1562
+ }
1563
+
1564
+ var tp_inst = this._get(inst, 'timepicker');
1565
+ if (tp_inst) {
1566
+ var min = null,
1567
+ max = null,
1568
+ onselect = null,
1569
+ overrides = tp_inst._defaults.evnts,
1570
+ fns = {},
1571
+ prop;
1572
+ if (typeof name == 'string') { // if min/max was set with the string
1573
+ if (name === 'minDate' || name === 'minDateTime') {
1574
+ min = value;
1575
+ } else if (name === 'maxDate' || name === 'maxDateTime') {
1576
+ max = value;
1577
+ } else if (name === 'onSelect') {
1578
+ onselect = value;
1579
+ } else if (overrides.hasOwnProperty(name)) {
1580
+ if (typeof (value) === 'undefined') {
1581
+ return overrides[name];
1582
+ }
1583
+ fns[name] = value;
1584
+ name_clone = {}; //empty results in exiting function after overrides updated
1585
+ }
1586
+ } else if (typeof name == 'object') { //if min/max was set with the JSON
1587
+ if (name.minDate) {
1588
+ min = name.minDate;
1589
+ } else if (name.minDateTime) {
1590
+ min = name.minDateTime;
1591
+ } else if (name.maxDate) {
1592
+ max = name.maxDate;
1593
+ } else if (name.maxDateTime) {
1594
+ max = name.maxDateTime;
1595
+ }
1596
+ for (prop in overrides) {
1597
+ if (overrides.hasOwnProperty(prop) && name[prop]) {
1598
+ fns[prop] = name[prop];
1599
+ }
1600
+ }
1601
+ }
1602
+ for (prop in fns) {
1603
+ if (fns.hasOwnProperty(prop)) {
1604
+ overrides[prop] = fns[prop];
1605
+ if (!name_clone) { name_clone = $.extend({}, name);}
1606
+ delete name_clone[prop];
1607
+ }
1608
+ }
1609
+ if (name_clone && isEmptyObject(name_clone)) { return; }
1610
+ if (min) { //if min was set
1611
+ if (min === 0) {
1612
+ min = new Date();
1613
+ } else {
1614
+ min = new Date(min);
1615
+ }
1616
+ tp_inst._defaults.minDate = min;
1617
+ tp_inst._defaults.minDateTime = min;
1618
+ } else if (max) { //if max was set
1619
+ if (max === 0) {
1620
+ max = new Date();
1621
+ } else {
1622
+ max = new Date(max);
1623
+ }
1624
+ tp_inst._defaults.maxDate = max;
1625
+ tp_inst._defaults.maxDateTime = max;
1626
+ } else if (onselect) {
1627
+ tp_inst._defaults.onSelect = onselect;
1628
+ }
1629
+ }
1630
+ if (value === undefined) {
1631
+ return this._base_optionDatepicker.call($.datepicker, target, name);
1632
+ }
1633
+ return this._base_optionDatepicker.call($.datepicker, target, name_clone || name, value);
1634
+ };
1635
+ /*
1636
+ * jQuery isEmptyObject does not check hasOwnProperty - if someone has added to the object prototype,
1637
+ * it will return false for all objects
1638
+ */
1639
+ var isEmptyObject = function(obj) {
1640
+ var prop;
1641
+ for (prop in obj) {
1642
+ if (obj.hasOwnProperty(obj)) {
1643
+ return false;
1644
+ }
1645
+ }
1646
+ return true;
1647
+ };
1648
+
1649
+ /*
1650
+ * jQuery extend now ignores nulls!
1651
+ */
1652
+ var extendRemove = function(target, props) {
1653
+ $.extend(target, props);
1654
+ for (var name in props) {
1655
+ if (props[name] === null || props[name] === undefined) {
1656
+ target[name] = props[name];
1657
+ }
1658
+ }
1659
+ return target;
1660
+ };
1661
+
1662
+ /*
1663
+ * Determine by the time format if should use ampm
1664
+ * Returns true if should use ampm, false if not
1665
+ */
1666
+ var useAmpm = function(timeFormat){
1667
+ return (timeFormat.indexOf('t') !== -1 && timeFormat.indexOf('h') !== -1);
1668
+ };
1669
+
1670
+ /*
1671
+ * Converts 24 hour format into 12 hour
1672
+ * Returns 12 hour without leading 0
1673
+ */
1674
+ var convert24to12 = function(hour) {
1675
+ if (hour > 12) {
1676
+ hour = hour - 12;
1677
+ }
1678
+
1679
+ if (hour == 0) {
1680
+ hour = 12;
1681
+ }
1682
+
1683
+ return String(hour);
1684
+ };
1685
+
1686
+ /*
1687
+ * Splits datetime string into date ans time substrings.
1688
+ * Throws exception when date can't be parsed
1689
+ * Returns [dateString, timeString]
1690
+ */
1691
+ var splitDateTime = function(dateFormat, dateTimeString, dateSettings, timeSettings) {
1692
+ try {
1693
+ // The idea is to get the number separator occurances in datetime and the time format requested (since time has
1694
+ // fewer unknowns, mostly numbers and am/pm). We will use the time pattern to split.
1695
+ var separator = timeSettings && timeSettings.separator ? timeSettings.separator : $.timepicker._defaults.separator,
1696
+ format = timeSettings && timeSettings.timeFormat ? timeSettings.timeFormat : $.timepicker._defaults.timeFormat,
1697
+ timeParts = format.split(separator), // how many occurances of separator may be in our format?
1698
+ timePartsLen = timeParts.length,
1699
+ allParts = dateTimeString.split(separator),
1700
+ allPartsLen = allParts.length;
1701
+
1702
+ if (allPartsLen > 1) {
1703
+ return [
1704
+ allParts.splice(0,allPartsLen-timePartsLen).join(separator),
1705
+ allParts.splice(0,timePartsLen).join(separator)
1706
+ ];
1707
+ }
1708
+
1709
+ } catch (err) {
1710
+ $.datepicker.log('Could not split the date from the time. Please check the following datetimepicker options' +
1711
+ "\nthrown error: " + err +
1712
+ "\ndateTimeString" + dateTimeString +
1713
+ "\ndateFormat = " + dateFormat +
1714
+ "\nseparator = " + timeSettings.separator +
1715
+ "\ntimeFormat = " + timeSettings.timeFormat);
1716
+
1717
+ if (err.indexOf(":") >= 0) {
1718
+ // Hack! The error message ends with a colon, a space, and
1719
+ // the "extra" characters. We rely on that instead of
1720
+ // attempting to perfectly reproduce the parsing algorithm.
1721
+ var dateStringLength = dateTimeString.length - (err.length - err.indexOf(':') - 2),
1722
+ timeString = dateTimeString.substring(dateStringLength);
1723
+
1724
+ return [$.trim(dateTimeString.substring(0, dateStringLength)), $.trim(dateTimeString.substring(dateStringLength))];
1725
+
1726
+ } else {
1727
+ throw err;
1728
+ }
1729
+ }
1730
+ return [dateTimeString, ''];
1731
+ };
1732
+
1733
+ /*
1734
+ * Internal function to parse datetime interval
1735
+ * Returns: {date: Date, timeObj: Object}, where
1736
+ * date - parsed date without time (type Date)
1737
+ * timeObj = {hour: , minute: , second: , millisec: } - parsed time. Optional
1738
+ */
1739
+ var parseDateTimeInternal = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) {
1740
+ var date;
1741
+ var splitRes = splitDateTime(dateFormat, dateTimeString, dateSettings, timeSettings);
1742
+ date = $.datepicker._base_parseDate(dateFormat, splitRes[0], dateSettings);
1743
+ if (splitRes[1] !== '') {
1744
+ var timeString = splitRes[1],
1745
+ parsedTime = $.datepicker.parseTime(timeFormat, timeString, timeSettings);
1746
+
1747
+ if (parsedTime === null) {
1748
+ throw 'Wrong time format';
1749
+ }
1750
+ return {
1751
+ date: date,
1752
+ timeObj: parsedTime
1753
+ };
1754
+ } else {
1755
+ return {
1756
+ date: date
1757
+ };
1758
+ }
1759
+ };
1760
+
1761
+ /*
1762
+ * Internal function to set timezone_select to the local timezone
1763
+ */
1764
+ var selectLocalTimeZone = function(tp_inst, date) {
1765
+ if (tp_inst && tp_inst.timezone_select) {
1766
+ tp_inst._defaults.useLocalTimezone = true;
1767
+ var now = typeof date !== 'undefined' ? date : new Date();
1768
+ var tzoffset = $.timepicker.timeZoneOffsetString(now);
1769
+ if (tp_inst._defaults.timezoneIso8601) {
1770
+ tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3);
1771
+ }
1772
+ tp_inst.timezone_select.val(tzoffset);
1773
+ }
1774
+ };
1775
+
1776
+ /*
1777
+ * Create a Singleton Insance
1778
+ */
1779
+ $.timepicker = new Timepicker();
1780
+
1781
+ /**
1782
+ * Get the timezone offset as string from a date object (eg '+0530' for UTC+5.5)
1783
+ * @param date
1784
+ * @return string
1785
+ */
1786
+ $.timepicker.timeZoneOffsetString = function(date) {
1787
+ var off = date.getTimezoneOffset() * -1,
1788
+ minutes = off % 60,
1789
+ hours = (off - minutes) / 60;
1790
+ return (off >= 0 ? '+' : '-') + ('0' + (hours * 101).toString()).slice(-2) + ('0' + (minutes * 101).toString()).slice(-2);
1791
+ };
1792
+
1793
+ /**
1794
+ * Calls `timepicker()` on the `startTime` and `endTime` elements, and configures them to
1795
+ * enforce date range limits.
1796
+ * n.b. The input value must be correctly formatted (reformatting is not supported)
1797
+ * @param Element startTime
1798
+ * @param Element endTime
1799
+ * @param obj options Options for the timepicker() call
1800
+ * @return jQuery
1801
+ */
1802
+ $.timepicker.timeRange = function(startTime, endTime, options) {
1803
+ return $.timepicker.handleRange('timepicker', startTime, endTime, options);
1804
+ };
1805
+
1806
+ /**
1807
+ * Calls `datetimepicker` on the `startTime` and `endTime` elements, and configures them to
1808
+ * enforce date range limits.
1809
+ * @param Element startTime
1810
+ * @param Element endTime
1811
+ * @param obj options Options for the `timepicker()` call. Also supports `reformat`,
1812
+ * a boolean value that can be used to reformat the input values to the `dateFormat`.
1813
+ * @param string method Can be used to specify the type of picker to be added
1814
+ * @return jQuery
1815
+ */
1816
+ $.timepicker.dateTimeRange = function(startTime, endTime, options) {
1817
+ $.timepicker.dateRange(startTime, endTime, options, 'datetimepicker');
1818
+ };
1819
+
1820
+ /**
1821
+ * Calls `method` on the `startTime` and `endTime` elements, and configures them to
1822
+ * enforce date range limits.
1823
+ * @param Element startTime
1824
+ * @param Element endTime
1825
+ * @param obj options Options for the `timepicker()` call. Also supports `reformat`,
1826
+ * a boolean value that can be used to reformat the input values to the `dateFormat`.
1827
+ * @param string method Can be used to specify the type of picker to be added
1828
+ * @return jQuery
1829
+ */
1830
+ $.timepicker.dateRange = function(startTime, endTime, options, method) {
1831
+ method = method || 'datepicker';
1832
+ $.timepicker.handleRange(method, startTime, endTime, options);
1833
+ };
1834
+
1835
+ /**
1836
+ * Calls `method` on the `startTime` and `endTime` elements, and configures them to
1837
+ * enforce date range limits.
1838
+ * @param string method Can be used to specify the type of picker to be added
1839
+ * @param Element startTime
1840
+ * @param Element endTime
1841
+ * @param obj options Options for the `timepicker()` call. Also supports `reformat`,
1842
+ * a boolean value that can be used to reformat the input values to the `dateFormat`.
1843
+ * @return jQuery
1844
+ */
1845
+ $.timepicker.handleRange = function(method, startTime, endTime, options) {
1846
+ $.fn[method].call(startTime, $.extend({
1847
+ onClose: function(dateText, inst) {
1848
+ checkDates(this, endTime, dateText);
1849
+ },
1850
+ onSelect: function(selectedDateTime) {
1851
+ selected(this, endTime, 'minDate');
1852
+ }
1853
+ }, options, options.start));
1854
+ $.fn[method].call(endTime, $.extend({
1855
+ onClose: function(dateText, inst) {
1856
+ checkDates(this, startTime, dateText);
1857
+ },
1858
+ onSelect: function(selectedDateTime) {
1859
+ selected(this, startTime, 'maxDate');
1860
+ }
1861
+ }, options, options.end));
1862
+ // timepicker doesn't provide access to its 'timeFormat' option,
1863
+ // nor could I get datepicker.formatTime() to behave with times, so I
1864
+ // have disabled reformatting for timepicker
1865
+ if (method != 'timepicker' && options.reformat) {
1866
+ $([startTime, endTime]).each(function() {
1867
+ var format = $(this)[method].call($(this), 'option', 'dateFormat'),
1868
+ date = new Date($(this).val());
1869
+ if ($(this).val() && date) {
1870
+ $(this).val($.datepicker.formatDate(format, date));
1871
+ }
1872
+ });
1873
+ }
1874
+ checkDates(startTime, endTime, startTime.val());
1875
+
1876
+ function checkDates(changed, other, dateText) {
1877
+ if (other.val() && (new Date(startTime.val()) > new Date(endTime.val()))) {
1878
+ other.val(dateText);
1879
+ }
1880
+ }
1881
+ selected(startTime, endTime, 'minDate');
1882
+ selected(endTime, startTime, 'maxDate');
1883
+
1884
+ function selected(changed, other, option) {
1885
+ if (!$(changed).val()) {
1886
+ return;
1887
+ }
1888
+ var date = $(changed)[method].call($(changed), 'getDate');
1889
+ // timepicker doesn't implement 'getDate' and returns a jQuery
1890
+ if (date.getTime) {
1891
+ $(other)[method].call($(other), 'option', option, date);
1892
+ }
1893
+ }
1894
+ return $([startTime.get(0), endTime.get(0)]);
1895
+ };
1896
+
1897
+ /*
1898
+ * Keep up with the version
1899
+ */
1900
+ $.timepicker.version = "1.1.2";
1901
+
1902
+ })(jQuery);