From 121cdc237d249f8bfb26a9745334b13d852bfe58 Mon Sep 17 00:00:00 2001 From: Fabio Cantoni Date: Wed, 22 Mar 2017 12:39:34 +0100 Subject: [PATCH] Update jquery-timepicker to version 1.11.10 --- .../assets/javascripts/jquery.timepicker.js | 137 ++++++++++-------- 1 file changed, 76 insertions(+), 61 deletions(-) mode change 100755 => 100644 vendor/assets/javascripts/jquery.timepicker.js diff --git a/vendor/assets/javascripts/jquery.timepicker.js b/vendor/assets/javascripts/jquery.timepicker.js old mode 100755 new mode 100644 index e8e9601..e5a7aeb --- a/vendor/assets/javascripts/jquery.timepicker.js +++ b/vendor/assets/javascripts/jquery.timepicker.js @@ -1,5 +1,5 @@ /*! - * jquery-timepicker v1.11.4 - A jQuery timepicker plugin inspired by Google Calendar. It supports both mouse and keyboard navigation. + * jquery-timepicker v1.11.10 - A jQuery timepicker plugin inspired by Google Calendar. It supports both mouse and keyboard navigation. * Copyright (c) 2015 Jon Thornton - http://jonthornton.github.com/jquery-timepicker/ * License: MIT */ @@ -30,6 +30,58 @@ hrs: 'hrs' }; + var _DEFAULTS = { + appendTo: 'body', + className: null, + closeOnWindowScroll: false, + disableTextInput: false, + disableTimeRanges: [], + disableTouchKeyboard: false, + durationTime: null, + forceRoundTime: false, + maxTime: null, + minTime: null, + noneOption: false, + orientation: 'l', + roundingFunction: function(seconds, settings) { + if (seconds === null) { + return null; + } else if (typeof settings.step !== "number") { + // TODO: nearest fit irregular steps + return seconds; + } else { + var offset = seconds % (settings.step*60); // step is in minutes + + var start = settings.minTime || 0; + + // adjust offset by start mod step so that the offset is aligned not to 00:00 but to the start + offset -= start % (settings.step * 60); + + if (offset >= settings.step*30) { + // if offset is larger than a half step, round up + seconds += (settings.step*60) - offset; + } else { + // round down + seconds -= offset; + } + + return _moduloSeconds(seconds, settings); + } + }, + scrollDefault: null, + selectOnBlur: false, + show2400: false, + showDuration: false, + showOn: ['click', 'focus'], + showOnFocus: true, + step: 30, + stopScrollPropagation: false, + timeFormat: 'g:ia', + typeaheadHighlight: true, + useSelect: false, + wrapHours: true + }; + var methods = { init: function(options) { @@ -39,13 +91,13 @@ // pick up settings from data attributes var attributeOptions = []; - for (var key in $.fn.timepicker.defaults) { + for (var key in _DEFAULTS) { if (self.data(key)) { attributeOptions[key] = self.data(key); } } - var settings = $.extend({}, $.fn.timepicker.defaults, attributeOptions, options); + var settings = $.extend({}, _DEFAULTS, options, attributeOptions); if (settings.lang) { _lang = $.extend(_lang, settings.lang); @@ -71,7 +123,7 @@ self.on('keydown.timepicker', _disableTextInputHandler); } - _formatValue.call(self.get(0)); + _formatValue.call(self.get(0), null, 'initial'); } }); }, @@ -243,6 +295,8 @@ self.data('timepicker-settings', settings); + _formatValue.call(self.get(0), {'type':'change'}, 'initial'); + if (list) { list.remove(); self.data('timepicker-list', false); @@ -507,8 +561,8 @@ row.text(timeString); } else { var row = $('
  • '); - row.addClass(timeInt % 86400 < 43200 ? 'ui-timepicker-am' : 'ui-timepicker-pm'); - row.data('time', (timeInt <= 86400 ? timeInt : timeInt % 86400)); + row.addClass((timeInt % _ONE_DAY) < (_ONE_DAY / 2) ? 'ui-timepicker-am' : 'ui-timepicker-pm'); + row.data('time', _moduloSeconds(timeInt, settings)); row.text(timeString); } @@ -748,17 +802,21 @@ }); if (settings.forceRoundTime) { - seconds = settings.roundingFunction(seconds, settings); + var roundSeconds = settings.roundingFunction(seconds, settings); + if (roundSeconds != seconds) { + seconds = roundSeconds; + origin = null; + } } var prettyTime = _int2time(seconds, settings); if (rangeError) { - if (_setTimeValue(self, prettyTime, 'error')) { + if (_setTimeValue(self, prettyTime, 'error') || e && e.type == 'change') { self.trigger('timeRangeError'); } } else { - _setTimeValue(self, prettyTime); + _setTimeValue(self, prettyTime, origin); } } @@ -787,7 +845,7 @@ self.data('ui-timepicker-value', value); if (source == 'select') { self.trigger('selectTime').trigger('changeTime').trigger('change', 'timepicker'); - } else if (source != 'error') { + } else if (['error', 'initial'].indexOf(source) == -1) { self.trigger('changeTime'); } @@ -1174,6 +1232,14 @@ return ("0" + n).slice(-2); } + function _moduloSeconds(seconds, settings) { + if (seconds == _ONE_DAY && settings.show2400) { + return seconds; + } + + return seconds%_ONE_DAY; + } + // Plugin entry $.fn.timepicker = function(method) { @@ -1188,55 +1254,4 @@ else if(typeof method === "object" || !method) { return methods.init.apply(this, arguments); } else { $.error("Method "+ method + " does not exist on jQuery.timepicker"); } }; - // Global defaults - $.fn.timepicker.defaults = { - appendTo: 'body', - className: null, - closeOnWindowScroll: false, - disableTextInput: false, - disableTimeRanges: [], - disableTouchKeyboard: false, - durationTime: null, - forceRoundTime: false, - maxTime: null, - minTime: null, - noneOption: false, - orientation: 'l', - roundingFunction: function(seconds, settings) { - if (seconds === null) { - return null; - } else if (typeof settings.step !== "number") { - // TODO: nearest fit irregular steps - return seconds; - } else { - var offset = seconds % (settings.step*60); // step is in minutes - - if (offset >= settings.step*30) { - // if offset is larger than a half step, round up - seconds += (settings.step*60) - offset; - } else { - // round down - seconds -= offset; - } - - if (seconds == _ONE_DAY && settings.show2400) { - return seconds; - } - - return seconds%_ONE_DAY; - } - }, - scrollDefault: null, - selectOnBlur: false, - show2400: false, - showDuration: false, - showOn: ['click', 'focus'], - showOnFocus: true, - step: 30, - stopScrollPropagation: false, - timeFormat: 'g:ia', - typeaheadHighlight: true, - useSelect: false, - wrapHours: true - }; }));