|
33 | 33 | this.timeSeparator = input.data('time-separator') ? input.data('time-separator') : options.timeSeparator; |
34 | 34 | this.amDesignator = input.data('am') ? input.data('am') : options.amDesignator; |
35 | 35 | this.pmDesignator = input.data('pm') ? input.data('pm') : options.pmDesignator; |
| 36 | + this.twoDigitsHour = input.data('two-digits-hour') ? input.data('two-digits-hour') : options.twoDigitsHour; |
36 | 37 | this._init(); |
37 | 38 | }; |
38 | 39 |
|
|
325 | 326 | if (this.hour === '') { |
326 | 327 | return ''; |
327 | 328 | } |
328 | | - |
329 | | - return this.hour + this.timeSeparator + (this.minute.toString().length === 1 ? '0' + this.minute : this.minute) + (this.showSeconds ? this.timeSeparator + (this.second.toString().length === 1 ? '0' + this.second : this.second) : '') + (this.showMeridian ? ' ' + this.meridian : ''); |
| 329 | + return this.getFormattedHour() + this.timeSeparator + (this.minute.toString().length === 1 ? '0' + this.minute : this.minute) + (this.showSeconds ? this.timeSeparator + (this.second.toString().length === 1 ? '0' + this.second : this.second) : '') + (this.showMeridian ? ' ' + this.meridian : ''); |
| 330 | + }, |
| 331 | + |
| 332 | + getFormattedHour : function() { |
| 333 | + var h = "" + this.hour; |
| 334 | + if (h.length==1 && this.twoDigitsHour===true) h = '0' + h; |
| 335 | + return h; |
330 | 336 | }, |
331 | 337 |
|
332 | 338 | hideWidget: function() { |
|
437 | 443 |
|
438 | 444 | if ($element.setSelectionRange) { |
439 | 445 | setTimeout(function() { |
440 | | - if (self.hour < 10) { |
441 | | - $element.setSelectionRange(0,1); |
442 | | - } else { |
443 | | - $element.setSelectionRange(0,2); |
444 | | - } |
| 446 | + var fh = self.getFormattedHour(); |
| 447 | + $element.setSelectionRange(0,fh.length); |
| 448 | + |
445 | 449 | }, 0); |
446 | 450 | } |
447 | 451 | }, |
|
454 | 458 |
|
455 | 459 | if ($element.setSelectionRange) { |
456 | 460 | setTimeout(function() { |
457 | | - if (self.hour < 10) { |
458 | | - $element.setSelectionRange(2,4); |
459 | | - } else { |
460 | | - $element.setSelectionRange(3,5); |
461 | | - } |
| 461 | + var fh = self.getFormattedHour(); |
| 462 | + var p = 1 + fh.length; |
| 463 | + $element.setSelectionRange(p,p+2); |
462 | 464 | }, 0); |
463 | 465 | } |
464 | 466 | }, |
|
471 | 473 |
|
472 | 474 | if ($element.setSelectionRange) { |
473 | 475 | setTimeout(function() { |
474 | | - if (self.hour < 10) { |
475 | | - $element.setSelectionRange(5,7); |
476 | | - } else { |
477 | | - $element.setSelectionRange(6,8); |
478 | | - } |
| 476 | + var fh = self.getFormattedHour(); |
| 477 | + var p = 4+fh.length; |
| 478 | + $element.setSelectionRange(p,p+2); |
479 | 479 | }, 0); |
480 | 480 | } |
481 | 481 | }, |
|
488 | 488 |
|
489 | 489 | if ($element.setSelectionRange) { |
490 | 490 | var start; |
491 | | - if (this.showSeconds) { |
492 | | - start = self.hour < 10 ? 8 : 9; |
| 491 | + var fh = self.getFormattedHour(); |
| 492 | + if (this.showSeconds) { |
| 493 | + start = 7 + fh.length; |
493 | 494 | } else { |
494 | | - start = self.hour < 10 ? 5 : 6; |
| 495 | + start = 4 + fh.length; |
495 | 496 | } |
496 | 497 |
|
497 | 498 | setTimeout(function() { |
|
731 | 732 | this.clear(); |
732 | 733 | return; |
733 | 734 | } |
734 | | - |
735 | 735 | var timeArray, |
736 | 736 | hour, |
737 | 737 | minute, |
|
1090 | 1090 | template: 'dropdown', |
1091 | 1091 | appendWidgetTo: 'body', |
1092 | 1092 | showWidgetOnAddonClick: true, |
| 1093 | + twoDigitsHour : false, |
1093 | 1094 | timeSeparator : ':', |
1094 | 1095 | amDesignator : 'AM', |
1095 | 1096 | pmDesignator : 'PM', |
|
0 commit comments