@websy/websy-designs 1.2.11 → 1.2.13

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.
@@ -450,7 +450,10 @@ class WebsyDatePicker {
450
450
  this.close()
451
451
  }
452
452
  else if (event.target.classList.contains('clear-selection')) {
453
- this.selectRange(0)
453
+ this.selectRange(0, false)
454
+ if (this.options.onClear) {
455
+ this.options.onClear()
456
+ }
454
457
  this.updateRange(0)
455
458
  }
456
459
  }
@@ -535,17 +538,7 @@ class WebsyDatePicker {
535
538
  console.log('diff', diff)
536
539
  }
537
540
  else if (this.options.mode === 'hour') {
538
- let diffStart
539
- let diffEnd
540
- this.options.hours.forEach((h, i) => {
541
- if (h.text === this.selectedRangeDates[0]) {
542
- diffStart = i
543
- }
544
- if (h.text === this.selectedRangeDates[this.selectedRangeDates.length - 1]) {
545
- diffEnd = i
546
- }
547
- })
548
- diff = diffEnd - diffStart
541
+ diff = this.selectedRangeDates[this.selectedRangeDates.length - 1] - this.selectedRangeDates[0]
549
542
  }
550
543
  for (let i = 0; i < diff + 1; i++) {
551
544
  let d
@@ -568,7 +561,7 @@ class WebsyDatePicker {
568
561
  rangeEnd = this.selectedRangeDates[this.selectedRangeDates.length - 1].getTime()
569
562
  }
570
563
  else if (this.options.mode === 'hour') {
571
- d = this.options.hours[i]
564
+ d = this.selectedRangeDates[0] + i
572
565
  rangeStart = this.selectedRangeDates[0]
573
566
  rangeEnd = this.selectedRangeDates[this.selectedRangeDates.length - 1]
574
567
  }
@@ -579,7 +572,10 @@ class WebsyDatePicker {
579
572
  else if (this.options.mode === 'year') {
580
573
  dateEl = document.getElementById(`${this.elementId}_${d}_year`)
581
574
  }
582
- else if (this.options.mode === 'monthyear') {
575
+ else if (this.options.mode === 'monthyear') {
576
+ console.log('d', d)
577
+ console.log(this.selectedRangeDates)
578
+ console.log(rangeStart, rangeEnd)
583
579
  dateEl = document.getElementById(`${this.elementId}_${d}_monthyear`)
584
580
  }
585
581
  else if (this.options.mode === 'hour') {
@@ -942,7 +938,7 @@ class WebsyDatePicker {
942
938
  this.selectedRange = -1
943
939
  this.highlightRange()
944
940
  }
945
- selectRange (index) {
941
+ selectRange (index, confirm = true) {
946
942
  if (this.options.ranges[this.options.mode][index]) {
947
943
  this.selectedRangeDates = [...this.options.ranges[this.options.mode][index].range]
948
944
  this.currentselection = [...this.options.ranges[this.options.mode][index].range]
@@ -957,7 +953,7 @@ class WebsyDatePicker {
957
953
  }
958
954
  }
959
955
  this.highlightRange()
960
- this.close(true)
956
+ this.close(confirm)
961
957
  }
962
958
  }
963
959
  selectCustomRange (range) {
@@ -493,7 +493,12 @@ var WebsyDatePicker = /*#__PURE__*/function () {
493
493
  } else if (event.target.classList.contains('websy-dp-cancel')) {
494
494
  this.close();
495
495
  } else if (event.target.classList.contains('clear-selection')) {
496
- this.selectRange(0);
496
+ this.selectRange(0, false);
497
+
498
+ if (this.options.onClear) {
499
+ this.options.onClear();
500
+ }
501
+
497
502
  this.updateRange(0);
498
503
  }
499
504
  }
@@ -595,18 +600,7 @@ var WebsyDatePicker = /*#__PURE__*/function () {
595
600
  console.log('year diff', yearDiff);
596
601
  console.log('diff', diff);
597
602
  } else if (this.options.mode === 'hour') {
598
- var diffStart;
599
- var diffEnd;
600
- this.options.hours.forEach(function (h, i) {
601
- if (h.text === _this3.selectedRangeDates[0]) {
602
- diffStart = i;
603
- }
604
-
605
- if (h.text === _this3.selectedRangeDates[_this3.selectedRangeDates.length - 1]) {
606
- diffEnd = i;
607
- }
608
- });
609
- diff = diffEnd - diffStart;
603
+ diff = this.selectedRangeDates[this.selectedRangeDates.length - 1] - this.selectedRangeDates[0];
610
604
  }
611
605
 
612
606
  for (var _i = 0; _i < diff + 1; _i++) {
@@ -628,7 +622,7 @@ var WebsyDatePicker = /*#__PURE__*/function () {
628
622
  rangeStart = this.selectedRangeDates[0].getTime();
629
623
  rangeEnd = this.selectedRangeDates[this.selectedRangeDates.length - 1].getTime();
630
624
  } else if (this.options.mode === 'hour') {
631
- d = this.options.hours[_i];
625
+ d = this.selectedRangeDates[0] + _i;
632
626
  rangeStart = this.selectedRangeDates[0];
633
627
  rangeEnd = this.selectedRangeDates[this.selectedRangeDates.length - 1];
634
628
  }
@@ -640,6 +634,9 @@ var WebsyDatePicker = /*#__PURE__*/function () {
640
634
  } else if (this.options.mode === 'year') {
641
635
  dateEl = document.getElementById("".concat(this.elementId, "_").concat(d, "_year"));
642
636
  } else if (this.options.mode === 'monthyear') {
637
+ console.log('d', d);
638
+ console.log(this.selectedRangeDates);
639
+ console.log(rangeStart, rangeEnd);
643
640
  dateEl = document.getElementById("".concat(this.elementId, "_").concat(d, "_monthyear"));
644
641
  } else if (this.options.mode === 'hour') {
645
642
  dateEl = document.getElementById("".concat(this.elementId, "_").concat(d, "_hour"));
@@ -1043,6 +1040,8 @@ var WebsyDatePicker = /*#__PURE__*/function () {
1043
1040
  }, {
1044
1041
  key: "selectRange",
1045
1042
  value: function selectRange(index) {
1043
+ var confirm = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
1044
+
1046
1045
  if (this.options.ranges[this.options.mode][index]) {
1047
1046
  this.selectedRangeDates = _toConsumableArray(this.options.ranges[this.options.mode][index].range);
1048
1047
  this.currentselection = _toConsumableArray(this.options.ranges[this.options.mode][index].range);
@@ -1058,7 +1057,7 @@ var WebsyDatePicker = /*#__PURE__*/function () {
1058
1057
  }
1059
1058
 
1060
1059
  this.highlightRange();
1061
- this.close(true);
1060
+ this.close(confirm);
1062
1061
  }
1063
1062
  }
1064
1063
  }, {