vendor/assets/javascripts/flatpickr.js in flatpickr-3.0.0.0 vs vendor/assets/javascripts/flatpickr.js in flatpickr-3.0.7.0

- old
+ new

@@ -1,10 +1,10 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; -/*! flatpickr v3.0.5-1, @license MIT */ +/*! flatpickr v3.0.6, @license MIT */ function FlatpickrInstance(element, config) { var self = this; self._ = {}; self._.afterDayAnim = afterDayAnim; @@ -48,11 +48,11 @@ if (self.selectedDates.length || self.config.noCalendar) { if (self.config.enableTime) { setHoursFromDate(self.config.noCalendar ? self.latestSelectedDateObj || self.config.minDate : null); } - updateValue(); + updateValue(false); } self.showTimeInput = self.selectedDates.length > 0 || self.config.noCalendar; if (self.config.weekNumbers) { @@ -671,11 +671,11 @@ var minuteInput = createNumberInput("flatpickr-minute"); self.minuteElement = minuteInput.childNodes[0]; self.hourElement.tabIndex = self.minuteElement.tabIndex = -1; - self.hourElement.value = self.pad(self.latestSelectedDateObj ? self.latestSelectedDateObj.getHours() : self.config.defaultHour); + self.hourElement.value = self.pad(self.latestSelectedDateObj ? self.latestSelectedDateObj.getHours() : self.config.defaultHour % (self.time_24hr ? 24 : 12)); self.minuteElement.value = self.pad(self.latestSelectedDateObj ? self.latestSelectedDateObj.getMinutes() : self.config.defaultMinute); self.hourElement.step = self.config.hourIncrement; self.minuteElement.step = self.config.minuteIncrement; @@ -698,11 +698,11 @@ self.timeContainer.classList.add("hasSeconds"); var secondInput = createNumberInput("flatpickr-second"); self.secondElement = secondInput.childNodes[0]; - self.secondElement.value = self.latestSelectedDateObj ? self.pad(self.latestSelectedDateObj.getSeconds()) : "00"; + self.secondElement.value = self.pad(self.latestSelectedDateObj ? self.latestSelectedDateObj.getSeconds() : self.config.defaultSeconds); self.secondElement.step = self.minuteElement.step; self.secondElement.min = self.minuteElement.min; self.secondElement.max = self.minuteElement.max; @@ -710,11 +710,11 @@ self.timeContainer.appendChild(secondInput); } if (!self.config.time_24hr) { // add self.amPM if appropriate - self.amPM = createElement("span", "flatpickr-am-pm", ["AM", "PM"][self.hourElement.value > 11 | 0]); + self.amPM = createElement("span", "flatpickr-am-pm", ["AM", "PM"][(self.latestSelectedDateObj ? self.hourElement.value : self.config.defaultHour) > 11 | 0]); self.amPM.title = self.l10n.toggleTitle; self.amPM.tabIndex = -1; self.timeContainer.appendChild(self.amPM); } @@ -872,11 +872,13 @@ self.input.removeAttribute("readonly"); self.input.value = ""; } ["_showTimeInput", "latestSelectedDateObj", "_hideNextMonthArrow", "_hidePrevMonthArrow", "__hideNextMonthArrow", "__hidePrevMonthArrow", "isMobile", "isOpen", "selectedDateElem", "minDateHasTime", "maxDateHasTime", "days", "daysContainer", "_input", "_positionElement", "innerContainer", "rContainer", "monthNav", "todayDateElem", "calendarContainer", "weekdayContainer", "prevMonthNav", "nextMonthNav", "currentMonthElement", "currentYearElement", "navigationCurrentMonth", "selectedDateElem", "config"].forEach(function (k) { - return delete self[k]; + try { + delete self[k]; + } catch (e) {} }); } function isCalendarElem(elem) { if (self.config.appendTo && self.config.appendTo.contains(elem)) return true; @@ -971,10 +973,15 @@ // escape e.preventDefault(); self.close(); break; + case "Backspace": + case "Delete": + if (!self.config.allowInput) self.clear(); + break; + case "ArrowLeft": case "ArrowRight": if (!isTimeObj) { e.preventDefault(); @@ -998,10 +1005,11 @@ focusOnDay(e.target.$i, 0); } else if (!isTimeObj) focusOnDay(e.target.$i, delta * 7); } else if (self.config.enableTime) { if (!isTimeObj) self.hourElement.focus(); updateTime(e); + self.debouncedChange(); } break; case "Tab": @@ -1340,11 +1348,11 @@ triggerEvent("Change"); // maintain focus if (!shouldChangeMonth) focusOnDay(e.target.$i, 0);else afterDayAnim(function () { - return self.selectedDateElem.focus(); + return self.selectedDateElem && self.selectedDateElem.focus(); }); if (self.config.enableTime) setTimeout(function () { return self.hourElement.select(); }, 451); @@ -1356,11 +1364,12 @@ if (single || range) self.close(); } } function set(option, value) { - self.config[option] = value; + if (option !== null && (typeof option === "undefined" ? "undefined" : _typeof(option)) === "object") _extends(self.config, option);else self.config[option] = value; + self.redraw(); jumpToDate(); } function setSelectedDate(inputDate, format) { @@ -1535,11 +1544,11 @@ function setupMobile() { var inputType = self.config.enableTime ? self.config.noCalendar ? "time" : "datetime-local" : "date"; self.mobileInput = createElement("input", self.input.className + " flatpickr-mobile"); - self.mobileInput.step = "any"; + self.mobileInput.step = self.input.getAttribute("step") || "any"; self.mobileInput.tabIndex = 1; self.mobileInput.type = inputType; self.mobileInput.disabled = self.input.disabled; self.mobileInput.placeholder = self.input.placeholder; @@ -2018,10 +2027,12 @@ * @param {String} givenFormat the date format, e.g. Y-m-d H:i * @param {Boolean} timeless whether to reset the time of Date object * @return {Date} the parsed Date object */ parseDate: function parseDate(date, givenFormat, timeless) { + var _this2 = this; + if (date !== 0 && !date) return null; var date_orig = date; if (date instanceof Date) date = new Date(date.getTime()); // create a copy @@ -2035,29 +2046,41 @@ if (date === "today") { date = new Date(); timeless = true; } else if (/Z$/.test(date) || /GMT$/.test(date)) // datestrings w/ timezone date = new Date(date);else if (this.config && this.config.parseDate) date = this.config.parseDate(date, format);else { - var parsedDate = !this.config || !this.config.noCalendar ? new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0) : new Date(new Date().setHours(0, 0, 0, 0)); + (function () { + var parsedDate = !_this2.config || !_this2.config.noCalendar ? new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0) : new Date(new Date().setHours(0, 0, 0, 0)); - var matched = void 0; + var matched = void 0, + ops = []; - for (var i = 0, matchIndex = 0, regexStr = ""; i < format.length; i++) { - var token = format[i]; - var isBackSlash = token === "\\"; - var escaped = format[i - 1] === "\\" || isBackSlash; + for (var i = 0, matchIndex = 0, regexStr = ""; i < format.length; i++) { + var token = format[i]; + var isBackSlash = token === "\\"; + var escaped = format[i - 1] === "\\" || isBackSlash; - if (this.tokenRegex[token] && !escaped) { - regexStr += this.tokenRegex[token]; - var match = new RegExp(regexStr).exec(date); - if (match && (matched = true)) { - parsedDate = this.revFormat[token](parsedDate, match[++matchIndex]) || parsedDate; - } - } else if (!isBackSlash) regexStr += "."; // don't really care - } + if (_this2.tokenRegex[token] && !escaped) { + regexStr += _this2.tokenRegex[token]; + var match = new RegExp(regexStr).exec(date); + if (match && (matched = true)) { + ops[token !== "Y" ? "push" : "unshift"]({ + fn: _this2.revFormat[token], + val: match[++matchIndex] + }); + } + } else if (!isBackSlash) regexStr += "."; // don't really care - date = matched ? parsedDate : null; + ops.forEach(function (_ref) { + var fn = _ref.fn, + val = _ref.val; + return parsedDate = fn(parsedDate, val) || parsedDate; + }); + } + + date = matched ? parsedDate : null; + })(); } } /* istanbul ignore next */ if (!(date instanceof Date)) { @@ -2118,11 +2141,11 @@ flatpickr.defaultConfig = FlatpickrInstance.defaultConfig = { mode: "single", position: "auto", - animate: window.navigator.userAgent.indexOf("MSIE") === -1, + animate: typeof window !== "undefined" && window.navigator.userAgent.indexOf("MSIE") === -1, // wrap: see https://chmln.github.io/flatpickr/examples/#flatpickr-external-elements wrap: false, // enables week numbers @@ -2224,9 +2247,12 @@ // initial value in the hour element defaultHour: 12, // initial value in the minute element defaultMinute: 0, + + // initial value in the seconds element + defaultSeconds: 0, // disable native mobile datetime input support disableMobile: false, // default locale \ No newline at end of file