PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.5.2
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.5.2
3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / assets / js / flatpickr / flatpickr.js
everest-forms / assets / js / flatpickr Last commit date
dist 3 years ago flatpickr.js 6 years ago flatpickr.min.js 1 year ago
flatpickr.js
2606 lines
1 /* flatpickr v4.6.3, @license MIT */
2 (function (global, factory) {
3 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4 typeof define === 'function' && define.amd ? define(factory) :
5 (global = global || self, global.flatpickr = factory());
6 }(this, function () { 'use strict';
7
8 /*! *****************************************************************************
9 Copyright (c) Microsoft Corporation. All rights reserved.
10 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
11 this file except in compliance with the License. You may obtain a copy of the
12 License at http://www.apache.org/licenses/LICENSE-2.0
13
14 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 MERCHANTABLITY OR NON-INFRINGEMENT.
18
19 See the Apache Version 2.0 License for specific language governing permissions
20 and limitations under the License.
21 ***************************************************************************** */
22
23 var __assign = function() {
24 __assign = Object.assign || function __assign(t) {
25 for (var s, i = 1, n = arguments.length; i < n; i++) {
26 s = arguments[i];
27 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
28 }
29 return t;
30 };
31 return __assign.apply(this, arguments);
32 };
33
34 var HOOKS = [
35 "onChange",
36 "onClose",
37 "onDayCreate",
38 "onDestroy",
39 "onKeyDown",
40 "onMonthChange",
41 "onOpen",
42 "onParseConfig",
43 "onReady",
44 "onValueUpdate",
45 "onYearChange",
46 "onPreCalendarPosition",
47 ];
48 var defaults = {
49 _disable: [],
50 _enable: [],
51 allowInput: false,
52 altFormat: "F j, Y",
53 altInput: false,
54 altInputClass: "form-control input",
55 animate: typeof window === "object" &&
56 window.navigator.userAgent.indexOf("MSIE") === -1,
57 ariaDateFormat: "F j, Y",
58 clickOpens: true,
59 closeOnSelect: true,
60 conjunction: ", ",
61 dateFormat: "Y-m-d",
62 defaultHour: 12,
63 defaultMinute: 0,
64 defaultSeconds: 0,
65 disable: [],
66 disableMobile: false,
67 enable: [],
68 enableSeconds: false,
69 enableTime: false,
70 errorHandler: function (err) {
71 return typeof console !== "undefined" && console.warn(err);
72 },
73 getWeek: function (givenDate) {
74 var date = new Date(givenDate.getTime());
75 date.setHours(0, 0, 0, 0);
76 // Thursday in current week decides the year.
77 date.setDate(date.getDate() + 3 - ((date.getDay() + 6) % 7));
78 // January 4 is always in week 1.
79 var week1 = new Date(date.getFullYear(), 0, 4);
80 // Adjust to Thursday in week 1 and count number of weeks from date to week1.
81 return (1 +
82 Math.round(((date.getTime() - week1.getTime()) / 86400000 -
83 3 +
84 ((week1.getDay() + 6) % 7)) /
85 7));
86 },
87 hourIncrement: 1,
88 ignoredFocusElements: [],
89 inline: false,
90 locale: "default",
91 minuteIncrement: 5,
92 mode: "single",
93 monthSelectorType: "dropdown",
94 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>",
95 noCalendar: false,
96 now: new Date(),
97 onChange: [],
98 onClose: [],
99 onDayCreate: [],
100 onDestroy: [],
101 onKeyDown: [],
102 onMonthChange: [],
103 onOpen: [],
104 onParseConfig: [],
105 onReady: [],
106 onValueUpdate: [],
107 onYearChange: [],
108 onPreCalendarPosition: [],
109 plugins: [],
110 position: "auto",
111 positionElement: undefined,
112 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>",
113 shorthandCurrentMonth: false,
114 showMonths: 1,
115 static: false,
116 time_24hr: false,
117 weekNumbers: false,
118 wrap: false
119 };
120
121 var english = {
122 weekdays: {
123 shorthand: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
124 longhand: [
125 "Sunday",
126 "Monday",
127 "Tuesday",
128 "Wednesday",
129 "Thursday",
130 "Friday",
131 "Saturday",
132 ]
133 },
134 months: {
135 shorthand: [
136 "Jan",
137 "Feb",
138 "Mar",
139 "Apr",
140 "May",
141 "Jun",
142 "Jul",
143 "Aug",
144 "Sep",
145 "Oct",
146 "Nov",
147 "Dec",
148 ],
149 longhand: [
150 "January",
151 "February",
152 "March",
153 "April",
154 "May",
155 "June",
156 "July",
157 "August",
158 "September",
159 "October",
160 "November",
161 "December",
162 ]
163 },
164 daysInMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
165 firstDayOfWeek: 0,
166 ordinal: function (nth) {
167 var s = nth % 100;
168 if (s > 3 && s < 21)
169 return "th";
170 switch (s % 10) {
171 case 1:
172 return "st";
173 case 2:
174 return "nd";
175 case 3:
176 return "rd";
177 default:
178 return "th";
179 }
180 },
181 rangeSeparator: " to ",
182 weekAbbreviation: "Wk",
183 scrollTitle: "Scroll to increment",
184 toggleTitle: "Click to toggle",
185 amPM: ["AM", "PM"],
186 yearAriaLabel: "Year",
187 hourAriaLabel: "Hour",
188 minuteAriaLabel: "Minute",
189 time_24hr: false
190 };
191
192 var pad = function (number) { return ("0" + number).slice(-2); };
193 var int = function (bool) { return (bool === true ? 1 : 0); };
194 /* istanbul ignore next */
195 function debounce(func, wait, immediate) {
196 if (immediate === void 0) { immediate = false; }
197 var timeout;
198 return function () {
199 var context = this, args = arguments;
200 timeout !== null && clearTimeout(timeout);
201 timeout = window.setTimeout(function () {
202 timeout = null;
203 if (!immediate)
204 func.apply(context, args);
205 }, wait);
206 if (immediate && !timeout)
207 func.apply(context, args);
208 };
209 }
210 var arrayify = function (obj) {
211 return obj instanceof Array ? obj : [obj];
212 };
213
214 function toggleClass(elem, className, bool) {
215 if (bool === true)
216 return elem.classList.add(className);
217 elem.classList.remove(className);
218 }
219 function createElement(tag, className, content) {
220 var e = window.document.createElement(tag);
221 className = className || "";
222 content = content || "";
223 e.className = className;
224 if (content !== undefined)
225 e.textContent = content;
226 return e;
227 }
228 function clearNode(node) {
229 while (node.firstChild)
230 node.removeChild(node.firstChild);
231 }
232 function findParent(node, condition) {
233 if (condition(node))
234 return node;
235 else if (node.parentNode)
236 return findParent(node.parentNode, condition);
237 return undefined; // nothing found
238 }
239 function createNumberInput(inputClassName, opts) {
240 var wrapper = createElement("div", "numInputWrapper"), numInput = createElement("input", "numInput " + inputClassName), arrowUp = createElement("span", "arrowUp"), arrowDown = createElement("span", "arrowDown");
241 if (navigator.userAgent.indexOf("MSIE 9.0") === -1) {
242 numInput.type = "number";
243 }
244 else {
245 numInput.type = "text";
246 numInput.pattern = "\\d*";
247 }
248 if (opts !== undefined)
249 for (var key in opts)
250 numInput.setAttribute(key, opts[key]);
251 wrapper.appendChild(numInput);
252 wrapper.appendChild(arrowUp);
253 wrapper.appendChild(arrowDown);
254 return wrapper;
255 }
256 function getEventTarget(event) {
257 if (typeof event.composedPath === "function") {
258 var path = event.composedPath();
259 return path[0];
260 }
261 return event.target;
262 }
263
264 var doNothing = function () { return undefined; };
265 var monthToStr = function (monthNumber, shorthand, locale) { return locale.months[shorthand ? "shorthand" : "longhand"][monthNumber]; };
266 var revFormat = {
267 D: doNothing,
268 F: function (dateObj, monthName, locale) {
269 dateObj.setMonth(locale.months.longhand.indexOf(monthName));
270 },
271 G: function (dateObj, hour) {
272 dateObj.setHours(parseFloat(hour));
273 },
274 H: function (dateObj, hour) {
275 dateObj.setHours(parseFloat(hour));
276 },
277 J: function (dateObj, day) {
278 dateObj.setDate(parseFloat(day));
279 },
280 K: function (dateObj, amPM, locale) {
281 dateObj.setHours((dateObj.getHours() % 12) +
282 12 * int(new RegExp(locale.amPM[1], "i").test(amPM)));
283 },
284 M: function (dateObj, shortMonth, locale) {
285 dateObj.setMonth(locale.months.shorthand.indexOf(shortMonth));
286 },
287 S: function (dateObj, seconds) {
288 dateObj.setSeconds(parseFloat(seconds));
289 },
290 U: function (_, unixSeconds) { return new Date(parseFloat(unixSeconds) * 1000); },
291 W: function (dateObj, weekNum, locale) {
292 var weekNumber = parseInt(weekNum);
293 var date = new Date(dateObj.getFullYear(), 0, 2 + (weekNumber - 1) * 7, 0, 0, 0, 0);
294 date.setDate(date.getDate() - date.getDay() + locale.firstDayOfWeek);
295 return date;
296 },
297 Y: function (dateObj, year) {
298 dateObj.setFullYear(parseFloat(year));
299 },
300 Z: function (_, ISODate) { return new Date(ISODate); },
301 d: function (dateObj, day) {
302 dateObj.setDate(parseFloat(day));
303 },
304 h: function (dateObj, hour) {
305 dateObj.setHours(parseFloat(hour));
306 },
307 i: function (dateObj, minutes) {
308 dateObj.setMinutes(parseFloat(minutes));
309 },
310 j: function (dateObj, day) {
311 dateObj.setDate(parseFloat(day));
312 },
313 l: doNothing,
314 m: function (dateObj, month) {
315 dateObj.setMonth(parseFloat(month) - 1);
316 },
317 n: function (dateObj, month) {
318 dateObj.setMonth(parseFloat(month) - 1);
319 },
320 s: function (dateObj, seconds) {
321 dateObj.setSeconds(parseFloat(seconds));
322 },
323 u: function (_, unixMillSeconds) {
324 return new Date(parseFloat(unixMillSeconds));
325 },
326 w: doNothing,
327 y: function (dateObj, year) {
328 dateObj.setFullYear(2000 + parseFloat(year));
329 }
330 };
331 var tokenRegex = {
332 D: "(\\w+)",
333 F: "(\\w+)",
334 G: "(\\d\\d|\\d)",
335 H: "(\\d\\d|\\d)",
336 J: "(\\d\\d|\\d)\\w+",
337 K: "",
338 M: "(\\w+)",
339 S: "(\\d\\d|\\d)",
340 U: "(.+)",
341 W: "(\\d\\d|\\d)",
342 Y: "(\\d{4})",
343 Z: "(.+)",
344 d: "(\\d\\d|\\d)",
345 h: "(\\d\\d|\\d)",
346 i: "(\\d\\d|\\d)",
347 j: "(\\d\\d|\\d)",
348 l: "(\\w+)",
349 m: "(\\d\\d|\\d)",
350 n: "(\\d\\d|\\d)",
351 s: "(\\d\\d|\\d)",
352 u: "(.+)",
353 w: "(\\d\\d|\\d)",
354 y: "(\\d{2})"
355 };
356 var formats = {
357 // get the date in UTC
358 Z: function (date) { return date.toISOString(); },
359 // weekday name, short, e.g. Thu
360 D: function (date, locale, options) {
361 return locale.weekdays.shorthand[formats.w(date, locale, options)];
362 },
363 // full month name e.g. January
364 F: function (date, locale, options) {
365 return monthToStr(formats.n(date, locale, options) - 1, false, locale);
366 },
367 // padded hour 1-12
368 G: function (date, locale, options) {
369 return pad(formats.h(date, locale, options));
370 },
371 // hours with leading zero e.g. 03
372 H: function (date) { return pad(date.getHours()); },
373 // day (1-30) with ordinal suffix e.g. 1st, 2nd
374 J: function (date, locale) {
375 return locale.ordinal !== undefined
376 ? date.getDate() + locale.ordinal(date.getDate())
377 : date.getDate();
378 },
379 // AM/PM
380 K: function (date, locale) { return locale.amPM[int(date.getHours() > 11)]; },
381 // shorthand month e.g. Jan, Sep, Oct, etc
382 M: function (date, locale) {
383 return monthToStr(date.getMonth(), true, locale);
384 },
385 // seconds 00-59
386 S: function (date) { return pad(date.getSeconds()); },
387 // unix timestamp
388 U: function (date) { return date.getTime() / 1000; },
389 W: function (date, _, options) {
390 return options.getWeek(date);
391 },
392 // full year e.g. 2016
393 Y: function (date) { return date.getFullYear(); },
394 // day in month, padded (01-30)
395 d: function (date) { return pad(date.getDate()); },
396 // hour from 1-12 (am/pm)
397 h: function (date) { return (date.getHours() % 12 ? date.getHours() % 12 : 12); },
398 // minutes, padded with leading zero e.g. 09
399 i: function (date) { return pad(date.getMinutes()); },
400 // day in month (1-30)
401 j: function (date) { return date.getDate(); },
402 // weekday name, full, e.g. Thursday
403 l: function (date, locale) {
404 return locale.weekdays.longhand[date.getDay()];
405 },
406 // padded month number (01-12)
407 m: function (date) { return pad(date.getMonth() + 1); },
408 // the month number (1-12)
409 n: function (date) { return date.getMonth() + 1; },
410 // seconds 0-59
411 s: function (date) { return date.getSeconds(); },
412 // Unix Milliseconds
413 u: function (date) { return date.getTime(); },
414 // number of the day of the week
415 w: function (date) { return date.getDay(); },
416 // last two digits of year e.g. 16 for 2016
417 y: function (date) { return String(date.getFullYear()).substring(2); }
418 };
419
420 var createDateFormatter = function (_a) {
421 var _b = _a.config, config = _b === void 0 ? defaults : _b, _c = _a.l10n, l10n = _c === void 0 ? english : _c;
422 return function (dateObj, frmt, overrideLocale) {
423 var locale = overrideLocale || l10n;
424 if (config.formatDate !== undefined) {
425 return config.formatDate(dateObj, frmt, locale);
426 }
427 return frmt
428 .split("")
429 .map(function (c, i, arr) {
430 return formats[c] && arr[i - 1] !== "\\"
431 ? formats[c](dateObj, locale, config)
432 : c !== "\\"
433 ? c
434 : "";
435 })
436 .join("");
437 };
438 };
439 var createDateParser = function (_a) {
440 var _b = _a.config, config = _b === void 0 ? defaults : _b, _c = _a.l10n, l10n = _c === void 0 ? english : _c;
441 return function (date, givenFormat, timeless, customLocale) {
442 if (date !== 0 && !date)
443 return undefined;
444 var locale = customLocale || l10n;
445 var parsedDate;
446 var dateOrig = date;
447 if (date instanceof Date)
448 parsedDate = new Date(date.getTime());
449 else if (typeof date !== "string" &&
450 date.toFixed !== undefined // timestamp
451 )
452 // create a copy
453 parsedDate = new Date(date);
454 else if (typeof date === "string") {
455 // date string
456 var format = givenFormat || (config || defaults).dateFormat;
457 var datestr = String(date).trim();
458 if (datestr === "today") {
459 parsedDate = new Date();
460 timeless = true;
461 }
462 else if (/Z$/.test(datestr) ||
463 /GMT$/.test(datestr) // datestrings w/ timezone
464 )
465 parsedDate = new Date(date);
466 else if (config && config.parseDate)
467 parsedDate = config.parseDate(date, format);
468 else {
469 parsedDate =
470 !config || !config.noCalendar
471 ? new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0)
472 : new Date(new Date().setHours(0, 0, 0, 0));
473 var matched = void 0, ops = [];
474 for (var i = 0, matchIndex = 0, regexStr = ""; i < format.length; i++) {
475 var token_1 = format[i];
476 var isBackSlash = token_1 === "\\";
477 var escaped = format[i - 1] === "\\" || isBackSlash;
478 if (tokenRegex[token_1] && !escaped) {
479 regexStr += tokenRegex[token_1];
480 var match = new RegExp(regexStr).exec(date);
481 if (match && (matched = true)) {
482 ops[token_1 !== "Y" ? "push" : "unshift"]({
483 fn: revFormat[token_1],
484 val: match[++matchIndex]
485 });
486 }
487 }
488 else if (!isBackSlash)
489 regexStr += "."; // don't really care
490 ops.forEach(function (_a) {
491 var fn = _a.fn, val = _a.val;
492 return (parsedDate = fn(parsedDate, val, locale) || parsedDate);
493 });
494 }
495 parsedDate = matched ? parsedDate : undefined;
496 }
497 }
498 /* istanbul ignore next */
499 if (!(parsedDate instanceof Date && !isNaN(parsedDate.getTime()))) {
500 config.errorHandler(new Error("Invalid date provided: " + dateOrig));
501 return undefined;
502 }
503 if (timeless === true)
504 parsedDate.setHours(0, 0, 0, 0);
505 return parsedDate;
506 };
507 };
508 /**
509 * Compute the difference in dates, measured in ms
510 */
511 function compareDates(date1, date2, timeless) {
512 if (timeless === void 0) { timeless = true; }
513 if (timeless !== false) {
514 return (new Date(date1.getTime()).setHours(0, 0, 0, 0) -
515 new Date(date2.getTime()).setHours(0, 0, 0, 0));
516 }
517 return date1.getTime() - date2.getTime();
518 }
519 var isBetween = function (ts, ts1, ts2) {
520 return ts > Math.min(ts1, ts2) && ts < Math.max(ts1, ts2);
521 };
522 var duration = {
523 DAY: 86400000
524 };
525
526 if (typeof Object.assign !== "function") {
527 Object.assign = function (target) {
528 var args = [];
529 for (var _i = 1; _i < arguments.length; _i++) {
530 args[_i - 1] = arguments[_i];
531 }
532 if (!target) {
533 throw TypeError("Cannot convert undefined or null to object");
534 }
535 var _loop_1 = function (source) {
536 if (source) {
537 Object.keys(source).forEach(function (key) { return (target[key] = source[key]); });
538 }
539 };
540 for (var _a = 0, args_1 = args; _a < args_1.length; _a++) {
541 var source = args_1[_a];
542 _loop_1(source);
543 }
544 return target;
545 };
546 }
547
548 var DEBOUNCED_CHANGE_MS = 300;
549 function FlatpickrInstance(element, instanceConfig) {
550 var self = {
551 config: __assign({}, defaults, flatpickr.defaultConfig),
552 l10n: english
553 };
554 self.parseDate = createDateParser({ config: self.config, l10n: self.l10n });
555 self._handlers = [];
556 self.pluginElements = [];
557 self.loadedPlugins = [];
558 self._bind = bind;
559 self._setHoursFromDate = setHoursFromDate;
560 self._positionCalendar = positionCalendar;
561 self.changeMonth = changeMonth;
562 self.changeYear = changeYear;
563 self.clear = clear;
564 self.close = close;
565 self._createElement = createElement;
566 self.destroy = destroy;
567 self.isEnabled = isEnabled;
568 self.jumpToDate = jumpToDate;
569 self.open = open;
570 self.redraw = redraw;
571 self.set = set;
572 self.setDate = setDate;
573 self.toggle = toggle;
574 function setupHelperFunctions() {
575 self.utils = {
576 getDaysInMonth: function (month, yr) {
577 if (month === void 0) { month = self.currentMonth; }
578 if (yr === void 0) { yr = self.currentYear; }
579 if (month === 1 && ((yr % 4 === 0 && yr % 100 !== 0) || yr % 400 === 0))
580 return 29;
581 return self.l10n.daysInMonth[month];
582 }
583 };
584 }
585 function init() {
586 self.element = self.input = element;
587 self.isOpen = false;
588 parseConfig();
589 setupLocale();
590 setupInputs();
591 setupDates();
592 setupHelperFunctions();
593 if (!self.isMobile)
594 build();
595 bindEvents();
596 if (self.selectedDates.length || self.config.noCalendar) {
597 if (self.config.enableTime) {
598 setHoursFromDate(self.config.noCalendar
599 ? self.latestSelectedDateObj || self.config.minDate
600 : undefined);
601 }
602 updateValue(false);
603 }
604 setCalendarWidth();
605 self.showTimeInput =
606 self.selectedDates.length > 0 || self.config.noCalendar;
607 var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
608 /* TODO: investigate this further
609
610 Currently, there is weird positioning behavior in safari causing pages
611 to scroll up. https://github.com/chmln/flatpickr/issues/563
612
613 However, most browsers are not Safari and positioning is expensive when used
614 in scale. https://github.com/chmln/flatpickr/issues/1096
615 */
616 if (!self.isMobile && isSafari) {
617 positionCalendar();
618 }
619 triggerEvent("onReady");
620 }
621 function bindToInstance(fn) {
622 return fn.bind(self);
623 }
624 function setCalendarWidth() {
625 var config = self.config;
626 if (config.weekNumbers === false && config.showMonths === 1)
627 return;
628 else if (config.noCalendar !== true) {
629 window.requestAnimationFrame(function () {
630 if (self.calendarContainer !== undefined) {
631 self.calendarContainer.style.visibility = "hidden";
632 self.calendarContainer.style.display = "block";
633 }
634 if (self.daysContainer !== undefined) {
635 var daysWidth = (self.days.offsetWidth + 1) * config.showMonths;
636 self.daysContainer.style.width = daysWidth + "px";
637 self.calendarContainer.style.width =
638 daysWidth +
639 (self.weekWrapper !== undefined
640 ? self.weekWrapper.offsetWidth
641 : 0) +
642 "px";
643 self.calendarContainer.style.removeProperty("visibility");
644 self.calendarContainer.style.removeProperty("display");
645 }
646 });
647 }
648 }
649 /**
650 * The handler for all events targeting the time inputs
651 */
652 function updateTime(e) {
653 if (self.selectedDates.length === 0) {
654 setDefaultTime();
655 }
656 if (e !== undefined && e.type !== "blur") {
657 timeWrapper(e);
658 }
659 var prevValue = self._input.value;
660 setHoursFromInputs();
661 updateValue();
662 if (self._input.value !== prevValue) {
663 self._debouncedChange();
664 }
665 }
666 function ampm2military(hour, amPM) {
667 return (hour % 12) + 12 * int(amPM === self.l10n.amPM[1]);
668 }
669 function military2ampm(hour) {
670 switch (hour % 24) {
671 case 0:
672 case 12:
673 return 12;
674 default:
675 return hour % 12;
676 }
677 }
678 /**
679 * Syncs the selected date object time with user's time input
680 */
681 function setHoursFromInputs() {
682 if (self.hourElement === undefined || self.minuteElement === undefined)
683 return;
684 var hours = (parseInt(self.hourElement.value.slice(-2), 10) || 0) % 24, minutes = (parseInt(self.minuteElement.value, 10) || 0) % 60, seconds = self.secondElement !== undefined
685 ? (parseInt(self.secondElement.value, 10) || 0) % 60
686 : 0;
687 if (self.amPM !== undefined) {
688 hours = ampm2military(hours, self.amPM.textContent);
689 }
690 var limitMinHours = self.config.minTime !== undefined ||
691 (self.config.minDate &&
692 self.minDateHasTime &&
693 self.latestSelectedDateObj &&
694 compareDates(self.latestSelectedDateObj, self.config.minDate, true) ===
695 0);
696 var limitMaxHours = self.config.maxTime !== undefined ||
697 (self.config.maxDate &&
698 self.maxDateHasTime &&
699 self.latestSelectedDateObj &&
700 compareDates(self.latestSelectedDateObj, self.config.maxDate, true) ===
701 0);
702 if (limitMaxHours) {
703 var maxTime = self.config.maxTime !== undefined
704 ? self.config.maxTime
705 : self.config.maxDate;
706 hours = Math.min(hours, maxTime.getHours());
707 if (hours === maxTime.getHours())
708 minutes = Math.min(minutes, maxTime.getMinutes());
709 if (minutes === maxTime.getMinutes())
710 seconds = Math.min(seconds, maxTime.getSeconds());
711 }
712 if (limitMinHours) {
713 var minTime = self.config.minTime !== undefined
714 ? self.config.minTime
715 : self.config.minDate;
716 hours = Math.max(hours, minTime.getHours());
717 if (hours === minTime.getHours())
718 minutes = Math.max(minutes, minTime.getMinutes());
719 if (minutes === minTime.getMinutes())
720 seconds = Math.max(seconds, minTime.getSeconds());
721 }
722 setHours(hours, minutes, seconds);
723 }
724 /**
725 * Syncs time input values with a date
726 */
727 function setHoursFromDate(dateObj) {
728 var date = dateObj || self.latestSelectedDateObj;
729 if (date)
730 setHours(date.getHours(), date.getMinutes(), date.getSeconds());
731 }
732 function setDefaultHours() {
733 var hours = self.config.defaultHour;
734 var minutes = self.config.defaultMinute;
735 var seconds = self.config.defaultSeconds;
736 if (self.config.minDate !== undefined) {
737 var minHr = self.config.minDate.getHours();
738 var minMinutes = self.config.minDate.getMinutes();
739 hours = Math.max(hours, minHr);
740 if (hours === minHr)
741 minutes = Math.max(minMinutes, minutes);
742 if (hours === minHr && minutes === minMinutes)
743 seconds = self.config.minDate.getSeconds();
744 }
745 if (self.config.maxDate !== undefined) {
746 var maxHr = self.config.maxDate.getHours();
747 var maxMinutes = self.config.maxDate.getMinutes();
748 hours = Math.min(hours, maxHr);
749 if (hours === maxHr)
750 minutes = Math.min(maxMinutes, minutes);
751 if (hours === maxHr && minutes === maxMinutes)
752 seconds = self.config.maxDate.getSeconds();
753 }
754 setHours(hours, minutes, seconds);
755 }
756 /**
757 * Sets the hours, minutes, and optionally seconds
758 * of the latest selected date object and the
759 * corresponding time inputs
760 * @param {Number} hours the hour. whether its military
761 * or am-pm gets inferred from config
762 * @param {Number} minutes the minutes
763 * @param {Number} seconds the seconds (optional)
764 */
765 function setHours(hours, minutes, seconds) {
766 if (self.latestSelectedDateObj !== undefined) {
767 self.latestSelectedDateObj.setHours(hours % 24, minutes, seconds || 0, 0);
768 }
769 if (!self.hourElement || !self.minuteElement || self.isMobile)
770 return;
771 self.hourElement.value = pad(!self.config.time_24hr
772 ? ((12 + hours) % 12) + 12 * int(hours % 12 === 0)
773 : hours);
774 self.minuteElement.value = pad(minutes);
775 if (self.amPM !== undefined)
776 self.amPM.textContent = self.l10n.amPM[int(hours >= 12)];
777 if (self.secondElement !== undefined)
778 self.secondElement.value = pad(seconds);
779 }
780 /**
781 * Handles the year input and incrementing events
782 * @param {Event} event the keyup or increment event
783 */
784 function onYearInput(event) {
785 var year = parseInt(event.target.value) + (event.delta || 0);
786 if (year / 1000 > 1 ||
787 (event.key === "Enter" && !/[^\d]/.test(year.toString()))) {
788 changeYear(year);
789 }
790 }
791 /**
792 * Essentially addEventListener + tracking
793 * @param {Element} element the element to addEventListener to
794 * @param {String} event the event name
795 * @param {Function} handler the event handler
796 */
797 function bind(element, event, handler, options) {
798 if (event instanceof Array)
799 return event.forEach(function (ev) { return bind(element, ev, handler, options); });
800 if (element instanceof Array)
801 return element.forEach(function (el) { return bind(el, event, handler, options); });
802 element.addEventListener(event, handler, options);
803 self._handlers.push({
804 element: element,
805 event: event,
806 handler: handler,
807 options: options
808 });
809 }
810 /**
811 * A mousedown handler which mimics click.
812 * Minimizes latency, since we don't need to wait for mouseup in most cases.
813 * Also, avoids handling right clicks.
814 *
815 * @param {Function} handler the event handler
816 */
817 function onClick(handler) {
818 return function (evt) {
819 evt.which === 1 && handler(evt);
820 };
821 }
822 function triggerChange() {
823 triggerEvent("onChange");
824 }
825 /**
826 * Adds all the necessary event listeners
827 */
828 function bindEvents() {
829 if (self.config.wrap) {
830 ["open", "close", "toggle", "clear"].forEach(function (evt) {
831 Array.prototype.forEach.call(self.element.querySelectorAll("[data-" + evt + "]"), function (el) {
832 return bind(el, "click", self[evt]);
833 });
834 });
835 }
836 if (self.isMobile) {
837 setupMobile();
838 return;
839 }
840 var debouncedResize = debounce(onResize, 50);
841 self._debouncedChange = debounce(triggerChange, DEBOUNCED_CHANGE_MS);
842 if (self.daysContainer && !/iPhone|iPad|iPod/i.test(navigator.userAgent))
843 bind(self.daysContainer, "mouseover", function (e) {
844 if (self.config.mode === "range")
845 onMouseOver(e.target);
846 });
847 bind(window.document.body, "keydown", onKeyDown);
848 if (!self.config.inline && !self.config.static)
849 bind(window, "resize", debouncedResize);
850 if (window.ontouchstart !== undefined)
851 bind(window.document, "touchstart", documentClick);
852 else
853 bind(window.document, "mousedown", onClick(documentClick));
854 bind(window.document, "focus", documentClick, { capture: true });
855 if (self.config.clickOpens === true) {
856 bind(self._input, "focus", self.open);
857 bind(self._input, "mousedown", onClick(self.open));
858 }
859 if (self.daysContainer !== undefined) {
860 bind(self.monthNav, "mousedown", onClick(onMonthNavClick));
861 bind(self.monthNav, ["keyup", "increment"], onYearInput);
862 bind(self.daysContainer, "mousedown", onClick(selectDate));
863 }
864 if (self.timeContainer !== undefined &&
865 self.minuteElement !== undefined &&
866 self.hourElement !== undefined) {
867 var selText = function (e) {
868 return e.target.select();
869 };
870 bind(self.timeContainer, ["increment"], updateTime);
871 bind(self.timeContainer, "blur", updateTime, { capture: true });
872 bind(self.timeContainer, "mousedown", onClick(timeIncrement));
873 bind([self.hourElement, self.minuteElement], ["focus", "click"], selText);
874 if (self.secondElement !== undefined)
875 bind(self.secondElement, "focus", function () { return self.secondElement && self.secondElement.select(); });
876 if (self.amPM !== undefined) {
877 bind(self.amPM, "mousedown", onClick(function (e) {
878 updateTime(e);
879 triggerChange();
880 }));
881 }
882 }
883 }
884 /**
885 * Set the calendar view to a particular date.
886 * @param {Date} jumpDate the date to set the view to
887 * @param {boolean} triggerChange if change events should be triggered
888 */
889 function jumpToDate(jumpDate, triggerChange) {
890 var jumpTo = jumpDate !== undefined
891 ? self.parseDate(jumpDate)
892 : self.latestSelectedDateObj ||
893 (self.config.minDate && self.config.minDate > self.now
894 ? self.config.minDate
895 : self.config.maxDate && self.config.maxDate < self.now
896 ? self.config.maxDate
897 : self.now);
898 var oldYear = self.currentYear;
899 var oldMonth = self.currentMonth;
900 try {
901 if (jumpTo !== undefined) {
902 self.currentYear = jumpTo.getFullYear();
903 self.currentMonth = jumpTo.getMonth();
904 }
905 }
906 catch (e) {
907 /* istanbul ignore next */
908 e.message = "Invalid date supplied: " + jumpTo;
909 self.config.errorHandler(e);
910 }
911 if (triggerChange && self.currentYear !== oldYear) {
912 triggerEvent("onYearChange");
913 buildMonthSwitch();
914 }
915 if (triggerChange &&
916 (self.currentYear !== oldYear || self.currentMonth !== oldMonth)) {
917 triggerEvent("onMonthChange");
918 }
919 self.redraw();
920 }
921 /**
922 * The up/down arrow handler for time inputs
923 * @param {Event} e the click event
924 */
925 function timeIncrement(e) {
926 if (~e.target.className.indexOf("arrow"))
927 incrementNumInput(e, e.target.classList.contains("arrowUp") ? 1 : -1);
928 }
929 /**
930 * Increments/decrements the value of input associ-
931 * ated with the up/down arrow by dispatching an
932 * "increment" event on the input.
933 *
934 * @param {Event} e the click event
935 * @param {Number} delta the diff (usually 1 or -1)
936 * @param {Element} inputElem the input element
937 */
938 function incrementNumInput(e, delta, inputElem) {
939 var target = e && e.target;
940 var input = inputElem ||
941 (target && target.parentNode && target.parentNode.firstChild);
942 var event = createEvent("increment");
943 event.delta = delta;
944 input && input.dispatchEvent(event);
945 }
946 function build() {
947 var fragment = window.document.createDocumentFragment();
948 self.calendarContainer = createElement("div", "flatpickr-calendar");
949 self.calendarContainer.tabIndex = -1;
950 if (!self.config.noCalendar) {
951 fragment.appendChild(buildMonthNav());
952 self.innerContainer = createElement("div", "flatpickr-innerContainer");
953 if (self.config.weekNumbers) {
954 var _a = buildWeeks(), weekWrapper = _a.weekWrapper, weekNumbers = _a.weekNumbers;
955 self.innerContainer.appendChild(weekWrapper);
956 self.weekNumbers = weekNumbers;
957 self.weekWrapper = weekWrapper;
958 }
959 self.rContainer = createElement("div", "flatpickr-rContainer");
960 self.rContainer.appendChild(buildWeekdays());
961 if (!self.daysContainer) {
962 self.daysContainer = createElement("div", "flatpickr-days");
963 self.daysContainer.tabIndex = -1;
964 }
965 buildDays();
966 self.rContainer.appendChild(self.daysContainer);
967 self.innerContainer.appendChild(self.rContainer);
968 fragment.appendChild(self.innerContainer);
969 }
970 if (self.config.enableTime) {
971 fragment.appendChild(buildTime());
972 }
973 toggleClass(self.calendarContainer, "rangeMode", self.config.mode === "range");
974 toggleClass(self.calendarContainer, "animate", self.config.animate === true);
975 toggleClass(self.calendarContainer, "multiMonth", self.config.showMonths > 1);
976 self.calendarContainer.appendChild(fragment);
977 var customAppend = self.config.appendTo !== undefined &&
978 self.config.appendTo.nodeType !== undefined;
979 if (self.config.inline || self.config.static) {
980 self.calendarContainer.classList.add(self.config.inline ? "inline" : "static");
981 if (self.config.inline) {
982 if (!customAppend && self.element.parentNode)
983 self.element.parentNode.insertBefore(self.calendarContainer, self._input.nextSibling);
984 else if (self.config.appendTo !== undefined)
985 self.config.appendTo.appendChild(self.calendarContainer);
986 }
987 if (self.config.static) {
988 var wrapper = createElement("div", "flatpickr-wrapper");
989 if (self.element.parentNode)
990 self.element.parentNode.insertBefore(wrapper, self.element);
991 wrapper.appendChild(self.element);
992 if (self.altInput)
993 wrapper.appendChild(self.altInput);
994 wrapper.appendChild(self.calendarContainer);
995 }
996 }
997 if (!self.config.static && !self.config.inline)
998 (self.config.appendTo !== undefined
999 ? self.config.appendTo
1000 : window.document.body).appendChild(self.calendarContainer);
1001 }
1002 function createDay(className, date, dayNumber, i) {
1003 var dateIsEnabled = isEnabled(date, true), dayElement = createElement("span", "flatpickr-day " + className, date.getDate().toString());
1004 dayElement.dateObj = date;
1005 dayElement.$i = i;
1006 dayElement.setAttribute("aria-label", self.formatDate(date, self.config.ariaDateFormat));
1007 if (className.indexOf("hidden") === -1 &&
1008 compareDates(date, self.now) === 0) {
1009 self.todayDateElem = dayElement;
1010 dayElement.classList.add("today");
1011 dayElement.setAttribute("aria-current", "date");
1012 }
1013 if (dateIsEnabled) {
1014 dayElement.tabIndex = -1;
1015 if (isDateSelected(date)) {
1016 dayElement.classList.add("selected");
1017 self.selectedDateElem = dayElement;
1018 if (self.config.mode === "range") {
1019 toggleClass(dayElement, "startRange", self.selectedDates[0] &&
1020 compareDates(date, self.selectedDates[0], true) === 0);
1021 toggleClass(dayElement, "endRange", self.selectedDates[1] &&
1022 compareDates(date, self.selectedDates[1], true) === 0);
1023 if (className === "nextMonthDay")
1024 dayElement.classList.add("inRange");
1025 }
1026 }
1027 }
1028 else {
1029 dayElement.classList.add("flatpickr-disabled");
1030 }
1031 if (self.config.mode === "range") {
1032 if (isDateInRange(date) && !isDateSelected(date))
1033 dayElement.classList.add("inRange");
1034 }
1035 if (self.weekNumbers &&
1036 self.config.showMonths === 1 &&
1037 className !== "prevMonthDay" &&
1038 dayNumber % 7 === 1) {
1039 self.weekNumbers.insertAdjacentHTML("beforeend", "<span class='flatpickr-day'>" + self.config.getWeek(date) + "</span>");
1040 }
1041 triggerEvent("onDayCreate", dayElement);
1042 return dayElement;
1043 }
1044 function focusOnDayElem(targetNode) {
1045 targetNode.focus();
1046 if (self.config.mode === "range")
1047 onMouseOver(targetNode);
1048 }
1049 function getFirstAvailableDay(delta) {
1050 var startMonth = delta > 0 ? 0 : self.config.showMonths - 1;
1051 var endMonth = delta > 0 ? self.config.showMonths : -1;
1052 for (var m = startMonth; m != endMonth; m += delta) {
1053 var month = self.daysContainer.children[m];
1054 var startIndex = delta > 0 ? 0 : month.children.length - 1;
1055 var endIndex = delta > 0 ? month.children.length : -1;
1056 for (var i = startIndex; i != endIndex; i += delta) {
1057 var c = month.children[i];
1058 if (c.className.indexOf("hidden") === -1 && isEnabled(c.dateObj))
1059 return c;
1060 }
1061 }
1062 return undefined;
1063 }
1064 function getNextAvailableDay(current, delta) {
1065 var givenMonth = current.className.indexOf("Month") === -1
1066 ? current.dateObj.getMonth()
1067 : self.currentMonth;
1068 var endMonth = delta > 0 ? self.config.showMonths : -1;
1069 var loopDelta = delta > 0 ? 1 : -1;
1070 for (var m = givenMonth - self.currentMonth; m != endMonth; m += loopDelta) {
1071 var month = self.daysContainer.children[m];
1072 var startIndex = givenMonth - self.currentMonth === m
1073 ? current.$i + delta
1074 : delta < 0
1075 ? month.children.length - 1
1076 : 0;
1077 var numMonthDays = month.children.length;
1078 for (var i = startIndex; i >= 0 && i < numMonthDays && i != (delta > 0 ? numMonthDays : -1); i += loopDelta) {
1079 var c = month.children[i];
1080 if (c.className.indexOf("hidden") === -1 &&
1081 isEnabled(c.dateObj) &&
1082 Math.abs(current.$i - i) >= Math.abs(delta))
1083 return focusOnDayElem(c);
1084 }
1085 }
1086 self.changeMonth(loopDelta);
1087 focusOnDay(getFirstAvailableDay(loopDelta), 0);
1088 return undefined;
1089 }
1090 function focusOnDay(current, offset) {
1091 var dayFocused = isInView(document.activeElement || document.body);
1092 var startElem = current !== undefined
1093 ? current
1094 : dayFocused
1095 ? document.activeElement
1096 : self.selectedDateElem !== undefined && isInView(self.selectedDateElem)
1097 ? self.selectedDateElem
1098 : self.todayDateElem !== undefined && isInView(self.todayDateElem)
1099 ? self.todayDateElem
1100 : getFirstAvailableDay(offset > 0 ? 1 : -1);
1101 if (startElem === undefined)
1102 return self._input.focus();
1103 if (!dayFocused)
1104 return focusOnDayElem(startElem);
1105 getNextAvailableDay(startElem, offset);
1106 }
1107 function buildMonthDays(year, month) {
1108 var firstOfMonth = (new Date(year, month, 1).getDay() - self.l10n.firstDayOfWeek + 7) % 7;
1109 var prevMonthDays = self.utils.getDaysInMonth((month - 1 + 12) % 12);
1110 var daysInMonth = self.utils.getDaysInMonth(month), days = window.document.createDocumentFragment(), isMultiMonth = self.config.showMonths > 1, prevMonthDayClass = isMultiMonth ? "prevMonthDay hidden" : "prevMonthDay", nextMonthDayClass = isMultiMonth ? "nextMonthDay hidden" : "nextMonthDay";
1111 var dayNumber = prevMonthDays + 1 - firstOfMonth, dayIndex = 0;
1112 // prepend days from the ending of previous month
1113 for (; dayNumber <= prevMonthDays; dayNumber++, dayIndex++) {
1114 days.appendChild(createDay(prevMonthDayClass, new Date(year, month - 1, dayNumber), dayNumber, dayIndex));
1115 }
1116 // Start at 1 since there is no 0th day
1117 for (dayNumber = 1; dayNumber <= daysInMonth; dayNumber++, dayIndex++) {
1118 days.appendChild(createDay("", new Date(year, month, dayNumber), dayNumber, dayIndex));
1119 }
1120 // append days from the next month
1121 for (var dayNum = daysInMonth + 1; dayNum <= 42 - firstOfMonth &&
1122 (self.config.showMonths === 1 || dayIndex % 7 !== 0); dayNum++, dayIndex++) {
1123 days.appendChild(createDay(nextMonthDayClass, new Date(year, month + 1, dayNum % daysInMonth), dayNum, dayIndex));
1124 }
1125 //updateNavigationCurrentMonth();
1126 var dayContainer = createElement("div", "dayContainer");
1127 dayContainer.appendChild(days);
1128 return dayContainer;
1129 }
1130 function buildDays() {
1131 if (self.daysContainer === undefined) {
1132 return;
1133 }
1134 clearNode(self.daysContainer);
1135 // TODO: week numbers for each month
1136 if (self.weekNumbers)
1137 clearNode(self.weekNumbers);
1138 var frag = document.createDocumentFragment();
1139 for (var i = 0; i < self.config.showMonths; i++) {
1140 var d = new Date(self.currentYear, self.currentMonth, 1);
1141 d.setMonth(self.currentMonth + i);
1142 frag.appendChild(buildMonthDays(d.getFullYear(), d.getMonth()));
1143 }
1144 self.daysContainer.appendChild(frag);
1145 self.days = self.daysContainer.firstChild;
1146 if (self.config.mode === "range" && self.selectedDates.length === 1) {
1147 onMouseOver();
1148 }
1149 }
1150 function buildMonthSwitch() {
1151 if (self.config.showMonths > 1 ||
1152 self.config.monthSelectorType !== "dropdown")
1153 return;
1154 var shouldBuildMonth = function (month) {
1155 if (self.config.minDate !== undefined &&
1156 self.currentYear === self.config.minDate.getFullYear() &&
1157 month < self.config.minDate.getMonth()) {
1158 return false;
1159 }
1160 return !(self.config.maxDate !== undefined &&
1161 self.currentYear === self.config.maxDate.getFullYear() &&
1162 month > self.config.maxDate.getMonth());
1163 };
1164 self.monthsDropdownContainer.tabIndex = -1;
1165 self.monthsDropdownContainer.innerHTML = "";
1166 for (var i = 0; i < 12; i++) {
1167 if (!shouldBuildMonth(i))
1168 continue;
1169 var month = createElement("option", "flatpickr-monthDropdown-month");
1170 month.value = new Date(self.currentYear, i).getMonth().toString();
1171 month.textContent = monthToStr(i, self.config.shorthandCurrentMonth, self.l10n);
1172 month.tabIndex = -1;
1173 if (self.currentMonth === i) {
1174 month.selected = true;
1175 }
1176 self.monthsDropdownContainer.appendChild(month);
1177 }
1178 }
1179 function buildMonth() {
1180 var container = createElement("div", "flatpickr-month");
1181 var monthNavFragment = window.document.createDocumentFragment();
1182 var monthElement;
1183 if (self.config.showMonths > 1 ||
1184 self.config.monthSelectorType === "static") {
1185 monthElement = createElement("span", "cur-month");
1186 }
1187 else {
1188 self.monthsDropdownContainer = createElement("select", "flatpickr-monthDropdown-months");
1189 bind(self.monthsDropdownContainer, "change", function (e) {
1190 var target = e.target;
1191 var selectedMonth = parseInt(target.value, 10);
1192 self.changeMonth(selectedMonth - self.currentMonth);
1193 triggerEvent("onMonthChange");
1194 });
1195 buildMonthSwitch();
1196 monthElement = self.monthsDropdownContainer;
1197 }
1198 var yearInput = createNumberInput("cur-year", { tabindex: "-1" });
1199 var yearElement = yearInput.getElementsByTagName("input")[0];
1200 yearElement.setAttribute("aria-label", self.l10n.yearAriaLabel);
1201 if (self.config.minDate) {
1202 yearElement.setAttribute("min", self.config.minDate.getFullYear().toString());
1203 }
1204 if (self.config.maxDate) {
1205 yearElement.setAttribute("max", self.config.maxDate.getFullYear().toString());
1206 yearElement.disabled =
1207 !!self.config.minDate &&
1208 self.config.minDate.getFullYear() === self.config.maxDate.getFullYear();
1209 }
1210 var currentMonth = createElement("div", "flatpickr-current-month");
1211 currentMonth.appendChild(monthElement);
1212 currentMonth.appendChild(yearInput);
1213 monthNavFragment.appendChild(currentMonth);
1214 container.appendChild(monthNavFragment);
1215 return {
1216 container: container,
1217 yearElement: yearElement,
1218 monthElement: monthElement
1219 };
1220 }
1221 function buildMonths() {
1222 clearNode(self.monthNav);
1223 self.monthNav.appendChild(self.prevMonthNav);
1224 if (self.config.showMonths) {
1225 self.yearElements = [];
1226 self.monthElements = [];
1227 }
1228 for (var m = self.config.showMonths; m--;) {
1229 var month = buildMonth();
1230 self.yearElements.push(month.yearElement);
1231 self.monthElements.push(month.monthElement);
1232 self.monthNav.appendChild(month.container);
1233 }
1234 self.monthNav.appendChild(self.nextMonthNav);
1235 }
1236 function buildMonthNav() {
1237 self.monthNav = createElement("div", "flatpickr-months");
1238 self.yearElements = [];
1239 self.monthElements = [];
1240 self.prevMonthNav = createElement("span", "flatpickr-prev-month");
1241 self.prevMonthNav.innerHTML = self.config.prevArrow;
1242 self.nextMonthNav = createElement("span", "flatpickr-next-month");
1243 self.nextMonthNav.innerHTML = self.config.nextArrow;
1244 buildMonths();
1245 Object.defineProperty(self, "_hidePrevMonthArrow", {
1246 get: function () { return self.__hidePrevMonthArrow; },
1247 set: function (bool) {
1248 if (self.__hidePrevMonthArrow !== bool) {
1249 toggleClass(self.prevMonthNav, "flatpickr-disabled", bool);
1250 self.__hidePrevMonthArrow = bool;
1251 }
1252 }
1253 });
1254 Object.defineProperty(self, "_hideNextMonthArrow", {
1255 get: function () { return self.__hideNextMonthArrow; },
1256 set: function (bool) {
1257 if (self.__hideNextMonthArrow !== bool) {
1258 toggleClass(self.nextMonthNav, "flatpickr-disabled", bool);
1259 self.__hideNextMonthArrow = bool;
1260 }
1261 }
1262 });
1263 self.currentYearElement = self.yearElements[0];
1264 updateNavigationCurrentMonth();
1265 return self.monthNav;
1266 }
1267 function buildTime() {
1268 self.calendarContainer.classList.add("hasTime");
1269 if (self.config.noCalendar)
1270 self.calendarContainer.classList.add("noCalendar");
1271 self.timeContainer = createElement("div", "flatpickr-time");
1272 self.timeContainer.tabIndex = -1;
1273 var separator = createElement("span", "flatpickr-time-separator", ":");
1274 var hourInput = createNumberInput("flatpickr-hour", {
1275 "aria-label": self.l10n.hourAriaLabel
1276 });
1277 self.hourElement = hourInput.getElementsByTagName("input")[0];
1278 var minuteInput = createNumberInput("flatpickr-minute", {
1279 "aria-label": self.l10n.minuteAriaLabel
1280 });
1281 self.minuteElement = minuteInput.getElementsByTagName("input")[0];
1282 self.hourElement.tabIndex = self.minuteElement.tabIndex = -1;
1283 self.hourElement.value = pad(self.latestSelectedDateObj
1284 ? self.latestSelectedDateObj.getHours()
1285 : self.config.time_24hr
1286 ? self.config.defaultHour
1287 : military2ampm(self.config.defaultHour));
1288 self.minuteElement.value = pad(self.latestSelectedDateObj
1289 ? self.latestSelectedDateObj.getMinutes()
1290 : self.config.defaultMinute);
1291 self.hourElement.setAttribute("step", self.config.hourIncrement.toString());
1292 self.minuteElement.setAttribute("step", self.config.minuteIncrement.toString());
1293 self.hourElement.setAttribute("min", self.config.time_24hr ? "0" : "1");
1294 self.hourElement.setAttribute("max", self.config.time_24hr ? "23" : "12");
1295 self.minuteElement.setAttribute("min", "0");
1296 self.minuteElement.setAttribute("max", "59");
1297 self.timeContainer.appendChild(hourInput);
1298 self.timeContainer.appendChild(separator);
1299 self.timeContainer.appendChild(minuteInput);
1300 if (self.config.time_24hr)
1301 self.timeContainer.classList.add("time24hr");
1302 if (self.config.enableSeconds) {
1303 self.timeContainer.classList.add("hasSeconds");
1304 var secondInput = createNumberInput("flatpickr-second");
1305 self.secondElement = secondInput.getElementsByTagName("input")[0];
1306 self.secondElement.value = pad(self.latestSelectedDateObj
1307 ? self.latestSelectedDateObj.getSeconds()
1308 : self.config.defaultSeconds);
1309 self.secondElement.setAttribute("step", self.minuteElement.getAttribute("step"));
1310 self.secondElement.setAttribute("min", "0");
1311 self.secondElement.setAttribute("max", "59");
1312 self.timeContainer.appendChild(createElement("span", "flatpickr-time-separator", ":"));
1313 self.timeContainer.appendChild(secondInput);
1314 }
1315 if (!self.config.time_24hr) {
1316 // add self.amPM if appropriate
1317 self.amPM = createElement("span", "flatpickr-am-pm", self.l10n.amPM[int((self.latestSelectedDateObj
1318 ? self.hourElement.value
1319 : self.config.defaultHour) > 11)]);
1320 self.amPM.title = self.l10n.toggleTitle;
1321 self.amPM.tabIndex = -1;
1322 self.timeContainer.appendChild(self.amPM);
1323 }
1324 return self.timeContainer;
1325 }
1326 function buildWeekdays() {
1327 if (!self.weekdayContainer)
1328 self.weekdayContainer = createElement("div", "flatpickr-weekdays");
1329 else
1330 clearNode(self.weekdayContainer);
1331 for (var i = self.config.showMonths; i--;) {
1332 var container = createElement("div", "flatpickr-weekdaycontainer");
1333 self.weekdayContainer.appendChild(container);
1334 }
1335 updateWeekdays();
1336 return self.weekdayContainer;
1337 }
1338 function updateWeekdays() {
1339 if (!self.weekdayContainer) {
1340 return;
1341 }
1342 var firstDayOfWeek = self.l10n.firstDayOfWeek;
1343 var weekdays = self.l10n.weekdays.shorthand.slice();
1344 if (firstDayOfWeek > 0 && firstDayOfWeek < weekdays.length) {
1345 weekdays = weekdays.splice(firstDayOfWeek, weekdays.length).concat(weekdays.splice(0, firstDayOfWeek));
1346 }
1347 for (var i = self.config.showMonths; i--;) {
1348 self.weekdayContainer.children[i].innerHTML = "\n <span class='flatpickr-weekday'>\n " + weekdays.join("</span><span class='flatpickr-weekday'>") + "\n </span>\n ";
1349 }
1350 }
1351 /* istanbul ignore next */
1352 function buildWeeks() {
1353 self.calendarContainer.classList.add("hasWeeks");
1354 var weekWrapper = createElement("div", "flatpickr-weekwrapper");
1355 weekWrapper.appendChild(createElement("span", "flatpickr-weekday", self.l10n.weekAbbreviation));
1356 var weekNumbers = createElement("div", "flatpickr-weeks");
1357 weekWrapper.appendChild(weekNumbers);
1358 return {
1359 weekWrapper: weekWrapper,
1360 weekNumbers: weekNumbers
1361 };
1362 }
1363 function changeMonth(value, isOffset) {
1364 if (isOffset === void 0) { isOffset = true; }
1365 var delta = isOffset ? value : value - self.currentMonth;
1366 if ((delta < 0 && self._hidePrevMonthArrow === true) ||
1367 (delta > 0 && self._hideNextMonthArrow === true))
1368 return;
1369 self.currentMonth += delta;
1370 if (self.currentMonth < 0 || self.currentMonth > 11) {
1371 self.currentYear += self.currentMonth > 11 ? 1 : -1;
1372 self.currentMonth = (self.currentMonth + 12) % 12;
1373 triggerEvent("onYearChange");
1374 buildMonthSwitch();
1375 }
1376 buildDays();
1377 triggerEvent("onMonthChange");
1378 updateNavigationCurrentMonth();
1379 }
1380 function clear(triggerChangeEvent, toInitial) {
1381 if (triggerChangeEvent === void 0) { triggerChangeEvent = true; }
1382 if (toInitial === void 0) { toInitial = true; }
1383 self.input.value = "";
1384 if (self.altInput !== undefined)
1385 self.altInput.value = "";
1386 if (self.mobileInput !== undefined)
1387 self.mobileInput.value = "";
1388 self.selectedDates = [];
1389 self.latestSelectedDateObj = undefined;
1390 if (toInitial === true) {
1391 self.currentYear = self._initialDate.getFullYear();
1392 self.currentMonth = self._initialDate.getMonth();
1393 }
1394 self.showTimeInput = false;
1395 if (self.config.enableTime === true) {
1396 setDefaultHours();
1397 }
1398 self.redraw();
1399 if (triggerChangeEvent)
1400 // triggerChangeEvent is true (default) or an Event
1401 triggerEvent("onChange");
1402 }
1403 function close() {
1404 self.isOpen = false;
1405 if (!self.isMobile) {
1406 if (self.calendarContainer !== undefined) {
1407 self.calendarContainer.classList.remove("open");
1408 }
1409 if (self._input !== undefined) {
1410 self._input.classList.remove("active");
1411 }
1412 }
1413 triggerEvent("onClose");
1414 }
1415 function destroy() {
1416 if (self.config !== undefined)
1417 triggerEvent("onDestroy");
1418 for (var i = self._handlers.length; i--;) {
1419 var h = self._handlers[i];
1420 h.element.removeEventListener(h.event, h.handler, h.options);
1421 }
1422 self._handlers = [];
1423 if (self.mobileInput) {
1424 if (self.mobileInput.parentNode)
1425 self.mobileInput.parentNode.removeChild(self.mobileInput);
1426 self.mobileInput = undefined;
1427 }
1428 else if (self.calendarContainer && self.calendarContainer.parentNode) {
1429 if (self.config.static && self.calendarContainer.parentNode) {
1430 var wrapper = self.calendarContainer.parentNode;
1431 wrapper.lastChild && wrapper.removeChild(wrapper.lastChild);
1432 if (wrapper.parentNode) {
1433 while (wrapper.firstChild)
1434 wrapper.parentNode.insertBefore(wrapper.firstChild, wrapper);
1435 wrapper.parentNode.removeChild(wrapper);
1436 }
1437 }
1438 else
1439 self.calendarContainer.parentNode.removeChild(self.calendarContainer);
1440 }
1441 if (self.altInput) {
1442 self.input.type = "text";
1443 if (self.altInput.parentNode)
1444 self.altInput.parentNode.removeChild(self.altInput);
1445 delete self.altInput;
1446 }
1447 if (self.input) {
1448 self.input.type = self.input._type;
1449 self.input.classList.remove("flatpickr-input");
1450 self.input.removeAttribute("readonly");
1451 self.input.value = "";
1452 }
1453 [
1454 "_showTimeInput",
1455 "latestSelectedDateObj",
1456 "_hideNextMonthArrow",
1457 "_hidePrevMonthArrow",
1458 "__hideNextMonthArrow",
1459 "__hidePrevMonthArrow",
1460 "isMobile",
1461 "isOpen",
1462 "selectedDateElem",
1463 "minDateHasTime",
1464 "maxDateHasTime",
1465 "days",
1466 "daysContainer",
1467 "_input",
1468 "_positionElement",
1469 "innerContainer",
1470 "rContainer",
1471 "monthNav",
1472 "todayDateElem",
1473 "calendarContainer",
1474 "weekdayContainer",
1475 "prevMonthNav",
1476 "nextMonthNav",
1477 "monthsDropdownContainer",
1478 "currentMonthElement",
1479 "currentYearElement",
1480 "navigationCurrentMonth",
1481 "selectedDateElem",
1482 "config",
1483 ].forEach(function (k) {
1484 try {
1485 delete self[k];
1486 }
1487 catch (_) { }
1488 });
1489 }
1490 function isCalendarElem(elem) {
1491 if (self.config.appendTo && self.config.appendTo.contains(elem))
1492 return true;
1493 return self.calendarContainer.contains(elem);
1494 }
1495 function documentClick(e) {
1496 if (self.isOpen && !self.config.inline) {
1497 var eventTarget_1 = getEventTarget(e);
1498 var isCalendarElement = isCalendarElem(eventTarget_1);
1499 var isInput = eventTarget_1 === self.input ||
1500 eventTarget_1 === self.altInput ||
1501 self.element.contains(eventTarget_1) ||
1502 // web components
1503 // e.path is not present in all browsers. circumventing typechecks
1504 (e.path &&
1505 e.path.indexOf &&
1506 (~e.path.indexOf(self.input) ||
1507 ~e.path.indexOf(self.altInput)));
1508 var lostFocus = e.type === "blur"
1509 ? isInput &&
1510 e.relatedTarget &&
1511 !isCalendarElem(e.relatedTarget)
1512 : !isInput &&
1513 !isCalendarElement &&
1514 !isCalendarElem(e.relatedTarget);
1515 var isIgnored = !self.config.ignoredFocusElements.some(function (elem) {
1516 return elem.contains(eventTarget_1);
1517 });
1518 if (lostFocus && isIgnored) {
1519 if (self.timeContainer !== undefined &&
1520 self.minuteElement !== undefined &&
1521 self.hourElement !== undefined) {
1522 updateTime();
1523 }
1524 self.close();
1525 if (self.config.mode === "range" && self.selectedDates.length === 1) {
1526 self.clear(false);
1527 self.redraw();
1528 }
1529 }
1530 }
1531 }
1532 function changeYear(newYear) {
1533 if (!newYear ||
1534 (self.config.minDate && newYear < self.config.minDate.getFullYear()) ||
1535 (self.config.maxDate && newYear > self.config.maxDate.getFullYear()))
1536 return;
1537 var newYearNum = newYear, isNewYear = self.currentYear !== newYearNum;
1538 self.currentYear = newYearNum || self.currentYear;
1539 if (self.config.maxDate &&
1540 self.currentYear === self.config.maxDate.getFullYear()) {
1541 self.currentMonth = Math.min(self.config.maxDate.getMonth(), self.currentMonth);
1542 }
1543 else if (self.config.minDate &&
1544 self.currentYear === self.config.minDate.getFullYear()) {
1545 self.currentMonth = Math.max(self.config.minDate.getMonth(), self.currentMonth);
1546 }
1547 if (isNewYear) {
1548 self.redraw();
1549 triggerEvent("onYearChange");
1550 buildMonthSwitch();
1551 }
1552 }
1553 function isEnabled(date, timeless) {
1554 if (timeless === void 0) { timeless = true; }
1555 var dateToCheck = self.parseDate(date, undefined, timeless); // timeless
1556 if ((self.config.minDate &&
1557 dateToCheck &&
1558 compareDates(dateToCheck, self.config.minDate, timeless !== undefined ? timeless : !self.minDateHasTime) < 0) ||
1559 (self.config.maxDate &&
1560 dateToCheck &&
1561 compareDates(dateToCheck, self.config.maxDate, timeless !== undefined ? timeless : !self.maxDateHasTime) > 0))
1562 return false;
1563 if (self.config.enable.length === 0 && self.config.disable.length === 0)
1564 return true;
1565 if (dateToCheck === undefined)
1566 return false;
1567 var bool = self.config.enable.length > 0, array = bool ? self.config.enable : self.config.disable;
1568 for (var i = 0, d = void 0; i < array.length; i++) {
1569 d = array[i];
1570 if (typeof d === "function" &&
1571 d(dateToCheck) // disabled by function
1572 )
1573 return bool;
1574 else if (d instanceof Date &&
1575 dateToCheck !== undefined &&
1576 d.getTime() === dateToCheck.getTime())
1577 // disabled by date
1578 return bool;
1579 else if (typeof d === "string" && dateToCheck !== undefined) {
1580 // disabled by date string
1581 var parsed = self.parseDate(d, undefined, true);
1582 return parsed && parsed.getTime() === dateToCheck.getTime()
1583 ? bool
1584 : !bool;
1585 }
1586 else if (
1587 // disabled by range
1588 typeof d === "object" &&
1589 dateToCheck !== undefined &&
1590 d.from &&
1591 d.to &&
1592 dateToCheck.getTime() >= d.from.getTime() &&
1593 dateToCheck.getTime() <= d.to.getTime())
1594 return bool;
1595 }
1596 return !bool;
1597 }
1598 function isInView(elem) {
1599 if (self.daysContainer !== undefined)
1600 return (elem.className.indexOf("hidden") === -1 &&
1601 self.daysContainer.contains(elem));
1602 return false;
1603 }
1604 function onKeyDown(e) {
1605 // e.key e.keyCode
1606 // "Backspace" 8
1607 // "Tab" 9
1608 // "Enter" 13
1609 // "Escape" (IE "Esc") 27
1610 // "ArrowLeft" (IE "Left") 37
1611 // "ArrowUp" (IE "Up") 38
1612 // "ArrowRight" (IE "Right") 39
1613 // "ArrowDown" (IE "Down") 40
1614 // "Delete" (IE "Del") 46
1615 var isInput = e.target === self._input;
1616 var allowInput = self.config.allowInput;
1617 var allowKeydown = self.isOpen && (!allowInput || !isInput);
1618 var allowInlineKeydown = self.config.inline && isInput && !allowInput;
1619 if (e.keyCode === 13 && isInput) {
1620 if (allowInput) {
1621 self.setDate(self._input.value, true, e.target === self.altInput
1622 ? self.config.altFormat
1623 : self.config.dateFormat);
1624 return e.target.blur();
1625 }
1626 else {
1627 self.open();
1628 }
1629 }
1630 else if (isCalendarElem(e.target) ||
1631 allowKeydown ||
1632 allowInlineKeydown) {
1633 var isTimeObj = !!self.timeContainer &&
1634 self.timeContainer.contains(e.target);
1635 switch (e.keyCode) {
1636 case 13:
1637 if (isTimeObj) {
1638 e.preventDefault();
1639 updateTime();
1640 focusAndClose();
1641 }
1642 else
1643 selectDate(e);
1644 break;
1645 case 27: // escape
1646 e.preventDefault();
1647 focusAndClose();
1648 break;
1649 case 8:
1650 case 46:
1651 if (isInput && !self.config.allowInput) {
1652 e.preventDefault();
1653 self.clear();
1654 }
1655 break;
1656 case 37:
1657 case 39:
1658 if (!isTimeObj && !isInput) {
1659 e.preventDefault();
1660 if (self.daysContainer !== undefined &&
1661 (allowInput === false ||
1662 (document.activeElement && isInView(document.activeElement)))) {
1663 var delta_1 = e.keyCode === 39 ? 1 : -1;
1664 if (!e.ctrlKey)
1665 focusOnDay(undefined, delta_1);
1666 else {
1667 e.stopPropagation();
1668 changeMonth(delta_1);
1669 focusOnDay(getFirstAvailableDay(1), 0);
1670 }
1671 }
1672 }
1673 else if (self.hourElement)
1674 self.hourElement.focus();
1675 break;
1676 case 38:
1677 case 40:
1678 e.preventDefault();
1679 var delta = e.keyCode === 40 ? 1 : -1;
1680 if ((self.daysContainer && e.target.$i !== undefined) ||
1681 e.target === self.input ||
1682 e.target === self.altInput) {
1683 if (e.ctrlKey) {
1684 e.stopPropagation();
1685 changeYear(self.currentYear - delta);
1686 focusOnDay(getFirstAvailableDay(1), 0);
1687 }
1688 else if (!isTimeObj)
1689 focusOnDay(undefined, delta * 7);
1690 }
1691 else if (e.target === self.currentYearElement) {
1692 changeYear(self.currentYear - delta);
1693 }
1694 else if (self.config.enableTime) {
1695 if (!isTimeObj && self.hourElement)
1696 self.hourElement.focus();
1697 updateTime(e);
1698 self._debouncedChange();
1699 }
1700 break;
1701 case 9:
1702 if (isTimeObj) {
1703 var elems = [
1704 self.hourElement,
1705 self.minuteElement,
1706 self.secondElement,
1707 self.amPM,
1708 ]
1709 .concat(self.pluginElements)
1710 .filter(function (x) { return x; });
1711 var i = elems.indexOf(e.target);
1712 if (i !== -1) {
1713 var target = elems[i + (e.shiftKey ? -1 : 1)];
1714 e.preventDefault();
1715 (target || self._input).focus();
1716 }
1717 }
1718 else if (!self.config.noCalendar &&
1719 self.daysContainer &&
1720 self.daysContainer.contains(e.target) &&
1721 e.shiftKey) {
1722 e.preventDefault();
1723 self._input.focus();
1724 }
1725 break;
1726 default:
1727 break;
1728 }
1729 }
1730 if (self.amPM !== undefined && e.target === self.amPM) {
1731 switch (e.key) {
1732 case self.l10n.amPM[0].charAt(0):
1733 case self.l10n.amPM[0].charAt(0).toLowerCase():
1734 self.amPM.textContent = self.l10n.amPM[0];
1735 setHoursFromInputs();
1736 updateValue();
1737 break;
1738 case self.l10n.amPM[1].charAt(0):
1739 case self.l10n.amPM[1].charAt(0).toLowerCase():
1740 self.amPM.textContent = self.l10n.amPM[1];
1741 setHoursFromInputs();
1742 updateValue();
1743 break;
1744 }
1745 }
1746 if (isInput || isCalendarElem(e.target)) {
1747 triggerEvent("onKeyDown", e);
1748 }
1749 }
1750 function onMouseOver(elem) {
1751 if (self.selectedDates.length !== 1 ||
1752 (elem &&
1753 (!elem.classList.contains("flatpickr-day") ||
1754 elem.classList.contains("flatpickr-disabled"))))
1755 return;
1756 var hoverDate = elem
1757 ? elem.dateObj.getTime()
1758 : self.days.firstElementChild.dateObj.getTime(), initialDate = self.parseDate(self.selectedDates[0], undefined, true).getTime(), rangeStartDate = Math.min(hoverDate, self.selectedDates[0].getTime()), rangeEndDate = Math.max(hoverDate, self.selectedDates[0].getTime());
1759 var containsDisabled = false;
1760 var minRange = 0, maxRange = 0;
1761 for (var t = rangeStartDate; t < rangeEndDate; t += duration.DAY) {
1762 if (!isEnabled(new Date(t), true)) {
1763 containsDisabled =
1764 containsDisabled || (t > rangeStartDate && t < rangeEndDate);
1765 if (t < initialDate && (!minRange || t > minRange))
1766 minRange = t;
1767 else if (t > initialDate && (!maxRange || t < maxRange))
1768 maxRange = t;
1769 }
1770 }
1771 for (var m = 0; m < self.config.showMonths; m++) {
1772 var month = self.daysContainer.children[m];
1773 var _loop_1 = function (i, l) {
1774 var dayElem = month.children[i], date = dayElem.dateObj;
1775 var timestamp = date.getTime();
1776 var outOfRange = (minRange > 0 && timestamp < minRange) ||
1777 (maxRange > 0 && timestamp > maxRange);
1778 if (outOfRange) {
1779 dayElem.classList.add("notAllowed");
1780 ["inRange", "startRange", "endRange"].forEach(function (c) {
1781 dayElem.classList.remove(c);
1782 });
1783 return "continue";
1784 }
1785 else if (containsDisabled && !outOfRange)
1786 return "continue";
1787 ["startRange", "inRange", "endRange", "notAllowed"].forEach(function (c) {
1788 dayElem.classList.remove(c);
1789 });
1790 if (elem !== undefined) {
1791 elem.classList.add(hoverDate <= self.selectedDates[0].getTime()
1792 ? "startRange"
1793 : "endRange");
1794 if (initialDate < hoverDate && timestamp === initialDate)
1795 dayElem.classList.add("startRange");
1796 else if (initialDate > hoverDate && timestamp === initialDate)
1797 dayElem.classList.add("endRange");
1798 if (timestamp >= minRange &&
1799 (maxRange === 0 || timestamp <= maxRange) &&
1800 isBetween(timestamp, initialDate, hoverDate))
1801 dayElem.classList.add("inRange");
1802 }
1803 };
1804 for (var i = 0, l = month.children.length; i < l; i++) {
1805 _loop_1(i, l);
1806 }
1807 }
1808 }
1809 function onResize() {
1810 if (self.isOpen && !self.config.static && !self.config.inline)
1811 positionCalendar();
1812 }
1813 function setDefaultTime() {
1814 self.setDate(self.config.minDate !== undefined
1815 ? new Date(self.config.minDate.getTime())
1816 : new Date(), true);
1817 setDefaultHours();
1818 updateValue();
1819 }
1820 function open(e, positionElement) {
1821 if (positionElement === void 0) { positionElement = self._positionElement; }
1822 if (self.isMobile === true) {
1823 if (e) {
1824 e.preventDefault();
1825 e.target && e.target.blur();
1826 }
1827 if (self.mobileInput !== undefined) {
1828 self.mobileInput.focus();
1829 self.mobileInput.click();
1830 }
1831 triggerEvent("onOpen");
1832 return;
1833 }
1834 if (self._input.disabled || self.config.inline)
1835 return;
1836 var wasOpen = self.isOpen;
1837 self.isOpen = true;
1838 if (!wasOpen) {
1839 self.calendarContainer.classList.add("open");
1840 self._input.classList.add("active");
1841 triggerEvent("onOpen");
1842 positionCalendar(positionElement);
1843 }
1844 if (self.config.enableTime === true && self.config.noCalendar === true) {
1845 if (self.selectedDates.length === 0) {
1846 setDefaultTime();
1847 }
1848 if (self.config.allowInput === false &&
1849 (e === undefined ||
1850 !self.timeContainer.contains(e.relatedTarget))) {
1851 setTimeout(function () { return self.hourElement.select(); }, 50);
1852 }
1853 }
1854 }
1855 function minMaxDateSetter(type) {
1856 return function (date) {
1857 var dateObj = (self.config["_" + type + "Date"] = self.parseDate(date, self.config.dateFormat));
1858 var inverseDateObj = self.config["_" + (type === "min" ? "max" : "min") + "Date"];
1859 if (dateObj !== undefined) {
1860 self[type === "min" ? "minDateHasTime" : "maxDateHasTime"] =
1861 dateObj.getHours() > 0 ||
1862 dateObj.getMinutes() > 0 ||
1863 dateObj.getSeconds() > 0;
1864 }
1865 if (self.selectedDates) {
1866 self.selectedDates = self.selectedDates.filter(function (d) { return isEnabled(d); });
1867 if (!self.selectedDates.length && type === "min")
1868 setHoursFromDate(dateObj);
1869 updateValue();
1870 }
1871 if (self.daysContainer) {
1872 redraw();
1873 if (dateObj !== undefined)
1874 self.currentYearElement[type] = dateObj.getFullYear().toString();
1875 else
1876 self.currentYearElement.removeAttribute(type);
1877 self.currentYearElement.disabled =
1878 !!inverseDateObj &&
1879 dateObj !== undefined &&
1880 inverseDateObj.getFullYear() === dateObj.getFullYear();
1881 }
1882 };
1883 }
1884 function parseConfig() {
1885 var boolOpts = [
1886 "wrap",
1887 "weekNumbers",
1888 "allowInput",
1889 "clickOpens",
1890 "time_24hr",
1891 "enableTime",
1892 "noCalendar",
1893 "altInput",
1894 "shorthandCurrentMonth",
1895 "inline",
1896 "static",
1897 "enableSeconds",
1898 "disableMobile",
1899 ];
1900 var userConfig = __assign({}, instanceConfig, JSON.parse(JSON.stringify(element.dataset || {})));
1901 var formats = {};
1902 self.config.parseDate = userConfig.parseDate;
1903 self.config.formatDate = userConfig.formatDate;
1904 Object.defineProperty(self.config, "enable", {
1905 get: function () { return self.config._enable; },
1906 set: function (dates) {
1907 self.config._enable = parseDateRules(dates);
1908 }
1909 });
1910 Object.defineProperty(self.config, "disable", {
1911 get: function () { return self.config._disable; },
1912 set: function (dates) {
1913 self.config._disable = parseDateRules(dates);
1914 }
1915 });
1916 var timeMode = userConfig.mode === "time";
1917 if (!userConfig.dateFormat && (userConfig.enableTime || timeMode)) {
1918 var defaultDateFormat = flatpickr.defaultConfig.dateFormat || defaults.dateFormat;
1919 formats.dateFormat =
1920 userConfig.noCalendar || timeMode
1921 ? "H:i" + (userConfig.enableSeconds ? ":S" : "")
1922 : defaultDateFormat + " H:i" + (userConfig.enableSeconds ? ":S" : "");
1923 }
1924 if (userConfig.altInput &&
1925 (userConfig.enableTime || timeMode) &&
1926 !userConfig.altFormat) {
1927 var defaultAltFormat = flatpickr.defaultConfig.altFormat || defaults.altFormat;
1928 formats.altFormat =
1929 userConfig.noCalendar || timeMode
1930 ? "h:i" + (userConfig.enableSeconds ? ":S K" : " K")
1931 : defaultAltFormat + (" h:i" + (userConfig.enableSeconds ? ":S" : "") + " K");
1932 }
1933 if (!userConfig.altInputClass) {
1934 self.config.altInputClass =
1935 self.input.className + " " + self.config.altInputClass;
1936 }
1937 Object.defineProperty(self.config, "minDate", {
1938 get: function () { return self.config._minDate; },
1939 set: minMaxDateSetter("min")
1940 });
1941 Object.defineProperty(self.config, "maxDate", {
1942 get: function () { return self.config._maxDate; },
1943 set: minMaxDateSetter("max")
1944 });
1945 var minMaxTimeSetter = function (type) { return function (val) {
1946 self.config[type === "min" ? "_minTime" : "_maxTime"] = self.parseDate(val, "H:i:S");
1947 }; };
1948 Object.defineProperty(self.config, "minTime", {
1949 get: function () { return self.config._minTime; },
1950 set: minMaxTimeSetter("min")
1951 });
1952 Object.defineProperty(self.config, "maxTime", {
1953 get: function () { return self.config._maxTime; },
1954 set: minMaxTimeSetter("max")
1955 });
1956 if (userConfig.mode === "time") {
1957 self.config.noCalendar = true;
1958 self.config.enableTime = true;
1959 }
1960 Object.assign(self.config, formats, userConfig);
1961 for (var i = 0; i < boolOpts.length; i++)
1962 self.config[boolOpts[i]] =
1963 self.config[boolOpts[i]] === true ||
1964 self.config[boolOpts[i]] === "true";
1965 HOOKS.filter(function (hook) { return self.config[hook] !== undefined; }).forEach(function (hook) {
1966 self.config[hook] = arrayify(self.config[hook] || []).map(bindToInstance);
1967 });
1968 self.isMobile =
1969 !self.config.disableMobile &&
1970 !self.config.inline &&
1971 self.config.mode === "single" &&
1972 !self.config.disable.length &&
1973 !self.config.enable.length &&
1974 !self.config.weekNumbers &&
1975 /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
1976 for (var i = 0; i < self.config.plugins.length; i++) {
1977 var pluginConf = self.config.plugins[i](self) || {};
1978 for (var key in pluginConf) {
1979 if (HOOKS.indexOf(key) > -1) {
1980 self.config[key] = arrayify(pluginConf[key])
1981 .map(bindToInstance)
1982 .concat(self.config[key]);
1983 }
1984 else if (typeof userConfig[key] === "undefined")
1985 self.config[key] = pluginConf[key];
1986 }
1987 }
1988 triggerEvent("onParseConfig");
1989 }
1990 function setupLocale() {
1991 if (typeof self.config.locale !== "object" &&
1992 typeof flatpickr.l10ns[self.config.locale] === "undefined")
1993 self.config.errorHandler(new Error("flatpickr: invalid locale " + self.config.locale));
1994 self.l10n = __assign({}, flatpickr.l10ns["default"], (typeof self.config.locale === "object"
1995 ? self.config.locale
1996 : self.config.locale !== "default"
1997 ? flatpickr.l10ns[self.config.locale]
1998 : undefined));
1999 tokenRegex.K = "(" + self.l10n.amPM[0] + "|" + self.l10n.amPM[1] + "|" + self.l10n.amPM[0].toLowerCase() + "|" + self.l10n.amPM[1].toLowerCase() + ")";
2000 var userConfig = __assign({}, instanceConfig, JSON.parse(JSON.stringify(element.dataset || {})));
2001 if (userConfig.time_24hr === undefined &&
2002 flatpickr.defaultConfig.time_24hr === undefined) {
2003 self.config.time_24hr = self.l10n.time_24hr;
2004 }
2005 self.formatDate = createDateFormatter(self);
2006 self.parseDate = createDateParser({ config: self.config, l10n: self.l10n });
2007 }
2008 function positionCalendar(customPositionElement) {
2009 if (self.calendarContainer === undefined)
2010 return;
2011 triggerEvent("onPreCalendarPosition");
2012 var positionElement = customPositionElement || self._positionElement;
2013 var calendarHeight = Array.prototype.reduce.call(self.calendarContainer.children, (function (acc, child) { return acc + child.offsetHeight; }), 0), calendarWidth = self.calendarContainer.offsetWidth, configPos = self.config.position.split(" "), configPosVertical = configPos[0], configPosHorizontal = configPos.length > 1 ? configPos[1] : null, inputBounds = positionElement.getBoundingClientRect(), distanceFromBottom = window.innerHeight - inputBounds.bottom, showOnTop = configPosVertical === "above" ||
2014 (configPosVertical !== "below" &&
2015 distanceFromBottom < calendarHeight &&
2016 inputBounds.top > calendarHeight);
2017 var top = window.pageYOffset +
2018 inputBounds.top +
2019 (!showOnTop ? positionElement.offsetHeight + 2 : -calendarHeight - 2);
2020 toggleClass(self.calendarContainer, "arrowTop", !showOnTop);
2021 toggleClass(self.calendarContainer, "arrowBottom", showOnTop);
2022 if (self.config.inline)
2023 return;
2024 var left = window.pageXOffset +
2025 inputBounds.left -
2026 (configPosHorizontal != null && configPosHorizontal === "center"
2027 ? (calendarWidth - inputBounds.width) / 2
2028 : 0);
2029 var right = window.document.body.offsetWidth - (window.pageXOffset + inputBounds.right);
2030 var rightMost = left + calendarWidth > window.document.body.offsetWidth;
2031 var centerMost = right + calendarWidth > window.document.body.offsetWidth;
2032 toggleClass(self.calendarContainer, "rightMost", rightMost);
2033 if (self.config.static)
2034 return;
2035 self.calendarContainer.style.top = top + "px";
2036 if (!rightMost) {
2037 self.calendarContainer.style.left = left + "px";
2038 self.calendarContainer.style.right = "auto";
2039 }
2040 else if (!centerMost) {
2041 self.calendarContainer.style.left = "auto";
2042 self.calendarContainer.style.right = right + "px";
2043 }
2044 else {
2045 var doc = document.styleSheets[0];
2046 // some testing environments don't have css support
2047 if (doc === undefined)
2048 return;
2049 var bodyWidth = window.document.body.offsetWidth;
2050 var centerLeft = Math.max(0, bodyWidth / 2 - calendarWidth / 2);
2051 var centerBefore = ".flatpickr-calendar.centerMost:before";
2052 var centerAfter = ".flatpickr-calendar.centerMost:after";
2053 var centerIndex = doc.cssRules.length;
2054 var centerStyle = "{left:" + inputBounds.left + "px;right:auto;}";
2055 toggleClass(self.calendarContainer, "rightMost", false);
2056 toggleClass(self.calendarContainer, "centerMost", true);
2057 doc.insertRule(centerBefore + "," + centerAfter + centerStyle, centerIndex);
2058 self.calendarContainer.style.left = centerLeft + "px";
2059 self.calendarContainer.style.right = "auto";
2060 }
2061 }
2062 function redraw() {
2063 if (self.config.noCalendar || self.isMobile)
2064 return;
2065 updateNavigationCurrentMonth();
2066 buildDays();
2067 }
2068 function focusAndClose() {
2069 self._input.focus();
2070 if (window.navigator.userAgent.indexOf("MSIE") !== -1 ||
2071 navigator.msMaxTouchPoints !== undefined) {
2072 // hack - bugs in the way IE handles focus keeps the calendar open
2073 setTimeout(self.close, 0);
2074 }
2075 else {
2076 self.close();
2077 }
2078 }
2079 function selectDate(e) {
2080 e.preventDefault();
2081 e.stopPropagation();
2082 var isSelectable = function (day) {
2083 return day.classList &&
2084 day.classList.contains("flatpickr-day") &&
2085 !day.classList.contains("flatpickr-disabled") &&
2086 !day.classList.contains("notAllowed");
2087 };
2088 var t = findParent(e.target, isSelectable);
2089 if (t === undefined)
2090 return;
2091 var target = t;
2092 var selectedDate = (self.latestSelectedDateObj = new Date(target.dateObj.getTime()));
2093 var shouldChangeMonth = (selectedDate.getMonth() < self.currentMonth ||
2094 selectedDate.getMonth() >
2095 self.currentMonth + self.config.showMonths - 1) &&
2096 self.config.mode !== "range";
2097 self.selectedDateElem = target;
2098 if (self.config.mode === "single")
2099 self.selectedDates = [selectedDate];
2100 else if (self.config.mode === "multiple") {
2101 var selectedIndex = isDateSelected(selectedDate);
2102 if (selectedIndex)
2103 self.selectedDates.splice(parseInt(selectedIndex), 1);
2104 else
2105 self.selectedDates.push(selectedDate);
2106 }
2107 else if (self.config.mode === "range") {
2108 if (self.selectedDates.length === 2) {
2109 self.clear(false, false);
2110 }
2111 self.latestSelectedDateObj = selectedDate;
2112 self.selectedDates.push(selectedDate);
2113 // unless selecting same date twice, sort ascendingly
2114 if (compareDates(selectedDate, self.selectedDates[0], true) !== 0)
2115 self.selectedDates.sort(function (a, b) { return a.getTime() - b.getTime(); });
2116 }
2117 setHoursFromInputs();
2118 if (shouldChangeMonth) {
2119 var isNewYear = self.currentYear !== selectedDate.getFullYear();
2120 self.currentYear = selectedDate.getFullYear();
2121 self.currentMonth = selectedDate.getMonth();
2122 if (isNewYear) {
2123 triggerEvent("onYearChange");
2124 buildMonthSwitch();
2125 }
2126 triggerEvent("onMonthChange");
2127 }
2128 updateNavigationCurrentMonth();
2129 buildDays();
2130 updateValue();
2131 if (self.config.enableTime)
2132 setTimeout(function () { return (self.showTimeInput = true); }, 50);
2133 // maintain focus
2134 if (!shouldChangeMonth &&
2135 self.config.mode !== "range" &&
2136 self.config.showMonths === 1)
2137 focusOnDayElem(target);
2138 else if (self.selectedDateElem !== undefined &&
2139 self.hourElement === undefined) {
2140 self.selectedDateElem && self.selectedDateElem.focus();
2141 }
2142 if (self.hourElement !== undefined)
2143 self.hourElement !== undefined && self.hourElement.focus();
2144 if (self.config.closeOnSelect) {
2145 var single = self.config.mode === "single" && !self.config.enableTime;
2146 var range = self.config.mode === "range" &&
2147 self.selectedDates.length === 2 &&
2148 !self.config.enableTime;
2149 if (single || range) {
2150 focusAndClose();
2151 }
2152 }
2153 triggerChange();
2154 }
2155 var CALLBACKS = {
2156 locale: [setupLocale, updateWeekdays],
2157 showMonths: [buildMonths, setCalendarWidth, buildWeekdays],
2158 minDate: [jumpToDate],
2159 maxDate: [jumpToDate]
2160 };
2161 function set(option, value) {
2162 if (option !== null && typeof option === "object") {
2163 Object.assign(self.config, option);
2164 for (var key in option) {
2165 if (CALLBACKS[key] !== undefined)
2166 CALLBACKS[key].forEach(function (x) { return x(); });
2167 }
2168 }
2169 else {
2170 self.config[option] = value;
2171 if (CALLBACKS[option] !== undefined)
2172 CALLBACKS[option].forEach(function (x) { return x(); });
2173 else if (HOOKS.indexOf(option) > -1)
2174 self.config[option] = arrayify(value);
2175 }
2176 self.redraw();
2177 updateValue(false);
2178 }
2179 function setSelectedDate(inputDate, format) {
2180 var dates = [];
2181 if (inputDate instanceof Array)
2182 dates = inputDate.map(function (d) { return self.parseDate(d, format); });
2183 else if (inputDate instanceof Date || typeof inputDate === "number")
2184 dates = [self.parseDate(inputDate, format)];
2185 else if (typeof inputDate === "string") {
2186 switch (self.config.mode) {
2187 case "single":
2188 case "time":
2189 dates = [self.parseDate(inputDate, format)];
2190 break;
2191 case "multiple":
2192 dates = inputDate
2193 .split(self.config.conjunction)
2194 .map(function (date) { return self.parseDate(date, format); });
2195 break;
2196 case "range":
2197 dates = inputDate
2198 .split(self.l10n.rangeSeparator)
2199 .map(function (date) { return self.parseDate(date, format); });
2200 break;
2201 default:
2202 break;
2203 }
2204 }
2205 else
2206 self.config.errorHandler(new Error("Invalid date supplied: " + JSON.stringify(inputDate)));
2207 self.selectedDates = dates.filter(function (d) { return d instanceof Date && isEnabled(d, false); });
2208 if (self.config.mode === "range")
2209 self.selectedDates.sort(function (a, b) { return a.getTime() - b.getTime(); });
2210 }
2211 function setDate(date, triggerChange, format) {
2212 if (triggerChange === void 0) { triggerChange = false; }
2213 if (format === void 0) { format = self.config.dateFormat; }
2214 if ((date !== 0 && !date) || (date instanceof Array && date.length === 0))
2215 return self.clear(triggerChange);
2216 setSelectedDate(date, format);
2217 self.showTimeInput = self.selectedDates.length > 0;
2218 self.latestSelectedDateObj =
2219 self.selectedDates[self.selectedDates.length - 1];
2220 self.redraw();
2221 jumpToDate();
2222 setHoursFromDate();
2223 if (self.selectedDates.length === 0) {
2224 self.clear(false);
2225 }
2226 updateValue(triggerChange);
2227 if (triggerChange)
2228 triggerEvent("onChange");
2229 }
2230 function parseDateRules(arr) {
2231 return arr
2232 .slice()
2233 .map(function (rule) {
2234 if (typeof rule === "string" ||
2235 typeof rule === "number" ||
2236 rule instanceof Date) {
2237 return self.parseDate(rule, undefined, true);
2238 }
2239 else if (rule &&
2240 typeof rule === "object" &&
2241 rule.from &&
2242 rule.to)
2243 return {
2244 from: self.parseDate(rule.from, undefined),
2245 to: self.parseDate(rule.to, undefined)
2246 };
2247 return rule;
2248 })
2249 .filter(function (x) { return x; }); // remove falsy values
2250 }
2251 function setupDates() {
2252 self.selectedDates = [];
2253 self.now = self.parseDate(self.config.now) || new Date();
2254 // Workaround IE11 setting placeholder as the input's value
2255 var preloadedDate = self.config.defaultDate ||
2256 ((self.input.nodeName === "INPUT" ||
2257 self.input.nodeName === "TEXTAREA") &&
2258 self.input.placeholder &&
2259 self.input.value === self.input.placeholder
2260 ? null
2261 : self.input.value);
2262 if (preloadedDate)
2263 setSelectedDate(preloadedDate, self.config.dateFormat);
2264 self._initialDate =
2265 self.selectedDates.length > 0
2266 ? self.selectedDates[0]
2267 : self.config.minDate &&
2268 self.config.minDate.getTime() > self.now.getTime()
2269 ? self.config.minDate
2270 : self.config.maxDate &&
2271 self.config.maxDate.getTime() < self.now.getTime()
2272 ? self.config.maxDate
2273 : self.now;
2274 self.currentYear = self._initialDate.getFullYear();
2275 self.currentMonth = self._initialDate.getMonth();
2276 if (self.selectedDates.length > 0)
2277 self.latestSelectedDateObj = self.selectedDates[0];
2278 if (self.config.minTime !== undefined)
2279 self.config.minTime = self.parseDate(self.config.minTime, "H:i");
2280 if (self.config.maxTime !== undefined)
2281 self.config.maxTime = self.parseDate(self.config.maxTime, "H:i");
2282 self.minDateHasTime =
2283 !!self.config.minDate &&
2284 (self.config.minDate.getHours() > 0 ||
2285 self.config.minDate.getMinutes() > 0 ||
2286 self.config.minDate.getSeconds() > 0);
2287 self.maxDateHasTime =
2288 !!self.config.maxDate &&
2289 (self.config.maxDate.getHours() > 0 ||
2290 self.config.maxDate.getMinutes() > 0 ||
2291 self.config.maxDate.getSeconds() > 0);
2292 Object.defineProperty(self, "showTimeInput", {
2293 get: function () { return self._showTimeInput; },
2294 set: function (bool) {
2295 self._showTimeInput = bool;
2296 if (self.calendarContainer)
2297 toggleClass(self.calendarContainer, "showTimeInput", bool);
2298 self.isOpen && positionCalendar();
2299 }
2300 });
2301 }
2302 function setupInputs() {
2303 self.input = self.config.wrap
2304 ? element.querySelector("[data-input]")
2305 : element;
2306 /* istanbul ignore next */
2307 if (!self.input) {
2308 self.config.errorHandler(new Error("Invalid input element specified"));
2309 return;
2310 }
2311 // hack: store previous type to restore it after destroy()
2312 self.input._type = self.input.type;
2313 self.input.type = "text";
2314 self.input.classList.add("flatpickr-input");
2315 self._input = self.input;
2316 if (self.config.altInput) {
2317 // replicate self.element
2318 self.altInput = createElement(self.input.nodeName, self.config.altInputClass);
2319 self._input = self.altInput;
2320 self.altInput.placeholder = self.input.placeholder;
2321 self.altInput.disabled = self.input.disabled;
2322 self.altInput.required = self.input.required;
2323 self.altInput.tabIndex = self.input.tabIndex;
2324 self.altInput.type = "text";
2325 self.input.setAttribute("type", "hidden");
2326 if (!self.config.static && self.input.parentNode)
2327 self.input.parentNode.insertBefore(self.altInput, self.input.nextSibling);
2328 }
2329 if (!self.config.allowInput)
2330 self._input.setAttribute("readonly", "readonly");
2331 self._positionElement = self.config.positionElement || self._input;
2332 }
2333 function setupMobile() {
2334 var inputType = self.config.enableTime
2335 ? self.config.noCalendar
2336 ? "time"
2337 : "datetime-local"
2338 : "date";
2339 self.mobileInput = createElement("input", self.input.className + " flatpickr-mobile");
2340 self.mobileInput.step = self.input.getAttribute("step") || "any";
2341 self.mobileInput.tabIndex = 1;
2342 self.mobileInput.type = inputType;
2343 self.mobileInput.disabled = self.input.disabled;
2344 self.mobileInput.required = self.input.required;
2345 self.mobileInput.placeholder = self.input.placeholder;
2346 self.mobileFormatStr =
2347 inputType === "datetime-local"
2348 ? "Y-m-d\\TH:i:S"
2349 : inputType === "date"
2350 ? "Y-m-d"
2351 : "H:i:S";
2352 if (self.selectedDates.length > 0) {
2353 self.mobileInput.defaultValue = self.mobileInput.value = self.formatDate(self.selectedDates[0], self.mobileFormatStr);
2354 }
2355 if (self.config.minDate)
2356 self.mobileInput.min = self.formatDate(self.config.minDate, "Y-m-d");
2357 if (self.config.maxDate)
2358 self.mobileInput.max = self.formatDate(self.config.maxDate, "Y-m-d");
2359 self.input.type = "hidden";
2360 if (self.altInput !== undefined)
2361 self.altInput.type = "hidden";
2362 try {
2363 if (self.input.parentNode)
2364 self.input.parentNode.insertBefore(self.mobileInput, self.input.nextSibling);
2365 }
2366 catch (_a) { }
2367 bind(self.mobileInput, "change", function (e) {
2368 self.setDate(e.target.value, false, self.mobileFormatStr);
2369 triggerEvent("onChange");
2370 triggerEvent("onClose");
2371 });
2372 }
2373 function toggle(e) {
2374 if (self.isOpen === true)
2375 return self.close();
2376 self.open(e);
2377 }
2378 function triggerEvent(event, data) {
2379 // If the instance has been destroyed already, all hooks have been removed
2380 if (self.config === undefined)
2381 return;
2382 var hooks = self.config[event];
2383 if (hooks !== undefined && hooks.length > 0) {
2384 for (var i = 0; hooks[i] && i < hooks.length; i++)
2385 hooks[i](self.selectedDates, self.input.value, self, data);
2386 }
2387 if (event === "onChange") {
2388 self.input.dispatchEvent(createEvent("change"));
2389 // many front-end frameworks bind to the input event
2390 self.input.dispatchEvent(createEvent("input"));
2391 }
2392 }
2393 function createEvent(name) {
2394 var e = document.createEvent("Event");
2395 e.initEvent(name, true, true);
2396 return e;
2397 }
2398 function isDateSelected(date) {
2399 for (var i = 0; i < self.selectedDates.length; i++) {
2400 if (compareDates(self.selectedDates[i], date) === 0)
2401 return "" + i;
2402 }
2403 return false;
2404 }
2405 function isDateInRange(date) {
2406 if (self.config.mode !== "range" || self.selectedDates.length < 2)
2407 return false;
2408 return (compareDates(date, self.selectedDates[0]) >= 0 &&
2409 compareDates(date, self.selectedDates[1]) <= 0);
2410 }
2411 function updateNavigationCurrentMonth() {
2412 if (self.config.noCalendar || self.isMobile || !self.monthNav)
2413 return;
2414 self.yearElements.forEach(function (yearElement, i) {
2415 var d = new Date(self.currentYear, self.currentMonth, 1);
2416 d.setMonth(self.currentMonth + i);
2417 if (self.config.showMonths > 1 ||
2418 self.config.monthSelectorType === "static") {
2419 self.monthElements[i].textContent =
2420 monthToStr(d.getMonth(), self.config.shorthandCurrentMonth, self.l10n) + " ";
2421 }
2422 else {
2423 self.monthsDropdownContainer.value = d.getMonth().toString();
2424 }
2425 yearElement.value = d.getFullYear().toString();
2426 });
2427 self._hidePrevMonthArrow =
2428 self.config.minDate !== undefined &&
2429 (self.currentYear === self.config.minDate.getFullYear()
2430 ? self.currentMonth <= self.config.minDate.getMonth()
2431 : self.currentYear < self.config.minDate.getFullYear());
2432 self._hideNextMonthArrow =
2433 self.config.maxDate !== undefined &&
2434 (self.currentYear === self.config.maxDate.getFullYear()
2435 ? self.currentMonth + 1 > self.config.maxDate.getMonth()
2436 : self.currentYear > self.config.maxDate.getFullYear());
2437 }
2438 function getDateStr(format) {
2439 return self.selectedDates
2440 .map(function (dObj) { return self.formatDate(dObj, format); })
2441 .filter(function (d, i, arr) {
2442 return self.config.mode !== "range" ||
2443 self.config.enableTime ||
2444 arr.indexOf(d) === i;
2445 })
2446 .join(self.config.mode !== "range"
2447 ? self.config.conjunction
2448 : self.l10n.rangeSeparator);
2449 }
2450 /**
2451 * Updates the values of inputs associated with the calendar
2452 */
2453 function updateValue(triggerChange) {
2454 if (triggerChange === void 0) { triggerChange = true; }
2455 if (self.mobileInput !== undefined && self.mobileFormatStr) {
2456 self.mobileInput.value =
2457 self.latestSelectedDateObj !== undefined
2458 ? self.formatDate(self.latestSelectedDateObj, self.mobileFormatStr)
2459 : "";
2460 }
2461 self.input.value = getDateStr(self.config.dateFormat);
2462 if (self.altInput !== undefined) {
2463 self.altInput.value = getDateStr(self.config.altFormat);
2464 }
2465 if (triggerChange !== false)
2466 triggerEvent("onValueUpdate");
2467 }
2468 function onMonthNavClick(e) {
2469 var isPrevMonth = self.prevMonthNav.contains(e.target);
2470 var isNextMonth = self.nextMonthNav.contains(e.target);
2471 if (isPrevMonth || isNextMonth) {
2472 changeMonth(isPrevMonth ? -1 : 1);
2473 }
2474 else if (self.yearElements.indexOf(e.target) >= 0) {
2475 e.target.select();
2476 }
2477 else if (e.target.classList.contains("arrowUp")) {
2478 self.changeYear(self.currentYear + 1);
2479 }
2480 else if (e.target.classList.contains("arrowDown")) {
2481 self.changeYear(self.currentYear - 1);
2482 }
2483 }
2484 function timeWrapper(e) {
2485 e.preventDefault();
2486 var isKeyDown = e.type === "keydown", input = e.target;
2487 if (self.amPM !== undefined && e.target === self.amPM) {
2488 self.amPM.textContent =
2489 self.l10n.amPM[int(self.amPM.textContent === self.l10n.amPM[0])];
2490 }
2491 var min = parseFloat(input.getAttribute("min")), max = parseFloat(input.getAttribute("max")), step = parseFloat(input.getAttribute("step")), curValue = parseInt(input.value, 10), delta = e.delta ||
2492 (isKeyDown ? (e.which === 38 ? 1 : -1) : 0);
2493 var newValue = curValue + step * delta;
2494 if (typeof input.value !== "undefined" && input.value.length === 2) {
2495 var isHourElem = input === self.hourElement, isMinuteElem = input === self.minuteElement;
2496 if (newValue < min) {
2497 newValue =
2498 max +
2499 newValue +
2500 int(!isHourElem) +
2501 (int(isHourElem) && int(!self.amPM));
2502 if (isMinuteElem)
2503 incrementNumInput(undefined, -1, self.hourElement);
2504 }
2505 else if (newValue > max) {
2506 newValue =
2507 input === self.hourElement ? newValue - max - int(!self.amPM) : min;
2508 if (isMinuteElem)
2509 incrementNumInput(undefined, 1, self.hourElement);
2510 }
2511 if (self.amPM &&
2512 isHourElem &&
2513 (step === 1
2514 ? newValue + curValue === 23
2515 : Math.abs(newValue - curValue) > step)) {
2516 self.amPM.textContent =
2517 self.l10n.amPM[int(self.amPM.textContent === self.l10n.amPM[0])];
2518 }
2519 input.value = pad(newValue);
2520 }
2521 }
2522 init();
2523 return self;
2524 }
2525 /* istanbul ignore next */
2526 function _flatpickr(nodeList, config) {
2527 // static list
2528 var nodes = Array.prototype.slice
2529 .call(nodeList)
2530 .filter(function (x) { return x instanceof HTMLElement; });
2531 var instances = [];
2532 for (var i = 0; i < nodes.length; i++) {
2533 var node = nodes[i];
2534 try {
2535 if (node.getAttribute("data-fp-omit") !== null)
2536 continue;
2537 if (node._flatpickr !== undefined) {
2538 node._flatpickr.destroy();
2539 node._flatpickr = undefined;
2540 }
2541 node._flatpickr = FlatpickrInstance(node, config || {});
2542 instances.push(node._flatpickr);
2543 }
2544 catch (e) {
2545 console.error(e);
2546 }
2547 }
2548 return instances.length === 1 ? instances[0] : instances;
2549 }
2550 /* istanbul ignore next */
2551 if (typeof HTMLElement !== "undefined" &&
2552 typeof HTMLCollection !== "undefined" &&
2553 typeof NodeList !== "undefined") {
2554 // browser env
2555 HTMLCollection.prototype.flatpickr = NodeList.prototype.flatpickr = function (config) {
2556 return _flatpickr(this, config);
2557 };
2558 HTMLElement.prototype.flatpickr = function (config) {
2559 return _flatpickr([this], config);
2560 };
2561 }
2562 /* istanbul ignore next */
2563 var flatpickr = function (selector, config) {
2564 if (typeof selector === "string") {
2565 return _flatpickr(window.document.querySelectorAll(selector), config);
2566 }
2567 else if (selector instanceof Node) {
2568 return _flatpickr([selector], config);
2569 }
2570 else {
2571 return _flatpickr(selector, config);
2572 }
2573 };
2574 /* istanbul ignore next */
2575 flatpickr.defaultConfig = {};
2576 flatpickr.l10ns = {
2577 en: __assign({}, english),
2578 "default": __assign({}, english)
2579 };
2580 flatpickr.localize = function (l10n) {
2581 flatpickr.l10ns["default"] = __assign({}, flatpickr.l10ns["default"], l10n);
2582 };
2583 flatpickr.setDefaults = function (config) {
2584 flatpickr.defaultConfig = __assign({}, flatpickr.defaultConfig, config);
2585 };
2586 flatpickr.parseDate = createDateParser({});
2587 flatpickr.formatDate = createDateFormatter({});
2588 flatpickr.compareDates = compareDates;
2589 /* istanbul ignore next */
2590 if (typeof jQuery !== "undefined" && typeof jQuery.fn !== "undefined") {
2591 jQuery.fn.flatpickr = function (config) {
2592 return _flatpickr(this, config);
2593 };
2594 }
2595 // eslint-disable-next-line @typescript-eslint/camelcase
2596 Date.prototype.fp_incr = function (days) {
2597 return new Date(this.getFullYear(), this.getMonth(), this.getDate() + (typeof days === "string" ? parseInt(days, 10) : days));
2598 };
2599 if (typeof window !== "undefined") {
2600 window.flatpickr = flatpickr;
2601 }
2602
2603 return flatpickr;
2604
2605 }));
2606