adt-js-components 1.0.5 → 1.0.8

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adt-js-components",
3
- "version": "1.0.5",
3
+ "version": "1.0.8",
4
4
  "description": "JavaScript components for Nette framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,29 +9,40 @@ const locale = document.querySelector('html').getAttribute('lang');
9
9
  function initTime(input, options) {
10
10
  $(input).timepicker({
11
11
  scrollDefault: 'now',
12
- timeFormat: options.format
12
+ timeFormat: options.format,
13
+ minTime: options.minTime,
14
+ maxTime: options.maxTime
13
15
  });
14
16
  }
15
17
 
16
- function initDate(input, options) {
18
+ async function initDate(input, options) {
19
+ if (locale === 'en') {
20
+ options.locale = null;
21
+ } else if (locale === 'el') {
22
+ options.locale = 'gr';
23
+ } else {
24
+ options.locale = locale;
25
+ }
26
+
17
27
  flatpickr(input, {
18
28
  dateFormat: options.format, // default datetime-local
19
29
  enableTime: options.type === 'datetime' || options.type === 'datetime-local',
20
30
  time_24hr: true,
21
- locale: require(`flatpickr/dist/l10n/${locale}.js`).default[locale],
22
- defaultDate: options.value,
23
- minDate: options.minDate
31
+ locale: options.locale ? require('flatpickr/dist/l10n/' + options.locale + '.js').default[options.locale] : null,
32
+ defaultDate: options.value ? new Date(options.value) : null,
33
+ minDate: options.minDate ? new Date(options.minDate) : null,
34
+ maxDate: options.maxDate ? new Date(options.maxDate) : null
24
35
  });
25
36
  }
26
37
 
27
38
  function run(options) {
28
39
  $.nette.ext('live').after(function($el) {
29
40
  $el.find('[data-adt-date-input]').each(function() {
30
- var options = $(this).data('adt-date-input');
41
+ const data = $(this).data('adt-date-input');
42
+
43
+ const options = $(this).data('adt-date-input');
31
44
  options.type = $(this).attr('type');
32
- options.value = $(this).attr('value');
33
- options.minDate = $(this).data('min-date') !== undefined ? $(this).data('min-date') : null;
34
-
45
+
35
46
  $(this).attr('type', 'text');
36
47
  if (options.type === 'time') {
37
48
  initTime(this, options);