1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-16 19:54:24 +02:00

Update jQuery UI timepicker addon to latest version

Co-authored-by: matjazpotocnik <matjaz.potocnik@um.si>
This commit is contained in:
Ryan Cramer
2023-04-21 09:33:53 -04:00
parent 3d6278e23d
commit 3052f0c77d
2 changed files with 112 additions and 83 deletions

View File

@@ -1,6 +1,6 @@
/*! jQuery Timepicker Addon - v1.6.1 - 2015-11-14 /*! jQuery Timepicker Addon - v1.6.4 - 2023-02-06
* http://trentrichardson.com/examples/timepicker * http://trentrichardson.com/examples/timepicker
* Copyright (c) 2015 Trent Richardson; Licensed MIT */ * Copyright (c) 2023 Trent Richardson; Licensed MIT */
(function (factory) { (function (factory) {
if (typeof define === 'function' && define.amd) { if (typeof define === 'function' && define.amd) {
define(['jquery', 'jquery-ui'], factory); define(['jquery', 'jquery-ui'], factory);
@@ -22,7 +22,7 @@
*/ */
$.extend($.ui, { $.extend($.ui, {
timepicker: { timepicker: {
version: "1.6.1" version: "1.6.4"
} }
}); });
@@ -187,14 +187,14 @@
overrides = { overrides = {
beforeShow: function (input, dp_inst) { beforeShow: function (input, dp_inst) {
if ($.isFunction(tp_inst._defaults.evnts.beforeShow)) { if (typeof tp_inst._defaults.evnts.beforeShow === "function") {
return tp_inst._defaults.evnts.beforeShow.call($input[0], input, dp_inst, tp_inst); return tp_inst._defaults.evnts.beforeShow.call($input[0], input, dp_inst, tp_inst);
} }
}, },
onChangeMonthYear: function (year, month, dp_inst) { onChangeMonthYear: function (year, month, dp_inst) {
// Update the time as well : this prevents the time from disappearing from the $input field. // Update the time as well : this prevents the time from disappearing from the $input field.
// tp_inst._updateDateTime(dp_inst); // tp_inst._updateDateTime(dp_inst);
if ($.isFunction(tp_inst._defaults.evnts.onChangeMonthYear)) { if (typeof tp_inst._defaults.evnts.onChangeMonthYear === "function") {
tp_inst._defaults.evnts.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst); tp_inst._defaults.evnts.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst);
} }
}, },
@@ -202,7 +202,7 @@
if (tp_inst.timeDefined === true && $input.val() !== '') { if (tp_inst.timeDefined === true && $input.val() !== '') {
tp_inst._updateDateTime(dp_inst); tp_inst._updateDateTime(dp_inst);
} }
if ($.isFunction(tp_inst._defaults.evnts.onClose)) { if (typeof tp_inst._defaults.evnts.onClose === "function") {
tp_inst._defaults.evnts.onClose.call($input[0], dateText, dp_inst, tp_inst); tp_inst._defaults.evnts.onClose.call($input[0], dateText, dp_inst, tp_inst);
} }
} }
@@ -226,7 +226,7 @@
// detect which units are supported // detect which units are supported
tp_inst.support = detectSupport( tp_inst.support = detectSupport(
tp_inst._defaults.timeFormat + tp_inst._defaults.timeFormat +
(tp_inst._defaults.pickerTimeFormat ? tp_inst._defaults.pickerTimeFormat : '') + (tp_inst._defaults.pickerTimeFormat ? tp_inst._defaults.pickerTimeFormat : '') +
(tp_inst._defaults.altTimeFormat ? tp_inst._defaults.altTimeFormat : '')); (tp_inst._defaults.altTimeFormat ? tp_inst._defaults.altTimeFormat : ''));
@@ -315,7 +315,7 @@
* add our sliders to the calendar * add our sliders to the calendar
*/ */
_addTimePicker: function (dp_inst) { _addTimePicker: function (dp_inst) {
var currDT = $.trim((this.$altInput && this._defaults.altFieldTimeOnly) ? this.$input.val() + ' ' + this.$altInput.val() : this.$input.val()); var currDT = ((this.$altInput && this._defaults.altFieldTimeOnly) ? this.$input.val() + ' ' + this.$altInput.val() : this.$input.val()).trim();
this.timeDefined = this._parseTime(currDT); this.timeDefined = this._parseTime(currDT);
this._limitMinMaxDateTime(dp_inst, false); this._limitMinMaxDateTime(dp_inst, false);
@@ -362,7 +362,7 @@
*/ */
_afterInject: function() { _afterInject: function() {
var o = this.inst.settings; var o = this.inst.settings;
if ($.isFunction(o.afterInject)) { if (typeof o.afterInject === "function") {
o.afterInject.call(this); o.afterInject.call(this);
} }
}, },
@@ -425,7 +425,7 @@
} }
html += '</dd>'; html += '</dd>';
} }
// Timezone // Timezone
var showTz = o.showTimezone !== null ? o.showTimezone : this.support.timezone; var showTz = o.showTimezone !== null ? o.showTimezone : this.support.timezone;
html += '<dt class="ui_tpicker_timezone_label' + (showTz ? '' : noDisplay) + '">' + o.timezoneText + '</dt>'; html += '<dt class="ui_tpicker_timezone_label' + (showTz ? '' : noDisplay) + '">' + o.timezoneText + '</dt>';
@@ -440,7 +440,7 @@
$tp.prepend('<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' + '<div class="ui-datepicker-title">' + o.timeOnlyTitle + '</div>' + '</div>'); $tp.prepend('<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' + '<div class="ui-datepicker-title">' + o.timeOnlyTitle + '</div>' + '</div>');
$dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide(); $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide();
} }
// add sliders, adjust grids, add events // add sliders, adjust grids, add events
for (i = 0, l = tp_inst.units.length; i < l; i++) { for (i = 0, l = tp_inst.units.length; i < l; i++) {
litem = tp_inst.units[i]; litem = tp_inst.units[i];
@@ -458,7 +458,7 @@
marginLeft: o.isRTL ? '0' : ((size / (-2 * gridSize[litem])) + "%"), marginLeft: o.isRTL ? '0' : ((size / (-2 * gridSize[litem])) + "%"),
marginRight: o.isRTL ? ((size / (-2 * gridSize[litem])) + "%") : '0', marginRight: o.isRTL ? ((size / (-2 * gridSize[litem])) + "%") : '0',
borderCollapse: 'collapse' borderCollapse: 'collapse'
}).find("td").on('click', function (e) { }).find("td").click(function (e) {
var $t = $(this), var $t = $(this),
h = $t.html(), h = $t.html(),
n = parseInt(h.replace(/[^0-9]/g), 10), n = parseInt(h.replace(/[^0-9]/g), 10),
@@ -475,7 +475,7 @@
} }
} }
} }
tp_inst.control.value(tp_inst, tp_inst[f + '_slider'], litem, n); tp_inst.control.value(tp_inst, tp_inst[f + '_slider'], litem, n);
tp_inst._onTimeChange(); tp_inst._onTimeChange();
@@ -515,7 +515,7 @@
tp_inst._afterInject(); tp_inst._afterInject();
}); });
// End timezone options // End timezone options
// inject timepicker into datepicker // inject timepicker into datepicker
var $buttonPanel = $dp.find('.ui-datepicker-buttonpane'); var $buttonPanel = $dp.find('.ui-datepicker-buttonpane');
if ($buttonPanel.length) { if ($buttonPanel.length) {
@@ -551,13 +551,13 @@
var sliderAccessArgs = this._defaults.sliderAccessArgs, var sliderAccessArgs = this._defaults.sliderAccessArgs,
rtl = this._defaults.isRTL; rtl = this._defaults.isRTL;
sliderAccessArgs.isRTL = rtl; sliderAccessArgs.isRTL = rtl;
setTimeout(function () { // fix for inline mode setTimeout(function () { // fix for inline mode
if ($tp.find('.ui-slider-access').length === 0) { if ($tp.find('.ui-slider-access').length === 0) {
$tp.find('.ui-slider:visible').sliderAccess(sliderAccessArgs); $tp.find('.ui-slider:visible').sliderAccess(sliderAccessArgs);
// fix any grids since sliders are shorter // fix any grids since sliders are shorter
var sliderAccessWidth = $tp.find('.ui-slider-access').eq(0).outerWidth(true); var sliderAccessWidth = $tp.find('.ui-slider-access:eq(0)').outerWidth(true);
if (sliderAccessWidth) { if (sliderAccessWidth) {
$tp.find('table:visible').each(function () { $tp.find('table:visible').each(function () {
var $g = $(this), var $g = $(this),
@@ -703,44 +703,44 @@
} }
} }
if (dp_inst.settings.minTime!==null) { if (dp_inst.settings.minTime!==null) {
var tempMinTime=new Date("01/01/1970 " + dp_inst.settings.minTime); var tempMinTime=new Date("01/01/1970 " + dp_inst.settings.minTime);
if (this.hour<tempMinTime.getHours()) { if (this.hour<tempMinTime.getHours()) {
this.hour=this._defaults.hourMin=tempMinTime.getHours(); this.hour=this._defaults.hourMin=tempMinTime.getHours();
this.minute=this._defaults.minuteMin=tempMinTime.getMinutes(); this.minute=this._defaults.minuteMin=tempMinTime.getMinutes();
} else if (this.hour===tempMinTime.getHours() && this.minute<tempMinTime.getMinutes()) { } else if (this.hour===tempMinTime.getHours() && this.minute<tempMinTime.getMinutes()) {
this.minute=this._defaults.minuteMin=tempMinTime.getMinutes(); this.minute=this._defaults.minuteMin=tempMinTime.getMinutes();
} else { } else {
if (this._defaults.hourMin<tempMinTime.getHours()) { if (this._defaults.hourMin<tempMinTime.getHours()) {
this._defaults.hourMin=tempMinTime.getHours(); this._defaults.hourMin=tempMinTime.getHours();
this._defaults.minuteMin=tempMinTime.getMinutes(); this._defaults.minuteMin=tempMinTime.getMinutes();
} else if (this._defaults.hourMin===tempMinTime.getHours()===this.hour && this._defaults.minuteMin<tempMinTime.getMinutes()) { } else if (this._defaults.hourMin===tempMinTime.getHours()===this.hour && this._defaults.minuteMin<tempMinTime.getMinutes()) {
this._defaults.minuteMin=tempMinTime.getMinutes(); this._defaults.minuteMin=tempMinTime.getMinutes();
} else { } else {
this._defaults.minuteMin=0; this._defaults.minuteMin=0;
} }
} }
} }
if (dp_inst.settings.maxTime!==null) { if (dp_inst.settings.maxTime!==null) {
var tempMaxTime=new Date("01/01/1970 " + dp_inst.settings.maxTime); var tempMaxTime=new Date("01/01/1970 " + dp_inst.settings.maxTime);
if (this.hour>tempMaxTime.getHours()) { if (this.hour>tempMaxTime.getHours()) {
this.hour=this._defaults.hourMax=tempMaxTime.getHours(); this.hour=this._defaults.hourMax=tempMaxTime.getHours();
this.minute=this._defaults.minuteMax=tempMaxTime.getMinutes();
} else if (this.hour===tempMaxTime.getHours() && this.minute>tempMaxTime.getMinutes()) {
this.minute=this._defaults.minuteMax=tempMaxTime.getMinutes(); this.minute=this._defaults.minuteMax=tempMaxTime.getMinutes();
} else if (this.hour===tempMaxTime.getHours() && this.minute>tempMaxTime.getMinutes()) {
this.minute=this._defaults.minuteMax=tempMaxTime.getMinutes();
} else { } else {
if (this._defaults.hourMax>tempMaxTime.getHours()) { if (this._defaults.hourMax>tempMaxTime.getHours()) {
this._defaults.hourMax=tempMaxTime.getHours(); this._defaults.hourMax=tempMaxTime.getHours();
this._defaults.minuteMax=tempMaxTime.getMinutes(); this._defaults.minuteMax=tempMaxTime.getMinutes();
} else if (this._defaults.hourMax===tempMaxTime.getHours()===this.hour && this._defaults.minuteMax>tempMaxTime.getMinutes()) { } else if (this._defaults.hourMax===tempMaxTime.getHours()===this.hour && this._defaults.minuteMax>tempMaxTime.getMinutes()) {
this._defaults.minuteMax=tempMaxTime.getMinutes(); this._defaults.minuteMax=tempMaxTime.getMinutes();
} else { } else {
this._defaults.minuteMax=59; this._defaults.minuteMax=59;
} }
} }
} }
if (adjustSliders !== undefined && adjustSliders === true) { if (adjustSliders !== undefined && adjustSliders === true) {
var hourMax = parseInt((this._defaults.hourMax - ((this._defaults.hourMax - this._defaults.hourMin) % this._defaults.stepHour)), 10), var hourMax = parseInt((this._defaults.hourMax - ((this._defaults.hourMax - this._defaults.hourMin) % this._defaults.stepHour)), 10),
minMax = parseInt((this._defaults.minuteMax - ((this._defaults.minuteMax - this._defaults.minuteMin) % this._defaults.stepMinute)), 10), minMax = parseInt((this._defaults.minuteMax - ((this._defaults.minuteMax - this._defaults.minuteMin) % this._defaults.stepMinute)), 10),
@@ -834,11 +834,11 @@
// If the update was done using the sliders, update the input field. // If the update was done using the sliders, update the input field.
var hasChanged = ( var hasChanged = (
hour !== parseInt(this.hour,10) || // sliders should all be numeric hour !== parseInt(this.hour,10) || // sliders should all be numeric
minute !== parseInt(this.minute,10) || minute !== parseInt(this.minute,10) ||
second !== parseInt(this.second,10) || second !== parseInt(this.second,10) ||
millisec !== parseInt(this.millisec,10) || millisec !== parseInt(this.millisec,10) ||
microsec !== parseInt(this.microsec,10) || microsec !== parseInt(this.microsec,10) ||
(this.ampm.length > 0 && (hour < 12) !== ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) || (this.ampm.length > 0 && (hour < 12) !== ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) ||
(this.timezone !== null && timezone !== this.timezone.toString()) // could be numeric or "EST" format, so use toString() (this.timezone !== null && timezone !== this.timezone.toString()) // could be numeric or "EST" format, so use toString()
); );
@@ -876,20 +876,23 @@
// Updates the time within the timepicker // Updates the time within the timepicker
this.formattedTime = $.datepicker.formatTime(o.timeFormat, this, o); this.formattedTime = $.datepicker.formatTime(o.timeFormat, this, o);
if (this.$timeObj) { if (this.$timeObj) {
var sPos = this.$timeObj[0].selectionStart;
var ePos = this.$timeObj[0].selectionEnd;
if (pickerTimeFormat === o.timeFormat) { if (pickerTimeFormat === o.timeFormat) {
this.$timeObj.val(this.formattedTime + pickerTimeSuffix); this.$timeObj.val(this.formattedTime + pickerTimeSuffix);
} }
else { else {
this.$timeObj.val($.datepicker.formatTime(pickerTimeFormat, this, o) + pickerTimeSuffix); this.$timeObj.val($.datepicker.formatTime(pickerTimeFormat, this, o) + pickerTimeSuffix);
} }
//this.$timeObj[0].setSelectionRange(sPos, ePos); if (this.$timeObj[0].setSelectionRange) {
var sPos = this.$timeObj[0].selectionStart;
var ePos = this.$timeObj[0].selectionEnd;
this.$timeObj[0].setSelectionRange(sPos, ePos);
}
} }
this.timeDefined = true; this.timeDefined = true;
if (hasChanged) { if (hasChanged) {
this._updateDateTime(); this._updateDateTime();
//this.$input.focus(); // may automatically open the picker on setDate
} }
}, },
@@ -910,8 +913,8 @@
*/ */
_updateDateTime: function (dp_inst) { _updateDateTime: function (dp_inst) {
dp_inst = this.inst || dp_inst; dp_inst = this.inst || dp_inst;
var dtTmp = (dp_inst.currentYear > 0? var dtTmp = (dp_inst.currentYear > 0?
new Date(dp_inst.currentYear, dp_inst.currentMonth, dp_inst.currentDay) : new Date(dp_inst.currentYear, dp_inst.currentMonth, dp_inst.currentDay) :
new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)), new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)),
dt = $.datepicker._daylightSavingAdjust(dtTmp), dt = $.datepicker._daylightSavingAdjust(dtTmp),
//dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)), //dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)),
@@ -921,7 +924,7 @@
timeAvailable = dt !== null && this.timeDefined; timeAvailable = dt !== null && this.timeDefined;
this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg); this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg);
var formattedDateTime = this.formattedDate; var formattedDateTime = this.formattedDate;
// if a slider was changed but datepicker doesn't have a value yet, set it // if a slider was changed but datepicker doesn't have a value yet, set it
if (dp_inst.lastVal === "") { if (dp_inst.lastVal === "") {
dp_inst.currentYear = dp_inst.selectedYear; dp_inst.currentYear = dp_inst.selectedYear;
@@ -931,7 +934,7 @@
/* /*
* remove following lines to force every changes in date picker to change the input value * remove following lines to force every changes in date picker to change the input value
* Bug descriptions: when an input field has a default value, and click on the field to pop up the date picker. * Bug descriptions: when an input field has a default value, and click on the field to pop up the date picker.
* If the user manually empty the value in the input field, the date picker will never change selected value. * If the user manually empty the value in the input field, the date picker will never change selected value.
*/ */
//if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0)) { //if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0)) {
@@ -956,7 +959,7 @@
var altFormattedDateTime = '', var altFormattedDateTime = '',
altSeparator = this._defaults.altSeparator !== null ? this._defaults.altSeparator : this._defaults.separator, altSeparator = this._defaults.altSeparator !== null ? this._defaults.altSeparator : this._defaults.separator,
altTimeSuffix = this._defaults.altTimeSuffix !== null ? this._defaults.altTimeSuffix : this._defaults.timeSuffix; altTimeSuffix = this._defaults.altTimeSuffix !== null ? this._defaults.altTimeSuffix : this._defaults.timeSuffix;
if (!this._defaults.timeOnly) { if (!this._defaults.timeOnly) {
if (this._defaults.altFormat) { if (this._defaults.altFormat) {
altFormattedDateTime = $.datepicker.formatDate(this._defaults.altFormat, (dt === null ? new Date() : dt), formatCfg); altFormattedDateTime = $.datepicker.formatDate(this._defaults.altFormat, (dt === null ? new Date() : dt), formatCfg);
@@ -1023,7 +1026,7 @@
stop: function (event, ui) { stop: function (event, ui) {
tp_inst._onSelectHandler(); tp_inst._onSelectHandler();
} }
}); });
}, },
options: function (tp_inst, obj, unit, opts, val) { options: function (tp_inst, obj, unit, opts, val) {
if (tp_inst._defaults.isRTL) { if (tp_inst._defaults.isRTL) {
@@ -1036,7 +1039,7 @@
} }
return obj.slider(opts); return obj.slider(opts);
} }
var min = opts.min, var min = opts.min,
max = opts.max; max = opts.max;
opts.min = opts.max = null; opts.min = opts.max = null;
if (min !== undefined) { if (min !== undefined) {
@@ -1074,7 +1077,7 @@
for (var i = min; i <= max; i += step) { for (var i = min; i <= max; i += step) {
sel += '<option value="' + i + '"' + (i === val ? ' selected' : '') + '>'; sel += '<option value="' + i + '"' + (i === val ? ' selected' : '') + '>';
if (unit === 'hour') { if (unit === 'hour') {
sel += $.datepicker.formatTime($.trim(format.replace(/[^ht ]/ig, '')), {hour: i}, tp_inst._defaults); sel += $.datepicker.formatTime(format.replace(/[^ht ]/ig, '').trim(), {hour: i}, tp_inst._defaults);
} }
else if (unit === 'millisec' || unit === 'microsec' || i >= 10) { sel += i; } else if (unit === 'millisec' || unit === 'microsec' || i >= 10) { sel += i; }
else {sel += '0' + i.toString(); } else {sel += '0' + i.toString(); }
@@ -1099,7 +1102,7 @@
if (val === undefined) { if (val === undefined) {
return $t.data(opts); return $t.data(opts);
} }
o[opts] = val; o[opts] = val;
} }
else { o = opts; } else { o = opts; }
return tp_inst.control.create(tp_inst, obj, $t.data('unit'), $t.val(), o.min>=0 ? o.min : $t.data('min'), o.max || $t.data('max'), o.step || $t.data('step')); return tp_inst.control.create(tp_inst, obj, $t.data('unit'), $t.val(), o.min>=0 ? o.min : $t.data('min'), o.max || $t.data('max'), o.step || $t.data('step'));
@@ -1334,11 +1337,11 @@
} }
catch (err2) { catch (err2) {
$.timepicker.log("Unable to parse \ntimeString: " + s + "\ntimeFormat: " + f); $.timepicker.log("Unable to parse \ntimeString: " + s + "\ntimeFormat: " + f);
} }
} }
return false; return false;
}; // end looseParse }; // end looseParse
if (typeof o.parse === "function") { if (typeof o.parse === "function") {
return o.parse(timeFormat, timeString, o); return o.parse(timeFormat, timeString, o);
} }
@@ -1487,11 +1490,11 @@
.replace(/tT/g, ampm ? 'AaPpMm' : '') .replace(/tT/g, ampm ? 'AaPpMm' : '')
.replace(/T/g, ampm ? 'AP' : '') .replace(/T/g, ampm ? 'AP' : '')
.replace(/tt/g, ampm ? 'apm' : '') .replace(/tt/g, ampm ? 'apm' : '')
.replace(/t/g, ampm ? 'ap' : '') + .replace(/t/g, ampm ? 'ap' : '') +
" " + tp_inst._defaults.separator + " " + tp_inst._defaults.separator +
tp_inst._defaults.timeSuffix + tp_inst._defaults.timeSuffix +
(tz ? tp_inst._defaults.timezoneList.join('') : '') + (tz ? tp_inst._defaults.timezoneList.join('') : '') +
(tp_inst._defaults.amNames.join('')) + (tp_inst._defaults.pmNames.join('')) + (tp_inst._defaults.amNames.join('')) + (tp_inst._defaults.pmNames.join('')) +
dateChars, dateChars,
chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode); chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1); return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1);
@@ -1514,11 +1517,11 @@
var altFormat = tp_inst._defaults.altFormat || tp_inst._defaults.dateFormat, var altFormat = tp_inst._defaults.altFormat || tp_inst._defaults.dateFormat,
date = this._getDate(inst), date = this._getDate(inst),
formatCfg = $.datepicker._getFormatConfig(inst), formatCfg = $.datepicker._getFormatConfig(inst),
altFormattedDateTime = '', altFormattedDateTime = '',
altSeparator = tp_inst._defaults.altSeparator ? tp_inst._defaults.altSeparator : tp_inst._defaults.separator, altSeparator = tp_inst._defaults.altSeparator ? tp_inst._defaults.altSeparator : tp_inst._defaults.separator,
altTimeSuffix = tp_inst._defaults.altTimeSuffix ? tp_inst._defaults.altTimeSuffix : tp_inst._defaults.timeSuffix, altTimeSuffix = tp_inst._defaults.altTimeSuffix ? tp_inst._defaults.altTimeSuffix : tp_inst._defaults.timeSuffix,
altTimeFormat = tp_inst._defaults.altTimeFormat !== null ? tp_inst._defaults.altTimeFormat : tp_inst._defaults.timeFormat; altTimeFormat = tp_inst._defaults.altTimeFormat !== null ? tp_inst._defaults.altTimeFormat : tp_inst._defaults.timeFormat;
altFormattedDateTime += $.datepicker.formatTime(altTimeFormat, tp_inst, tp_inst._defaults) + altTimeSuffix; altFormattedDateTime += $.datepicker.formatTime(altTimeFormat, tp_inst, tp_inst._defaults) + altTimeSuffix;
if (!tp_inst._defaults.timeOnly && !tp_inst._defaults.altFieldTimeOnly && date !== null) { if (!tp_inst._defaults.timeOnly && !tp_inst._defaults.altFieldTimeOnly && date !== null) {
if (tp_inst._defaults.altFormat) { if (tp_inst._defaults.altFormat) {
@@ -1532,7 +1535,7 @@
} }
} }
else { else {
$.datepicker._base_updateAlternate(inst); $.datepicker._base_updateAlternate(inst);
} }
}; };
@@ -1565,9 +1568,13 @@
var inst = this._getInst($(id)[0]); var inst = this._getInst($(id)[0]);
this._base_gotoToday(id); this._base_gotoToday(id);
var tp_inst = this._get(inst, 'timepicker'); var tp_inst = this._get(inst, 'timepicker');
if (!tp_inst) {
return;
}
var tzoffset = $.timepicker.timezoneOffsetNumber(tp_inst.timezone); var tzoffset = $.timepicker.timezoneOffsetNumber(tp_inst.timezone);
var now = new Date(); var now = new Date();
now.setMinutes(now.getMinutes() + now.getTimezoneOffset() + tzoffset); now.setMinutes(now.getMinutes() + now.getTimezoneOffset() + parseInt(tzoffset, 10));
this._setTime(inst, now); this._setTime(inst, now);
this._setDate(inst, now); this._setDate(inst, now);
tp_inst._onSelectHandler(); tp_inst._onSelectHandler();
@@ -1622,7 +1629,7 @@
tp_inst.millisec = date ? date.getMilliseconds() : defaults.millisec; tp_inst.millisec = date ? date.getMilliseconds() : defaults.millisec;
tp_inst.microsec = date ? date.getMicroseconds() : defaults.microsec; tp_inst.microsec = date ? date.getMicroseconds() : defaults.microsec;
//check if within min/max times.. //check if within min/max times..
tp_inst._limitMinMaxDateTime(inst, true); tp_inst._limitMinMaxDateTime(inst, true);
tp_inst._onTimeChange(); tp_inst._onTimeChange();
@@ -1690,9 +1697,9 @@
} else { } else {
tp_date = date; tp_date = date;
} }
// This is important if you are using the timezone option, javascript's Date // This is important if you are using the timezone option, javascript's Date
// object will only return the timezone offset for the current locale, so we // object will only return the timezone offset for the current locale, so we
// adjust it accordingly. If not using timezone option this won't matter.. // adjust it accordingly. If not using timezone option this won't matter..
// If a timezone is different in tp, keep the timezone as is // If a timezone is different in tp, keep the timezone as is
if (tp_inst && tp_date) { if (tp_inst && tp_date) {
@@ -1700,8 +1707,8 @@
if (!tp_inst.support.timezone && tp_inst._defaults.timezone === null) { if (!tp_inst.support.timezone && tp_inst._defaults.timezone === null) {
tp_inst.timezone = tp_date.getTimezoneOffset() * -1; tp_inst.timezone = tp_date.getTimezoneOffset() * -1;
} }
date = $.timepicker.timezoneAdjust(date, tp_inst.timezone); date = $.timepicker.timezoneAdjust(date, $.timepicker.timezoneOffsetString(-date.getTimezoneOffset()), tp_inst.timezone);
tp_date = $.timepicker.timezoneAdjust(tp_date, tp_inst.timezone); tp_date = $.timepicker.timezoneAdjust(tp_date, $.timepicker.timezoneOffsetString(-tp_date.getTimezoneOffset()), tp_inst.timezone);
} }
this._updateDatepicker(inst); this._updateDatepicker(inst);
@@ -1728,20 +1735,39 @@
} }
var date = this._getDate(inst); var date = this._getDate(inst);
var currDT = $.trim((tp_inst.$altInput && tp_inst._defaults.altFieldTimeOnly) ? tp_inst.$input.val() + ' ' + tp_inst.$altInput.val() : tp_inst.$input.val());
var currDT = null;
if (tp_inst.$altInput && tp_inst._defaults.altFieldTimeOnly) {
currDT = tp_inst.$input.val() + ' ' + tp_inst.$altInput.val();
}
else if (tp_inst.$input.get(0).tagName !== 'INPUT' && tp_inst.$altInput) {
/**
* in case the datetimepicker has been applied to a non-input tag for inline UI,
* and the user has not configured the plugin to display only time in altInput,
* pick current date time from the altInput (and hope for the best, for now, until "ER1" is applied)
*
* @todo ER1. Since altInput can have a totally difference format, convert it to standard format by reading input format from "altFormat" and "altTimeFormat" option values
*/
currDT = tp_inst.$altInput.val();
}
else {
currDT = tp_inst.$input.val();
}
if (date && tp_inst._parseTime(currDT, !inst.settings.timeOnly)) { if (date && tp_inst._parseTime(currDT, !inst.settings.timeOnly)) {
date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec); date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
date.setMicroseconds(tp_inst.microsec); date.setMicroseconds(tp_inst.microsec);
// This is important if you are using the timezone option, javascript's Date // This is important if you are using the timezone option, javascript's Date
// object will only return the timezone offset for the current locale, so we // object will only return the timezone offset for the current locale, so we
// adjust it accordingly. If not using timezone option this won't matter.. // adjust it accordingly. If not using timezone option this won't matter..
if (tp_inst.timezone != null) { if (tp_inst.timezone != null) {
// look out for DST if tz wasn't specified // look out for DST if tz wasn't specified
if (!tp_inst.support.timezone && tp_inst._defaults.timezone === null) { if (!tp_inst.support.timezone && tp_inst._defaults.timezone === null) {
tp_inst.timezone = date.getTimezoneOffset() * -1; tp_inst.timezone = date.getTimezoneOffset() * -1;
} }
date = $.timepicker.timezoneAdjust(date, tp_inst.timezone); date = $.timepicker.timezoneAdjust(date, tp_inst.timezone, $.timepicker.timezoneOffsetString(-date.getTimezoneOffset()));
} }
} }
return date; return date;
@@ -1865,8 +1891,8 @@
tp_inst._defaults.onSelect = onselect; tp_inst._defaults.onSelect = onselect;
} }
// Datepicker will override our date when we call _base_optionDatepicker when // Datepicker will override our date when we call _base_optionDatepicker when
// calling minDate/maxDate, so we will first grab the value, call // calling minDate/maxDate, so we will first grab the value, call
// _base_optionDatepicker, then set our value back. // _base_optionDatepicker, then set our value back.
if(min || max){ if(min || max){
$target = $(target); $target = $(target);
@@ -1881,7 +1907,7 @@
} }
return this._base_optionDatepicker.call($.datepicker, target, name_clone || name, value); return this._base_optionDatepicker.call($.datepicker, target, name_clone || name, value);
}; };
/* /*
* jQuery isEmptyObject does not check hasOwnProperty - if someone has added to the object prototype, * jQuery isEmptyObject does not check hasOwnProperty - if someone has added to the object prototype,
* it will return false for all objects * it will return false for all objects
@@ -2039,7 +2065,7 @@
hours = (off - minutes) / 60, hours = (off - minutes) / 60,
iso = iso8601 ? ':' : '', iso = iso8601 ? ':' : '',
tz = (off >= 0 ? '+' : '-') + ('0' + Math.abs(hours)).slice(-2) + iso + ('0' + Math.abs(minutes)).slice(-2); tz = (off >= 0 ? '+' : '-') + ('0' + Math.abs(hours)).slice(-2) + iso + ('0' + Math.abs(minutes)).slice(-2);
if (tz === '+00:00') { if (tz === '+00:00') {
return 'Z'; return 'Z';
} }
@@ -2059,7 +2085,7 @@
} }
if (!/^(\-|\+)\d{4}$/.test(normalized)) { // possibly a user defined tz, so just give it back if (!/^(\-|\+)\d{4}$/.test(normalized)) { // possibly a user defined tz, so just give it back
return tzString; return parseInt(tzString, 10);
} }
return ((normalized.substr(0, 1) === '-' ? -1 : 1) * // plus or minus return ((normalized.substr(0, 1) === '-' ? -1 : 1) * // plus or minus
@@ -2070,13 +2096,15 @@
/** /**
* No way to set timezone in js Date, so we must adjust the minutes to compensate. (think setDate, getDate) * No way to set timezone in js Date, so we must adjust the minutes to compensate. (think setDate, getDate)
* @param {Date} date * @param {Date} date
* @param {string} fromTimezone formatted like "+0500", "-1245"
* @param {string} toTimezone formatted like "+0500", "-1245" * @param {string} toTimezone formatted like "+0500", "-1245"
* @return {Date} * @return {Date}
*/ */
$.timepicker.timezoneAdjust = function (date, toTimezone) { $.timepicker.timezoneAdjust = function (date, fromTimezone, toTimezone) {
var fromTz = $.timepicker.timezoneOffsetNumber(fromTimezone);
var toTz = $.timepicker.timezoneOffsetNumber(toTimezone); var toTz = $.timepicker.timezoneOffsetNumber(toTimezone);
if (!isNaN(toTz)) { if (!isNaN(toTz)) {
date.setMinutes(date.getMinutes() + -date.getTimezoneOffset() - toTz); date.setMinutes(date.getMinutes() + (-fromTz) - (-toTz));
} }
return date; return date;
}; };
@@ -2183,7 +2211,7 @@
date.setMilliseconds(date.getMilliseconds() - options.minInterval); date.setMilliseconds(date.getMilliseconds() - options.minInterval);
} }
} }
if (date.getTime) { if (date.getTime) {
other[method].call(other, 'option', option, date); other[method].call(other, 'option', option, date);
} }
@@ -2209,7 +2237,7 @@
}, options, options.end)); }, options, options.end));
checkDates(startTime, endTime); checkDates(startTime, endTime);
selected(startTime, endTime, 'minDate'); selected(startTime, endTime, 'minDate');
selected(endTime, startTime, 'maxDate'); selected(endTime, startTime, 'maxDate');
@@ -2222,7 +2250,8 @@
* @return {void} * @return {void}
*/ */
$.timepicker.log = function () { $.timepicker.log = function () {
if (window.console) { // Older IE (9, maybe 10) throw error on accessing `window.console.log.apply`, so check first.
if (window.console && window.console.log && window.console.log.apply) {
window.console.log.apply(window.console, Array.prototype.slice.call(arguments)); window.console.log.apply(window.console, Array.prototype.slice.call(arguments));
} }
}; };
@@ -2257,6 +2286,6 @@
/* /*
* Keep up with the version * Keep up with the version
*/ */
$.timepicker.version = "1.6.1"; $.timepicker.version = "1.6.4";
})); }));

File diff suppressed because one or more lines are too long