Skip to content

Commit 2362c6c

Browse files
Merge pull request trentrichardson#179 from alexandergitter/dev
Fixed a couple of bugs
2 parents f80d8c1 + d9da87b commit 2362c6c

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

jquery-ui-timepicker-addon.js

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ $.extend(Timepicker.prototype, {
429429
var h = $(this).html();
430430
if(o.ampm) {
431431
var ap = h.substring(2).toLowerCase(),
432-
aph = parseInt(h.substring(0,2));
432+
aph = parseInt(h.substring(0,2), 10);
433433
if (ap == 'a') {
434434
if (aph == 12) h = 0;
435435
else h = aph;
@@ -519,8 +519,8 @@ $.extend(Timepicker.prototype, {
519519

520520
if(!this._defaults.showTimepicker) return; // No time so nothing to check here
521521

522-
if(this._defaults.minDateTime !== null && dp_date){
523-
var minDateTime = this._defaults.minDateTime,
522+
if($.datepicker._get(dp_inst, 'minDateTime') !== null && dp_date){
523+
var minDateTime = $.datepicker._get(dp_inst, 'minDateTime'),
524524
minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0);
525525

526526
if(this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null){
@@ -552,8 +552,8 @@ $.extend(Timepicker.prototype, {
552552
}
553553
}
554554

555-
if(this._defaults.maxDateTime !== null && dp_date){
556-
var maxDateTime = this._defaults.maxDateTime,
555+
if($.datepicker._get(dp_inst, 'maxDateTime') !== null && dp_date){
556+
var maxDateTime = $.datepicker._get(dp_inst, 'maxDateTime'),
557557
maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0);
558558

559559
if(this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null){
@@ -607,13 +607,18 @@ $.extend(Timepicker.prototype, {
607607
minute = (this.minute_slider) ? this.minute_slider.slider('value') : false,
608608
second = (this.second_slider) ? this.second_slider.slider('value') : false,
609609
timezone = (this.timezone_select) ? this.timezone_select.val() : false;
610-
610+
611+
if (typeof(hour) == 'object') hour = false;
612+
if (typeof(minute) == 'object') minute = false;
613+
if (typeof(second) == 'object') second = false;
614+
if (typeof(timezone) == 'object') timezone = false;
615+
611616
if (hour !== false) hour = parseInt(hour,10);
612617
if (minute !== false) minute = parseInt(minute,10);
613618
if (second !== false) second = parseInt(second,10);
614619

615620
var ampm = (hour < 12) ? 'AM' : 'PM';
616-
621+
617622
// If the update was done in the input field, the input field should not be updated.
618623
// If the update was done using the sliders, update the input field.
619624
var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || (this.ampm.length > 0 && this.ampm != ampm) || timezone != this.timezone);
@@ -793,6 +798,16 @@ $.datepicker._selectDate = function (id, dateStr) {
793798
//#############################################################################################
794799
$.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker;
795800
$.datepicker._updateDatepicker = function(inst) {
801+
802+
// don't popup the datepicker if there is another instance already opened
803+
var input = inst.input[0];
804+
if($.datepicker._curInst &&
805+
$.datepicker._curInst != inst &&
806+
$.datepicker._datepickerShowing &&
807+
$.datepicker._lastInput != input) {
808+
return;
809+
}
810+
796811
if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {
797812

798813
this._base_updateDatepicker(inst);
@@ -804,7 +819,7 @@ $.datepicker._updateDatepicker = function(inst) {
804819
};
805820

806821
//#######################################################################################
807-
// third bad hack :/ override datepicker so it allows spaces and colan in the input field
822+
// third bad hack :/ override datepicker so it allows spaces and colon in the input field
808823
//#######################################################################################
809824
$.datepicker._base_doKeyPress = $.datepicker._doKeyPress;
810825
$.datepicker._doKeyPress = function(event) {
@@ -814,6 +829,7 @@ $.datepicker._doKeyPress = function(event) {
814829
if (tp_inst) {
815830
if ($.datepicker._get(inst, 'constrainInput')) {
816831
var ampm = tp_inst._defaults.ampm,
832+
dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
817833
datetimeChars = tp_inst._defaults.timeFormat.toString()
818834
.replace(/[hms]/g, '')
819835
.replace(/TT/g, ampm ? 'APM' : '')
@@ -825,9 +841,10 @@ $.datepicker._doKeyPress = function(event) {
825841
" " +
826842
tp_inst._defaults.separator +
827843
tp_inst._defaults.timeSuffix +
828-
$.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
844+
(tp_inst._defaults.showTimezone ? tp_inst._defaults.timezoneList.join('') : '') +
845+
dateChars,
829846
chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
830-
return event.ctrlKey || (chr < ' ' || !datetimeChars || datetimeChars.indexOf(chr) > -1);
847+
return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1);
831848
}
832849
}
833850

@@ -908,12 +925,13 @@ $.datepicker._setTime = function(inst, date) {
908925
second = defaults.secondMin;
909926
}
910927

928+
tp_inst.hour = hour;
929+
tp_inst.minute = minute;
930+
tp_inst.second = second;
931+
911932
if (tp_inst.hour_slider) tp_inst.hour_slider.slider('value', hour);
912-
else tp_inst.hour = hour;
913933
if (tp_inst.minute_slider) tp_inst.minute_slider.slider('value', minute);
914-
else tp_inst.minute = minute;
915934
if (tp_inst.second_slider) tp_inst.second_slider.slider('value', second);
916-
else tp_inst.second = second;
917935

918936
tp_inst._onTimeChange();
919937
tp_inst._updateDateTime(inst);

0 commit comments

Comments
 (0)