vendor/assets/javascripts/flatpickr.js in flatpickr-2.4.9.0 vs vendor/assets/javascripts/flatpickr.js in flatpickr-2.5.3.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.4.9, @license MIT */
+/*! flatpickr v2.5.3, @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) destroy(element._flatpickr);
+ if (element._flatpickr) element._flatpickr = undefined;
element._flatpickr = self;
self.element = element;
self.instanceConfig = config || {};
@@ -171,20 +171,20 @@
return onMouseOver(e.target);
});
document.body.addEventListener("keydown", onKeyDown);
- if (!self.config.static) (self.altInput || self.input).addEventListener("keydown", onKeyDown);
+ if (!self.config.static) self._input.addEventListener("keydown", onKeyDown);
if (!self.config.inline && !self.config.static) window.addEventListener("resize", self.debouncedResize);
if (window.ontouchstart) window.document.addEventListener("touchstart", documentClick);
window.document.addEventListener("click", documentClick);
- (self.altInput || self.input).addEventListener("blur", documentClick);
+ self._input.addEventListener("blur", documentClick);
- if (self.config.clickOpens) (self.altInput || self.input).addEventListener("focus", open);
+ if (self.config.clickOpens) self._input.addEventListener("focus", open);
if (!self.config.noCalendar) {
self.prevMonthNav.addEventListener("click", function () {
return changeMonth(-1);
});
@@ -273,16 +273,21 @@
}
}
function animateMonths(e) {
switch (e.animationName) {
- case "slideLeft":
- case "slideRight":
+ case "slideLeftNew":
+ case "slideRightNew":
self.navigationCurrentMonth.classList.remove("slideLeftNew");
self.navigationCurrentMonth.classList.remove("slideRightNew");
- self.monthNav.removeChild(self.oldCurMonth);
- self.oldCurMonth = null;
+ var nav = self.navigationCurrentMonth;
+
+ while (nav.nextSibling && /curr/.test(nav.nextSibling.className)) {
+ self.monthNav.removeChild(nav.nextSibling);
+ }while (nav.previousSibling && /curr/.test(nav.previousSibling.className)) {
+ self.monthNav.removeChild(nav.previousSibling);
+ }self.oldCurMonth = null;
break;
}
}
function jumpToDate(jumpDate) {
@@ -374,11 +379,11 @@
if (self.config.inline || self.config.static) {
self.calendarContainer.classList.add(self.config.inline ? "inline" : "static");
if (self.config.inline && !customAppend) {
- return self.element.parentNode.insertBefore(self.calendarContainer, (self.altInput || self.input).nextSibling);
+ return self.element.parentNode.insertBefore(self.calendarContainer, self._input.nextSibling);
}
if (self.config.static) {
var wrapper = createElement("div", "flatpickr-wrapper");
self.element.parentNode.insertBefore(wrapper, self.element);
@@ -701,11 +706,24 @@
if (skipAnimations) {
triggerEvent("MonthChange");
return updateNavigationCurrentMonth();
}
+ // remove possible remnants from clicking too fast
+ var nav = self.navigationCurrentMonth;
+ if (delta < 0) {
+ while (nav.nextSibling && /curr/.test(nav.nextSibling.className)) {
+ self.monthNav.removeChild(nav.nextSibling);
+ }
+ } else if (delta > 0) {
+ while (nav.previousSibling && /curr/.test(nav.previousSibling.className)) {
+ self.monthNav.removeChild(nav.previousSibling);
+ }
+ }
+
self.oldCurMonth = self.navigationCurrentMonth;
+
self.navigationCurrentMonth = self.monthNav.insertBefore(self.oldCurMonth.cloneNode(true), delta > 0 ? self.oldCurMonth.nextSibling : self.oldCurMonth);
if (delta > 0) {
self.daysContainer.firstChild.classList.add("slideLeft");
self.daysContainer.lastChild.classList.add("slideLeftNew");
@@ -756,43 +774,46 @@
function close() {
self.isOpen = false;
if (!self.isMobile) {
self.calendarContainer.classList.remove("open");
- (self.altInput || self.input).classList.remove("active");
+ self._input.classList.remove("active");
}
triggerEvent("Close");
}
function destroy(instance) {
instance = instance || self;
- instance.clear(false);
window.removeEventListener("resize", instance.debouncedResize);
window.document.removeEventListener("click", documentClick);
window.document.removeEventListener("touchstart", documentClick);
window.document.removeEventListener("blur", documentClick);
if (instance.mobileInput) {
if (instance.mobileInput.parentNode) instance.mobileInput.parentNode.removeChild(instance.mobileInput);
- delete instance.mobileInput;
+ instance.mobileInput = undefined;
} else if (instance.calendarContainer && instance.calendarContainer.parentNode) instance.calendarContainer.parentNode.removeChild(instance.calendarContainer);
if (instance.altInput) {
instance.input.type = "text";
if (instance.altInput.parentNode) instance.altInput.parentNode.removeChild(instance.altInput);
- delete instance.altInput;
+ instance.altInput = undefined;
}
- instance.input.type = instance.input._type;
- instance.input.classList.remove("flatpickr-input");
- instance.input.removeEventListener("focus", open);
- instance.input.removeAttribute("readonly");
+ if (instance.input) {
+ instance.input.type = instance.input._type;
+ instance.input.classList.remove("flatpickr-input");
+ instance.input.removeEventListener("focus", open);
+ instance.input.removeAttribute("readonly");
+ instance.input.value = "";
+ }
- delete instance.input._flatpickr;
+ instance.config = undefined;
+ instance.input._flatpickr = undefined;
}
function isCalendarElem(elem) {
if (self.config.appendTo && self.config.appendTo.contains(elem)) return true;
@@ -864,17 +885,20 @@
return !bool;
}
function onKeyDown(e) {
- var isInput = e.target === (self.altInput || self.input);
+ var isInput = e.target === self._input;
var calendarElem = isCalendarElem(e.target);
+ var allowInput = self.config.allowInput;
+ var allowKeydown = self.isOpen && (!allowInput || !isInput);
+ var allowInlineKeydown = self.config.inline && isInput && !allowInput;
- if (e.key === "Enter" && self.config.allowInput && isInput) {
- self.setDate((self.altInput || self.input).value, true, e.target === self.altInput ? self.config.altFormat : self.config.dateFormat);
+ if (e.key === "Enter" && allowInput && isInput) {
+ self.setDate(self._input.value, true, e.target === self.altInput ? self.config.altFormat : self.config.dateFormat);
return e.target.blur();
- } else if (self.isOpen || self.config.inline && (isInput || calendarElem)) {
+ } else if (calendarElem || allowKeydown || allowInlineKeydown) {
var isTimeObj = self.timeContainer && self.timeContainer.contains(e.target);
switch (e.key) {
case "Enter":
if (isTimeObj) updateValue();else selectDate(e);
@@ -1022,16 +1046,16 @@
triggerEvent("Open");
return;
}
- if (self.isOpen || (self.altInput || self.input).disabled || self.config.inline) return;
+ if (self.isOpen || self._input.disabled || self.config.inline) return;
self.isOpen = true;
self.calendarContainer.classList.add("open");
positionCalendar();
- (self.altInput || self.input).classList.add("active");
+ self._input.classList.add("active");
triggerEvent("Open");
}
function minMaxDateSetter(type) {
@@ -1129,11 +1153,11 @@
if (self.calendarContainer === undefined) return;
var calendarHeight = self.calendarContainer.offsetHeight,
calendarWidth = self.calendarContainer.offsetWidth,
configPos = self.config.position,
- input = self.altInput || self.input,
+ input = self._input,
inputBounds = input.getBoundingClientRect(),
distanceFromBottom = window.innerHeight - inputBounds.bottom + input.offsetHeight,
showOnTop = configPos === "above" || configPos !== "below" && distanceFromBottom < calendarHeight && inputBounds.top > calendarHeight;
var top = window.pageYOffset + inputBounds.top + (!showOnTop ? input.offsetHeight + 2 : -calendarHeight - 2);
@@ -1397,26 +1421,27 @@
function setupInputs() {
self.input = self.config.wrap ? self.element.querySelector("[data-input]") : self.element;
/* 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";
self.input.classList.add("flatpickr-input");
+ self._input = self.input;
if (self.config.altInput) {
// replicate self.element
self.altInput = createElement(self.input.nodeName, self.input.className + " " + self.config.altInputClass);
+ self._input = self.altInput;
self.altInput.placeholder = self.input.placeholder;
self.altInput.type = "text";
self.input.type = "hidden";
if (!self.config.static && self.input.parentNode) self.input.parentNode.insertBefore(self.altInput, self.input.nextSibling);
}
- if (!self.config.allowInput) (self.altInput || self.input).setAttribute("readonly", "readonly");
+ if (!self.config.allowInput) self._input.setAttribute("readonly", "readonly");
}
function setupMobile() {
var inputType = self.config.enableTime ? self.config.noCalendar ? "time" : "datetime-local" : "date";
@@ -1977,11 +2002,14 @@
},
U: function U(dateObj, unixSeconds) {
return new Date(parseFloat(unixSeconds) * 1000);
},
- W: function W() {},
+ W: function W(dateObj, weekNumber) {
+ weekNumber = parseInt(weekNumber);
+ return new Date(dateObj.getFullYear(), 0, 2 + (weekNumber - 1) * 7, 0, 0, 0, 0, 0);
+ },
Y: function Y(dateObj, year) {
dateObj.setFullYear(year);
},
Z: function Z(dateObj, ISODate) {
return new Date(ISODate);
@@ -2022,9 +2050,10 @@
J: "(\\d\\d|\\d)\\w+",
K: "(\\w+)",
M: "(\\w+)",
S: "(\\d\\d|\\d)",
U: "(.+)",
+ W: "(\\d\\d|\\d)",
Y: "(\\d{4})",
Z: "(.+)",
d: "(\\d\\d|\\d)",
h: "(\\d\\d|\\d)",
i: "(\\d\\d|\\d)",
\ No newline at end of file