flatpickr 4.5.2.0 → 4.5.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -14
  3. data/lib/flatpickr/version.rb +1 -1
  4. data/vendor/assets/javascripts/flatpickr.js +2065 -2106
  5. data/vendor/assets/javascripts/flatpickr/l10n/ar.js +12 -35
  6. data/vendor/assets/javascripts/flatpickr/l10n/at.js +17 -53
  7. data/vendor/assets/javascripts/flatpickr/l10n/be.js +22 -58
  8. data/vendor/assets/javascripts/flatpickr/l10n/bg.js +12 -48
  9. data/vendor/assets/javascripts/flatpickr/l10n/bn.js +12 -48
  10. data/vendor/assets/javascripts/flatpickr/l10n/cat.js +34 -66
  11. data/vendor/assets/javascripts/flatpickr/l10n/cs.js +22 -58
  12. data/vendor/assets/javascripts/flatpickr/l10n/cy.js +23 -75
  13. data/vendor/assets/javascripts/flatpickr/l10n/da.js +18 -54
  14. data/vendor/assets/javascripts/flatpickr/l10n/de.js +17 -53
  15. data/vendor/assets/javascripts/flatpickr/l10n/default.js +35 -66
  16. data/vendor/assets/javascripts/flatpickr/l10n/eo.js +20 -56
  17. data/vendor/assets/javascripts/flatpickr/l10n/es.js +17 -53
  18. data/vendor/assets/javascripts/flatpickr/l10n/et.js +20 -56
  19. data/vendor/assets/javascripts/flatpickr/l10n/fa.js +16 -52
  20. data/vendor/assets/javascripts/flatpickr/l10n/fi.js +16 -52
  21. data/vendor/assets/javascripts/flatpickr/l10n/fr.js +21 -58
  22. data/vendor/assets/javascripts/flatpickr/l10n/gr.js +21 -57
  23. data/vendor/assets/javascripts/flatpickr/l10n/he.js +12 -40
  24. data/vendor/assets/javascripts/flatpickr/l10n/hi.js +12 -48
  25. data/vendor/assets/javascripts/flatpickr/l10n/hr.js +13 -49
  26. data/vendor/assets/javascripts/flatpickr/l10n/hu.js +19 -55
  27. data/vendor/assets/javascripts/flatpickr/l10n/id.js +16 -44
  28. data/vendor/assets/javascripts/flatpickr/l10n/index.js +963 -2805
  29. data/vendor/assets/javascripts/flatpickr/l10n/it.js +20 -54
  30. data/vendor/assets/javascripts/flatpickr/l10n/ja.js +12 -48
  31. data/vendor/assets/javascripts/flatpickr/l10n/km.js +21 -57
  32. data/vendor/assets/javascripts/flatpickr/l10n/ko.js +15 -51
  33. data/vendor/assets/javascripts/flatpickr/l10n/kz.js +22 -58
  34. data/vendor/assets/javascripts/flatpickr/l10n/lt.js +19 -55
  35. data/vendor/assets/javascripts/flatpickr/l10n/lv.js +14 -50
  36. data/vendor/assets/javascripts/flatpickr/l10n/mk.js +15 -51
  37. data/vendor/assets/javascripts/flatpickr/l10n/mn.js +14 -42
  38. data/vendor/assets/javascripts/flatpickr/l10n/ms.js +16 -52
  39. data/vendor/assets/javascripts/flatpickr/l10n/my.js +16 -52
  40. data/vendor/assets/javascripts/flatpickr/l10n/nl.js +21 -58
  41. data/vendor/assets/javascripts/flatpickr/l10n/no.js +20 -56
  42. data/vendor/assets/javascripts/flatpickr/l10n/pa.js +12 -48
  43. data/vendor/assets/javascripts/flatpickr/l10n/pl.js +20 -56
  44. data/vendor/assets/javascripts/flatpickr/l10n/pt.js +13 -49
  45. data/vendor/assets/javascripts/flatpickr/l10n/ro.js +16 -52
  46. data/vendor/assets/javascripts/flatpickr/l10n/ru.js +22 -58
  47. data/vendor/assets/javascripts/flatpickr/l10n/si.js +12 -48
  48. data/vendor/assets/javascripts/flatpickr/l10n/sk.js +17 -53
  49. data/vendor/assets/javascripts/flatpickr/l10n/sl.js +17 -53
  50. data/vendor/assets/javascripts/flatpickr/l10n/sq.js +12 -48
  51. data/vendor/assets/javascripts/flatpickr/l10n/sr.js +15 -51
  52. data/vendor/assets/javascripts/flatpickr/l10n/sv.js +17 -53
  53. data/vendor/assets/javascripts/flatpickr/l10n/th.js +19 -55
  54. data/vendor/assets/javascripts/flatpickr/l10n/tr.js +21 -57
  55. data/vendor/assets/javascripts/flatpickr/l10n/uk.js +13 -49
  56. data/vendor/assets/javascripts/flatpickr/l10n/vn.js +13 -49
  57. data/vendor/assets/javascripts/flatpickr/l10n/zh.js +16 -52
  58. data/vendor/assets/javascripts/flatpickr/plugins/confirmDate/confirmDate.js +32 -35
  59. data/vendor/assets/javascripts/flatpickr/plugins/labelPlugin/labelPlugin.js +18 -17
  60. data/vendor/assets/javascripts/flatpickr/plugins/minMaxTimePlugin.js +262 -251
  61. data/vendor/assets/javascripts/flatpickr/plugins/monthSelect/monthSelect.js +46 -63
  62. data/vendor/assets/javascripts/flatpickr/plugins/rangePlugin.js +134 -125
  63. data/vendor/assets/javascripts/flatpickr/plugins/scrollPlugin.js +44 -31
  64. data/vendor/assets/javascripts/flatpickr/plugins/weekSelect/weekSelect.js +63 -66
  65. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aefb1f8a878822368904ed5062434b61de40956de54b594e7d4f0e31fc3da7ac
4
- data.tar.gz: 68ccc9dde42a26165d783812ae84134289d87717faae9b272040826acbbf11cd
3
+ metadata.gz: 7f9608aa605955ea05a9b425f02c44433b04e208b211d8c5424cba1457098b0c
4
+ data.tar.gz: 43e85efaa0bbe56ab1fa499aaf8b207fda441e437893b3cd526dcfa5be90466d
5
5
  SHA512:
