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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d86d03cd7b9bfdfaf953583d17201a69956c9eab
4
- data.tar.gz: d8d0c435b5a68da661d1230f46adde633af60be7
2
+ SHA256:
3
+ metadata.gz: aefb1f8a878822368904ed5062434b61de40956de54b594e7d4f0e31fc3da7ac
4
+ data.tar.gz: 68ccc9dde42a26165d783812ae84134289d87717faae9b272040826acbbf11cd
5
5
  SHA512:
6
- metadata.gz: b1e6c80b0c671a1ccff19aac836617f2b266ff84eb723caf829186883e78d249c723d2cfe52150711f91efa1279ccf24918a93b36b6c63518113da7df3a30a50
7
- data.tar.gz: f4894411c55c26c576865595e8fc8101be617cc5a9a582d983d6c96098eaaa9b0b844126184da0589c19513eafd19d847c0b6d8f9ef4e9b9de94e8c40861aa3c
6
+ metadata.gz: f631d6b2e23ef445c3f987994528edc44ce718377a6f55cbf915d338a773dc9a30f6bd86bcb6829cb8e70b1e3c9971afeae485730a5663a534c16c1dd9e69959
7
+ data.tar.gz: c5401ef23e14e15057dcb662391cfc659c23e1f658295408a9607f84e565f375c9591ddab046da32b69f489852c705253a008a4d736999f06c3cd9c9e0f47c80
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Zoran Pesic
3
+ Copyright (c) 2018 Zoran Pesic
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -20,7 +20,7 @@ $ bundle
20
20
 
21
21
  In your application.css, add the following:
22
22
 
23
- ```sass
23
+ ```
24
24
  *= require flatpickr
25
25
 
26
26
  /* Optionally, you can include any of the flatpickr themes by adding in their styles, like so: */
@@ -32,17 +32,36 @@ And in your application.js:
32
32
  ```js
33
33
  //= require flatpickr
34
34
  //
35
- // Locales can be included like so:
35
+ // Locales can be included as well:
36
36
  //= require flatpickr/l10n/da
37
- ```
38
37
 
39
- To initialize flatpickr:
40
-
41
- ```js
42
38
  flatpickr('.your-selector');
43
39
 
44
40
  // if using jQuery
45
- $('.your-selector').flatpickr();
41
+ // $('.your-selector').flatpickr();
42
+ ```
43
+
44
+ #### Using Plugins
45
+
46
+ Flatpickr provides plugins which expand the library's functionality. To include the `confirmDate` plugin, for example, you must require the necessary assets and specify the plugin during initialization:
47
+
48
+ In your application.css:
49
+ ```
50
+ *= require flatpickr
51
+ *= require flatpickr/plugins/confirmDate/confirmDate
52
+ ```
53
+
54
+ In application.js:
55
+ ```js
56
+ //= require flatpickr
57
+ //= require flatpickr/plugins/confirmDate/confirmDate
58
+
59
+ flatpickr('.your-selector', {
60
+ enableTime: true,
61
+ plugins: [
62
+ new confirmDatePlugin({})
63
+ ]
64
+ })
46
65
  ```
47
66
 
