|
58 | 58 | this._defaults = { // Global defaults for all the datetime picker instances
|
59 | 59 | showButtonPanel: true,
|
60 | 60 | timeOnly: false,
|
61 |
| - showHour: true, |
62 |
| - showMinute: true, |
63 |
| - showSecond: false, |
64 |
| - showMillisec: false, |
65 |
| - showTimezone: false, |
| 61 | + showHour: null, |
| 62 | + showMinute: null, |
| 63 | + showSecond: null, |
| 64 | + showMillisec: null, |
| 65 | + showTimezone: null, |
66 | 66 | showTime: true,
|
67 | 67 | stepHour: 1,
|
68 | 68 | stepMinute: 1,
|
|
137 | 137 | formattedDateTime: '',
|
138 | 138 | timezoneList: null,
|
139 | 139 | units: ['hour','minute','second','millisec'],
|
| 140 | + support: {}, |
140 | 141 | control: null,
|
141 | 142 |
|
142 | 143 | /*
|
|
210 | 211 | return val.toUpperCase();
|
211 | 212 | });
|
212 | 213 |
|
| 214 | + // detect which units are supported |
| 215 | + tp_inst.support = detectSupport( |
| 216 | + tp_inst._defaults.timeFormat + |
| 217 | + (tp_inst._defaults.pickerTimeFormat? tp_inst._defaults.pickerTimeFormat:'') + |
| 218 | + (tp_inst._defaults.altTimeFormat? tp_inst._defaults.altTimeFormat:'')); |
| 219 | + |
213 | 220 | // controlType is string - key to our this._controls
|
214 | 221 | if(typeof(tp_inst._defaults.controlType) === 'string'){
|
215 | 222 | if($.fn[tp_inst._defaults.controlType] === undefined){
|
|
336 | 343 | tp_inst = this,
|
337 | 344 | litem = '',
|
338 | 345 | uitem = '',
|
| 346 | + show = null, |
339 | 347 | max = {},
|
340 | 348 | gridSize = {},
|
341 | 349 | size = null,
|
|
352 | 360 | for(i=0,l=this.units.length; i<l; i++){
|
353 | 361 | litem = this.units[i];
|
354 | 362 | uitem = litem.substr(0,1).toUpperCase() + litem.substr(1);
|
| 363 | + show = o['show'+uitem] !== null? o['show'+uitem] : this.support[litem]; |
| 364 | + |
355 | 365 | // Added by Peter Medeiros:
|
356 | 366 | // - Figure out what the hour/minute/second max should be based on the step values.
|
357 | 367 | // - Example: if stepMinute is 15, then minMax is 45.
|
358 | 368 | max[litem] = parseInt((o[litem+'Max'] - ((o[litem+'Max'] - o[litem+'Min']) % o['step'+uitem])), 10);
|
359 | 369 | gridSize[litem] = 0;
|
360 | 370 |
|
361 |
| - html += '<dt class="ui_tpicker_'+ litem +'_label"' + ((o['show'+uitem]) ? '' : noDisplay) + '>' + o[litem +'Text'] + '</dt>' + |
362 |
| - '<dd class="ui_tpicker_'+ litem +'"><div class="ui_tpicker_'+ litem +'_slider"' + ((o['show'+uitem]) ? '' : noDisplay) + '></div>'; |
| 371 | + html += '<dt class="ui_tpicker_'+ litem +'_label"' + (show ? '' : noDisplay) + '>' + o[litem +'Text'] + '</dt>' + |
| 372 | + '<dd class="ui_tpicker_'+ litem +'"><div class="ui_tpicker_'+ litem +'_slider"' + (show ? '' : noDisplay) + '></div>'; |
363 | 373 |
|
364 |
| - if (o['show'+uitem] && o[litem+'Grid'] > 0) { |
| 374 | + if (show && o[litem+'Grid'] > 0) { |
365 | 375 | html += '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>';
|
366 | 376 |
|
367 | 377 | if(litem == 'hour'){
|
368 | 378 | for (var h = o[litem+'Min']; h <= max[litem]; h += parseInt(o[litem+'Grid'], 10)) {
|
369 | 379 | gridSize[litem]++;
|
370 |
| - var tmph = $.datepicker.formatTime(useAmpm(o.pickerTimeFormat || o.timeFormat)? 'hht':'HH', {hour:h}, o); |
| 380 | + var tmph = $.datepicker.formatTime(this.support.ampm? 'hht':'HH', {hour:h}, o); |
371 | 381 | html += '<td data-for="'+litem+'">' + tmph + '</td>';
|
372 | 382 | }
|
373 | 383 | }
|
|
384 | 394 | }
|
385 | 395 |
|
386 | 396 | // Timezone
|
387 |
| - html += '<dt class="ui_tpicker_timezone_label"' + ((o.showTimezone) ? '' : noDisplay) + '>' + o.timezoneText + '</dt>'; |
388 |
| - html += '<dd class="ui_tpicker_timezone" ' + ((o.showTimezone) ? '' : noDisplay) + '></dd>'; |
| 397 | + var showTz = o.showTimezone !== null? o.showTimezone : this.support.timezone; |
| 398 | + html += '<dt class="ui_tpicker_timezone_label"' + (showTz ? '' : noDisplay) + '>' + o.timezoneText + '</dt>'; |
| 399 | + html += '<dd class="ui_tpicker_timezone" ' + (showTz ? '' : noDisplay) + '></dd>'; |
389 | 400 |
|
390 | 401 | // Create the elements from string
|
391 | 402 | html += '</dl></div>';
|
|
401 | 412 | for(i=0,l=tp_inst.units.length; i<l; i++){
|
402 | 413 | litem = tp_inst.units[i];
|
403 | 414 | uitem = litem.substr(0,1).toUpperCase() + litem.substr(1);
|
| 415 | + show = o['show'+uitem] !== null? o['show'+uitem] : this.support[litem]; |
404 | 416 |
|
405 | 417 | // add the slider
|
406 | 418 | 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]);
|
407 | 419 |
|
408 | 420 | // adjust the grid and add click event
|
409 |
| - if (o['show'+uitem] && o[litem+'Grid'] > 0) { |
| 421 | + if (show && o[litem+'Grid'] > 0) { |
410 | 422 | size = 100 * gridSize[litem] * o[litem+'Grid'] / (max[litem] - o[litem+'Min']);
|
411 | 423 | $tp.find('.ui_tpicker_'+litem+' table').css({
|
412 | 424 | width: size + "%",
|
|
722 | 734 |
|
723 | 735 | this._limitMinMaxDateTime(this.inst, true);
|
724 | 736 | }
|
725 |
| - if (useAmpm(o.timeFormat)) { |
| 737 | + if (this.support.ampm) { |
726 | 738 | this.ampm = ampm;
|
727 | 739 | }
|
728 | 740 |
|
|
1318 | 1330 |
|
1319 | 1331 | if (tp_inst) {
|
1320 | 1332 | if ($.datepicker._get(inst, 'constrainInput')) {
|
1321 |
| - var ampm = useAmpm(tp_inst._defaults.timeFormat), |
| 1333 | + var ampm = tp_inst.support.ampm, |
| 1334 | + tz = tp_inst._defaults.showTimezone !== null? tp_inst._defaults.showTimezone : tp_inst.support.timezone, |
1322 | 1335 | dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
|
1323 | 1336 | datetimeChars = tp_inst._defaults.timeFormat.toString()
|
1324 | 1337 | .replace(/[hms]/g, '')
|
|
1330 | 1343 | .replace(/t/g, ampm ? 'ap' : '') +
|
1331 | 1344 | " " + tp_inst._defaults.separator +
|
1332 | 1345 | tp_inst._defaults.timeSuffix +
|
1333 |
| - (tp_inst._defaults.showTimezone ? tp_inst._defaults.timezoneList.join('') : '') + |
| 1346 | + (tz ? tp_inst._defaults.timezoneList.join('') : '') + |
1334 | 1347 | (tp_inst._defaults.amNames.join('')) + (tp_inst._defaults.pmNames.join('')) +
|
1335 | 1348 | dateChars,
|
1336 | 1349 | chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
|
|
1705 | 1718 | };
|
1706 | 1719 |
|
1707 | 1720 | /*
|
1708 |
| - * Determine by the time format if should use ampm |
1709 |
| - * Returns true if should use ampm, false if not |
| 1721 | + * Determine by the time format which units are supported |
| 1722 | + * Returns an object of booleans for each unit |
1710 | 1723 | */
|
1711 |
| - var useAmpm = function(timeFormat){ |
1712 |
| - return ((timeFormat.indexOf('t') !== -1 || timeFormat.indexOf('T') !== -1) && timeFormat.indexOf('h') !== -1); |
| 1724 | + var detectSupport = function(timeFormat){ |
| 1725 | + var tf = timeFormat.replace(/\'.*?\'/g,'').toLowerCase(), // removes literals |
| 1726 | + isIn = function(f, t){ // does the format contain the token? |
| 1727 | + return f.indexOf(t) !== -1? true:false; |
| 1728 | + }; |
| 1729 | + return { |
| 1730 | + hour: isIn(tf,'h'), |
| 1731 | + minute: isIn(tf,'m'), |
| 1732 | + second: isIn(tf,'s'), |
| 1733 | + millisec: isIn(tf,'l'), |
| 1734 | + timezone: isIn(tf,'z'), |
| 1735 | + ampm: isIn('t') && isIn(timeFormat,'h') |
| 1736 | + }; |
1713 | 1737 | };
|
1714 | 1738 |
|
1715 | 1739 | /*
|
|
0 commit comments