6
- metadata.gz: f631d6b2e23ef445c3f987994528edc44ce718377a6f55cbf915d338a773dc9a30f6bd86bcb6829cb8e70b1e3c9971afeae485730a5663a534c16c1dd9e69959
7
- data.tar.gz: c5401ef23e14e15057dcb662391cfc659c23e1f658295408a9607f84e565f375c9591ddab046da32b69f489852c705253a008a4d736999f06c3cd9c9e0f47c80
6
+ metadata.gz: 662f681f83f7498b1ad50606f0a2d6048375b31349eff63a1f690cb89402633e8cf770778be28aa0325b5b533fa73c18080541c88fc1ebb3a92512c727cd873d
7
+ data.tar.gz: 29b92656bc2ff39424b244ebde8397a382ce2bc9af1e2b3ab69a60a4f1133845fa2754f42b2be8dd5a00fd0c8859a828834e8387a6e476889b72af5a7f75ed24
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/flatpickr.svg)](https://badge.fury.io/rb/flatpickr)
4
4
 
5
- [Flatpickr](https://github.com/chmln/flatpickr) is a lightweight and powerful datetimepicker with no dependencies. This gem packages flatpickr's assets for drop-in use in Rails applications.
5
+ [Flatpickr](https://github.com/flatpickr/flatpickr) is a lightweight and powerful datetimepicker with no dependencies. This gem packages flatpickr's assets for drop-in use in Rails applications.
6
6
 
7
7
  ## Installation
8
8
 
@@ -31,14 +31,10 @@ And in your application.js:
31
31
 
32
32
  ```js
33
33
  //= require flatpickr
34
- //
35
- // Locales can be included as well:
36
- //= require flatpickr/l10n/da
37
34
 
38
- flatpickr('.your-selector');
39
-
40
- // if using jQuery
41
- // $('.your-selector').flatpickr();
35
+ document.addEventListener('DOMContentLoaded', function() {
36
+ flatpickr('.your-selector');
37
+ })
42
38
  ```
43
39
 
44
40
  #### Using Plugins
@@ -56,15 +52,17 @@ In application.js:
56
52
  //= require flatpickr
57
53
  //= require flatpickr/plugins/confirmDate/confirmDate
58
54
 
59
- flatpickr('.your-selector', {
60
- enableTime: true,
61
- plugins: [
62
- new confirmDatePlugin({})
63
- ]
55
+ document.addEventListener('DOMContentLoaded', function() {
56
+ flatpickr('.your-selector', {
57
+ enableTime: true,
58
+ plugins: [
59
+ new confirmDatePlugin({})
60
+ ]
61
+ })
64
62
  })
65
63
  ```
66
64
 
67
- See [flatpickr's docs](https://chmln.github.io/flatpickr/) for configuration and usage info.
65
+ See [flatpickr's official docs](https://flatpickr.js.org/) for more configuration and usage details.
68
66
 
69
67
  ## License
70
68
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flatpickr
4
- VERSION = '4.5.2.0'
4
+ VERSION = '4.5.2.1'
5
5
  end
@@ -5,2209 +5,2168 @@
5
5
  (global.flatpickr = factory());
6
6
  }(this, (function () { 'use strict';
7
7
 
8
- const pad = (number) => `0${number}`.slice(-2);
9
- const int = (bool) => (bool === true ? 1 : 0);
10
- function debounce(func, wait, immediate = false) {
11
- let timeout;
12
- return function () {
13
- let context = this, args = arguments;
14
- timeout !== null && clearTimeout(timeout);
15
- timeout = window.setTimeout(function () {
16
- timeout = null;
17
- if (!immediate)
18
- func.apply(context, args);
19
- }, wait);
20
- if (immediate && !timeout)
21
- func.apply(context, args);
22
- };
8
+ var pad = function pad(number) {
9
+ return ("0" + number).slice(-2);
10
+ };
11
+ var int = function int(bool) {
12
+ return bool === true ? 1 : 0;
13
+ };
14
+ function debounce(func, wait, immediate) {
15
+ if (immediate === void 0) {
16
+ immediate = false;
17
+ }
18
+
19
+ var timeout;
20
+ return function () {
21
+ var context = this,
22
+ args = arguments;
23
+ timeout !== null && clearTimeout(timeout);
24
+ timeout = window.setTimeout(function () {
25
+ timeout = null;
26
+ if (!immediate) func.apply(context, args);
27
+ }, wait);
28
+ if (immediate && !timeout) func.apply(context, args);
29
+ };
23
30
  }
24
- const arrayify = (obj) => obj instanceof Array ? obj : [obj];
25
-
26
- const do_nothing = () => undefined;
27
- const monthToStr = (monthNumber, shorthand, locale) => locale.months[shorthand ? "shorthand" : "longhand"][monthNumber];
28
- const revFormat = {
29
- D: do_nothing,
30
- F: function (dateObj, monthName, locale) {
31
- dateObj.setMonth(locale.months.longhand.indexOf(monthName));
32
- },
33
- G: (dateObj, hour) => {
34
- dateObj.setHours(parseFloat(hour));
35
- },
36
- H: (dateObj, hour) => {
37
- dateObj.setHours(parseFloat(hour));
38
- },
39
- J: (dateObj, day) => {
40
- dateObj.setDate(parseFloat(day));
41
- },
42
- K: (dateObj, amPM, locale) => {
43
- dateObj.setHours((dateObj.getHours() % 12) +
44
- 12 * int(new RegExp(locale.amPM[1], "i").test(amPM)));
45
- },
46
- M: function (dateObj, shortMonth, locale) {
47
- dateObj.setMonth(locale.months.shorthand.indexOf(shortMonth));
48
- },
49
- S: (dateObj, seconds) => {
50
- dateObj.setSeconds(parseFloat(seconds));
51
- },
52
- U: (_, unixSeconds) => new Date(parseFloat(unixSeconds) * 1000),
53
- W: function (dateObj, weekNum) {
54
- const weekNumber = parseInt(weekNum);
55
- return new Date(dateObj.getFullYear(), 0, 2 + (weekNumber - 1) * 7, 0, 0, 0, 0);
56
- },
57
- Y: (dateObj, year) => {
58
- dateObj.setFullYear(parseFloat(year));
59
- },
60
- Z: (_, ISODate) => new Date(ISODate),
61
- d: (dateObj, day) => {
62
- dateObj.setDate(parseFloat(day));
63
- },
64
- h: (dateObj, hour) => {
65
- dateObj.setHours(parseFloat(hour));
66
- },
67
- i: (dateObj, minutes) => {
68
- dateObj.setMinutes(parseFloat(minutes));
69
- },
70
- j: (dateObj, day) => {
71
- dateObj.setDate(parseFloat(day));
72
- },
73
- l: do_nothing,
74
- m: (dateObj, month) => {
75
- dateObj.setMonth(parseFloat(month) - 1);
76
- },
77
- n: (dateObj, month) => {
78
- dateObj.setMonth(parseFloat(month) - 1);
79
- },
80
- s: (dateObj, seconds) => {
81
- dateObj.setSeconds(parseFloat(seconds));
82
- },
83
- w: do_nothing,
84
- y: (dateObj, year) => {
85
- dateObj.setFullYear(2000 + parseFloat(year));
86
- },
31
+ var arrayify = function arrayify(obj) {
32
+ return obj instanceof Array ? obj : [obj];
33
+ };
34
+
35
+ var do_nothing = function do_nothing() {
36
+ return undefined;
37
+ };
38
+
39
+ var monthToStr = function monthToStr(monthNumber, shorthand, locale) {
40
+ return locale.months[shorthand ? "shorthand" : "longhand"][monthNumber];
87
41
  };
88
- const tokenRegex = {
89
- D: "(\\w+)",
90
- F: "(\\w+)",
91
- G: "(\\d\\d|\\d)",
92
- H: "(\\d\\d|\\d)",
93
- J: "(\\d\\d|\\d)\\w+",
94
- K: "",
95
- M: "(\\w+)",
96
- S: "(\\d\\d|\\d)",
97
- U: "(.+)",
98
- W: "(\\d\\d|\\d)",
99
- Y: "(\\d{4})",
100
- Z: "(.+)",
101
- d: "(\\d\\d|\\d)",
102
- h: "(\\d\\d|\\d)",
103
- i: "(\\d\\d|\\d)",
104
- j: "(\\d\\d|\\d)",
105
- l: "(\\w+)",
106
- m: "(\\d\\d|\\d)",
107
- n: "(\\d\\d|\\d)",
108
- s: "(\\d\\d|\\d)",
109
- w: "(\\d\\d|\\d)",
110
- y: "(\\d{2})",
42
+ var revFormat = {
43
+ D: do_nothing,
44
+ F: function F(dateObj, monthName, locale) {
45
+ dateObj.setMonth(locale.months.longhand.indexOf(monthName));
46
+ },
47
+ G: function G(dateObj, hour) {
48
+ dateObj.setHours(parseFloat(hour));
49
+ },
50
+ H: function H(dateObj, hour) {
51
+ dateObj.setHours(parseFloat(hour));
52
+ },
53
+ J: function J(dateObj, day) {
54
+ dateObj.setDate(parseFloat(day));
55
+ },
56
+ K: function K(dateObj, amPM, locale) {
57
+ dateObj.setHours(dateObj.getHours() % 12 + 12 * int(new RegExp(locale.amPM[1], "i").test(amPM)));
58
+ },
59
+ M: function M(dateObj, shortMonth, locale) {
60
+ dateObj.setMonth(locale.months.shorthand.indexOf(shortMonth));
61
+ },
62
+ S: function S(dateObj, seconds) {
63
+ dateObj.setSeconds(parseFloat(seconds));
64
+ },
65
+ U: function U(_, unixSeconds) {
66
+ return new Date(parseFloat(unixSeconds) * 1000);
67
+ },
68
+ W: function W(dateObj, weekNum) {
69
+ var weekNumber = parseInt(weekNum);
70
+ return new Date(dateObj.getFullYear(), 0, 2 + (weekNumber - 1) * 7, 0, 0, 0, 0);
71
+ },
72
+ Y: function Y(dateObj, year) {
73
+ dateObj.setFullYear(parseFloat(year));
74
+ },
75
+ Z: function Z(_, ISODate) {
76
+ return new Date(ISODate);
77
+ },
78
+ d: function d(dateObj, day) {
79
+ dateObj.setDate(parseFloat(day));
80
+ },
81
+ h: function h(dateObj, hour) {
82
+ dateObj.setHours(parseFloat(hour));
83
+ },
84
+ i: function i(dateObj, minutes) {
85
+ dateObj.setMinutes(parseFloat(minutes));
86
+ },
87
+ j: function j(dateObj, day) {
88
+ dateObj.setDate(parseFloat(day));
89
+ },
90
+ l: do_nothing,
91
+ m: function m(dateObj, month) {
92
+ dateObj.setMonth(parseFloat(month) - 1);
93
+ },
94
+ n: function n(dateObj, month) {
95
+ dateObj.setMonth(parseFloat(month) - 1);
96
+ },
97
+ s: function s(dateObj, seconds) {
98
+ dateObj.setSeconds(parseFloat(seconds));
99
+ },
100
+ w: do_nothing,
101
+ y: function y(dateObj, year) {
102
+ dateObj.setFullYear(2000 + parseFloat(year));
103
+ }
111
104
  };
112
- const formats = {
113
- Z: (date) => date.toISOString(),
114
- D: function (date, locale, options) {
115
- return locale.weekdays.shorthand[formats.w(date, locale, options)];
116
- },
117
- F: function (date, locale, options) {
118
- return monthToStr(formats.n(date, locale, options) - 1, false, locale);
119
- },
120
- G: function (date, locale, options) {
121
- return pad(formats.h(date, locale, options));
122
- },
123
- H: (date) => pad(date.getHours()),
124
- J: function (date, locale) {
125
- return locale.ordinal !== undefined
126
- ? date.getDate() + locale.ordinal(date.getDate())
127
- : date.getDate();
128
- },
129
- K: (date, locale) => locale.amPM[int(date.getHours() > 11)],
130
- M: function (date, locale) {
131
- return monthToStr(date.getMonth(), true, locale);
132
- },
133
- S: (date) => pad(date.getSeconds()),
134
- U: (date) => date.getTime() / 1000,
135
- W: function (date, _, options) {
136
- return options.getWeek(date);
137
- },
138
- Y: (date) => date.getFullYear(),
139
- d: (date) => pad(date.getDate()),
140
- h: (date) => (date.getHours() % 12 ? date.getHours() % 12 : 12),
141
- i: (date) => pad(date.getMinutes()),
142
- j: (date) => date.getDate(),
143
- l: function (date, locale) {
144
- return locale.weekdays.longhand[date.getDay()];
145
- },
146
- m: (date) => pad(date.getMonth() + 1),
147
- n: (date) => date.getMonth() + 1,
148
- s: (date) => date.getSeconds(),
149
- w: (date) => date.getDay(),
150
- y: (date) => String(date.getFullYear()).substring(2),
105
+ var tokenRegex = {
106
+ D: "(\\w+)",
107
+ F: "(\\w+)",
108
+ G: "(\\d\\d|\\d)",
109
+ H: "(\\d\\d|\\d)",
110
+ J: "(\\d\\d|\\d)\\w+",
111
+ K: "",
112
+ M: "(\\w+)",
113
+ S: "(\\d\\d|\\d)",
114
+ U: "(.+)",
115
+ W: "(\\d\\d|\\d)",
116
+ Y: "(\\d{4})",
117
+ Z: "(.+)",
118
+ d: "(\\d\\d|\\d)",
119
+ h: "(\\d\\d|\\d)",
120
+ i: "(\\d\\d|\\d)",
121
+ j: "(\\d\\d|\\d)",
122
+ l: "(\\w+)",
123
+ m: "(\\d\\d|\\d)",
124
+ n: "(\\d\\d|\\d)",
125
+ s: "(\\d\\d|\\d)",
126
+ w: "(\\d\\d|\\d)",
127
+ y: "(\\d{2})"
128
+ };
129
+ var formats = {
130
+ Z: function Z(date) {
131
+ return date.toISOString();
132
+ },
133
+ D: function D(date, locale, options) {
134
+ return locale.weekdays.shorthand[formats.w(date, locale, options)];
135
+ },
136
+ F: function F(date, locale, options) {
137
+ return monthToStr(formats.n(date, locale, options) - 1, false, locale);
138
+ },
139
+ G: function G(date, locale, options) {
140
+ return pad(formats.h(date, locale, options));
141
+ },
142
+ H: function H(date) {
143
+ return pad(date.getHours());
144
+ },
145
+ J: function J(date, locale) {
146
+ return locale.ordinal !== undefined ? date.getDate() + locale.ordinal(date.getDate()) : date.getDate();
147
+ },
148
+ K: function K(date, locale) {
149
+ return locale.amPM[int(date.getHours() > 11)];
150
+ },
151
+ M: function M(date, locale) {
152
+ return monthToStr(date.getMonth(), true, locale);
153
+ },
154
+ S: function S(date) {
155
+ return pad(date.getSeconds());
156
+ },
157
+ U: function U(date) {
158
+ return date.getTime() / 1000;
159
+ },
160
+ W: function W(date, _, options) {
161
+ return options.getWeek(date);
162
+ },
163
+ Y: function Y(date) {
164
+ return date.getFullYear();
165
+ },
166
+ d: function d(date) {
167
+ return pad(date.getDate());
168
+ },
169
+ h: function h(date) {
170
+ return date.getHours() % 12 ? date.getHours() % 12 : 12;
171
+ },
172
+ i: function i(date) {
173
+ return pad(date.getMinutes());
174
+ },
175
+ j: function j(date) {
176
+ return date.getDate();
177
+ },
178
+ l: function l(date, locale) {
179
+ return locale.weekdays.longhand[date.getDay()];
180
+ },
181
+ m: function m(date) {
182
+ return pad(date.getMonth() + 1);
183
+ },
184
+ n: function n(date) {
185
+ return date.getMonth() + 1;
186
+ },
187
+ s: function s(date) {
188
+ return date.getSeconds();
189
+ },
190
+ w: function w(date) {
191
+ return date.getDay();
192
+ },
193
+ y: function y(date) {
194
+ return String(date.getFullYear()).substring(2);
195
+ }
151
196
  };
152
197
 
153
- const english = {
154
- weekdays: {
155
- shorthand: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
156
- longhand: [
157
- "Sunday",
158
- "Monday",
159
- "Tuesday",
160
- "Wednesday",
161
- "Thursday",
162
- "Friday",
163
- "Saturday",
164
- ],
165
- },
166
- months: {
167
- shorthand: [
168
- "Jan",
169
- "Feb",
170
- "Mar",
171
- "Apr",
172
- "May",
173
- "Jun",
174
- "Jul",
175
- "Aug",
176
- "Sep",
177
- "Oct",
178
- "Nov",
179
- "Dec",
180
- ],
181
- longhand: [
182
- "January",
183
- "February",
184
- "March",
185
- "April",
186
- "May",
187
- "June",
188
- "July",
189
- "August",
190
- "September",
191
- "October",
192
- "November",
193
- "December",
194
- ],
195
- },
196
- daysInMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
197
- firstDayOfWeek: 0,
198
- ordinal: (nth) => {
199
- const s = nth % 100;
200
- if (s > 3 && s < 21)
201
- return "th";
202
- switch (s % 10) {
203
- case 1:
204
- return "st";
205
- case 2:
206
- return "nd";
207
- case 3:
208
- return "rd";
209
- default:
210
- return "th";
211
- }
212
- },
213
- rangeSeparator: " to ",
214
- weekAbbreviation: "Wk",
215
- scrollTitle: "Scroll to increment",
216
- toggleTitle: "Click to toggle",
217
- amPM: ["AM", "PM"],
218
- yearAriaLabel: "Year",
198
+ var english = {
199
+ weekdays: {
200
+ shorthand: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
201
+ longhand: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
202
+ },
203
+ months: {
204
+ shorthand: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
205
+ longhand: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
206
+ },
207
+ daysInMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
208
+ firstDayOfWeek: 0,
209
+ ordinal: function ordinal(nth) {
210
+ var s = nth % 100;
211
+ if (s > 3 && s < 21) return "th";
212
+
213
+ switch (s % 10) {
214
+ case 1:
215
+ return "st";
216
+
217
+ case 2:
218
+ return "nd";
219
+
220
+ case 3:
221
+ return "rd";
222
+
223
+ default:
224
+ return "th";
225
+ }
226
+ },
227
+ rangeSeparator: " to ",
228
+ weekAbbreviation: "Wk",
229
+ scrollTitle: "Scroll to increment",
230
+ toggleTitle: "Click to toggle",
231
+ amPM: ["AM", "PM"],
232
+ yearAriaLabel: "Year"
219
233
  };
220
234
 
221
- const createDateFormatter = ({ config = defaults, l10n = english, }) => (dateObj, frmt, overrideLocale) => {
222
- const locale = overrideLocale || l10n;
235
+ var createDateFormatter = function createDateFormatter(_ref) {
236
+ var _ref$config = _ref.config,
237
+ config = _ref$config === void 0 ? defaults : _ref$config,
238
+ _ref$l10n = _ref.l10n,
239
+ l10n = _ref$l10n === void 0 ? english : _ref$l10n;
240
+ return function (dateObj, frmt, overrideLocale) {
241
+ var locale = overrideLocale || l10n;
242
+
223
243
  if (config.formatDate !== undefined) {
224
- return config.formatDate(dateObj, frmt, locale);
225
- }
226
- return frmt
227
- .split("")
228
- .map((c, i, arr) => formats[c] && arr[i - 1] !== "\\"
229
- ? formats[c](dateObj, locale, config)
230
- : c !== "\\"
231
- ? c
232
- : "")
233
- .join("");
244
+ return config.formatDate(dateObj, frmt, locale);
245
+ }
246
+
247
+ return frmt.split("").map(function (c, i, arr) {
248
+ return formats[c] && arr[i - 1] !== "\\" ? formats[c](dateObj, locale, config) : c !== "\\" ? c : "";
249
+ }).join("");
250
+ };
234
251
  };
235
- const createDateParser = ({ config = defaults, l10n = english }) => (date, givenFormat, timeless, customLocale) => {
236
- if (date !== 0 && !date)
237
- return undefined;
238
- const locale = customLocale || l10n;
239
- let parsedDate;
240
- const date_orig = date;
241
- if (date instanceof Date)
242
- parsedDate = new Date(date.getTime());
243
- else if (typeof date !== "string" &&
244
- date.toFixed !== undefined)
245
- parsedDate = new Date(date);
246
- else if (typeof date === "string") {
247
- const format = givenFormat || (config || defaults).dateFormat;
248
- const datestr = String(date).trim();
249
- if (datestr === "today") {
250
- parsedDate = new Date();
251
- timeless = true;
252
- }
253
- else if (/Z$/.test(datestr) ||
254
- /GMT$/.test(datestr))
255
- parsedDate = new Date(date);
256
- else if (config && config.parseDate)
257
- parsedDate = config.parseDate(date, format);
258
- else {
259
- parsedDate =
260
- !config || !config.noCalendar
261
- ? new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0)
262
- : new Date(new Date().setHours(0, 0, 0, 0));
263
- let matched, ops = [];
264
- for (let i = 0, matchIndex = 0, regexStr = ""; i < format.length; i++) {
265
- const token = format[i];
266
- const isBackSlash = token === "\\";
267
- const escaped = format[i - 1] === "\\" || isBackSlash;
268
- if (tokenRegex[token] && !escaped) {
269
- regexStr += tokenRegex[token];
270
- const match = new RegExp(regexStr).exec(date);
271
- if (match && (matched = true)) {
272
- ops[token !== "Y" ? "push" : "unshift"]({
273
- fn: revFormat[token],
274
- val: match[++matchIndex],
275
- });
276
- }
277
- }
278
- else if (!isBackSlash)
279
- regexStr += ".";
280
- ops.forEach(({ fn, val }) => (parsedDate = fn(parsedDate, val, locale) || parsedDate));
252
+ var createDateParser = function createDateParser(_ref2) {
253
+ var _ref2$config = _ref2.config,
254
+ config = _ref2$config === void 0 ? defaults : _ref2$config,
255
+ _ref2$l10n = _ref2.l10n,
256
+ l10n = _ref2$l10n === void 0 ? english : _ref2$l10n;
257
+ return function (date, givenFormat, timeless, customLocale) {
258
+ if (date !== 0 && !date) return undefined;
259
+ var locale = customLocale || l10n;
260
+ var parsedDate;
261
+ var date_orig = date;
262
+ if (date instanceof Date) parsedDate = new Date(date.getTime());else if (typeof date !== "string" && date.toFixed !== undefined) parsedDate = new Date(date);else if (typeof date === "string") {
263
+ var format = givenFormat || (config || defaults).dateFormat;
264
+ var datestr = String(date).trim();
265
+
266
+ if (datestr === "today") {
267
+ parsedDate = new Date();
268
+ timeless = true;
269
+ } else if (/Z$/.test(datestr) || /GMT$/.test(datestr)) parsedDate = new Date(date);else if (config && config.parseDate) parsedDate = config.parseDate(date, format);else {
270
+ parsedDate = !config || !config.noCalendar ? new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0) : new Date(new Date().setHours(0, 0, 0, 0));
271
+ var matched,
272
+ ops = [];
273
+
274
+ for (var i = 0, matchIndex = 0, regexStr = ""; i < format.length; i++) {
275
+ var token = format[i];
276
+ var isBackSlash = token === "\\";
277
+ var escaped = format[i - 1] === "\\" || isBackSlash;
278
+
279
+ if (tokenRegex[token] && !escaped) {
280
+ regexStr += tokenRegex[token];
281
+ var match = new RegExp(regexStr).exec(date);
282
+
283
+ if (match && (matched = true)) {
284
+ ops[token !== "Y" ? "push" : "unshift"]({
285
+ fn: revFormat[token],
286
+ val: match[++matchIndex]
287
+ });
281
288
  }
282
- parsedDate = matched ? parsedDate : undefined;
289
+ } else if (!isBackSlash) regexStr += ".";
290
+
291
+ ops.forEach(function (_ref3) {
292
+ var fn = _ref3.fn,
293
+ val = _ref3.val;
294
+ return parsedDate = fn(parsedDate, val, locale) || parsedDate;
295
+ });
283
296
  }
297
+
298
+ parsedDate = matched ? parsedDate : undefined;
299
+ }
284
300
  }
301
+
285
302
  if (!(parsedDate instanceof Date && !isNaN(parsedDate.getTime()))) {
286
- config.errorHandler(new Error(`Invalid date provided: ${date_orig}`));
287
- return undefined;
303
+ config.errorHandler(new Error("Invalid date provided: " + date_orig));
304
+ return undefined;
288
305
  }
289
- if (timeless === true)
290
- parsedDate.setHours(0, 0, 0, 0);
306
+
307
+ if (timeless === true) parsedDate.setHours(0, 0, 0, 0);
291
308
  return parsedDate;
309
+ };
292
310
  };
293
- function compareDates(date1, date2, timeless = true) {
294
- if (timeless !== false) {
295
- return (new Date(date1.getTime()).setHours(0, 0, 0, 0) -
296
- new Date(date2.getTime()).setHours(0, 0, 0, 0));
297
- }
298
- return date1.getTime() - date2.getTime();
311
+ function compareDates(date1, date2, timeless) {
312
+ if (timeless === void 0) {
313
+ timeless = true;
314
+ }
315
+
316
+ if (timeless !== false) {
317
+ return new Date(date1.getTime()).setHours(0, 0, 0, 0) - new Date(date2.getTime()).setHours(0, 0, 0, 0);
318
+ }
319
+
320
+ return date1.getTime() - date2.getTime();
299
321
  }
300
- const getWeek = (givenDate) => {
301
- const date = new Date(givenDate.getTime());
302
- date.setHours(0, 0, 0, 0);
303
- date.setDate(date.getDate() + 3 - ((date.getDay() + 6) % 7));
304
- var week1 = new Date(date.getFullYear(), 0, 4);
305
- return (1 +
306
- Math.round(((date.getTime() - week1.getTime()) / 86400000 -
307
- 3 +
308
- ((week1.getDay() + 6) % 7)) /
309
- 7));
322
+ var getWeek = function getWeek(givenDate) {
323
+ var date = new Date(givenDate.getTime());
324
+ date.setHours(0, 0, 0, 0);
325
+ date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
326
+ var week1 = new Date(date.getFullYear(), 0, 4);
327
+ return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
310
328
  };
311
- const isBetween = (ts, ts1, ts2) => {
312
- return ts > Math.min(ts1, ts2) && ts < Math.max(ts1, ts2);
329
+ var isBetween = function isBetween(ts, ts1, ts2) {
330
+ return ts > Math.min(ts1, ts2) && ts < Math.max(ts1, ts2);
313
331
  };
314
- const duration = {
315
- DAY: 86400000,
332
+ var duration = {
333
+ DAY: 86400000
316
334
  };
317
335
 
318
- const HOOKS = [
319
- "onChange",
320
- "onClose",
321
- "onDayCreate",
322
- "onDestroy",
323
- "onKeyDown",
324
- "onMonthChange",
325
- "onOpen",
326
- "onParseConfig",
327
- "onReady",
328
- "onValueUpdate",
329
- "onYearChange",
330
- "onPreCalendarPosition",
331
- ];
332
- const defaults = {
333
- _disable: [],
334
- _enable: [],
335
- allowInput: false,
336
- altFormat: "F j, Y",
337
- altInput: false,
338
- altInputClass: "form-control input",
339
- animate: typeof window === "object" &&
340
- window.navigator.userAgent.indexOf("MSIE") === -1,
341
- ariaDateFormat: "F j, Y",
342
- clickOpens: true,
343
- closeOnSelect: true,
344
- conjunction: ", ",
345
- dateFormat: "Y-m-d",
346
- defaultHour: 12,
347
- defaultMinute: 0,
348
- defaultSeconds: 0,
349
- disable: [],
350
- disableMobile: false,
351
- enable: [],
352
- enableSeconds: false,
353
- enableTime: false,
354
- errorHandler: (err) => typeof console !== "undefined" && console.warn(err),
355
- getWeek,
356
- hourIncrement: 1,
357
- ignoredFocusElements: [],
358
- inline: false,
359
- locale: "default",
360
- minuteIncrement: 5,
361
- mode: "single",
362
- 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>",
363
- noCalendar: false,
364
- now: new Date(),
365
- onChange: [],
366
- onClose: [],
367
- onDayCreate: [],
368
- onDestroy: [],
369
- onKeyDown: [],
370
- onMonthChange: [],
371
- onOpen: [],
372
- onParseConfig: [],
373
- onReady: [],
374
- onValueUpdate: [],
375
- onYearChange: [],
376
- onPreCalendarPosition: [],
377
- plugins: [],
378
- position: "auto",
379
- positionElement: undefined,
380
- 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>",
381
- shorthandCurrentMonth: false,
382
- showMonths: 1,
383
- static: false,
384
- time_24hr: false,
385
- weekNumbers: false,
386
- wrap: false,
336
+ var HOOKS = ["onChange", "onClose", "onDayCreate", "onDestroy", "onKeyDown", "onMonthChange", "onOpen", "onParseConfig", "onReady", "onValueUpdate", "onYearChange", "onPreCalendarPosition"];
337
+ var defaults = {
338
+ _disable: [],
339
+ _enable: [],
340
+ allowInput: false,
341
+ altFormat: "F j, Y",
342
+ altInput: false,
343
+ altInputClass: "form-control input",
344
+ animate: typeof window === "object" && window.navigator.userAgent.indexOf("MSIE") === -1,
345
+ ariaDateFormat: "F j, Y",
346
+ clickOpens: true,
347
+ closeOnSelect: true,
348
+ conjunction: ", ",
349
+ dateFormat: "Y-m-d",
350
+ defaultHour: 12,
351
+ defaultMinute: 0,
352
+ defaultSeconds: 0,
353
+ disable: [],
354
+ disableMobile: false,
355
+ enable: [],
356
+ enableSeconds: false,
357
+ enableTime: false,
358
+ errorHandler: function errorHandler(err) {
359
+ return typeof console !== "undefined" && console.warn(err);
360
+ },
361
+ getWeek: getWeek,
362
+ hourIncrement: 1,
363
+ ignoredFocusElements: [],
364
+ inline: false,
365
+ locale: "default",
366
+ minuteIncrement: 5,
367
+ mode: "single",
368
+ 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>",
369
+ noCalendar: false,
370
+ now: new Date(),
371
+ onChange: [],
372
+ onClose: [],
373
+ onDayCreate: [],
374
+ onDestroy: [],
375
+ onKeyDown: [],
376
+ onMonthChange: [],
377
+ onOpen: [],
378
+ onParseConfig: [],
379
+ onReady: [],
380
+ onValueUpdate: [],
381
+ onYearChange: [],
382
+ onPreCalendarPosition: [],
383
+ plugins: [],
384
+ position: "auto",
385
+ positionElement: undefined,
386
+ 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>",
387
+ shorthandCurrentMonth: false,
388
+ showMonths: 1,
389
+ static: false,
390
+ time_24hr: false,
391
+ weekNumbers: false,
392
+ wrap: false
387
393
  };
388
394
 
389
395
  function toggleClass(elem, className, bool) {
390
- if (bool === true)
391
- return elem.classList.add(className);
392
- elem.classList.remove(className);
396
+ if (bool === true) return elem.classList.add(className);
397
+ elem.classList.remove(className);
393
398
  }
394
399
  function createElement(tag, className, content) {
395
- const e = window.document.createElement(tag);
396
- className = className || "";
397
- content = content || "";
398
- e.className = className;
399
- if (content !== undefined)
400
- e.textContent = content;
401
- return e;
400
+ var e = window.document.createElement(tag);
401
+ className = className || "";
402
+ content = content || "";
403
+ e.className = className;
404
+ if (content !== undefined) e.textContent = content;
405
+ return e;
402
406
  }
403
407
  function clearNode(node) {
404
- while (node.firstChild)
405
- node.removeChild(node.firstChild);
408
+ while (node.firstChild) {
409
+ node.removeChild(node.firstChild);
410
+ }
406
411
  }
407
412
  function findParent(node, condition) {
408
- if (condition(node))
409
- return node;
410
- else if (node.parentNode)
411
- return findParent(node.parentNode, condition);
412
- return undefined;
413
+ if (condition(node)) return node;else if (node.parentNode) return findParent(node.parentNode, condition);
414
+ return undefined;
413
415
  }
414
416
  function createNumberInput(inputClassName, opts) {
415
- const wrapper = createElement("div", "numInputWrapper"), numInput = createElement("input", "numInput " + inputClassName), arrowUp = createElement("span", "arrowUp"), arrowDown = createElement("span", "arrowDown");
416
- numInput.type = "text";
417
- numInput.pattern = "\\d*";
418
- if (opts !== undefined)
419
- for (const key in opts)
420
- numInput.setAttribute(key, opts[key]);
421
- wrapper.appendChild(numInput);
422
- wrapper.appendChild(arrowUp);
423
- wrapper.appendChild(arrowDown);
424
- return wrapper;
417
+ var wrapper = createElement("div", "numInputWrapper"),
418
+ numInput = createElement("input", "numInput " + inputClassName),
419
+ arrowUp = createElement("span", "arrowUp"),
420
+ arrowDown = createElement("span", "arrowDown");
421
+ numInput.type = "text";
422
+ numInput.pattern = "\\d*";
423
+ if (opts !== undefined) for (var key in opts) {
424
+ numInput.setAttribute(key, opts[key]);
425
+ }
426
+ wrapper.appendChild(numInput);
427
+ wrapper.appendChild(arrowUp);
428
+ wrapper.appendChild(arrowDown);
429
+ return wrapper;
425
430
  }
426
431
 
427
432
  if (typeof Object.assign !== "function") {
428
- Object.assign = function (target, ...args) {
429
- if (!target) {
430
- throw TypeError("Cannot convert undefined or null to object");
431
- }
432
- return target;
433
+ Object.assign = function (target) {
434
+ if (!target) {
435
+ throw TypeError("Cannot convert undefined or null to object");
436
+ }
437
+
438
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
439
+ args[_key - 1] = arguments[_key];
440
+ }
441
+
442
+ var _loop = function _loop() {
443
+ var source = args[_i];
444
+
445
+ if (source) {
446
+ Object.keys(source).forEach(function (key) {
447
+ return target[key] = source[key];
448
+ });
449
+ }
433
450
  };
451
+
452
+ for (var _i = 0; _i < args.length; _i++) {
453
+ _loop();
454
+ }
455
+
456
+ return target;
457
+ };
434
458
  }
435
459
 
436
- const DEBOUNCED_CHANGE_MS = 300;
460
+ var DEBOUNCED_CHANGE_MS = 300;
461
+
437
462
  function FlatpickrInstance(element, instanceConfig) {
438
- const self = {
439
- config: Object.assign({}, flatpickr.defaultConfig),
440
- l10n: english,
441
- };
442
- self.parseDate = createDateParser({ config: self.config, l10n: self.l10n });
443
- self._handlers = [];
444
- self._bind = bind;
445
- self._setHoursFromDate = setHoursFromDate;
446
- self._positionCalendar = positionCalendar;
447
- self.changeMonth = changeMonth;
448
- self.changeYear = changeYear;
449
- self.clear = clear;
450
- self.close = close;
451
- self._createElement = createElement;
452
- self.destroy = destroy;
453
- self.isEnabled = isEnabled;
454
- self.jumpToDate = jumpToDate;
455
- self.open = open;
456
- self.redraw = redraw;
457
- self.set = set;
458
- self.setDate = setDate;
459
- self.toggle = toggle;
460
- function setupHelperFunctions() {
461
- self.utils = {
462
- getDaysInMonth(month = self.currentMonth, yr = self.currentYear) {
463
- if (month === 1 && ((yr % 4 === 0 && yr % 100 !== 0) || yr % 400 === 0))
464
- return 29;
465
- return self.l10n.daysInMonth[month];
466
- },
467
- };
468
- }
469
- function init() {
470
- self.element = self.input = element;
471
- self.isOpen = false;
472
- parseConfig();
473
- setupLocale();
474
- setupInputs();
475
- setupDates();
476
- setupHelperFunctions();
477
- if (!self.isMobile)
478
- build();
479
- bindEvents();
480
- if (self.selectedDates.length || self.config.noCalendar) {
481
- if (self.config.enableTime) {
482
- setHoursFromDate(self.config.noCalendar
483
- ? self.latestSelectedDateObj || self.config.minDate
484
- : undefined);
485
- }
486
- updateValue(false);
487
- }
488
- setCalendarWidth();
489
- self.showTimeInput =
490
- self.selectedDates.length > 0 || self.config.noCalendar;
491
- const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
492
- if (!self.isMobile && isSafari) {
493
- positionCalendar();
494
- }
495
- triggerEvent("onReady");
496
- }
497
- function bindToInstance(fn) {
498
- return fn.bind(self);
499
- }
500
- function setCalendarWidth() {
501
- const config = self.config;
502
- if (config.weekNumbers === false && config.showMonths === 1)
503
- return;
504
- else if (config.noCalendar !== true) {
505
- window.requestAnimationFrame(function () {
506
- self.calendarContainer.style.visibility = "hidden";
507
- self.calendarContainer.style.display = "block";
508
- if (self.daysContainer !== undefined) {
509
- const daysWidth = (self.days.offsetWidth + 1) * config.showMonths;
510
- self.daysContainer.style.width = daysWidth + "px";
511
- self.calendarContainer.style.width =
512
- daysWidth +
513
- (self.weekWrapper !== undefined
514
- ? self.weekWrapper.offsetWidth
515
- : 0) +
516
- "px";
517
- self.calendarContainer.style.removeProperty("visibility");
518
- self.calendarContainer.style.removeProperty("display");
519
- }
520
- });
521
- }
522
- }
523
- function updateTime(e) {
524
- if (self.selectedDates.length === 0)
525
- return;
526
- if (e !== undefined && e.type !== "blur") {
527
- timeWrapper(e);
463
+ var self = {
464
+ config: Object.assign({}, flatpickr.defaultConfig),
465
+ l10n: english
466
+ };
467
+ self.parseDate = createDateParser({
468
+ config: self.config,
469
+ l10n: self.l10n
470
+ });
471
+ self._handlers = [];
472
+ self._bind = bind;
473
+ self._setHoursFromDate = setHoursFromDate;
474
+ self._positionCalendar = positionCalendar;
475
+ self.changeMonth = changeMonth;
476
+ self.changeYear = changeYear;
477
+ self.clear = clear;
478
+ self.close = close;
479
+ self._createElement = createElement;
480
+ self.destroy = destroy;
481
+ self.isEnabled = isEnabled;
482
+ self.jumpToDate = jumpToDate;
483
+ self.open = open;
484
+ self.redraw = redraw;
485
+ self.set = set;
486
+ self.setDate = setDate;
487
+ self.toggle = toggle;
488
+
489
+ function setupHelperFunctions() {
490
+ self.utils = {
491
+ getDaysInMonth: function getDaysInMonth(month, yr) {
492
+ if (month === void 0) {
493
+ month = self.currentMonth;
528
494
  }
529
- const prevValue = self._input.value;
530
- setHoursFromInputs();
531
- updateValue();
532
- if (self._input.value !== prevValue) {
533
- self._debouncedChange();
495
+
496
+ if (yr === void 0) {
497
+ yr = self.currentYear;
534
498
  }
499
+
500
+ if (month === 1 && (yr % 4 === 0 && yr % 100 !== 0 || yr % 400 === 0)) return 29;
501
+ return self.l10n.daysInMonth[month];
502
+ }
503
+ };
504
+ }
505
+
506
+ function init() {
507
+ self.element = self.input = element;
508
+ self.isOpen = false;
509
+ parseConfig();
510
+ setupLocale();
511
+ setupInputs();
512
+ setupDates();
513
+ setupHelperFunctions();
514
+ if (!self.isMobile) build();
515
+ bindEvents();
516
+
517
+ if (self.selectedDates.length || self.config.noCalendar) {
518
+ if (self.config.enableTime) {
519
+ setHoursFromDate(self.config.noCalendar ? self.latestSelectedDateObj || self.config.minDate : undefined);
520
+ }
521
+
522
+ updateValue(false);
535
523
  }
536
- function ampm2military(hour, amPM) {
537
- return (hour % 12) + 12 * int(amPM === self.l10n.amPM[1]);
524
+
525
+ setCalendarWidth();
526
+ self.showTimeInput = self.selectedDates.length > 0 || self.config.noCalendar;
527
+ var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
528
+
529
+ if (!self.isMobile && isSafari) {
530
+ positionCalendar();
538
531
  }
539
- function military2ampm(hour) {
540
- switch (hour % 24) {
541
- case 0:
542
- case 12:
543
- return 12;
544
- default:
545
- return hour % 12;
532
+
533
+ triggerEvent("onReady");
534
+ }
535
+
536
+ function bindToInstance(fn) {
537
+ return fn.bind(self);
538
+ }
539
+
540
+ function setCalendarWidth() {
541
+ var config = self.config;
542
+ if (config.weekNumbers === false && config.showMonths === 1) return;else if (config.noCalendar !== true) {
543
+ window.requestAnimationFrame(function () {
544
+ self.calendarContainer.style.visibility = "hidden";
545
+ self.calendarContainer.style.display = "block";
546
+
547
+ if (self.daysContainer !== undefined) {
548
+ var daysWidth = (self.days.offsetWidth + 1) * config.showMonths;
549
+ self.daysContainer.style.width = daysWidth + "px";
550
+ self.calendarContainer.style.width = daysWidth + (self.weekWrapper !== undefined ? self.weekWrapper.offsetWidth : 0) + "px";
551
+ self.calendarContainer.style.removeProperty("visibility");
552
+ self.calendarContainer.style.removeProperty("display");
546
553
  }
554
+ });
547
555
  }
548
- function setHoursFromInputs() {
549
- if (self.hourElement === undefined || self.minuteElement === undefined)
550
- return;
551
- let hours = (parseInt(self.hourElement.value.slice(-2), 10) || 0) % 24, minutes = (parseInt(self.minuteElement.value, 10) || 0) % 60, seconds = self.secondElement !== undefined
552
- ? (parseInt(self.secondElement.value, 10) || 0) % 60
553
- : 0;
554
- if (self.amPM !== undefined) {
555
- hours = ampm2military(hours, self.amPM.textContent);
556
- }
557
- const limitMinHours = self.config.minTime !== undefined ||
558
- (self.config.minDate &&
559
- self.minDateHasTime &&
560
- self.latestSelectedDateObj &&
561
- compareDates(self.latestSelectedDateObj, self.config.minDate, true) ===
562
- 0);
563
- const limitMaxHours = self.config.maxTime !== undefined ||
564
- (self.config.maxDate &&
565
- self.maxDateHasTime &&
566
- self.latestSelectedDateObj &&
567
- compareDates(self.latestSelectedDateObj, self.config.maxDate, true) ===
568
- 0);
569
- if (limitMaxHours) {
570
- const maxTime = self.config.maxTime !== undefined
571
- ? self.config.maxTime
572
- : self.config.maxDate;
573
- hours = Math.min(hours, maxTime.getHours());
574
- if (hours === maxTime.getHours())
575
- minutes = Math.min(minutes, maxTime.getMinutes());
576
- if (minutes === maxTime.getMinutes())
577
- seconds = Math.min(seconds, maxTime.getSeconds());
578
- }
579
- if (limitMinHours) {
580
- const minTime = self.config.minTime !== undefined
581
- ? self.config.minTime
582
- : self.config.minDate;
583
- hours = Math.max(hours, minTime.getHours());
584
- if (hours === minTime.getHours())
585
- minutes = Math.max(minutes, minTime.getMinutes());
586
- if (minutes === minTime.getMinutes())
587
- seconds = Math.max(seconds, minTime.getSeconds());
588
- }
589
- setHours(hours, minutes, seconds);
590
- }
591
- function setHoursFromDate(dateObj) {
592
- const date = dateObj || self.latestSelectedDateObj;
593
- if (date)
594
- setHours(date.getHours(), date.getMinutes(), date.getSeconds());
595
- }
596
- function setDefaultHours() {
597
- let hours = self.config.defaultHour;
598
- let minutes = self.config.defaultMinute;
599
- let seconds = self.config.defaultSeconds;
600
- if (self.config.minDate !== undefined) {
601
- const min_hr = self.config.minDate.getHours();
602
- const min_minutes = self.config.minDate.getMinutes();
603
- hours = Math.max(hours, min_hr);
604
- if (hours === min_hr)
605
- minutes = Math.max(min_minutes, minutes);
606
- if (hours === min_hr && minutes === min_minutes)
607
- seconds = self.config.minDate.getSeconds();
608
- }
609
- if (self.config.maxDate !== undefined) {
610
- const max_hr = self.config.maxDate.getHours();
611
- const max_minutes = self.config.maxDate.getMinutes();
612
- hours = Math.min(hours, max_hr);
613
- if (hours === max_hr)
614
- minutes = Math.min(max_minutes, minutes);
615
- if (hours === max_hr && minutes === max_minutes)
616
- seconds = self.config.maxDate.getSeconds();
617
- }
618
- setHours(hours, minutes, seconds);
556
+ }
557
+
558
+ function updateTime(e) {
559
+ if (self.selectedDates.length === 0) return;
560
+
561
+ if (e !== undefined && e.type !== "blur") {
562
+ timeWrapper(e);
619
563
  }
620
- function setHours(hours, minutes, seconds) {
621
- if (self.latestSelectedDateObj !== undefined) {
622
- self.latestSelectedDateObj.setHours(hours % 24, minutes, seconds || 0, 0);
623
- }
624
- if (!self.hourElement || !self.minuteElement || self.isMobile)
625
- return;
626
- self.hourElement.value = pad(!self.config.time_24hr
627
- ? ((12 + hours) % 12) + 12 * int(hours % 12 === 0)
628
- : hours);
629
- self.minuteElement.value = pad(minutes);
630
- if (self.amPM !== undefined)
631
- self.amPM.textContent = self.l10n.amPM[int(hours >= 12)];
632
- if (self.secondElement !== undefined)
633
- self.secondElement.value = pad(seconds);
634
- }
635
- function onYearInput(event) {
636
- const year = parseInt(event.target.value) + (event.delta || 0);
637
- if (year / 1000 > 1 ||
638
- (event.key === "Enter" && !/[^\d]/.test(year.toString()))) {
639
- changeYear(year);
640
- }
564
+
565
+ var prevValue = self._input.value;
566
+ setHoursFromInputs();
567
+ updateValue();
568
+
569
+ if (self._input.value !== prevValue) {
570
+ self._debouncedChange();
641
571
  }
642
- function bind(element, event, handler, options) {
643
- if (event instanceof Array)
644
- return event.forEach(ev => bind(element, ev, handler, options));
645
- if (element instanceof Array)
646
- return element.forEach(el => bind(el, event, handler, options));
647
- element.addEventListener(event, handler, options);
648
- self._handlers.push({
649
- element: element,
650
- event,
651
- handler,
652
- options,
653
- });
572
+ }
573
+
574
+ function ampm2military(hour, amPM) {
575
+ return hour % 12 + 12 * int(amPM === self.l10n.amPM[1]);
576
+ }
577
+
578
+ function military2ampm(hour) {
579
+ switch (hour % 24) {
580
+ case 0:
581
+ case 12:
582
+ return 12;
583
+
584
+ default:
585
+ return hour % 12;
654
586
  }
655
- function onClick(handler) {
656
- return evt => {
657
- evt.which === 1 && handler(evt);
658
- };
587
+ }
588
+
589
+ function setHoursFromInputs() {
590
+ if (self.hourElement === undefined || self.minuteElement === undefined) return;
591
+ var hours = (parseInt(self.hourElement.value.slice(-2), 10) || 0) % 24,
592
+ minutes = (parseInt(self.minuteElement.value, 10) || 0) % 60,
593
+ seconds = self.secondElement !== undefined ? (parseInt(self.secondElement.value, 10) || 0) % 60 : 0;
594
+
595
+ if (self.amPM !== undefined) {
596
+ hours = ampm2military(hours, self.amPM.textContent);
659
597
  }
660
- function triggerChange() {
661
- triggerEvent("onChange");
598
+
599
+ var limitMinHours = self.config.minTime !== undefined || self.config.minDate && self.minDateHasTime && self.latestSelectedDateObj && compareDates(self.latestSelectedDateObj, self.config.minDate, true) === 0;
600
+ var limitMaxHours = self.config.maxTime !== undefined || self.config.maxDate && self.maxDateHasTime && self.latestSelectedDateObj && compareDates(self.latestSelectedDateObj, self.config.maxDate, true) === 0;
601
+
602
+ if (limitMaxHours) {
603
+ var maxTime = self.config.maxTime !== undefined ? self.config.maxTime : self.config.maxDate;
604
+ hours = Math.min(hours, maxTime.getHours());
605
+ if (hours === maxTime.getHours()) minutes = Math.min(minutes, maxTime.getMinutes());
606
+ if (minutes === maxTime.getMinutes()) seconds = Math.min(seconds, maxTime.getSeconds());
662
607
  }
663
- function bindEvents() {
664
- if (self.config.wrap) {
665
- ["open", "close", "toggle", "clear"].forEach(evt => {
666
- Array.prototype.forEach.call(self.element.querySelectorAll(`[data-${evt}]`), (el) => bind(el, "click", self[evt]));
667
- });
668
- }
669
- if (self.isMobile) {
670
- setupMobile();
671
- return;
672
- }
673
- const debouncedResize = debounce(onResize, 50);
674
- self._debouncedChange = debounce(triggerChange, DEBOUNCED_CHANGE_MS);
675
- if (self.daysContainer && !/iPhone|iPad|iPod/i.test(navigator.userAgent))
676
- bind(self.daysContainer, "mouseover", (e) => {
677
- if (self.config.mode === "range")
678
- onMouseOver(e.target);
679
- });
680
- bind(window.document.body, "keydown", onKeyDown);
681
- if (!self.config.static)
682
- bind(self._input, "keydown", onKeyDown);
683
- if (!self.config.inline && !self.config.static)
684
- bind(window, "resize", debouncedResize);
685
- if (window.ontouchstart !== undefined)
686
- bind(window.document, "click", documentClick);
687
- else
688
- bind(window.document, "mousedown", onClick(documentClick));
689
- bind(window.document, "focus", documentClick, { capture: true });
690
- if (self.config.clickOpens === true) {
691
- bind(self._input, "focus", self.open);
692
- bind(self._input, "mousedown", onClick(self.open));
693
- }
694
- if (self.daysContainer !== undefined) {
695
- bind(self.monthNav, "mousedown", onClick(onMonthNavClick));
696
- bind(self.monthNav, ["keyup", "increment"], onYearInput);
697
- bind(self.daysContainer, "mousedown", onClick(selectDate));
698
- }
699
- if (self.timeContainer !== undefined &&
700
- self.minuteElement !== undefined &&
701
- self.hourElement !== undefined) {
702
- const selText = (e) => e.target.select();
703
- bind(self.timeContainer, ["increment"], updateTime);
704
- bind(self.timeContainer, "blur", updateTime, { capture: true });
705
- bind(self.timeContainer, "mousedown", onClick(timeIncrement));
706
- bind([self.hourElement, self.minuteElement], ["focus", "click"], selText);
707
- if (self.secondElement !== undefined)
708
- bind(self.secondElement, "focus", () => self.secondElement && self.secondElement.select());
709
- if (self.amPM !== undefined) {
710
- bind(self.amPM, "mousedown", onClick(e => {
711
- updateTime(e);
712
- triggerChange();
713
- }));
714
- }
715
- }
608
+
609
+ if (limitMinHours) {
610
+ var minTime = self.config.minTime !== undefined ? self.config.minTime : self.config.minDate;
611
+ hours = Math.max(hours, minTime.getHours());
612
+ if (hours === minTime.getHours()) minutes = Math.max(minutes, minTime.getMinutes());
613
+ if (minutes === minTime.getMinutes()) seconds = Math.max(seconds, minTime.getSeconds());
716
614
  }
717
- function jumpToDate(jumpDate) {
718
- const jumpTo = jumpDate !== undefined
719
- ? self.parseDate(jumpDate)
720
- : self.latestSelectedDateObj ||
721
- (self.config.minDate && self.config.minDate > self.now
722
- ? self.config.minDate
723
- : self.config.maxDate && self.config.maxDate < self.now
724
- ? self.config.maxDate
725
- : self.now);
726
- try {
727
- if (jumpTo !== undefined) {
728
- self.currentYear = jumpTo.getFullYear();
729
- self.currentMonth = jumpTo.getMonth();
730
- }
731
- }
732
- catch (e) {
733
- e.message = "Invalid date supplied: " + jumpTo;
734
- self.config.errorHandler(e);
735
- }
736
- self.redraw();
737
- }
738
- function timeIncrement(e) {
739
- if (~e.target.className.indexOf("arrow"))
740
- incrementNumInput(e, e.target.classList.contains("arrowUp") ? 1 : -1);
741
- }
742
- function incrementNumInput(e, delta, inputElem) {
743
- const target = e && e.target;
744
- const input = inputElem ||
745
- (target && target.parentNode && target.parentNode.firstChild);
746
- const event = createEvent("increment");
747
- event.delta = delta;
748
- input && input.dispatchEvent(event);
749
- }
750
- function build() {
751
- const fragment = window.document.createDocumentFragment();
752
- self.calendarContainer = createElement("div", "flatpickr-calendar");
753
- self.calendarContainer.tabIndex = -1;
754
- if (!self.config.noCalendar) {
755
- fragment.appendChild(buildMonthNav());
756
- self.innerContainer = createElement("div", "flatpickr-innerContainer");
757
- if (self.config.weekNumbers) {
758
- const { weekWrapper, weekNumbers } = buildWeeks();
759
- self.innerContainer.appendChild(weekWrapper);
760
- self.weekNumbers = weekNumbers;
761
- self.weekWrapper = weekWrapper;
762
- }
763
- self.rContainer = createElement("div", "flatpickr-rContainer");
764
- self.rContainer.appendChild(buildWeekdays());
765
- if (!self.daysContainer) {
766
- self.daysContainer = createElement("div", "flatpickr-days");
767
- self.daysContainer.tabIndex = -1;
768
- }
769
- buildDays();
770
- self.rContainer.appendChild(self.daysContainer);
771
- self.innerContainer.appendChild(self.rContainer);
772
- fragment.appendChild(self.innerContainer);
773
- }
774
- if (self.config.enableTime) {
775
- fragment.appendChild(buildTime());
776
- }
777
- toggleClass(self.calendarContainer, "rangeMode", self.config.mode === "range");
778
- toggleClass(self.calendarContainer, "animate", self.config.animate === true);
779
- toggleClass(self.calendarContainer, "multiMonth", self.config.showMonths > 1);
780
- self.calendarContainer.appendChild(fragment);
781
- const customAppend = self.config.appendTo !== undefined &&
782
- self.config.appendTo.nodeType !== undefined;
783
- if (self.config.inline || self.config.static) {
784
- self.calendarContainer.classList.add(self.config.inline ? "inline" : "static");
785
- if (self.config.inline) {
786
- if (!customAppend && self.element.parentNode)
787
- self.element.parentNode.insertBefore(self.calendarContainer, self._input.nextSibling);
788
- else if (self.config.appendTo !== undefined)
789
- self.config.appendTo.appendChild(self.calendarContainer);
790
- }
791
- if (self.config.static) {
792
- const wrapper = createElement("div", "flatpickr-wrapper");
793
- if (self.element.parentNode)
794
- self.element.parentNode.insertBefore(wrapper, self.element);
795
- wrapper.appendChild(self.element);
796
- if (self.altInput)
797
- wrapper.appendChild(self.altInput);
798
- wrapper.appendChild(self.calendarContainer);
799
- }
800
- }
801
- if (!self.config.static && !self.config.inline)
802
- (self.config.appendTo !== undefined
803
- ? self.config.appendTo
804
- : window.document.body).appendChild(self.calendarContainer);
805
- }
806
- function createDay(className, date, dayNumber, i) {
807
- const dateIsEnabled = isEnabled(date, true), dayElement = createElement("span", "flatpickr-day " + className, date.getDate().toString());
808
- dayElement.dateObj = date;
809
- dayElement.$i = i;
810
- dayElement.setAttribute("aria-label", self.formatDate(date, self.config.ariaDateFormat));
811
- if (className.indexOf("hidden") === -1 &&
812
- compareDates(date, self.now) === 0) {
813
- self.todayDateElem = dayElement;
814
- dayElement.classList.add("today");
815
- dayElement.setAttribute("aria-current", "date");
816
- }
817
- if (dateIsEnabled) {
818
- dayElement.tabIndex = -1;
819
- if (isDateSelected(date)) {
820
- dayElement.classList.add("selected");
821
- self.selectedDateElem = dayElement;
822
- if (self.config.mode === "range") {
823
- toggleClass(dayElement, "startRange", self.selectedDates[0] &&
824
- compareDates(date, self.selectedDates[0], true) === 0);
825
- toggleClass(dayElement, "endRange", self.selectedDates[1] &&
826
- compareDates(date, self.selectedDates[1], true) === 0);
827
- if (className === "nextMonthDay")
828
- dayElement.classList.add("inRange");
829
- }
830
- }
831
- }
832
- else {
833
- dayElement.classList.add("disabled");
834
- }
835
- if (self.config.mode === "range") {
836
- if (isDateInRange(date) && !isDateSelected(date))
837
- dayElement.classList.add("inRange");
838
- }
839
- if (self.weekNumbers &&
840
- self.config.showMonths === 1 &&
841
- className !== "prevMonthDay" &&
842
- dayNumber % 7 === 1) {
843
- self.weekNumbers.insertAdjacentHTML("beforeend", "<span class='flatpickr-day'>" + self.config.getWeek(date) + "</span>");
844
- }
845
- triggerEvent("onDayCreate", dayElement);
846
- return dayElement;
847
- }
848
- function focusOnDayElem(targetNode) {
849
- targetNode.focus();
850
- if (self.config.mode === "range")
851
- onMouseOver(targetNode);
852
- }
853
- function getFirstAvailableDay(delta) {
854
- const startMonth = delta > 0 ? 0 : self.config.showMonths - 1;
855
- const endMonth = delta > 0 ? self.config.showMonths : -1;
856
- for (let m = startMonth; m != endMonth; m += delta) {
857
- const month = self.daysContainer.children[m];
858
- const startIndex = delta > 0 ? 0 : month.children.length - 1;
859
- const endIndex = delta > 0 ? month.children.length : -1;
860
- for (let i = startIndex; i != endIndex; i += delta) {
861
- const c = month.children[i];
862
- if (c.className.indexOf("hidden") === -1 && isEnabled(c.dateObj))
863
- return c;
864
- }
865
- }
866
- return undefined;
867
- }
868
- function getNextAvailableDay(current, delta) {
869
- const givenMonth = current.className.indexOf("Month") === -1
870
- ? current.dateObj.getMonth()
871
- : self.currentMonth;
872
- const endMonth = delta > 0 ? self.config.showMonths : -1;
873
- const loopDelta = delta > 0 ? 1 : -1;
874
- for (let m = givenMonth - self.currentMonth; m != endMonth; m += loopDelta) {
875
- const month = self.daysContainer.children[m];
876
- const startIndex = givenMonth - self.currentMonth === m
877
- ? current.$i + delta
878
- : delta < 0
879
- ? month.children.length - 1
880
- : 0;
881
- const numMonthDays = month.children.length;
882
- for (let i = startIndex; i >= 0 && i < numMonthDays && i != (delta > 0 ? numMonthDays : -1); i += loopDelta) {
883
- const c = month.children[i];
884
- if (c.className.indexOf("hidden") === -1 &&
885
- isEnabled(c.dateObj) &&
886
- Math.abs(current.$i - i) >= Math.abs(delta))
887
- return focusOnDayElem(c);
888
- }
889
- }
890
- self.changeMonth(loopDelta);
891
- focusOnDay(getFirstAvailableDay(loopDelta), 0);
892
- return undefined;
893
- }
894
- function focusOnDay(current, offset) {
895
- const dayFocused = isInView(document.activeElement || document.body);
896
- const startElem = current !== undefined
897
- ? current
898
- : dayFocused
899
- ? document.activeElement
900
- : self.selectedDateElem !== undefined &&
901
- isInView(self.selectedDateElem)
902
- ? self.selectedDateElem
903
- : self.todayDateElem !== undefined && isInView(self.todayDateElem)
904
- ? self.todayDateElem
905
- : getFirstAvailableDay(offset > 0 ? 1 : -1);
906
- if (startElem === undefined)
907
- return self._input.focus();
908
- if (!dayFocused)
909
- return focusOnDayElem(startElem);
910
- getNextAvailableDay(startElem, offset);
911
- }
912
- function buildMonthDays(year, month) {
913
- const firstOfMonth = (new Date(year, month, 1).getDay() - self.l10n.firstDayOfWeek + 7) % 7;
914
- const prevMonthDays = self.utils.getDaysInMonth((month - 1 + 12) % 12);
915
- const daysInMonth = self.utils.getDaysInMonth(month), days = window.document.createDocumentFragment(), isMultiMonth = self.config.showMonths > 1, prevMonthDayClass = isMultiMonth ? "prevMonthDay hidden" : "prevMonthDay", nextMonthDayClass = isMultiMonth ? "nextMonthDay hidden" : "nextMonthDay";
916
- let dayNumber = prevMonthDays + 1 - firstOfMonth, dayIndex = 0;
917
- for (; dayNumber <= prevMonthDays; dayNumber++, dayIndex++) {
918
- days.appendChild(createDay(prevMonthDayClass, new Date(year, month - 1, dayNumber), dayNumber, dayIndex));
919
- }
920
- for (dayNumber = 1; dayNumber <= daysInMonth; dayNumber++, dayIndex++) {
921
- days.appendChild(createDay("", new Date(year, month, dayNumber), dayNumber, dayIndex));
922
- }
923
- for (let dayNum = daysInMonth + 1; dayNum <= 42 - firstOfMonth &&
924
- (self.config.showMonths === 1 || dayIndex % 7 !== 0); dayNum++, dayIndex++) {
925
- days.appendChild(createDay(nextMonthDayClass, new Date(year, month + 1, dayNum % daysInMonth), dayNum, dayIndex));
926
- }
927
- const dayContainer = createElement("div", "dayContainer");
928
- dayContainer.appendChild(days);
929
- return dayContainer;
615
+
616
+ setHours(hours, minutes, seconds);
617
+ }
618
+
619
+ function setHoursFromDate(dateObj) {
620
+ var date = dateObj || self.latestSelectedDateObj;
621
+ if (date) setHours(date.getHours(), date.getMinutes(), date.getSeconds());
622
+ }
623
+
624
+ function setDefaultHours() {
625
+ var hours = self.config.defaultHour;
626
+ var minutes = self.config.defaultMinute;
627
+ var seconds = self.config.defaultSeconds;
628
+
629
+ if (self.config.minDate !== undefined) {
630
+ var min_hr = self.config.minDate.getHours();
631
+ var min_minutes = self.config.minDate.getMinutes();
632
+ hours = Math.max(hours, min_hr);
633
+ if (hours === min_hr) minutes = Math.max(min_minutes, minutes);
634
+ if (hours === min_hr && minutes === min_minutes) seconds = self.config.minDate.getSeconds();
930
635
  }
931
- function buildDays() {
932
- if (self.daysContainer === undefined) {
933
- return;
934
- }
935
- clearNode(self.daysContainer);
936
- if (self.weekNumbers)
937
- clearNode(self.weekNumbers);
938
- const frag = document.createDocumentFragment();
939
- for (let i = 0; i < self.config.showMonths; i++) {
940
- const d = new Date(self.currentYear, self.currentMonth, 1);
941
- d.setMonth(self.currentMonth + i);
942
- frag.appendChild(buildMonthDays(d.getFullYear(), d.getMonth()));
943
- }
944
- self.daysContainer.appendChild(frag);
945
- self.days = self.daysContainer.firstChild;
946
- if (self.config.mode === "range" && self.selectedDates.length === 1) {
947
- onMouseOver();
948
- }
636
+
637
+ if (self.config.maxDate !== undefined) {
638
+ var max_hr = self.config.maxDate.getHours();
639
+ var max_minutes = self.config.maxDate.getMinutes();
640
+ hours = Math.min(hours, max_hr);
641
+ if (hours === max_hr) minutes = Math.min(max_minutes, minutes);
642
+ if (hours === max_hr && minutes === max_minutes) seconds = self.config.maxDate.getSeconds();
949
643
  }
950
- function buildMonth() {
951
- const container = createElement("div", "flatpickr-month");
952
- const monthNavFragment = window.document.createDocumentFragment();
953
- const monthElement = createElement("span", "cur-month");
954
- const yearInput = createNumberInput("cur-year", { tabindex: "-1" });
955
- const yearElement = yearInput.getElementsByTagName("input")[0];
956
- yearElement.setAttribute("aria-label", self.l10n.yearAriaLabel);
957
- if (self.config.minDate)
958
- yearElement.setAttribute("data-min", self.config.minDate.getFullYear().toString());
959
- if (self.config.maxDate) {
960
- yearElement.setAttribute("data-max", self.config.maxDate.getFullYear().toString());
961
- yearElement.disabled =
962
- !!self.config.minDate &&
963
- self.config.minDate.getFullYear() === self.config.maxDate.getFullYear();
964
- }
965
- const currentMonth = createElement("div", "flatpickr-current-month");
966
- currentMonth.appendChild(monthElement);
967
- currentMonth.appendChild(yearInput);
968
- monthNavFragment.appendChild(currentMonth);
969
- container.appendChild(monthNavFragment);
970
- return {
971
- container,
972
- yearElement,
973
- monthElement,
974
- };
975
- }
976
- function buildMonths() {
977
- clearNode(self.monthNav);
978
- self.monthNav.appendChild(self.prevMonthNav);
979
- for (let m = self.config.showMonths; m--;) {
980
- const month = buildMonth();
981
- self.yearElements.push(month.yearElement);
982
- self.monthElements.push(month.monthElement);
983
- self.monthNav.appendChild(month.container);
984
- }
985
- self.monthNav.appendChild(self.nextMonthNav);
986
- }
987
- function buildMonthNav() {
988
- self.monthNav = createElement("div", "flatpickr-months");
989
- self.yearElements = [];
990
- self.monthElements = [];
991
- self.prevMonthNav = createElement("span", "flatpickr-prev-month");
992
- self.prevMonthNav.innerHTML = self.config.prevArrow;
993
- self.nextMonthNav = createElement("span", "flatpickr-next-month");
994
- self.nextMonthNav.innerHTML = self.config.nextArrow;
995
- buildMonths();
996
- Object.defineProperty(self, "_hidePrevMonthArrow", {
997
- get: () => self.__hidePrevMonthArrow,
998
- set(bool) {
999
- if (self.__hidePrevMonthArrow !== bool) {
1000
- toggleClass(self.prevMonthNav, "disabled", bool);
1001
- self.__hidePrevMonthArrow = bool;
1002
- }
1003
- },
1004
- });
1005
- Object.defineProperty(self, "_hideNextMonthArrow", {
1006
- get: () => self.__hideNextMonthArrow,
1007
- set(bool) {
1008
- if (self.__hideNextMonthArrow !== bool) {
1009
- toggleClass(self.nextMonthNav, "disabled", bool);
1010
- self.__hideNextMonthArrow = bool;
1011
- }
1012
- },
1013
- });
1014
- self.currentYearElement = self.yearElements[0];
1015
- updateNavigationCurrentMonth();
1016
- return self.monthNav;
1017
- }
1018
- function buildTime() {
1019
- self.calendarContainer.classList.add("hasTime");
1020
- if (self.config.noCalendar)
1021
- self.calendarContainer.classList.add("noCalendar");
1022
- self.timeContainer = createElement("div", "flatpickr-time");
1023
- self.timeContainer.tabIndex = -1;
1024
- const separator = createElement("span", "flatpickr-time-separator", ":");
1025
- const hourInput = createNumberInput("flatpickr-hour");
1026
- self.hourElement = hourInput.getElementsByTagName("input")[0];
1027
- const minuteInput = createNumberInput("flatpickr-minute");
1028
- self.minuteElement = minuteInput.getElementsByTagName("input")[0];
1029
- self.hourElement.tabIndex = self.minuteElement.tabIndex = -1;
1030
- self.hourElement.value = pad(self.latestSelectedDateObj
1031
- ? self.latestSelectedDateObj.getHours()
1032
- : self.config.time_24hr
1033
- ? self.config.defaultHour
1034
- : military2ampm(self.config.defaultHour));
1035
- self.minuteElement.value = pad(self.latestSelectedDateObj
1036
- ? self.latestSelectedDateObj.getMinutes()
1037
- : self.config.defaultMinute);
1038
- self.hourElement.setAttribute("data-step", self.config.hourIncrement.toString());
1039
- self.minuteElement.setAttribute("data-step", self.config.minuteIncrement.toString());
1040
- self.hourElement.setAttribute("data-min", self.config.time_24hr ? "0" : "1");
1041
- self.hourElement.setAttribute("data-max", self.config.time_24hr ? "23" : "12");
1042
- self.minuteElement.setAttribute("data-min", "0");
1043
- self.minuteElement.setAttribute("data-max", "59");
1044
- self.timeContainer.appendChild(hourInput);
1045
- self.timeContainer.appendChild(separator);
1046
- self.timeContainer.appendChild(minuteInput);
1047
- if (self.config.time_24hr)
1048
- self.timeContainer.classList.add("time24hr");
1049
- if (self.config.enableSeconds) {
1050
- self.timeContainer.classList.add("hasSeconds");
1051
- const secondInput = createNumberInput("flatpickr-second");
1052
- self.secondElement = secondInput.getElementsByTagName("input")[0];
1053
- self.secondElement.value = pad(self.latestSelectedDateObj
1054
- ? self.latestSelectedDateObj.getSeconds()
1055
- : self.config.defaultSeconds);
1056
- self.secondElement.setAttribute("data-step", self.minuteElement.getAttribute("data-step"));
1057
- self.secondElement.setAttribute("data-min", self.minuteElement.getAttribute("data-min"));
1058
- self.secondElement.setAttribute("data-max", self.minuteElement.getAttribute("data-max"));
1059
- self.timeContainer.appendChild(createElement("span", "flatpickr-time-separator", ":"));
1060
- self.timeContainer.appendChild(secondInput);
1061
- }
1062
- if (!self.config.time_24hr) {
1063
- self.amPM = createElement("span", "flatpickr-am-pm", self.l10n.amPM[int((self.latestSelectedDateObj
1064
- ? self.hourElement.value
1065
- : self.config.defaultHour) > 11)]);
1066
- self.amPM.title = self.l10n.toggleTitle;
1067
- self.amPM.tabIndex = -1;
1068
- self.timeContainer.appendChild(self.amPM);
1069
- }
1070
- return self.timeContainer;
1071
- }
1072
- function buildWeekdays() {
1073
- if (!self.weekdayContainer)
1074
- self.weekdayContainer = createElement("div", "flatpickr-weekdays");
1075
- else
1076
- clearNode(self.weekdayContainer);
1077
- for (let i = self.config.showMonths; i--;) {
1078
- const container = createElement("div", "flatpickr-weekdaycontainer");
1079
- self.weekdayContainer.appendChild(container);
1080
- }
1081
- updateWeekdays();
1082
- return self.weekdayContainer;
1083
- }
1084
- function updateWeekdays() {
1085
- const firstDayOfWeek = self.l10n.firstDayOfWeek;
1086
- let weekdays = [...self.l10n.weekdays.shorthand];
1087
- if (firstDayOfWeek > 0 && firstDayOfWeek < weekdays.length) {
1088
- weekdays = [
1089
- ...weekdays.splice(firstDayOfWeek, weekdays.length),
1090
- ...weekdays.splice(0, firstDayOfWeek),
1091
- ];
1092
- }
1093
- for (let i = self.config.showMonths; i--;) {
1094
- self.weekdayContainer.children[i].innerHTML = `
1095
- <span class=flatpickr-weekday>
1096
- ${weekdays.join("</span><span class=flatpickr-weekday>")}
1097
- </span>
1098
- `;
1099
- }
644
+
645
+ setHours(hours, minutes, seconds);
646
+ }
647
+
648
+ function setHours(hours, minutes, seconds) {
649
+ if (self.latestSelectedDateObj !== undefined) {
650
+ self.latestSelectedDateObj.setHours(hours % 24, minutes, seconds || 0, 0);
1100
651
  }
1101
- function buildWeeks() {
1102
- self.calendarContainer.classList.add("hasWeeks");
1103
- const weekWrapper = createElement("div", "flatpickr-weekwrapper");
1104
- weekWrapper.appendChild(createElement("span", "flatpickr-weekday", self.l10n.weekAbbreviation));
1105
- const weekNumbers = createElement("div", "flatpickr-weeks");
1106
- weekWrapper.appendChild(weekNumbers);
1107
- return {
1108
- weekWrapper,
1109
- weekNumbers,
1110
- };
1111
- }
1112
- function changeMonth(value, is_offset = true) {
1113
- const delta = is_offset ? value : value - self.currentMonth;
1114
- if ((delta < 0 && self._hidePrevMonthArrow === true) ||
1115
- (delta > 0 && self._hideNextMonthArrow === true))
1116
- return;
1117
- self.currentMonth += delta;
1118
- if (self.currentMonth < 0 || self.currentMonth > 11) {
1119
- self.currentYear += self.currentMonth > 11 ? 1 : -1;
1120
- self.currentMonth = (self.currentMonth + 12) % 12;
1121
- triggerEvent("onYearChange");
1122
- }
1123
- buildDays();
1124
- triggerEvent("onMonthChange");
1125
- updateNavigationCurrentMonth();
1126
- }
1127
- function clear(triggerChangeEvent = true) {
1128
- self.input.value = "";
1129
- if (self.altInput !== undefined)
1130
- self.altInput.value = "";
1131
- if (self.mobileInput !== undefined)
1132
- self.mobileInput.value = "";
1133
- self.selectedDates = [];
1134
- self.latestSelectedDateObj = undefined;
1135
- self.showTimeInput = false;
1136
- if (self.config.enableTime === true) {
1137
- setDefaultHours();
1138
- }
1139
- self.redraw();
1140
- if (triggerChangeEvent)
1141
- triggerEvent("onChange");
1142
- }
1143
- function close() {
1144
- self.isOpen = false;
1145
- if (!self.isMobile) {
1146
- self.calendarContainer.classList.remove("open");
1147
- self._input.classList.remove("active");
1148
- }
1149
- triggerEvent("onClose");
1150
- }
1151
- function destroy() {
1152
- if (self.config !== undefined)
1153
- triggerEvent("onDestroy");
1154
- for (let i = self._handlers.length; i--;) {
1155
- const h = self._handlers[i];
1156
- h.element.removeEventListener(h.event, h.handler, h.options);
1157
- }
1158
- self._handlers = [];
1159
- if (self.mobileInput) {
1160
- if (self.mobileInput.parentNode)
1161
- self.mobileInput.parentNode.removeChild(self.mobileInput);
1162
- self.mobileInput = undefined;
1163
- }
1164
- else if (self.calendarContainer && self.calendarContainer.parentNode) {
1165
- if (self.config.static && self.calendarContainer.parentNode) {
1166
- const wrapper = self.calendarContainer.parentNode;
1167
- wrapper.lastChild && wrapper.removeChild(wrapper.lastChild);
1168
- if (wrapper.parentNode) {
1169
- while (wrapper.firstChild)
1170
- wrapper.parentNode.insertBefore(wrapper.firstChild, wrapper);
1171
- wrapper.parentNode.removeChild(wrapper);
1172
- }
1173
- }
1174
- else
1175
- self.calendarContainer.parentNode.removeChild(self.calendarContainer);
1176
- }
1177
- if (self.altInput) {
1178
- self.input.type = "text";
1179
- if (self.altInput.parentNode)
1180
- self.altInput.parentNode.removeChild(self.altInput);
1181
- delete self.altInput;
1182
- }
1183
- if (self.input) {
1184
- self.input.type = self.input._type;
1185
- self.input.classList.remove("flatpickr-input");
1186
- self.input.removeAttribute("readonly");
1187
- self.input.value = "";
1188
- }
1189
- [
1190
- "_showTimeInput",
1191
- "latestSelectedDateObj",
1192
- "_hideNextMonthArrow",
1193
- "_hidePrevMonthArrow",
1194
- "__hideNextMonthArrow",
1195
- "__hidePrevMonthArrow",
1196
- "isMobile",
1197
- "isOpen",
1198
- "selectedDateElem",
1199
- "minDateHasTime",
1200
- "maxDateHasTime",
1201
- "days",
1202
- "daysContainer",
1203
- "_input",
1204
- "_positionElement",
1205
- "innerContainer",
1206
- "rContainer",
1207
- "monthNav",
1208
- "todayDateElem",
1209
- "calendarContainer",
1210
- "weekdayContainer",
1211
- "prevMonthNav",
1212
- "nextMonthNav",
1213
- "currentMonthElement",
1214
- "currentYearElement",
1215
- "navigationCurrentMonth",
1216
- "selectedDateElem",
1217
- "config",
1218
- ].forEach(k => {
1219
- try {
1220
- delete self[k];
1221
- }
1222
- catch (_) { }
652
+
653
+ if (!self.hourElement || !self.minuteElement || self.isMobile) return;
654
+ self.hourElement.value = pad(!self.config.time_24hr ? (12 + hours) % 12 + 12 * int(hours % 12 === 0) : hours);
655
+ self.minuteElement.value = pad(minutes);
656
+ if (self.amPM !== undefined) self.amPM.textContent = self.l10n.amPM[int(hours >= 12)];
657
+ if (self.secondElement !== undefined) self.secondElement.value = pad(seconds);
658
+ }
659
+
660
+ function onYearInput(event) {
661
+ var year = parseInt(event.target.value) + (event.delta || 0);
662
+
663
+ if (year / 1000 > 1 || event.key === "Enter" && !/[^\d]/.test(year.toString())) {
664
+ changeYear(year);
665
+ }
666
+ }
667
+
668
+ function bind(element, event, handler, options) {
669
+ if (event instanceof Array) return event.forEach(function (ev) {
670
+ return bind(element, ev, handler, options);
671
+ });
672
+ if (element instanceof Array) return element.forEach(function (el) {
673
+ return bind(el, event, handler, options);
674
+ });
675
+ element.addEventListener(event, handler, options);
676
+
677
+ self._handlers.push({
678
+ element: element,
679
+ event: event,
680
+ handler: handler,
681
+ options: options
682
+ });
683
+ }
684
+
685
+ function onClick(handler) {
686
+ return function (evt) {
687
+ evt.which === 1 && handler(evt);
688
+ };
689
+ }
690
+
691
+ function triggerChange() {
692
+ triggerEvent("onChange");
693
+ }
694
+
695
+ function bindEvents() {
696
+ if (self.config.wrap) {
697
+ ["open", "close", "toggle", "clear"].forEach(function (evt) {
698
+ Array.prototype.forEach.call(self.element.querySelectorAll("[data-" + evt + "]"), function (el) {
699
+ return bind(el, "click", self[evt]);
1223
700
  });
701
+ });
1224
702
  }
1225
- function isCalendarElem(elem) {
1226
- if (self.config.appendTo && self.config.appendTo.contains(elem))
1227
- return true;
1228
- return self.calendarContainer.contains(elem);
1229
- }
1230
- function documentClick(e) {
1231
- if (self.isOpen && !self.config.inline) {
1232
- const isCalendarElement = isCalendarElem(e.target);
1233
- const isInput = e.target === self.input ||
1234
- e.target === self.altInput ||
1235
- self.element.contains(e.target) ||
1236
- (e.path &&
1237
- e.path.indexOf &&
1238
- (~e.path.indexOf(self.input) ||
1239
- ~e.path.indexOf(self.altInput)));
1240
- const lostFocus = e.type === "blur"
1241
- ? isInput &&
1242
- e.relatedTarget &&
1243
- !isCalendarElem(e.relatedTarget)
1244
- : !isInput && !isCalendarElement;
1245
- const isIgnored = !self.config.ignoredFocusElements.some(elem => elem.contains(e.target));
1246
- if (lostFocus && isIgnored) {
1247
- self.close();
1248
- if (self.config.mode === "range" && self.selectedDates.length === 1) {
1249
- self.clear(false);
1250
- self.redraw();
1251
- }
1252
- }
1253
- }
703
+
704
+ if (self.isMobile) {
705
+ setupMobile();
706
+ return;
1254
707
  }
1255
- function changeYear(newYear) {
1256
- if (!newYear ||
1257
- (self.config.minDate && newYear < self.config.minDate.getFullYear()) ||
1258
- (self.config.maxDate && newYear > self.config.maxDate.getFullYear()))
1259
- return;
1260
- const newYearNum = newYear, isNewYear = self.currentYear !== newYearNum;
1261
- self.currentYear = newYearNum || self.currentYear;
1262
- if (self.config.maxDate &&
1263
- self.currentYear === self.config.maxDate.getFullYear()) {
1264
- self.currentMonth = Math.min(self.config.maxDate.getMonth(), self.currentMonth);
1265
- }
1266
- else if (self.config.minDate &&
1267
- self.currentYear === self.config.minDate.getFullYear()) {
1268
- self.currentMonth = Math.max(self.config.minDate.getMonth(), self.currentMonth);
1269
- }
1270
- if (isNewYear) {
1271
- self.redraw();
1272
- triggerEvent("onYearChange");
1273
- }
708
+
709
+ var debouncedResize = debounce(onResize, 50);
710
+ self._debouncedChange = debounce(triggerChange, DEBOUNCED_CHANGE_MS);
711
+ if (self.daysContainer && !/iPhone|iPad|iPod/i.test(navigator.userAgent)) bind(self.daysContainer, "mouseover", function (e) {
712
+ if (self.config.mode === "range") onMouseOver(e.target);
713
+ });
714
+ bind(window.document.body, "keydown", onKeyDown);
715
+ if (!self.config.static) bind(self._input, "keydown", onKeyDown);
716
+ if (!self.config.inline && !self.config.static) bind(window, "resize", debouncedResize);
717
+ if (window.ontouchstart !== undefined) bind(window.document, "click", documentClick);else bind(window.document, "mousedown", onClick(documentClick));
718
+ bind(window.document, "focus", documentClick, {
719
+ capture: true
720
+ });
721
+
722
+ if (self.config.clickOpens === true) {
723
+ bind(self._input, "focus", self.open);
724
+ bind(self._input, "mousedown", onClick(self.open));
1274
725
  }
1275
- function isEnabled(date, timeless = true) {
1276
- const dateToCheck = self.parseDate(date, undefined, timeless);
1277
- if ((self.config.minDate &&
1278
- dateToCheck &&
1279
- compareDates(dateToCheck, self.config.minDate, timeless !== undefined ? timeless : !self.minDateHasTime) < 0) ||
1280
- (self.config.maxDate &&
1281
- dateToCheck &&
1282
- compareDates(dateToCheck, self.config.maxDate, timeless !== undefined ? timeless : !self.maxDateHasTime) > 0))
1283
- return false;
1284
- if (self.config.enable.length === 0 && self.config.disable.length === 0)
1285
- return true;
1286
- if (dateToCheck === undefined)
1287
- return false;
1288
- const bool = self.config.enable.length > 0, array = bool ? self.config.enable : self.config.disable;
1289
- for (let i = 0, d; i < array.length; i++) {
1290
- d = array[i];
1291
- if (typeof d === "function" &&
1292
- d(dateToCheck))
1293
- return bool;
1294
- else if (d instanceof Date &&
1295
- dateToCheck !== undefined &&
1296
- d.getTime() === dateToCheck.getTime())
1297
- return bool;
1298
- else if (typeof d === "string" && dateToCheck !== undefined) {
1299
- const parsed = self.parseDate(d, undefined, true);
1300
- return parsed && parsed.getTime() === dateToCheck.getTime()
1301
- ? bool
1302
- : !bool;
1303
- }
1304
- else if (typeof d === "object" &&
1305
- dateToCheck !== undefined &&
1306
- d.from &&
1307
- d.to &&
1308
- dateToCheck.getTime() >= d.from.getTime() &&
1309
- dateToCheck.getTime() <= d.to.getTime())
1310
- return bool;
1311
- }
1312
- return !bool;
1313
- }
1314
- function isInView(elem) {
1315
- if (self.daysContainer !== undefined)
1316
- return (elem.className.indexOf("hidden") === -1 &&
1317
- self.daysContainer.contains(elem));
1318
- return false;
1319
- }
1320
- function onKeyDown(e) {
1321
- const isInput = e.target === self._input;
1322
- const allowInput = self.config.allowInput;
1323
- const allowKeydown = self.isOpen && (!allowInput || !isInput);
1324
- const allowInlineKeydown = self.config.inline && isInput && !allowInput;
1325
- if (e.keyCode === 13 && isInput) {
1326
- if (allowInput) {
1327
- self.setDate(self._input.value, true, e.target === self.altInput
1328
- ? self.config.altFormat
1329
- : self.config.dateFormat);
1330
- return e.target.blur();
1331
- }
1332
- else
1333
- self.open();
1334
- }
1335
- else if (isCalendarElem(e.target) ||
1336
- allowKeydown ||
1337
- allowInlineKeydown) {
1338
- const isTimeObj = !!self.timeContainer &&
1339
- self.timeContainer.contains(e.target);
1340
- switch (e.keyCode) {
1341
- case 13:
1342
- if (isTimeObj)
1343
- updateTime();
1344
- else
1345
- selectDate(e);
1346
- break;
1347
- case 27:
1348
- e.preventDefault();
1349
- focusAndClose();
1350
- break;
1351
- case 8:
1352
- case 46:
1353
- if (isInput && !self.config.allowInput) {
1354
- e.preventDefault();
1355
- self.clear();
1356
- }
1357
- break;
1358
- case 37:
1359
- case 39:
1360
- if (!isTimeObj) {
1361
- e.preventDefault();
1362
- if (self.daysContainer !== undefined &&
1363
- (allowInput === false || isInView(document.activeElement))) {
1364
- const delta = e.keyCode === 39 ? 1 : -1;
1365
- if (!e.ctrlKey)
1366
- focusOnDay(undefined, delta);
1367
- else {
1368
- changeMonth(delta);
1369
- focusOnDay(getFirstAvailableDay(1), 0);
1370
- }
1371
- }
1372
- }
1373
- else if (self.hourElement)
1374
- self.hourElement.focus();
1375
- break;
1376
- case 38:
1377
- case 40:
1378
- e.preventDefault();
1379
- const delta = e.keyCode === 40 ? 1 : -1;
1380
- if (self.daysContainer && e.target.$i !== undefined) {
1381
- if (e.ctrlKey) {
1382
- changeYear(self.currentYear - delta);
1383
- focusOnDay(getFirstAvailableDay(1), 0);
1384
- }
1385
- else if (!isTimeObj)
1386
- focusOnDay(undefined, delta * 7);
1387
- }
1388
- else if (self.config.enableTime) {
1389
- if (!isTimeObj && self.hourElement)
1390
- self.hourElement.focus();
1391
- updateTime(e);
1392
- self._debouncedChange();
1393
- }
1394
- break;
1395
- case 9:
1396
- if (!isTimeObj) {
1397
- self.element.focus();
1398
- break;
1399
- }
1400
- const elems = [
1401
- self.hourElement,
1402
- self.minuteElement,
1403
- self.secondElement,
1404
- self.amPM,
1405
- ].filter(x => x);
1406
- const i = elems.indexOf(e.target);
1407
- if (i !== -1) {
1408
- const target = elems[i + (e.shiftKey ? -1 : 1)];
1409
- if (target !== undefined) {
1410
- e.preventDefault();
1411
- target.focus();
1412
- }
1413
- else {
1414
- self.element.focus();
1415
- }
1416
- }
1417
- break;
1418
- default:
1419
- break;
1420
- }
1421
- }
1422
- if (self.amPM !== undefined && e.target === self.amPM) {
1423
- switch (e.key) {
1424
- case self.l10n.amPM[0].charAt(0):
1425
- case self.l10n.amPM[0].charAt(0).toLowerCase():
1426
- self.amPM.textContent = self.l10n.amPM[0];
1427
- setHoursFromInputs();
1428
- updateValue();
1429
- break;
1430
- case self.l10n.amPM[1].charAt(0):
1431
- case self.l10n.amPM[1].charAt(0).toLowerCase():
1432
- self.amPM.textContent = self.l10n.amPM[1];
1433
- setHoursFromInputs();
1434
- updateValue();
1435
- break;
1436
- }
1437
- }
1438
- triggerEvent("onKeyDown", e);
1439
- }
1440
- function onMouseOver(elem) {
1441
- if (self.selectedDates.length !== 1 ||
1442
- (elem &&
1443
- (!elem.classList.contains("flatpickr-day") ||
1444
- elem.classList.contains("disabled"))))
1445
- return;
1446
- const hoverDate = elem
1447
- ? elem.dateObj.getTime()
1448
- : 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()), lastDate = self.daysContainer.lastChild
1449
- .lastChild.dateObj.getTime();
1450
- let containsDisabled = false;
1451
- let minRange = 0, maxRange = 0;
1452
- for (let t = rangeStartDate; t < lastDate; t += duration.DAY) {
1453
- if (!isEnabled(new Date(t), true)) {
1454
- containsDisabled =
1455
- containsDisabled || (t > rangeStartDate && t < rangeEndDate);
1456
- if (t < initialDate && (!minRange || t > minRange))
1457
- minRange = t;
1458
- else if (t > initialDate && (!maxRange || t < maxRange))
1459
- maxRange = t;
1460
- }
1461
- }
1462
- for (let m = 0; m < self.config.showMonths; m++) {
1463
- const month = self.daysContainer.children[m];
1464
- const prevMonth = self.daysContainer.children[m - 1];
1465
- for (let i = 0, l = month.children.length; i < l; i++) {
1466
- const dayElem = month.children[i], date = dayElem.dateObj;
1467
- const timestamp = date.getTime();
1468
- const outOfRange = (minRange > 0 && timestamp < minRange) ||
1469
- (maxRange > 0 && timestamp > maxRange);
1470
- if (outOfRange) {
1471
- dayElem.classList.add("notAllowed");
1472
- ["inRange", "startRange", "endRange"].forEach(c => {
1473
- dayElem.classList.remove(c);
1474
- });
1475
- continue;
1476
- }
1477
- else if (containsDisabled && !outOfRange)
1478
- continue;
1479
- ["startRange", "inRange", "endRange", "notAllowed"].forEach(c => {
1480
- dayElem.classList.remove(c);
1481
- });
1482
- if (elem !== undefined) {
1483
- elem.classList.add(hoverDate < self.selectedDates[0].getTime()
1484
- ? "startRange"
1485
- : "endRange");
1486
- if (month.contains(elem) ||
1487
- !(m > 0 &&
1488
- prevMonth &&
1489
- prevMonth.lastChild.dateObj.getTime() >= timestamp)) {
1490
- if (initialDate < hoverDate && timestamp === initialDate)
1491
- dayElem.classList.add("startRange");
1492
- else if (initialDate > hoverDate && timestamp === initialDate)
1493
- dayElem.classList.add("endRange");
1494
- if (timestamp >= minRange &&
1495
- (maxRange === 0 || timestamp <= maxRange) &&
1496
- isBetween(timestamp, initialDate, hoverDate))
1497
- dayElem.classList.add("inRange");
1498
- }
1499
- }
1500
- }
1501
- }
726
+
727
+ if (self.daysContainer !== undefined) {
728
+ bind(self.monthNav, "mousedown", onClick(onMonthNavClick));
729
+ bind(self.monthNav, ["keyup", "increment"], onYearInput);
730
+ bind(self.daysContainer, "mousedown", onClick(selectDate));
1502
731
  }
1503
- function onResize() {
1504
- if (self.isOpen && !self.config.static && !self.config.inline)
1505
- positionCalendar();
732
+
733
+ if (self.timeContainer !== undefined && self.minuteElement !== undefined && self.hourElement !== undefined) {
734
+ var selText = function selText(e) {
735
+ return e.target.select();
736
+ };
737
+
738
+ bind(self.timeContainer, ["increment"], updateTime);
739
+ bind(self.timeContainer, "blur", updateTime, {
740
+ capture: true
741
+ });
742
+ bind(self.timeContainer, "mousedown", onClick(timeIncrement));
743
+ bind([self.hourElement, self.minuteElement], ["focus", "click"], selText);
744
+ if (self.secondElement !== undefined) bind(self.secondElement, "focus", function () {
745
+ return self.secondElement && self.secondElement.select();
746
+ });
747
+
748
+ if (self.amPM !== undefined) {
749
+ bind(self.amPM, "mousedown", onClick(function (e) {
750
+ updateTime(e);
751
+ triggerChange();
752
+ }));
753
+ }
754
+ }
755
+ }
756
+
757
+ function jumpToDate(jumpDate) {
758
+ var jumpTo = jumpDate !== undefined ? self.parseDate(jumpDate) : self.latestSelectedDateObj || (self.config.minDate && self.config.minDate > self.now ? self.config.minDate : self.config.maxDate && self.config.maxDate < self.now ? self.config.maxDate : self.now);
759
+
760
+ try {
761
+ if (jumpTo !== undefined) {
762
+ self.currentYear = jumpTo.getFullYear();
763
+ self.currentMonth = jumpTo.getMonth();
764
+ }
765
+ } catch (e) {
766
+ e.message = "Invalid date supplied: " + jumpTo;
767
+ self.config.errorHandler(e);
1506
768
  }
1507
- function open(e, positionElement = self._positionElement) {
1508
- if (self.isMobile === true) {
1509
- if (e) {
1510
- e.preventDefault();
1511
- e.target && e.target.blur();
1512
- }
1513
- if (self.mobileInput !== undefined) {
1514
- self.mobileInput.focus();
1515
- self.mobileInput.click();
1516
- }
1517
- triggerEvent("onOpen");
1518
- return;
1519
- }
1520
- if (self._input.disabled || self.config.inline)
1521
- return;
1522
- const wasOpen = self.isOpen;
1523
- self.isOpen = true;
1524
- if (!wasOpen) {
1525
- self.calendarContainer.classList.add("open");
1526
- self._input.classList.add("active");
1527
- triggerEvent("onOpen");
1528
- positionCalendar(positionElement);
1529
- }
1530
- if (self.config.enableTime === true && self.config.noCalendar === true) {
1531
- if (self.selectedDates.length === 0) {
1532
- self.setDate(self.config.minDate !== undefined
1533
- ? new Date(self.config.minDate.getTime())
1534
- : new Date(), false);
1535
- setDefaultHours();
1536
- updateValue();
1537
- }
1538
- if (self.config.allowInput === false &&
1539
- (e === undefined ||
1540
- !self.timeContainer.contains(e.relatedTarget))) {
1541
- setTimeout(() => self.hourElement.select(), 50);
1542
- }
1543
- }
769
+
770
+ self.redraw();
771
+ }
772
+
773
+ function timeIncrement(e) {
774
+ if (~e.target.className.indexOf("arrow")) incrementNumInput(e, e.target.classList.contains("arrowUp") ? 1 : -1);
775
+ }
776
+
777
+ function incrementNumInput(e, delta, inputElem) {
778
+ var target = e && e.target;
779
+ var input = inputElem || target && target.parentNode && target.parentNode.firstChild;
780
+ var event = createEvent("increment");
781
+ event.delta = delta;
782
+ input && input.dispatchEvent(event);
783
+ }
784
+
785
+ function build() {
786
+ var fragment = window.document.createDocumentFragment();
787
+ self.calendarContainer = createElement("div", "flatpickr-calendar");
788
+ self.calendarContainer.tabIndex = -1;
789
+
790
+ if (!self.config.noCalendar) {
791
+ fragment.appendChild(buildMonthNav());
792
+ self.innerContainer = createElement("div", "flatpickr-innerContainer");
793
+
794
+ if (self.config.weekNumbers) {
795
+ var _buildWeeks = buildWeeks(),
796
+ weekWrapper = _buildWeeks.weekWrapper,
797
+ weekNumbers = _buildWeeks.weekNumbers;
798
+
799
+ self.innerContainer.appendChild(weekWrapper);
800
+ self.weekNumbers = weekNumbers;
801
+ self.weekWrapper = weekWrapper;
802
+ }
803
+
804
+ self.rContainer = createElement("div", "flatpickr-rContainer");
805
+ self.rContainer.appendChild(buildWeekdays());
806
+
807
+ if (!self.daysContainer) {
808
+ self.daysContainer = createElement("div", "flatpickr-days");
809
+ self.daysContainer.tabIndex = -1;
810
+ }
811
+
812
+ buildDays();
813
+ self.rContainer.appendChild(self.daysContainer);
814
+ self.innerContainer.appendChild(self.rContainer);
815
+ fragment.appendChild(self.innerContainer);
1544
816
  }
1545
- function minMaxDateSetter(type) {
1546
- return (date) => {
1547
- const dateObj = (self.config[`_${type}Date`] = self.parseDate(date, self.config.dateFormat));
1548
- const inverseDateObj = self.config[`_${type === "min" ? "max" : "min"}Date`];
1549
- if (dateObj !== undefined) {
1550
- self[type === "min" ? "minDateHasTime" : "maxDateHasTime"] =
1551
- dateObj.getHours() > 0 ||
1552
- dateObj.getMinutes() > 0 ||
1553
- dateObj.getSeconds() > 0;
1554
- }
1555
- if (self.selectedDates) {
1556
- self.selectedDates = self.selectedDates.filter(d => isEnabled(d));
1557
- if (!self.selectedDates.length && type === "min")
1558
- setHoursFromDate(dateObj);
1559
- updateValue();
1560
- }
1561
- if (self.daysContainer) {
1562
- redraw();
1563
- if (dateObj !== undefined)
1564
- self.currentYearElement[type] = dateObj.getFullYear().toString();
1565
- else
1566
- self.currentYearElement.removeAttribute(type);
1567
- self.currentYearElement.disabled =
1568
- !!inverseDateObj &&
1569
- dateObj !== undefined &&
1570
- inverseDateObj.getFullYear() === dateObj.getFullYear();
1571
- }
1572
- };
1573
- }
1574
- function parseConfig() {
1575
- const boolOpts = [
1576
- "wrap",
1577
- "weekNumbers",
1578
- "allowInput",
1579
- "clickOpens",
1580
- "time_24hr",
1581
- "enableTime",
1582
- "noCalendar",
1583
- "altInput",
1584
- "shorthandCurrentMonth",
1585
- "inline",
1586
- "static",
1587
- "enableSeconds",
1588
- "disableMobile",
1589
- ];
1590
- const userConfig = Object.assign({}, instanceConfig, JSON.parse(JSON.stringify(element.dataset || {})));
1591
- const formats$$1 = {};
1592
- self.config.parseDate = userConfig.parseDate;
1593
- self.config.formatDate = userConfig.formatDate;
1594
- Object.defineProperty(self.config, "enable", {
1595
- get: () => self.config._enable,
1596
- set: dates => {
1597
- self.config._enable = parseDateRules(dates);
1598
- },
1599
- });
1600
- Object.defineProperty(self.config, "disable", {
1601
- get: () => self.config._disable,
1602
- set: dates => {
1603
- self.config._disable = parseDateRules(dates);
1604
- },
1605
- });
1606
- const timeMode = userConfig.mode === "time";
1607
- if (!userConfig.dateFormat && (userConfig.enableTime || timeMode)) {
1608
- formats$$1.dateFormat =
1609
- userConfig.noCalendar || timeMode
1610
- ? "H:i" + (userConfig.enableSeconds ? ":S" : "")
1611
- : flatpickr.defaultConfig.dateFormat +
1612
- " H:i" +
1613
- (userConfig.enableSeconds ? ":S" : "");
1614
- }
1615
- if (userConfig.altInput &&
1616
- (userConfig.enableTime || timeMode) &&
1617
- !userConfig.altFormat) {
1618
- formats$$1.altFormat =
1619
- userConfig.noCalendar || timeMode
1620
- ? "h:i" + (userConfig.enableSeconds ? ":S K" : " K")
1621
- : flatpickr.defaultConfig.altFormat +
1622
- ` h:i${userConfig.enableSeconds ? ":S" : ""} K`;
1623
- }
1624
- Object.defineProperty(self.config, "minDate", {
1625
- get: () => self.config._minDate,
1626
- set: minMaxDateSetter("min"),
1627
- });
1628
- Object.defineProperty(self.config, "maxDate", {
1629
- get: () => self.config._maxDate,
1630
- set: minMaxDateSetter("max"),
1631
- });
1632
- const minMaxTimeSetter = (type) => (val) => {
1633
- self.config[type === "min" ? "_minTime" : "_maxTime"] = self.parseDate(val, "H:i");
1634
- };
1635
- Object.defineProperty(self.config, "minTime", {
1636
- get: () => self.config._minTime,
1637
- set: minMaxTimeSetter("min"),
1638
- });
1639
- Object.defineProperty(self.config, "maxTime", {
1640
- get: () => self.config._maxTime,
1641
- set: minMaxTimeSetter("max"),
1642
- });
1643
- if (userConfig.mode === "time") {
1644
- self.config.noCalendar = true;
1645
- self.config.enableTime = true;
1646
- }
1647
- Object.assign(self.config, formats$$1, userConfig);
1648
- for (let i = 0; i < boolOpts.length; i++)
1649
- self.config[boolOpts[i]] =
1650
- self.config[boolOpts[i]] === true ||
1651
- self.config[boolOpts[i]] === "true";
1652
- HOOKS.filter(hook => self.config[hook] !== undefined).forEach(hook => {
1653
- self.config[hook] = arrayify(self.config[hook] || []).map(bindToInstance);
1654
- });
1655
- self.isMobile =
1656
- !self.config.disableMobile &&
1657
- !self.config.inline &&
1658
- self.config.mode === "single" &&
1659
- !self.config.disable.length &&
1660
- !self.config.enable.length &&
1661
- !self.config.weekNumbers &&
1662
- /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
1663
- for (let i = 0; i < self.config.plugins.length; i++) {
1664
- const pluginConf = self.config.plugins[i](self) || {};
1665
- for (const key in pluginConf) {
1666
- if (HOOKS.indexOf(key) > -1) {
1667
- self.config[key] = arrayify(pluginConf[key])
1668
- .map(bindToInstance)
1669
- .concat(self.config[key]);
1670
- }
1671
- else if (typeof userConfig[key] === "undefined")
1672
- self.config[key] = pluginConf[key];
1673
- }
1674
- }
1675
- triggerEvent("onParseConfig");
1676
- }
1677
- function setupLocale() {
1678
- if (typeof self.config.locale !== "object" &&
1679
- typeof flatpickr.l10ns[self.config.locale] === "undefined")
1680
- self.config.errorHandler(new Error(`flatpickr: invalid locale ${self.config.locale}`));
1681
- self.l10n = Object.assign({}, flatpickr.l10ns.default, (typeof self.config.locale === "object"
1682
- ? self.config.locale
1683
- : self.config.locale !== "default"
1684
- ? flatpickr.l10ns[self.config.locale]
1685
- : undefined));
1686
- tokenRegex.K = `(${self.l10n.amPM[0]}|${self.l10n.amPM[1]}|${self.l10n.amPM[0].toLowerCase()}|${self.l10n.amPM[1].toLowerCase()})`;
1687
- self.formatDate = createDateFormatter(self);
1688
- self.parseDate = createDateParser({ config: self.config, l10n: self.l10n });
1689
- }
1690
- function positionCalendar(customPositionElement) {
1691
- if (self.calendarContainer === undefined)
1692
- return;
1693
- triggerEvent("onPreCalendarPosition");
1694
- const positionElement = customPositionElement || self._positionElement;
1695
- const calendarHeight = Array.prototype.reduce.call(self.calendarContainer.children, (acc, child) => 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" ||
1696
- (configPosVertical !== "below" &&
1697
- distanceFromBottom < calendarHeight &&
1698
- inputBounds.top > calendarHeight);
1699
- let top = window.pageYOffset +
1700
- inputBounds.top +
1701
- (!showOnTop ? positionElement.offsetHeight + 2 : -calendarHeight - 2);
1702
- toggleClass(self.calendarContainer, "arrowTop", !showOnTop);
1703
- toggleClass(self.calendarContainer, "arrowBottom", showOnTop);
1704
- if (self.config.inline)
1705
- return;
1706
- const left = window.pageXOffset +
1707
- inputBounds.left -
1708
- (configPosHorizontal != null && configPosHorizontal === "center"
1709
- ? (calendarWidth - inputBounds.width) / 2
1710
- : 0);
1711
- const right = window.document.body.offsetWidth - inputBounds.right;
1712
- const rightMost = left + calendarWidth > window.document.body.offsetWidth;
1713
- toggleClass(self.calendarContainer, "rightMost", rightMost);
1714
- if (self.config.static)
1715
- return;
1716
- self.calendarContainer.style.top = `${top}px`;
1717
- if (!rightMost) {
1718
- self.calendarContainer.style.left = `${left}px`;
1719
- self.calendarContainer.style.right = "auto";
1720
- }
1721
- else {
1722
- self.calendarContainer.style.left = "auto";
1723
- self.calendarContainer.style.right = `${right}px`;
1724
- }
817
+
818
+ if (self.config.enableTime) {
819
+ fragment.appendChild(buildTime());
1725
820
  }
1726
- function redraw() {
1727
- if (self.config.noCalendar || self.isMobile)
1728
- return;
1729
- updateNavigationCurrentMonth();
1730
- buildDays();
1731
- }
1732
- function focusAndClose() {
1733
- self._input.focus();
1734
- if (window.navigator.userAgent.indexOf("MSIE") !== -1 ||
1735
- navigator.msMaxTouchPoints !== undefined) {
1736
- setTimeout(self.close, 0);
1737
- }
1738
- else {
1739
- self.close();
1740
- }
821
+
822
+ toggleClass(self.calendarContainer, "rangeMode", self.config.mode === "range");
823
+ toggleClass(self.calendarContainer, "animate", self.config.animate === true);
824
+ toggleClass(self.calendarContainer, "multiMonth", self.config.showMonths > 1);
825
+ self.calendarContainer.appendChild(fragment);
826
+ var customAppend = self.config.appendTo !== undefined && self.config.appendTo.nodeType !== undefined;
827
+
828
+ if (self.config.inline || self.config.static) {
829
+ self.calendarContainer.classList.add(self.config.inline ? "inline" : "static");
830
+
831
+ if (self.config.inline) {
832
+ if (!customAppend && self.element.parentNode) self.element.parentNode.insertBefore(self.calendarContainer, self._input.nextSibling);else if (self.config.appendTo !== undefined) self.config.appendTo.appendChild(self.calendarContainer);
833
+ }
834
+
835
+ if (self.config.static) {
836
+ var wrapper = createElement("div", "flatpickr-wrapper");
837
+ if (self.element.parentNode) self.element.parentNode.insertBefore(wrapper, self.element);
838
+ wrapper.appendChild(self.element);
839
+ if (self.altInput) wrapper.appendChild(self.altInput);
840
+ wrapper.appendChild(self.calendarContainer);
841
+ }
1741
842
  }
1742
- function selectDate(e) {
1743
- e.preventDefault();
1744
- e.stopPropagation();
1745
- const isSelectable = (day) => day.classList &&
1746
- day.classList.contains("flatpickr-day") &&
1747
- !day.classList.contains("disabled") &&
1748
- !day.classList.contains("notAllowed");
1749
- const t = findParent(e.target, isSelectable);
1750
- if (t === undefined)
1751
- return;
1752
- const target = t;
1753
- const selectedDate = (self.latestSelectedDateObj = new Date(target.dateObj.getTime()));
1754
- const shouldChangeMonth = (selectedDate.getMonth() < self.currentMonth ||
1755
- selectedDate.getMonth() >
1756
- self.currentMonth + self.config.showMonths - 1) &&
1757
- self.config.mode !== "range";
1758
- self.selectedDateElem = target;
1759
- if (self.config.mode === "single")
1760
- self.selectedDates = [selectedDate];
1761
- else if (self.config.mode === "multiple") {
1762
- const selectedIndex = isDateSelected(selectedDate);
1763
- if (selectedIndex)
1764
- self.selectedDates.splice(parseInt(selectedIndex), 1);
1765
- else
1766
- self.selectedDates.push(selectedDate);
1767
- }
1768
- else if (self.config.mode === "range") {
1769
- if (self.selectedDates.length === 2)
1770
- self.clear(false);
1771
- self.selectedDates.push(selectedDate);
1772
- if (compareDates(selectedDate, self.selectedDates[0], true) !== 0)
1773
- self.selectedDates.sort((a, b) => a.getTime() - b.getTime());
1774
- }
1775
- setHoursFromInputs();
1776
- if (shouldChangeMonth) {
1777
- const isNewYear = self.currentYear !== selectedDate.getFullYear();
1778
- self.currentYear = selectedDate.getFullYear();
1779
- self.currentMonth = selectedDate.getMonth();
1780
- if (isNewYear)
1781
- triggerEvent("onYearChange");
1782
- triggerEvent("onMonthChange");
1783
- }
1784
- updateNavigationCurrentMonth();
1785
- buildDays();
1786
- updateValue();
1787
- if (self.config.enableTime)
1788
- setTimeout(() => (self.showTimeInput = true), 50);
1789
- if (!shouldChangeMonth &&
1790
- self.config.mode !== "range" &&
1791
- self.config.showMonths === 1)
1792
- focusOnDayElem(target);
1793
- else
1794
- self.selectedDateElem && self.selectedDateElem.focus();
1795
- if (self.hourElement !== undefined)
1796
- setTimeout(() => self.hourElement !== undefined && self.hourElement.select(), 451);
1797
- if (self.config.closeOnSelect) {
1798
- const single = self.config.mode === "single" && !self.config.enableTime;
1799
- const range = self.config.mode === "range" &&
1800
- self.selectedDates.length === 2 &&
1801
- !self.config.enableTime;
1802
- if (single || range) {
1803
- focusAndClose();
1804
- }
1805
- }
1806
- triggerChange();
843
+
844
+ if (!self.config.static && !self.config.inline) (self.config.appendTo !== undefined ? self.config.appendTo : window.document.body).appendChild(self.calendarContainer);
845
+ }
846
+
847
+ function createDay(className, date, dayNumber, i) {
848
+ var dateIsEnabled = isEnabled(date, true),
849
+ dayElement = createElement("span", "flatpickr-day " + className, date.getDate().toString());
850
+ dayElement.dateObj = date;
851
+ dayElement.$i = i;
852
+ dayElement.setAttribute("aria-label", self.formatDate(date, self.config.ariaDateFormat));
853
+
854
+ if (className.indexOf("hidden") === -1 && compareDates(date, self.now) === 0) {
855
+ self.todayDateElem = dayElement;
856
+ dayElement.classList.add("today");
857
+ dayElement.setAttribute("aria-current", "date");
1807
858
  }
1808
- const CALLBACKS = {
1809
- locale: [setupLocale, updateWeekdays],
1810
- showMonths: [buildMonths, setCalendarWidth, buildWeekdays],
1811
- };
1812
- function set(option, value) {
1813
- if (option !== null && typeof option === "object")
1814
- Object.assign(self.config, option);
1815
- else {
1816
- self.config[option] = value;
1817
- if (CALLBACKS[option] !== undefined)
1818
- CALLBACKS[option].forEach(x => x());
1819
- else if (HOOKS.indexOf(option) > -1)
1820
- self.config[option] = arrayify(value);
1821
- }
1822
- self.redraw();
1823
- jumpToDate();
1824
- updateValue(false);
1825
- }
1826
- function setSelectedDate(inputDate, format) {
1827
- let dates = [];
1828
- if (inputDate instanceof Array)
1829
- dates = inputDate.map(d => self.parseDate(d, format));
1830
- else if (inputDate instanceof Date || typeof inputDate === "number")
1831
- dates = [self.parseDate(inputDate, format)];
1832
- else if (typeof inputDate === "string") {
1833
- switch (self.config.mode) {
1834
- case "single":
1835
- case "time":
1836
- dates = [self.parseDate(inputDate, format)];
1837
- break;
1838
- case "multiple":
1839
- dates = inputDate
1840
- .split(self.config.conjunction)
1841
- .map(date => self.parseDate(date, format));
1842
- break;
1843
- case "range":
1844
- dates = inputDate
1845
- .split(self.l10n.rangeSeparator)
1846
- .map(date => self.parseDate(date, format));
1847
- break;
1848
- default:
1849
- break;
1850
- }
859
+
860
+ if (dateIsEnabled) {
861
+ dayElement.tabIndex = -1;
862
+
863
+ if (isDateSelected(date)) {
864
+ dayElement.classList.add("selected");
865
+ self.selectedDateElem = dayElement;
866
+
867
+ if (self.config.mode === "range") {
868
+ toggleClass(dayElement, "startRange", self.selectedDates[0] && compareDates(date, self.selectedDates[0], true) === 0);
869
+ toggleClass(dayElement, "endRange", self.selectedDates[1] && compareDates(date, self.selectedDates[1], true) === 0);
870
+ if (className === "nextMonthDay") dayElement.classList.add("inRange");
1851
871
  }
1852
- else
1853
- self.config.errorHandler(new Error(`Invalid date supplied: ${JSON.stringify(inputDate)}`));
1854
- self.selectedDates = dates.filter(d => d instanceof Date && isEnabled(d, false));
1855
- if (self.config.mode === "range")
1856
- self.selectedDates.sort((a, b) => a.getTime() - b.getTime());
1857
- }
1858
- function setDate(date, triggerChange = false, format = self.config.dateFormat) {
1859
- if ((date !== 0 && !date) || (date instanceof Array && date.length === 0))
1860
- return self.clear(triggerChange);
1861
- setSelectedDate(date, format);
1862
- self.showTimeInput = self.selectedDates.length > 0;
1863
- self.latestSelectedDateObj = self.selectedDates[0];
1864
- self.redraw();
1865
- jumpToDate();
1866
- setHoursFromDate();
1867
- updateValue(triggerChange);
1868
- if (triggerChange)
1869
- triggerEvent("onChange");
1870
- }
1871
- function parseDateRules(arr) {
1872
- return arr
1873
- .slice()
1874
- .map(rule => {
1875
- if (typeof rule === "string" ||
1876
- typeof rule === "number" ||
1877
- rule instanceof Date) {
1878
- return self.parseDate(rule, undefined, true);
1879
- }
1880
- else if (rule &&
1881
- typeof rule === "object" &&
1882
- rule.from &&
1883
- rule.to)
1884
- return {
1885
- from: self.parseDate(rule.from, undefined),
1886
- to: self.parseDate(rule.to, undefined),
1887
- };
1888
- return rule;
1889
- })
1890
- .filter(x => x);
1891
- }
1892
- function setupDates() {
1893
- self.selectedDates = [];
1894
- self.now = self.parseDate(self.config.now) || new Date();
1895
- const preloadedDate = self.config.defaultDate ||
1896
- ((self.input.nodeName === "INPUT" ||
1897
- self.input.nodeName === "TEXTAREA") &&
1898
- self.input.placeholder &&
1899
- self.input.value === self.input.placeholder
1900
- ? null
1901
- : self.input.value);
1902
- if (preloadedDate)
1903
- setSelectedDate(preloadedDate, self.config.dateFormat);
1904
- const initialDate = self.selectedDates.length > 0
1905
- ? self.selectedDates[0]
1906
- : self.config.minDate &&
1907
- self.config.minDate.getTime() > self.now.getTime()
1908
- ? self.config.minDate
1909
- : self.config.maxDate &&
1910
- self.config.maxDate.getTime() < self.now.getTime()
1911
- ? self.config.maxDate
1912
- : self.now;
1913
- self.currentYear = initialDate.getFullYear();
1914
- self.currentMonth = initialDate.getMonth();
1915
- if (self.selectedDates.length > 0)
1916
- self.latestSelectedDateObj = self.selectedDates[0];
1917
- if (self.config.minTime !== undefined)
1918
- self.config.minTime = self.parseDate(self.config.minTime, "H:i");
1919
- if (self.config.maxTime !== undefined)
1920
- self.config.maxTime = self.parseDate(self.config.maxTime, "H:i");
1921
- self.minDateHasTime =
1922
- !!self.config.minDate &&
1923
- (self.config.minDate.getHours() > 0 ||
1924
- self.config.minDate.getMinutes() > 0 ||
1925
- self.config.minDate.getSeconds() > 0);
1926
- self.maxDateHasTime =
1927
- !!self.config.maxDate &&
1928
- (self.config.maxDate.getHours() > 0 ||
1929
- self.config.maxDate.getMinutes() > 0 ||
1930
- self.config.maxDate.getSeconds() > 0);
1931
- Object.defineProperty(self, "showTimeInput", {
1932
- get: () => self._showTimeInput,
1933
- set(bool) {
1934
- self._showTimeInput = bool;
1935
- if (self.calendarContainer)
1936
- toggleClass(self.calendarContainer, "showTimeInput", bool);
1937
- self.isOpen && positionCalendar();
1938
- },
1939
- });
872
+ }
873
+ } else {
874
+ dayElement.classList.add("disabled");
1940
875
  }
1941
- function setupInputs() {
1942
- self.input = self.config.wrap
1943
- ? element.querySelector("[data-input]")
1944
- : element;
1945
- if (!self.input) {
1946
- self.config.errorHandler(new Error("Invalid input element specified"));
1947
- return;
1948
- }
1949
- self.input._type = self.input.type;
1950
- self.input.type = "text";
1951
- self.input.classList.add("flatpickr-input");
1952
- self._input = self.input;
1953
- if (self.config.altInput) {
1954
- self.altInput = createElement(self.input.nodeName, self.input.className + " " + self.config.altInputClass);
1955
- self._input = self.altInput;
1956
- self.altInput.placeholder = self.input.placeholder;
1957
- self.altInput.disabled = self.input.disabled;
1958
- self.altInput.required = self.input.required;
1959
- self.altInput.tabIndex = self.input.tabIndex;
1960
- self.altInput.type = "text";
1961
- self.input.setAttribute("type", "hidden");
1962
- if (!self.config.static && self.input.parentNode)
1963
- self.input.parentNode.insertBefore(self.altInput, self.input.nextSibling);
1964
- }
1965
- if (!self.config.allowInput)
1966
- self._input.setAttribute("readonly", "readonly");
1967
- self._positionElement = self.config.positionElement || self._input;
1968
- }
1969
- function setupMobile() {
1970
- const inputType = self.config.enableTime
1971
- ? self.config.noCalendar
1972
- ? "time"
1973
- : "datetime-local"
1974
- : "date";
1975
- self.mobileInput = createElement("input", self.input.className + " flatpickr-mobile");
1976
- self.mobileInput.step = self.input.getAttribute("step") || "any";
1977
- self.mobileInput.tabIndex = 1;
1978
- self.mobileInput.type = inputType;
1979
- self.mobileInput.disabled = self.input.disabled;
1980
- self.mobileInput.required = self.input.required;
1981
- self.mobileInput.placeholder = self.input.placeholder;
1982
- self.mobileFormatStr =
1983
- inputType === "datetime-local"
1984
- ? "Y-m-d\\TH:i:S"
1985
- : inputType === "date"
1986
- ? "Y-m-d"
1987
- : "H:i:S";
1988
- if (self.selectedDates.length > 0) {
1989
- self.mobileInput.defaultValue = self.mobileInput.value = self.formatDate(self.selectedDates[0], self.mobileFormatStr);
1990
- }
1991
- if (self.config.minDate)
1992
- self.mobileInput.min = self.formatDate(self.config.minDate, "Y-m-d");
1993
- if (self.config.maxDate)
1994
- self.mobileInput.max = self.formatDate(self.config.maxDate, "Y-m-d");
1995
- self.input.type = "hidden";
1996
- if (self.altInput !== undefined)
1997
- self.altInput.type = "hidden";
1998
- try {
1999
- if (self.input.parentNode)
2000
- self.input.parentNode.insertBefore(self.mobileInput, self.input.nextSibling);
2001
- }
2002
- catch (_a) { }
2003
- bind(self.mobileInput, "change", (e) => {
2004
- self.setDate(e.target.value, false, self.mobileFormatStr);
2005
- triggerEvent("onChange");
2006
- triggerEvent("onClose");
2007
- });
876
+
877
+ if (self.config.mode === "range") {
878
+ if (isDateInRange(date) && !isDateSelected(date)) dayElement.classList.add("inRange");
2008
879
  }
2009
- function toggle(e) {
2010
- if (self.isOpen === true)
2011
- return self.close();
2012
- self.open(e);
2013
- }
2014
- function triggerEvent(event, data) {
2015
- if (self.config === undefined)
2016
- return;
2017
- const hooks = self.config[event];
2018
- if (hooks !== undefined && hooks.length > 0) {
2019
- for (let i = 0; hooks[i] && i < hooks.length; i++)
2020
- hooks[i](self.selectedDates, self.input.value, self, data);
2021
- }
2022
- if (event === "onChange") {
2023
- self.input.dispatchEvent(createEvent("change"));
2024
- self.input.dispatchEvent(createEvent("input"));
2025
- }
880
+
881
+ if (self.weekNumbers && self.config.showMonths === 1 && className !== "prevMonthDay" && dayNumber % 7 === 1) {
882
+ self.weekNumbers.insertAdjacentHTML("beforeend", "<span class='flatpickr-day'>" + self.config.getWeek(date) + "</span>");
2026
883
  }
2027
- function createEvent(name) {
2028
- const e = document.createEvent("Event");
2029
- e.initEvent(name, true, true);
2030
- return e;
884
+
885
+ triggerEvent("onDayCreate", dayElement);
886
+ return dayElement;
887
+ }
888
+
889
+ function focusOnDayElem(targetNode) {
890
+ targetNode.focus();
891
+ if (self.config.mode === "range") onMouseOver(targetNode);
892
+ }
893
+
894
+ function getFirstAvailableDay(delta) {
895
+ var startMonth = delta > 0 ? 0 : self.config.showMonths - 1;
896
+ var endMonth = delta > 0 ? self.config.showMonths : -1;
897
+
898
+ for (var m = startMonth; m != endMonth; m += delta) {
899
+ var month = self.daysContainer.children[m];
900
+ var startIndex = delta > 0 ? 0 : month.children.length - 1;
901
+ var endIndex = delta > 0 ? month.children.length : -1;
902
+
903
+ for (var i = startIndex; i != endIndex; i += delta) {
904
+ var c = month.children[i];
905
+ if (c.className.indexOf("hidden") === -1 && isEnabled(c.dateObj)) return c;
906
+ }
2031
907
  }
2032
- function isDateSelected(date) {
2033
- for (let i = 0; i < self.selectedDates.length; i++) {
2034
- if (compareDates(self.selectedDates[i], date) === 0)
2035
- return "" + i;
2036
- }
2037
- return false;
2038
- }
2039
- function isDateInRange(date) {
2040
- if (self.config.mode !== "range" || self.selectedDates.length < 2)
2041
- return false;
2042
- return (compareDates(date, self.selectedDates[0]) >= 0 &&
2043
- compareDates(date, self.selectedDates[1]) <= 0);
2044
- }
2045
- function updateNavigationCurrentMonth() {
2046
- if (self.config.noCalendar || self.isMobile || !self.monthNav)
2047
- return;
2048
- self.yearElements.forEach((yearElement, i) => {
2049
- const d = new Date(self.currentYear, self.currentMonth, 1);
2050
- d.setMonth(self.currentMonth + i);
2051
- self.monthElements[i].textContent =
2052
- monthToStr(d.getMonth(), self.config.shorthandCurrentMonth, self.l10n) +
2053
- " ";
2054
- yearElement.value = d.getFullYear().toString();
2055
- });
2056
- self._hidePrevMonthArrow =
2057
- self.config.minDate !== undefined &&
2058
- (self.currentYear === self.config.minDate.getFullYear()
2059
- ? self.currentMonth <= self.config.minDate.getMonth()
2060
- : self.currentYear < self.config.minDate.getFullYear());
2061
- self._hideNextMonthArrow =
2062
- self.config.maxDate !== undefined &&
2063
- (self.currentYear === self.config.maxDate.getFullYear()
2064
- ? self.currentMonth + 1 > self.config.maxDate.getMonth()
2065
- : self.currentYear > self.config.maxDate.getFullYear());
2066
- }
2067
- function getDateStr(format) {
2068
- return self.selectedDates
2069
- .map(dObj => self.formatDate(dObj, format))
2070
- .filter((d, i, arr) => self.config.mode !== "range" ||
2071
- self.config.enableTime ||
2072
- arr.indexOf(d) === i)
2073
- .join(self.config.mode !== "range"
2074
- ? self.config.conjunction
2075
- : self.l10n.rangeSeparator);
2076
- }
2077
- function updateValue(triggerChange = true) {
2078
- if (self.selectedDates.length === 0)
2079
- return self.clear(triggerChange);
2080
- if (self.mobileInput !== undefined && self.mobileFormatStr) {
2081
- self.mobileInput.value =
2082
- self.latestSelectedDateObj !== undefined
2083
- ? self.formatDate(self.latestSelectedDateObj, self.mobileFormatStr)
2084
- : "";
2085
- }
2086
- self.input.value = getDateStr(self.config.dateFormat);
2087
- if (self.altInput !== undefined) {
2088
- self.altInput.value = getDateStr(self.config.altFormat);
2089
- }
2090
- if (triggerChange !== false)
2091
- triggerEvent("onValueUpdate");
908
+
909
+ return undefined;
910
+ }
911
+
912
+ function getNextAvailableDay(current, delta) {
913
+ var givenMonth = current.className.indexOf("Month") === -1 ? current.dateObj.getMonth() : self.currentMonth;
914
+ var endMonth = delta > 0 ? self.config.showMonths : -1;
915
+ var loopDelta = delta > 0 ? 1 : -1;
916
+
917
+ for (var m = givenMonth - self.currentMonth; m != endMonth; m += loopDelta) {
918
+ var month = self.daysContainer.children[m];
919
+ var startIndex = givenMonth - self.currentMonth === m ? current.$i + delta : delta < 0 ? month.children.length - 1 : 0;
920
+ var numMonthDays = month.children.length;
921
+
922
+ for (var i = startIndex; i >= 0 && i < numMonthDays && i != (delta > 0 ? numMonthDays : -1); i += loopDelta) {
923
+ var c = month.children[i];
924
+ if (c.className.indexOf("hidden") === -1 && isEnabled(c.dateObj) && Math.abs(current.$i - i) >= Math.abs(delta)) return focusOnDayElem(c);
925
+ }
2092
926
  }
2093
- function onMonthNavClick(e) {
2094
- e.preventDefault();
2095
- const isPrevMonth = self.prevMonthNav.contains(e.target);
2096
- const isNextMonth = self.nextMonthNav.contains(e.target);
2097
- if (isPrevMonth || isNextMonth) {
2098
- changeMonth(isPrevMonth ? -1 : 1);
2099
- }
2100
- else if (self.yearElements.indexOf(e.target) >= 0) {
2101
- e.target.select();
2102
- }
2103
- else if (e.target.classList.contains("arrowUp")) {
2104
- self.changeYear(self.currentYear + 1);
2105
- }
2106
- else if (e.target.classList.contains("arrowDown")) {
2107
- self.changeYear(self.currentYear - 1);
927
+
928
+ self.changeMonth(loopDelta);
929
+ focusOnDay(getFirstAvailableDay(loopDelta), 0);
930
+ return undefined;
931
+ }
932
+
933
+ function focusOnDay(current, offset) {
934
+ var dayFocused = isInView(document.activeElement || document.body);
935
+ var startElem = current !== undefined ? current : dayFocused ? document.activeElement : self.selectedDateElem !== undefined && isInView(self.selectedDateElem) ? self.selectedDateElem : self.todayDateElem !== undefined && isInView(self.todayDateElem) ? self.todayDateElem : getFirstAvailableDay(offset > 0 ? 1 : -1);
936
+ if (startElem === undefined) return self._input.focus();
937
+ if (!dayFocused) return focusOnDayElem(startElem);
938
+ getNextAvailableDay(startElem, offset);
939
+ }
940
+
941
+ function buildMonthDays(year, month) {
942
+ var firstOfMonth = (new Date(year, month, 1).getDay() - self.l10n.firstDayOfWeek + 7) % 7;
943
+ var prevMonthDays = self.utils.getDaysInMonth((month - 1 + 12) % 12);
944
+ var daysInMonth = self.utils.getDaysInMonth(month),
945
+ days = window.document.createDocumentFragment(),
946
+ isMultiMonth = self.config.showMonths > 1,
947
+ prevMonthDayClass = isMultiMonth ? "prevMonthDay hidden" : "prevMonthDay",
948
+ nextMonthDayClass = isMultiMonth ? "nextMonthDay hidden" : "nextMonthDay";
949
+ var dayNumber = prevMonthDays + 1 - firstOfMonth,
950
+ dayIndex = 0;
951
+
952
+ for (; dayNumber <= prevMonthDays; dayNumber++, dayIndex++) {
953
+ days.appendChild(createDay(prevMonthDayClass, new Date(year, month - 1, dayNumber), dayNumber, dayIndex));
954
+ }
955
+
956
+ for (dayNumber = 1; dayNumber <= daysInMonth; dayNumber++, dayIndex++) {
957
+ days.appendChild(createDay("", new Date(year, month, dayNumber), dayNumber, dayIndex));
958
+ }
959
+
960
+ for (var dayNum = daysInMonth + 1; dayNum <= 42 - firstOfMonth && (self.config.showMonths === 1 || dayIndex % 7 !== 0); dayNum++, dayIndex++) {
961
+ days.appendChild(createDay(nextMonthDayClass, new Date(year, month + 1, dayNum % daysInMonth), dayNum, dayIndex));
962
+ }
963
+
964
+ var dayContainer = createElement("div", "dayContainer");
965
+ dayContainer.appendChild(days);
966
+ return dayContainer;
967
+ }
968
+
969
+ function buildDays() {
970
+ if (self.daysContainer === undefined) {
971
+ return;
972
+ }
973
+
974
+ clearNode(self.daysContainer);
975
+ if (self.weekNumbers) clearNode(self.weekNumbers);
976
+ var frag = document.createDocumentFragment();
977
+
978
+ for (var i = 0; i < self.config.showMonths; i++) {
979
+ var d = new Date(self.currentYear, self.currentMonth, 1);
980
+ d.setMonth(self.currentMonth + i);
981
+ frag.appendChild(buildMonthDays(d.getFullYear(), d.getMonth()));
982
+ }
983
+
984
+ self.daysContainer.appendChild(frag);
985
+ self.days = self.daysContainer.firstChild;
986
+
987
+ if (self.config.mode === "range" && self.selectedDates.length === 1) {
988
+ onMouseOver();
989
+ }
990
+ }
991
+
992
+ function buildMonth() {
993
+ var container = createElement("div", "flatpickr-month");
994
+ var monthNavFragment = window.document.createDocumentFragment();
995
+ var monthElement = createElement("span", "cur-month");
996
+ var yearInput = createNumberInput("cur-year", {
997
+ tabindex: "-1"
998
+ });
999
+ var yearElement = yearInput.getElementsByTagName("input")[0];
1000
+ yearElement.setAttribute("aria-label", self.l10n.yearAriaLabel);
1001
+ if (self.config.minDate) yearElement.setAttribute("data-min", self.config.minDate.getFullYear().toString());
1002
+
1003
+ if (self.config.maxDate) {
1004
+ yearElement.setAttribute("data-max", self.config.maxDate.getFullYear().toString());
1005
+ yearElement.disabled = !!self.config.minDate && self.config.minDate.getFullYear() === self.config.maxDate.getFullYear();
1006
+ }
1007
+
1008
+ var currentMonth = createElement("div", "flatpickr-current-month");
1009
+ currentMonth.appendChild(monthElement);
1010
+ currentMonth.appendChild(yearInput);
1011
+ monthNavFragment.appendChild(currentMonth);
1012
+ container.appendChild(monthNavFragment);
1013
+ return {
1014
+ container: container,
1015
+ yearElement: yearElement,
1016
+ monthElement: monthElement
1017
+ };
1018
+ }
1019
+
1020
+ function buildMonths() {
1021
+ clearNode(self.monthNav);
1022
+ self.monthNav.appendChild(self.prevMonthNav);
1023
+
1024
+ for (var m = self.config.showMonths; m--;) {
1025
+ var month = buildMonth();
1026
+ self.yearElements.push(month.yearElement);
1027
+ self.monthElements.push(month.monthElement);
1028
+ self.monthNav.appendChild(month.container);
1029
+ }
1030
+
1031
+ self.monthNav.appendChild(self.nextMonthNav);
1032
+ }
1033
+
1034
+ function buildMonthNav() {
1035
+ self.monthNav = createElement("div", "flatpickr-months");
1036
+ self.yearElements = [];
1037
+ self.monthElements = [];
1038
+ self.prevMonthNav = createElement("span", "flatpickr-prev-month");
1039
+ self.prevMonthNav.innerHTML = self.config.prevArrow;
1040
+ self.nextMonthNav = createElement("span", "flatpickr-next-month");
1041
+ self.nextMonthNav.innerHTML = self.config.nextArrow;
1042
+ buildMonths();
1043
+ Object.defineProperty(self, "_hidePrevMonthArrow", {
1044
+ get: function get() {
1045
+ return self.__hidePrevMonthArrow;
1046
+ },
1047
+ set: function set(bool) {
1048
+ if (self.__hidePrevMonthArrow !== bool) {
1049
+ toggleClass(self.prevMonthNav, "disabled", bool);
1050
+ self.__hidePrevMonthArrow = bool;
1051
+ }
1052
+ }
1053
+ });
1054
+ Object.defineProperty(self, "_hideNextMonthArrow", {
1055
+ get: function get() {
1056
+ return self.__hideNextMonthArrow;
1057
+ },
1058
+ set: function set(bool) {
1059
+ if (self.__hideNextMonthArrow !== bool) {
1060
+ toggleClass(self.nextMonthNav, "disabled", bool);
1061
+ self.__hideNextMonthArrow = bool;
1062
+ }
1063
+ }
1064
+ });
1065
+ self.currentYearElement = self.yearElements[0];
1066
+ updateNavigationCurrentMonth();
1067
+ return self.monthNav;
1068
+ }
1069
+
1070
+ function buildTime() {
1071
+ self.calendarContainer.classList.add("hasTime");
1072
+ if (self.config.noCalendar) self.calendarContainer.classList.add("noCalendar");
1073
+ self.timeContainer = createElement("div", "flatpickr-time");
1074
+ self.timeContainer.tabIndex = -1;
1075
+ var separator = createElement("span", "flatpickr-time-separator", ":");
1076
+ var hourInput = createNumberInput("flatpickr-hour");
1077
+ self.hourElement = hourInput.getElementsByTagName("input")[0];
1078
+ var minuteInput = createNumberInput("flatpickr-minute");
1079
+ self.minuteElement = minuteInput.getElementsByTagName("input")[0];
1080
+ self.hourElement.tabIndex = self.minuteElement.tabIndex = -1;
1081
+ self.hourElement.value = pad(self.latestSelectedDateObj ? self.latestSelectedDateObj.getHours() : self.config.time_24hr ? self.config.defaultHour : military2ampm(self.config.defaultHour));
1082
+ self.minuteElement.value = pad(self.latestSelectedDateObj ? self.latestSelectedDateObj.getMinutes() : self.config.defaultMinute);
1083
+ self.hourElement.setAttribute("data-step", self.config.hourIncrement.toString());
1084
+ self.minuteElement.setAttribute("data-step", self.config.minuteIncrement.toString());
1085
+ self.hourElement.setAttribute("data-min", self.config.time_24hr ? "0" : "1");
1086
+ self.hourElement.setAttribute("data-max", self.config.time_24hr ? "23" : "12");
1087
+ self.minuteElement.setAttribute("data-min", "0");
1088
+ self.minuteElement.setAttribute("data-max", "59");
1089
+ self.timeContainer.appendChild(hourInput);
1090
+ self.timeContainer.appendChild(separator);
1091
+ self.timeContainer.appendChild(minuteInput);
1092
+ if (self.config.time_24hr) self.timeContainer.classList.add("time24hr");
1093
+
1094
+ if (self.config.enableSeconds) {
1095
+ self.timeContainer.classList.add("hasSeconds");
1096
+ var secondInput = createNumberInput("flatpickr-second");
1097
+ self.secondElement = secondInput.getElementsByTagName("input")[0];
1098
+ self.secondElement.value = pad(self.latestSelectedDateObj ? self.latestSelectedDateObj.getSeconds() : self.config.defaultSeconds);
1099
+ self.secondElement.setAttribute("data-step", self.minuteElement.getAttribute("data-step"));
1100
+ self.secondElement.setAttribute("data-min", self.minuteElement.getAttribute("data-min"));
1101
+ self.secondElement.setAttribute("data-max", self.minuteElement.getAttribute("data-max"));
1102
+ self.timeContainer.appendChild(createElement("span", "flatpickr-time-separator", ":"));
1103
+ self.timeContainer.appendChild(secondInput);
1104
+ }
1105
+
1106
+ if (!self.config.time_24hr) {
1107
+ self.amPM = createElement("span", "flatpickr-am-pm", self.l10n.amPM[int((self.latestSelectedDateObj ? self.hourElement.value : self.config.defaultHour) > 11)]);
1108
+ self.amPM.title = self.l10n.toggleTitle;
1109
+ self.amPM.tabIndex = -1;
1110
+ self.timeContainer.appendChild(self.amPM);
1111
+ }
1112
+
1113
+ return self.timeContainer;
1114
+ }
1115
+
1116
+ function buildWeekdays() {
1117
+ if (!self.weekdayContainer) self.weekdayContainer = createElement("div", "flatpickr-weekdays");else clearNode(self.weekdayContainer);
1118
+
1119
+ for (var i = self.config.showMonths; i--;) {
1120
+ var container = createElement("div", "flatpickr-weekdaycontainer");
1121
+ self.weekdayContainer.appendChild(container);
1122
+ }
1123
+
1124
+ updateWeekdays();
1125
+ return self.weekdayContainer;
1126
+ }
1127
+
1128
+ function updateWeekdays() {
1129
+ var firstDayOfWeek = self.l10n.firstDayOfWeek;
1130
+ var weekdays = self.l10n.weekdays.shorthand.concat();
1131
+
1132
+ if (firstDayOfWeek > 0 && firstDayOfWeek < weekdays.length) {
1133
+ weekdays = weekdays.splice(firstDayOfWeek, weekdays.length).concat(weekdays.splice(0, firstDayOfWeek));
1134
+ }
1135
+
1136
+ for (var i = self.config.showMonths; i--;) {
1137
+ self.weekdayContainer.children[i].innerHTML = "\n <span class=flatpickr-weekday>\n " + weekdays.join("</span><span class=flatpickr-weekday>") + "\n </span>\n ";
1138
+ }
1139
+ }
1140
+
1141
+ function buildWeeks() {
1142
+ self.calendarContainer.classList.add("hasWeeks");
1143
+ var weekWrapper = createElement("div", "flatpickr-weekwrapper");
1144
+ weekWrapper.appendChild(createElement("span", "flatpickr-weekday", self.l10n.weekAbbreviation));
1145
+ var weekNumbers = createElement("div", "flatpickr-weeks");
1146
+ weekWrapper.appendChild(weekNumbers);
1147
+ return {
1148
+ weekWrapper: weekWrapper,
1149
+ weekNumbers: weekNumbers
1150
+ };
1151
+ }
1152
+
1153
+ function changeMonth(value, is_offset) {
1154
+ if (is_offset === void 0) {
1155
+ is_offset = true;
1156
+ }
1157
+
1158
+ var delta = is_offset ? value : value - self.currentMonth;
1159
+ if (delta < 0 && self._hidePrevMonthArrow === true || delta > 0 && self._hideNextMonthArrow === true) return;
1160
+ self.currentMonth += delta;
1161
+
1162
+ if (self.currentMonth < 0 || self.currentMonth > 11) {
1163
+ self.currentYear += self.currentMonth > 11 ? 1 : -1;
1164
+ self.currentMonth = (self.currentMonth + 12) % 12;
1165
+ triggerEvent("onYearChange");
1166
+ }
1167
+
1168
+ buildDays();
1169
+ triggerEvent("onMonthChange");
1170
+ updateNavigationCurrentMonth();
1171
+ }
1172
+
1173
+ function clear(triggerChangeEvent) {
1174
+ if (triggerChangeEvent === void 0) {
1175
+ triggerChangeEvent = true;
1176
+ }
1177
+
1178
+ self.input.value = "";
1179
+ if (self.altInput !== undefined) self.altInput.value = "";
1180
+ if (self.mobileInput !== undefined) self.mobileInput.value = "";
1181
+ self.selectedDates = [];
1182
+ self.latestSelectedDateObj = undefined;
1183
+ self.showTimeInput = false;
1184
+
1185
+ if (self.config.enableTime === true) {
1186
+ setDefaultHours();
1187
+ }
1188
+
1189
+ self.redraw();
1190
+ if (triggerChangeEvent) triggerEvent("onChange");
1191
+ }
1192
+
1193
+ function close() {
1194
+ self.isOpen = false;
1195
+
1196
+ if (!self.isMobile) {
1197
+ self.calendarContainer.classList.remove("open");
1198
+
1199
+ self._input.classList.remove("active");
1200
+ }
1201
+
1202
+ triggerEvent("onClose");
1203
+ }
1204
+
1205
+ function destroy() {
1206
+ if (self.config !== undefined) triggerEvent("onDestroy");
1207
+
1208
+ for (var i = self._handlers.length; i--;) {
1209
+ var h = self._handlers[i];
1210
+ h.element.removeEventListener(h.event, h.handler, h.options);
1211
+ }
1212
+
1213
+ self._handlers = [];
1214
+
1215
+ if (self.mobileInput) {
1216
+ if (self.mobileInput.parentNode) self.mobileInput.parentNode.removeChild(self.mobileInput);
1217
+ self.mobileInput = undefined;
1218
+ } else if (self.calendarContainer && self.calendarContainer.parentNode) {
1219
+ if (self.config.static && self.calendarContainer.parentNode) {
1220
+ var wrapper = self.calendarContainer.parentNode;
1221
+ wrapper.lastChild && wrapper.removeChild(wrapper.lastChild);
1222
+
1223
+ if (wrapper.parentNode) {
1224
+ while (wrapper.firstChild) {
1225
+ wrapper.parentNode.insertBefore(wrapper.firstChild, wrapper);
1226
+ }
1227
+
1228
+ wrapper.parentNode.removeChild(wrapper);
2108
1229
  }
1230
+ } else self.calendarContainer.parentNode.removeChild(self.calendarContainer);
2109
1231
  }
2110
- function timeWrapper(e) {
2111
- e.preventDefault();
2112
- const isKeyDown = e.type === "keydown", input = e.target;
2113
- if (self.amPM !== undefined && e.target === self.amPM) {
2114
- self.amPM.textContent =
2115
- self.l10n.amPM[int(self.amPM.textContent === self.l10n.amPM[0])];
1232
+
1233
+ if (self.altInput) {
1234
+ self.input.type = "text";
1235
+ if (self.altInput.parentNode) self.altInput.parentNode.removeChild(self.altInput);
1236
+ delete self.altInput;
1237
+ }
1238
+
1239
+ if (self.input) {
1240
+ self.input.type = self.input._type;
1241
+ self.input.classList.remove("flatpickr-input");
1242
+ self.input.removeAttribute("readonly");
1243
+ self.input.value = "";
1244
+ }
1245
+
1246
+ ["_showTimeInput", "latestSelectedDateObj", "_hideNextMonthArrow", "_hidePrevMonthArrow", "__hideNextMonthArrow", "__hidePrevMonthArrow", "isMobile", "isOpen", "selectedDateElem", "minDateHasTime", "maxDateHasTime", "days", "daysContainer", "_input", "_positionElement", "innerContainer", "rContainer", "monthNav", "todayDateElem", "calendarContainer", "weekdayContainer", "prevMonthNav", "nextMonthNav", "currentMonthElement", "currentYearElement", "navigationCurrentMonth", "selectedDateElem", "config"].forEach(function (k) {
1247
+ try {
1248
+ delete self[k];
1249
+ } catch (_) {}
1250
+ });
1251
+ }
1252
+
1253
+ function isCalendarElem(elem) {
1254
+ if (self.config.appendTo && self.config.appendTo.contains(elem)) return true;
1255
+ return self.calendarContainer.contains(elem);
1256
+ }
1257
+
1258
+ function documentClick(e) {
1259
+ if (self.isOpen && !self.config.inline) {
1260
+ var isCalendarElement = isCalendarElem(e.target);
1261
+ var isInput = e.target === self.input || e.target === self.altInput || self.element.contains(e.target) || e.path && e.path.indexOf && (~e.path.indexOf(self.input) || ~e.path.indexOf(self.altInput));
1262
+ var lostFocus = e.type === "blur" ? isInput && e.relatedTarget && !isCalendarElem(e.relatedTarget) : !isInput && !isCalendarElement;
1263
+ var isIgnored = !self.config.ignoredFocusElements.some(function (elem) {
1264
+ return elem.contains(e.target);
1265
+ });
1266
+
1267
+ if (lostFocus && isIgnored) {
1268
+ self.close();
1269
+
1270
+ if (self.config.mode === "range" && self.selectedDates.length === 1) {
1271
+ self.clear(false);
1272
+ self.redraw();
2116
1273
  }
2117
- const min = parseFloat(input.getAttribute("data-min")), max = parseFloat(input.getAttribute("data-max")), step = parseFloat(input.getAttribute("data-step")), curValue = parseInt(input.value, 10), delta = e.delta ||
2118
- (isKeyDown ? (e.which === 38 ? 1 : -1) : 0);
2119
- let newValue = curValue + step * delta;
2120
- if (typeof input.value !== "undefined" && input.value.length === 2) {
2121
- const isHourElem = input === self.hourElement, isMinuteElem = input === self.minuteElement;
2122
- if (newValue < min) {
2123
- newValue =
2124
- max +
2125
- newValue +
2126
- int(!isHourElem) +
2127
- (int(isHourElem) && int(!self.amPM));
2128
- if (isMinuteElem)
2129
- incrementNumInput(undefined, -1, self.hourElement);
2130
- }
2131
- else if (newValue > max) {
2132
- newValue =
2133
- input === self.hourElement ? newValue - max - int(!self.amPM) : min;
2134
- if (isMinuteElem)
2135
- incrementNumInput(undefined, 1, self.hourElement);
1274
+ }
1275
+ }
1276
+ }
1277
+
1278
+ function changeYear(newYear) {
1279
+ if (!newYear || self.config.minDate && newYear < self.config.minDate.getFullYear() || self.config.maxDate && newYear > self.config.maxDate.getFullYear()) return;
1280
+ var newYearNum = newYear,
1281
+ isNewYear = self.currentYear !== newYearNum;
1282
+ self.currentYear = newYearNum || self.currentYear;
1283
+
1284
+ if (self.config.maxDate && self.currentYear === self.config.maxDate.getFullYear()) {
1285
+ self.currentMonth = Math.min(self.config.maxDate.getMonth(), self.currentMonth);
1286
+ } else if (self.config.minDate && self.currentYear === self.config.minDate.getFullYear()) {
1287
+ self.currentMonth = Math.max(self.config.minDate.getMonth(), self.currentMonth);
1288
+ }
1289
+
1290
+ if (isNewYear) {
1291
+ self.redraw();
1292
+ triggerEvent("onYearChange");
1293
+ }
1294
+ }
1295
+
1296
+ function isEnabled(date, timeless) {
1297
+ if (timeless === void 0) {
1298
+ timeless = true;
1299
+ }
1300
+
1301
+ var dateToCheck = self.parseDate(date, undefined, timeless);
1302
+ if (self.config.minDate && dateToCheck && compareDates(dateToCheck, self.config.minDate, timeless !== undefined ? timeless : !self.minDateHasTime) < 0 || self.config.maxDate && dateToCheck && compareDates(dateToCheck, self.config.maxDate, timeless !== undefined ? timeless : !self.maxDateHasTime) > 0) return false;
1303
+ if (self.config.enable.length === 0 && self.config.disable.length === 0) return true;
1304
+ if (dateToCheck === undefined) return false;
1305
+ var bool = self.config.enable.length > 0,
1306
+ array = bool ? self.config.enable : self.config.disable;
1307
+
1308
+ for (var i = 0, d; i < array.length; i++) {
1309
+ d = array[i];
1310
+ if (typeof d === "function" && d(dateToCheck)) return bool;else if (d instanceof Date && dateToCheck !== undefined && d.getTime() === dateToCheck.getTime()) return bool;else if (typeof d === "string" && dateToCheck !== undefined) {
1311
+ var parsed = self.parseDate(d, undefined, true);
1312
+ return parsed && parsed.getTime() === dateToCheck.getTime() ? bool : !bool;
1313
+ } else if (typeof d === "object" && dateToCheck !== undefined && d.from && d.to && dateToCheck.getTime() >= d.from.getTime() && dateToCheck.getTime() <= d.to.getTime()) return bool;
1314
+ }
1315
+
1316
+ return !bool;
1317
+ }
1318
+
1319
+ function isInView(elem) {
1320
+ if (self.daysContainer !== undefined) return elem.className.indexOf("hidden") === -1 && self.daysContainer.contains(elem);
1321
+ return false;
1322
+ }
1323
+
1324
+ function onKeyDown(e) {
1325
+ var isInput = e.target === self._input;
1326
+ var allowInput = self.config.allowInput;
1327
+ var allowKeydown = self.isOpen && (!allowInput || !isInput);
1328
+ var allowInlineKeydown = self.config.inline && isInput && !allowInput;
1329
+
1330
+ if (e.keyCode === 13 && isInput) {
1331
+ if (allowInput) {
1332
+ self.setDate(self._input.value, true, e.target === self.altInput ? self.config.altFormat : self.config.dateFormat);
1333
+ return e.target.blur();
1334
+ } else self.open();
1335
+ } else if (isCalendarElem(e.target) || allowKeydown || allowInlineKeydown) {
1336
+ var isTimeObj = !!self.timeContainer && self.timeContainer.contains(e.target);
1337
+
1338
+ switch (e.keyCode) {
1339
+ case 13:
1340
+ if (isTimeObj) updateTime();else selectDate(e);
1341
+ break;
1342
+
1343
+ case 27:
1344
+ e.preventDefault();
1345
+ focusAndClose();
1346
+ break;
1347
+
1348
+ case 8:
1349
+ case 46:
1350
+ if (isInput && !self.config.allowInput) {
1351
+ e.preventDefault();
1352
+ self.clear();
1353
+ }
1354
+
1355
+ break;
1356
+
1357
+ case 37:
1358
+ case 39:
1359
+ if (!isTimeObj) {
1360
+ e.preventDefault();
1361
+
1362
+ if (self.daysContainer !== undefined && (allowInput === false || isInView(document.activeElement))) {
1363
+ var _delta = e.keyCode === 39 ? 1 : -1;
1364
+
1365
+ if (!e.ctrlKey) focusOnDay(undefined, _delta);else {
1366
+ changeMonth(_delta);
1367
+ focusOnDay(getFirstAvailableDay(1), 0);
1368
+ }
2136
1369
  }
2137
- if (self.amPM &&
2138
- isHourElem &&
2139
- (step === 1
2140
- ? newValue + curValue === 23
2141
- : Math.abs(newValue - curValue) > step)) {
2142
- self.amPM.textContent =
2143
- self.l10n.amPM[int(self.amPM.textContent === self.l10n.amPM[0])];
1370
+ } else if (self.hourElement) self.hourElement.focus();
1371
+
1372
+ break;
1373
+
1374
+ case 38:
1375
+ case 40:
1376
+ e.preventDefault();
1377
+ var delta = e.keyCode === 40 ? 1 : -1;
1378
+
1379
+ if (self.daysContainer && e.target.$i !== undefined) {
1380
+ if (e.ctrlKey) {
1381
+ changeYear(self.currentYear - delta);
1382
+ focusOnDay(getFirstAvailableDay(1), 0);
1383
+ } else if (!isTimeObj) focusOnDay(undefined, delta * 7);
1384
+ } else if (self.config.enableTime) {
1385
+ if (!isTimeObj && self.hourElement) self.hourElement.focus();
1386
+ updateTime(e);
1387
+
1388
+ self._debouncedChange();
1389
+ }
1390
+
1391
+ break;
1392
+
1393
+ case 9:
1394
+ if (!isTimeObj) {
1395
+ self.element.focus();
1396
+ break;
1397
+ }
1398
+
1399
+ var elems = [self.hourElement, self.minuteElement, self.secondElement, self.amPM].filter(function (x) {
1400
+ return x;
1401
+ });
1402
+ var i = elems.indexOf(e.target);
1403
+
1404
+ if (i !== -1) {
1405
+ var target = elems[i + (e.shiftKey ? -1 : 1)];
1406
+
1407
+ if (target !== undefined) {
1408
+ e.preventDefault();
1409
+ target.focus();
1410
+ } else {
1411
+ self.element.focus();
2144
1412
  }
2145
- input.value = pad(newValue);
1413
+ }
1414
+
1415
+ break;
1416
+
1417
+ default:
1418
+ break;
1419
+ }
1420
+ }
1421
+
1422
+ if (self.amPM !== undefined && e.target === self.amPM) {
1423
+ switch (e.key) {
1424
+ case self.l10n.amPM[0].charAt(0):
1425
+ case self.l10n.amPM[0].charAt(0).toLowerCase():
1426
+ self.amPM.textContent = self.l10n.amPM[0];
1427
+ setHoursFromInputs();
1428
+ updateValue();
1429
+ break;
1430
+
1431
+ case self.l10n.amPM[1].charAt(0):
1432
+ case self.l10n.amPM[1].charAt(0).toLowerCase():
1433
+ self.amPM.textContent = self.l10n.amPM[1];
1434
+ setHoursFromInputs();
1435
+ updateValue();
1436
+ break;
1437
+ }
1438
+ }
1439
+
1440
+ triggerEvent("onKeyDown", e);
1441
+ }
1442
+
1443
+ function onMouseOver(elem) {
1444
+ if (self.selectedDates.length !== 1 || elem && (!elem.classList.contains("flatpickr-day") || elem.classList.contains("disabled"))) return;
1445
+ var hoverDate = elem ? elem.dateObj.getTime() : self.days.firstElementChild.dateObj.getTime(),
1446
+ initialDate = self.parseDate(self.selectedDates[0], undefined, true).getTime(),
1447
+ rangeStartDate = Math.min(hoverDate, self.selectedDates[0].getTime()),
1448
+ rangeEndDate = Math.max(hoverDate, self.selectedDates[0].getTime()),
1449
+ lastDate = self.daysContainer.lastChild.lastChild.dateObj.getTime();
1450
+ var containsDisabled = false;
1451
+ var minRange = 0,
1452
+ maxRange = 0;
1453
+
1454
+ for (var t = rangeStartDate; t < lastDate; t += duration.DAY) {
1455
+ if (!isEnabled(new Date(t), true)) {
1456
+ containsDisabled = containsDisabled || t > rangeStartDate && t < rangeEndDate;
1457
+ if (t < initialDate && (!minRange || t > minRange)) minRange = t;else if (t > initialDate && (!maxRange || t < maxRange)) maxRange = t;
1458
+ }
1459
+ }
1460
+
1461
+ for (var m = 0; m < self.config.showMonths; m++) {
1462
+ var month = self.daysContainer.children[m];
1463
+ var prevMonth = self.daysContainer.children[m - 1];
1464
+
1465
+ var _loop = function _loop(i, l) {
1466
+ var dayElem = month.children[i],
1467
+ date = dayElem.dateObj;
1468
+ var timestamp = date.getTime();
1469
+ var outOfRange = minRange > 0 && timestamp < minRange || maxRange > 0 && timestamp > maxRange;
1470
+
1471
+ if (outOfRange) {
1472
+ dayElem.classList.add("notAllowed");
1473
+ ["inRange", "startRange", "endRange"].forEach(function (c) {
1474
+ dayElem.classList.remove(c);
1475
+ });
1476
+ return "continue";
1477
+ } else if (containsDisabled && !outOfRange) return "continue";
1478
+
1479
+ ["startRange", "inRange", "endRange", "notAllowed"].forEach(function (c) {
1480
+ dayElem.classList.remove(c);
1481
+ });
1482
+
1483
+ if (elem !== undefined) {
1484
+ elem.classList.add(hoverDate < self.selectedDates[0].getTime() ? "startRange" : "endRange");
1485
+
1486
+ if (month.contains(elem) || !(m > 0 && prevMonth && prevMonth.lastChild.dateObj.getTime() >= timestamp)) {
1487
+ if (initialDate < hoverDate && timestamp === initialDate) dayElem.classList.add("startRange");else if (initialDate > hoverDate && timestamp === initialDate) dayElem.classList.add("endRange");
1488
+ if (timestamp >= minRange && (maxRange === 0 || timestamp <= maxRange) && isBetween(timestamp, initialDate, hoverDate)) dayElem.classList.add("inRange");
1489
+ }
2146
1490
  }
1491
+ };
1492
+
1493
+ for (var i = 0, l = month.children.length; i < l; i++) {
1494
+ var _ret = _loop(i, l);
1495
+
1496
+ if (_ret === "continue") continue;
1497
+ }
2147
1498
  }
2148
- init();
2149
- return self;
1499
+ }
1500
+
1501
+ function onResize() {
1502
+ if (self.isOpen && !self.config.static && !self.config.inline) positionCalendar();
1503
+ }
1504
+
1505
+ function open(e, positionElement) {
1506
+ if (positionElement === void 0) {
1507
+ positionElement = self._positionElement;
1508
+ }
1509
+
1510
+ if (self.isMobile === true) {
1511
+ if (e) {
1512
+ e.preventDefault();
1513
+ e.target && e.target.blur();
1514
+ }
1515
+
1516
+ if (self.mobileInput !== undefined) {
1517
+ self.mobileInput.focus();
1518
+ self.mobileInput.click();
1519
+ }
1520
+
1521
+ triggerEvent("onOpen");
1522
+ return;
1523
+ }
1524
+
1525
+ if (self._input.disabled || self.config.inline) return;
1526
+ var wasOpen = self.isOpen;
1527
+ self.isOpen = true;
1528
+
1529
+ if (!wasOpen) {
1530
+ self.calendarContainer.classList.add("open");
1531
+
1532
+ self._input.classList.add("active");
1533
+
1534
+ triggerEvent("onOpen");
1535
+ positionCalendar(positionElement);
1536
+ }
1537
+
1538
+ if (self.config.enableTime === true && self.config.noCalendar === true) {
1539
+ if (self.selectedDates.length === 0) {
1540
+ self.setDate(self.config.minDate !== undefined ? new Date(self.config.minDate.getTime()) : new Date(), false);
1541
+ setDefaultHours();
1542
+ updateValue();
1543
+ }
1544
+
1545
+ if (self.config.allowInput === false && (e === undefined || !self.timeContainer.contains(e.relatedTarget))) {
1546
+ setTimeout(function () {
1547
+ return self.hourElement.select();
1548
+ }, 50);
1549
+ }
1550
+ }
1551
+ }
1552
+
1553
+ function minMaxDateSetter(type) {
1554
+ return function (date) {
1555
+ var dateObj = self.config["_" + type + "Date"] = self.parseDate(date, self.config.dateFormat);
1556
+ var inverseDateObj = self.config["_" + (type === "min" ? "max" : "min") + "Date"];
1557
+
1558
+ if (dateObj !== undefined) {
1559
+ self[type === "min" ? "minDateHasTime" : "maxDateHasTime"] = dateObj.getHours() > 0 || dateObj.getMinutes() > 0 || dateObj.getSeconds() > 0;
1560
+ }
1561
+
1562
+ if (self.selectedDates) {
1563
+ self.selectedDates = self.selectedDates.filter(function (d) {
1564
+ return isEnabled(d);
1565
+ });
1566
+ if (!self.selectedDates.length && type === "min") setHoursFromDate(dateObj);
1567
+ updateValue();
1568
+ }
1569
+
1570
+ if (self.daysContainer) {
1571
+ redraw();
1572
+ if (dateObj !== undefined) self.currentYearElement[type] = dateObj.getFullYear().toString();else self.currentYearElement.removeAttribute(type);
1573
+ self.currentYearElement.disabled = !!inverseDateObj && dateObj !== undefined && inverseDateObj.getFullYear() === dateObj.getFullYear();
1574
+ }
1575
+ };
1576
+ }
1577
+
1578
+ function parseConfig() {
1579
+ var boolOpts = ["wrap", "weekNumbers", "allowInput", "clickOpens", "time_24hr", "enableTime", "noCalendar", "altInput", "shorthandCurrentMonth", "inline", "static", "enableSeconds", "disableMobile"];
1580
+ var userConfig = Object.assign({}, instanceConfig, JSON.parse(JSON.stringify(element.dataset || {})));
1581
+ var formats$$1 = {};
1582
+ self.config.parseDate = userConfig.parseDate;
1583
+ self.config.formatDate = userConfig.formatDate;
1584
+ Object.defineProperty(self.config, "enable", {
1585
+ get: function get() {
1586
+ return self.config._enable;
1587
+ },
1588
+ set: function set(dates) {
1589
+ self.config._enable = parseDateRules(dates);
1590
+ }
1591
+ });
1592
+ Object.defineProperty(self.config, "disable", {
1593
+ get: function get() {
1594
+ return self.config._disable;
1595
+ },
1596
+ set: function set(dates) {
1597
+ self.config._disable = parseDateRules(dates);
1598
+ }
1599
+ });
1600
+ var timeMode = userConfig.mode === "time";
1601
+
1602
+ if (!userConfig.dateFormat && (userConfig.enableTime || timeMode)) {
1603
+ formats$$1.dateFormat = userConfig.noCalendar || timeMode ? "H:i" + (userConfig.enableSeconds ? ":S" : "") : flatpickr.defaultConfig.dateFormat + " H:i" + (userConfig.enableSeconds ? ":S" : "");
1604
+ }
1605
+
1606
+ if (userConfig.altInput && (userConfig.enableTime || timeMode) && !userConfig.altFormat) {
1607
+ formats$$1.altFormat = userConfig.noCalendar || timeMode ? "h:i" + (userConfig.enableSeconds ? ":S K" : " K") : flatpickr.defaultConfig.altFormat + (" h:i" + (userConfig.enableSeconds ? ":S" : "") + " K");
1608
+ }
1609
+
1610
+ Object.defineProperty(self.config, "minDate", {
1611
+ get: function get() {
1612
+ return self.config._minDate;
1613
+ },
1614
+ set: minMaxDateSetter("min")
1615
+ });
1616
+ Object.defineProperty(self.config, "maxDate", {
1617
+ get: function get() {
1618
+ return self.config._maxDate;
1619
+ },
1620
+ set: minMaxDateSetter("max")
1621
+ });
1622
+
1623
+ var minMaxTimeSetter = function minMaxTimeSetter(type) {
1624
+ return function (val) {
1625
+ self.config[type === "min" ? "_minTime" : "_maxTime"] = self.parseDate(val, "H:i");
1626
+ };
1627
+ };
1628
+
1629
+ Object.defineProperty(self.config, "minTime", {
1630
+ get: function get() {
1631
+ return self.config._minTime;
1632
+ },
1633
+ set: minMaxTimeSetter("min")
1634
+ });
1635
+ Object.defineProperty(self.config, "maxTime", {
1636
+ get: function get() {
1637
+ return self.config._maxTime;
1638
+ },
1639
+ set: minMaxTimeSetter("max")
1640
+ });
1641
+
1642
+ if (userConfig.mode === "time") {
1643
+ self.config.noCalendar = true;
1644
+ self.config.enableTime = true;
1645
+ }
1646
+
1647
+ Object.assign(self.config, formats$$1, userConfig);
1648
+
1649
+ for (var i = 0; i < boolOpts.length; i++) {
1650
+ self.config[boolOpts[i]] = self.config[boolOpts[i]] === true || self.config[boolOpts[i]] === "true";
1651
+ }
1652
+
1653
+ HOOKS.filter(function (hook) {
1654
+ return self.config[hook] !== undefined;
1655
+ }).forEach(function (hook) {
1656
+ self.config[hook] = arrayify(self.config[hook] || []).map(bindToInstance);
1657
+ });
1658
+ self.isMobile = !self.config.disableMobile && !self.config.inline && self.config.mode === "single" && !self.config.disable.length && !self.config.enable.length && !self.config.weekNumbers && /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
1659
+
1660
+ for (var _i = 0; _i < self.config.plugins.length; _i++) {
1661
+ var pluginConf = self.config.plugins[_i](self) || {};
1662
+
1663
+ for (var key in pluginConf) {
1664
+ if (HOOKS.indexOf(key) > -1) {
1665
+ self.config[key] = arrayify(pluginConf[key]).map(bindToInstance).concat(self.config[key]);
1666
+ } else if (typeof userConfig[key] === "undefined") self.config[key] = pluginConf[key];
1667
+ }
1668
+ }
1669
+
1670
+ triggerEvent("onParseConfig");
1671
+ }
1672
+
1673
+ function setupLocale() {
1674
+ if (typeof self.config.locale !== "object" && typeof flatpickr.l10ns[self.config.locale] === "undefined") self.config.errorHandler(new Error("flatpickr: invalid locale " + self.config.locale));
1675
+ self.l10n = Object.assign({}, flatpickr.l10ns.default, typeof self.config.locale === "object" ? self.config.locale : self.config.locale !== "default" ? flatpickr.l10ns[self.config.locale] : undefined);
1676
+ tokenRegex.K = "(" + self.l10n.amPM[0] + "|" + self.l10n.amPM[1] + "|" + self.l10n.amPM[0].toLowerCase() + "|" + self.l10n.amPM[1].toLowerCase() + ")";
1677
+ self.formatDate = createDateFormatter(self);
1678
+ self.parseDate = createDateParser({
1679
+ config: self.config,
1680
+ l10n: self.l10n
1681
+ });
1682
+ }
1683
+
1684
+ function positionCalendar(customPositionElement) {
1685
+ if (self.calendarContainer === undefined) return;
1686
+ triggerEvent("onPreCalendarPosition");
1687
+ var positionElement = customPositionElement || self._positionElement;
1688
+ var calendarHeight = Array.prototype.reduce.call(self.calendarContainer.children, function (acc, child) {
1689
+ return acc + child.offsetHeight;
1690
+ }, 0),
1691
+ calendarWidth = self.calendarContainer.offsetWidth,
1692
+ configPos = self.config.position.split(" "),
1693
+ configPosVertical = configPos[0],
1694
+ configPosHorizontal = configPos.length > 1 ? configPos[1] : null,
1695
+ inputBounds = positionElement.getBoundingClientRect(),
1696
+ distanceFromBottom = window.innerHeight - inputBounds.bottom,
1697
+ showOnTop = configPosVertical === "above" || configPosVertical !== "below" && distanceFromBottom < calendarHeight && inputBounds.top > calendarHeight;
1698
+ var top = window.pageYOffset + inputBounds.top + (!showOnTop ? positionElement.offsetHeight + 2 : -calendarHeight - 2);
1699
+ toggleClass(self.calendarContainer, "arrowTop", !showOnTop);
1700
+ toggleClass(self.calendarContainer, "arrowBottom", showOnTop);
1701
+ if (self.config.inline) return;
1702
+ var left = window.pageXOffset + inputBounds.left - (configPosHorizontal != null && configPosHorizontal === "center" ? (calendarWidth - inputBounds.width) / 2 : 0);
1703
+ var right = window.document.body.offsetWidth - inputBounds.right;
1704
+ var rightMost = left + calendarWidth > window.document.body.offsetWidth;
1705
+ toggleClass(self.calendarContainer, "rightMost", rightMost);
1706
+ if (self.config.static) return;
1707
+ self.calendarContainer.style.top = top + "px";
1708
+
1709
+ if (!rightMost) {
1710
+ self.calendarContainer.style.left = left + "px";
1711
+ self.calendarContainer.style.right = "auto";
1712
+ } else {
1713
+ self.calendarContainer.style.left = "auto";
1714
+ self.calendarContainer.style.right = right + "px";
1715
+ }
1716
+ }
1717
+
1718
+ function redraw() {
1719
+ if (self.config.noCalendar || self.isMobile) return;
1720
+ updateNavigationCurrentMonth();
1721
+ buildDays();
1722
+ }
1723
+
1724
+ function focusAndClose() {
1725
+ self._input.focus();
1726
+
1727
+ if (window.navigator.userAgent.indexOf("MSIE") !== -1 || navigator.msMaxTouchPoints !== undefined) {
1728
+ setTimeout(self.close, 0);
1729
+ } else {
1730
+ self.close();
1731
+ }
1732
+ }
1733
+
1734
+ function selectDate(e) {
1735
+ e.preventDefault();
1736
+ e.stopPropagation();
1737
+
1738
+ var isSelectable = function isSelectable(day) {
1739
+ return day.classList && day.classList.contains("flatpickr-day") && !day.classList.contains("disabled") && !day.classList.contains("notAllowed");
1740
+ };
1741
+
1742
+ var t = findParent(e.target, isSelectable);
1743
+ if (t === undefined) return;
1744
+ var target = t;
1745
+ var selectedDate = self.latestSelectedDateObj = new Date(target.dateObj.getTime());
1746
+ var shouldChangeMonth = (selectedDate.getMonth() < self.currentMonth || selectedDate.getMonth() > self.currentMonth + self.config.showMonths - 1) && self.config.mode !== "range";
1747
+ self.selectedDateElem = target;
1748
+ if (self.config.mode === "single") self.selectedDates = [selectedDate];else if (self.config.mode === "multiple") {
1749
+ var selectedIndex = isDateSelected(selectedDate);
1750
+ if (selectedIndex) self.selectedDates.splice(parseInt(selectedIndex), 1);else self.selectedDates.push(selectedDate);
1751
+ } else if (self.config.mode === "range") {
1752
+ if (self.selectedDates.length === 2) self.clear(false);
1753
+ self.selectedDates.push(selectedDate);
1754
+ if (compareDates(selectedDate, self.selectedDates[0], true) !== 0) self.selectedDates.sort(function (a, b) {
1755
+ return a.getTime() - b.getTime();
1756
+ });
1757
+ }
1758
+ setHoursFromInputs();
1759
+
1760
+ if (shouldChangeMonth) {
1761
+ var isNewYear = self.currentYear !== selectedDate.getFullYear();
1762
+ self.currentYear = selectedDate.getFullYear();
1763
+ self.currentMonth = selectedDate.getMonth();
1764
+ if (isNewYear) triggerEvent("onYearChange");
1765
+ triggerEvent("onMonthChange");
1766
+ }
1767
+
1768
+ updateNavigationCurrentMonth();
1769
+ buildDays();
1770
+ updateValue();
1771
+ if (self.config.enableTime) setTimeout(function () {
1772
+ return self.showTimeInput = true;
1773
+ }, 50);
1774
+ if (!shouldChangeMonth && self.config.mode !== "range" && self.config.showMonths === 1) focusOnDayElem(target);else self.selectedDateElem && self.selectedDateElem.focus();
1775
+ if (self.hourElement !== undefined) setTimeout(function () {
1776
+ return self.hourElement !== undefined && self.hourElement.select();
1777
+ }, 451);
1778
+
1779
+ if (self.config.closeOnSelect) {
1780
+ var single = self.config.mode === "single" && !self.config.enableTime;
1781
+ var range = self.config.mode === "range" && self.selectedDates.length === 2 && !self.config.enableTime;
1782
+
1783
+ if (single || range) {
1784
+ focusAndClose();
1785
+ }
1786
+ }
1787
+
1788
+ triggerChange();
1789
+ }
1790
+
1791
+ var CALLBACKS = {
1792
+ locale: [setupLocale, updateWeekdays],
1793
+ showMonths: [buildMonths, setCalendarWidth, buildWeekdays]
1794
+ };
1795
+
1796
+ function set(option, value) {
1797
+ if (option !== null && typeof option === "object") Object.assign(self.config, option);else {
1798
+ self.config[option] = value;
1799
+ if (CALLBACKS[option] !== undefined) CALLBACKS[option].forEach(function (x) {
1800
+ return x();
1801
+ });else if (HOOKS.indexOf(option) > -1) self.config[option] = arrayify(value);
1802
+ }
1803
+ self.redraw();
1804
+ jumpToDate();
1805
+ updateValue(false);
1806
+ }
1807
+
1808
+ function setSelectedDate(inputDate, format) {
1809
+ var dates = [];
1810
+ if (inputDate instanceof Array) dates = inputDate.map(function (d) {
1811
+ return self.parseDate(d, format);
1812
+ });else if (inputDate instanceof Date || typeof inputDate === "number") dates = [self.parseDate(inputDate, format)];else if (typeof inputDate === "string") {
1813
+ switch (self.config.mode) {
1814
+ case "single":
1815
+ case "time":
1816
+ dates = [self.parseDate(inputDate, format)];
1817
+ break;
1818
+
1819
+ case "multiple":
1820
+ dates = inputDate.split(self.config.conjunction).map(function (date) {
1821
+ return self.parseDate(date, format);
1822
+ });
1823
+ break;
1824
+
1825
+ case "range":
1826
+ dates = inputDate.split(self.l10n.rangeSeparator).map(function (date) {
1827
+ return self.parseDate(date, format);
1828
+ });
1829
+ break;
1830
+
1831
+ default:
1832
+ break;
1833
+ }
1834
+ } else self.config.errorHandler(new Error("Invalid date supplied: " + JSON.stringify(inputDate)));
1835
+ self.selectedDates = dates.filter(function (d) {
1836
+ return d instanceof Date && isEnabled(d, false);
1837
+ });
1838
+ if (self.config.mode === "range") self.selectedDates.sort(function (a, b) {
1839
+ return a.getTime() - b.getTime();
1840
+ });
1841
+ }
1842
+
1843
+ function setDate(date, triggerChange, format) {
1844
+ if (triggerChange === void 0) {
1845
+ triggerChange = false;
1846
+ }
1847
+
1848
+ if (format === void 0) {
1849
+ format = self.config.dateFormat;
1850
+ }
1851
+
1852
+ if (date !== 0 && !date || date instanceof Array && date.length === 0) return self.clear(triggerChange);
1853
+ setSelectedDate(date, format);
1854
+ self.showTimeInput = self.selectedDates.length > 0;
1855
+ self.latestSelectedDateObj = self.selectedDates[0];
1856
+ self.redraw();
1857
+ jumpToDate();
1858
+ setHoursFromDate();
1859
+ updateValue(triggerChange);
1860
+ if (triggerChange) triggerEvent("onChange");
1861
+ }
1862
+
1863
+ function parseDateRules(arr) {
1864
+ return arr.slice().map(function (rule) {
1865
+ if (typeof rule === "string" || typeof rule === "number" || rule instanceof Date) {
1866
+ return self.parseDate(rule, undefined, true);
1867
+ } else if (rule && typeof rule === "object" && rule.from && rule.to) return {
1868
+ from: self.parseDate(rule.from, undefined),
1869
+ to: self.parseDate(rule.to, undefined)
1870
+ };
1871
+
1872
+ return rule;
1873
+ }).filter(function (x) {
1874
+ return x;
1875
+ });
1876
+ }
1877
+
1878
+ function setupDates() {
1879
+ self.selectedDates = [];
1880
+ self.now = self.parseDate(self.config.now) || new Date();
1881
+ var preloadedDate = self.config.defaultDate || ((self.input.nodeName === "INPUT" || self.input.nodeName === "TEXTAREA") && self.input.placeholder && self.input.value === self.input.placeholder ? null : self.input.value);
1882
+ if (preloadedDate) setSelectedDate(preloadedDate, self.config.dateFormat);
1883
+ var initialDate = self.selectedDates.length > 0 ? self.selectedDates[0] : self.config.minDate && self.config.minDate.getTime() > self.now.getTime() ? self.config.minDate : self.config.maxDate && self.config.maxDate.getTime() < self.now.getTime() ? self.config.maxDate : self.now;
1884
+ self.currentYear = initialDate.getFullYear();
1885
+ self.currentMonth = initialDate.getMonth();
1886
+ if (self.selectedDates.length > 0) self.latestSelectedDateObj = self.selectedDates[0];
1887
+ if (self.config.minTime !== undefined) self.config.minTime = self.parseDate(self.config.minTime, "H:i");
1888
+ if (self.config.maxTime !== undefined) self.config.maxTime = self.parseDate(self.config.maxTime, "H:i");
1889
+ self.minDateHasTime = !!self.config.minDate && (self.config.minDate.getHours() > 0 || self.config.minDate.getMinutes() > 0 || self.config.minDate.getSeconds() > 0);
1890
+ self.maxDateHasTime = !!self.config.maxDate && (self.config.maxDate.getHours() > 0 || self.config.maxDate.getMinutes() > 0 || self.config.maxDate.getSeconds() > 0);
1891
+ Object.defineProperty(self, "showTimeInput", {
1892
+ get: function get() {
1893
+ return self._showTimeInput;
1894
+ },
1895
+ set: function set(bool) {
1896
+ self._showTimeInput = bool;
1897
+ if (self.calendarContainer) toggleClass(self.calendarContainer, "showTimeInput", bool);
1898
+ self.isOpen && positionCalendar();
1899
+ }
1900
+ });
1901
+ }
1902
+
1903
+ function setupInputs() {
1904
+ self.input = self.config.wrap ? element.querySelector("[data-input]") : element;
1905
+
1906
+ if (!self.input) {
1907
+ self.config.errorHandler(new Error("Invalid input element specified"));
1908
+ return;
1909
+ }
1910
+
1911
+ self.input._type = self.input.type;
1912
+ self.input.type = "text";
1913
+ self.input.classList.add("flatpickr-input");
1914
+ self._input = self.input;
1915
+
1916
+ if (self.config.altInput) {
1917
+ self.altInput = createElement(self.input.nodeName, self.input.className + " " + self.config.altInputClass);
1918
+ self._input = self.altInput;
1919
+ self.altInput.placeholder = self.input.placeholder;
1920
+ self.altInput.disabled = self.input.disabled;
1921
+ self.altInput.required = self.input.required;
1922
+ self.altInput.tabIndex = self.input.tabIndex;
1923
+ self.altInput.type = "text";
1924
+ self.input.setAttribute("type", "hidden");
1925
+ if (!self.config.static && self.input.parentNode) self.input.parentNode.insertBefore(self.altInput, self.input.nextSibling);
1926
+ }
1927
+
1928
+ if (!self.config.allowInput) self._input.setAttribute("readonly", "readonly");
1929
+ self._positionElement = self.config.positionElement || self._input;
1930
+ }
1931
+
1932
+ function setupMobile() {
1933
+ var inputType = self.config.enableTime ? self.config.noCalendar ? "time" : "datetime-local" : "date";
1934
+ self.mobileInput = createElement("input", self.input.className + " flatpickr-mobile");
1935
+ self.mobileInput.step = self.input.getAttribute("step") || "any";
1936
+ self.mobileInput.tabIndex = 1;
1937
+ self.mobileInput.type = inputType;
1938
+ self.mobileInput.disabled = self.input.disabled;
1939
+ self.mobileInput.required = self.input.required;
1940
+ self.mobileInput.placeholder = self.input.placeholder;
1941
+ self.mobileFormatStr = inputType === "datetime-local" ? "Y-m-d\\TH:i:S" : inputType === "date" ? "Y-m-d" : "H:i:S";
1942
+
1943
+ if (self.selectedDates.length > 0) {
1944
+ self.mobileInput.defaultValue = self.mobileInput.value = self.formatDate(self.selectedDates[0], self.mobileFormatStr);
1945
+ }
1946
+
1947
+ if (self.config.minDate) self.mobileInput.min = self.formatDate(self.config.minDate, "Y-m-d");
1948
+ if (self.config.maxDate) self.mobileInput.max = self.formatDate(self.config.maxDate, "Y-m-d");
1949
+ self.input.type = "hidden";
1950
+ if (self.altInput !== undefined) self.altInput.type = "hidden";
1951
+
1952
+ try {
1953
+ if (self.input.parentNode) self.input.parentNode.insertBefore(self.mobileInput, self.input.nextSibling);
1954
+ } catch (_a) {}
1955
+
1956
+ bind(self.mobileInput, "change", function (e) {
1957
+ self.setDate(e.target.value, false, self.mobileFormatStr);
1958
+ triggerEvent("onChange");
1959
+ triggerEvent("onClose");
1960
+ });
1961
+ }
1962
+
1963
+ function toggle(e) {
1964
+ if (self.isOpen === true) return self.close();
1965
+ self.open(e);
1966
+ }
1967
+
1968
+ function triggerEvent(event, data) {
1969
+ if (self.config === undefined) return;
1970
+ var hooks = self.config[event];
1971
+
1972
+ if (hooks !== undefined && hooks.length > 0) {
1973
+ for (var i = 0; hooks[i] && i < hooks.length; i++) {
1974
+ hooks[i](self.selectedDates, self.input.value, self, data);
1975
+ }
1976
+ }
1977
+
1978
+ if (event === "onChange") {
1979
+ self.input.dispatchEvent(createEvent("change"));
1980
+ self.input.dispatchEvent(createEvent("input"));
1981
+ }
1982
+ }
1983
+
1984
+ function createEvent(name) {
1985
+ var e = document.createEvent("Event");
1986
+ e.initEvent(name, true, true);
1987
+ return e;
1988
+ }
1989
+
1990
+ function isDateSelected(date) {
1991
+ for (var i = 0; i < self.selectedDates.length; i++) {
1992
+ if (compareDates(self.selectedDates[i], date) === 0) return "" + i;
1993
+ }
1994
+
1995
+ return false;
1996
+ }
1997
+
1998
+ function isDateInRange(date) {
1999
+ if (self.config.mode !== "range" || self.selectedDates.length < 2) return false;
2000
+ return compareDates(date, self.selectedDates[0]) >= 0 && compareDates(date, self.selectedDates[1]) <= 0;
2001
+ }
2002
+
2003
+ function updateNavigationCurrentMonth() {
2004
+ if (self.config.noCalendar || self.isMobile || !self.monthNav) return;
2005
+ self.yearElements.forEach(function (yearElement, i) {
2006
+ var d = new Date(self.currentYear, self.currentMonth, 1);
2007
+ d.setMonth(self.currentMonth + i);
2008
+ self.monthElements[i].textContent = monthToStr(d.getMonth(), self.config.shorthandCurrentMonth, self.l10n) + " ";
2009
+ yearElement.value = d.getFullYear().toString();
2010
+ });
2011
+ self._hidePrevMonthArrow = self.config.minDate !== undefined && (self.currentYear === self.config.minDate.getFullYear() ? self.currentMonth <= self.config.minDate.getMonth() : self.currentYear < self.config.minDate.getFullYear());
2012
+ self._hideNextMonthArrow = self.config.maxDate !== undefined && (self.currentYear === self.config.maxDate.getFullYear() ? self.currentMonth + 1 > self.config.maxDate.getMonth() : self.currentYear > self.config.maxDate.getFullYear());
2013
+ }
2014
+
2015
+ function getDateStr(format) {
2016
+ return self.selectedDates.map(function (dObj) {
2017
+ return self.formatDate(dObj, format);
2018
+ }).filter(function (d, i, arr) {
2019
+ return self.config.mode !== "range" || self.config.enableTime || arr.indexOf(d) === i;
2020
+ }).join(self.config.mode !== "range" ? self.config.conjunction : self.l10n.rangeSeparator);
2021
+ }
2022
+
2023
+ function updateValue(triggerChange) {
2024
+ if (triggerChange === void 0) {
2025
+ triggerChange = true;
2026
+ }
2027
+
2028
+ if (self.selectedDates.length === 0) return self.clear(triggerChange);
2029
+
2030
+ if (self.mobileInput !== undefined && self.mobileFormatStr) {
2031
+ self.mobileInput.value = self.latestSelectedDateObj !== undefined ? self.formatDate(self.latestSelectedDateObj, self.mobileFormatStr) : "";
2032
+ }
2033
+
2034
+ self.input.value = getDateStr(self.config.dateFormat);
2035
+
2036
+ if (self.altInput !== undefined) {
2037
+ self.altInput.value = getDateStr(self.config.altFormat);
2038
+ }
2039
+
2040
+ if (triggerChange !== false) triggerEvent("onValueUpdate");
2041
+ }
2042
+
2043
+ function onMonthNavClick(e) {
2044
+ e.preventDefault();
2045
+ var isPrevMonth = self.prevMonthNav.contains(e.target);
2046
+ var isNextMonth = self.nextMonthNav.contains(e.target);
2047
+
2048
+ if (isPrevMonth || isNextMonth) {
2049
+ changeMonth(isPrevMonth ? -1 : 1);
2050
+ } else if (self.yearElements.indexOf(e.target) >= 0) {
2051
+ e.target.select();
2052
+ } else if (e.target.classList.contains("arrowUp")) {
2053
+ self.changeYear(self.currentYear + 1);
2054
+ } else if (e.target.classList.contains("arrowDown")) {
2055
+ self.changeYear(self.currentYear - 1);
2056
+ }
2057
+ }
2058
+
2059
+ function timeWrapper(e) {
2060
+ e.preventDefault();
2061
+ var isKeyDown = e.type === "keydown",
2062
+ input = e.target;
2063
+
2064
+ if (self.amPM !== undefined && e.target === self.amPM) {
2065
+ self.amPM.textContent = self.l10n.amPM[int(self.amPM.textContent === self.l10n.amPM[0])];
2066
+ }
2067
+
2068
+ var min = parseFloat(input.getAttribute("data-min")),
2069
+ max = parseFloat(input.getAttribute("data-max")),
2070
+ step = parseFloat(input.getAttribute("data-step")),
2071
+ curValue = parseInt(input.value, 10),
2072
+ delta = e.delta || (isKeyDown ? e.which === 38 ? 1 : -1 : 0);
2073
+ var newValue = curValue + step * delta;
2074
+
2075
+ if (typeof input.value !== "undefined" && input.value.length === 2) {
2076
+ var isHourElem = input === self.hourElement,
2077
+ isMinuteElem = input === self.minuteElement;
2078
+
2079
+ if (newValue < min) {
2080
+ newValue = max + newValue + int(!isHourElem) + (int(isHourElem) && int(!self.amPM));
2081
+ if (isMinuteElem) incrementNumInput(undefined, -1, self.hourElement);
2082
+ } else if (newValue > max) {
2083
+ newValue = input === self.hourElement ? newValue - max - int(!self.amPM) : min;
2084
+ if (isMinuteElem) incrementNumInput(undefined, 1, self.hourElement);
2085
+ }
2086
+
2087
+ if (self.amPM && isHourElem && (step === 1 ? newValue + curValue === 23 : Math.abs(newValue - curValue) > step)) {
2088
+ self.amPM.textContent = self.l10n.amPM[int(self.amPM.textContent === self.l10n.amPM[0])];
2089
+ }
2090
+
2091
+ input.value = pad(newValue);
2092
+ }
2093
+ }
2094
+
2095
+ init();
2096
+ return self;
2150
2097
  }
2098
+
2151
2099
  function _flatpickr(nodeList, config) {
2152
- const nodes = Array.prototype.slice.call(nodeList);
2153
- let instances = [];
2154
- for (let i = 0; i < nodes.length; i++) {
2155
- const node = nodes[i];
2156
- try {
2157
- if (node.getAttribute("data-fp-omit") !== null)
2158
- continue;
2159
- if (node._flatpickr !== undefined) {
2160
- node._flatpickr.destroy();
2161
- node._flatpickr = undefined;
2162
- }
2163
- node._flatpickr = FlatpickrInstance(node, config || {});
2164
- instances.push(node._flatpickr);
2165
- }
2166
- catch (e) {
2167
- console.error(e);
2168
- }
2100
+ var nodes = Array.prototype.slice.call(nodeList);
2101
+ var instances = [];
2102
+
2103
+ for (var i = 0; i < nodes.length; i++) {
2104
+ var node = nodes[i];
2105
+
2106
+ try {
2107
+ if (node.getAttribute("data-fp-omit") !== null) continue;
2108
+
2109
+ if (node._flatpickr !== undefined) {
2110
+ node._flatpickr.destroy();
2111
+
2112
+ node._flatpickr = undefined;
2113
+ }
2114
+
2115
+ node._flatpickr = FlatpickrInstance(node, config || {});
2116
+ instances.push(node._flatpickr);
2117
+ } catch (e) {
2118
+ console.error(e);
2169
2119
  }
2170
- return instances.length === 1 ? instances[0] : instances;
2120
+ }
2121
+
2122
+ return instances.length === 1 ? instances[0] : instances;
2171
2123
  }
2124
+
2172
2125
  if (typeof HTMLElement !== "undefined") {
2173
- HTMLCollection.prototype.flatpickr = NodeList.prototype.flatpickr = function (config) {
2174
- return _flatpickr(this, config);
2175
- };
2176
- HTMLElement.prototype.flatpickr = function (config) {
2177
- return _flatpickr([this], config);
2178
- };
2126
+ HTMLCollection.prototype.flatpickr = NodeList.prototype.flatpickr = function (config) {
2127
+ return _flatpickr(this, config);
2128
+ };
2129
+
2130
+ HTMLElement.prototype.flatpickr = function (config) {
2131
+ return _flatpickr([this], config);
2132
+ };
2179
2133
  }
2180
- var flatpickr = function (selector, config) {
2181
- if (selector instanceof NodeList)
2182
- return _flatpickr(selector, config);
2183
- else if (typeof selector === "string")
2184
- return _flatpickr(window.document.querySelectorAll(selector), config);
2185
- return _flatpickr([selector], config);
2134
+
2135
+ var flatpickr = function flatpickr(selector, config) {
2136
+ if (selector instanceof NodeList) return _flatpickr(selector, config);else if (typeof selector === "string") return _flatpickr(window.document.querySelectorAll(selector), config);
2137
+ return _flatpickr([selector], config);
2186
2138
  };
2139
+
2187
2140
  flatpickr.defaultConfig = defaults;
2188
2141
  flatpickr.l10ns = {
2189
- en: Object.assign({}, english),
2190
- default: Object.assign({}, english),
2142
+ en: Object.assign({}, english),
2143
+ default: Object.assign({}, english)
2191
2144
  };
2192
- flatpickr.localize = (l10n) => {
2193
- flatpickr.l10ns.default = Object.assign({}, flatpickr.l10ns.default, l10n);
2145
+
2146
+ flatpickr.localize = function (l10n) {
2147
+ flatpickr.l10ns.default = Object.assign({}, flatpickr.l10ns.default, l10n);
2194
2148
  };
2195
- flatpickr.setDefaults = (config) => {
2196
- flatpickr.defaultConfig = Object.assign({}, flatpickr.defaultConfig, config);
2149
+
2150
+ flatpickr.setDefaults = function (config) {
2151
+ flatpickr.defaultConfig = Object.assign({}, flatpickr.defaultConfig, config);
2197
2152
  };
2153
+
2198
2154
  flatpickr.parseDate = createDateParser({});
2199
2155
  flatpickr.formatDate = createDateFormatter({});
2200
2156
  flatpickr.compareDates = compareDates;
2157
+
2201
2158
  if (typeof jQuery !== "undefined") {
2202
- jQuery.fn.flatpickr = function (config) {
2203
- return _flatpickr(this, config);
2204
- };
2159
+ jQuery.fn.flatpickr = function (config) {
2160
+ return _flatpickr(this, config);
2161
+ };
2205
2162
  }
2163
+
2206
2164
  Date.prototype.fp_incr = function (days) {
2207
- return new Date(this.getFullYear(), this.getMonth(), this.getDate() + (typeof days === "string" ? parseInt(days, 10) : days));
2165
+ return new Date(this.getFullYear(), this.getMonth(), this.getDate() + (typeof days === "string" ? parseInt(days, 10) : days));
2208
2166
  };
2167
+
2209
2168
  if (typeof window !== "undefined") {
2210
- window.flatpickr = flatpickr;
2169
+ window.flatpickr = flatpickr;
2211
2170
  }
2212
2171
 
2213
2172
  return flatpickr;