48
67
  See [flatpickr's docs](https://chmln.github.io/flatpickr/) for configuration and usage info.
data/Rakefile CHANGED
@@ -1,28 +1,36 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
  require 'flatpickr/version'
4
6
 
5
7
  RSpec::Core::RakeTask.new(:spec)
6
8
 
7
- task :default => :spec
9
+ task default: :spec
8
10
 
9
11
  namespace :flatpickr do
10
12
  namespace :assets do
11
- desc 'Update Flatpickr\'s assets.'
13
+ desc 'Update Flatpickr assets from source.'
12
14
  task update: :clean do
13
15
  version = ARGV[1] || "v#{Flatpickr::VERSION.sub(/.\d+$/, '')}"
14
16
 
15
- sh 'git clone git@github.com:chmln/flatpickr.git flatpickr_source'
17
+ sh 'git clone git@github.com:flatpickr/flatpickr.git flatpickr_source'
16
18
  sh "cd flatpickr_source && git checkout tags/#{version}"
19
+ sh 'cd flatpickr_source && npm install && npm run build:pre && npm run build:build'
17
20
 
18
21
  sh 'cp flatpickr_source/dist/flatpickr.js vendor/assets/javascripts/flatpickr.js'
22
+ sh 'cp -R flatpickr_source/dist/plugins/ vendor/assets/javascripts/flatpickr/plugins/'
23
+ sh 'cd vendor/assets/javascripts/flatpickr/plugins/ && find . -name "*.css" -type f -delete'
19
24
  sh 'cp -R flatpickr_source/dist/l10n/ vendor/assets/javascripts/flatpickr/l10n/'
20
25
 
21
- sh 'cp flatpickr_source/dist/flatpickr.min.css vendor/assets/stylesheets/flatpickr.css'
22
- sh 'cp -R flatpickr_source/dist/rtl/ vendor/assets/stylesheets/flatpickr/rtl/'
26
+ sh 'cp flatpickr_source/dist/flatpickr.css vendor/assets/stylesheets/flatpickr.css'
27
+ sh 'cp -R flatpickr_source/dist/plugins/ vendor/assets/stylesheets/flatpickr/plugins/'
28
+ sh 'cd vendor/assets/stylesheets/flatpickr/plugins/ && find . -name "*.js" -type f -delete'
23
29
  sh 'cp -R flatpickr_source/dist/themes/ vendor/assets/stylesheets/flatpickr/themes/'
30
+ sh 'cp flatpickr_source/dist/ie.css vendor/assets/stylesheets/flatpickr/ie.css'
24
31
 
25
- puts "\n=*=*=*=*=*=*=*=*=*=*\n=* ASSETS UPDATED! *=\n=*=*=*=*=*=*=*=*=*=*\n"
32
+ puts "\n===============================\n"
33
+ puts "ASSETS UPDATED to #{version}! ✨"
26
34
  end
27
35
 
28
36
  desc 'Remove previous Flatpickr assets.'
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'flatpickr/version'
2
- require 'flatpickr/engine' if (defined?(Rails) && defined?(Rails::Engine))
4
+ require 'flatpickr/engine' if defined?(Rails) && defined?(Rails::Engine)
3
5
 
4
6
  module Flatpickr; end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Flatpickr
2
4
  class Engine < Rails::Engine
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Flatpickr
2
- VERSION = '3.0.7.0'
4
+ VERSION = '4.5.2.0'
3
5
  end
@@ -1,2351 +1,2215 @@
1
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
2
-
3
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
4
-
5
- /*! flatpickr v3.0.6, @license MIT */
6
- function FlatpickrInstance(element, config) {
7
- var self = this;
8
-
9
- self._ = {};
10
- self._.afterDayAnim = afterDayAnim;
11
- self._bind = bind;
12
- self._compareDates = compareDates;
13
- self._setHoursFromDate = setHoursFromDate;
14
- self.changeMonth = changeMonth;
15
- self.changeYear = changeYear;
16
- self.clear = clear;
17
- self.close = close;
18
- self._createElement = createElement;
19
- self.destroy = destroy;
20
- self.isEnabled = isEnabled;
21
- self.jumpToDate = jumpToDate;
22
- self.open = open;
23
- self.redraw = redraw;
24
- self.set = set;
25
- self.setDate = setDate;
26
- self.toggle = toggle;
27
-
28
- function init() {
29
- self.element = self.input = element;
30
- self.instanceConfig = config || {};
31
- self.parseDate = FlatpickrInstance.prototype.parseDate.bind(self);
32
- self.formatDate = FlatpickrInstance.prototype.formatDate.bind(self);
33
-
34
- setupFormats();
35
- parseConfig();
36
- setupLocale();
37
- setupInputs();
38
- setupDates();
39
- setupHelperFunctions();
40
-
41
- self.isOpen = false;
42
-
43
- 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);
44
-
45
- if (!self.isMobile) build();
46
-
47
- bindEvents();
48
-
49
- if (self.selectedDates.length || self.config.noCalendar) {
50
- if (self.config.enableTime) {
51
- setHoursFromDate(self.config.noCalendar ? self.latestSelectedDateObj || self.config.minDate : null);
52
- }
53
- updateValue(false);
54
- }
55
-
56
- self.showTimeInput = self.selectedDates.length > 0 || self.config.noCalendar;
57
-
58
- if (self.config.weekNumbers) {
59
- self.calendarContainer.style.width = self.daysContainer.offsetWidth + self.weekWrapper.offsetWidth + "px";
60
- }
61
-
62
- if (!self.isMobile) positionCalendar();
63
-
64
- triggerEvent("Ready");
65
- }
66
-
67
- /**
68
- * Binds a function to the current flatpickr instance
69
- * @param {Function} fn the function
70
- * @return {Function} the function bound to the instance
71
- */
72
- function bindToInstance(fn) {
73
- return fn.bind(self);
74
- }
75
-
76
- /**
77
- * The handler for all events targeting the time inputs
78
- * @param {Event} e the event - "input", "wheel", "increment", etc
79
- */
80
- function updateTime(e) {
81
- if (self.config.noCalendar && !self.selectedDates.length)
82
- // picking time only
83
- self.selectedDates = [self.now];
84
-
85
- timeWrapper(e);
86
-
87
- if (!self.selectedDates.length) return;
88
-
89
- if (!self.minDateHasTime || e.type !== "input" || e.target.value.length >= 2) {
90
- setHoursFromInputs();
91
- updateValue();
92
- } else {
93
- setTimeout(function () {
94
- setHoursFromInputs();
95
- updateValue();
96
- }, 1000);
97
- }
98
- }
99
-
100
- /**
101
- * Syncs the selected date object time with user's time input
102
- */
103
- function setHoursFromInputs() {
104
- if (!self.config.enableTime) return;
105
-
106
- var hours = (parseInt(self.hourElement.value, 10) || 0) % (self.amPM ? 12 : 24),
107
- minutes = (parseInt(self.minuteElement.value, 10) || 0) % 60,
108
- seconds = self.config.enableSeconds ? (parseInt(self.secondElement.value, 10) || 0) % 60 : 0;
109
-
110
- if (self.amPM !== undefined) hours = hours % 12 + 12 * (self.amPM.textContent === "PM");
111
-
112
- if (self.minDateHasTime && compareDates(self.latestSelectedDateObj, self.config.minDate) === 0) {
113
-
114
- hours = Math.max(hours, self.config.minDate.getHours());
115
- if (hours === self.config.minDate.getHours()) minutes = Math.max(minutes, self.config.minDate.getMinutes());
116
- }
117
-
118
- if (self.maxDateHasTime && compareDates(self.latestSelectedDateObj, self.config.maxDate) === 0) {
119
- hours = Math.min(hours, self.config.maxDate.getHours());
120
- if (hours === self.config.maxDate.getHours()) minutes = Math.min(minutes, self.config.maxDate.getMinutes());
121
- }
122
-
123
- setHours(hours, minutes, seconds);
124
- }
125
-
126
- /**
127
- * Syncs time input values with a date
128
- * @param {Date} dateObj the date to sync with
129
- */
130
- function setHoursFromDate(dateObj) {
131
- var date = dateObj || self.latestSelectedDateObj;
132
-
133
- if (date) setHours(date.getHours(), date.getMinutes(), date.getSeconds());
134
- }
135
-
136
- /**
137
- * Sets the hours, minutes, and optionally seconds
138
- * of the latest selected date object and the
139
- * corresponding time inputs
140
- * @param {Number} hours the hour. whether its military
141
- * or am-pm gets inferred from config
142
- * @param {Number} minutes the minutes
143
- * @param {Number} seconds the seconds (optional)
144
- */
145
- function setHours(hours, minutes, seconds) {
146
- if (self.selectedDates.length) {
147
- self.latestSelectedDateObj.setHours(hours % 24, minutes, seconds || 0, 0);
148
- }
149
-
150
- if (!self.config.enableTime || self.isMobile) return;
151
-
152
- self.hourElement.value = self.pad(!self.config.time_24hr ? (12 + hours) % 12 + 12 * (hours % 12 === 0) : hours);
153
-
154
- self.minuteElement.value = self.pad(minutes);
155
-
156
- if (!self.config.time_24hr) self.amPM.textContent = hours >= 12 ? "PM" : "AM";
157
-
158
- if (self.config.enableSeconds === true) self.secondElement.value = self.pad(seconds);
159
- }
160
-
161
- /**
162
- * Handles the year input and incrementing events
163
- * @param {Event} event the keyup or increment event
164
- */
165
- function onYearInput(event) {
166
- var year = event.target.value;
167
- if (event.delta) year = (parseInt(year) + event.delta).toString();
168
-
169
- if (year.length === 4 || event.key === "Enter") {
170
- self.currentYearElement.blur();
171
- if (!/[^\d]/.test(year)) changeYear(year);
172
- }
173
- }
174
-
175
- /**
176
- * Essentially addEventListener + tracking
177
- * @param {Element} element the element to addEventListener to
178
- * @param {String} event the event name
179
- * @param {Function} handler the event handler
180
- */
181
- function bind(element, event, handler) {
182
- if (event instanceof Array) return event.forEach(function (ev) {
183
- return bind(element, ev, handler);
184
- });
185
-
186
- if (element instanceof Array) return element.forEach(function (el) {
187
- return bind(el, event, handler);
188
- });
189
-
190
- element.addEventListener(event, handler);
191
- self._handlers.push({ element: element, event: event, handler: handler });
192
- }
193
-
194
- /**
195
- * A mousedown handler which mimics click.
196
- * Minimizes latency, since we don't need to wait for mouseup in most cases.
197
- * Also, avoids handling right clicks.
198
- *
199
- * @param {Function} handler the event handler
200
- */
201
- function onClick(handler) {
202
- return function (evt) {
203
- return evt.which === 1 && handler(evt);
204
- };
205
- }
206
-
207
- /**
208
- * Adds all the necessary event listeners
209
- */
210
- function bindEvents() {
211
- self._handlers = [];
212
- self._animationLoop = [];
213
- if (self.config.wrap) {
214
- ["open", "close", "toggle", "clear"].forEach(function (evt) {
215
- Array.prototype.forEach.call(self.element.querySelectorAll("[data-" + evt + "]"), function (el) {
216
- return bind(el, "mousedown", onClick(self[evt]));
217
- });
218
- });
219
- }
220
-
221
- if (self.isMobile) return setupMobile();
222
-
223
- self.debouncedResize = debounce(onResize, 50);
224
- self.triggerChange = function () {
225
- triggerEvent("Change");
226
- };
227
- self.debouncedChange = debounce(self.triggerChange, 300);
228
-
229
- if (self.config.mode === "range" && self.daysContainer) bind(self.daysContainer, "mouseover", function (e) {
230
- return onMouseOver(e.target);
231
- });
232
-
233
- bind(window.document.body, "keydown", onKeyDown);
234
-
235
- if (!self.config.static) bind(self._input, "keydown", onKeyDown);
236
-
237
- if (!self.config.inline && !self.config.static) bind(window, "resize", self.debouncedResize);
238
-
239
- if (window.ontouchstart !== undefined) bind(window.document, "touchstart", documentClick);
240
-
241
- bind(window.document, "mousedown", onClick(documentClick));
242
- bind(self._input, "blur", documentClick);
243
-
244
- if (self.config.clickOpens === true) {
245
- bind(self._input, "focus", self.open);
246
- bind(self._input, "mousedown", onClick(self.open));
247
- }
248
-
249
- if (!self.config.noCalendar) {
250
- self.monthNav.addEventListener("wheel", function (e) {
251
- return e.preventDefault();
252
- });
253
- bind(self.monthNav, "wheel", debounce(onMonthNavScroll, 10));
254
- bind(self.monthNav, "mousedown", onClick(onMonthNavClick));
255
-
256
- bind(self.monthNav, ["keyup", "increment"], onYearInput);
257
- bind(self.daysContainer, "mousedown", onClick(selectDate));
258
-
259
- if (self.config.animate) {
260
- bind(self.daysContainer, ["webkitAnimationEnd", "animationend"], animateDays);
261
- bind(self.monthNav, ["webkitAnimationEnd", "animationend"], animateMonths);
262
- }
263
- }
264
-
265
- if (self.config.enableTime) {
266
- var selText = function selText(e) {
267
- return e.target.select();
268
- };
269
- bind(self.timeContainer, ["wheel", "input", "increment"], updateTime);
270
- bind(self.timeContainer, "mousedown", onClick(timeIncrement));
271
-
272
- bind(self.timeContainer, ["wheel", "increment"], self.debouncedChange);
273
- bind(self.timeContainer, "input", self.triggerChange);
274
-
275
- bind([self.hourElement, self.minuteElement], "focus", selText);
276
-
277
- if (self.secondElement !== undefined) bind(self.secondElement, "focus", function () {
278
- return self.secondElement.select();
279
- });
280
-
281
- if (self.amPM !== undefined) {
282
- bind(self.amPM, "mousedown", onClick(function (e) {
283
- updateTime(e);
284
- self.triggerChange(e);
285
- }));
286
- }
287
- }
288
- }
289
-
290
- function processPostDayAnimation() {
291
- for (var i = self._animationLoop.length; i--;) {
292
- self._animationLoop[i]();
293
- self._animationLoop.splice(i, 1);
294
- }
295
- }
296
-
297
- /**
298
- * Removes the day container that slided out of view
299
- * @param {Event} e the animation event
300
- */
301
- function animateDays(e) {
302
- if (self.daysContainer.childNodes.length > 1) {
303
- switch (e.animationName) {
304
- case "fpSlideLeft":
305
- self.daysContainer.lastChild.classList.remove("slideLeftNew");
306
- self.daysContainer.removeChild(self.daysContainer.firstChild);
307
- self.days = self.daysContainer.firstChild;
308
- processPostDayAnimation();
309
-
310
- break;
311
-
312
- case "fpSlideRight":
313
- self.daysContainer.firstChild.classList.remove("slideRightNew");
314
- self.daysContainer.removeChild(self.daysContainer.lastChild);
315
- self.days = self.daysContainer.firstChild;
316
- processPostDayAnimation();
317
-
318
- break;
319
-
320
- default:
321
- break;
322
- }
323
- }
324
- }
325
-
326
- /**
327
- * Removes the month element that animated out of view
328
- * @param {Event} e the animation event
329
- */
330
- function animateMonths(e) {
331
- switch (e.animationName) {
332
- case "fpSlideLeftNew":
333
- case "fpSlideRightNew":
334
- self.navigationCurrentMonth.classList.remove("slideLeftNew");
335
- self.navigationCurrentMonth.classList.remove("slideRightNew");
336
- var nav = self.navigationCurrentMonth;
337
-
338
- while (nav.nextSibling && /curr/.test(nav.nextSibling.className)) {
339
- self.monthNav.removeChild(nav.nextSibling);
340
- }while (nav.previousSibling && /curr/.test(nav.previousSibling.className)) {
341
- self.monthNav.removeChild(nav.previousSibling);
342
- }self.oldCurMonth = null;
343
- break;
344
- }
345
- }
346
-
347
- /**
348
- * Set the calendar view to a particular date.
349
- * @param {Date} jumpDate the date to set the view to
350
- */
351
- function jumpToDate(jumpDate) {
352
- jumpDate = jumpDate ? self.parseDate(jumpDate) : self.latestSelectedDateObj || (self.config.minDate > self.now ? self.config.minDate : self.config.maxDate && self.config.maxDate < self.now ? self.config.maxDate : self.now);
353
-
354
- try {
355
- self.currentYear = jumpDate.getFullYear();
356
- self.currentMonth = jumpDate.getMonth();
357
- } catch (e) {
358
- /* istanbul ignore next */
359
- console.error(e.stack);
360
- /* istanbul ignore next */
361
- console.warn("Invalid date supplied: " + jumpDate);
362
- }
363
-
364
- self.redraw();
365
- }
366
-
367
- /**
368
- * The up/down arrow handler for time inputs
369
- * @param {Event} e the click event
370
- */
371
- function timeIncrement(e) {
372
- if (~e.target.className.indexOf("arrow")) incrementNumInput(e, e.target.classList.contains("arrowUp") ? 1 : -1);
373
- }
374
-
375
- /**
376
- * Increments/decrements the value of input associ-
377
- * ated with the up/down arrow by dispatching an
378
- * "increment" event on the input.
379
- *
380
- * @param {Event} e the click event
381
- * @param {Number} delta the diff (usually 1 or -1)
382
- * @param {Element} inputElem the input element
383
- */
384
- function incrementNumInput(e, delta, inputElem) {
385
- var input = inputElem || e.target.parentNode.childNodes[0];
386
- var event = createEvent("increment");
387
- event.delta = delta;
388
- input.dispatchEvent(event);
389
- }
390
-
391
- function createNumberInput(inputClassName) {
392
- var wrapper = createElement("div", "numInputWrapper"),
393
- numInput = createElement("input", "numInput " + inputClassName),
394
- arrowUp = createElement("span", "arrowUp"),
395
- arrowDown = createElement("span", "arrowDown");
396
-
397
- numInput.type = "text";
398
- numInput.pattern = "\\d*";
399
-
400
- wrapper.appendChild(numInput);
401
- wrapper.appendChild(arrowUp);
402
- wrapper.appendChild(arrowDown);
403
-
404
- return wrapper;
405
- }
406
-
407
- function build() {
408
- var fragment = window.document.createDocumentFragment();
409
- self.calendarContainer = createElement("div", "flatpickr-calendar");
410
- self.calendarContainer.tabIndex = -1;
411
-
412
- if (!self.config.noCalendar) {
413
- fragment.appendChild(buildMonthNav());
414
- self.innerContainer = createElement("div", "flatpickr-innerContainer");
415
-
416
- if (self.config.weekNumbers) self.innerContainer.appendChild(buildWeeks());
417
-
418
- self.rContainer = createElement("div", "flatpickr-rContainer");
419
- self.rContainer.appendChild(buildWeekdays());
420
-
421
- if (!self.daysContainer) {
422
- self.daysContainer = createElement("div", "flatpickr-days");
423
- self.daysContainer.tabIndex = -1;
424
- }
425
-
426
- buildDays();
427
- self.rContainer.appendChild(self.daysContainer);
428
-
429
- self.innerContainer.appendChild(self.rContainer);
430
- fragment.appendChild(self.innerContainer);
431
- }
432
-
433
- if (self.config.enableTime) fragment.appendChild(buildTime());
434
-
435
- toggleClass(self.calendarContainer, "rangeMode", self.config.mode === "range");
436
- toggleClass(self.calendarContainer, "animate", self.config.animate);
437
-
438
- self.calendarContainer.appendChild(fragment);
439
-
440
- var customAppend = self.config.appendTo && self.config.appendTo.nodeType;
441
-
442
- if (self.config.inline || self.config.static) {
443
- self.calendarContainer.classList.add(self.config.inline ? "inline" : "static");
444
-
445
- if (self.config.inline && !customAppend) {
446
- return self.element.parentNode.insertBefore(self.calendarContainer, self._input.nextSibling);
447
- }
448
-
449
- if (self.config.static) {
450
- var wrapper = createElement("div", "flatpickr-wrapper");
451
- self.element.parentNode.insertBefore(wrapper, self.element);
452
- wrapper.appendChild(self.element);
453
-
454
- if (self.altInput) wrapper.appendChild(self.altInput);
455
-
456
- wrapper.appendChild(self.calendarContainer);
457
- return;
458
- }
459
- }
460
-
461
- (customAppend ? self.config.appendTo : window.document.body).appendChild(self.calendarContainer);
462
- }
463
-
464
- function createDay(className, date, dayNumber, i) {
465
- var dateIsEnabled = isEnabled(date, true),
466
- dayElement = createElement("span", "flatpickr-day " + className, date.getDate());
467
-
468
- dayElement.dateObj = date;
469
- dayElement.$i = i;
470
- dayElement.setAttribute("aria-label", self.formatDate(date, self.config.ariaDateFormat));
471
-
472
- if (compareDates(date, self.now) === 0) {
473
- self.todayDateElem = dayElement;
474
- dayElement.classList.add("today");
475
- }
476
-
477
- if (dateIsEnabled) {
478
- dayElement.tabIndex = -1;
479
- if (isDateSelected(date)) {
480
- dayElement.classList.add("selected");
481
- self.selectedDateElem = dayElement;
482
- if (self.config.mode === "range") {
483
- toggleClass(dayElement, "startRange", compareDates(date, self.selectedDates[0]) === 0);
484
-
485
- toggleClass(dayElement, "endRange", compareDates(date, self.selectedDates[1]) === 0);
486
- }
487
- }
488
- } else {
489
- dayElement.classList.add("disabled");
490
- if (self.selectedDates[0] && date > self.minRangeDate && date < self.selectedDates[0]) self.minRangeDate = date;else if (self.selectedDates[0] && date < self.maxRangeDate && date > self.selectedDates[0]) self.maxRangeDate = date;
491
- }
492
-
493
- if (self.config.mode === "range") {
494
- if (isDateInRange(date) && !isDateSelected(date)) dayElement.classList.add("inRange");
495
-
496
- if (self.selectedDates.length === 1 && (date < self.minRangeDate || date > self.maxRangeDate)) dayElement.classList.add("notAllowed");
497
- }
498
-
499
- if (self.config.weekNumbers && className !== "prevMonthDay" && dayNumber % 7 === 1) {
500
- self.weekNumbers.insertAdjacentHTML("beforeend", "<span class='disabled flatpickr-day'>" + self.config.getWeek(date) + "</span>");
501
- }
502
-
503
- triggerEvent("DayCreate", dayElement);
504
-
505
- return dayElement;
506
- }
507
-
508
- function focusOnDay(currentIndex, offset) {
509
- var newIndex = currentIndex + offset || 0,
510
- targetNode = currentIndex !== undefined ? self.days.childNodes[newIndex] : self.selectedDateElem || self.todayDateElem || self.days.childNodes[0],
511
- focus = function focus() {
512
- targetNode = targetNode || self.days.childNodes[newIndex];
513
- targetNode.focus();
514
-
515
- if (self.config.mode === "range") onMouseOver(targetNode);
516
- };
517
-
518
- if (targetNode === undefined && offset !== 0) {
519
- if (offset > 0) {
520
- self.changeMonth(1);
521
- newIndex = newIndex % 42;
522
- } else if (offset < 0) {
523
- self.changeMonth(-1);
524
- newIndex += 42;
525
- }
526
-
527
- return afterDayAnim(focus);
528
- }
529
-
530
- focus();
531
- }
532
-
533
- function afterDayAnim(fn) {
534
- if (self.config.animate === true) return self._animationLoop.push(fn);
535
- fn();
536
- }
537
-
538
- function buildDays(delta) {
539
- var firstOfMonth = (new Date(self.currentYear, self.currentMonth, 1).getDay() - self.l10n.firstDayOfWeek + 7) % 7,
540
- isRangeMode = self.config.mode === "range";
541
-
542
- self.prevMonthDays = self.utils.getDaysinMonth((self.currentMonth - 1 + 12) % 12);
543
- self.selectedDateElem = undefined;
544
- self.todayDateElem = undefined;
545
-
546
- var daysInMonth = self.utils.getDaysinMonth(),
547
- days = window.document.createDocumentFragment();
548
-
549
- var dayNumber = self.prevMonthDays + 1 - firstOfMonth,
550
- dayIndex = 0;
551
-
552
- if (self.config.weekNumbers && self.weekNumbers.firstChild) self.weekNumbers.textContent = "";
553
-
554
- if (isRangeMode) {
555
- // const dateLimits = self.config.enable.length || self.config.disable.length || self.config.mixDate || self.config.maxDate;
556
- self.minRangeDate = new Date(self.currentYear, self.currentMonth - 1, dayNumber);
557
- self.maxRangeDate = new Date(self.currentYear, self.currentMonth + 1, (42 - firstOfMonth) % daysInMonth);
558
- }
559
-
560
- // prepend days from the ending of previous month
561
- for (; dayNumber <= self.prevMonthDays; dayNumber++, dayIndex++) {
562
- days.appendChild(createDay("prevMonthDay", new Date(self.currentYear, self.currentMonth - 1, dayNumber), dayNumber, dayIndex));
563
- }
564
-
565
- // Start at 1 since there is no 0th day
566
- for (dayNumber = 1; dayNumber <= daysInMonth; dayNumber++, dayIndex++) {
567
- days.appendChild(createDay("", new Date(self.currentYear, self.currentMonth, dayNumber), dayNumber, dayIndex));
568
- }
569
-
570
- // append days from the next month
571
- for (var dayNum = daysInMonth + 1; dayNum <= 42 - firstOfMonth; dayNum++, dayIndex++) {
572
- days.appendChild(createDay("nextMonthDay", new Date(self.currentYear, self.currentMonth + 1, dayNum % daysInMonth), dayNum, dayIndex));
573
- }
574
-
575
- if (isRangeMode && self.selectedDates.length === 1 && days.childNodes[0]) {
576
- self._hidePrevMonthArrow = self._hidePrevMonthArrow || self.minRangeDate > days.childNodes[0].dateObj;
577
-
578
- self._hideNextMonthArrow = self._hideNextMonthArrow || self.maxRangeDate < new Date(self.currentYear, self.currentMonth + 1, 1);
579
- } else updateNavigationCurrentMonth();
580
-
581
- var dayContainer = createElement("div", "dayContainer");
582
- dayContainer.appendChild(days);
583
-
584
- if (!self.config.animate || delta === undefined) clearNode(self.daysContainer);else {
585
- while (self.daysContainer.childNodes.length > 1) {
586
- self.daysContainer.removeChild(self.daysContainer.firstChild);
587
- }
588
- }
589
-
590
- if (delta >= 0) self.daysContainer.appendChild(dayContainer);else self.daysContainer.insertBefore(dayContainer, self.daysContainer.firstChild);
591
-
592
- self.days = self.daysContainer.firstChild;
593
- return self.daysContainer;
594
- }
595
-
596
- function clearNode(node) {
597
- while (node.firstChild) {
598
- node.removeChild(node.firstChild);
599
- }
600
- }
601
-
602
- function buildMonthNav() {
603
- var monthNavFragment = window.document.createDocumentFragment();
604
- self.monthNav = createElement("div", "flatpickr-month");
605
-
606
- self.prevMonthNav = createElement("span", "flatpickr-prev-month");
607
- self.prevMonthNav.innerHTML = self.config.prevArrow;
608
-
609
- self.currentMonthElement = createElement("span", "cur-month");
610
- self.currentMonthElement.title = self.l10n.scrollTitle;
611
-
612
- var yearInput = createNumberInput("cur-year");
613
- self.currentYearElement = yearInput.childNodes[0];
614
- self.currentYearElement.title = self.l10n.scrollTitle;
615
-
616
- if (self.config.minDate) self.currentYearElement.min = self.config.minDate.getFullYear();
617
-
618
- if (self.config.maxDate) {
619
- self.currentYearElement.max = self.config.maxDate.getFullYear();
620
-
621
- self.currentYearElement.disabled = self.config.minDate && self.config.minDate.getFullYear() === self.config.maxDate.getFullYear();
622
- }
623
-
624
- self.nextMonthNav = createElement("span", "flatpickr-next-month");
625
- self.nextMonthNav.innerHTML = self.config.nextArrow;
626
-
627
- self.navigationCurrentMonth = createElement("span", "flatpickr-current-month");
628
- self.navigationCurrentMonth.appendChild(self.currentMonthElement);
629
- self.navigationCurrentMonth.appendChild(yearInput);
630
-
631
- monthNavFragment.appendChild(self.prevMonthNav);
632
- monthNavFragment.appendChild(self.navigationCurrentMonth);
633
- monthNavFragment.appendChild(self.nextMonthNav);
634
- self.monthNav.appendChild(monthNavFragment);
635
-
636
- Object.defineProperty(self, "_hidePrevMonthArrow", {
637
- get: function get() {
638
- return this.__hidePrevMonthArrow;
639
- },
640
- set: function set(bool) {
641
- if (this.__hidePrevMonthArrow !== bool) self.prevMonthNav.style.display = bool ? "none" : "block";
642
- this.__hidePrevMonthArrow = bool;
643
- }
644
- });
645
-
646
- Object.defineProperty(self, "_hideNextMonthArrow", {
647
- get: function get() {
648
- return this.__hideNextMonthArrow;
649
- },
650
- set: function set(bool) {
651
- if (this.__hideNextMonthArrow !== bool) self.nextMonthNav.style.display = bool ? "none" : "block";
652
- this.__hideNextMonthArrow = bool;
653
- }
654
- });
655
-
656
- updateNavigationCurrentMonth();
657
-
658
- return self.monthNav;
659
- }
660
-
661
- function buildTime() {
662
- self.calendarContainer.classList.add("hasTime");
663
- if (self.config.noCalendar) self.calendarContainer.classList.add("noCalendar");
664
- self.timeContainer = createElement("div", "flatpickr-time");
665
- self.timeContainer.tabIndex = -1;
666
- var separator = createElement("span", "flatpickr-time-separator", ":");
667
-
668
- var hourInput = createNumberInput("flatpickr-hour");
669
- self.hourElement = hourInput.childNodes[0];
670
-
671
- var minuteInput = createNumberInput("flatpickr-minute");
672
- self.minuteElement = minuteInput.childNodes[0];
673
-
674
- self.hourElement.tabIndex = self.minuteElement.tabIndex = -1;
675
-
676
- self.hourElement.value = self.pad(self.latestSelectedDateObj ? self.latestSelectedDateObj.getHours() : self.config.defaultHour % (self.time_24hr ? 24 : 12));
677
-
678
- self.minuteElement.value = self.pad(self.latestSelectedDateObj ? self.latestSelectedDateObj.getMinutes() : self.config.defaultMinute);
679
-
680
- self.hourElement.step = self.config.hourIncrement;
681
- self.minuteElement.step = self.config.minuteIncrement;
682
-
683
- self.hourElement.min = self.config.time_24hr ? 0 : 1;
684
- self.hourElement.max = self.config.time_24hr ? 23 : 12;
685
-
686
- self.minuteElement.min = 0;
687
- self.minuteElement.max = 59;
688
-
689
- self.hourElement.title = self.minuteElement.title = self.l10n.scrollTitle;
690
-
691
- self.timeContainer.appendChild(hourInput);
692
- self.timeContainer.appendChild(separator);
693
- self.timeContainer.appendChild(minuteInput);
694
-
695
- if (self.config.time_24hr) self.timeContainer.classList.add("time24hr");
696
-
697
- if (self.config.enableSeconds) {
698
- self.timeContainer.classList.add("hasSeconds");
699
-
700
- var secondInput = createNumberInput("flatpickr-second");
701
- self.secondElement = secondInput.childNodes[0];
702
-
703
- self.secondElement.value = self.pad(self.latestSelectedDateObj ? self.latestSelectedDateObj.getSeconds() : self.config.defaultSeconds);
704
-
705
- self.secondElement.step = self.minuteElement.step;
706
- self.secondElement.min = self.minuteElement.min;
707
- self.secondElement.max = self.minuteElement.max;
708
-
709
- self.timeContainer.appendChild(createElement("span", "flatpickr-time-separator", ":"));
710
- self.timeContainer.appendChild(secondInput);
711
- }
712
-
713
- if (!self.config.time_24hr) {
714
- // add self.amPM if appropriate
715
- self.amPM = createElement("span", "flatpickr-am-pm", ["AM", "PM"][(self.latestSelectedDateObj ? self.hourElement.value : self.config.defaultHour) > 11 | 0]);
716
- self.amPM.title = self.l10n.toggleTitle;
717
- self.amPM.tabIndex = -1;
718
- self.timeContainer.appendChild(self.amPM);
719
- }
720
-
721
- return self.timeContainer;
722
- }
723
-
724
- function buildWeekdays() {
725
- if (!self.weekdayContainer) self.weekdayContainer = createElement("div", "flatpickr-weekdays");
726
-
727
- var firstDayOfWeek = self.l10n.firstDayOfWeek;
728
- var weekdays = self.l10n.weekdays.shorthand.slice();
729
-
730
- if (firstDayOfWeek > 0 && firstDayOfWeek < weekdays.length) {
731
- weekdays = [].concat(weekdays.splice(firstDayOfWeek, weekdays.length), weekdays.splice(0, firstDayOfWeek));
732
- }
733
-
734
- self.weekdayContainer.innerHTML = "\n\t\t<span class=flatpickr-weekday>\n\t\t\t" + weekdays.join("</span><span class=flatpickr-weekday>") + "\n\t\t</span>\n\t\t";
735
-
736
- return self.weekdayContainer;
737
- }
738
-
739
- /* istanbul ignore next */
740
- function buildWeeks() {
741
- self.calendarContainer.classList.add("hasWeeks");
742
- self.weekWrapper = createElement("div", "flatpickr-weekwrapper");
743
- self.weekWrapper.appendChild(createElement("span", "flatpickr-weekday", self.l10n.weekAbbreviation));
744
- self.weekNumbers = createElement("div", "flatpickr-weeks");
745
- self.weekWrapper.appendChild(self.weekNumbers);
746
-
747
- return self.weekWrapper;
748
- }
749
-
750
- function changeMonth(value, is_offset, animate) {
751
- is_offset = is_offset === undefined || is_offset;
752
- var delta = is_offset ? value : value - self.currentMonth;
753
- var skipAnimations = !self.config.animate || animate === false;
754
-
755
- if (delta < 0 && self._hidePrevMonthArrow || delta > 0 && self._hideNextMonthArrow) return;
756
-
757
- self.currentMonth += delta;
758
-
759
- if (self.currentMonth < 0 || self.currentMonth > 11) {
760
- self.currentYear += self.currentMonth > 11 ? 1 : -1;
761
- self.currentMonth = (self.currentMonth + 12) % 12;
762
-
763
- triggerEvent("YearChange");
764
- }
765
-
766
- buildDays(!skipAnimations ? delta : undefined);
767
-
768
- if (skipAnimations) {
769
- triggerEvent("MonthChange");
770
- return updateNavigationCurrentMonth();
771
- }
772
-
773
- // remove possible remnants from clicking too fast
774
- var nav = self.navigationCurrentMonth;
775
- if (delta < 0) {
776
- while (nav.nextSibling && /curr/.test(nav.nextSibling.className)) {
777
- self.monthNav.removeChild(nav.nextSibling);
778
- }
779
- } else if (delta > 0) {
780
- while (nav.previousSibling && /curr/.test(nav.previousSibling.className)) {
781
- self.monthNav.removeChild(nav.previousSibling);
782
- }
783
- }
784
-
785
- self.oldCurMonth = self.navigationCurrentMonth;
786
-
787
- self.navigationCurrentMonth = self.monthNav.insertBefore(self.oldCurMonth.cloneNode(true), delta > 0 ? self.oldCurMonth.nextSibling : self.oldCurMonth);
788
-
789
- if (delta > 0) {
790
- self.daysContainer.firstChild.classList.add("slideLeft");
791
- self.daysContainer.lastChild.classList.add("slideLeftNew");
792
-
793
- self.oldCurMonth.classList.add("slideLeft");
794
- self.navigationCurrentMonth.classList.add("slideLeftNew");
795
- } else if (delta < 0) {
796
- self.daysContainer.firstChild.classList.add("slideRightNew");
797
- self.daysContainer.lastChild.classList.add("slideRight");
798
-
799
- self.oldCurMonth.classList.add("slideRight");
800
- self.navigationCurrentMonth.classList.add("slideRightNew");
801
- }
802
-
803
- self.currentMonthElement = self.navigationCurrentMonth.firstChild;
804
- self.currentYearElement = self.navigationCurrentMonth.lastChild.childNodes[0];
805
-
806
- updateNavigationCurrentMonth();
807
- self.oldCurMonth.firstChild.textContent = self.utils.monthToStr(self.currentMonth - delta);
808
-
809
- triggerEvent("MonthChange");
810
-
811
- if (document.activeElement && document.activeElement.$i) {
812
- var index = document.activeElement.$i;
813
- afterDayAnim(function () {
814
- focusOnDay(index, 0);
815
- });
816
- }
817
- }
818
-
819
- function clear(triggerChangeEvent) {
820
- self.input.value = "";
821
-
822
- if (self.altInput) self.altInput.value = "";
823
-
824
- if (self.mobileInput) self.mobileInput.value = "";
825
-
826
- self.selectedDates = [];
827
- self.latestSelectedDateObj = undefined;
828
- self.showTimeInput = false;
829
-
830
- self.redraw();
831
-
832
- if (triggerChangeEvent !== false)
833
- // triggerChangeEvent is true (default) or an Event
834
- triggerEvent("Change");
835
- }
836
-
837
- function close() {
838
- self.isOpen = false;
839
-
840
- if (!self.isMobile) {
841
- self.calendarContainer.classList.remove("open");
842
- self._input.classList.remove("active");
843
- }
844
-
845
- triggerEvent("Close");
846
- }
847
-
848
- function destroy() {
849
- if (self.config !== undefined) triggerEvent("Destroy");
850
-
851
- for (var i = self._handlers.length; i--;) {
852
- var h = self._handlers[i];
853
- h.element.removeEventListener(h.event, h.handler);
854
- }
855
-
856
- self._handlers = [];
857
-
858
- if (self.mobileInput) {
859
- if (self.mobileInput.parentNode) self.mobileInput.parentNode.removeChild(self.mobileInput);
860
- self.mobileInput = null;
861
- } else if (self.calendarContainer && self.calendarContainer.parentNode) self.calendarContainer.parentNode.removeChild(self.calendarContainer);
862
-
863
- if (self.altInput) {
864
- self.input.type = "text";
865
- if (self.altInput.parentNode) self.altInput.parentNode.removeChild(self.altInput);
866
- delete self.altInput;
867
- }
868
-
869
- if (self.input) {
870
- self.input.type = self.input._type;
871
- self.input.classList.remove("flatpickr-input");
872
- self.input.removeAttribute("readonly");
873
- self.input.value = "";
874
- }
875
-
876
- ["_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) {
877
- try {
878
- delete self[k];
879
- } catch (e) {}
880
- });
881
- }
882
-
883
- function isCalendarElem(elem) {
884
- if (self.config.appendTo && self.config.appendTo.contains(elem)) return true;
885
-
886
- return self.calendarContainer.contains(elem);
887
- }
888
-
889
- function documentClick(e) {
890
- if (self.isOpen && !self.config.inline) {
891
- var isCalendarElement = isCalendarElem(e.target);
892
- var isInput = e.target === self.input || e.target === self.altInput || self.element.contains(e.target) ||
893
- // web components
894
- e.path && e.path.indexOf && (~e.path.indexOf(self.input) || ~e.path.indexOf(self.altInput));
895
-
896
- var lostFocus = e.type === "blur" ? isInput && e.relatedTarget && !isCalendarElem(e.relatedTarget) : !isInput && !isCalendarElement;
897
-
898
- if (lostFocus && self.config.ignoredFocusElements.indexOf(e.target) === -1) {
899
- self.close();
900
-
901
- if (self.config.mode === "range" && self.selectedDates.length === 1) {
902
- self.clear(false);
903
- self.redraw();
904
- }
905
- }
906
- }
907
- }
908
-
909
- function changeYear(newYear) {
910
- if (!newYear || self.currentYearElement.min && newYear < self.currentYearElement.min || self.currentYearElement.max && newYear > self.currentYearElement.max) return;
911
-
912
- var newYearNum = parseInt(newYear, 10),
913
- isNewYear = self.currentYear !== newYearNum;
914
-
915
- self.currentYear = newYearNum || self.currentYear;
916
-
917
- if (self.config.maxDate && self.currentYear === self.config.maxDate.getFullYear()) {
918
- self.currentMonth = Math.min(self.config.maxDate.getMonth(), self.currentMonth);
919
- } else if (self.config.minDate && self.currentYear === self.config.minDate.getFullYear()) {
920
- self.currentMonth = Math.max(self.config.minDate.getMonth(), self.currentMonth);
921
- }
922
-
923
- if (isNewYear) {
924
- self.redraw();
925
- triggerEvent("YearChange");
926
- }
927
- }
928
-
929
- function isEnabled(date, timeless) {
930
- if (self.config.minDate && compareDates(date, self.config.minDate, timeless !== undefined ? timeless : !self.minDateHasTime) < 0 || self.config.maxDate && compareDates(date, self.config.maxDate, timeless !== undefined ? timeless : !self.maxDateHasTime) > 0) return false;
931
-
932
- if (!self.config.enable.length && !self.config.disable.length) return true;
933
-
934
- var dateToCheck = self.parseDate(date, null, true); // timeless
935
-
936
- var bool = self.config.enable.length > 0,
937
- array = bool ? self.config.enable : self.config.disable;
938
-
939
- for (var i = 0, d; i < array.length; i++) {
940
- d = array[i];
941
-
942
- if (d instanceof Function && d(dateToCheck)) // disabled by function
943
- return bool;else if (d instanceof Date && d.getTime() === dateToCheck.getTime())
944
- // disabled by date
945
- return bool;else if (typeof d === "string" && self.parseDate(d, null, true).getTime() === dateToCheck.getTime())
946
- // disabled by date string
947
- return bool;else if ( // disabled by range
948
- (typeof d === "undefined" ? "undefined" : _typeof(d)) === "object" && d.from && d.to && dateToCheck >= d.from && dateToCheck <= d.to) return bool;
949
- }
950
-
951
- return !bool;
952
- }
953
-
954
- function onKeyDown(e) {
955
- var isInput = e.target === self._input;
956
- var calendarElem = isCalendarElem(e.target);
957
- var allowInput = self.config.allowInput;
958
- var allowKeydown = self.isOpen && (!allowInput || !isInput);
959
- var allowInlineKeydown = self.config.inline && isInput && !allowInput;
960
-
961
- if (e.key === "Enter" && allowInput && isInput) {
962
- self.setDate(self._input.value, true, e.target === self.altInput ? self.config.altFormat : self.config.dateFormat);
963
- return e.target.blur();
964
- } else if (calendarElem || allowKeydown || allowInlineKeydown) {
965
- var isTimeObj = self.timeContainer && self.timeContainer.contains(e.target);
966
- switch (e.key) {
967
- case "Enter":
968
- if (isTimeObj) updateValue();else selectDate(e);
969
-
970
- break;
971
-
972
- case "Escape":
973
- // escape
974
- e.preventDefault();
975
- self.close();
976
- break;
977
-
978
- case "Backspace":
979
- case "Delete":
980
- if (!self.config.allowInput) self.clear();
981
- break;
982
-
983
- case "ArrowLeft":
984
- case "ArrowRight":
985
- if (!isTimeObj) {
986
- e.preventDefault();
987
-
988
- if (self.daysContainer) {
989
- var _delta = e.key === "ArrowRight" ? 1 : -1;
990
-
991
- if (!e.ctrlKey) focusOnDay(e.target.$i, _delta);else changeMonth(_delta, true);
992
- } else if (self.config.enableTime && !isTimeObj) self.hourElement.focus();
993
- }
994
-
995
- break;
996
-
997
- case "ArrowUp":
998
- case "ArrowDown":
999
- e.preventDefault();
1000
- var delta = e.key === "ArrowDown" ? 1 : -1;
1001
-
1002
- if (self.daysContainer) {
1003
- if (e.ctrlKey) {
1004
- changeYear(self.currentYear - delta);
1005
- focusOnDay(e.target.$i, 0);
1006
- } else if (!isTimeObj) focusOnDay(e.target.$i, delta * 7);
1007
- } else if (self.config.enableTime) {
1008
- if (!isTimeObj) self.hourElement.focus();
1009
- updateTime(e);
1010
- self.debouncedChange();
1011
- }
1012
-
1013
- break;
1014
-
1015
- case "Tab":
1016
- if (e.target === self.hourElement) {
1017
- e.preventDefault();
1018
- self.minuteElement.select();
1019
- } else if (e.target === self.minuteElement && (self.secondElement || self.amPM)) {
1020
- e.preventDefault();
1021
- (self.secondElement || self.amPM).focus();
1022
- } else if (e.target === self.secondElement) {
1023
- e.preventDefault();
1024
- self.amPM.focus();
1025
- }
1026
-
1027
- break;
1028
-
1029
- case "a":
1030
- if (e.target === self.amPM) {
1031
- self.amPM.textContent = "AM";
1032
- setHoursFromInputs();
1033
- updateValue();
1034
- }
1035
- break;
1036
-
1037
- case "p":
1038
- if (e.target === self.amPM) {
1039
- self.amPM.textContent = "PM";
1040
- setHoursFromInputs();
1041
- updateValue();
1042
- }
1043
- break;
1044
-
1045
- default:
1046
- break;
1047
-
1048
- }
1049
-
1050
- triggerEvent("KeyDown", e);
1051
- }
1052
- }
1053
-
1054
- function onMouseOver(elem) {
1055
- if (self.selectedDates.length !== 1 || !elem.classList.contains("flatpickr-day")) return;
1056
-
1057
- var hoverDate = elem.dateObj,
1058
- initialDate = self.parseDate(self.selectedDates[0], null, true),
1059
- rangeStartDate = Math.min(hoverDate.getTime(), self.selectedDates[0].getTime()),
1060
- rangeEndDate = Math.max(hoverDate.getTime(), self.selectedDates[0].getTime()),
1061
- containsDisabled = false;
1062
-
1063
- for (var t = rangeStartDate; t < rangeEndDate; t += self.utils.duration.DAY) {
1064
- if (!isEnabled(new Date(t))) {
1065
- containsDisabled = true;
1066
- break;
1067
- }
1068
- }
1069
-
1070
- var _loop = function _loop(timestamp, i) {
1071
- var outOfRange = timestamp < self.minRangeDate.getTime() || timestamp > self.maxRangeDate.getTime(),
1072
- dayElem = self.days.childNodes[i];
1073
-
1074
- if (outOfRange) {
1075
- self.days.childNodes[i].classList.add("notAllowed");
1076
- ["inRange", "startRange", "endRange"].forEach(function (c) {
1077
- dayElem.classList.remove(c);
1078
- });
1079
- return "continue";
1080
- } else if (containsDisabled && !outOfRange) return "continue";
1081
-
1082
- ["startRange", "inRange", "endRange", "notAllowed"].forEach(function (c) {
1083
- dayElem.classList.remove(c);
1084
- });
1085
-
1086
- var minRangeDate = Math.max(self.minRangeDate.getTime(), rangeStartDate),
1087
- maxRangeDate = Math.min(self.maxRangeDate.getTime(), rangeEndDate);
1088
-
1089
- elem.classList.add(hoverDate < self.selectedDates[0] ? "startRange" : "endRange");
1090
-
1091
- if (initialDate < hoverDate && timestamp === initialDate.getTime()) dayElem.classList.add("startRange");else if (initialDate > hoverDate && timestamp === initialDate.getTime()) dayElem.classList.add("endRange");
1092
-
1093
- if (timestamp >= minRangeDate && timestamp <= maxRangeDate) dayElem.classList.add("inRange");
1094
- };
1095
-
1096
- for (var timestamp = self.days.childNodes[0].dateObj.getTime(), i = 0; i < 42; i++, timestamp += self.utils.duration.DAY) {
1097
- var _ret = _loop(timestamp, i);
1098
-
1099
- if (_ret === "continue") continue;
1100
- }
1101
- }
1102
-
1103
- function onResize() {
1104
- if (self.isOpen && !self.config.static && !self.config.inline) positionCalendar();
1105
- }
1106
-
1107
- function open(e, positionElement) {
1108
- if (self.isMobile) {
1109
- if (e) {
1110
- e.preventDefault();
1111
- e.target.blur();
1112
- }
1113
-
1114
- setTimeout(function () {
1115
- self.mobileInput.click();
1116
- }, 0);
1117
-
1118
- triggerEvent("Open");
1119
- return;
1120
- }
1121
-
1122
- if (self.isOpen || self._input.disabled || self.config.inline) return;
1123
-
1124
- self.isOpen = true;
1125
- self.calendarContainer.classList.add("open");
1126
- positionCalendar(positionElement);
1127
- self._input.classList.add("active");
1128
-
1129
- triggerEvent("Open");
1130
- }
1131
-
1132
- function minMaxDateSetter(type) {
1133
- return function (date) {
1134
- var dateObj = self.config["_" + type + "Date"] = self.parseDate(date);
1135
-
1136
- var inverseDateObj = self.config["_" + (type === "min" ? "max" : "min") + "Date"];
1137
- var isValidDate = date && dateObj instanceof Date;
1138
-
1139
- if (isValidDate) {
1140
- self[type + "DateHasTime"] = dateObj.getHours() || dateObj.getMinutes() || dateObj.getSeconds();
1141
- }
1142
-
1143
- if (self.selectedDates) {
1144
- self.selectedDates = self.selectedDates.filter(function (d) {
1145
- return isEnabled(d);
1146
- });
1147
- if (!self.selectedDates.length && type === "min") setHoursFromDate(dateObj);
1148
- updateValue();
1149
- }
1150
-
1151
- if (self.daysContainer) {
1152
- redraw();
1153
-
1154
- if (isValidDate) self.currentYearElement[type] = dateObj.getFullYear();else self.currentYearElement.removeAttribute(type);
1155
-
1156
- self.currentYearElement.disabled = inverseDateObj && dateObj && inverseDateObj.getFullYear() === dateObj.getFullYear();
1157
- }
1158
- };
1159
- }
1160
-
1161
- function parseConfig() {
1162
- var boolOpts = ["wrap", "weekNumbers", "allowInput", "clickOpens", "time_24hr", "enableTime", "noCalendar", "altInput", "shorthandCurrentMonth", "inline", "static", "enableSeconds", "disableMobile"];
1163
-
1164
- var hooks = ["onChange", "onClose", "onDayCreate", "onDestroy", "onKeyDown", "onMonthChange", "onOpen", "onParseConfig", "onReady", "onValueUpdate", "onYearChange"];
1165
-
1166
- self.config = Object.create(flatpickr.defaultConfig);
1167
-
1168
- var userConfig = _extends({}, self.instanceConfig, JSON.parse(JSON.stringify(self.element.dataset || {})));
1169
-
1170
- self.config.parseDate = userConfig.parseDate;
1171
- self.config.formatDate = userConfig.formatDate;
1172
-
1173
- Object.defineProperty(self.config, "enable", {
1174
- get: function get() {
1175
- return self.config._enable || [];
1176
- },
1177
- set: function set(dates) {
1178
- return self.config._enable = parseDateRules(dates);
1179
- }
1180
- });
1181
-
1182
- Object.defineProperty(self.config, "disable", {
1183
- get: function get() {
1184
- return self.config._disable || [];
1185
- },
1186
- set: function set(dates) {
1187
- return self.config._disable = parseDateRules(dates);
1188
- }
1189
- });
1190
-
1191
- _extends(self.config, userConfig);
1192
-
1193
- if (!userConfig.dateFormat && userConfig.enableTime) {
1194
- self.config.dateFormat = self.config.noCalendar ? "H:i" + (self.config.enableSeconds ? ":S" : "") : flatpickr.defaultConfig.dateFormat + " H:i" + (self.config.enableSeconds ? ":S" : "");
1195
- }
1196
-
1197
- if (userConfig.altInput && userConfig.enableTime && !userConfig.altFormat) {
1198
- self.config.altFormat = self.config.noCalendar ? "h:i" + (self.config.enableSeconds ? ":S K" : " K") : flatpickr.defaultConfig.altFormat + (" h:i" + (self.config.enableSeconds ? ":S" : "") + " K");
1199
- }
1200
-
1201
- Object.defineProperty(self.config, "minDate", {
1202
- get: function get() {
1203
- return this._minDate;
1204
- },
1205
- set: minMaxDateSetter("min")
1206
- });
1207
-
1208
- Object.defineProperty(self.config, "maxDate", {
1209
- get: function get() {
1210
- return this._maxDate;
1211
- },
1212
- set: minMaxDateSetter("max")
1213
- });
1214
-
1215
- self.config.minDate = userConfig.minDate;
1216
- self.config.maxDate = userConfig.maxDate;
1217
-
1218
- for (var i = 0; i < boolOpts.length; i++) {
1219
- self.config[boolOpts[i]] = self.config[boolOpts[i]] === true || self.config[boolOpts[i]] === "true";
1220
- }for (var _i = hooks.length; _i--;) {
1221
- if (self.config[hooks[_i]] !== undefined) {
1222
- self.config[hooks[_i]] = arrayify(self.config[hooks[_i]] || []).map(bindToInstance);
1223
- }
1224
- }
1225
-
1226
- for (var _i2 = 0; _i2 < self.config.plugins.length; _i2++) {
1227
- var pluginConf = self.config.plugins[_i2](self) || {};
1228
- for (var key in pluginConf) {
1229
-
1230
- if (self.config[key] instanceof Array || ~hooks.indexOf(key)) {
1231
- self.config[key] = arrayify(pluginConf[key]).map(bindToInstance).concat(self.config[key]);
1232
- } else if (typeof userConfig[key] === "undefined") self.config[key] = pluginConf[key];
1233
- }
1234
- }
1235
-
1236
- triggerEvent("ParseConfig");
1237
- }
1238
-
1239
- function setupLocale() {
1240
- if (_typeof(self.config.locale) !== "object" && typeof flatpickr.l10ns[self.config.locale] === "undefined") console.warn("flatpickr: invalid locale " + self.config.locale);
1241
-
1242
- self.l10n = _extends(Object.create(flatpickr.l10ns.default), _typeof(self.config.locale) === "object" ? self.config.locale : self.config.locale !== "default" ? flatpickr.l10ns[self.config.locale] || {} : {});
1243
- }
1244
-
1245
- function positionCalendar() {
1246
- var positionElement = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : self._positionElement;
1247
-
1248
- if (self.calendarContainer === undefined) return;
1249
-
1250
- var calendarHeight = self.calendarContainer.offsetHeight,
1251
- calendarWidth = self.calendarContainer.offsetWidth,
1252
- configPos = self.config.position,
1253
- inputBounds = positionElement.getBoundingClientRect(),
1254
- distanceFromBottom = window.innerHeight - inputBounds.bottom,
1255
- showOnTop = configPos === "above" || configPos !== "below" && distanceFromBottom < calendarHeight && inputBounds.top > calendarHeight;
1256
-
1257
- var top = window.pageYOffset + inputBounds.top + (!showOnTop ? positionElement.offsetHeight + 2 : -calendarHeight - 2);
1258
-
1259
- toggleClass(self.calendarContainer, "arrowTop", !showOnTop);
1260
- toggleClass(self.calendarContainer, "arrowBottom", showOnTop);
1261
-
1262
- if (self.config.inline) return;
1263
-
1264
- var left = window.pageXOffset + inputBounds.left;
1265
- var right = window.document.body.offsetWidth - inputBounds.right;
1266
- var rightMost = left + calendarWidth > window.document.body.offsetWidth;
1267
-
1268
- toggleClass(self.calendarContainer, "rightMost", rightMost);
1269
-
1270
- if (self.config.static) return;
1271
-
1272
- self.calendarContainer.style.top = top + "px";
1273
-
1274
- if (!rightMost) {
1275
- self.calendarContainer.style.left = left + "px";
1276
- self.calendarContainer.style.right = "auto";
1277
- } else {
1278
- self.calendarContainer.style.left = "auto";
1279
- self.calendarContainer.style.right = right + "px";
1280
- }
1281
- }
1282
-
1283
- function redraw() {
1284
- if (self.config.noCalendar || self.isMobile) return;
1285
-
1286
- buildWeekdays();
1287
- updateNavigationCurrentMonth();
1288
- buildDays();
1289
- }
1290
-
1291
- function selectDate(e) {
1292
- e.preventDefault();
1293
- e.stopPropagation();
1294
-
1295
- if (!e.target.classList.contains("flatpickr-day") || e.target.classList.contains("disabled") || e.target.classList.contains("notAllowed")) return;
1296
-
1297
- var selectedDate = self.latestSelectedDateObj = new Date(e.target.dateObj.getTime());
1298
-
1299
- var shouldChangeMonth = selectedDate.getMonth() !== self.currentMonth && self.config.mode !== "range";
1300
-
1301
- self.selectedDateElem = e.target;
1302
-
1303
- if (self.config.mode === "single") self.selectedDates = [selectedDate];else if (self.config.mode === "multiple") {
1304
- var selectedIndex = isDateSelected(selectedDate);
1305
- if (selectedIndex) self.selectedDates.splice(selectedIndex, 1);else self.selectedDates.push(selectedDate);
1306
- } else if (self.config.mode === "range") {
1307
- if (self.selectedDates.length === 2) self.clear();
1308
-
1309
- self.selectedDates.push(selectedDate);
1310
-
1311
- // unless selecting same date twice, sort ascendingly
1312
- if (compareDates(selectedDate, self.selectedDates[0], true) !== 0) self.selectedDates.sort(function (a, b) {
1313
- return a.getTime() - b.getTime();
1314
- });
1315
- }
1316
-
1317
- setHoursFromInputs();
1318
-
1319
- if (shouldChangeMonth) {
1320
- var isNewYear = self.currentYear !== selectedDate.getFullYear();
1321
- self.currentYear = selectedDate.getFullYear();
1322
- self.currentMonth = selectedDate.getMonth();
1323
-
1324
- if (isNewYear) triggerEvent("YearChange");
1325
-
1326
- triggerEvent("MonthChange");
1327
- }
1328
-
1329
- buildDays();
1330
-
1331
- if (self.minDateHasTime && self.config.enableTime && compareDates(selectedDate, self.config.minDate) === 0) setHoursFromDate(self.config.minDate);
1332
-
1333
- updateValue();
1334
-
1335
- if (self.config.enableTime) setTimeout(function () {
1336
- return self.showTimeInput = true;
1337
- }, 50);
1338
-
1339
- if (self.config.mode === "range") {
1340
- if (self.selectedDates.length === 1) {
1341
- onMouseOver(e.target);
1342
-
1343
- self._hidePrevMonthArrow = self._hidePrevMonthArrow || self.minRangeDate > self.days.childNodes[0].dateObj;
1344
-
1345
- self._hideNextMonthArrow = self._hideNextMonthArrow || self.maxRangeDate < new Date(self.currentYear, self.currentMonth + 1, 1);
1346
- } else updateNavigationCurrentMonth();
1347
- }
1348
-
1349
- triggerEvent("Change");
1350
-
1351
- // maintain focus
1352
- if (!shouldChangeMonth) focusOnDay(e.target.$i, 0);else afterDayAnim(function () {
1353
- return self.selectedDateElem && self.selectedDateElem.focus();
1354
- });
1355
-
1356
- if (self.config.enableTime) setTimeout(function () {
1357
- return self.hourElement.select();
1358
- }, 451);
1359
-
1360
- if (self.config.closeOnSelect) {
1361
- var single = self.config.mode === "single" && !self.config.enableTime;
1362
- var range = self.config.mode === "range" && self.selectedDates.length === 2 && !self.config.enableTime;
1363
-
1364
- if (single || range) self.close();
1365
- }
1366
- }
1367
-
1368
- function set(option, value) {
1369
- if (option !== null && (typeof option === "undefined" ? "undefined" : _typeof(option)) === "object") _extends(self.config, option);else self.config[option] = value;
1370
-
1371
- self.redraw();
1372
- jumpToDate();
1373
- }
1374
-
1375
- function setSelectedDate(inputDate, format) {
1376
- if (inputDate instanceof Array) self.selectedDates = inputDate.map(function (d) {
1377
- return self.parseDate(d, format);
1378
- });else if (inputDate instanceof Date || !isNaN(inputDate)) self.selectedDates = [self.parseDate(inputDate, format)];else if (inputDate && inputDate.substring) {
1379
- switch (self.config.mode) {
1380
- case "single":
1381
- self.selectedDates = [self.parseDate(inputDate, format)];
1382
- break;
1383
-
1384
- case "multiple":
1385
- self.selectedDates = inputDate.split("; ").map(function (date) {
1386
- return self.parseDate(date, format);
1387
- });
1388
- break;
1389
-
1390
- case "range":
1391
- self.selectedDates = inputDate.split(self.l10n.rangeSeparator).map(function (date) {
1392
- return self.parseDate(date, format);
1393
- });
1394
-
1395
- break;
1396
-
1397
- default:
1398
- break;
1399
- }
1400
- }
1401
-
1402
- self.selectedDates = self.selectedDates.filter(function (d) {
1403
- return d instanceof Date && isEnabled(d, false);
1404
- });
1405
-
1406
- self.selectedDates.sort(function (a, b) {
1407
- return a.getTime() - b.getTime();
1408
- });
1409
- }
1410
-
1411
- function setDate(date, triggerChange, format) {
1412
- if (date !== 0 && !date) return self.clear(triggerChange);
1413
-
1414
- setSelectedDate(date, format);
1415
-
1416
- self.showTimeInput = self.selectedDates.length > 0;
1417
- self.latestSelectedDateObj = self.selectedDates[0];
1418
-
1419
- self.redraw();
1420
- jumpToDate();
1421
-
1422
- setHoursFromDate();
1423
- updateValue(triggerChange);
1424
-
1425
- if (triggerChange) triggerEvent("Change");
1426
- }
1427
-
1428
- function parseDateRules(arr) {
1429
- for (var i = arr.length; i--;) {
1430
- if (typeof arr[i] === "string" || +arr[i]) arr[i] = self.parseDate(arr[i], null, true);else if (arr[i] && arr[i].from && arr[i].to) {
1431
- arr[i].from = self.parseDate(arr[i].from);
1432
- arr[i].to = self.parseDate(arr[i].to);
1433
- }
1434
- }
1435
-
1436
- return arr.filter(function (x) {
1437
- return x;
1438
- }); // remove falsy values
1439
- }
1440
-
1441
- function setupDates() {
1442
- self.selectedDates = [];
1443
- self.now = new Date();
1444
-
1445
- var preloadedDate = self.config.defaultDate || self.input.value;
1446
- if (preloadedDate) setSelectedDate(preloadedDate, self.config.dateFormat);
1447
-
1448
- var initialDate = self.selectedDates.length ? self.selectedDates[0] : self.config.minDate && self.config.minDate.getTime() > self.now ? self.config.minDate : self.config.maxDate && self.config.maxDate.getTime() < self.now ? self.config.maxDate : self.now;
1449
-
1450
- self.currentYear = initialDate.getFullYear();
1451
- self.currentMonth = initialDate.getMonth();
1452
-
1453
- if (self.selectedDates.length) self.latestSelectedDateObj = self.selectedDates[0];
1454
-
1455
- self.minDateHasTime = self.config.minDate && (self.config.minDate.getHours() || self.config.minDate.getMinutes() || self.config.minDate.getSeconds());
1456
-
1457
- self.maxDateHasTime = self.config.maxDate && (self.config.maxDate.getHours() || self.config.maxDate.getMinutes() || self.config.maxDate.getSeconds());
1458
-
1459
- Object.defineProperty(self, "latestSelectedDateObj", {
1460
- get: function get() {
1461
- return self._selectedDateObj || self.selectedDates[self.selectedDates.length - 1];
1462
- },
1463
- set: function set(date) {
1464
- self._selectedDateObj = date;
1465
- }
1466
- });
1467
-
1468
- if (!self.isMobile) {
1469
- Object.defineProperty(self, "showTimeInput", {
1470
- get: function get() {
1471
- return self._showTimeInput;
1472
- },
1473
- set: function set(bool) {
1474
- self._showTimeInput = bool;
1475
- if (self.calendarContainer) toggleClass(self.calendarContainer, "showTimeInput", bool);
1476
- positionCalendar();
1477
- }
1478
- });
1479
- }
1480
- }
1481
-
1482
- function setupHelperFunctions() {
1483
- self.utils = {
1484
- duration: {
1485
- DAY: 86400000
1486
- },
1487
- getDaysinMonth: function getDaysinMonth(month, yr) {
1488
- month = typeof month === "undefined" ? self.currentMonth : month;
1489
-
1490
- yr = typeof yr === "undefined" ? self.currentYear : yr;
1491
-
1492
- if (month === 1 && (yr % 4 === 0 && yr % 100 !== 0 || yr % 400 === 0)) return 29;
1493
-
1494
- return self.l10n.daysInMonth[month];
1495
- },
1496
- monthToStr: function monthToStr(monthNumber, shorthand) {
1497
- shorthand = typeof shorthand === "undefined" ? self.config.shorthandCurrentMonth : shorthand;
1498
-
1499
- return self.l10n.months[(shorthand ? "short" : "long") + "hand"][monthNumber];
1500
- }
1501
- };
1502
- }
1503
-
1504
- /* istanbul ignore next */
1505
- function setupFormats() {
1506
- self.formats = Object.create(FlatpickrInstance.prototype.formats);
1507
- ["D", "F", "J", "M", "W", "l"].forEach(function (f) {
1508
- self.formats[f] = FlatpickrInstance.prototype.formats[f].bind(self);
1509
- });
1510
-
1511
- self.revFormat.F = FlatpickrInstance.prototype.revFormat.F.bind(self);
1512
- self.revFormat.M = FlatpickrInstance.prototype.revFormat.M.bind(self);
1513
- }
1514
-
1515
- function setupInputs() {
1516
- self.input = self.config.wrap ? self.element.querySelector("[data-input]") : self.element;
1517
-
1518
- /* istanbul ignore next */
1519
- if (!self.input) return console.warn("Error: invalid input element specified", self.input);
1520
-
1521
- self.input._type = self.input.type;
1522
- self.input.type = "text";
1523
-
1524
- self.input.classList.add("flatpickr-input");
1525
- self._input = self.input;
1526
-
1527
- if (self.config.altInput) {
1528
- // replicate self.element
1529
- self.altInput = createElement(self.input.nodeName, self.input.className + " " + self.config.altInputClass);
1530
- self._input = self.altInput;
1531
- self.altInput.placeholder = self.input.placeholder;
1532
- self.altInput.disabled = self.input.disabled;
1533
- self.altInput.required = self.input.required;
1534
- self.altInput.type = "text";
1535
- self.input.type = "hidden";
1536
-
1537
- if (!self.config.static && self.input.parentNode) self.input.parentNode.insertBefore(self.altInput, self.input.nextSibling);
1538
- }
1539
-
1540
- if (!self.config.allowInput) self._input.setAttribute("readonly", "readonly");
1541
-
1542
- self._positionElement = self.config.positionElement || self._input;
1543
- }
1544
-
1545
- function setupMobile() {
1546
- var inputType = self.config.enableTime ? self.config.noCalendar ? "time" : "datetime-local" : "date";
1547
-
1548
- self.mobileInput = createElement("input", self.input.className + " flatpickr-mobile");
1549
- self.mobileInput.step = self.input.getAttribute("step") || "any";
1550
- self.mobileInput.tabIndex = 1;
1551
- self.mobileInput.type = inputType;
1552
- self.mobileInput.disabled = self.input.disabled;
1553
- self.mobileInput.placeholder = self.input.placeholder;
1554
-
1555
- self.mobileFormatStr = inputType === "datetime-local" ? "Y-m-d\\TH:i:S" : inputType === "date" ? "Y-m-d" : "H:i:S";
1556
-
1557
- if (self.selectedDates.length) {
1558
- self.mobileInput.defaultValue = self.mobileInput.value = self.formatDate(self.selectedDates[0], self.mobileFormatStr);
1559
- }
1560
-
1561
- if (self.config.minDate) self.mobileInput.min = self.formatDate(self.config.minDate, "Y-m-d");
1562
-
1563
- if (self.config.maxDate) self.mobileInput.max = self.formatDate(self.config.maxDate, "Y-m-d");
1564
-
1565
- self.input.type = "hidden";
1566
- if (self.config.altInput) self.altInput.type = "hidden";
1567
-
1568
- try {
1569
- self.input.parentNode.insertBefore(self.mobileInput, self.input.nextSibling);
1570
- } catch (e) {
1571
- //
1572
- }
1573
-
1574
- self.mobileInput.addEventListener("change", function (e) {
1575
- self.setDate(e.target.value, false, self.mobileFormatStr);
1576
- triggerEvent("Change");
1577
- triggerEvent("Close");
1578
- });
1579
- }
1580
-
1581
- function toggle() {
1582
- if (self.isOpen) return self.close();
1583
- self.open();
1584
- }
1585
-
1586
- function triggerEvent(event, data) {
1587
- var hooks = self.config["on" + event];
1588
-
1589
- if (hooks !== undefined && hooks.length > 0) {
1590
- for (var i = 0; hooks[i] && i < hooks.length; i++) {
1591
- hooks[i](self.selectedDates, self.input.value, self, data);
1592
- }
1593
- }
1594
-
1595
- if (event === "Change") {
1596
- self.input.dispatchEvent(createEvent("change"));
1597
-
1598
- // many front-end frameworks bind to the input event
1599
- self.input.dispatchEvent(createEvent("input"));
1600
- }
1601
- }
1602
-
1603
- /**
1604
- * Creates an Event, normalized across browsers
1605
- * @param {String} name the event name, e.g. "click"
1606
- * @return {Event} the created event
1607
- */
1608
- function createEvent(name) {
1609
- if (self._supportsEvents) return new Event(name, { bubbles: true });
1610
-
1611
- self._[name + "Event"] = document.createEvent("Event");
1612
- self._[name + "Event"].initEvent(name, true, true);
1613
- return self._[name + "Event"];
1614
- }
1615
-
1616
- function isDateSelected(date) {
1617
- for (var i = 0; i < self.selectedDates.length; i++) {
1618
- if (compareDates(self.selectedDates[i], date) === 0) return "" + i;
1619
- }
1620
-
1621
- return false;
1622
- }
1623
-
1624
- function isDateInRange(date) {
1625
- if (self.config.mode !== "range" || self.selectedDates.length < 2) return false;
1626
- return compareDates(date, self.selectedDates[0]) >= 0 && compareDates(date, self.selectedDates[1]) <= 0;
1627
- }
1628
-
1629
- function updateNavigationCurrentMonth() {
1630
- if (self.config.noCalendar || self.isMobile || !self.monthNav) return;
1631
-
1632
- self.currentMonthElement.textContent = self.utils.monthToStr(self.currentMonth) + " ";
1633
- self.currentYearElement.value = self.currentYear;
1634
-
1635
- self._hidePrevMonthArrow = self.config.minDate && (self.currentYear === self.config.minDate.getFullYear() ? self.currentMonth <= self.config.minDate.getMonth() : self.currentYear < self.config.minDate.getFullYear());
1636
-
1637
- self._hideNextMonthArrow = self.config.maxDate && (self.currentYear === self.config.maxDate.getFullYear() ? self.currentMonth + 1 > self.config.maxDate.getMonth() : self.currentYear > self.config.maxDate.getFullYear());
1638
- }
1639
-
1640
- /**
1641
- * Updates the values of inputs associated with the calendar
1642
- * @return {void}
1643
- */
1644
- function updateValue(triggerChange) {
1645
- if (!self.selectedDates.length) return self.clear(triggerChange);
1646
-
1647
- if (self.isMobile) {
1648
- self.mobileInput.value = self.selectedDates.length ? self.formatDate(self.latestSelectedDateObj, self.mobileFormatStr) : "";
1649
- }
1650
-
1651
- var joinChar = self.config.mode !== "range" ? "; " : self.l10n.rangeSeparator;
1652
-
1653
- self.input.value = self.selectedDates.map(function (dObj) {
1654
- return self.formatDate(dObj, self.config.dateFormat);
1655
- }).join(joinChar);
1656
-
1657
- if (self.config.altInput) {
1658
- self.altInput.value = self.selectedDates.map(function (dObj) {
1659
- return self.formatDate(dObj, self.config.altFormat);
1660
- }).join(joinChar);
1661
- }
1662
-
1663
- if (triggerChange !== false) triggerEvent("ValueUpdate");
1664
- }
1665
-
1666
- function mouseDelta(e) {
1667
- return Math.max(-1, Math.min(1, e.wheelDelta || -e.deltaY));
1668
- }
1669
-
1670
- function onMonthNavScroll(e) {
1671
- e.preventDefault();
1672
- var isYear = self.currentYearElement.parentNode.contains(e.target);
1673
-
1674
- if (e.target === self.currentMonthElement || isYear) {
1675
-
1676
- var delta = mouseDelta(e);
1677
-
1678
- if (isYear) {
1679
- changeYear(self.currentYear + delta);
1680
- e.target.value = self.currentYear;
1681
- } else self.changeMonth(delta, true, false);
1682
- }
1683
- }
1684
-
1685
- function onMonthNavClick(e) {
1686
- var isPrevMonth = self.prevMonthNav.contains(e.target);
1687
- var isNextMonth = self.nextMonthNav.contains(e.target);
1688
-
1689
- if (isPrevMonth || isNextMonth) changeMonth(isPrevMonth ? -1 : 1);else if (e.target === self.currentYearElement) {
1690
- e.preventDefault();
1691
- self.currentYearElement.select();
1692
- } else if (e.target.className === "arrowUp") self.changeYear(self.currentYear + 1);else if (e.target.className === "arrowDown") self.changeYear(self.currentYear - 1);
1693
- }
1694
-
1695
- /**
1696
- * Creates an HTMLElement with given tag, class, and textual content
1697
- * @param {String} tag the HTML tag
1698
- * @param {String} className the new element's class name
1699
- * @param {String} content The new element's text content
1700
- * @return {HTMLElement} the created HTML element
1701
- */
1702
- function createElement(tag, className, content) {
1703
- var e = window.document.createElement(tag);
1704
- className = className || "";
1705
- content = content || "";
1706
-
1707
- e.className = className;
1708
-
1709
- if (content !== undefined) e.textContent = content;
1710
-
1711
- return e;
1712
- }
1713
-
1714
- function arrayify(obj) {
1715
- if (obj instanceof Array) return obj;
1716
- return [obj];
1717
- }
1718
-
1719
- function toggleClass(elem, className, bool) {
1720
- if (bool) return elem.classList.add(className);
1721
- elem.classList.remove(className);
1722
- }
1723
-
1724
- /* istanbul ignore next */
1725
- function debounce(func, wait, immediate) {
1726
- var timeout = void 0;
1727
- return function () {
1728
- var context = this,
1729
- args = arguments;
1730
- clearTimeout(timeout);
1731
- timeout = setTimeout(function () {
1732
- timeout = null;
1733
- if (!immediate) func.apply(context, args);
1734
- }, wait);
1735
- if (immediate && !timeout) func.apply(context, args);
1736
- };
1737
- }
1738
-
1739
- /**
1740
- * Compute the difference in dates, measured in ms
1741
- * @param {Date} date1
1742
- * @param {Date} date2
1743
- * @param {Boolean} timeless whether to reset times of both dates to 00:00
1744
- * @return {Number} the difference in ms
1745
- */
1746
- function compareDates(date1, date2, timeless) {
1747
- if (!(date1 instanceof Date) || !(date2 instanceof Date)) return false;
1748
-
1749
- if (timeless !== false) {
1750
- return new Date(date1.getTime()).setHours(0, 0, 0, 0) - new Date(date2.getTime()).setHours(0, 0, 0, 0);
1751
- }
1752
-
1753
- return date1.getTime() - date2.getTime();
1754
- }
1755
-
1756
- function timeWrapper(e) {
1757
- e.preventDefault();
1758
-
1759
- var isKeyDown = e.type === "keydown",
1760
- isWheel = e.type === "wheel",
1761
- isIncrement = e.type === "increment",
1762
- input = e.target;
1763
-
1764
- if (self.amPM && e.target === self.amPM) return e.target.textContent = ["AM", "PM"][e.target.textContent === "AM" | 0];
1765
-
1766
- var min = Number(input.min),
1767
- max = Number(input.max),
1768
- step = Number(input.step),
1769
- curValue = parseInt(input.value, 10),
1770
- delta = e.delta || (!isKeyDown ? Math.max(-1, Math.min(1, e.wheelDelta || -e.deltaY)) || 0 : e.which === 38 ? 1 : -1);
1771
-
1772
- var newValue = curValue + step * delta;
1773
-
1774
- if (typeof input.value !== "undefined" && input.value.length === 2) {
1775
- var isHourElem = input === self.hourElement,
1776
- isMinuteElem = input === self.minuteElement;
1777
-
1778
- if (newValue < min) {
1779
- newValue = max + newValue + !isHourElem + (isHourElem && !self.amPM);
1780
-
1781
- if (isMinuteElem) incrementNumInput(null, -1, self.hourElement);
1782
- } else if (newValue > max) {
1783
- newValue = input === self.hourElement ? newValue - max - !self.amPM : min;
1784
-
1785
- if (isMinuteElem) incrementNumInput(null, 1, self.hourElement);
1786
- }
1787
-
1788
- if (self.amPM && isHourElem && (step === 1 ? newValue + curValue === 23 : Math.abs(newValue - curValue) > step)) self.amPM.textContent = self.amPM.textContent === "PM" ? "AM" : "PM";
1789
-
1790
- input.value = self.pad(newValue);
1791
- }
1792
- }
1793
-
1794
- init();
1795
- return self;
1796
- }
1797
-
1798
- FlatpickrInstance.prototype = {
1799
- formats: {
1800
- // get the date in UTC
1801
- Z: function Z(date) {
1802
- return date.toISOString();
1803
- },
1804
-
1805
- // weekday name, short, e.g. Thu
1806
- D: function D(date) {
1807
- return this.l10n.weekdays.shorthand[this.formats.w(date)];
1808
- },
1809
-
1810
- // full month name e.g. January
1811
- F: function F(date) {
1812
- return this.utils.monthToStr(this.formats.n(date) - 1, false);
1813
- },
1814
-
1815
- // padded hour 1-12
1816
- G: function G(date) {
1817
- return FlatpickrInstance.prototype.pad(FlatpickrInstance.prototype.formats.h(date));
1818
- },
1819
-
1820
- // hours with leading zero e.g. 03
1821
- H: function H(date) {
1822
- return FlatpickrInstance.prototype.pad(date.getHours());
1823
- },
1824
-
1825
- // day (1-30) with ordinal suffix e.g. 1st, 2nd
1826
- J: function J(date) {
1827
- return date.getDate() + this.l10n.ordinal(date.getDate());
1828
- },
1829
-
1830
- // AM/PM
1831
- K: function K(date) {
1832
- return date.getHours() > 11 ? "PM" : "AM";
1833
- },
1834
-
1835
- // shorthand month e.g. Jan, Sep, Oct, etc
1836
- M: function M(date) {
1837
- return this.utils.monthToStr(date.getMonth(), true);
1838
- },
1839
-
1840
- // seconds 00-59
1841
- S: function S(date) {
1842
- return FlatpickrInstance.prototype.pad(date.getSeconds());
1843
- },
1844
-
1845
- // unix timestamp
1846
- U: function U(date) {
1847
- return date.getTime() / 1000;
1848
- },
1849
-
1850
- W: function W(date) {
1851
- return this.config.getWeek(date);
1852
- },
1853
-
1854
- // full year e.g. 2016
1855
- Y: function Y(date) {
1856
- return date.getFullYear();
1857
- },
1858
-
1859
- // day in month, padded (01-30)
1860
- d: function d(date) {
1861
- return FlatpickrInstance.prototype.pad(date.getDate());
1862
- },
1863
-
1864
- // hour from 1-12 (am/pm)
1865
- h: function h(date) {
1866
- return date.getHours() % 12 ? date.getHours() % 12 : 12;
1867
- },
1868
-
1869
- // minutes, padded with leading zero e.g. 09
1870
- i: function i(date) {
1871
- return FlatpickrInstance.prototype.pad(date.getMinutes());
1872
- },
1873
-
1874
- // day in month (1-30)
1875
- j: function j(date) {
1876
- return date.getDate();
1877
- },
1878
-
1879
- // weekday name, full, e.g. Thursday
1880
- l: function l(date) {
1881
- return this.l10n.weekdays.longhand[date.getDay()];
1882
- },
1883
-
1884
- // padded month number (01-12)
1885
- m: function m(date) {
1886
- return FlatpickrInstance.prototype.pad(date.getMonth() + 1);
1887
- },
1888
-
1889
- // the month number (1-12)
1890
- n: function n(date) {
1891
- return date.getMonth() + 1;
1892
- },
1893
-
1894
- // seconds 0-59
1895
- s: function s(date) {
1896
- return date.getSeconds();
1897
- },
1898
-
1899
- // number of the day of the week
1900
- w: function w(date) {
1901
- return date.getDay();
1902
- },
1903
-
1904
- // last two digits of year e.g. 16 for 2016
1905
- y: function y(date) {
1906
- return String(date.getFullYear()).substring(2);
1907
- }
1908
- },
1909
-
1910
- /**
1911
- * Formats a given Date object into a string based on supplied format
1912
- * @param {Date} dateObj the date object
1913
- * @param {String} frmt a string composed of formatting tokens e.g. "Y-m-d"
1914
- * @return {String} The textual representation of the date e.g. 2017-02-03
1915
- */
1916
- formatDate: function formatDate(dateObj, frmt) {
1917
- var _this = this;
1918
-
1919
- if (this.config !== undefined && this.config.formatDate !== undefined) return this.config.formatDate(dateObj, frmt);
1920
-
1921
- return frmt.split("").map(function (c, i, arr) {
1922
- return _this.formats[c] && arr[i - 1] !== "\\" ? _this.formats[c](dateObj) : c !== "\\" ? c : "";
1923
- }).join("");
1924
- },
1925
-
1926
-
1927
- revFormat: {
1928
- D: function D() {},
1929
- F: function F(dateObj, monthName) {
1930
- dateObj.setMonth(this.l10n.months.longhand.indexOf(monthName));
1931
- },
1932
- G: function G(dateObj, hour) {
1933
- dateObj.setHours(parseFloat(hour));
1934
- },
1935
- H: function H(dateObj, hour) {
1936
- dateObj.setHours(parseFloat(hour));
1937
- },
1938
- J: function J(dateObj, day) {
1939
- dateObj.setDate(parseFloat(day));
1940
- },
1941
- K: function K(dateObj, amPM) {
1942
- var hours = dateObj.getHours();
1943
-
1944
- if (hours !== 12) dateObj.setHours(hours % 12 + 12 * /pm/i.test(amPM));
1945
- },
1946
- M: function M(dateObj, shortMonth) {
1947
- dateObj.setMonth(this.l10n.months.shorthand.indexOf(shortMonth));
1948
- },
1949
- S: function S(dateObj, seconds) {
1950
- dateObj.setSeconds(seconds);
1951
- },
1952
- U: function U(dateObj, unixSeconds) {
1953
- return new Date(parseFloat(unixSeconds) * 1000);
1954
- },
1955
-
1956
- W: function W(dateObj, weekNumber) {
1957
- weekNumber = parseInt(weekNumber);
1958
- return new Date(dateObj.getFullYear(), 0, 2 + (weekNumber - 1) * 7, 0, 0, 0, 0, 0);
1959
- },
1960
- Y: function Y(dateObj, year) {
1961
- dateObj.setFullYear(year);
1962
- },
1963
- Z: function Z(dateObj, ISODate) {
1964
- return new Date(ISODate);
1965
- },
1966
-
1967
- d: function d(dateObj, day) {
1968
- dateObj.setDate(parseFloat(day));
1969
- },
1970
- h: function h(dateObj, hour) {
1971
- dateObj.setHours(parseFloat(hour));
1972
- },
1973
- i: function i(dateObj, minutes) {
1974
- dateObj.setMinutes(parseFloat(minutes));
1975
- },
1976
- j: function j(dateObj, day) {
1977
- dateObj.setDate(parseFloat(day));
1978
- },
1979
- l: function l() {},
1980
- m: function m(dateObj, month) {
1981
- dateObj.setMonth(parseFloat(month) - 1);
1982
- },
1983
- n: function n(dateObj, month) {
1984
- dateObj.setMonth(parseFloat(month) - 1);
1985
- },
1986
- s: function s(dateObj, seconds) {
1987
- dateObj.setSeconds(parseFloat(seconds));
1988
- },
1989
- w: function w() {},
1990
- y: function y(dateObj, year) {
1991
- dateObj.setFullYear(2000 + parseFloat(year));
1992
- }
1993
- },
1994
-
1995
- tokenRegex: {
1996
- D: "(\\w+)",
1997
- F: "(\\w+)",
1998
- G: "(\\d\\d|\\d)",
1999
- H: "(\\d\\d|\\d)",
2000
- J: "(\\d\\d|\\d)\\w+",
2001
- K: "(am|AM|Am|aM|pm|PM|Pm|pM)",
2002
- M: "(\\w+)",
2003
- S: "(\\d\\d|\\d)",
2004
- U: "(.+)",
2005
- W: "(\\d\\d|\\d)",
2006
- Y: "(\\d{4})",
2007
- Z: "(.+)",
2008
- d: "(\\d\\d|\\d)",
2009
- h: "(\\d\\d|\\d)",
2010
- i: "(\\d\\d|\\d)",
2011
- j: "(\\d\\d|\\d)",
2012
- l: "(\\w+)",
2013
- m: "(\\d\\d|\\d)",
2014
- n: "(\\d\\d|\\d)",
2015
- s: "(\\d\\d|\\d)",
2016
- w: "(\\d\\d|\\d)",
2017
- y: "(\\d{2})"
2018
- },
2019
-
2020
- pad: function pad(number) {
2021
- return ("0" + number).slice(-2);
2022
- },
2023
-
2024
- /**
2025
- * Parses a date(+time) string into a Date object
2026
- * @param {String} date the date string, e.g. 2017-02-03 14:45
2027
- * @param {String} givenFormat the date format, e.g. Y-m-d H:i
2028
- * @param {Boolean} timeless whether to reset the time of Date object
2029
- * @return {Date} the parsed Date object
2030
- */
2031
- parseDate: function parseDate(date, givenFormat, timeless) {
2032
- var _this2 = this;
2033
-
2034
- if (date !== 0 && !date) return null;
2035
-
2036
- var date_orig = date;
2037
-
2038
- if (date instanceof Date) date = new Date(date.getTime()); // create a copy
2039
-
2040
- else if (date.toFixed !== undefined) // timestamp
2041
- date = new Date(date);else {
2042
- // date string
2043
- var format = givenFormat || (this.config || flatpickr.defaultConfig).dateFormat;
2044
- date = String(date).trim();
2045
-
2046
- if (date === "today") {
2047
- date = new Date();
2048
- timeless = true;
2049
- } else if (/Z$/.test(date) || /GMT$/.test(date)) // datestrings w/ timezone
2050
- date = new Date(date);else if (this.config && this.config.parseDate) date = this.config.parseDate(date, format);else {
2051
- (function () {
2052
- var parsedDate = !_this2.config || !_this2.config.noCalendar ? new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0) : new Date(new Date().setHours(0, 0, 0, 0));
2053
-
2054
- var matched = void 0,
2055
- ops = [];
2056
-
2057
- for (var i = 0, matchIndex = 0, regexStr = ""; i < format.length; i++) {
2058
- var token = format[i];
2059
- var isBackSlash = token === "\\";
2060
- var escaped = format[i - 1] === "\\" || isBackSlash;
2061
-
2062
- if (_this2.tokenRegex[token] && !escaped) {
2063
- regexStr += _this2.tokenRegex[token];
2064
- var match = new RegExp(regexStr).exec(date);
2065
- if (match && (matched = true)) {
2066
- ops[token !== "Y" ? "push" : "unshift"]({
2067
- fn: _this2.revFormat[token],
2068
- val: match[++matchIndex]
2069
- });
2070
- }
2071
- } else if (!isBackSlash) regexStr += "."; // don't really care
2072
-
2073
- ops.forEach(function (_ref) {
2074
- var fn = _ref.fn,
2075
- val = _ref.val;
2076
- return parsedDate = fn(parsedDate, val) || parsedDate;
2077
- });
2078
- }
2079
-
2080
- date = matched ? parsedDate : null;
2081
- })();
2082
- }
2083
- }
2084
-
2085
- /* istanbul ignore next */
2086
- if (!(date instanceof Date)) {
2087
- console.warn("flatpickr: invalid date " + date_orig);
2088
- console.info(this.element);
2089
- return null;
2090
- }
2091
-
2092
- if (timeless === true) date.setHours(0, 0, 0, 0);
2093
-
2094
- return date;
2095
- }
2096
- };
2097
-
2098
- /* istanbul ignore next */
2099
- function _flatpickr(nodeList, config) {
2100
- var nodes = Array.prototype.slice.call(nodeList); // static list
2101
- var instances = [];
2102
- for (var i = 0; i < nodes.length; i++) {
2103
- try {
2104
- if (nodes[i].getAttribute("data-fp-omit") !== null) continue;
2105
-
2106
- if (nodes[i]._flatpickr) {
2107
- nodes[i]._flatpickr.destroy();
2108
- nodes[i]._flatpickr = null;
2109
- }
2110
-
2111
- nodes[i]._flatpickr = new FlatpickrInstance(nodes[i], config || {});
2112
- instances.push(nodes[i]._flatpickr);
2113
- } catch (e) {
2114
- console.warn(e, e.stack);
2115
- }
2116
- }
2117
-
2118
- return instances.length === 1 ? instances[0] : instances;
2119
- }
2120
-
2121
- /* istanbul ignore next */
2122
- if (typeof HTMLElement !== "undefined") {
2123
- // browser env
2124
- HTMLCollection.prototype.flatpickr = NodeList.prototype.flatpickr = function (config) {
2125
- return _flatpickr(this, config);
2126
- };
2127
-
2128
- HTMLElement.prototype.flatpickr = function (config) {
2129
- return _flatpickr([this], config);
2130
- };
2131
- }
2132
-
2133
- /* istanbul ignore next */
2134
- function flatpickr(selector, config) {
2135
- if (selector instanceof NodeList) return _flatpickr(selector, config);else if (!(selector instanceof HTMLElement)) return _flatpickr(window.document.querySelectorAll(selector), config);
2136
-
2137
- return _flatpickr([selector], config);
2138
- }
2139
-
2140
- /* istanbul ignore next */
2141
- flatpickr.defaultConfig = FlatpickrInstance.defaultConfig = {
2142
- mode: "single",
2143
-
2144
- position: "auto",
2145
-
2146
- animate: typeof window !== "undefined" && window.navigator.userAgent.indexOf("MSIE") === -1,
2147
-
2148
- // wrap: see https://chmln.github.io/flatpickr/examples/#flatpickr-external-elements
2149
- wrap: false,
2150
-
2151
- // enables week numbers
2152
- weekNumbers: false,
2153
-
2154
- // allow manual datetime input
2155
- allowInput: false,
2156
-
2157
- /*
2158
- clicking on input opens the date(time)picker.
2159
- disable if you wish to open the calendar manually with .open()
2160
- */
2161
- clickOpens: true,
2162
-
2163
- /*
2164
- closes calendar after date selection,
2165
- unless 'mode' is 'multiple' or enableTime is true
2166
- */
2167
- closeOnSelect: true,
2168
-
2169
- // display time picker in 24 hour mode
2170
- time_24hr: false,
2171
-
2172
- // enables the time picker functionality
2173
- enableTime: false,
2174
-
2175
- // noCalendar: true will hide the calendar. use for a time picker along w/ enableTime
2176
- noCalendar: false,
2177
-
2178
- // more date format chars at https://chmln.github.io/flatpickr/#dateformat
2179
- dateFormat: "Y-m-d",
2180
-
2181
- // date format used in aria-label for days
2182
- ariaDateFormat: "F j, Y",
2183
-
2184
- // altInput - see https://chmln.github.io/flatpickr/#altinput
2185
- altInput: false,
2186
-
2187
- // the created altInput element will have this class.
2188
- altInputClass: "form-control input",
2189
-
2190
- // same as dateFormat, but for altInput
2191
- altFormat: "F j, Y", // defaults to e.g. June 10, 2016
2192
-
2193
- // defaultDate - either a datestring or a date object. used for datetimepicker"s initial value
2194
- defaultDate: null,
2195
-
2196
- // the minimum date that user can pick (inclusive)
2197
- minDate: null,
2198
-
2199
- // the maximum date that user can pick (inclusive)
2200
- maxDate: null,
2201
-
2202
- // dateparser that transforms a given string to a date object
2203
- parseDate: null,
2204
-
2205
- // dateformatter that transforms a given date object to a string, according to passed format
2206
- formatDate: null,
2207
-
2208
- getWeek: function getWeek(givenDate) {
2209
- var date = new Date(givenDate.getTime());
2210
- var onejan = new Date(date.getFullYear(), 0, 1);
2211
- return Math.ceil(((date - onejan) / 86400000 + onejan.getDay() + 1) / 7);
2212
- },
2213
-
2214
-
2215
- // see https://chmln.github.io/flatpickr/#disable
2216
- enable: [],
2217
-
2218
- // see https://chmln.github.io/flatpickr/#disable
2219
- disable: [],
2220
-
2221
- // display the short version of month names - e.g. Sep instead of September
2222
- shorthandCurrentMonth: false,
2223
-
2224
- // displays calendar inline. see https://chmln.github.io/flatpickr/#inline-calendar
2225
- inline: false,
2226
-
2227
- // position calendar inside wrapper and next to the input element
2228
- // leave at false unless you know what you"re doing
2229
- "static": false,
2230
-
2231
- // DOM node to append the calendar to in *static* mode
2232
- appendTo: null,
2233
-
2234
- // code for previous/next icons. this is where you put your custom icon code e.g. fontawesome
2235
- 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>",
2236
- 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>",
2237
-
2238
- // enables seconds in the time picker
2239
- enableSeconds: false,
2240
-
2241
- // step size used when scrolling/incrementing the hour element
2242
- hourIncrement: 1,
2243
-
2244
- // step size used when scrolling/incrementing the minute element
2245
- minuteIncrement: 5,
2246
-
2247
- // initial value in the hour element
2248
- defaultHour: 12,
2249
-
2250
- // initial value in the minute element
2251
- defaultMinute: 0,
2252
-
2253
- // initial value in the seconds element
2254
- defaultSeconds: 0,
2255
-
2256
- // disable native mobile datetime input support
2257
- disableMobile: false,
2258
-
2259
- // default locale
2260
- locale: "default",
2261
-
2262
- plugins: [],
2263
-
2264
- ignoredFocusElements: [],
2265
-
2266
- // called every time calendar is closed
2267
- onClose: undefined, // function (dateObj, dateStr) {}
2268
-
2269
- // onChange callback when user selects a date or time
2270
- onChange: undefined, // function (dateObj, dateStr) {}
2271
-
2272
- // called for every day element
2273
- onDayCreate: undefined,
2274
-
2275
- // called every time the month is changed
2276
- onMonthChange: undefined,
2277
-
2278
- // called every time calendar is opened
2279
- onOpen: undefined, // function (dateObj, dateStr) {}
2280
-
2281
- // called after the configuration has been parsed
2282
- onParseConfig: undefined,
2283
-
2284
- // called after calendar is ready
2285
- onReady: undefined, // function (dateObj, dateStr) {}
2286
-
2287
- // called after input value updated
2288
- onValueUpdate: undefined,
2289
-
2290
- // called every time the year is changed
2291
- onYearChange: undefined,
2292
-
2293
- onKeyDown: undefined,
2294
-
2295
- onDestroy: undefined
2296
- };
2297
-
2298
- /* istanbul ignore next */
2299
- flatpickr.l10ns = {
2300
- en: {
2301
- weekdays: {
2302
- shorthand: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
2303
- longhand: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
2304
- },
2305
- months: {
2306
- shorthand: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
2307
- longhand: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
2308
- },
2309
- daysInMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
2310
- firstDayOfWeek: 0,
2311
- ordinal: function ordinal(nth) {
2312
- var s = nth % 100;
2313
- if (s > 3 && s < 21) return "th";
2314
- switch (s % 10) {
2315
- case 1:
2316
- return "st";
2317
- case 2:
2318
- return "nd";
2319
- case 3:
2320
- return "rd";
2321
- default:
2322
- return "th";
2323
- }
2324
- },
2325
- rangeSeparator: " to ",
2326
- weekAbbreviation: "Wk",
2327
- scrollTitle: "Scroll to increment",
2328
- toggleTitle: "Click to toggle"
2329
- }
2330
- };
2331
-
2332
- flatpickr.l10ns.default = Object.create(flatpickr.l10ns.en);
2333
- flatpickr.localize = function (l10n) {
2334
- return _extends(flatpickr.l10ns.default, l10n || {});
2335
- };
2336
- flatpickr.setDefaults = function (config) {
2337
- return _extends(flatpickr.defaultConfig, config || {});
2338
- };
2339
-
2340
- /* istanbul ignore next */
2341
- if (typeof jQuery !== "undefined") {
2342
- jQuery.fn.flatpickr = function (config) {
2343
- return _flatpickr(this, config);
2344
- };
2345
- }
2346
-
2347
- Date.prototype.fp_incr = function (days) {
2348
- return new Date(this.getFullYear(), this.getMonth(), this.getDate() + parseInt(days, 10));
2349
- };
2350
-
2351
- if (typeof module !== "undefined") module.exports = flatpickr;
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.flatpickr = factory());
6
+ }(this, (function () { 'use strict';
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
+ };
23
+ }
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
+ },
87
+ };
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})",
111
+ };
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),
151
+ };
152
+
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",
219
+ };
220
+
221
+ const createDateFormatter = ({ config = defaults, l10n = english, }) => (dateObj, frmt, overrideLocale) => {
222
+ const locale = overrideLocale || l10n;
223
+ 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("");
234
+ };
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));
281
+ }
282
+ parsedDate = matched ? parsedDate : undefined;
283
+ }
284
+ }
285
+ if (!(parsedDate instanceof Date && !isNaN(parsedDate.getTime()))) {
286
+ config.errorHandler(new Error(`Invalid date provided: ${date_orig}`));
287
+ return undefined;
288
+ }
289
+ if (timeless === true)
290
+ parsedDate.setHours(0, 0, 0, 0);
291
+ return parsedDate;
292
+ };
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();
299
+ }
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));
310
+ };
311
+ const isBetween = (ts, ts1, ts2) => {
312
+ return ts > Math.min(ts1, ts2) && ts < Math.max(ts1, ts2);
313
+ };
314
+ const duration = {
315
+ DAY: 86400000,
316
+ };
317
+
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,
387
+ };
388
+
389
+ function toggleClass(elem, className, bool) {
390
+ if (bool === true)
391
+ return elem.classList.add(className);
392
+ elem.classList.remove(className);
393
+ }
394
+ 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;
402
+ }
403
+ function clearNode(node) {
404
+ while (node.firstChild)
405
+ node.removeChild(node.firstChild);
406
+ }
407
+ 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
+ }
414
+ 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;
425
+ }
426
+
427
+ 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
+ };
434
+ }
435
+
436
+ const DEBOUNCED_CHANGE_MS = 300;
437
+ 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);
528
+ }
529
+ const prevValue = self._input.value;
530
+ setHoursFromInputs();
531
+ updateValue();
532
+ if (self._input.value !== prevValue) {
533
+ self._debouncedChange();
534
+ }
535
+ }
536
+ function ampm2military(hour, amPM) {
537
+ return (hour % 12) + 12 * int(amPM === self.l10n.amPM[1]);
538
+ }
539
+ function military2ampm(hour) {
540
+ switch (hour % 24) {
541
+ case 0:
542
+ case 12:
543
+ return 12;
544
+ default:
545
+ return hour % 12;
546
+ }
547
+ }
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);
619
+ }
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
+ }
641
+ }
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
+ });
654
+ }
655
+ function onClick(handler) {
656
+ return evt => {
657
+ evt.which === 1 && handler(evt);
658
+ };
659
+ }
660
+ function triggerChange() {
661
+ triggerEvent("onChange");
662
+ }
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
+ }
716
+ }
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;
930
+ }
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
+ }
949
+ }
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
+ }
1100
+ }
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 (_) { }
1223
+ });
1224
+ }
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
+ }
1254
+ }
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
+ }
1274
+ }
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
+ }
1502
+ }
1503
+ function onResize() {
1504
+ if (self.isOpen && !self.config.static && !self.config.inline)
1505
+ positionCalendar();
1506
+ }
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
+ }
1544
+ }
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
+ }
1725
+ }
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
+ }
1741
+ }
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();
1807
+ }
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
+ }
1851
+ }
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
+ });
1940
+ }
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
+ });
2008
+ }
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
+ }
2026
+ }
2027
+ function createEvent(name) {
2028
+ const e = document.createEvent("Event");
2029
+ e.initEvent(name, true, true);
2030
+ return e;
2031
+ }
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");
2092
+ }
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);
2108
+ }
2109
+ }
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])];
2116
+ }
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);
2136
+ }
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])];
2144
+ }
2145
+ input.value = pad(newValue);
2146
+ }
2147
+ }
2148
+ init();
2149
+ return self;
2150
+ }
2151
+ 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
+ }
2169
+ }
2170
+ return instances.length === 1 ? instances[0] : instances;
2171
+ }
2172
+ 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
+ };
2179
+ }
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);
2186
+ };
2187
+ flatpickr.defaultConfig = defaults;
2188
+ flatpickr.l10ns = {
2189
+ en: Object.assign({}, english),
2190
+ default: Object.assign({}, english),
2191
+ };
2192
+ flatpickr.localize = (l10n) => {
2193
+ flatpickr.l10ns.default = Object.assign({}, flatpickr.l10ns.default, l10n);
2194
+ };
2195
+ flatpickr.setDefaults = (config) => {
2196
+ flatpickr.defaultConfig = Object.assign({}, flatpickr.defaultConfig, config);
2197
+ };
2198
+ flatpickr.parseDate = createDateParser({});
2199
+ flatpickr.formatDate = createDateFormatter({});
2200
+ flatpickr.compareDates = compareDates;
2201
+ if (typeof jQuery !== "undefined") {
2202
+ jQuery.fn.flatpickr = function (config) {
2203
+ return _flatpickr(this, config);
2204
+ };
2205
+ }
2206
+ Date.prototype.fp_incr = function (days) {
2207
+ return new Date(this.getFullYear(), this.getMonth(), this.getDate() + (typeof days === "string" ? parseInt(days, 10) : days));
2208
+ };
2209
+ if (typeof window !== "undefined") {
2210
+ window.flatpickr = flatpickr;
2211
+ }
2212
+
2213
+ return flatpickr;
2214
+
2215
+ })));