|
31 | 31 | this.appendWidgetTo = options.appendWidgetTo; |
32 | 32 | this.showWidgetOnAddonClick = options.showWidgetOnAddonClick; |
33 | 33 | this.maxHours = options.maxHours; |
34 | | - this.explicitMode = options.explicitMode; // If true 123 = 1:23, 12345 = 1:23:45, else invalid. |
| 34 | + this.explicitMode = options.explicitMode; // If true 123 = 1:23, 12345 = 1:23:45, else invalid. |
| 35 | + this.twoDigitsHour = options.twoDigitsHour; |
35 | 36 |
|
36 | 37 | this.handleDocumentClick = function (e) { |
37 | 38 | var self = e.data.scope; |
|
351 | 352 | return ''; |
352 | 353 | } |
353 | 354 |
|
354 | | - return this.hour + ':' + (this.minute.toString().length === 1 ? '0' + this.minute : this.minute) + (this.showSeconds ? ':' + (this.second.toString().length === 1 ? '0' + this.second : this.second) : '') + (this.showMeridian ? ' ' + this.meridian : ''); |
| 355 | + return this.getFormattedHour() + ':' + (this.minute.toString().length === 1 ? '0' + this.minute : this.minute) + (this.showSeconds ? ':' + (this.second.toString().length === 1 ? '0' + this.second : this.second) : '') + (this.showMeridian ? ' ' + this.meridian : ''); |
| 356 | + }, |
| 357 | + |
| 358 | + getFormattedHour : function() { |
| 359 | + var h = '' + this.hour; |
| 360 | + if (h.length === 1 && this.twoDigitsHour) { |
| 361 | + h = '0' + h; |
| 362 | + } |
| 363 | + return h; |
355 | 364 | }, |
356 | 365 |
|
357 | 366 | hideWidget: function() { |
|
462 | 471 |
|
463 | 472 | if ($element.setSelectionRange) { |
464 | 473 | setTimeout(function() { |
465 | | - if (self.hour < 10) { |
466 | | - $element.setSelectionRange(0,1); |
467 | | - } else { |
468 | | - $element.setSelectionRange(0,2); |
469 | | - } |
| 474 | + var fh = self.getFormattedHour(); |
| 475 | + $element.setSelectionRange(0,fh.length); |
470 | 476 | }, 0); |
471 | 477 | } |
472 | 478 | }, |
|
479 | 485 |
|
480 | 486 | if ($element.setSelectionRange) { |
481 | 487 | setTimeout(function() { |
482 | | - if (self.hour < 10) { |
483 | | - $element.setSelectionRange(2,4); |
484 | | - } else { |
485 | | - $element.setSelectionRange(3,5); |
486 | | - } |
| 488 | + var fh = self.getFormattedHour(); |
| 489 | + var p = 1 + fh.length; |
| 490 | + $element.setSelectionRange(p,p+2); |
487 | 491 | }, 0); |
488 | 492 | } |
489 | 493 | }, |
|
496 | 500 |
|
497 | 501 | if ($element.setSelectionRange) { |
498 | 502 | setTimeout(function() { |
499 | | - if (self.hour < 10) { |
500 | | - $element.setSelectionRange(5,7); |
501 | | - } else { |
502 | | - $element.setSelectionRange(6,8); |
503 | | - } |
| 503 | + var fh = self.getFormattedHour(); |
| 504 | + var p = 4 + fh.length; |
| 505 | + $element.setSelectionRange(p,p+2); |
504 | 506 | }, 0); |
505 | 507 | } |
506 | 508 | }, |
|
512 | 514 | this.highlightedUnit = 'meridian'; |
513 | 515 |
|
514 | 516 | if ($element.setSelectionRange) { |
| 517 | + var start; |
| 518 | + var fh = self.getFormattedHour(); |
515 | 519 | if (this.showSeconds) { |
516 | | - setTimeout(function() { |
517 | | - if (self.hour < 10) { |
518 | | - $element.setSelectionRange(8,10); |
519 | | - } else { |
520 | | - $element.setSelectionRange(9,11); |
521 | | - } |
522 | | - }, 0); |
| 520 | + start = 7 + fh.length; |
523 | 521 | } else { |
524 | | - setTimeout(function() { |
525 | | - if (self.hour < 10) { |
526 | | - $element.setSelectionRange(5,7); |
527 | | - } else { |
528 | | - $element.setSelectionRange(6,8); |
529 | | - } |
530 | | - }, 0); |
| 522 | + start = 4 + fh.length; |
531 | 523 | } |
| 524 | + setTimeout(function() { |
| 525 | + $element.setSelectionRange(start,start+self.meridian.length); |
| 526 | + }, 0); |
532 | 527 | } |
533 | 528 | }, |
534 | 529 |
|
|
988 | 983 | return; |
989 | 984 | } |
990 | 985 |
|
991 | | - var hour = this.hour, |
| 986 | + var hour = this.getFormattedHour(), |
992 | 987 | minute = this.minute.toString().length === 1 ? '0' + this.minute : this.minute, |
993 | 988 | second = this.second.toString().length === 1 ? '0' + this.second : this.second; |
994 | 989 |
|
|
1147 | 1142 | appendWidgetTo: 'body', |
1148 | 1143 | showWidgetOnAddonClick: true, |
1149 | 1144 | maxHours: 24, |
1150 | | - explicitMode: false |
| 1145 | + explicitMode: false, |
| 1146 | + twoDigitsHour : false |
1151 | 1147 | }; |
1152 | 1148 |
|
1153 | 1149 | $.fn.timepicker.Constructor = Timepicker; |
|
0 commit comments