|
1 | 1 | /*
|
2 | 2 | * jQuery timepicker addon
|
3 | 3 | * By: Trent Richardson [http://trentrichardson.com]
|
4 |
| -* Version 0.6.3 |
5 |
| -* Last Modified: 10/1/2010 |
| 4 | +* Version 0.6.4 |
| 5 | +* Last Modified: 10/7/2010 |
6 | 6 | *
|
7 | 7 | * Copyright 2010 Trent Richardson
|
8 | 8 | * Dual licensed under the MIT and GPL licenses.
|
|
13 | 13 | * .ui-timepicker-div dl{ text-align: left; }
|
14 | 14 | * .ui-timepicker-div dl dt{ height: 25px; }
|
15 | 15 | * .ui-timepicker-div dl dd{ margin: -25px 0 10px 65px; }
|
| 16 | +* .ui-timepicker-div div:first-child { margin-left: 0.5em; margin-right: 0px; } |
| 17 | +* .ui-timepicker-div .ui_tpicker_hour div { padding-right: 2px; } |
| 18 | +* .ui-timepicker-div .ui_tpicker_minute div { padding-right: 6px; } |
| 19 | +* .ui-timepicker-div .ui_tpicker_second div { padding-right: 6px; } |
| 20 | +* .ui-timepicker-div td { font-size: 8pt; } |
16 | 21 | */
|
17 | 22 |
|
18 | 23 | (function($) {
|
|
48 | 53 | hourMax: 23,
|
49 | 54 | minuteMax: 59,
|
50 | 55 | secondMax: 59,
|
| 56 | + hourGrid: 0, |
| 57 | + minuteGrid: 0, |
| 58 | + secondGrid: 0, |
51 | 59 | alwaysSetTime: true
|
52 | 60 | };
|
53 | 61 | $.extend(this.defaults, this.regional['']);
|
|
59 | 67 |
|
60 | 68 | Timepicker.prototype = {
|
61 | 69 | $input: null,
|
| 70 | + $altInput: null, |
62 | 71 | $timeObj: null,
|
63 | 72 | inst: null,
|
64 | 73 | hour_slider: null,
|
|
77 | 86 | //########################################################################
|
78 | 87 | addTimePicker: function(dp_inst) {
|
79 | 88 | var tp_inst = this;
|
80 |
| - var currDT = this.$input.val(); |
| 89 | + var currDT |
| 90 | + if ((this.$altInput) && this.$altInput != null) |
| 91 | + { |
| 92 | + currDT = this.$input.val() + ' ' + this.$altInput.val(); |
| 93 | + } |
| 94 | + else |
| 95 | + { |
| 96 | + currDT = this.$input.val(); |
| 97 | + } |
81 | 98 | var regstr = this.defaults.timeFormat.toString()
|
82 | 99 | .replace(/h{1,2}/ig, '(\\d?\\d)')
|
83 | 100 | .replace(/m{1,2}/ig, '(\\d?\\d)')
|
|
169 | 186 | if ($dp.find("div#ui-timepicker-div-"+ dp_inst.id).length === 0) {
|
170 | 187 | var noDisplay = ' style="display:none;"';
|
171 | 188 | var html =
|
172 |
| - '<div class="ui-timepicker-div" id="ui-timepicker-div-'+ dp_inst.id +'"><dl>' + |
173 |
| - '<dt class="ui_tpicker_time_label" id="ui_tpicker_time_label_'+ dp_inst.id +'"' + ((opts.showTime) ? '' : noDisplay) + '>'+ opts.timeText +'</dt>' + |
174 |
| - '<dd class="ui_tpicker_time" id="ui_tpicker_time_'+ dp_inst.id +'"' + ((opts.showTime) ? '' : noDisplay) + '></dd>' + |
175 |
| - '<dt class="ui_tpicker_hour_label" id="ui_tpicker_hour_label_'+ dp_inst.id +'"' + ((opts.showHour) ? '' : noDisplay) + '>'+ opts.hourText +'</dt>' + |
176 |
| - '<dd class="ui_tpicker_hour" id="ui_tpicker_hour_'+ dp_inst.id +'"' + ((opts.showHour) ? '' : noDisplay) + '></dd>' + |
177 |
| - '<dt class="ui_tpicker_minute_label" id="ui_tpicker_minute_label_'+ dp_inst.id +'"' + ((opts.showMinute) ? '' : noDisplay) + '>'+ opts.minuteText +'</dt>' + |
178 |
| - '<dd class="ui_tpicker_minute" id="ui_tpicker_minute_'+ dp_inst.id +'"' + ((opts.showMinute) ? '' : noDisplay) + '></dd>' + |
179 |
| - '<dt class="ui_tpicker_second_label" id="ui_tpicker_second_label_'+ dp_inst.id +'"' + ((opts.showSecond) ? '' : noDisplay) + '>'+ opts.secondText +'</dt>' + |
180 |
| - '<dd class="ui_tpicker_second" id="ui_tpicker_second_'+ dp_inst.id +'"' + ((opts.showSecond) ? '' : noDisplay) + '></dd>' + |
181 |
| - '</dl></div>'; |
| 189 | + '<div class="ui-timepicker-div" id="ui-timepicker-div-' + dp_inst.id + '"><dl>' + |
| 190 | + '<dt class="ui_tpicker_time_label" id="ui_tpicker_time_label_' + dp_inst.id + '"' + ((opts.showTime) ? '' : noDisplay) + '>' + opts.timeText + '</dt>' + |
| 191 | + '<dd class="ui_tpicker_time" id="ui_tpicker_time_' + dp_inst.id + '"' + ((opts.showTime) ? '' : noDisplay) + '></dd>' + |
| 192 | + '<dt class="ui_tpicker_hour_label" id="ui_tpicker_hour_label_' + dp_inst.id + '"' + ((opts.showHour) ? '' : noDisplay) + '>' + opts.hourText + '</dt>'; |
| 193 | + |
| 194 | + if (opts.hourGrid > 0) |
| 195 | + { |
| 196 | + html += '<dd class="ui_tpicker_hour ui_tpicker_hour_' + opts.hourGrid + '">' + |
| 197 | + '<div id="ui_tpicker_hour_' + dp_inst.id + '"' + ((opts.showHour) ? '' : noDisplay) + '></div>' + |
| 198 | + '<div><table><tr>'; |
| 199 | + |
| 200 | + for (var h = 0; h < hourMax; h += opts.hourGrid) |
| 201 | + { |
| 202 | + var tmph = h; |
| 203 | + if(opts.ampm && h > 12) |
| 204 | + tmph = h-12; |
| 205 | + else tmph = h; |
| 206 | + |
| 207 | + if(tmph < 10) |
| 208 | + tmph = '0' + tmph; |
| 209 | + if(opts.ampm) |
| 210 | + { |
| 211 | + if(h == 0) |
| 212 | + tmph = 12 +'a'; |
| 213 | + else if(h < 12) |
| 214 | + tmph += 'a'; |
| 215 | + else tmph += 'p'; |
| 216 | + } |
| 217 | + html += '<td>' + tmph + '</td>'; |
| 218 | + } |
| 219 | + |
| 220 | + html += '</tr></table></div>' + |
| 221 | + '</dd>'; |
| 222 | + } |
| 223 | + else |
| 224 | + { |
| 225 | + html += '<dd class="ui_tpicker_hour" id="ui_tpicker_hour_' + dp_inst.id + '"' + ((opts.showHour) ? '' : noDisplay) + '></dd>'; |
| 226 | + } |
| 227 | + |
| 228 | + html += '<dt class="ui_tpicker_minute_label" id="ui_tpicker_minute_label_' + dp_inst.id + '"' + ((opts.showMinute) ? '' : noDisplay) + '>' + opts.minuteText + '</dt>'; |
| 229 | + |
| 230 | + if (opts.minuteGrid > 0) |
| 231 | + { |
| 232 | + html += '<dd class="ui_tpicker_minute ui_tpicker_minute_' + opts.minuteGrid + '">' + |
| 233 | + '<div id="ui_tpicker_minute_' + dp_inst.id + '"' + ((opts.showMinute) ? '' : noDisplay) + '></div>' + |
| 234 | + '<div><table><tr>'; |
| 235 | + |
| 236 | + for (var m = 0; m < minMax; m += opts.minuteGrid) |
| 237 | + { |
| 238 | + html += '<td>' + ((m < 10) ? '0' : '') + m + '</td>'; |
| 239 | + } |
| 240 | + |
| 241 | + html += '</tr></table></div>' + |
| 242 | + '</dd>'; |
| 243 | + } |
| 244 | + else |
| 245 | + { |
| 246 | + html += '<dd class="ui_tpicker_minute" id="ui_tpicker_minute_' + dp_inst.id + '"' + ((opts.showMinute) ? '' : noDisplay) + '></dd>' |
| 247 | + } |
| 248 | + |
| 249 | + html += '<dt class="ui_tpicker_second_label" id="ui_tpicker_second_label_' + dp_inst.id + '"' + ((opts.showSecond) ? '' : noDisplay) + '>' + opts.secondText + '</dt>'; |
| 250 | + |
| 251 | + if (opts.secondGrid > 0) |
| 252 | + { |
| 253 | + html += '<dd class="ui_tpicker_second ui_tpicker_second_' + opts.secondGrid + '">' + |
| 254 | + '<div id="ui_tpicker_second_' + dp_inst.id + '"' + ((opts.showSecond) ? '' : noDisplay) + '></div>' + |
| 255 | + '<table><table><tr>'; |
| 256 | + |
| 257 | + for (var s = 0; s < secMax; s += opts.secondGrid) |
| 258 | + { |
| 259 | + html += '<td>' + ((s < 10) ? '0' : '') + s + '</td>'; |
| 260 | + } |
| 261 | + |
| 262 | + html += '</tr></table></table>' + |
| 263 | + '</dd>'; |
| 264 | + } |
| 265 | + else |
| 266 | + { |
| 267 | + html += '<dd class="ui_tpicker_second" id="ui_tpicker_second_' + dp_inst.id + '"' + ((opts.showSecond) ? '' : noDisplay) + '></dd>'; |
| 268 | + } |
| 269 | + |
| 270 | + html += '</dl></div>'; |
182 | 271 | $tp = $(html);
|
183 | 272 |
|
184 | 273 | // if we only want time picker...
|
|
228 | 317 | tp_inst.onTimeChange(dp_inst, tp_inst);
|
229 | 318 | }
|
230 | 319 | });
|
231 |
| - |
| 320 | + |
| 321 | + // Add grid functionality |
| 322 | + $tp.find(".ui_tpicker_hour td").each( |
| 323 | + function(index) |
| 324 | + { |
| 325 | + $(this).click( |
| 326 | + function() |
| 327 | + { |
| 328 | + var h = $(this).html(); |
| 329 | + if(opts.ampm) |
| 330 | + { |
| 331 | + var ap = h.substring(2).toLowerCase(); |
| 332 | + var aph = new Number(h.substring(0,2)); |
| 333 | + |
| 334 | + if(ap == 'a'){ |
| 335 | + if(aph == 12) |
| 336 | + h = 0; |
| 337 | + else h = aph; |
| 338 | + }else{ |
| 339 | + if(aph == 12) |
| 340 | + h = 12; |
| 341 | + else h = aph + 12; |
| 342 | + } |
| 343 | + } |
| 344 | + tp_inst.hour_slider.slider("option", "value", h); |
| 345 | + tp_inst.onTimeChange(dp_inst, tp_inst); |
| 346 | + } |
| 347 | + ); |
| 348 | + |
| 349 | + $(this).css({ 'cursor': "pointer", 'width': '1%', 'text-align': 'left' }); |
| 350 | + } |
| 351 | + ); |
| 352 | + $tp.find(".ui_tpicker_minute td").each( |
| 353 | + function(index) |
| 354 | + { |
| 355 | + $(this).click( |
| 356 | + function() |
| 357 | + { |
| 358 | + tp_inst.minute_slider.slider("option", "value", $(this).html()); |
| 359 | + tp_inst.onTimeChange(dp_inst, tp_inst); |
| 360 | + } |
| 361 | + ); |
| 362 | + |
| 363 | + $(this).css({ 'cursor': "pointer", 'width': '1%', 'text-align': 'left' }); |
| 364 | + } |
| 365 | + ); |
| 366 | + $tp.find(".ui_tpicker_second td").each( |
| 367 | + function(index) |
| 368 | + { |
| 369 | + $(this).click( |
| 370 | + function() |
| 371 | + { |
| 372 | + tp_inst.second_slider.slider("option", "value", $(this).html()); |
| 373 | + tp_inst.onTimeChange(dp_inst, tp_inst); |
| 374 | + } |
| 375 | + ); |
| 376 | + $(this).css({ 'cursor': "pointer", 'width': '1%', 'text-align': 'left' }); |
| 377 | + } |
| 378 | + ); |
| 379 | + |
232 | 380 | $dp.find('.ui-datepicker-calendar').after($tp);
|
233 | 381 |
|
234 | 382 | tp_inst.$timeObj = $('#ui_tpicker_time_'+ dp_inst.id);
|
|
313 | 461 | // update our input with the new date time..
|
314 | 462 | //########################################################################
|
315 | 463 | updateDateTime: function(dp_inst, tp_inst) {
|
316 |
| - //var dt = this.$input.datepicker('getDate'); |
317 | 464 | var dt = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay);
|
318 | 465 | var dateFmt = $.datepicker._get(dp_inst, 'dateFormat');
|
319 | 466 | var formatCfg = $.datepicker._getFormatConfig(dp_inst);
|
|
327 | 474 | else if (this.defaults.timeOnly !== true && (this.defaults.alwaysSetTime || timeAvailable)) {
|
328 | 475 | formattedDateTime += ' ' + this.formattedTime;
|
329 | 476 | }
|
330 |
| - |
| 477 | + |
| 478 | + if ((this.$altInput) && this.$altInput != null) |
| 479 | + { |
| 480 | + this.$altInput.val(formattedDateTime); |
| 481 | + } |
| 482 | + |
331 | 483 | this.formattedDateTime = formattedDateTime;
|
332 | 484 | this.$input.val(formattedDateTime);
|
333 | 485 | this.$input.trigger("change");
|
|
366 | 518 | tp.second = tp.defaults.second;
|
367 | 519 | tp.ampm = '';
|
368 | 520 | tp.$input = $(input);
|
| 521 | + tp.$altInput = $($.datepicker._get(inst, 'altField')); |
369 | 522 | tp.inst = inst;
|
370 | 523 | tp.addTimePicker(inst);
|
371 | 524 | if ($.isFunction(opts.beforeShow)) {
|
|
0 commit comments