|
1 | 1 | /*!
|
2 |
| - * jquery-timepicker v1.14.0 - A jQuery timepicker plugin inspired by Google Calendar. It supports both mouse and keyboard navigation. |
| 2 | + * jquery-timepicker v1.14.1 - A jQuery timepicker plugin inspired by Google Calendar. It supports both mouse and keyboard navigation. |
3 | 3 | * Copyright (c) 2021 Jon Thornton - https://www.jonthornton.com/jquery-timepicker/
|
4 | 4 | * License: MIT
|
5 | 5 | */
|
|
168 | 168 | }
|
169 | 169 |
|
170 | 170 | var ONE_DAY = 86400;
|
| 171 | + var EVENT_DEFAULTS = { |
| 172 | + bubbles: true, |
| 173 | + cancelable: false, |
| 174 | + detail: null |
| 175 | + }; |
171 | 176 |
|
172 | 177 | var roundingFunction = function roundingFunction(seconds, settings) {
|
173 | 178 | if (seconds === null) {
|
|
239 | 244 | hrs: "hrs"
|
240 | 245 | };
|
241 | 246 |
|
242 |
| - var EVENT_DEFAULTS = { |
243 |
| - bubbles: true, |
244 |
| - cancelable: false, |
245 |
| - detail: null |
246 |
| - }; |
247 |
| - |
248 | 247 | var Timepicker = /*#__PURE__*/function () {
|
249 | 248 | function Timepicker(targetEl) {
|
250 | 249 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
431 | 430 |
|
432 | 431 | timeString = timeString.toLowerCase().replace(/[\s\.]/g, ""); // if the last character is an "a" or "p", add the "m"
|
433 | 432 |
|
434 |
| - if (timeString.slice(-1) == "a" || timeString.slice(-1) == "p") { |
| 433 | + if (this.settings.lang.am === "am" && (timeString.slice(-1) == "a" || timeString.slice(-1) == "p")) { |
435 | 434 | timeString += "m";
|
436 | 435 | }
|
437 | 436 |
|
|
817 | 816 | return;
|
818 | 817 | }
|
819 | 818 |
|
820 |
| - var rangeError = false; // check that the time in within bounds |
| 819 | + var rangeError = this._isTimeRangeError(seconds, settings); |
| 820 | + |
| 821 | + if (settings.forceRoundTime) { |
| 822 | + var roundSeconds = settings.roundingFunction(seconds, settings); |
| 823 | + |
| 824 | + if (roundSeconds != seconds) { |
| 825 | + seconds = roundSeconds; |
| 826 | + origin = null; |
| 827 | + } |
| 828 | + } |
| 829 | + |
| 830 | + var prettyTime = this._int2time(seconds); |
| 831 | + |
| 832 | + if (rangeError) { |
| 833 | + this._setTimeValue(prettyTime); |
821 | 834 |
|
| 835 | + var timeRangeErrorEvent = new CustomEvent('timeRangeError', EVENT_DEFAULTS); |
| 836 | + this.targetEl.dispatchEvent(timeRangeErrorEvent); |
| 837 | + } else { |
| 838 | + this._setTimeValue(prettyTime, origin); |
| 839 | + } |
| 840 | + } |
| 841 | + }, { |
| 842 | + key: "_isTimeRangeError", |
| 843 | + value: function _isTimeRangeError(seconds, settings) { |
| 844 | + // check that the time in within bounds |
822 | 845 | if (settings.minTime !== null && settings.maxTime !== null && (seconds < settings.minTime() || seconds > settings.maxTime())) {
|
823 |
| - rangeError = true; |
| 846 | + return true; |
824 | 847 | } // check that time isn't within disabled time ranges
|
825 | 848 |
|
826 | 849 |
|
|
832 | 855 | var range = _step.value;
|
833 | 856 |
|
834 | 857 | if (seconds >= range[0] && seconds < range[1]) {
|
835 |
| - rangeError = true; |
836 |
| - break; |
| 858 | + return true; |
837 | 859 | }
|
838 | 860 | }
|
839 | 861 | } catch (err) {
|
|
842 | 864 | _iterator.f();
|
843 | 865 | }
|
844 | 866 |
|
845 |
| - if (settings.forceRoundTime) { |
846 |
| - var roundSeconds = settings.roundingFunction(seconds, settings); |
847 |
| - |
848 |
| - if (roundSeconds != seconds) { |
849 |
| - seconds = roundSeconds; |
850 |
| - origin = null; |
851 |
| - } |
852 |
| - } |
853 |
| - |
854 |
| - var prettyTime = this._int2time(seconds); |
855 |
| - |
856 |
| - if (rangeError) { |
857 |
| - this._setTimeValue(prettyTime); |
858 |
| - |
859 |
| - var timeRangeErrorEvent = new CustomEvent('timeRangeError', EVENT_DEFAULTS); |
860 |
| - this.targetEl.dispatchEvent(timeRangeErrorEvent); |
861 |
| - } else { |
862 |
| - this._setTimeValue(prettyTime, origin); |
863 |
| - } |
| 867 | + return false; |
864 | 868 | }
|
865 | 869 | }, {
|
866 | 870 | key: "_generateNoneElement",
|
|
1143 | 1147 |
|
1144 | 1148 | function _renderSelectItem(item) {
|
1145 | 1149 | var el = document.createElement('option');
|
1146 |
| - el.value = item.label; |
| 1150 | + el.value = item.value || item.label; |
1147 | 1151 |
|
1148 | 1152 | if (item.duration) {
|
1149 | 1153 | el.appendChild(document.createTextNode(item.label + ' (' + item.duration + ')'));
|
|
1536 | 1540 | setTime: function setTime(value) {
|
1537 | 1541 | var tp = this[0].timepickerObj;
|
1538 | 1542 | var settings = tp.settings;
|
| 1543 | + var seconds = tp.anytime2int(value); |
| 1544 | + |
| 1545 | + if (tp._isTimeRangeError(seconds, settings)) { |
| 1546 | + var timeRangeErrorEvent = new CustomEvent('timeRangeError', EVENT_DEFAULTS); |
| 1547 | + tp.targetEl.dispatchEvent(timeRangeErrorEvent); |
| 1548 | + } |
1539 | 1549 |
|
1540 | 1550 | if (settings.forceRoundTime) {
|
1541 |
| - var prettyTime = tp._roundAndFormatTime(tp.anytime2int(value)); |
| 1551 | + var prettyTime = tp._roundAndFormatTime(seconds); |
1542 | 1552 | } else {
|
1543 |
| - var prettyTime = tp._int2time(tp.anytime2int(value)); |
| 1553 | + var prettyTime = tp._int2time(seconds); |
1544 | 1554 | }
|
1545 | 1555 |
|
1546 | 1556 | if (value && prettyTime === null && settings.noneOption) {
|
|
0 commit comments