vendor/assets/javascripts/flatpickr.js in flatpickr-2.6.3.0 vs vendor/assets/javascripts/flatpickr.js in flatpickr-3.0.0.0
- old
+ new
@@ -1,15 +1,18 @@
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.3, @license MIT */
-function Flatpickr(element, config) {
+/*! flatpickr v3.0.5-1, @license MIT */
+function FlatpickrInstance(element, config) {
var self = this;
self._ = {};
self._.afterDayAnim = afterDayAnim;
+ self._bind = bind;
+ self._compareDates = compareDates;
+ self._setHoursFromDate = setHoursFromDate;
self.changeMonth = changeMonth;
self.changeYear = changeYear;
self.clear = clear;
self.close = close;
self._createElement = createElement;
@@ -23,12 +26,12 @@
self.toggle = toggle;
function init() {
self.element = self.input = element;
self.instanceConfig = config || {};
- self.parseDate = Flatpickr.prototype.parseDate.bind(self);
- self.formatDate = Flatpickr.prototype.formatDate.bind(self);
+ self.parseDate = FlatpickrInstance.prototype.parseDate.bind(self);
+ self.formatDate = FlatpickrInstance.prototype.formatDate.bind(self);
setupFormats();
parseConfig();
setupLocale();
setupInputs();
@@ -48,16 +51,16 @@
setHoursFromDate(self.config.noCalendar ? self.latestSelectedDateObj || self.config.minDate : null);
}
updateValue();
}
+ self.showTimeInput = self.selectedDates.length > 0 || self.config.noCalendar;
+
if (self.config.weekNumbers) {
self.calendarContainer.style.width = self.daysContainer.offsetWidth + self.weekWrapper.offsetWidth + "px";
}
- self.showTimeInput = self.selectedDates.length > 0 || self.config.noCalendar;
-
if (!self.isMobile) positionCalendar();
triggerEvent("Ready");
}
@@ -236,11 +239,14 @@
if (window.ontouchstart !== undefined) bind(window.document, "touchstart", documentClick);
bind(window.document, "mousedown", onClick(documentClick));
bind(self._input, "blur", documentClick);
- if (self.config.clickOpens === true) bind(self._input, "focus", self.open);
+ if (self.config.clickOpens === true) {
+ bind(self._input, "focus", self.open);
+ bind(self._input, "mousedown", onClick(self.open));
+ }
if (!self.config.noCalendar) {
self.monthNav.addEventListener("wheel", function (e) {
return e.preventDefault();
});
@@ -838,10 +844,12 @@
triggerEvent("Close");
}
function destroy() {
+ if (self.config !== undefined) triggerEvent("Destroy");
+
for (var i = self._handlers.length; i--;) {
var h = self._handlers[i];
h.element.removeEventListener(h.event, h.handler);
}
@@ -883,12 +891,11 @@
// web components
e.path && e.path.indexOf && (~e.path.indexOf(self.input) || ~e.path.indexOf(self.altInput));
var lostFocus = e.type === "blur" ? isInput && e.relatedTarget && !isCalendarElem(e.relatedTarget) : !isInput && !isCalendarElement;
- if (lostFocus) {
- e.preventDefault();
+ if (lostFocus && self.config.ignoredFocusElements.indexOf(e.target) === -1) {
self.close();
if (self.config.mode === "range" && self.selectedDates.length === 1) {
self.clear(false);
self.redraw();
@@ -1087,11 +1094,11 @@
function onResize() {
if (self.isOpen && !self.config.static && !self.config.inline) positionCalendar();
}
- function open(e) {
+ function open(e, positionElement) {
if (self.isMobile) {
if (e) {
e.preventDefault();
e.target.blur();
}
@@ -1106,11 +1113,11 @@
if (self.isOpen || self._input.disabled || self.config.inline) return;
self.isOpen = true;
self.calendarContainer.classList.add("open");
- positionCalendar();
+ positionCalendar(positionElement);
self._input.classList.add("active");
triggerEvent("Open");
}
@@ -1142,29 +1149,47 @@
}
};
}
function parseConfig() {
- var boolOpts = ["utc", "wrap", "weekNumbers", "allowInput", "clickOpens", "time_24hr", "enableTime", "noCalendar", "altInput", "shorthandCurrentMonth", "inline", "static", "enableSeconds", "disableMobile"];
+ var boolOpts = ["wrap", "weekNumbers", "allowInput", "clickOpens", "time_24hr", "enableTime", "noCalendar", "altInput", "shorthandCurrentMonth", "inline", "static", "enableSeconds", "disableMobile"];
- var hooks = ["onChange", "onClose", "onDayCreate", "onKeyDown", "onMonthChange", "onOpen", "onParseConfig", "onReady", "onValueUpdate", "onYearChange"];
+ var hooks = ["onChange", "onClose", "onDayCreate", "onDestroy", "onKeyDown", "onMonthChange", "onOpen", "onParseConfig", "onReady", "onValueUpdate", "onYearChange"];
- self.config = Object.create(Flatpickr.defaultConfig);
+ self.config = Object.create(flatpickr.defaultConfig);
var userConfig = _extends({}, self.instanceConfig, JSON.parse(JSON.stringify(self.element.dataset || {})));
self.config.parseDate = userConfig.parseDate;
self.config.formatDate = userConfig.formatDate;
+ Object.defineProperty(self.config, "enable", {
+ get: function get() {
+ return self.config._enable || [];
+ },
+ set: function set(dates) {
+ return self.config._enable = parseDateRules(dates);
+ }
+ });
+
+ Object.defineProperty(self.config, "disable", {
+ get: function get() {
+ return self.config._disable || [];
+ },
+ set: function set(dates) {
+ return self.config._disable = parseDateRules(dates);
+ }
+ });
+
_extends(self.config, userConfig);
if (!userConfig.dateFormat && userConfig.enableTime) {
- self.config.dateFormat = self.config.noCalendar ? "H:i" + (self.config.enableSeconds ? ":S" : "") : Flatpickr.defaultConfig.dateFormat + " H:i" + (self.config.enableSeconds ? ":S" : "");
+ self.config.dateFormat = self.config.noCalendar ? "H:i" + (self.config.enableSeconds ? ":S" : "") : flatpickr.defaultConfig.dateFormat + " H:i" + (self.config.enableSeconds ? ":S" : "");
}
if (userConfig.altInput && userConfig.enableTime && !userConfig.altFormat) {
- self.config.altFormat = self.config.noCalendar ? "h:i" + (self.config.enableSeconds ? ":S K" : " K") : Flatpickr.defaultConfig.altFormat + (" h:i" + (self.config.enableSeconds ? ":S" : "") + " K");
+ self.config.altFormat = self.config.noCalendar ? "h:i" + (self.config.enableSeconds ? ":S K" : " K") : flatpickr.defaultConfig.altFormat + (" h:i" + (self.config.enableSeconds ? ":S" : "") + " K");
}
Object.defineProperty(self.config, "minDate", {
get: function get() {
return this._minDate;
@@ -1202,26 +1227,28 @@
triggerEvent("ParseConfig");
}
function setupLocale() {
- if (_typeof(self.config.locale) !== "object" && typeof Flatpickr.l10ns[self.config.locale] === "undefined") console.warn("flatpickr: invalid locale " + self.config.locale);
+ if (_typeof(self.config.locale) !== "object" && typeof flatpickr.l10ns[self.config.locale] === "undefined") console.warn("flatpickr: invalid locale " + self.config.locale);
- self.l10n = _extends(Object.create(Flatpickr.l10ns.default), _typeof(self.config.locale) === "object" ? self.config.locale : self.config.locale !== "default" ? Flatpickr.l10ns[self.config.locale] || {} : {});
+ self.l10n = _extends(Object.create(flatpickr.l10ns.default), _typeof(self.config.locale) === "object" ? self.config.locale : self.config.locale !== "default" ? flatpickr.l10ns[self.config.locale] || {} : {});
}
function positionCalendar() {
+ var positionElement = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : self._positionElement;
+
if (self.calendarContainer === undefined) return;
var calendarHeight = self.calendarContainer.offsetHeight,
calendarWidth = self.calendarContainer.offsetWidth,
configPos = self.config.position,
- inputBounds = self._positionElement.getBoundingClientRect(),
+ inputBounds = 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._positionElement.offsetHeight + 2 : -calendarHeight - 2);
+ var top = window.pageYOffset + inputBounds.top + (!showOnTop ? positionElement.offsetHeight + 2 : -calendarHeight - 2);
toggleClass(self.calendarContainer, "arrowTop", !showOnTop);
toggleClass(self.calendarContainer, "arrowBottom", showOnTop);
if (self.config.inline) return;
@@ -1371,11 +1398,11 @@
return a.getTime() - b.getTime();
});
}
function setDate(date, triggerChange, format) {
- if (!date) return self.clear(triggerChange);
+ if (date !== 0 && !date) return self.clear(triggerChange);
setSelectedDate(date, format);
self.showTimeInput = self.selectedDates.length > 0;
self.latestSelectedDateObj = self.selectedDates[0];
@@ -1387,31 +1414,27 @@
updateValue(triggerChange);
if (triggerChange) triggerEvent("Change");
}
- function setupDates() {
- function parseDateRules(arr) {
- for (var i = arr.length; i--;) {
- if (typeof arr[i] === "string" || +arr[i]) arr[i] = self.parseDate(arr[i], null, true);else if (arr[i] && arr[i].from && arr[i].to) {
- arr[i].from = self.parseDate(arr[i].from);
- arr[i].to = self.parseDate(arr[i].to);
- }
+ function parseDateRules(arr) {
+ for (var i = arr.length; i--;) {
+ if (typeof arr[i] === "string" || +arr[i]) arr[i] = self.parseDate(arr[i], null, true);else if (arr[i] && arr[i].from && arr[i].to) {
+ arr[i].from = self.parseDate(arr[i].from);
+ arr[i].to = self.parseDate(arr[i].to);
}
-
- return arr.filter(function (x) {
- return x;
- }); // remove falsy values
}
+ return arr.filter(function (x) {
+ return x;
+ }); // remove falsy values
+ }
+
+ function setupDates() {
self.selectedDates = [];
self.now = new Date();
- if (self.config.disable.length) self.config.disable = parseDateRules(self.config.disable);
-
- if (self.config.enable.length) self.config.enable = parseDateRules(self.config.enable);
-
var preloadedDate = self.config.defaultDate || self.input.value;
if (preloadedDate) setSelectedDate(preloadedDate, self.config.dateFormat);
var initialDate = self.selectedDates.length ? self.selectedDates[0] : self.config.minDate && self.config.minDate.getTime() > self.now ? self.config.minDate : self.config.maxDate && self.config.maxDate.getTime() < self.now ? self.config.maxDate : self.now;
@@ -1469,16 +1492,17 @@
};
}
/* istanbul ignore next */
function setupFormats() {
+ self.formats = Object.create(FlatpickrInstance.prototype.formats);
["D", "F", "J", "M", "W", "l"].forEach(function (f) {
- self.formats[f] = Flatpickr.prototype.formats[f].bind(self);
+ self.formats[f] = FlatpickrInstance.prototype.formats[f].bind(self);
});
- self.revFormat.F = Flatpickr.prototype.revFormat.F.bind(self);
- self.revFormat.M = Flatpickr.prototype.revFormat.M.bind(self);
+ self.revFormat.F = FlatpickrInstance.prototype.revFormat.F.bind(self);
+ self.revFormat.M = FlatpickrInstance.prototype.revFormat.M.bind(self);
}
function setupInputs() {
self.input = self.config.wrap ? self.element.querySelector("[data-input]") : self.element;
@@ -1495,10 +1519,11 @@
// 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.required = self.input.required;
self.altInput.type = "text";
self.input.type = "hidden";
if (!self.config.static && self.input.parentNode) self.input.parentNode.insertBefore(self.altInput, self.input.nextSibling);
}
@@ -1623,11 +1648,12 @@
if (self.config.altInput) {
self.altInput.value = self.selectedDates.map(function (dObj) {
return self.formatDate(dObj, self.config.altFormat);
}).join(joinChar);
}
- triggerEvent("ValueUpdate");
+
+ if (triggerChange !== false) triggerEvent("ValueUpdate");
}
function mouseDelta(e) {
return Math.max(-1, Math.min(1, e.wheelDelta || -e.deltaY));
}
@@ -1758,208 +1784,11 @@
init();
return self;
}
-/* istanbul ignore next */
-Flatpickr.defaultConfig = {
- mode: "single",
-
- position: "auto",
-
- animate: window.navigator.userAgent.indexOf("MSIE") === -1,
-
- /* if true, dates will be parsed, formatted, and displayed in UTC.
- preloading date strings w/ timezones is recommended but not necessary */
- utc: false,
-
- // wrap: see https://chmln.github.io/flatpickr/examples/#flatpickr-external-elements
- wrap: false,
-
- // enables week numbers
- weekNumbers: false,
-
- // allow manual datetime input
- allowInput: false,
-
- /*
- clicking on input opens the date(time)picker.
- disable if you wish to open the calendar manually with .open()
- */
- clickOpens: true,
-
- /*
- closes calendar after date selection,
- unless 'mode' is 'multiple' or enableTime is true
- */
- closeOnSelect: true,
-
- // display time picker in 24 hour mode
- time_24hr: false,
-
- // enables the time picker functionality
- enableTime: false,
-
- // noCalendar: true will hide the calendar. use for a time picker along w/ enableTime
- noCalendar: false,
-
- // more date format chars at https://chmln.github.io/flatpickr/#dateformat
- dateFormat: "Y-m-d",
-
- // date format used in aria-label for days
- ariaDateFormat: "F j, Y",
-
- // altInput - see https://chmln.github.io/flatpickr/#altinput
- altInput: false,
-
- // the created altInput element will have this class.
- 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
- defaultDate: null,
-
- // the minimum date that user can pick (inclusive)
- minDate: null,
-
- // the maximum date that user can pick (inclusive)
- maxDate: null,
-
- // dateparser that transforms a given string to a date object
- parseDate: null,
-
- // dateformatter that transforms a given date object to a string, according to passed format
- formatDate: null,
-
- getWeek: function getWeek(givenDate) {
- var date = new Date(givenDate.getTime());
- var onejan = new Date(date.getFullYear(), 0, 1);
- return Math.ceil(((date - onejan) / 86400000 + onejan.getDay() + 1) / 7);
- },
-
-
- // see https://chmln.github.io/flatpickr/#disable
- enable: [],
-
- // see https://chmln.github.io/flatpickr/#disable
- disable: [],
-
- // display the short version of month names - e.g. Sep instead of September
- shorthandCurrentMonth: false,
-
- // displays calendar inline. see https://chmln.github.io/flatpickr/#inline-calendar
- inline: false,
-
- // position calendar inside wrapper and next to the input element
- // leave at false unless you know what you"re doing
- "static": false,
-
- // DOM node to append the calendar to in *static* mode
- appendTo: null,
-
- // code for previous/next icons. this is where you put your custom icon code e.g. fontawesome
- prevArrow: "<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 17 17'><g></g><path d='M5.207 8.471l7.146 7.147-0.707 0.707-7.853-7.854 7.854-7.853 0.707 0.707-7.147 7.146z' /></svg>",
- nextArrow: "<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 17 17'><g></g><path d='M13.207 8.472l-7.854 7.854-0.707-0.707 7.146-7.146-7.146-7.148 0.707-0.707 7.854 7.854z' /></svg>",
-
- // enables seconds in the time picker
- enableSeconds: false,
-
- // step size used when scrolling/incrementing the hour element
- hourIncrement: 1,
-
- // step size used when scrolling/incrementing the minute element
- minuteIncrement: 5,
-
- // initial value in the hour element
- defaultHour: 12,
-
- // initial value in the minute element
- defaultMinute: 0,
-
- // disable native mobile datetime input support
- disableMobile: false,
-
- // default locale
- locale: "default",
-
- plugins: [],
-
- // called every time calendar is closed
- onClose: undefined, // function (dateObj, dateStr) {}
-
- // onChange callback when user selects a date or time
- onChange: undefined, // function (dateObj, dateStr) {}
-
- // called for every day element
- onDayCreate: undefined,
-
- // called every time the month is changed
- onMonthChange: undefined,
-
- // called every time calendar is opened
- onOpen: undefined, // function (dateObj, dateStr) {}
-
- // called after the configuration has been parsed
- onParseConfig: undefined,
-
- // called after calendar is ready
- onReady: undefined, // function (dateObj, dateStr) {}
-
- // called after input value updated
- onValueUpdate: undefined,
-
- // called every time the year is changed
- onYearChange: undefined,
-
- onKeyDown: undefined
-};
-
-/* istanbul ignore next */
-Flatpickr.l10ns = {
- en: {
- weekdays: {
- shorthand: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
- longhand: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
- },
- months: {
- shorthand: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
- longhand: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
- },
- daysInMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
- firstDayOfWeek: 0,
- ordinal: function ordinal(nth) {
- var s = nth % 100;
- if (s > 3 && s < 21) return "th";
- switch (s % 10) {
- case 1:
- return "st";
- case 2:
- return "nd";
- case 3:
- return "rd";
- default:
- return "th";
- }
- },
- rangeSeparator: " to ",
- weekAbbreviation: "Wk",
- scrollTitle: "Scroll to increment",
- toggleTitle: "Click to toggle"
- }
-};
-
-Flatpickr.l10ns.default = Object.create(Flatpickr.l10ns.en);
-Flatpickr.localize = function (l10n) {
- return _extends(Flatpickr.l10ns.default, l10n || {});
-};
-Flatpickr.setDefaults = function (config) {
- return _extends(Flatpickr.defaultConfig, config || {});
-};
-
-Flatpickr.prototype = {
+FlatpickrInstance.prototype = {
formats: {
// get the date in UTC
Z: function Z(date) {
return date.toISOString();
},
@@ -1974,16 +1803,16 @@
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));
+ return FlatpickrInstance.prototype.pad(FlatpickrInstance.prototype.formats.h(date));
},
// hours with leading zero e.g. 03
H: function H(date) {
- return Flatpickr.prototype.pad(date.getHours());
+ return FlatpickrInstance.prototype.pad(date.getHours());
},
// day (1-30) with ordinal suffix e.g. 1st, 2nd
J: function J(date) {
return date.getDate() + this.l10n.ordinal(date.getDate());
@@ -1999,11 +1828,11 @@
return this.utils.monthToStr(date.getMonth(), true);
},
// seconds 00-59
S: function S(date) {
- return Flatpickr.prototype.pad(date.getSeconds());
+ return FlatpickrInstance.prototype.pad(date.getSeconds());
},
// unix timestamp
U: function U(date) {
return date.getTime() / 1000;
@@ -2018,21 +1847,21 @@
return date.getFullYear();
},
// day in month, padded (01-30)
d: function d(date) {
- return Flatpickr.prototype.pad(date.getDate());
+ return FlatpickrInstance.prototype.pad(date.getDate());
},
// hour from 1-12 (am/pm)
h: function h(date) {
return date.getHours() % 12 ? date.getHours() % 12 : 12;
},
// minutes, padded with leading zero e.g. 09
i: function i(date) {
- return Flatpickr.prototype.pad(date.getMinutes());
+ return FlatpickrInstance.prototype.pad(date.getMinutes());
},
// day in month (1-30)
j: function j(date) {
return date.getDate();
@@ -2043,11 +1872,11 @@
return this.l10n.weekdays.longhand[date.getDay()];
},
// padded month number (01-12)
m: function m(date) {
- return Flatpickr.prototype.pad(date.getMonth() + 1);
+ return FlatpickrInstance.prototype.pad(date.getMonth() + 1);
},
// the month number (1-12)
n: function n(date) {
return date.getMonth() + 1;
@@ -2158,11 +1987,11 @@
D: "(\\w+)",
F: "(\\w+)",
G: "(\\d\\d|\\d)",
H: "(\\d\\d|\\d)",
J: "(\\d\\d|\\d)\\w+",
- K: "(\\w+)",
+ K: "(am|AM|Am|aM|pm|PM|Pm|pM)",
M: "(\\w+)",
S: "(\\d\\d|\\d)",
U: "(.+)",
W: "(\\d\\d|\\d)",
Y: "(\\d{4})",
@@ -2189,59 +2018,56 @@
* @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) {
- if (!date) return null;
+ if (date !== 0 && !date) return null;
var date_orig = date;
- 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();
+ if (date instanceof Date) date = new Date(date.getTime()); // create a copy
- 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));
+ 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();
- var matched = void 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));
- for (var i = 0, matchIndex = 0, regexStr = ""; i < format.length; i++) {
- var token = format[i];
- var isBackSlash = token === "\\";
- var escaped = format[i - 1] === "\\" || isBackSlash;
+ var matched = void 0;
- 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
- }
+ for (var i = 0, matchIndex = 0, regexStr = ""; i < format.length; i++) {
+ var token = format[i];
+ var isBackSlash = token === "\\";
+ var escaped = format[i - 1] === "\\" || isBackSlash;
- 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);
return null;
}
- if (this.config && this.config.utc && !date.fp_isUTC) date = date.fp_toUTC();
-
if (timeless === true) date.setHours(0, 0, 0, 0);
return date;
}
};
@@ -2250,11 +2076,18 @@
function _flatpickr(nodeList, config) {
var nodes = Array.prototype.slice.call(nodeList); // static list
var instances = [];
for (var i = 0; i < nodes.length; i++) {
try {
- nodes[i]._flatpickr = new Flatpickr(nodes[i], config || {});
+ if (nodes[i].getAttribute("data-fp-omit") !== null) continue;
+
+ if (nodes[i]._flatpickr) {
+ nodes[i]._flatpickr.destroy();
+ nodes[i]._flatpickr = null;
+ }
+
+ nodes[i]._flatpickr = new FlatpickrInstance(nodes[i], config || {});
instances.push(nodes[i]._flatpickr);
} catch (e) {
console.warn(e, e.stack);
}
}
@@ -2274,28 +2107,219 @@
};
}
/* istanbul ignore next */
function flatpickr(selector, config) {
- return _flatpickr(window.document.querySelectorAll(selector), config);
+ if (selector instanceof NodeList) return _flatpickr(selector, config);else if (!(selector instanceof HTMLElement)) return _flatpickr(window.document.querySelectorAll(selector), config);
+
+ return _flatpickr([selector], config);
}
/* istanbul ignore next */
+flatpickr.defaultConfig = FlatpickrInstance.defaultConfig = {
+ mode: "single",
+
+ position: "auto",
+
+ animate: window.navigator.userAgent.indexOf("MSIE") === -1,
+
+ // wrap: see https://chmln.github.io/flatpickr/examples/#flatpickr-external-elements
+ wrap: false,
+
+ // enables week numbers
+ weekNumbers: false,
+
+ // allow manual datetime input
+ allowInput: false,
+
+ /*
+ clicking on input opens the date(time)picker.
+ disable if you wish to open the calendar manually with .open()
+ */
+ clickOpens: true,
+
+ /*
+ closes calendar after date selection,
+ unless 'mode' is 'multiple' or enableTime is true
+ */
+ closeOnSelect: true,
+
+ // display time picker in 24 hour mode
+ time_24hr: false,
+
+ // enables the time picker functionality
+ enableTime: false,
+
+ // noCalendar: true will hide the calendar. use for a time picker along w/ enableTime
+ noCalendar: false,
+
+ // more date format chars at https://chmln.github.io/flatpickr/#dateformat
+ dateFormat: "Y-m-d",
+
+ // date format used in aria-label for days
+ ariaDateFormat: "F j, Y",
+
+ // altInput - see https://chmln.github.io/flatpickr/#altinput
+ altInput: false,
+
+ // the created altInput element will have this class.
+ 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
+ defaultDate: null,
+
+ // the minimum date that user can pick (inclusive)
+ minDate: null,
+
+ // the maximum date that user can pick (inclusive)
+ maxDate: null,
+
+ // dateparser that transforms a given string to a date object
+ parseDate: null,
+
+ // dateformatter that transforms a given date object to a string, according to passed format
+ formatDate: null,
+
+ getWeek: function getWeek(givenDate) {
+ var date = new Date(givenDate.getTime());
+ var onejan = new Date(date.getFullYear(), 0, 1);
+ return Math.ceil(((date - onejan) / 86400000 + onejan.getDay() + 1) / 7);
+ },
+
+
+ // see https://chmln.github.io/flatpickr/#disable
+ enable: [],
+
+ // see https://chmln.github.io/flatpickr/#disable
+ disable: [],
+
+ // display the short version of month names - e.g. Sep instead of September
+ shorthandCurrentMonth: false,
+
+ // displays calendar inline. see https://chmln.github.io/flatpickr/#inline-calendar
+ inline: false,
+
+ // position calendar inside wrapper and next to the input element
+ // leave at false unless you know what you"re doing
+ "static": false,
+
+ // DOM node to append the calendar to in *static* mode
+ appendTo: null,
+
+ // code for previous/next icons. this is where you put your custom icon code e.g. fontawesome
+ prevArrow: "<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 17 17'><g></g><path d='M5.207 8.471l7.146 7.147-0.707 0.707-7.853-7.854 7.854-7.853 0.707 0.707-7.147 7.146z' /></svg>",
+ nextArrow: "<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 17 17'><g></g><path d='M13.207 8.472l-7.854 7.854-0.707-0.707 7.146-7.146-7.146-7.148 0.707-0.707 7.854 7.854z' /></svg>",
+
+ // enables seconds in the time picker
+ enableSeconds: false,
+
+ // step size used when scrolling/incrementing the hour element
+ hourIncrement: 1,
+
+ // step size used when scrolling/incrementing the minute element
+ minuteIncrement: 5,
+
+ // initial value in the hour element
+ defaultHour: 12,
+
+ // initial value in the minute element
+ defaultMinute: 0,
+
+ // disable native mobile datetime input support
+ disableMobile: false,
+
+ // default locale
+ locale: "default",
+
+ plugins: [],
+
+ ignoredFocusElements: [],
+
+ // called every time calendar is closed
+ onClose: undefined, // function (dateObj, dateStr) {}
+
+ // onChange callback when user selects a date or time
+ onChange: undefined, // function (dateObj, dateStr) {}
+
+ // called for every day element
+ onDayCreate: undefined,
+
+ // called every time the month is changed
+ onMonthChange: undefined,
+
+ // called every time calendar is opened
+ onOpen: undefined, // function (dateObj, dateStr) {}
+
+ // called after the configuration has been parsed
+ onParseConfig: undefined,
+
+ // called after calendar is ready
+ onReady: undefined, // function (dateObj, dateStr) {}
+
+ // called after input value updated
+ onValueUpdate: undefined,
+
+ // called every time the year is changed
+ onYearChange: undefined,
+
+ onKeyDown: undefined,
+
+ onDestroy: undefined
+};
+
+/* istanbul ignore next */
+flatpickr.l10ns = {
+ en: {
+ weekdays: {
+ shorthand: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
+ longhand: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
+ },
+ months: {
+ shorthand: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
+ longhand: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
+ },
+ daysInMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
+ firstDayOfWeek: 0,
+ ordinal: function ordinal(nth) {
+ var s = nth % 100;
+ if (s > 3 && s < 21) return "th";
+ switch (s % 10) {
+ case 1:
+ return "st";
+ case 2:
+ return "nd";
+ case 3:
+ return "rd";
+ default:
+ return "th";
+ }
+ },
+ rangeSeparator: " to ",
+ weekAbbreviation: "Wk",
+ scrollTitle: "Scroll to increment",
+ toggleTitle: "Click to toggle"
+ }
+};
+
+flatpickr.l10ns.default = Object.create(flatpickr.l10ns.en);
+flatpickr.localize = function (l10n) {
+ return _extends(flatpickr.l10ns.default, l10n || {});
+};
+flatpickr.setDefaults = function (config) {
+ return _extends(flatpickr.defaultConfig, config || {});
+};
+
+/* istanbul ignore next */
if (typeof jQuery !== "undefined") {
jQuery.fn.flatpickr = function (config) {
return _flatpickr(this, config);
};
}
Date.prototype.fp_incr = function (days) {
return new Date(this.getFullYear(), this.getMonth(), this.getDate() + parseInt(days, 10));
};
-Date.prototype.fp_isUTC = false;
-Date.prototype.fp_toUTC = function () {
- var newDate = new Date(this.getUTCFullYear(), this.getUTCMonth(), this.getUTCDate(), this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds());
-
- newDate.fp_isUTC = true;
- return newDate;
-};
-
-if (typeof module !== "undefined") module.exports = Flatpickr;
+if (typeof module !== "undefined") module.exports = flatpickr;
\ No newline at end of file