vendor/assets/javascripts/flatpickr.js in flatpickr-2.6.2.0 vs vendor/assets/javascripts/flatpickr.js in flatpickr-2.6.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.6.2, @license MIT */
+/*! flatpickr v2.6.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() {
- self.element = element;
+ self.element = self.input = element;
self.instanceConfig = config || {};
self.parseDate = Flatpickr.prototype.parseDate.bind(self);
self.formatDate = Flatpickr.prototype.formatDate.bind(self);
setupFormats();
@@ -204,10 +204,11 @@
/**
* Adds all the necessary event listeners
*/
function bindEvents() {
self._handlers = [];
+ self._animationLoop = [];
if (self.config.wrap) {
["open", "close", "toggle", "clear"].forEach(function (evt) {
Array.prototype.forEach.call(self.element.querySelectorAll("[data-" + evt + "]"), function (el) {
return bind(el, "mousedown", onClick(self[evt]));
});
@@ -278,10 +279,17 @@
}));
}
}
}
+ function processPostDayAnimation() {
+ for (var i = self._animationLoop.length; i--;) {
+ self._animationLoop[i]();
+ self._animationLoop.splice(i, 1);
+ }
+ }
+
/**
* Removes the day container that slided out of view
* @param {Event} e the animation event
*/
function animateDays(e) {
@@ -289,17 +297,19 @@
switch (e.animationName) {
case "fpSlideLeft":
self.daysContainer.lastChild.classList.remove("slideLeftNew");
self.daysContainer.removeChild(self.daysContainer.firstChild);
self.days = self.daysContainer.firstChild;
+ processPostDayAnimation();
break;
case "fpSlideRight":
self.daysContainer.firstChild.classList.remove("slideRightNew");
self.daysContainer.removeChild(self.daysContainer.lastChild);
self.days = self.daysContainer.firstChild;
+ processPostDayAnimation();
break;
default:
break;
@@ -513,11 +523,11 @@
focus();
}
function afterDayAnim(fn) {
- if (self.config.animate) return setTimeout(fn, self._.daysAnimDuration + 1);
+ if (self.config.animate === true) return self._animationLoop.push(fn);
fn();
}
function buildDays(delta) {
var firstOfMonth = (new Date(self.currentYear, self.currentMonth, 1).getDay() - self.l10n.firstDayOfWeek + 7) % 7,
@@ -790,16 +800,15 @@
updateNavigationCurrentMonth();
self.oldCurMonth.firstChild.textContent = self.utils.monthToStr(self.currentMonth - delta);
triggerEvent("MonthChange");
- if (self._.daysAnimDuration === undefined) {
- var compStyle = window.getComputedStyle(self.daysContainer.lastChild);
-
- var duration = compStyle.getPropertyValue("animation-duration") || compStyle.getPropertyValue("-webkit-animation-duration");
-
- self._.daysAnimDuration = parseInt(/(\d+)s/.exec(duration)[1]);
+ if (document.activeElement && document.activeElement.$i) {
+ var index = document.activeElement.$i;
+ afterDayAnim(function () {
+ focusOnDay(index, 0);
+ });
}
}
function clear(triggerChangeEvent) {
self.input.value = "";
@@ -963,16 +972,11 @@
e.preventDefault();
if (self.daysContainer) {
var _delta = e.key === "ArrowRight" ? 1 : -1;
- if (!e.ctrlKey) focusOnDay(e.target.$i, _delta);else {
- changeMonth(_delta, true);
- afterDayAnim(function () {
- focusOnDay(e.target.$i, 0);
- });
- }
+ if (!e.ctrlKey) focusOnDay(e.target.$i, _delta);else changeMonth(_delta, true);
} else if (self.config.enableTime && !isTimeObj) self.hourElement.focus();
}
break;
@@ -1316,11 +1320,16 @@
if (self.config.enableTime) setTimeout(function () {
return self.hourElement.select();
}, 451);
- if (self.config.mode !== "multiple" && !self.config.enableTime && self.config.closeOnSelect) self.close();
+ if (self.config.closeOnSelect) {
+ var single = self.config.mode === "single" && !self.config.enableTime;
+ var range = self.config.mode === "range" && self.selectedDates.length === 2 && !self.config.enableTime;
+
+ if (single || range) self.close();
+ }
}
function set(option, value) {
self.config[option] = value;
self.redraw();
@@ -1485,10 +1494,11 @@
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.disabled = self.input.disabled;
self.altInput.type = "text";
self.input.type = "hidden";
if (!self.config.static && self.input.parentNode) self.input.parentNode.insertBefore(self.altInput, self.input.nextSibling);
}
@@ -1542,11 +1552,11 @@
function triggerEvent(event, data) {
var hooks = self.config["on" + event];
if (hooks !== undefined && hooks.length > 0) {
for (var i = 0; hooks[i] && i < hooks.length; i++) {
- hooks[i](self.selectedDates, self._input.value, self, data);
+ hooks[i](self.selectedDates, self.input.value, self, data);
}
}
if (event === "Change") {
self.input.dispatchEvent(createEvent("change"));
@@ -1962,10 +1972,15 @@
// full month name e.g. January
F: function F(date) {
return this.utils.monthToStr(this.formats.n(date) - 1, false);
},
+ // padded hour 1-12
+ G: function G(date) {
+ return Flatpickr.prototype.pad(Flatpickr.prototype.formats.h(date));
+ },
+
// hours with leading zero e.g. 03
H: function H(date) {
return Flatpickr.prototype.pad(date.getHours());
},
@@ -2074,10 +2089,13 @@
revFormat: {
D: function D() {},
F: function F(dateObj, monthName) {
dateObj.setMonth(this.l10n.months.longhand.indexOf(monthName));
},
+ G: function G(dateObj, hour) {
+ dateObj.setHours(parseFloat(hour));
+ },
H: function H(dateObj, hour) {
dateObj.setHours(parseFloat(hour));
},
J: function J(dateObj, day) {
dateObj.setDate(parseFloat(day));
@@ -2137,9 +2155,10 @@
},
tokenRegex: {
D: "(\\w+)",
F: "(\\w+)",
+ G: "(\\d\\d|\\d)",
H: "(\\d\\d|\\d)",
J: "(\\d\\d|\\d)\\w+",
K: "(\\w+)",
M: "(\\w+)",
S: "(\\d\\d|\\d)",
\ No newline at end of file