flatpickr 3.0.7.0 → 4.5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE.txt +1 -1
  3. data/README.md +26 -7
  4. data/Rakefile +14 -6
  5. data/lib/flatpickr.rb +3 -1
  6. data/lib/flatpickr/engine.rb +2 -0
  7. data/lib/flatpickr/version.rb +3 -1
  8. data/vendor/assets/javascripts/flatpickr.js +2215 -2351
  9. data/vendor/assets/javascripts/flatpickr/l10n/ar.js +52 -14
  10. data/vendor/assets/javascripts/flatpickr/l10n/at.js +70 -0
  11. data/vendor/assets/javascripts/flatpickr/l10n/be.js +75 -0
  12. data/vendor/assets/javascripts/flatpickr/l10n/bg.js +65 -14
  13. data/vendor/assets/javascripts/flatpickr/l10n/bn.js +65 -14
  14. data/vendor/assets/javascripts/flatpickr/l10n/cat.js +79 -30
  15. data/vendor/assets/javascripts/flatpickr/l10n/cs.js +71 -16
  16. data/vendor/assets/javascripts/flatpickr/l10n/cy.js +88 -32
  17. data/vendor/assets/javascripts/flatpickr/l10n/da.js +68 -15
  18. data/vendor/assets/javascripts/flatpickr/l10n/de.js +66 -17
  19. data/vendor/assets/javascripts/flatpickr/l10n/default.js +81 -0
  20. data/vendor/assets/javascripts/flatpickr/l10n/eo.js +69 -22
  21. data/vendor/assets/javascripts/flatpickr/l10n/es.js +66 -16
  22. data/vendor/assets/javascripts/flatpickr/l10n/et.js +69 -22
  23. data/vendor/assets/javascripts/flatpickr/l10n/fa.js +66 -15
  24. data/vendor/assets/javascripts/flatpickr/l10n/fi.js +65 -16
  25. data/vendor/assets/javascripts/flatpickr/l10n/fr.js +71 -23
  26. data/vendor/assets/javascripts/flatpickr/l10n/gr.js +70 -25
  27. data/vendor/assets/javascripts/flatpickr/l10n/he.js +57 -14
  28. data/vendor/assets/javascripts/flatpickr/l10n/hi.js +65 -14
  29. data/vendor/assets/javascripts/flatpickr/l10n/hr.js +62 -13
  30. data/vendor/assets/javascripts/flatpickr/l10n/hu.js +68 -21
  31. data/vendor/assets/javascripts/flatpickr/l10n/id.js +57 -16
  32. data/vendor/assets/javascripts/flatpickr/l10n/index.js +3022 -97
  33. data/vendor/assets/javascripts/flatpickr/l10n/it.js +67 -21
  34. data/vendor/assets/javascripts/flatpickr/l10n/ja.js +65 -14
  35. data/vendor/assets/javascripts/flatpickr/l10n/km.js +74 -0
  36. data/vendor/assets/javascripts/flatpickr/l10n/ko.js +65 -15
  37. data/vendor/assets/javascripts/flatpickr/l10n/kz.js +75 -0
  38. data/vendor/assets/javascripts/flatpickr/l10n/lt.js +68 -21
  39. data/vendor/assets/javascripts/flatpickr/l10n/lv.js +64 -13
  40. data/vendor/assets/javascripts/flatpickr/l10n/mk.js +64 -15
  41. data/vendor/assets/javascripts/flatpickr/l10n/mn.js +59 -0
  42. data/vendor/assets/javascripts/flatpickr/l10n/ms.js +64 -16
  43. data/vendor/assets/javascripts/flatpickr/l10n/my.js +65 -16
  44. data/vendor/assets/javascripts/flatpickr/l10n/nl.js +71 -23
  45. data/vendor/assets/javascripts/flatpickr/l10n/no.js +69 -20
  46. data/vendor/assets/javascripts/flatpickr/l10n/pa.js +65 -14
  47. data/vendor/assets/javascripts/flatpickr/l10n/pl.js +70 -15
  48. data/vendor/assets/javascripts/flatpickr/l10n/pt.js +62 -13
  49. data/vendor/assets/javascripts/flatpickr/l10n/ro.js +65 -17
  50. data/vendor/assets/javascripts/flatpickr/l10n/ru.js +72 -13
  51. data/vendor/assets/javascripts/flatpickr/l10n/si.js +62 -12
  52. data/vendor/assets/javascripts/flatpickr/l10n/sk.js +66 -17
  53. data/vendor/assets/javascripts/flatpickr/l10n/sl.js +66 -17
  54. data/vendor/assets/javascripts/flatpickr/l10n/sq.js +65 -14
  55. data/vendor/assets/javascripts/flatpickr/l10n/sr.js +64 -15
  56. data/vendor/assets/javascripts/flatpickr/l10n/sv.js +66 -17
  57. data/vendor/assets/javascripts/flatpickr/l10n/th.js +68 -20
  58. data/vendor/assets/javascripts/flatpickr/l10n/tr.js +71 -13
  59. data/vendor/assets/javascripts/flatpickr/l10n/uk.js +63 -13
  60. data/vendor/assets/javascripts/flatpickr/l10n/vn.js +62 -13
  61. data/vendor/assets/javascripts/flatpickr/l10n/zh.js +65 -16
  62. data/vendor/assets/javascripts/flatpickr/plugins/confirmDate/confirmDate.js +49 -0
  63. data/vendor/assets/javascripts/flatpickr/plugins/labelPlugin/labelPlugin.js +31 -0
  64. data/vendor/assets/javascripts/flatpickr/plugins/minMaxTimePlugin.js +281 -0
  65. data/vendor/assets/javascripts/flatpickr/plugins/monthSelect/monthSelect.js +77 -0
  66. data/vendor/assets/javascripts/flatpickr/plugins/rangePlugin.js +138 -0
  67. data/vendor/assets/javascripts/flatpickr/plugins/scrollPlugin.js +50 -0
  68. data/vendor/assets/javascripts/flatpickr/plugins/weekSelect/weekSelect.js +80 -0
  69. data/vendor/assets/stylesheets/flatpickr.css +741 -13
  70. data/vendor/assets/stylesheets/flatpickr/ie.css +13 -0
  71. data/vendor/assets/stylesheets/flatpickr/plugins/confirmDate/confirmDate.css +24 -0
  72. data/vendor/assets/stylesheets/flatpickr/plugins/monthSelect/monthSelect.css +10 -0
  73. data/vendor/assets/stylesheets/flatpickr/themes/airbnb.css +103 -210
  74. data/vendor/assets/stylesheets/flatpickr/themes/confetti.css +102 -209
  75. data/vendor/assets/stylesheets/flatpickr/themes/dark.css +117 -224
  76. data/vendor/assets/stylesheets/flatpickr/themes/light.css +102 -209
  77. data/vendor/assets/stylesheets/flatpickr/themes/material_blue.css +102 -209
  78. data/vendor/assets/stylesheets/flatpickr/themes/material_green.css +102 -209
  79. data/vendor/assets/stylesheets/flatpickr/themes/material_orange.css +102 -209
  80. data/vendor/assets/stylesheets/flatpickr/themes/material_red.css +102 -209
  81. metadata +19 -12
  82. data/vendor/assets/stylesheets/flatpickr/rtl/flatpickr.min.css +0 -13
  83. data/vendor/assets/stylesheets/flatpickr/rtl/themes/airbnb.rtl.css +0 -946
  84. data/vendor/assets/stylesheets/flatpickr/rtl/themes/base16_flat.rtl.css +0 -869
  85. data/vendor/assets/stylesheets/flatpickr/rtl/themes/confetti.rtl.css +0 -883
  86. data/vendor/assets/stylesheets/flatpickr/rtl/themes/dark.rtl.css +0 -869
  87. data/vendor/assets/stylesheets/flatpickr/rtl/themes/material_blue.rtl.css +0 -883
  88. data/vendor/assets/stylesheets/flatpickr/rtl/themes/material_green.rtl.css +0 -883
  89. data/vendor/assets/stylesheets/flatpickr/rtl/themes/material_orange.rtl.css +0 -883
  90. data/vendor/assets/stylesheets/flatpickr/rtl/themes/material_red.rtl.css +0 -883
