From e6015c253d7256f6e95419eb9c7ecd2ce2e54b0f Mon Sep 17 00:00:00 2001 From: alextselegidis Date: Sun, 23 Oct 2016 23:12:19 +0200 Subject: [PATCH] Updated timepicker addon extension which fixes timezone issues (fixes #220). --- src/assets/css/general.css | 33 +- .../jquery-ui/jquery-ui-timepicker-addon.js | 1372 ++++++++++------- .../js/backend_calendar_appointments_modal.js | 18 +- 3 files changed, 814 insertions(+), 609 deletions(-) diff --git a/src/assets/css/general.css b/src/assets/css/general.css index 5f4b33e3..607e4d85 100644 --- a/src/assets/css/general.css +++ b/src/assets/css/general.css @@ -186,16 +186,33 @@ li.language:hover { /* JQUERY UI DATETIME PICKER ADDON ------------------------------------------------------------------------- */ -.ui-timepicker-div .ui-widget-header { margin-bottom: 8px; padding: 6px; } -.ui-timepicker-div dl { text-align: left; padding: 0 15px; color: #575757; } -/*.ui-timepicker-div dl dt { height: 25px; margin-bottom: -25px; }*/ -/*.ui-timepicker-div dl dd { margin: 0 10px 10px 65px; }*/ +.ui-timepicker-div .ui-widget-header { margin-bottom: 8px; } +.ui-timepicker-div dl { text-align: left; } +.ui-timepicker-div dl dt { float: left; clear:left; padding: 0 0 0 5px; } +.ui-timepicker-div dl dd { margin: 0 10px 10px 40%; } .ui-timepicker-div td { font-size: 90%; } .ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; } +.ui-timepicker-div .ui_tpicker_unit_hide{ display: none; } + +.ui-timepicker-div .ui_tpicker_time .ui_tpicker_time_input { background: none; color: inherit; border: none; outline: none; border-bottom: solid 1px #555; width: 95%; } +.ui-timepicker-div .ui_tpicker_time .ui_tpicker_time_input:focus { border-bottom-color: #aaa; } .ui-timepicker-rtl{ direction: rtl; } -.ui-timepicker-rtl dl { text-align: right; } -.ui-timepicker-rtl dl dd { margin: 0 65px 10px 10px; } +.ui-timepicker-rtl dl { text-align: right; padding: 0 5px 0 0; } +.ui-timepicker-rtl dl dt{ float: right; clear: right; } +.ui-timepicker-rtl dl dd { margin: 0 40% 10px 10px; } -.ui-timepicker-div .ui-datepicker .ui-datepicker-buttonpane { border: none; margin: 0; } -.ui-datepicker .ui-datepicker-buttonpane button { padding: .2em .6em 0.2em .6em; font-size: 12px; } +/* Shortened version style */ +.ui-timepicker-div.ui-timepicker-oneLine { padding-right: 2px; } +.ui-timepicker-div.ui-timepicker-oneLine .ui_tpicker_time, +.ui-timepicker-div.ui-timepicker-oneLine dt { display: none; } +.ui-timepicker-div.ui-timepicker-oneLine .ui_tpicker_time_label { display: block; padding-top: 2px; } +.ui-timepicker-div.ui-timepicker-oneLine dl { text-align: right; } +.ui-timepicker-div.ui-timepicker-oneLine dl dd, +.ui-timepicker-div.ui-timepicker-oneLine dl dd > div { display:inline-block; margin:0; } +.ui-timepicker-div.ui-timepicker-oneLine dl dd.ui_tpicker_minute:before, +.ui-timepicker-div.ui-timepicker-oneLine dl dd.ui_tpicker_second:before { content:':'; display:inline-block; } +.ui-timepicker-div.ui-timepicker-oneLine dl dd.ui_tpicker_millisec:before, +.ui-timepicker-div.ui-timepicker-oneLine dl dd.ui_tpicker_microsec:before { content:'.'; display:inline-block; } +.ui-timepicker-div.ui-timepicker-oneLine .ui_tpicker_unit_hide, +.ui-timepicker-div.ui-timepicker-oneLine .ui_tpicker_unit_hide:before{ display: none; } diff --git a/src/assets/ext/jquery-ui/jquery-ui-timepicker-addon.js b/src/assets/ext/jquery-ui/jquery-ui-timepicker-addon.js index fc17c6cd..81c55aa6 100644 --- a/src/assets/ext/jquery-ui/jquery-ui-timepicker-addon.js +++ b/src/assets/ext/jquery-ui/jquery-ui-timepicker-addon.js @@ -1,18 +1,13 @@ -/* - * jQuery timepicker addon - * By: Trent Richardson [http://trentrichardson.com] - * Version 1.3 - * Last Modified: 05/05/2013 - * - * Copyright 2013 Trent Richardson - * You may use this project under MIT or GPL licenses. - * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt - * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt - */ - -/*jslint evil: true, white: false, undef: false, nomen: false */ - -(function($) { +/*! jQuery Timepicker Addon - v1.6.3 - 2016-04-20 +* http://trentrichardson.com/examples/timepicker +* Copyright (c) 2016 Trent Richardson; Licensed MIT */ +(function (factory) { + if (typeof define === 'function' && define.amd) { + define(['jquery', 'jquery-ui'], factory); + } else { + factory(jQuery); + } +}(function ($) { /* * Lets not redefine timepicker, Prevent "Uncaught RangeError: Maximum call stack size exceeded" @@ -27,17 +22,17 @@ */ $.extend($.ui, { timepicker: { - version: "1.3" + version: "1.6.3" } }); - /* + /* * Timepicker manager. * Use the singleton instance of this class, $.timepicker, to interact with the time picker. * Settings for (groups of) time pickers are maintained in an instance object, * allowing multiple different settings on the same page. */ - var Timepicker = function() { + var Timepicker = function () { this.regional = []; // Available regional settings, indexed by language code this.regional[''] = { // Default regional settings currentText: 'Now', @@ -59,6 +54,7 @@ this._defaults = { // Global defaults for all the datetime picker instances showButtonPanel: true, timeOnly: false, + timeOnlyShowDate: false, showHour: null, showMinute: null, showSecond: null, @@ -89,6 +85,8 @@ microsecMax: 999, minDateTime: null, maxDateTime: null, + maxTime: null, + minTime: null, onSelect: null, hourGrid: 0, minuteGrid: 0, @@ -101,6 +99,7 @@ altTimeFormat: null, altSeparator: null, altTimeSuffix: null, + altRedirectFocus: true, pickerTimeFormat: null, pickerTimeSuffix: null, showTimepicker: true, @@ -108,8 +107,10 @@ addSliderAccess: false, sliderAccessArgs: null, controlType: 'slider', + oneLine: false, defaultValue: null, - parse: 'strict' + parse: 'strict', + afterInject: null }; $.extend(this._defaults, this.regional['']); }; @@ -125,6 +126,8 @@ millisec_slider: null, microsec_slider: null, timezone_select: null, + maxTime: null, + minTime: null, hour: 0, minute: 0, second: 0, @@ -146,16 +149,16 @@ formattedTime: '', formattedDateTime: '', timezoneList: null, - units: ['hour','minute','second','millisec', 'microsec'], + units: ['hour', 'minute', 'second', 'millisec', 'microsec'], support: {}, control: null, - /* + /* * Override the default settings for all instances of the time picker. - * @param settings object - the new settings to use as defaults (anonymous object) - * @return the manager object + * @param {Object} settings object - the new settings to use as defaults (anonymous object) + * @return {Object} the manager object */ - setDefaults: function(settings) { + setDefaults: function (settings) { extendRemove(this._defaults, settings || {}); return this; }, @@ -163,14 +166,14 @@ /* * Create a new Timepicker instance */ - _newInst: function($input, o) { + _newInst: function ($input, opts) { var tp_inst = new Timepicker(), inlineSettings = {}, - fns = {}, - overrides, i; + fns = {}, + overrides, i; for (var attrName in this._defaults) { - if(this._defaults.hasOwnProperty(attrName)){ + if (this._defaults.hasOwnProperty(attrName)) { var attrValue = $input.attr('time:' + attrName); if (attrValue) { try { @@ -182,72 +185,72 @@ } } - overrides = { - beforeShow: function (input, dp_inst) { - if ($.isFunction(tp_inst._defaults.evnts.beforeShow)) { - 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)) { - tp_inst._defaults.evnts.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst); - } - }, - onClose: function (dateText, dp_inst) { - if (tp_inst.timeDefined === true && $input.val() !== '') { - tp_inst._updateDateTime(dp_inst); - } - if ($.isFunction(tp_inst._defaults.evnts.onClose)) { - tp_inst._defaults.evnts.onClose.call($input[0], dateText, dp_inst, tp_inst); - } - } - }; - for (i in overrides) { - if (overrides.hasOwnProperty(i)) { - fns[i] = o[i] || null; - } - } + overrides = { + beforeShow: function (input, dp_inst) { + if ($.isFunction(tp_inst._defaults.evnts.beforeShow)) { + 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)) { + tp_inst._defaults.evnts.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst); + } + }, + onClose: function (dateText, dp_inst) { + if (tp_inst.timeDefined === true && $input.val() !== '') { + tp_inst._updateDateTime(dp_inst); + } + if ($.isFunction(tp_inst._defaults.evnts.onClose)) { + tp_inst._defaults.evnts.onClose.call($input[0], dateText, dp_inst, tp_inst); + } + } + }; + for (i in overrides) { + if (overrides.hasOwnProperty(i)) { + fns[i] = opts[i] || this._defaults[i] || null; + } + } - tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, overrides, { - evnts:fns, - timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker'); - }); - tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) { + tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, opts, overrides, { + evnts: fns, + timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker'); + }); + tp_inst.amNames = $.map(tp_inst._defaults.amNames, function (val) { return val.toUpperCase(); }); - tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) { + tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function (val) { return val.toUpperCase(); }); // detect which units are supported tp_inst.support = detectSupport( - tp_inst._defaults.timeFormat + - (tp_inst._defaults.pickerTimeFormat? tp_inst._defaults.pickerTimeFormat:'') + - (tp_inst._defaults.altTimeFormat? tp_inst._defaults.altTimeFormat:'')); + tp_inst._defaults.timeFormat + + (tp_inst._defaults.pickerTimeFormat ? tp_inst._defaults.pickerTimeFormat : '') + + (tp_inst._defaults.altTimeFormat ? tp_inst._defaults.altTimeFormat : '')); // controlType is string - key to our this._controls - if(typeof(tp_inst._defaults.controlType) === 'string'){ - if(tp_inst._defaults.controlType == 'slider' && typeof(jQuery.ui.slider) === 'undefined'){ + if (typeof(tp_inst._defaults.controlType) === 'string') { + if (tp_inst._defaults.controlType === 'slider' && typeof($.ui.slider) === 'undefined') { tp_inst._defaults.controlType = 'select'; } tp_inst.control = tp_inst._controls[tp_inst._defaults.controlType]; } // controlType is an object and must implement create, options, value methods - else{ + else { tp_inst.control = tp_inst._defaults.controlType; } // prep the timezone options - var timezoneList = [-720,-660,-600,-570,-540,-480,-420,-360,-300,-270,-240,-210,-180,-120,-60, - 0,60,120,180,210,240,270,300,330,345,360,390,420,480,525,540,570,600,630,660,690,720,765,780,840]; + var timezoneList = [-720, -660, -600, -570, -540, -480, -420, -360, -300, -270, -240, -210, -180, -120, -60, + 0, 60, 120, 180, 210, 240, 270, 300, 330, 345, 360, 390, 420, 480, 525, 540, 570, 600, 630, 660, 690, 720, 765, 780, 840]; if (tp_inst._defaults.timezoneList !== null) { timezoneList = tp_inst._defaults.timezoneList; } - var tzl=timezoneList.length,tzi=0,tzv=null; + var tzl = timezoneList.length, tzi = 0, tzv = null; if (tzl > 0 && typeof timezoneList[0] !== 'object') { - for(; tzi tp_inst._defaults.hourMax? tp_inst._defaults.hourMax : tp_inst._defaults.hour; - tp_inst.minute = tp_inst._defaults.minute < tp_inst._defaults.minuteMin? tp_inst._defaults.minuteMin : - tp_inst._defaults.minute > tp_inst._defaults.minuteMax? tp_inst._defaults.minuteMax : tp_inst._defaults.minute; - tp_inst.second = tp_inst._defaults.second < tp_inst._defaults.secondMin? tp_inst._defaults.secondMin : - tp_inst._defaults.second > tp_inst._defaults.secondMax? tp_inst._defaults.secondMax : tp_inst._defaults.second; - tp_inst.millisec = tp_inst._defaults.millisec < tp_inst._defaults.millisecMin? tp_inst._defaults.millisecMin : - tp_inst._defaults.millisec > tp_inst._defaults.millisecMax? tp_inst._defaults.millisecMax : tp_inst._defaults.millisec; - tp_inst.microsec = tp_inst._defaults.microsec < tp_inst._defaults.microsecMin? tp_inst._defaults.microsecMin : - tp_inst._defaults.microsec > tp_inst._defaults.microsecMax? tp_inst._defaults.microsecMax : tp_inst._defaults.microsec; + tp_inst.timezone = tp_inst._defaults.timezone !== null ? $.timepicker.timezoneOffsetNumber(tp_inst._defaults.timezone) : + ((new Date()).getTimezoneOffset() * -1); + tp_inst.hour = tp_inst._defaults.hour < tp_inst._defaults.hourMin ? tp_inst._defaults.hourMin : + tp_inst._defaults.hour > tp_inst._defaults.hourMax ? tp_inst._defaults.hourMax : tp_inst._defaults.hour; + tp_inst.minute = tp_inst._defaults.minute < tp_inst._defaults.minuteMin ? tp_inst._defaults.minuteMin : + tp_inst._defaults.minute > tp_inst._defaults.minuteMax ? tp_inst._defaults.minuteMax : tp_inst._defaults.minute; + tp_inst.second = tp_inst._defaults.second < tp_inst._defaults.secondMin ? tp_inst._defaults.secondMin : + tp_inst._defaults.second > tp_inst._defaults.secondMax ? tp_inst._defaults.secondMax : tp_inst._defaults.second; + tp_inst.millisec = tp_inst._defaults.millisec < tp_inst._defaults.millisecMin ? tp_inst._defaults.millisecMin : + tp_inst._defaults.millisec > tp_inst._defaults.millisecMax ? tp_inst._defaults.millisecMax : tp_inst._defaults.millisec; + tp_inst.microsec = tp_inst._defaults.microsec < tp_inst._defaults.microsecMin ? tp_inst._defaults.microsecMin : + tp_inst._defaults.microsec > tp_inst._defaults.microsecMax ? tp_inst._defaults.microsecMax : tp_inst._defaults.microsec; tp_inst.ampm = ''; tp_inst.$input = $input; - if (o.altField) { - tp_inst.$altInput = $(o.altField).css({ - cursor: 'pointer' - }).focus(function() { - $input.trigger("focus"); - }); + if (tp_inst._defaults.altField) { + tp_inst.$altInput = $(tp_inst._defaults.altField); + if (tp_inst._defaults.altRedirectFocus === true) { + tp_inst.$altInput.css({ + cursor: 'pointer' + }).focus(function () { + $input.trigger("focus"); + }); + } } if (tp_inst._defaults.minDate === 0 || tp_inst._defaults.minDateTime === 0) { @@ -298,7 +304,7 @@ if (tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date) { tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime()); } - tp_inst.$input.bind('focus', function() { + tp_inst.$input.bind('focus', function () { tp_inst._onFocus(); }); @@ -308,18 +314,19 @@ /* * add our sliders to the calendar */ - _addTimePicker: function(dp_inst) { - var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ? this.$input.val() + ' ' + this.$altInput.val() : this.$input.val(); + _addTimePicker: function (dp_inst) { + var currDT = $.trim((this.$altInput && this._defaults.altFieldTimeOnly) ? this.$input.val() + ' ' + this.$altInput.val() : this.$input.val()); this.timeDefined = this._parseTime(currDT); this._limitMinMaxDateTime(dp_inst, false); this._injectTimePicker(); + this._afterInject(); }, /* * parse the time string from input value or _setTime */ - _parseTime: function(timeString, withDate) { + _parseTime: function (timeString, withDate) { if (!this.inst) { this.inst = $.datepicker._getInst(this.$input[0]); } @@ -350,10 +357,20 @@ } }, + /* + * Handle callback option after injecting timepicker + */ + _afterInject: function() { + var o = this.inst.settings; + if ($.isFunction(o.afterInject)) { + o.afterInject.call(this); + } + }, + /* * generate and inject html for timepicker into ui datepicker */ - _injectTimePicker: function() { + _injectTimePicker: function () { var $dp = this.inst.dpDiv, o = this.inst.settings, tp_inst = this, @@ -363,44 +380,44 @@ max = {}, gridSize = {}, size = null, - i=0, - l=0; + i = 0, + l = 0; // Prevent displaying twice if ($dp.find("div.ui-timepicker-div").length === 0 && o.showTimepicker) { - var noDisplay = ' style="display:none;"', - html = '
' + '
' + o.timeText + '
' + - '
'; + var noDisplay = ' ui_tpicker_unit_hide', + html = '
' + '
' + o.timeText + '
' + + '
'; // Create the markup - for(i=0,l=this.units.length; i' + o[litem +'Text'] + '' + - '
'; + html += '
' + o[litem + 'Text'] + '
' + + '
'; - if (show && o[litem+'Grid'] > 0) { + if (show && o[litem + 'Grid'] > 0) { html += '
'; - if(litem == 'hour'){ - for (var h = o[litem+'Min']; h <= max[litem]; h += parseInt(o[litem+'Grid'], 10)) { + if (litem === 'hour') { + for (var h = o[litem + 'Min']; h <= max[litem]; h += parseInt(o[litem + 'Grid'], 10)) { gridSize[litem]++; - var tmph = $.datepicker.formatTime(this.support.ampm? 'hht':'HH', {hour:h}, o); - html += ''; + var tmph = $.datepicker.formatTime(this.support.ampm ? 'hht' : 'HH', {hour: h}, o); + html += ''; } } - else{ - for (var m = o[litem+'Min']; m <= max[litem]; m += parseInt(o[litem+'Grid'], 10)) { + else { + for (var m = o[litem + 'Min']; m <= max[litem]; m += parseInt(o[litem + 'Grid'], 10)) { gridSize[litem]++; - html += ''; + html += ''; } } @@ -408,11 +425,11 @@ } html += ''; } - + // Timezone - var showTz = o.showTimezone !== null? o.showTimezone : this.support.timezone; - html += '
' + o.timezoneText + '
'; - html += '
'; + var showTz = o.showTimezone !== null ? o.showTimezone : this.support.timezone; + html += '
' + o.timezoneText + '
'; + html += '
'; // Create the elements from string html += ''; @@ -423,43 +440,43 @@ $tp.prepend('
' + '
' + o.timeOnlyTitle + '
' + '
'); $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide(); } - + // add sliders, adjust grids, add events - for(i=0,l=tp_inst.units.length; i 0) { - size = 100 * gridSize[litem] * o[litem+'Grid'] / (max[litem] - o[litem+'Min']); - $tp.find('.ui_tpicker_'+litem+' table').css({ + if (show && o[litem + 'Grid'] > 0) { + size = 100 * gridSize[litem] * o[litem + 'Grid'] / (max[litem] - o[litem + 'Min']); + $tp.find('.ui_tpicker_' + litem + ' table').css({ width: size + "%", - marginLeft: o.isRTL? '0' : ((size / (-2 * gridSize[litem])) + "%"), - marginRight: o.isRTL? ((size / (-2 * gridSize[litem])) + "%") : '0', + marginLeft: o.isRTL ? '0' : ((size / (-2 * gridSize[litem])) + "%"), + marginRight: o.isRTL ? ((size / (-2 * gridSize[litem])) + "%") : '0', borderCollapse: 'collapse' - }).find("td").click(function(e){ + }).find("td").click(function (e) { var $t = $(this), h = $t.html(), - n = parseInt(h.replace(/[^0-9]/g),10), + n = parseInt(h.replace(/[^0-9]/g), 10), ap = h.replace(/[^apm]/ig), f = $t.data('for'); // loses scope, so we use data-for - if(f == 'hour'){ - if(ap.indexOf('p') !== -1 && n < 12){ + if (f === 'hour') { + if (ap.indexOf('p') !== -1 && n < 12) { n += 12; } - else{ - if(ap.indexOf('a') !== -1 && n === 12){ + else { + if (ap.indexOf('a') !== -1 && n === 12) { n = 0; } } } - - 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._onSelectHandler(); @@ -475,29 +492,30 @@ // Add timezone options this.timezone_select = $tp.find('.ui_tpicker_timezone').append('').find("select"); $.fn.append.apply(this.timezone_select, - $.map(o.timezoneList, function(val, idx) { - return $("
' + tmph + '' + tmph + '' + ((m < 10) ? '0' : '') + m + '' + ((m < 10) ? '0' : '') + m + '