flatpickr-ce 4.7.2 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/README.md +53 -0
  2. package/dist/esm/index.js +372 -221
  3. package/dist/esm/l10n/az.js +4 -0
  4. package/dist/esm/l10n/bg.js +1 -0
  5. package/dist/esm/l10n/br.js +67 -0
  6. package/dist/esm/l10n/da.js +4 -0
  7. package/dist/esm/l10n/de.js +4 -0
  8. package/dist/esm/l10n/es.js +4 -0
  9. package/dist/esm/l10n/fi.js +4 -0
  10. package/dist/esm/l10n/fr.js +4 -0
  11. package/dist/esm/l10n/gl.js +62 -0
  12. package/dist/esm/l10n/he.js +1 -1
  13. package/dist/esm/l10n/index.js +6 -0
  14. package/dist/esm/l10n/ko.js +4 -0
  15. package/dist/esm/l10n/pl.js +4 -0
  16. package/dist/esm/l10n/pt.js +4 -0
  17. package/dist/esm/l10n/sv.js +4 -0
  18. package/dist/esm/l10n/tg.js +62 -0
  19. package/dist/esm/l10n/zh.js +4 -0
  20. package/dist/esm/l10n/zh_tw.js +4 -0
  21. package/dist/esm/plugins/confirmDate/confirmDate.js +5 -2
  22. package/dist/esm/plugins/monthSelect/index.js +16 -49
  23. package/dist/esm/plugins/rangePlugin.js +60 -38
  24. package/dist/esm/plugins/yearSelect/index.js +341 -0
  25. package/dist/esm/types/options.js +2 -0
  26. package/dist/esm/utils/dates.js +18 -7
  27. package/dist/esm/utils/formatting.js +43 -35
  28. package/dist/flatpickr.js +523 -266
  29. package/dist/flatpickr.min.js +2 -2
  30. package/dist/l10n/ar-dz.d.ts +3 -0
  31. package/dist/l10n/ar.d.ts +3 -0
  32. package/dist/l10n/at.d.ts +3 -0
  33. package/dist/l10n/az.d.ts +3 -0
  34. package/dist/l10n/az.js +4 -0
  35. package/dist/l10n/be.d.ts +3 -0
  36. package/dist/l10n/bg.d.ts +3 -0
  37. package/dist/l10n/bg.js +1 -0
  38. package/dist/l10n/bn.d.ts +3 -0
  39. package/dist/l10n/br.d.ts +75 -0
  40. package/dist/l10n/br.js +80 -0
  41. package/dist/l10n/bs.d.ts +3 -0
  42. package/dist/l10n/cat.d.ts +3 -0
  43. package/dist/l10n/ckb.d.ts +3 -0
  44. package/dist/l10n/cs.d.ts +3 -0
  45. package/dist/l10n/cy.d.ts +3 -0
  46. package/dist/l10n/da.d.ts +3 -0
  47. package/dist/l10n/da.js +4 -0
  48. package/dist/l10n/de.d.ts +3 -0
  49. package/dist/l10n/de.js +4 -0
  50. package/dist/l10n/eo.d.ts +3 -0
  51. package/dist/l10n/es.d.ts +3 -0
  52. package/dist/l10n/es.js +4 -0
  53. package/dist/l10n/et.d.ts +3 -0
  54. package/dist/l10n/fa.d.ts +3 -0
  55. package/dist/l10n/fi.d.ts +3 -0
  56. package/dist/l10n/fi.js +4 -0
  57. package/dist/l10n/fo.d.ts +3 -0
  58. package/dist/l10n/fr.d.ts +3 -0
  59. package/dist/l10n/fr.js +4 -0
  60. package/dist/l10n/ga.d.ts +3 -0
  61. package/dist/l10n/gl.d.ts +75 -0
  62. package/dist/l10n/gl.js +75 -0
  63. package/dist/l10n/gr.d.ts +3 -0
  64. package/dist/l10n/he.d.ts +3 -0
  65. package/dist/l10n/he.js +1 -1
  66. package/dist/l10n/hi.d.ts +3 -0
  67. package/dist/l10n/hr.d.ts +3 -0
  68. package/dist/l10n/hu.d.ts +3 -0
  69. package/dist/l10n/hy.d.ts +3 -0
  70. package/dist/l10n/id.d.ts +3 -0
  71. package/dist/l10n/index.js +418 -171
  72. package/dist/l10n/is.d.ts +3 -0
  73. package/dist/l10n/it.d.ts +3 -0
  74. package/dist/l10n/ja.d.ts +3 -0
  75. package/dist/l10n/ka.d.ts +3 -0
  76. package/dist/l10n/km.d.ts +3 -0
  77. package/dist/l10n/ko.d.ts +3 -0
  78. package/dist/l10n/ko.js +4 -0
  79. package/dist/l10n/kz.d.ts +3 -0
  80. package/dist/l10n/lt.d.ts +3 -0
  81. package/dist/l10n/lv.d.ts +3 -0
  82. package/dist/l10n/mk.d.ts +3 -0
  83. package/dist/l10n/mn.d.ts +3 -0
  84. package/dist/l10n/ms.d.ts +3 -0
  85. package/dist/l10n/my.d.ts +3 -0
  86. package/dist/l10n/nl.d.ts +3 -0
  87. package/dist/l10n/nn.d.ts +3 -0
  88. package/dist/l10n/no.d.ts +3 -0
  89. package/dist/l10n/pa.d.ts +3 -0
  90. package/dist/l10n/pl.d.ts +3 -0
  91. package/dist/l10n/pl.js +4 -0
  92. package/dist/l10n/pt.d.ts +3 -0
  93. package/dist/l10n/pt.js +4 -0
  94. package/dist/l10n/ro.d.ts +3 -0
  95. package/dist/l10n/ru.d.ts +3 -0
  96. package/dist/l10n/si.d.ts +3 -0
  97. package/dist/l10n/sk.d.ts +3 -0
  98. package/dist/l10n/sl.d.ts +3 -0
  99. package/dist/l10n/sq.d.ts +3 -0
  100. package/dist/l10n/sr-cyr.d.ts +3 -0
  101. package/dist/l10n/sr.d.ts +3 -0
  102. package/dist/l10n/sv.d.ts +3 -0
  103. package/dist/l10n/sv.js +4 -0
  104. package/dist/l10n/tg.d.ts +75 -0
  105. package/dist/l10n/tg.js +76 -0
  106. package/dist/l10n/th.d.ts +3 -0
  107. package/dist/l10n/tr.d.ts +3 -0
  108. package/dist/l10n/uk.d.ts +3 -0
  109. package/dist/l10n/uz.d.ts +3 -0
  110. package/dist/l10n/uz_latn.d.ts +3 -0
  111. package/dist/l10n/vn.d.ts +3 -0
  112. package/dist/l10n/zh.d.ts +3 -0
  113. package/dist/l10n/zh.js +4 -0
  114. package/dist/l10n/zh_tw.d.ts +3 -0
  115. package/dist/l10n/zh_tw.js +4 -0
  116. package/dist/plugins/confirmDate/confirmDate.js +6 -2
  117. package/dist/plugins/minMaxTimePlugin.js +1 -0
  118. package/dist/plugins/monthSelect/index.js +20 -49
  119. package/dist/plugins/rangePlugin.js +85 -38
  120. package/dist/plugins/yearSelect/index.d.ts +14 -0
  121. package/dist/plugins/yearSelect/index.js +412 -0
  122. package/dist/plugins/yearSelect/style.css +108 -0
  123. package/dist/types/instance.d.ts +2 -0
  124. package/dist/types/locale.d.ts +1 -1
  125. package/dist/types/options.d.ts +3 -1
  126. package/package.json +1 -1