@@ -0,0 +1,31 @@
1
+ /* flatpickr v4.5.2, @license MIT */
2
+ (function (global, factory) {
3
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
+ typeof define === 'function' && define.amd ? define(factory) :
5
+ (global.labelPlugin = factory());
6
+ }(this, (function () { 'use strict';
7
+
8
+ function labelPlugin() {
9
+ return function (fp) {
10
+ return {
11
+ onReady() {
12
+ const id = fp.input.id;
13
+ if (!id) {
14
+ return;
15
+ }
16
+ if (fp.mobileInput) {
17
+ fp.input.removeAttribute("id");
18
+ fp.mobileInput.id = id;
19
+ }
20
+ else if (fp.altInput) {
21
+ fp.input.removeAttribute("id");
22
+ fp.altInput.id = id;
23
+ }
24
+ },
25
+ };
26
+ };
27
+ }
28
+
29
+ return labelPlugin;
30
+
31
+ })));
@@ -0,0 +1,281 @@
1
+ /* flatpickr v4.5.2, @license MIT */
2
+ (function (global, factory) {
3
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
+ typeof define === 'function' && define.amd ? define(factory) :
5
+ (global.minMaxTimePlugin = factory());
6
+ }(this, (function () { 'use strict';
7
+
8
+ const pad = (number) => `0${number}`.slice(-2);
9
+ const int = (bool) => (bool === true ? 1 : 0);
10
+
11
+ const monthToStr = (monthNumber, shorthand, locale) => locale.months[shorthand ? "shorthand" : "longhand"][monthNumber];
12
+ const formats = {
13
+ Z: (date) => date.toISOString(),
14
+ D: function (date, locale, options) {
15
+ return locale.weekdays.shorthand[formats.w(date, locale, options)];
16
+ },
17
+ F: function (date, locale, options) {
18
+ return monthToStr(formats.n(date, locale, options) - 1, false, locale);
19
+ },
20
+ G: function (date, locale, options) {
21
+ return pad(formats.h(date, locale, options));
22
+ },
23
+ H: (date) => pad(date.getHours()),
24
+ J: function (date, locale) {
25
+ return locale.ordinal !== undefined
26
+ ? date.getDate() + locale.ordinal(date.getDate())
27
+ : date.getDate();
28
+ },
29
+ K: (date, locale) => locale.amPM[int(date.getHours() > 11)],
30
+ M: function (date, locale) {
31
+ return monthToStr(date.getMonth(), true, locale);
32
+ },
33
+ S: (date) => pad(date.getSeconds()),
34
+ U: (date) => date.getTime() / 1000,
35
+ W: function (date, _, options) {
36
+ return options.getWeek(date);
37
+ },
38
+ Y: (date) => date.getFullYear(),
39
+ d: (date) => pad(date.getDate()),
40
+ h: (date) => (date.getHours() % 12 ? date.getHours() % 12 : 12),
41
+ i: (date) => pad(date.getMinutes()),
42
+ j: (date) => date.getDate(),
43
+ l: function (date, locale) {
44
+ return locale.weekdays.longhand[date.getDay()];
45
+ },
46
+ m: (date) => pad(date.getMonth() + 1),
47
+ n: (date) => date.getMonth() + 1,
48
+ s: (date) => date.getSeconds(),
49
+ w: (date) => date.getDay(),
50
+ y: (date) => String(date.getFullYear()).substring(2),
51
+ };
52
+
53
+ const defaults = {
54
+ _disable: [],
55
+ _enable: [],
56
+ allowInput: false,
57
+ altFormat: "F j, Y",
58
+ altInput: false,
59
+ altInputClass: "form-control input",
60
+ animate: typeof window === "object" &&
61
+ window.navigator.userAgent.indexOf("MSIE") === -1,
62
+ ariaDateFormat: "F j, Y",
63
+ clickOpens: true,
64
+ closeOnSelect: true,
65
+ conjunction: ", ",
66
+ dateFormat: "Y-m-d",
67
+ defaultHour: 12,
68
+ defaultMinute: 0,
69
+ defaultSeconds: 0,
70
+ disable: [],
71
+ disableMobile: false,
72
+ enable: [],
73
+ enableSeconds: false,
74
+ enableTime: false,
75
+ errorHandler: (err) => typeof console !== "undefined" && console.warn(err),
76
+ getWeek,
77
+ hourIncrement: 1,
78
+ ignoredFocusElements: [],
79
+ inline: false,
80
+ locale: "default",
81
+ minuteIncrement: 5,
82
+ mode: "single",
83
+ 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>",
84
+ noCalendar: false,
85
+ now: new Date(),
86
+ onChange: [],
87
+ onClose: [],
88
+ onDayCreate: [],
89
+ onDestroy: [],
90
+ onKeyDown: [],
91
+ onMonthChange: [],
92
+ onOpen: [],
93
+ onParseConfig: [],
94
+ onReady: [],
95
+ onValueUpdate: [],
96
+ onYearChange: [],
97
+ onPreCalendarPosition: [],
98
+ plugins: [],
99
+ position: "auto",
100
+ positionElement: undefined,
101
+ 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>",
102
+ shorthandCurrentMonth: false,
103
+ showMonths: 1,
104
+ static: false,
105
+ time_24hr: false,
106
+ weekNumbers: false,
107
+ wrap: false,
108
+ };
109
+
110
+ const english = {
111
+ weekdays: {
112
+ shorthand: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
113
+ longhand: [
114
+ "Sunday",
115
+ "Monday",
116
+ "Tuesday",
117
+ "Wednesday",
118
+ "Thursday",
119
+ "Friday",
120
+ "Saturday",
121
+ ],
122
+ },
123
+ months: {
124
+ shorthand: [
125
+ "Jan",
126
+ "Feb",
127
+ "Mar",
128
+ "Apr",
129
+ "May",
130
+ "Jun",
131
+ "Jul",
132
+ "Aug",
133
+ "Sep",
134
+ "Oct",
135
+ "Nov",
136
+ "Dec",
137
+ ],
138
+ longhand: [
139
+ "January",
140
+ "February",
141
+ "March",
142
+ "April",
143
+ "May",
144
+ "June",
145
+ "July",
146
+ "August",
147
+ "September",
148
+ "October",
149
+ "November",
150
+ "December",
151
+ ],
152
+ },
153
+ daysInMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
154
+ firstDayOfWeek: 0,
155
+ ordinal: (nth) => {
156
+ const s = nth % 100;
157
+ if (s > 3 && s < 21)
158
+ return "th";
159
+ switch (s % 10) {
160
+ case 1:
161
+ return "st";
162
+ case 2:
163
+ return "nd";
164
+ case 3:
165
+ return "rd";
166
+ default:
167
+ return "th";
168
+ }
169
+ },
170
+ rangeSeparator: " to ",
171
+ weekAbbreviation: "Wk",
172
+ scrollTitle: "Scroll to increment",
173
+ toggleTitle: "Click to toggle",
174
+ amPM: ["AM", "PM"],
175
+ yearAriaLabel: "Year",
176
+ };
177
+
178
+ const createDateFormatter = ({ config = defaults, l10n = english, }) => (dateObj, frmt, overrideLocale) => {
179
+ const locale = overrideLocale || l10n;
180
+ if (config.formatDate !== undefined) {
181
+ return config.formatDate(dateObj, frmt, locale);
182
+ }
183
+ return frmt
184
+ .split("")
185
+ .map((c, i, arr) => formats[c] && arr[i - 1] !== "\\"
186
+ ? formats[c](dateObj, locale, config)
187
+ : c !== "\\"
188
+ ? c
189
+ : "")
190
+ .join("");
191
+ };
192
+ function compareDates(date1, date2, timeless = true) {
193
+ if (timeless !== false) {
194
+ return (new Date(date1.getTime()).setHours(0, 0, 0, 0) -
195
+ new Date(date2.getTime()).setHours(0, 0, 0, 0));
196
+ }
197
+ return date1.getTime() - date2.getTime();
198
+ }
199
+ function compareTimes(date1, date2) {
200
+ return (3600 * (date1.getHours() - date2.getHours()) +
201
+ 60 * (date1.getMinutes() - date2.getMinutes()) +
202
+ date1.getSeconds() -
203
+ date2.getSeconds());
204
+ }
205
+ const getWeek = (givenDate) => {
206
+ const date = new Date(givenDate.getTime());
207
+ date.setHours(0, 0, 0, 0);
208
+ date.setDate(date.getDate() + 3 - ((date.getDay() + 6) % 7));
209
+ var week1 = new Date(date.getFullYear(), 0, 4);
210
+ return (1 +
211
+ Math.round(((date.getTime() - week1.getTime()) / 86400000 -
212
+ 3 +
213
+ ((week1.getDay() + 6) % 7)) /
214
+ 7));
215
+ };
216
+
217
+ function minMaxTimePlugin(config = {}) {
218
+ const state = {
219
+ formatDate: createDateFormatter({}),
220
+ tableDateFormat: config.tableDateFormat || "Y-m-d",
221
+ defaults: {
222
+ minTime: undefined,
223
+ maxTime: undefined,
224
+ },
225
+ };
226
+ function findDateTimeLimit(date) {
227
+ if (config.table !== undefined) {
228
+ return config.table[state.formatDate(date, state.tableDateFormat)];
229
+ }
230
+ return config.getTimeLimits && config.getTimeLimits(date);
231
+ }
232
+ return function (fp) {
233
+ return {
234
+ onReady() {
235
+ state.formatDate = this.formatDate;
236
+ state.defaults = {
237
+ minTime: this.config.minTime && state.formatDate(this.config.minTime, "H:i"),
238
+ maxTime: this.config.maxTime && state.formatDate(this.config.maxTime, "H:i"),
239
+ };
240
+ },
241
+ onChange() {
242
+ const latest = this.latestSelectedDateObj;
243
+ const matchingTimeLimit = latest && findDateTimeLimit(latest);
244
+ if (latest && matchingTimeLimit !== undefined) {
245
+ this.set(matchingTimeLimit);
246
+ fp.config.minTime.setFullYear(latest.getFullYear());
247
+ fp.config.maxTime.setFullYear(latest.getFullYear());
248
+ fp.config.minTime.setMonth(latest.getMonth());
249
+ fp.config.maxTime.setMonth(latest.getMonth());
250
+ fp.config.minTime.setDate(latest.getDate());
251
+ fp.config.maxTime.setDate(latest.getDate());
252
+ if (compareDates(latest, fp.config.maxTime, false) > 0) {
253
+ fp.setDate(new Date(latest.getTime()).setHours(fp.config.maxTime.getHours(), fp.config.maxTime.getMinutes(), fp.config.maxTime.getSeconds(), fp.config.maxTime.getMilliseconds()), false);
254
+ }
255
+ else if (compareDates(latest, fp.config.minTime, false) < 0)
256
+ fp.setDate(new Date(latest.getTime()).setHours(fp.config.minTime.getHours(), fp.config.minTime.getMinutes(), fp.config.minTime.getSeconds(), fp.config.minTime.getMilliseconds()), false);
257
+ }
258
+ else {
259
+ const newMinMax = state.defaults || {
260
+ minTime: undefined,
261
+ maxTime: undefined,
262
+ };
263
+ this.set(newMinMax);
264
+ if (!latest)
265
+ return;
266
+ const { minTime, maxTime } = fp.config;
267
+ if (minTime && compareTimes(latest, minTime) < 0) {
268
+ fp.setDate(new Date(latest.getTime()).setHours(minTime.getHours(), minTime.getMinutes(), minTime.getSeconds(), minTime.getMilliseconds()), false);
269
+ }
270
+ else if (maxTime && compareTimes(latest, maxTime) > 0) {
271
+ fp.setDate(new Date(latest.getTime()).setHours(maxTime.getHours(), maxTime.getMinutes(), maxTime.getSeconds(), maxTime.getMilliseconds()));
272
+ }
273
+ }
274
+ },
275
+ };
276
+ };
277
+ }
278
+
279
+ return minMaxTimePlugin;
280
+
281
+ })));
@@ -0,0 +1,77 @@
1
+ /* flatpickr v4.5.2, @license MIT */
2
+ (function (global, factory) {
3
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
+ typeof define === 'function' && define.amd ? define(factory) :
5
+ (global.monthSelect = factory());
6
+ }(this, (function () { 'use strict';
7
+
8
+ function monthSelectPlugin() {
9
+ return function (fp) {
10
+ var days;
11
+ function onDayHover(event) {
12
+ if (!event.target ||
13
+ !event.target.classList.contains("flatpickr-day"))
14
+ return;
15
+ const dayIndex = Array.prototype.indexOf.call(days, event.target);
16
+ fp.monthStartDay = new Date(days[dayIndex].dateObj.getFullYear(), days[dayIndex].dateObj.getMonth(), 1, 0, 0, 0, 0).getTime();
17
+ fp.monthEndDay = new Date(days[dayIndex].dateObj.getFullYear(), days[dayIndex].dateObj.getMonth() + 1, 0, 0, 0, 0, 0).getTime();
18
+ for (var i = days.length; i--;) {
19
+ var date = days[i].dateObj.getTime();
20
+ if (date > fp.monthEndDay || date < fp.monthStartDay)
21
+ days[i].classList.remove("inRange");
22
+ else
23
+ days[i].classList.add("inRange");
24
+ if (date != fp.monthEndDay)
25
+ days[i].classList.remove("endRange");
26
+ else
27
+ days[i].classList.add("endRange");
28
+ if (date != fp.monthStartDay)
29
+ days[i].classList.remove("startRange");
30
+ else
31
+ days[i].classList.add("startRange");
32
+ }
33
+ }
34
+ function highlightMonth() {
35
+ for (var i = days.length; i--;) {
36
+ var date = days[i].dateObj.getTime();
37
+ if (date >= fp.monthStartDay && date <= fp.monthEndDay)
38
+ days[i].classList.add("month", "selected");
39
+ if (date != fp.monthEndDay)
40
+ days[i].classList.remove("endRange");
41
+ else
42
+ days[i].classList.add("endRange");
43
+ if (date != fp.monthStartDay)
44
+ days[i].classList.remove("startRange");
45
+ else
46
+ days[i].classList.add("startRange");
47
+ }
48
+ }
49
+ function clearHover() {
50
+ for (var i = days.length; i--;) {
51
+ days[i].classList.remove("inRange");
52
+ }
53
+ }
54
+ return {
55
+ onChange: highlightMonth,
56
+ onMonthChange: highlightMonth,
57
+ onClose: clearHover,
58
+ onParseConfig: function onParseConfig() {
59
+ fp.config.mode = "single";
60
+ fp.config.enableTime = false;
61
+ },
62
+ onReady: [
63
+ function () {
64
+ days = fp.days.childNodes;
65
+ },
66
+ function () {
67
+ return fp.days.addEventListener("mouseover", onDayHover);
68
+ },
69
+ highlightMonth,
70
+ ],
71
+ };
72
+ };
73
+ }
74
+
75
+ return monthSelectPlugin;
76
+
77
+ })));
@@ -0,0 +1,138 @@
1
+ /* flatpickr v4.5.2, @license MIT */
2
+ (function (global, factory) {
3
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
+ typeof define === 'function' && define.amd ? define(factory) :
5
+ (global.rangePlugin = factory());
6
+ }(this, (function () { 'use strict';
7
+
8
+ function rangePlugin(config = {}) {
9
+ return function (fp) {
10
+ let dateFormat = "", secondInput, _firstInputFocused, _secondInputFocused, _prevDates;
11
+ const createSecondInput = () => {
12
+ if (config.input) {
13
+ secondInput =
14
+ config.input instanceof Element
15
+ ? config.input
16
+ : window.document.querySelector(config.input);
17
+ }
18
+ else {
19
+ secondInput = fp._input.cloneNode();
20
+ secondInput.removeAttribute("id");
21
+ secondInput._flatpickr = undefined;
22
+ }
23
+ if (secondInput.value) {
24
+ const parsedDate = fp.parseDate(secondInput.value);
25
+ if (parsedDate)
26
+ fp.selectedDates.push(parsedDate);
27
+ }
28
+ secondInput.setAttribute("data-fp-omit", "");
29
+ fp._bind(secondInput, ["focus", "click"], () => {
30
+ if (fp.selectedDates[1]) {
31
+ fp.latestSelectedDateObj = fp.selectedDates[1];
32
+ fp._setHoursFromDate(fp.selectedDates[1]);
33
+ fp.jumpToDate(fp.selectedDates[1]);
34
+ }
35
+ [_firstInputFocused, _secondInputFocused] = [false, true];
36
+ fp.isOpen = false;
37
+ fp.open(undefined, secondInput);
38
+ });
39
+ fp._bind(fp._input, ["focus", "click"], (e) => {
40
+ e.preventDefault();
41
+ fp.isOpen = false;
42
+ fp.open();
43
+ });
44
+ if (fp.config.allowInput)
45
+ fp._bind(secondInput, "keydown", (e) => {
46
+ if (e.key === "Enter") {
47
+ fp.setDate([fp.selectedDates[0], secondInput.value], true, dateFormat);
48
+ secondInput.click();
49
+ }
50
+ });
51
+ if (!config.input)
52
+ fp._input.parentNode &&
53
+ fp._input.parentNode.insertBefore(secondInput, fp._input.nextSibling);
54
+ };
55
+ const plugin = {
56
+ onParseConfig() {
57
+ fp.config.mode = "range";
58
+ dateFormat = fp.config.altInput
59
+ ? fp.config.altFormat
60
+ : fp.config.dateFormat;
61
+ },
62
+ onReady() {
63
+ createSecondInput();
64
+ fp.config.ignoredFocusElements.push(secondInput);
65
+ if (fp.config.allowInput) {
66
+ fp._input.removeAttribute("readonly");
67
+ secondInput.removeAttribute("readonly");
68
+ }
69
+ else {
70
+ secondInput.setAttribute("readonly", "readonly");
71
+ }
72
+ fp._bind(fp._input, "focus", () => {
73
+ fp.latestSelectedDateObj = fp.selectedDates[0];
74
+ fp._setHoursFromDate(fp.selectedDates[0]);
75
+ [_firstInputFocused, _secondInputFocused] = [true, false];
76
+ fp.jumpToDate(fp.selectedDates[0]);
77
+ });
78
+ if (fp.config.allowInput)
79
+ fp._bind(fp._input, "keydown", (e) => {
80
+ if (e.key === "Enter")
81
+ fp.setDate([fp._input.value, fp.selectedDates[1]], true, dateFormat);
82
+ });
83
+ fp.setDate(fp.selectedDates, false);
84
+ plugin.onValueUpdate(fp.selectedDates);
85
+ },
86
+ onPreCalendarPosition() {
87
+ if (_secondInputFocused) {
88
+ fp._positionElement = secondInput;
89
+ setTimeout(() => {
90
+ fp._positionElement = fp._input;
91
+ }, 0);
92
+ }
93
+ },
94
+ onChange() {
95
+ if (!fp.selectedDates.length) {
96
+ setTimeout(() => {
97
+ if (fp.selectedDates.length)
98
+ return;
99
+ secondInput.value = "";
100
+ _prevDates = [];
101
+ }, 10);
102
+ }
103
+ if (_secondInputFocused) {
104
+ setTimeout(() => {
105
+ secondInput.focus();
106
+ }, 0);
107
+ }
108
+ },
109
+ onDestroy() {
110
+ if (!config.input)
111
+ secondInput.parentNode &&
112
+ secondInput.parentNode.removeChild(secondInput);
113
+ },
114
+ onValueUpdate(selDates) {
115
+ if (!secondInput)
116
+ return;
117
+ _prevDates =
118
+ !_prevDates || selDates.length >= _prevDates.length
119
+ ? [...selDates]
120
+ : _prevDates;
121
+ if (_prevDates.length > selDates.length) {
122
+ const newSelectedDate = selDates[0];
123
+ const newDates = _secondInputFocused
124
+ ? [_prevDates[0], newSelectedDate]
125
+ : [newSelectedDate, _prevDates[1]];
126
+ fp.setDate(newDates, false);
127
+ _prevDates = [...newDates];
128
+ }
129
+ [fp._input.value = "", secondInput.value = ""] = fp.selectedDates.map(d => fp.formatDate(d, dateFormat));
130
+ },
131
+ };
132
+ return plugin;
133
+ };
134
+ }
135
+
136
+ return rangePlugin;
137
+
138
+ })));