flatpickr 4.5.2.0 → 4.6.6.0

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