package/dist/flatpickr.js CHANGED
@@ -1,4 +1,4 @@
1
- /* flatpickr v4.7.2, @license MIT */
1
+ /* flatpickr v4.9.0, @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) :
@@ -43,6 +43,7 @@
43
43
  "onChange",
44
44
  "onClose",
45
45
  "onDayCreate",
46
+ "onDaysBuilt",
46
47
  "onDestroy",
47
48
  "onKeyDown",
48
49
  "onMonthChange",
@@ -105,6 +106,7 @@
105
106
  onChange: [],
106
107
  onClose: [],
107
108
  onDayCreate: [],
109
+ onDaysBuilt: [],
108
110
  onDestroy: [],
109
111
  onKeyDown: [],
110
112
  onMonthChange: [],
@@ -279,30 +281,59 @@
279
281
 
280
282
  var doNothing = function () { return undefined; };
281
283
  var monthToStr = function (monthNumber, shorthand, locale) { return locale.months[shorthand ? "shorthand" : "longhand"][monthNumber]; };
284
+ // The parser matches names with the i flag, which compares characters by their
285
+ // upper case, so a matched month name is looked up the same way
286
+ var monthIndex = function (monthNames, monthName) {
287
+ return monthNames.map(function (name) { return name.toUpperCase(); }).indexOf(monthName.toUpperCase());
288
+ };
289
+ // Date carries a value past a field's range over into the next field (month 13
290
+ // into the next year, hour 24 into the next day), so a value the field doesn't
291
+ // have gives an invalid date, which the parser reports as such
292
+ var invalidDate = function () { return new Date(NaN); };
293
+ var setInRange = function (min, max, set) { return function (dateObj, data) {
294
+ var value = parseFloat(data);
295
+ if (value < min || value > max)
296
+ return invalidDate();
297
+ set(dateObj, value);
298
+ }; };
299
+ // The day is written after the year and the month (see createDateParser), so a
300
+ // day that month doesn't have moves the date into the next one
301
+ var setDay = function (dateObj, day) {
302
+ var value = parseFloat(day);
303
+ dateObj.setDate(value);
304
+ if (dateObj.getDate() !== value)
305
+ return invalidDate();
306
+ };
307
+ var setMonth = setInRange(1, 12, function (dateObj, month) {
308
+ dateObj.setMonth(month - 1, 1);
309
+ });
310
+ var setHours = setInRange(0, 23, function (dateObj, hour) {
311
+ dateObj.setHours(hour);
312
+ });
313
+ var setHours12 = setInRange(0, 23, function (dateObj, hour) {
314
+ dateObj.setHours((dateObj.getHours() >= 12 ? 12 : 0) + hour);
315
+ });
316
+ var setSeconds = setInRange(0, 59, function (dateObj, seconds) {
317
+ dateObj.setSeconds(seconds);
318
+ });
319
+ // Month setters start the month on the 1st: the day, if any, is written after
320
+ // the month (see createDateParser), and the base date's day may not exist in it
282
321
  var revFormat = {
283
322
  D: doNothing,
284
323
  F: function (dateObj, monthName, locale) {
285
- dateObj.setMonth(locale.months.longhand.indexOf(monthName));
286
- },
287
- G: function (dateObj, hour) {
288
- dateObj.setHours((dateObj.getHours() >= 12 ? 12 : 0) + parseFloat(hour));
289
- },
290
- H: function (dateObj, hour) {
291
- dateObj.setHours(parseFloat(hour));
292
- },
293
- J: function (dateObj, day) {
294
- dateObj.setDate(parseFloat(day));
324
+ dateObj.setMonth(monthIndex(locale.months.longhand, monthName), 1);
295
325
  },
326
+ G: setHours12,
327
+ H: setHours,
328
+ J: setDay,
296
329
  K: function (dateObj, amPM, locale) {
297
330
  dateObj.setHours((dateObj.getHours() % 12) +
298
331
  12 * int(new RegExp(locale.amPM[1], "i").test(amPM)));
299
332
  },
300
333
  M: function (dateObj, shortMonth, locale) {
301
- dateObj.setMonth(locale.months.shorthand.indexOf(shortMonth));
302
- },
303
- S: function (dateObj, seconds) {
304
- dateObj.setSeconds(parseFloat(seconds));
334
+ dateObj.setMonth(monthIndex(locale.months.shorthand, shortMonth), 1);
305
335
  },
336
+ S: setSeconds,
306
337
  U: function (_, unixSeconds) { return new Date(parseFloat(unixSeconds) * 1000); },
307
338
  W: function (dateObj, weekNum, locale) {
308
339
  var weekNumber = parseInt(weekNum);
@@ -314,28 +345,16 @@
314
345
  dateObj.setFullYear(parseFloat(year));
315
346
  },
316
347
  Z: function (_, ISODate) { return new Date(ISODate); },
317
- d: function (dateObj, day) {
318
- dateObj.setDate(parseFloat(day));
319
- },
320
- h: function (dateObj, hour) {
321
- dateObj.setHours((dateObj.getHours() >= 12 ? 12 : 0) + parseFloat(hour));
322
- },
323
- i: function (dateObj, minutes) {
324
- dateObj.setMinutes(parseFloat(minutes));
325
- },
326
- j: function (dateObj, day) {
327
- dateObj.setDate(parseFloat(day));
328
- },
348
+ d: setDay,
349
+ h: setHours12,
350
+ i: setInRange(0, 59, function (dateObj, minutes) {
351
+ dateObj.setMinutes(minutes);
352
+ }),
353
+ j: setDay,
329
354
  l: doNothing,
330
- m: function (dateObj, month) {
331
- dateObj.setMonth(parseFloat(month) - 1);
332
- },
333
- n: function (dateObj, month) {
334
- dateObj.setMonth(parseFloat(month) - 1);
335
- },
336
- s: function (dateObj, seconds) {
337
- dateObj.setSeconds(parseFloat(seconds));
338
- },
355
+ m: setMonth,
356
+ n: setMonth,
357
+ s: setSeconds,
339
358
  u: function (_, unixMillSeconds) {
340
359
  return new Date(parseFloat(unixMillSeconds));
341
360
  },
@@ -433,6 +452,17 @@
433
452
  y: function (date) { return String(date.getFullYear()).substring(2); },
434
453
  };
435
454
 
455
+ // The parsed fields are written one by one into a Date, which rolls a day its
456
+ // month doesn't have (February 30th) over into the next month, so the year is
457
+ // written first, then the month, then the rest in format order
458
+ var writeOrder = {
459
+ Y: 0,
460
+ y: 0,
461
+ F: 1,
462
+ M: 1,
463
+ m: 1,
464
+ n: 1,
465
+ };
436
466
  var createDateFormatter = function (_a) {
437
467
  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;
438
468
  return function (dateObj, frmt, overrideLocale) {
@@ -455,6 +485,7 @@
455
485
  var createDateParser = function (_a) {
456
486
  var _b = _a.config, config = _b === void 0 ? defaults : _b, _c = _a.l10n, l10n = _c === void 0 ? english : _c;
457
487
  return function (date, givenFormat, timeless, customLocale) {
488
+ var _a;
458
489
  if (date !== 0 && !date)
459
490
  return undefined;
460
491
  var locale = customLocale || l10n;
@@ -484,16 +515,16 @@
484
515
  parsedDate = new Date(date);
485
516
  }
486
517
  else {
487
- var matched = void 0, ops = [];
518
+ var matched = void 0, ops = [[], [], []];
488
519
  for (var i = 0, matchIndex = 0, regexStr = ""; i < format.length; i++) {
489
520
  var token_1 = format[i];
490
521
  var isBackSlash = token_1 === "\\";
491
522
  var escaped = format[i - 1] === "\\" || isBackSlash;
492
523
  if (tokenRegex[token_1] && !escaped) {
493
524
  regexStr += tokenRegex[token_1];
494
- var match = new RegExp(regexStr).exec(date);
525
+ var match = new RegExp(regexStr, "i").exec(date);
495
526
  if (match && (matched = true)) {
496
- ops[token_1 !== "Y" ? "push" : "unshift"]({
527
+ ops[(_a = writeOrder[token_1]) !== null && _a !== void 0 ? _a : 2].push({
497
528
  fn: revFormat[token_1],
498
529
  val: match[++matchIndex],
499
530
  });
@@ -506,9 +537,11 @@
506
537
  !config || !config.noCalendar
507
538
  ? new Date(new Date().getFullYear(), 0, 1, 0, 0, 0, 0)
508
539
  : new Date(new Date().setHours(0, 0, 0, 0));
509
- ops.forEach(function (_a) {
510
- var fn = _a.fn, val = _a.val;
511
- return (parsedDate = fn(parsedDate, val, locale) || parsedDate);
540
+ ops.forEach(function (group) {
541
+ return group.forEach(function (_a) {
542
+ var fn = _a.fn, val = _a.val;
543
+ return (parsedDate = fn(parsedDate, val, locale) || parsedDate);
544
+ });
512
545
  });
513
546
  parsedDate = matched ? parsedDate : undefined;
514
547
  }
@@ -571,7 +604,7 @@
571
604
  if (hours === maxHr)
572
605
  minutes = Math.min(maxMinutes, minutes);
573
606
  if (hours === maxHr && minutes === maxMinutes)
574
- seconds = config.maxDate.getSeconds();
607
+ seconds = Math.min(seconds, config.maxDate.getSeconds());
575
608
  }
576
609
  return { hours: hours, minutes: minutes, seconds: seconds };
577
610
  }
@@ -599,17 +632,29 @@
599
632
  }
600
633
 
601
634
  var DEBOUNCED_CHANGE_MS = 300;
635
+ // Instances created so far, which numbers their fields' ids
636
+ var instanceCount = 0;
602
637
  function FlatpickrInstance(element, instanceConfig) {
603
638
  var self = {
604
639
  config: __assign(__assign({}, defaults), flatpickr.defaultConfig),
605
640
  l10n: english,
606
641
  };
642
+ // The options the user gave, at creation and through set(), as opposed to
643
+ // defaults
644
+ var userConfig = {};
645
+ // The calendar's own fields get ids, unique on the page and kept across
646
+ // rebuilds: Chrome flags a field with neither an id nor a name, and a name
647
+ // would get them submitted with a form holding a static or inline calendar
648
+ var idPrefix = "flatpickr-" + ++instanceCount;
607
649
  // The element may live in another document than the one flatpickr was
608
650
  // loaded in (an iframe, or a window.open() popup), each with its own globals.
609
651
  // A document without a window (e.g. a <template> clone not yet inserted)
610
652
  // can't render anything, so fall back to ours.
611
653
  var win = element.ownerDocument.defaultView || window;
612
654
  var doc = win.document;
655
+ // Listeners on the document and the window, bound only while the calendar
656
+ // is open; kept apart from _handlers, which last until destroy()
657
+ var openHandlers = [];
613
658
  self.parseDate = createDateParser({ config: self.config, l10n: self.l10n });
614
659
  self._handlers = [];
615
660
  self.pluginElements = [];
@@ -617,6 +662,8 @@
617
662
  self._bind = bind;
618
663
  self._setHoursFromDate = setHoursFromDate;
619
664
  self._positionCalendar = positionCalendar;
665
+ self._showValue = showValue;
666
+ self._typedValue = typedValue;
620
667
  self.changeMonth = changeMonth;
621
668
  self.changeYear = changeYear;
622
669
  self.clear = clear;
@@ -789,20 +836,22 @@
789
836
  ? self.config.maxTime
790
837
  : self.config.maxDate;
791
838
  hours = Math.min(hours, maxTime.getHours());
792
- if (hours === maxTime.getHours())
839
+ if (hours === maxTime.getHours()) {
793
840
  minutes = Math.min(minutes, maxTime.getMinutes());
794
- if (minutes === maxTime.getMinutes())
795
- seconds = Math.min(seconds, maxTime.getSeconds());
841
+ if (minutes === maxTime.getMinutes())
842
+ seconds = Math.min(seconds, maxTime.getSeconds());
843
+ }
796
844
  }
797
845
  if (limitMinHours) {
798
846
  var minTime = self.config.minTime !== undefined
799
847
  ? self.config.minTime
800
848
  : self.config.minDate;
801
849
  hours = Math.max(hours, minTime.getHours());
802
- if (hours === minTime.getHours() && minutes < minTime.getMinutes())
803
- minutes = minTime.getMinutes();
804
- if (minutes === minTime.getMinutes())
805
- seconds = Math.max(seconds, minTime.getSeconds());
850
+ if (hours === minTime.getHours()) {
851
+ minutes = Math.max(minutes, minTime.getMinutes());
852
+ if (minutes === minTime.getMinutes())
853
+ seconds = Math.max(seconds, minTime.getSeconds());
854
+ }
806
855
  }
807
856
  }
808
857
  setHours(hours, minutes, seconds);
@@ -812,7 +861,7 @@
812
861
  */
