Skip to content

Commit e5577fc

Browse files
author
Trent
committed
Merge branch 'dev'
2 parents 72f763d + 9efeb99 commit e5577fc

File tree

1 file changed

+58
-21
lines changed

1 file changed

+58
-21
lines changed

jquery-ui-timepicker-addon.js

+58-21
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ function Timepicker() {
6565
secondGrid: 0,
6666
alwaysSetTime: true,
6767
separator: ' ',
68-
altFieldTimeOnly: true
68+
altFieldTimeOnly: true,
69+
showTimepicker: true
6970
};
7071
$.extend(this._defaults, this.regional['']);
7172
}
@@ -125,31 +126,30 @@ $.extend(Timepicker.prototype, {
125126
}
126127
}
127128
tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, {
128-
beforeShow: function(input, dp_inst) {
129-
if (o.altField)
130-
tp_inst.$altInput = $($.datepicker._get(dp_inst, 'altField'))
131-
.css({ cursor: 'pointer' })
132-
.focus(function(){
133-
$input.trigger("focus");
134-
});
129+
beforeShow: function(input, dp_inst) {
135130
if ($.isFunction(o.beforeShow))
136-
o.beforeShow(input, dp_inst);
131+
o.beforeShow(input, dp_inst, tp_inst);
137132
},
138133
onChangeMonthYear: function(year, month, dp_inst) {
139134
// Update the time as well : this prevents the time from disappearing from the $input field.
140135
tp_inst._updateDateTime(dp_inst);
141136
if ($.isFunction(o.onChangeMonthYear))
142-
o.onChangeMonthYear(year, month, dp_inst);
137+
o.onChangeMonthYear(year, month, dp_inst, tp_inst);
143138
},
144139
onClose: function(dateText, dp_inst) {
145140
if (tp_inst.timeDefined === true && $input.val() != '')
146141
tp_inst._updateDateTime(dp_inst);
147142
if ($.isFunction(o.onClose))
148-
o.onClose(dateText, dp_inst);
143+
o.onClose(dateText, dp_inst, tp_inst);
149144
},
150145
timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
151146
});
152147

148+
if (o.altField)
149+
tp_inst.$altInput = $(o.altField)
150+
.css({ cursor: 'pointer' })
151+
.focus(function(){ $input.trigger("focus"); });
152+
153153
// datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime..
154154
if(tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date)
155155
tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime());
@@ -195,7 +195,7 @@ $.extend(Timepicker.prototype, {
195195
// the time should come after x number of characters and a space.
196196
// x = at least the length of text specified by the date format
197197
var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat');
198-
regstr = '.{' + dp_dateFormat.length + ',}\\s*' + this._defaults.separator.replace(/\s/g, '\\s?') + regstr;
198+
regstr = '.{' + dp_dateFormat.length + ',}' + this._defaults.separator + regstr;
199199
}
200200

201201
treg = timeString.match(new RegExp(regstr, 'i'));
@@ -254,7 +254,8 @@ $.extend(Timepicker.prototype, {
254254
dp_id = this.inst.id.toString().replace(/([^A-Za-z0-9_])/g, '');
255255

256256
// Prevent displaying twice
257-
if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0) {
257+
//if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0) {
258+
if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0 && o.showTimepicker) {
258259
var noDisplay = ' style="display:none;"',
259260
html = '<div class="ui-timepicker-div" id="ui-timepicker-div-' + dp_id + '"><dl>' +
260261
'<dt class="ui_tpicker_time_label" id="ui_tpicker_time_label_' + dp_id + '"' +
@@ -458,6 +459,18 @@ $.extend(Timepicker.prototype, {
458459
this._onTimeChange();
459460
this.timeDefined = timeDefined;
460461
}
462+
463+
//Emulate datepicker onSelect behavior. Call on slidestop.
464+
var onSelect = tp_inst._defaults['onSelect'];
465+
if (onSelect) {
466+
var inputEl = tp_inst.$input ? tp_inst.$input[0] : null;
467+
var onSelectHandler = function() {
468+
onSelect.apply(inputEl, [tp_inst.formattedDateTime, tp_inst]); // trigger custom callback*/
469+
}
470+
this.hour_slider.bind('slidestop',onSelectHandler);
471+
this.minute_slider.bind('slidestop',onSelectHandler);
472+
this.second_slider.bind('slidestop',onSelectHandler);
473+
}
461474
}
462475
},
463476

@@ -549,14 +562,12 @@ $.extend(Timepicker.prototype, {
549562

550563
if (hasChanged) {
551564

552-
if (hour !== false) {
553-
this.hour = hour;
554-
if (this._defaults.ampm) this.ampm = ampm;
555-
}
565+
if (hour !== false)this.hour = hour;
556566
if (minute !== false) this.minute = minute;
557567
if (second !== false) this.second = second;
558-
559568
}
569+
if (this._defaults.ampm) this.ampm = ampm;
570+
560571
this._formatTime();
561572
if (this.$timeObj) this.$timeObj.text(this.formattedTime);
562573
this.timeDefined = true;
@@ -621,8 +632,10 @@ $.extend(Timepicker.prototype, {
621632
}
622633

623634
this.formattedDateTime = formattedDateTime;
624-
625-
if (this.$altInput && this._defaults.altFieldTimeOnly === true) {
635+
636+
if(!this._defaults.showTimepicker) {
637+
this.$input.val(this.formattedDate);
638+
} else if (this.$altInput && this._defaults.altFieldTimeOnly === true) {
626639
this.$altInput.val(this.formattedTime);
627640
this.$input.val(this.formattedDate);
628641
} else if(this.$altInput) {
@@ -689,7 +702,8 @@ $.datepicker._selectDate = function (id, dateStr) {
689702
if (tp_inst) {
690703
tp_inst._limitMinMaxDateTime(inst, true);
691704
inst.inline = inst.stay_open = true;
692-
this._base_selectDate(id, dateStr);
705+
//This way the onSelect handler called from calendarpicker get the full dateTime
706+
this._base_selectDate(id, dateStr + tp_inst._defaults.separator + tp_inst.formattedTime);
693707
inst.inline = inst.stay_open = false;
694708
this._notifyChange(inst);
695709
this._updateDatepicker(inst);
@@ -772,6 +786,29 @@ $.datepicker._gotoToday = function(id) {
772786
this._setTime(this._getInst($(id)[0]), new Date());
773787
};
774788

789+
//#######################################################################################
790+
// Disable & enable the Time in the datetimepicker
791+
//#######################################################################################
792+
$.datepicker._disableTimepickerDatepicker = function(target, date, withDate) {
793+
var inst = this._getInst(target),
794+
tp_inst = this._get(inst, 'timepicker');
795+
if (tp_inst) {
796+
tp_inst._defaults.showTimepicker = false;
797+
tp_inst._onTimeChange();
798+
tp_inst._updateDateTime(inst);
799+
}
800+
};
801+
802+
$.datepicker._enableTimepickerDatepicker = function(target, date, withDate) {
803+
var inst = this._getInst(target),
804+
tp_inst = this._get(inst, 'timepicker');
805+
if (tp_inst) {
806+
tp_inst._defaults.showTimepicker = true;
807+
tp_inst._onTimeChange();
808+
tp_inst._updateDateTime(inst);
809+
}
810+
};
811+
775812
//#######################################################################################
776813
// Create our own set time function
777814
//#######################################################################################

0 commit comments

Comments
 (0)