scrivito_advanced_editors 1.4.1 → 1.5.0.dev1

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