vendor/assets/javascripts/flatpickr.js in flatpickr-2.5.8.0 vs vendor/assets/javascripts/flatpickr.js in flatpickr-2.5.9.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 v2.5.8, @license MIT */ +/*! flatpickr v2.5.9, @license MIT */ function Flatpickr(element, config) { var self = this; self._ = {}; self._.afterDayAnim = afterDayAnim; @@ -21,11 +21,11 @@ self.set = set; self.setDate = setDate; self.toggle = toggle; function init() { - if (element._flatpickr) element._flatpickr = undefined; + if (element._flatpickr) element._flatpickr.destroy(); element._flatpickr = self; self.element = element; self.instanceConfig = config || {}; @@ -106,11 +106,11 @@ var hours = (parseInt(self.hourElement.value, 10) || 0) % (self.amPM ? 12 : 24), minutes = (parseInt(self.minuteElement.value, 10) || 0) % 60, seconds = self.config.enableSeconds ? parseInt(self.secondElement.value, 10) || 0 : 0; - if (self.amPM) hours = hours % 12 + 12 * (self.amPM.textContent === "PM"); + if (self.amPM !== undefined) hours = hours % 12 + 12 * (self.amPM.textContent === "PM"); if (self.minDateHasTime && compareDates(self.latestSelectedDateObj, self.config.minDate) === 0) { hours = Math.max(hours, self.config.minDate.getHours()); if (hours === self.config.minDate.getHours()) minutes = Math.max(minutes, self.config.minDate.getMinutes()); @@ -234,39 +234,25 @@ if (!self.config.static) bind(self._input, "keydown", onKeyDown); if (!self.config.inline && !self.config.static) bind(window, "resize", self.debouncedResize); - if (window.ontouchstart) bind(window.document, "touchstart", documentClick); + if (window.ontouchstart !== undefined) bind(window.document, "touchstart", documentClick); bind(window.document, "mousedown", onClick(documentClick)); bind(self._input, "blur", documentClick); - if (self.config.clickOpens) bind(self._input, "focus", open); + if (self.config.clickOpens === true) bind(self._input, "focus", self.open); if (!self.config.noCalendar) { - bind(self.prevMonthNav, "mousedown", onClick(function () { - return changeMonth(-1); - })); - bind(self.nextMonthNav, "mousedown", onClick(function () { - return changeMonth(1); - })); - self.monthNav.addEventListener("wheel", function (e) { return e.preventDefault(); }); - bind(self.monthNav, "wheel", debounce(onMonthNavScroll, 10)); bind(self.monthNav, "mousedown", onClick(onMonthNavClick)); - bind(self.monthNav, "mousedown", onClick(function (e) { - e.preventDefault(); - if (e.target === self.currentYearElement) self.currentYearElement.select(); - })); - bind(self.monthNav, ["keyup", "increment"], onYearInput); - bind(self.daysContainer, "mousedown", onClick(selectDate)); if (self.config.animate) { bind(self.daysContainer, ["webkitAnimationEnd", "animationend"], animateDays); bind(self.monthNav, ["webkitAnimationEnd", "animationend"], animateMonths); @@ -1224,15 +1210,15 @@ if (self.calendarContainer === undefined) return; var calendarHeight = self.calendarContainer.offsetHeight, calendarWidth = self.calendarContainer.offsetWidth, configPos = self.config.position, - inputBounds = self._input.getBoundingClientRect(), + inputBounds = self._positionElement.getBoundingClientRect(), distanceFromBottom = window.innerHeight - inputBounds.bottom, showOnTop = configPos === "above" || configPos !== "below" && distanceFromBottom < calendarHeight && inputBounds.top > calendarHeight; - var top = window.pageYOffset + inputBounds.top + (!showOnTop ? self._input.offsetHeight + 2 : -calendarHeight - 2); + var top = window.pageYOffset + inputBounds.top + (!showOnTop ? self._positionElement.offsetHeight + 2 : -calendarHeight - 2); toggleClass(self.calendarContainer, "arrowTop", !showOnTop); toggleClass(self.calendarContainer, "arrowBottom", showOnTop); if (self.config.inline) return; @@ -1391,11 +1377,11 @@ self.redraw(); jumpToDate(); setHoursFromDate(); - updateValue(); + updateValue(triggerChange); if (triggerChange) triggerEvent("Change"); } function setupDates() { @@ -1489,10 +1475,12 @@ } function setupInputs() { self.input = self.config.wrap ? self.element.querySelector("[data-input]") : self.element; + self._positionElement = self.config.positionElement || self.input; + /* istanbul ignore next */ if (!self.input) return console.warn("Error: invalid input element specified", self.input); self.input._type = self.input.type; self.input.type = "text"; @@ -1576,15 +1564,12 @@ * Creates an Event, normalized across browsers * @param {String} name the event name, e.g. "click" * @return {Event} the created event */ function createEvent(name) { - var existing = self._[name + "Event"]; - if (existing !== undefined) return existing; + if (self._supportsEvents) return new Event(name, { bubbles: true }); - if (self._supportsEvents) return self._[name + "Event"] = new Event(name, { bubbles: true }); - self._[name + "Event"] = document.createEvent("Event"); self._[name + "Event"].initEvent(name, true, true); return self._[name + "Event"]; } @@ -1614,12 +1599,12 @@ /** * Updates the values of inputs associated with the calendar * @return {void} */ - function updateValue() { - if (!self.selectedDates.length) return self.clear(); + function updateValue(triggerChange) { + if (!self.selectedDates.length) return self.clear(triggerChange); if (self.isMobile) { self.mobileInput.value = self.selectedDates.length ? self.formatDate(self.latestSelectedDateObj, self.mobileFormatStr) : ""; } @@ -1632,11 +1617,10 @@ if (self.config.altInput) { self.altInput.value = self.selectedDates.map(function (dObj) { return self.formatDate(dObj, self.config.altFormat); }).join(joinChar); } - triggerEvent("ValueUpdate"); } function mouseDelta(e) { return Math.max(-1, Math.min(1, e.wheelDelta || -e.deltaY)); @@ -1656,11 +1640,17 @@ } else self.changeMonth(delta, true, false); } } function onMonthNavClick(e) { - if (e.target.className === "arrowUp") self.changeYear(self.currentYear + 1);else if (e.target.className === "arrowDown") self.changeYear(self.currentYear - 1); + var isPrevMonth = self.prevMonthNav.contains(e.target); + var isNextMonth = self.nextMonthNav.contains(e.target); + + if (isPrevMonth || isNextMonth) changeMonth(isPrevMonth ? -1 : 1);else if (e.target === self.currentYearElement) { + e.preventDefault(); + self.currentYearElement.select(); + } else if (e.target.className === "arrowUp") self.changeYear(self.currentYear + 1);else if (e.target.className === "arrowDown") self.changeYear(self.currentYear - 1); } /** * Creates an HTMLElement with given tag, class, and textual content * @param {String} tag the HTML tag @@ -1805,11 +1795,11 @@ // altInput - see https://chmln.github.io/flatpickr/#altinput altInput: false, // the created altInput element will have this class. - altInputClass: "flatpickr-input form-control input", + altInputClass: "form-control input", // same as dateFormat, but for altInput altFormat: "F j, Y", // defaults to e.g. June 10, 2016 // defaultDate - either a datestring or a date object. used for datetimepicker"s initial value @@ -2179,43 +2169,44 @@ parseDate: function parseDate(date, givenFormat, timeless) { if (!date) return null; var date_orig = date; - if (date instanceof Date) date = new Date(date.getTime()); // create a copy + if (date instanceof Date) { + date = new Date(date.getTime()); // create a copy + date.fp_isUTC = date_orig.fp_isUTC; + } else if (date.toFixed !== undefined) // timestamp + date = new Date(date);else { + // date string + var format = givenFormat || (this.config || Flatpickr.defaultConfig).dateFormat; + date = String(date).trim(); - else if (date.toFixed !== undefined) // timestamp - date = new Date(date);else { - // date string - var format = givenFormat || (this.config || Flatpickr.defaultConfig).dateFormat; - date = String(date).trim(); + 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)); - 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)); + var matched = void 0; - var matched = void 0; + 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 - } - - date = matched ? parsedDate : null; + 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 } + + date = matched ? parsedDate : null; } + } /* istanbul ignore next */ if (!(date instanceof Date)) { console.warn("flatpickr: invalid date " + date_orig); console.info(this.element); \ No newline at end of file