1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-16 03:34:33 +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
* Copyright (c) 2015 Trent Richardson; Licensed MIT */
* Copyright (c) 2023 Trent Richardson; Licensed MIT */
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery', 'jquery-ui'], factory);
@@ -22,7 +22,7 @@
*/
$.extend($.ui, {
timepicker: {
version: "1.6.1"
version: "1.6.4"
}
});
@@ -187,14 +187,14 @@
overrides = {
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);
}
},
onChangeMonthYear: function (year, month, dp_inst) {
// Update the time as well : this prevents the time from disappearing from the $input field.
// 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);
}
},
@@ -202,7 +202,7 @@
if (tp_inst.timeDefined === true && $input.val() !== '') {
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);
}
}
@@ -315,7 +315,7 @@
* add our sliders to the calendar
*/
_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._limitMinMaxDateTime(dp_inst, false);
@@ -362,7 +362,7 @@
*/
_afterInject: function() {
var o = this.inst.settings;
if ($.isFunction(o.afterInject)) {
if (typeof o.afterInject === "function") {
o.afterInject.call(this);
}
},
@@ -458,7 +458,7 @@
marginLeft: o.isRTL ? '0' : ((size / (-2 * gridSize[litem])) + "%"),
marginRight: o.isRTL ? ((size / (-2 * gridSize[litem])) + "%") : '0',
borderCollapse: 'collapse'
}).find("td").on('click', function (e) {
}).find("td").click(function (e) {
var $t = $(this),
h = $t.html(),
n = parseInt(h.replace(/[^0-9]/g), 10),
@@ -557,7 +557,7 @@
$tp.find('.ui-slider:visible').sliderAccess(sliderAccessArgs);
// 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) {
$tp.find('table:visible').each(function () {
var $g = $(this),
@@ -876,20 +876,23 @@
// Updates the time within the timepicker
this.formattedTime = $.datepicker.formatTime(o.timeFormat, this, o);
if (this.$timeObj) {
var sPos = this.$timeObj[0].selectionStart;
var ePos = this.$timeObj[0].selectionEnd;
if (pickerTimeFormat === o.timeFormat) {
this.$timeObj.val(this.formattedTime + pickerTimeSuffix);
}
else {
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;
if (hasChanged) {
this._updateDateTime();
//this.$input.focus(); // may automatically open the picker on setDate
}
},
@@ -1074,7 +1077,7 @@
for (var i = min; i <= max; i += step) {
sel += '<option value="' + i + '"' + (i === val ? ' selected' : '') + '>';
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 {sel += '0' + i.toString(); }
@@ -1565,9 +1568,13 @@
var inst = this._getInst($(id)[0]);
this._base_gotoToday(id);
var tp_inst = this._get(inst, 'timepicker');
if (!tp_inst) {
return;
}
var tzoffset = $.timepicker.timezoneOffsetNumber(tp_inst.timezone);
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._setDate(inst, now);
tp_inst._onSelectHandler();
@@ -1700,8 +1707,8 @@
if (!tp_inst.support.timezone && tp_inst._defaults.timezone === null) {
tp_inst.timezone = tp_date.getTimezoneOffset() * -1;
}
date = $.timepicker.timezoneAdjust(date, tp_inst.timezone);
tp_date = $.timepicker.timezoneAdjust(tp_date, tp_inst.timezone);
date = $.timepicker.timezoneAdjust(date, $.timepicker.timezoneOffsetString(-date.getTimezoneOffset()), tp_inst.timezone);
tp_date = $.timepicker.timezoneAdjust(tp_date, $.timepicker.timezoneOffsetString(-tp_date.getTimezoneOffset()), tp_inst.timezone);
}
this._updateDatepicker(inst);
@@ -1728,7 +1735,26 @@
}
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)) {
date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
date.setMicroseconds(tp_inst.microsec);
@@ -1741,7 +1767,7 @@
if (!tp_inst.support.timezone && tp_inst._defaults.timezone === null) {
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;
@@ -2059,7 +2085,7 @@
}
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
@@ -2070,13 +2096,15 @@
/**
* No way to set timezone in js Date, so we must adjust the minutes to compensate. (think setDate, getDate)
* @param {Date} date
* @param {string} fromTimezone formatted like "+0500", "-1245"
* @param {string} toTimezone formatted like "+0500", "-1245"
* @return {Date}
*/
$.timepicker.timezoneAdjust = function (date, toTimezone) {
$.timepicker.timezoneAdjust = function (date, fromTimezone, toTimezone) {
var fromTz = $.timepicker.timezoneOffsetNumber(fromTimezone);
var toTz = $.timepicker.timezoneOffsetNumber(toTimezone);
if (!isNaN(toTz)) {
date.setMinutes(date.getMinutes() + -date.getTimezoneOffset() - toTz);
date.setMinutes(date.getMinutes() + (-fromTz) - (-toTz));
}
return date;
};
@@ -2222,7 +2250,8 @@
* @return {void}
*/
$.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));
}
};
@@ -2257,6 +2286,6 @@
/*
* 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