813
862
  function setHoursFromDate(dateObj) {
814
863
  var date = dateObj || self.latestSelectedDateObj;
815
- if (date && date instanceof Date) {
864
+ if (date) {
816
865
  setHours(date.getHours(), date.getMinutes(), date.getSeconds());
817
866
  }
818
867
  }
@@ -846,6 +895,9 @@
846
895
  */
847
896
  function onYearInput(event) {
848
897
  var eventTarget = getEventTarget(event);
898
+ // bound on monthNav, which also holds the month dropdown
899
+ if (self.yearElements.indexOf(eventTarget) === -1)
900
+ return;
849
901
  var year = parseInt(eventTarget.value) + (event.delta || 0);
850
902
  if (year / 1000 > 1 ||
851
903
  (event.key === "Enter" && !/[^\d]/.test(year.toString()))) {
@@ -871,6 +923,26 @@
871
923
  function triggerChange() {
872
924
  triggerEvent("onChange");
873
925
  }
926
+ /**
927
+ * Listens for what an open calendar answers to outside itself: a press or a
928
+ * focus elsewhere closes it, a resize moves it
929
+ */
930
+ function bindOpenEvents() {
931
+ var listen = function (target, event, handler, options) {
932
+ target.addEventListener(event, handler, options);
933
+ openHandlers.push({
934
+ remove: function () { return target.removeEventListener(event, handler, options); },
935
+ });
936
+ };
937
+ if (!self.config.static)
938
+ listen(win, "resize", debounce(onResize, 50));
939
+ listen(doc, win.ontouchstart !== undefined ? "touchstart" : "mousedown", documentClick);
940
+ listen(doc, "focus", documentClick, { capture: true });
941
+ }
942
+ function unbindOpenEvents() {
943
+ openHandlers.forEach(function (h) { return h.remove(); });
944
+ openHandlers = [];
945
+ }
874
946
  /**
875
947
  * Adds all the necessary event listeners
876
948
  */
@@ -886,7 +958,6 @@
886
958
  setupMobile();
887
959
  return;
888
960
  }
889
- var debouncedResize = debounce(onResize, 50);
890
961
  self._debouncedChange = debounce(triggerChange, DEBOUNCED_CHANGE_MS);
891
962
  if (self.daysContainer && !/iPhone|iPad|iPod/i.test(navigator.userAgent))
892
963
  bind(self.daysContainer, "mouseover", function (e) {
@@ -897,13 +968,6 @@
897
968
  if (self.calendarContainer !== undefined) {
898
969
  bind(self.calendarContainer, "keydown", onKeyDown);
899
970
  }
900
- if (!self.config.inline && !self.config.static)
901
- bind(win, "resize", debouncedResize);
902
- if (win.ontouchstart !== undefined)
903
- bind(doc, "touchstart", documentClick);
904
- else
905
- bind(doc, "mousedown", documentClick);
906
- bind(doc, "focus", documentClick, { capture: true });
907
971
  if (self.config.clickOpens === true) {
908
972
  bind(self._input, "focus", self.open);
909
973
  bind(self._input, "click", self.open);
@@ -913,28 +977,43 @@
913
977
  bind(self.monthNav, ["keyup", "increment"], onYearInput);
914
978
  bind(self.daysContainer, "click", selectDate);
915
979
  }
916
- if (self.timeContainer !== undefined &&
917
- self.minuteElement !== undefined &&
918
- self.hourElement !== undefined) {
919
- var selText = function (e) {
920
- return getEventTarget(e).select();
921
- };
922
- bind(self.timeContainer, ["increment"], updateTime);
923
- bind(self.timeContainer, "blur", updateTime, { capture: true });
924
- bind(self.timeContainer, "click", timeIncrement);
925
- bind([self.hourElement, self.minuteElement], ["focus", "click"], selText);
926
- if (self.secondElement !== undefined)
927
- bind(self.secondElement, "focus", function () { return self.secondElement && self.secondElement.select(); });
928
- if (self.amPM !== undefined) {
929
- bind(self.amPM, "click", function (e) {
930
- updateTime(e);
931
- });
932
- }
933
- }
980
+ bindTimeEvents();
934
981
  if (self.config.allowInput) {
935
982
  bind(self._input, "blur", onBlur);
936
983
  }
937
984
  }
985
+ function bindTimeEvents() {
986
+ if (self.timeContainer === undefined ||
987
+ self.minuteElement === undefined ||
988
+ self.hourElement === undefined)
989
+ return;
990
+ var selText = function (e) {
991
+ return getEventTarget(e).select();
992
+ };
993
+ bind(self.timeContainer, ["increment"], updateTime);
994
+ bind(self.timeContainer, "blur", updateTime, { capture: true });
995
+ bind(self.timeContainer, "click", timeIncrement);
996
+ bind([self.hourElement, self.minuteElement], ["focus", "click"], selText);
997
+ if (self.secondElement !== undefined)
998
+ bind(self.secondElement, "focus", function () { return self.secondElement && self.secondElement.select(); });
999
+ if (self.amPM !== undefined) {
1000
+ bind(self.amPM, "click", function (e) {
1001
+ updateTime(e);
1002
+ });
1003
+ }
1004
+ }
1005
+ /**
1006
+ * The date, or the minDate or maxDate it falls outside of; the view falls
1007
+ * back to it when there is no selected date to show
1008
+ */
1009
+ function withinLimits(date) {
1010
+ var _a = self.config, minDate = _a.minDate, maxDate = _a.maxDate;
1011
+ if (minDate && minDate.getTime() > date.getTime())
1012
+ return minDate;
1013
+ if (maxDate && maxDate.getTime() < date.getTime())
1014
+ return maxDate;
1015
+ return date;
1016
+ }
938
1017
  /**
939
1018
  * Set the calendar view to a particular date.
940
1019
  * @param {Date} jumpDate the date to set the view to
@@ -943,12 +1022,7 @@
943
1022
  function jumpToDate(jumpDate, triggerChange) {
944
1023
  var jumpTo = jumpDate !== undefined
945
1024
  ? self.parseDate(jumpDate)
946
- : self.latestSelectedDateObj ||
947
- (self.config.minDate && self.config.minDate > self.now
948
- ? self.config.minDate
949
- : self.config.maxDate && self.config.maxDate < self.now
950
- ? self.config.maxDate
951
- : self.now);
1025
+ : self.latestSelectedDateObj || withinLimits(self.now);
952
1026
  var oldYear = self.currentYear;
953
1027
  var oldMonth = self.currentMonth;
954
1028
  try {
@@ -962,15 +1036,17 @@
962
1036
  e.message = "Invalid date supplied: " + jumpTo;
963
1037
  self.config.errorHandler(e);
964
1038
  }
965
- if (triggerChange && self.currentYear !== oldYear) {
1039
+ if (triggerChange)
1040
+ triggerViewChange(oldYear, oldMonth);
1041
+ self.redraw();
1042
+ }
1043
+ function triggerViewChange(oldYear, oldMonth) {
1044
+ if (self.currentYear !== oldYear) {
966
1045
  triggerEvent("onYearChange");
967
- buildMonthSwitch();
968
1046
  }
969
- if (triggerChange &&
970
- (self.currentYear !== oldYear || self.currentMonth !== oldMonth)) {
1047
+ if (self.currentYear !== oldYear || self.currentMonth !== oldMonth) {
971
1048
  triggerEvent("onMonthChange");
972
1049
  }
973
- self.redraw();
974
1050
  }
975
1051
  /**
976
1052
  * The up/down arrow handler for time inputs
@@ -1044,8 +1120,9 @@
1044
1120
  if (self.element.parentNode)
1045
1121
  self.element.parentNode.insertBefore(wrapper, self.element);
1046
1122
  wrapper.appendChild(self.element);
1047
- if (self.altInput)
1048
- wrapper.appendChild(self.altInput);
1123
+ // next to the input, which with wrap is inside self.element
1124
+ if (self.altInput && self.input.parentNode)
1125
+ self.input.parentNode.insertBefore(self.altInput, self.input.nextSibling);
1049
1126
  wrapper.appendChild(self.calendarContainer);
1050
1127
  }
1051
1128
  }
@@ -1065,24 +1142,25 @@
1065
1142
  dayElement.classList.add("today");
1066
1143
  dayElement.setAttribute("aria-current", "date");
1067
1144
  }
1068
- if (dateIsEnabled) {
1145
+ if (dateIsEnabled)
1069
1146
  dayElement.tabIndex = -1;
1070
- if (isDateSelected(date)) {
1071
- dayElement.classList.add("selected");
1147
+ else
1148
+ dayElement.classList.add("flatpickr-disabled");
1149
+ // a selected date can be disabled, e.g. one kept by allowInvalidPreload
1150
+ if (isDateSelected(date)) {
1151
+ dayElement.classList.add("selected");
1152
+ // keyboard navigation starts from here, and disabled days can't be focused
1153
+ if (dateIsEnabled)
1072
1154
  self.selectedDateElem = dayElement;
1073
- if (self.config.mode === "range") {
1074
- toggleClass(dayElement, "startRange", self.selectedDates[0] &&
1075
- compareDates(date, self.selectedDates[0], true) === 0);
1076
- toggleClass(dayElement, "endRange", self.selectedDates[1] &&
1077
- compareDates(date, self.selectedDates[1], true) === 0);
1078
- if (className === "nextMonthDay")
1079
- dayElement.classList.add("inRange");
1080
- }
1155
+ if (self.config.mode === "range") {
1156
+ toggleClass(dayElement, "startRange", self.selectedDates[0] &&
1157
+ compareDates(date, self.selectedDates[0], true) === 0);
1158
+ toggleClass(dayElement, "endRange", self.selectedDates[1] &&
1159
+ compareDates(date, self.selectedDates[1], true) === 0);
1160
+ if (className === "nextMonthDay")
1161
+ dayElement.classList.add("inRange");
1081
1162
  }
1082
1163
  }
1083
- else {
1084
- dayElement.classList.add("flatpickr-disabled");
1085
- }
1086
1164
  if (self.config.mode === "range") {
1087
1165
  if (isDateInRange(date) && !isDateSelected(date))
1088
1166
  dayElement.classList.add("inRange");
@@ -1116,35 +1194,49 @@
1116
1194
  }
1117
1195
  return undefined;
1118
1196
  }
1119
- function getNextAvailableDay(current, delta) {
1120
- var givenMonth = current.className.indexOf("Month") === -1
1121
- ? current.dateObj.getMonth()
1122
- : self.currentMonth;
1123
- var endMonth = delta > 0 ? self.config.showMonths : -1;
1124
- var loopDelta = delta > 0 ? 1 : -1;
1125
- for (var m = givenMonth - self.currentMonth; m != endMonth; m += loopDelta) {
1126
- var month = self.daysContainer.children[m];
1127
- var startIndex = givenMonth - self.currentMonth === m
1128
- ? current.$i + delta
1129
- : delta < 0
1130
- ? month.children.length - 1
1131
- : 0;
1132
- var numMonthDays = month.children.length;
1133
- for (var i = startIndex; i >= 0 && i < numMonthDays && i != (delta > 0 ? numMonthDays : -1); i += loopDelta) {
1134
- var c = month.children[i];
1135
- if (c.className.indexOf("hidden") === -1 &&
1136
- isEnabled(c.dateObj) &&
1137
- Math.abs(current.$i - i) >= Math.abs(delta))
1138
- return focusOnDayElem(c);
1139
- }
1197
+ function findEnabledDate(from, step) {
1198
+ var limit = step > 0 ? self.config.maxDate : self.config.minDate;
1199
+ // stop at minDate/maxDate, and after ten years either way
1200
+ for (var i = 0; i <= 3653; i++) {
1201
+ var date = new Date(from.getFullYear(), from.getMonth(), from.getDate() + i * step);
1202
+ if (limit !== undefined && compareDates(date, limit) * step > 0)
1203
+ return undefined;
1204
+ if (isEnabled(date))
1205
+ return date;
1140
1206
  }
1141
- self.changeMonth(loopDelta);
1142
- focusOnDay(getFirstAvailableDay(loopDelta), 0);
1143
1207
  return undefined;
1144
1208
  }
1209
+ function getVisibleDay(date) {
1210
+ var days = self.daysContainer.querySelectorAll(".flatpickr-day:not(.hidden)");
1211
+ for (var i = 0; i < days.length; i++) {
1212
+ if (compareDates(days[i].dateObj, date) === 0)
1213
+ return days[i];
1214
+ }
1215
+ return undefined;
1216
+ }
1217
+ function focusOnDate(date) {
1218
+ if (getVisibleDay(date) === undefined) {
1219
+ var firstMonth = self.currentYear * 12 + self.currentMonth;
1220
+ var targetMonth = date.getFullYear() * 12 + date.getMonth();
1221
+ // bring the target month in at the edge of the view it moves towards
1222
+ changeMonth(targetMonth < firstMonth
1223
+ ? targetMonth - firstMonth
1224
+ : targetMonth - (firstMonth + self.config.showMonths - 1));
1225
+ }
1226
+ var dayElem = getVisibleDay(date);
1227
+ if (dayElem !== undefined)
1228
+ focusOnDayElem(dayElem);
1229
+ }
1145
1230
  function focusOnDay(current, offset) {
1231
+ // no day grid, or a plugin such as monthSelect has replaced it
1232
+ if (self.daysContainer === undefined ||
1233
+ !self.rContainer.contains(self.daysContainer))
1234
+ return;
1146
1235
  var activeElement = getClosestActiveElement();
1147
- var dayFocused = isInView(activeElement || doc.body);
1236
+ var step = offset > 0 ? 1 : -1;
1237
+ var dayFocused = activeElement !== null &&
1238
+ activeElement.classList.contains("flatpickr-day") &&
1239
+ isInView(activeElement);
1148
1240
  var startElem = current !== undefined
1149
1241
  ? current
1150
1242
  : dayFocused
@@ -1153,15 +1245,28 @@
1153
1245
  ? self.selectedDateElem
1154
1246
  : self.todayDateElem !== undefined && isInView(self.todayDateElem)
1155
1247
  ? self.todayDateElem
1156
- : getFirstAvailableDay(offset > 0 ? 1 : -1);
1248
+ : getFirstAvailableDay(step);
1157
1249
  if (startElem === undefined) {
1158
- self._input.focus();
1250
+ // nothing enabled in view: look past its edge, and keep the focus in
1251
+ // the calendar if there is nothing there either (#3064)
1252
+ var target = offset !== 0
1253
+ ? findEnabledDate(step > 0
1254
+ ? new Date(self.currentYear, self.currentMonth + self.config.showMonths, 1)
1255
+ : new Date(self.currentYear, self.currentMonth, 0), step)
1256
+ : undefined;
1257
+ if (target !== undefined)
1258
+ focusOnDate(target);
1259
+ else
1260
+ self.daysContainer.focus();
1159
1261
  }
1160
1262
  else if (!dayFocused) {
1161
1263
  focusOnDayElem(startElem);
1162
1264
  }
1163
1265
  else {
1164
- getNextAvailableDay(startElem, offset);
1266
+ var dateObj = startElem.dateObj;
1267
+ var target = findEnabledDate(new Date(dateObj.getFullYear(), dateObj.getMonth(), dateObj.getDate() + offset), step);
1268
+ if (target !== undefined)
1269
+ focusOnDate(target);
1165
1270
  }
1166
1271
  }
1167
1272
  function buildMonthDays(year, month) {
@@ -1206,9 +1311,11 @@
1206
1311
  if (self.config.mode === "range" && self.selectedDates.length === 1) {
1207
1312
  onMouseOver();
1208
1313
  }
1314
+ triggerEvent("onDaysBuilt");
1209
1315
  }
1210
1316
  function buildMonthSwitch() {
1211
- if (self.config.showMonths > 1 ||
1317
+ if (self.monthsDropdownContainer === undefined ||
1318
+ self.config.showMonths > 1 ||
1212
1319
  self.config.monthSelectorType !== "dropdown")
1213
1320
  return;
1214
1321
  var shouldBuildMonth = function (month) {
@@ -1236,7 +1343,7 @@
1236
1343
  self.monthsDropdownContainer.appendChild(month);
1237
1344
  }
1238
1345
  }
1239
- function buildMonth() {
1346
+ function buildMonth(index) {
1240
1347
  var container = createElement("div", "flatpickr-month");
1241
1348
  var monthNavFragment = doc.createDocumentFragment();
1242
1349
  var monthElement;
@@ -1246,6 +1353,7 @@
1246
1353
  }
1247
1354
  else {
1248
1355
  self.monthsDropdownContainer = createElement("select", "flatpickr-monthDropdown-months");
1356
+ self.monthsDropdownContainer.id = idPrefix + "-month";
1249
1357
  self.monthsDropdownContainer.setAttribute("aria-label", self.l10n.monthAriaLabel);
1250
1358
  bind(self.monthsDropdownContainer, "change", function (e) {
1251
1359
  var target = getEventTarget(e);
@@ -1256,7 +1364,10 @@
1256
1364
  buildMonthSwitch();
1257
1365
  monthElement = self.monthsDropdownContainer;
1258
1366
  }
1259
- var yearInput = createNumberInput("cur-year", { tabindex: "-1" });
1367
+ var yearInput = createNumberInput("cur-year", {
1368
+ id: idPrefix + "-year-" + index,
1369
+ tabindex: "-1",
1370
+ });
1260
1371
  var yearElement = yearInput.getElementsByTagName("input")[0];
1261
1372
  yearElement.setAttribute("aria-label", self.l10n.yearAriaLabel);
1262
1373
  if (self.config.minDate) {
@@ -1286,8 +1397,8 @@
1286
1397
  self.yearElements = [];
1287
1398
  self.monthElements = [];
1288
1399
  }
1289
- for (var m = self.config.showMonths; m--;) {
1290
- var month = buildMonth();
1400
+ for (var i = 0; i < self.config.showMonths; i++) {
1401
+ var month = buildMonth(i);
1291
1402
  self.yearElements.push(month.yearElement);
1292
1403
  self.monthElements.push(month.monthElement);
1293
1404
  self.monthNav.appendChild(month.container);
@@ -1334,10 +1445,12 @@
1334
1445
  self.timeContainer.tabIndex = -1;
1335
1446
  var separator = createElement("span", "flatpickr-time-separator", ":");
1336
1447
  var hourInput = createNumberInput("flatpickr-hour", {
1448
+ id: idPrefix + "-hour",
1337
1449
  "aria-label": self.l10n.hourAriaLabel,
1338
1450
  });
1339
1451
  self.hourElement = hourInput.getElementsByTagName("input")[0];
1340
1452
  var minuteInput = createNumberInput("flatpickr-minute", {
1453
+ id: idPrefix + "-minute",
1341
1454
  "aria-label": self.l10n.minuteAriaLabel,
1342
1455
  });
1343
1456
  self.minuteElement = minuteInput.getElementsByTagName("input")[0];
@@ -1365,7 +1478,9 @@
1365
1478
  self.timeContainer.classList.add("time24hr");
1366
1479
  if (self.config.enableSeconds) {
1367
1480
  self.timeContainer.classList.add("hasSeconds");
1368
- var secondInput = createNumberInput("flatpickr-second");
1481
+ var secondInput = createNumberInput("flatpickr-second", {
1482
+ id: idPrefix + "-second",
1483
+ });
1369
1484
  self.secondElement = secondInput.getElementsByTagName("input")[0];
1370
1485
  self.secondElement.value = pad(self.latestSelectedDateObj
1371
1486
  ? self.latestSelectedDateObj.getSeconds()
@@ -1388,6 +1503,28 @@
1388
1503
  }
1389
1504
  return self.timeContainer;
1390
1505
  }
1506
+ // Rebuilds the time picker after a time option changes through set(). The
1507
+ // core reads the time elements' presence as "time is enabled", so they are
1508
+ // cleared, not just hidden.
1509
+ function rebuildTime() {
1510
+ if (self.isMobile)
1511
+ return setMobileInputType();
1512
+ var previous = self.timeContainer;
1513
+ self.timeContainer = self.hourElement = self.minuteElement = undefined;
1514
+ self.secondElement = self.amPM = undefined;
1515
+ self.calendarContainer.classList.remove("hasTime");
1516
+ self.calendarContainer.classList.remove("noCalendar");
1517
+ if (self.config.enableTime) {
1518
+ self.calendarContainer.insertBefore(buildTime(), previous ||
1519
+ (self.innerContainer
1520
+ ? self.innerContainer.nextSibling
1521
+ : self.calendarContainer.firstChild));
1522
+ bindTimeEvents();
1523
+ setHoursFromDate();
1524
+ }
1525
+ if (previous)
1526
+ self.calendarContainer.removeChild(previous);
1527
+ }
1391
1528
  function buildWeekdays() {
1392
1529
  if (!self.weekdayContainer)
1393
1530
  self.weekdayContainer = createElement("div", "flatpickr-weekdays");
@@ -1433,8 +1570,8 @@
1433
1570
  return;
1434
1571
  self.currentMonth += delta;
1435
1572
  if (self.currentMonth < 0 || self.currentMonth > 11) {
1436
- self.currentYear += self.currentMonth > 11 ? 1 : -1;
1437
- self.currentMonth = (self.currentMonth + 12) % 12;
1573
+ self.currentYear += Math.floor(self.currentMonth / 12);
1574
+ self.currentMonth = ((self.currentMonth % 12) + 12) % 12;
1438
1575
  triggerEvent("onYearChange");
1439
1576
  buildMonthSwitch();
1440
1577
  }
@@ -1445,16 +1582,16 @@
1445
1582
  function clear(triggerChangeEvent, toInitial) {
1446
1583
  if (triggerChangeEvent === void 0) { triggerChangeEvent = true; }
1447
1584
  if (toInitial === void 0) { toInitial = true; }
1448
- self.input.value = "";
1449
- if (self.altInput !== undefined)
1450
- self.altInput.value = "";
1451
1585
  if (self.mobileInput !== undefined)
1452
1586
  self.mobileInput.value = "";
1453
1587
  self.selectedDates = [];
1454
1588
  self.latestSelectedDateObj = undefined;
1589
+ self._showValue();
1455
1590
  if (toInitial === true) {
1456
- self.currentYear = self._initialDate.getFullYear();
1457
- self.currentMonth = self._initialDate.getMonth();
1591
+ // minDate and maxDate may have changed since init
1592
+ var initialDate = withinLimits(self._initialDate);
1593
+ self.currentYear = initialDate.getFullYear();
1594
+ self.currentMonth = initialDate.getMonth();
1458
1595
  }
1459
1596
  if (self.config.enableTime === true) {
1460
1597
  var _a = getDefaultHours(self.config), hours = _a.hours, minutes = _a.minutes, seconds = _a.seconds;
@@ -1467,6 +1604,7 @@
1467
1604
  }
1468
1605
  function close() {
1469
1606
  self.isOpen = false;
1607
+ unbindOpenEvents();
1470
1608
  if (!self.isMobile) {
1471
1609
  if (self.calendarContainer !== undefined) {
1472
1610
  self.calendarContainer.classList.remove("open");
@@ -1484,6 +1622,7 @@
1484
1622
  self._handlers[i].remove();
1485
1623
  }
1486
1624
  self._handlers = [];
1625
+ unbindOpenEvents();
1487
1626
  if (self.mobileInput) {
1488
1627
  if (self.mobileInput.parentNode)
1489
1628
  self.mobileInput.parentNode.removeChild(self.mobileInput);
@@ -1553,38 +1692,38 @@
1553
1692
  function isCalendarElem(elem) {
1554
1693
  return self.calendarContainer.contains(elem);
1555
1694
  }
1695
+ // Only bound while the calendar is open, by bindOpenEvents()
1556
1696
  function documentClick(e) {
1557
- if (self.isOpen && !self.config.inline) {
1558
- var eventTarget_1 = getEventTarget(e);
1559
- var isCalendarElement = isCalendarElem(eventTarget_1);
1560
- var isInput = eventTarget_1 === self.input ||
1561
- eventTarget_1 === self.altInput ||
1562
- self.element.contains(eventTarget_1);
1563
- var lostFocus = !isInput &&
1564
- !isCalendarElement &&
1565
- !isCalendarElem(e.relatedTarget);
1566
- var isIgnored = !self.config.ignoredFocusElements.some(function (elem) {
1567
- return elem.contains(eventTarget_1);
1568
- });
1569
- if (lostFocus && isIgnored) {
1570
- if (self.config.allowInput) {
1571
- self.setDate(self._input.value, false, self.config.altInput
1572
- ? self.config.altFormat
1573
- : self.config.dateFormat);
1574
- }
1575
- if (self.timeContainer !== undefined &&
1576
- self.minuteElement !== undefined &&
1577
- self.hourElement !== undefined &&
1578
- self.input.value !== "" &&
1579
- self.input.value !== undefined) {
1580
- updateTime();
1581
- }
1582
- self.close();
1583
- if (self.config &&
1584
- self.config.mode === "range" &&
1585
- self.selectedDates.length === 1)
1586
- self.clear(false);
1697
+ var eventTarget = getEventTarget(e);
1698
+ var isCalendarElement = isCalendarElem(eventTarget);
1699
+ var isInput = eventTarget === self.input ||
1700
+ eventTarget === self.altInput ||
1701
+ self.element.contains(eventTarget);
1702
+ var lostFocus = !isInput &&
1703
+ !isCalendarElement &&
1704
+ !isCalendarElem(e.relatedTarget);
1705
+ var isIgnored = !self.config.ignoredFocusElements.some(function (elem) {
1706
+ return elem.contains(eventTarget);
1707
+ });
1708
+ if (lostFocus && isIgnored) {
1709
+ var committed = self.config.allowInput ? commitTypedValue() : undefined;
1710
+ // a typed value has already overwritten the time inputs
1711
+ if (committed === undefined &&
1712
+ self.timeContainer !== undefined &&
1713
+ self.minuteElement !== undefined &&
1714
+ self.hourElement !== undefined &&
1715
+ self.input.value !== "" &&
1716
+ self.input.value !== undefined) {
1717
+ updateTime();
1587
1718
  }
1719
+ self.close();
1720
+ // onClose may have destroyed the instance
1721
+ if (self.config === undefined)
1722
+ return;
1723
+ if (self.config.mode === "range" && self.selectedDates.length === 1)
1724
+ self.clear(false);
1725
+ // announce the outcome of the whole click, like selecting a day does
1726
+ announceCommit(committed);
1588
1727
  }
1589
1728
  }
1590
1729
  function changeYear(newYear) {
@@ -1605,7 +1744,6 @@
1605
1744
  if (isNewYear) {
1606
1745
  self.redraw();
1607
1746
  triggerEvent("onYearChange");
1608
- buildMonthSwitch();
1609
1747
  }
1610
1748
  }
1611
1749
  function isEnabled(date, timeless) {
@@ -1662,16 +1800,55 @@
1662
1800
  return false;
1663
1801
  }
1664
1802
  function onBlur(e) {
1665
- var isInput = e.target === self._input;
1666
- var valueChanged = self._input.value.trimEnd() !== getDateStr();
1667
- if (isInput &&
1668
- valueChanged &&
1669
- !(e.relatedTarget && isCalendarElem(e.relatedTarget))) {
1670
- self.setDate(self._input.value, true, e.target === self.altInput
1671
- ? self.config.altFormat
1672
- : self.config.dateFormat);
1803
+ if (e.target === self._input &&
1804
+ !(e.relatedTarget && isCalendarElem(e.relatedTarget)))
1805
+ announceCommit(commitTypedValue());
1806
+ }
1807
+ /**
1808
+ * What was typed into the input since showValue() wrote it, if anything.
1809
+ * A plugin that lays the value out across inputs of its own (rangePlugin)
1810
+ * reads it from those
1811
+ */
1812
+ function typedValue() {
1813
+ return self._input.value.trimEnd() === getDateStr()
1814
+ ? undefined
1815
+ : self._input.value;
1816
+ }
1817
+ /**
1818
+ * Applies what was typed into the input, if anything, without announcing it.
1819
+ * Returns the state to compare against when announcing.
1820
+ */
1821
+ function commitTypedValue() {
1822
+ var typed = self._typedValue();
1823
+ if (typed === undefined)
1824
+ return undefined;
1825
+ var committed = {
1826
+ times: getSelectedTimes(),
1827
+ year: self.currentYear,
1828
+ month: self.currentMonth,
1829
+ };
1830
+ self.setDate(typed, false, self.config.altInput ? self.config.altFormat : self.config.dateFormat);
1831
+ // hold a typed time within minTime/maxTime, as the time inputs do
1832
+ if (self.hourElement !== undefined) {
1833
+ setHoursFromInputs();
1834
+ updateValue(false);
1835
+ }
1836
+ return committed;
1837
+ }
1838
+ function announceCommit(committed) {
1839
+ if (committed === undefined)
1840
+ return;
1841
+ triggerViewChange(committed.year, committed.month);
1842
+ if (getSelectedTimes() !== committed.times) {
1843
+ // an emptied value announces like clear(), which leaves out onValueUpdate
1844
+ if (self.selectedDates.length > 0)
1845
+ triggerEvent("onValueUpdate");
1846
+ triggerEvent("onChange");
1673
1847
  }
1674
1848
  }
1849
+ function getSelectedTimes() {
1850
+ return self.selectedDates.map(function (d) { return d.getTime(); }).join();
1851
+ }
1675
1852
  function onKeyDown(e) {
1676
1853
  // e.key e.keyCode
1677
1854
  // "Backspace" 8
@@ -1690,11 +1867,13 @@
1690
1867
  var allowInput = self.config.allowInput;
1691
1868
  var allowKeydown = self.isOpen && (!allowInput || !isInput);
1692
1869
  var allowInlineKeydown = self.config.inline && isInput && !allowInput;
1870
+ // the month dropdown moves through its options with the arrow keys itself
1871
+ var isMonthDropdownArrowKey = eventTarget === self.monthsDropdownContainer &&
1872
+ e.keyCode >= 37 &&
1873
+ e.keyCode <= 40;
1693
1874
  if (e.keyCode === 13 && isInput) {
1694
1875
  if (allowInput) {
1695
- self.setDate(self._input.value, true, eventTarget === self.altInput
1696
- ? self.config.altFormat
1697
- : self.config.dateFormat);
1876
+ announceCommit(commitTypedValue());
1698
1877
  self.close();
1699
1878
  return eventTarget.blur();
1700
1879
  }
@@ -1702,9 +1881,10 @@
1702
1881
  self.open();
1703
1882
  }
1704
1883
  }
1705
- else if (isCalendarElem(eventTarget) ||
1706
- allowKeydown ||
1707
- allowInlineKeydown) {
1884
+ else if (!isMonthDropdownArrowKey &&
1885
+ (isCalendarElem(eventTarget) ||
1886
+ allowKeydown ||
1887
+ allowInlineKeydown)) {
1708
1888
  var isTimeObj = !!self.timeContainer &&
1709
1889
  self.timeContainer.contains(eventTarget);
1710
1890
  switch (e.keyCode) {
@@ -1756,7 +1936,8 @@
1756
1936
  if ((self.daysContainer &&
1757
1937
  eventTarget.$i !== undefined) ||
1758
1938
  eventTarget === self.input ||
1759
- eventTarget === self.altInput) {
1939
+ eventTarget === self.altInput ||
1940
+ eventTarget === self.daysContainer) {
1760
1941
  if (e.ctrlKey) {
1761
1942
  e.stopPropagation();
1762
1943
  changeYear(self.currentYear - delta);
@@ -1904,6 +2085,7 @@
1904
2085
  var wasOpen = self.isOpen;
1905
2086
  self.isOpen = true;
1906
2087
  if (!wasOpen) {
2088
+ bindOpenEvents();
1907
2089
  self.calendarContainer.classList.add("open");
1908
2090
  self._input.classList.add("active");
1909
2091
  triggerEvent("onOpen");
@@ -1928,7 +2110,14 @@
1928
2110
  dateObj.getSeconds() > 0;
1929
2111
  }
1930
2112
  if (self.selectedDates) {
1931
- self.selectedDates = self.selectedDates.filter(function (d) { return isEnabled(d); });
2113
+ if (!self.config.allowInvalidPreload)
2114
+ self.selectedDates = filterEnabledDates(self.selectedDates, true);
2115
+ // the view and the time inputs follow the latest pick; move it only
2116
+ // when the new limit dropped it (#3002)
2117
+ if (self.latestSelectedDateObj &&
2118
+ self.selectedDates.indexOf(self.latestSelectedDateObj) === -1)
2119
+ self.latestSelectedDateObj =
2120
+ self.selectedDates[self.selectedDates.length - 1];
1932
2121
  if (!self.selectedDates.length && type === "min")
1933
2122
  setHoursFromDate(dateObj);
1934
2123
  updateValue();
@@ -1963,8 +2152,7 @@
1963
2152
  "enableSeconds",
1964
2153
  "disableMobile",
1965
2154
  ];
1966
- var userConfig = __assign(__assign({}, JSON.parse(JSON.stringify(element.dataset || {}))), instanceConfig);
1967
- var formats = {};
2155
+ Object.assign(userConfig, JSON.parse(JSON.stringify(element.dataset || {})), instanceConfig);
1968
2156
  self.config.parseDate = userConfig.parseDate;
1969
2157
  self.config.formatDate = userConfig.formatDate;
1970
2158
  Object.defineProperty(self.config, "enable", {
@@ -1979,23 +2167,6 @@
1979
2167
  self.config._disable = parseDateRules(dates);
1980
2168
  },
1981
2169
  });
1982
- var timeMode = userConfig.mode === "time";
1983
- if (!userConfig.dateFormat && (userConfig.enableTime || timeMode)) {
1984
- var defaultDateFormat = flatpickr.defaultConfig.dateFormat || defaults.dateFormat;
1985
- formats.dateFormat =
1986
- userConfig.noCalendar || timeMode
1987
- ? "H:i" + (userConfig.enableSeconds ? ":S" : "")
1988
- : defaultDateFormat + " H:i" + (userConfig.enableSeconds ? ":S" : "");
1989
- }
1990
- if (userConfig.altInput &&
1991
- (userConfig.enableTime || timeMode) &&
1992
- !userConfig.altFormat) {
1993
- var defaultAltFormat = flatpickr.defaultConfig.altFormat || defaults.altFormat;
1994
- formats.altFormat =
1995
- userConfig.noCalendar || timeMode
1996
- ? "h:i" + (userConfig.enableSeconds ? ":S K" : " K")
1997
- : defaultAltFormat + (" h:i" + (userConfig.enableSeconds ? ":S" : "") + " K");
1998
- }
1999
2170
  Object.defineProperty(self.config, "minDate", {
2000
2171
  get: function () { return self.config._minDate; },
2001
2172
  set: minMaxDateSetter("min"),
@@ -2019,7 +2190,7 @@
2019
2190
  self.config.noCalendar = true;
2020
2191
  self.config.enableTime = true;
2021
2192
  }
2022
- Object.assign(self.config, formats, userConfig);
2193
+ Object.assign(self.config, defaultFormats(), userConfig);
2023
2194
  for (var i = 0; i < boolOpts.length; i++)
2024
2195
  // https://github.com/microsoft/TypeScript/issues/31663
2025
2196
  self.config[boolOpts[i]] =
@@ -2028,14 +2199,6 @@
2028
2199
  HOOKS.filter(function (hook) { return self.config[hook] !== undefined; }).forEach(function (hook) {
2029
2200
  self.config[hook] = arrayify(self.config[hook] || []).map(bindToInstance);
2030
2201
  });
2031
- self.isMobile =
2032
- !self.config.disableMobile &&
2033
- !self.config.inline &&
2034
- self.config.mode === "single" &&
2035
- !self.config.disable.length &&
2036
- !self.config.enable &&
2037
- !self.config.weekNumbers &&
2038
- /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
2039
2202
  for (var i = 0; i < self.config.plugins.length; i++) {
2040
2203
  var pluginConf = self.config.plugins[i](self) || {};
2041
2204
  for (var key in pluginConf) {
@@ -2048,12 +2211,49 @@
2048
2211
  self.config[key] = pluginConf[key];
2049
2212
  }
2050
2213
  }
2214
+ // after the plugins, whose options (e.g. disableMobile) count too
2215
+ self.isMobile =
2216
+ !self.config.disableMobile &&
2217
+ !self.config.inline &&
2218
+ self.config.mode === "single" &&
2219
+ !self.config.disable.length &&
2220
+ !self.config.enable &&
2221
+ !self.config.weekNumbers &&
2222
+ /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
2051
2223
  if (!userConfig.altInputClass) {
2052
2224
  self.config.altInputClass =
2053
2225
  getInputElem().className + " " + self.config.altInputClass;
2054
2226
  }
2055
2227
  triggerEvent("onParseConfig");
2056
2228
  }
2229
+ // The dateFormat/altFormat the user's time options imply when they don't
2230
+ // give their own
2231
+ function defaultFormats() {
2232
+ var defaultDateFormat = flatpickr.defaultConfig.dateFormat || defaults.dateFormat;
2233
+ var defaultAltFormat = flatpickr.defaultConfig.altFormat || defaults.altFormat;
2234
+ var timeMode = userConfig.mode === "time";
2235
+ if (!userConfig.enableTime && !timeMode)
2236
+ return { dateFormat: defaultDateFormat, altFormat: defaultAltFormat };
2237
+ var timeOnly = userConfig.noCalendar || timeMode;
2238
+ var seconds = userConfig.enableSeconds ? ":S" : "";
2239
+ return {
2240
+ dateFormat: timeOnly
2241
+ ? "H:i" + seconds
2242
+ : defaultDateFormat + " H:i" + seconds,
2243
+ altFormat: !userConfig.altInput
2244
+ ? defaultAltFormat
2245
+ : timeOnly
2246
+ ? "h:i" + seconds + " K"
2247
+ : defaultAltFormat + (" h:i" + seconds + " K"),
2248
+ };
2249
+ }
2250
+ function updateDefaultFormats() {
2251
+ var formats = defaultFormats();
2252
+ if (userConfig.dateFormat === undefined)
2253
+ self.config.dateFormat = formats.dateFormat;
2254
+ if (userConfig.altFormat === undefined)
2255
+ self.config.altFormat = formats.altFormat;
2256
+ }
2057
2257
  function getInputElem() {
2058
2258
  return self.config.wrap
2059
2259
  ? element.querySelector("[data-input]")
@@ -2070,10 +2270,15 @@
2070
2270
  : undefined));
2071
2271
  tokenRegex.D = "(" + self.l10n.weekdays.shorthand.join("|") + ")";
2072
2272
  tokenRegex.l = "(" + self.l10n.weekdays.longhand.join("|") + ")";
2073
- tokenRegex.M = "(" + self.l10n.months.shorthand.join("|") + ")";
2074
- tokenRegex.F = "(" + self.l10n.months.longhand.join("|") + ")";
2075
- tokenRegex.K = "(" + self.l10n.amPM[0] + "|" + self.l10n.amPM[1] + "|" + self.l10n.amPM[0].toLowerCase() + "|" + self.l10n.amPM[1].toLowerCase() + ")";
2076
- var userConfig = __assign(__assign({}, instanceConfig), JSON.parse(JSON.stringify(element.dataset || {})));
2273
+ tokenRegex.M = "(" + self.l10n.months.shorthand
2274
+ .slice()
2275
+ .sort(function (a, b) { return b.length - a.length; })
2276
+ .join("|") + ")";
2277
+ tokenRegex.F = "(" + self.l10n.months.longhand
2278
+ .slice()
2279
+ .sort(function (a, b) { return b.length - a.length; })
2280
+ .join("|") + ")";
2281
+ tokenRegex.K = "(" + self.l10n.amPM[0] + "|" + self.l10n.amPM[1] + ")";
2077
2282
  if (userConfig.time_24hr === undefined &&
2078
2283
  flatpickr.defaultConfig.time_24hr === undefined) {
2079
2284
  self.config.time_24hr = self.l10n.time_24hr;
@@ -2089,15 +2294,28 @@
2089
2294
  return;
2090
2295
  triggerEvent("onPreCalendarPosition");
2091
2296
  var positionElement = customPositionElement || self._positionElement;
2092
- 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 = win.innerHeight - inputBounds.bottom, showOnTop = configPosVertical === "above" ||
2093
- (configPosVertical !== "below" &&
2094
- distanceFromBottom < calendarHeight &&
2095
- inputBounds.top > calendarHeight);
2096
- var top = win.pageYOffset +
2297
+ 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 = win.innerHeight - inputBounds.bottom, isAutoVertical = configPosVertical !== "above" && configPosVertical !== "below", fitsBelow = distanceFromBottom >= calendarHeight, fitsAbove = inputBounds.top > calendarHeight,
2298
+ // the page can't always be scrolled to what sticks out of the viewport
2299
+ // (scroll-locked modals, touch screens), so a calendar that fits
2300
+ // neither above nor below goes on the roomier side, kept in the viewport
2301
+ keepInViewport = isAutoVertical &&
2302
+ !fitsBelow &&
2303
+ !fitsAbove &&
2304
+ !self.config.static &&
2305
+ !self.config.inline, showOnTop = keepInViewport
2306
+ ? inputBounds.top > distanceFromBottom
2307
+ : configPosVertical === "above" ||
2308
+ (isAutoVertical && !fitsBelow && fitsAbove);
2309
+ var anchoredTop = win.pageYOffset +
2097
2310
  inputBounds.top +
2098
2311
  (!showOnTop ? positionElement.offsetHeight + 2 : -calendarHeight - 2);
2099
- toggleClass(self.calendarContainer, "arrowTop", !showOnTop);
2100
- toggleClass(self.calendarContainer, "arrowBottom", showOnTop);
2312
+ // a calendar taller than the viewport sticks to its top
2313
+ var top = keepInViewport
2314
+ ? Math.max(win.pageYOffset, Math.min(anchoredTop, win.pageYOffset + win.innerHeight - calendarHeight))
2315
+ : anchoredTop;
2316
+ // a calendar kept in the viewport may cover the input it would point at
2317
+ toggleClass(self.calendarContainer, "arrowTop", !keepInViewport && !showOnTop);
2318
+ toggleClass(self.calendarContainer, "arrowBottom", !keepInViewport && showOnTop);
2101
2319
  if (self.config.inline)
2102
2320
  return;
2103
2321
  var left = win.pageXOffset + inputBounds.left;
@@ -2139,24 +2357,32 @@
2139
2357
  }
2140
2358
  function getContainingBlockOrigin() {
2141
2359
  var containingBlock = self.calendarContainer.offsetParent;
2142
- // offsetParent is null while the calendar is hidden, and is <body> both
2143
- // when <body> is positioned and when there is no positioned ancestor
2144
- if (containingBlock === null ||
2145
- (containingBlock === doc.body &&
2146
- win.getComputedStyle(containingBlock).position === "static"))
2360
+ // offsetParent is null while the calendar is hidden, and stops at <body>
2361
+ // even when <body> is static: the containing block is then <html> if that
2362
+ // is positioned (scroll locks fix it at -scrollY), or else the page
2363
+ if (containingBlock === doc.body && isStatic(doc.body))
2364
+ containingBlock = isStatic(doc.documentElement)
2365
+ ? null
2366
+ : doc.documentElement;
2367
+ if (containingBlock === null)
2147
2368
  return { top: 0, left: 0 };
2148
2369
  var bounds = containingBlock.getBoundingClientRect();
2370
+ // <html>'s scroll offsets are the page's, already in pageX/YOffset
2371
+ var isRoot = containingBlock === doc.documentElement;
2149
2372
  return {
2150
2373
  top: win.pageYOffset +
2151
2374
  bounds.top +
2152
2375
  containingBlock.clientTop -
2153
- containingBlock.scrollTop,
2376
+ (isRoot ? 0 : containingBlock.scrollTop),
2154
2377
  left: win.pageXOffset +
2155
2378
  bounds.left +
2156
2379
  containingBlock.clientLeft -
2157
- containingBlock.scrollLeft,
2380
+ (isRoot ? 0 : containingBlock.scrollLeft),
2158
2381
  };
2159
2382
  }
2383
+ function isStatic(elem) {
2384
+ return win.getComputedStyle(elem).position === "static";
2385
+ }
2160
2386
  function redraw() {
2161
2387
  if (self.config.noCalendar || self.isMobile)
2162
2388
  return;
@@ -2189,9 +2415,10 @@
2189
2415
  return;
2190
2416
  var target = t;
2191
2417
  var selectedDate = (self.latestSelectedDateObj = new Date(target.dateObj.getTime()));
2192
- var shouldChangeMonth = (selectedDate.getMonth() < self.currentMonth ||
2193
- selectedDate.getMonth() >
2194
- self.currentMonth + self.config.showMonths - 1) &&
2418
+ var firstMonth = self.currentYear * 12 + self.currentMonth;
2419
+ var selectedMonth = selectedDate.getFullYear() * 12 + selectedDate.getMonth();
2420
+ var shouldChangeMonth = (selectedMonth < firstMonth ||
2421
+ selectedMonth > firstMonth + self.config.showMonths - 1) &&
2195
2422
  self.config.mode !== "range";
2196
2423
  self.selectedDateElem = target;
2197
2424
  if (self.config.mode === "single")
@@ -2255,6 +2482,9 @@
2255
2482
  minDate: [jumpToDate],
2256
2483
  maxDate: [jumpToDate],
2257
2484
  positionElement: [updatePositionElement],
2485
+ enableTime: [updateDefaultFormats, rebuildTime],
2486
+ enableSeconds: [updateDefaultFormats, rebuildTime],
2487
+ time_24hr: [rebuildTime],
2258
2488
  clickOpens: [
2259
2489
  function () {
2260
2490
  if (self.config.clickOpens === true) {
@@ -2271,6 +2501,7 @@
2271
2501
  function set(option, value) {
2272
2502
  if (option !== null && typeof option === "object") {
2273
2503
  Object.assign(self.config, option);
2504
+ Object.assign(userConfig, option);
2274
2505
  for (var key in option) {
2275
2506
  if (CALLBACKS[key] !== undefined)
2276
2507
  CALLBACKS[key].forEach(function (x) { return x(); });
@@ -2278,6 +2509,7 @@
2278
2509
  }
2279
2510
  else {
2280
2511
  self.config[option] = value;
2512
+ userConfig[option] = value;
2281
2513
  if (CALLBACKS[option] !== undefined)
2282
2514
  CALLBACKS[option].forEach(function (x) { return x(); });
2283
2515
  else if (HOOKS.indexOf(option) > -1)
@@ -2286,6 +2518,17 @@
2286
2518
  self.redraw();
2287
2519
  updateValue(true);
2288
2520
  }
2521
+ /**
2522
+ * Leaves out the dates minDate, maxDate, enable or disable rule out. The two
2523
+ * ends of a range go together: either on its own reads as a range whose
2524
+ * start was just picked (#3108)
2525
+ */
2526
+ function filterEnabledDates(dates, timeless) {
2527
+ var enabled = dates.filter(function (d) { return isEnabled(d, timeless); });
2528
+ return self.config.mode === "range" && enabled.length < dates.length
2529
+ ? []
2530
+ : enabled;
2531
+ }
2289
2532
  function setSelectedDate(inputDate, format) {
2290
2533
  var dates = [];
2291
2534
  if (inputDate instanceof Array)
@@ -2307,14 +2550,21 @@
2307
2550
  dates = inputDate
2308
2551
  .split(self.l10n.rangeSeparator)
2309
2552
  .map(function (date) { return self.parseDate(date, format); });
2553
+ // getDateStr() writes a same-day range as its one date without
2554
+ // enableTime (#1478): it reads back as both ends (#3010)
2555
+ if (dates.length === 1 && !self.config.enableTime)
2556
+ dates.push(self.parseDate(inputDate, format));
2310
2557
  break;
2311
2558
  }
2312
2559
  }
2313
2560
  else
2314
2561
  self.config.errorHandler(new Error("Invalid date supplied: " + JSON.stringify(inputDate)));
2315
- self.selectedDates = (self.config.allowInvalidPreload
2316
- ? dates
2317
- : dates.filter(function (d) { return d instanceof Date && isEnabled(d, false); }));
2562
+ // allowInvalidPreload keeps the dates the rules rule out, not the ones
2563
+ // that couldn't be parsed (#3000)
2564
+ var parsed = dates.filter(function (d) { return d instanceof Date; });
2565
+ self.selectedDates = self.config.allowInvalidPreload
2566
+ ? parsed
2567
+ : filterEnabledDates(parsed, false);
2318
2568
  if (self.config.mode === "range")
2319
2569
  self.selectedDates.sort(function (a, b) { return a.getTime() - b.getTime(); });
2320
2570
  }
@@ -2373,13 +2623,7 @@
2373
2623
  self._initialDate =
2374
2624
  self.selectedDates.length > 0
2375
2625
  ? self.selectedDates[0]
2376
- : self.config.minDate &&
2377
- self.config.minDate.getTime() > self.now.getTime()
2378
- ? self.config.minDate
2379
- : self.config.maxDate &&
2380
- self.config.maxDate.getTime() < self.now.getTime()
2381
- ? self.config.maxDate
2382
- : self.now;
2626
+ : withinLimits(self.now);
2383
2627
  self.currentYear = self._initialDate.getFullYear();
2384
2628
  self.currentMonth = self._initialDate.getMonth();
2385
2629
  if (self.selectedDates.length > 0)
@@ -2431,24 +2675,27 @@
2431
2675
  function updatePositionElement() {
2432
2676
  self._positionElement = self.config.positionElement || self._input;
2433
2677
  }
2434
- function setupMobile() {
2678
+ function setMobileInputType() {
2435
2679
  var inputType = self.config.enableTime
2436
2680
  ? self.config.noCalendar
2437
2681
  ? "time"
2438
2682
  : "datetime-local"
2439
2683
  : "date";
2440
- self.mobileInput = createElement("input", self.input.className + " flatpickr-mobile");
2441
- self.mobileInput.tabIndex = 1;
2442
2684
  self.mobileInput.type = inputType;
2443
- self.mobileInput.disabled = self.input.disabled;
2444
- self.mobileInput.required = self.input.required;
2445
- self.mobileInput.placeholder = self.input.placeholder;
2446
2685
  self.mobileFormatStr =
2447
2686
  inputType === "datetime-local"
2448
2687
  ? "Y-m-d\\TH:i:S"
2449
2688
  : inputType === "date"
2450
2689
  ? "Y-m-d"
2451
2690
  : "H:i:S";
2691
+ }
2692
+ function setupMobile() {
2693
+ self.mobileInput = createElement("input", self.input.className + " flatpickr-mobile");
2694
+ self.mobileInput.tabIndex = 1;
2695
+ setMobileInputType();
2696
+ self.mobileInput.disabled = self.input.disabled;
2697
+ self.mobileInput.required = self.input.required;
2698
+ self.mobileInput.placeholder = self.input.placeholder;
2452
2699
  if (self.selectedDates.length > 0) {
2453
2700
  self.mobileInput.defaultValue = self.mobileInput.value = self.formatDate(self.selectedDates[0], self.mobileFormatStr);
2454
2701
  }
@@ -2499,9 +2746,7 @@
2499
2746
  }
2500
2747
  function isDateSelected(date) {
2501
2748
  for (var i = 0; i < self.selectedDates.length; i++) {
2502
- var selectedDate = self.selectedDates[i];
2503
- if (selectedDate instanceof Date &&
2504
- compareDates(selectedDate, date) === 0)
2749
+ if (compareDates(self.selectedDates[i], date) === 0)
2505
2750
  return "" + i;
2506
2751
  }
2507
2752
  return false;
@@ -2559,17 +2804,29 @@
2559
2804
  function updateValue(triggerChange) {
2560
2805
  if (triggerChange === void 0) { triggerChange = true; }
2561
2806
  if (self.mobileInput !== undefined && self.mobileFormatStr) {
2562
- self.mobileInput.value =
2563
- self.latestSelectedDateObj !== undefined
2564
- ? self.formatDate(self.latestSelectedDateObj, self.mobileFormatStr)
2565
- : "";
2566
- }
2807
+ var mobileValue = self.latestSelectedDateObj !== undefined
2808
+ ? self.formatDate(self.latestSelectedDateObj, self.mobileFormatStr)
2809
+ : "";
2810
+ var currentDate = self.parseDate(self.mobileInput.value, self.mobileFormatStr);
2811
+ // Browsers leave out zero seconds ("15:05", not "15:05:00"). Writing an
2812
+ // equivalent value back resets the field the user is typing in (#3144)
2813
+ if (currentDate === undefined ||
2814
+ self.formatDate(currentDate, self.mobileFormatStr) !== mobileValue)
2815
+ self.mobileInput.value = mobileValue;
2816
+ }
2817
+ self._showValue();
2818
+ if (triggerChange !== false)
2819
+ triggerEvent("onValueUpdate");
2820
+ }
2821
+ /**
2822
+ * Writes the selected dates into the input and altInput. A plugin that lays
2823
+ * the value out across inputs of its own (rangePlugin) writes those too
2824
+ */
2825
+ function showValue() {
2567
2826
  self.input.value = getDateStr(self.config.dateFormat);
2568
2827
  if (self.altInput !== undefined) {
2569
2828
  self.altInput.value = getDateStr(self.config.altFormat);
2570
2829
  }
2571
- if (triggerChange !== false)
2572
- triggerEvent("onValueUpdate");
2573
2830
  }
2574
2831
  function onMonthNavClick(e) {
2575
2832
  var eventTarget = getEventTarget(e);