@wernfried/daterangepicker 4.17.4 → 4.18.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.
- package/API_Doc.md +52 -28
- package/README.md +5 -5
- package/dist/esm/daterangepicker.js +223 -71
- package/dist/esm/daterangepicker.min.js +2 -2
- package/dist/global/daterangepicker.js +223 -71
- package/dist/global/daterangepicker.min.js +2 -2
- package/package.json +1 -1
|
@@ -362,7 +362,7 @@ class DateRangePicker {
|
|
|
362
362
|
console.error(`Value of startDate "${this.#startDate}" violates ${vio.find((x) => x.reason.startsWith("isInvalid")).reason}`);
|
|
363
363
|
} else {
|
|
364
364
|
const newDate = vio.filter((x) => x.new != null).at(-1).new;
|
|
365
|
-
if (process
|
|
365
|
+
if (typeof process !== "undefined" && process.env.JEST_WORKER_ID == null)
|
|
366
366
|
console.warn(`Correcting startDate from ${this.#startDate} to ${newDate}`);
|
|
367
367
|
this.#startDate = newDate;
|
|
368
368
|
}
|
|
@@ -374,7 +374,7 @@ class DateRangePicker {
|
|
|
374
374
|
console.error(`Value of endDate "${this.#endDate}" violates ${vio.find((x) => x.reason.startsWith("isInvalid")).reason}`);
|
|
375
375
|
} else {
|
|
376
376
|
const newDate = vio.filter((x) => x.new != null).at(-1).new;
|
|
377
|
-
if (process
|
|
377
|
+
if (typeof process !== "undefined" && process.env.JEST_WORKER_ID == null)
|
|
378
378
|
console.warn(`Correcting endDate from ${this.#endDate} to ${newDate}`);
|
|
379
379
|
this.#endDate = newDate;
|
|
380
380
|
}
|
|
@@ -532,6 +532,152 @@ class DateRangePicker {
|
|
|
532
532
|
set endDate(val) {
|
|
533
533
|
this.#endDate = val;
|
|
534
534
|
}
|
|
535
|
+
/**
|
|
536
|
+
* DateRangePicker specific events
|
|
537
|
+
*/
|
|
538
|
+
#events = {
|
|
539
|
+
/**
|
|
540
|
+
* Emitted when the date is changed through `<input>` element or via {@link #DateRangePicker+setStartDate|setStartDate} or
|
|
541
|
+
* {@link #DateRangePicker+setRange|setRange} and date is not valid due to
|
|
542
|
+
* `minDate`, `maxDate`, `minSpan`, `maxSpan`, `invalidDate` and `invalidTime` constraints.<br>
|
|
543
|
+
* Event is only triggered when date string is valid and date value is changing<br>
|
|
544
|
+
* @event
|
|
545
|
+
* @name "violated.daterangepicker"
|
|
546
|
+
* @param {DateRangePicker} picker - The daterangepicker object
|
|
547
|
+
* @param {InputViolation} result - The violation object, see example of `validateInput()`
|
|
548
|
+
* @param {Object} newDate - Object of {startDate, endDate}
|
|
549
|
+
* @return {boolean}=undefined - If handler returns `true`, then values from `newDate` object are used
|
|
550
|
+
* @example
|
|
551
|
+
*
|
|
552
|
+
* $('#picker').daterangepicker({
|
|
553
|
+
* startDate: DateTime.now(),
|
|
554
|
+
* // allow only dates from current year
|
|
555
|
+
* minDate: DateTime.now().startOf('year'),
|
|
556
|
+
* manDate: DateTime.now().endOf('year'),
|
|
557
|
+
* singleDatePicker: true,
|
|
558
|
+
* locale: {
|
|
559
|
+
* format: DateTime.DATETIME_SHORT
|
|
560
|
+
* }
|
|
561
|
+
* }).on('violated.daterangepicker', (ev, picker, result, newDate) => {
|
|
562
|
+
* newDate.startDate = DateTime.now().minus({ days: 3 }).startOf('day');
|
|
563
|
+
* return true;
|
|
564
|
+
* });
|
|
565
|
+
*
|
|
566
|
+
* // Try to set date outside permitted range at <input> elemet
|
|
567
|
+
* $('#picker').val(DateTime.now().minus({ years: 10 })).toLocaleString(DateTime.DATETIME_SHORT).trigger('keyup');
|
|
568
|
+
|
|
569
|
+
* // Try to set date outside permitted range by code
|
|
570
|
+
* const drp = $('#picker').data('daterangepicker').setStartDate(DateTime.now().minus({ years: 10 })
|
|
571
|
+
*
|
|
572
|
+
* // -> Calendar selects and shows "today - 3 days"
|
|
573
|
+
*/
|
|
574
|
+
onViolated: { type: "violated.daterangepicker", param: (...args) => [this, ...args] },
|
|
575
|
+
/**
|
|
576
|
+
* Emitted before the calendar time picker is rendered.
|
|
577
|
+
* @event
|
|
578
|
+
* @name "beforeRenderCalendar.daterangepicker"
|
|
579
|
+
* @param {DateRangePicker} this - The daterangepicker object
|
|
580
|
+
*/
|
|
581
|
+
onBeforeRenderTimePicker: { type: "beforeRenderTimePicker.daterangepicker", param: this },
|
|
582
|
+
/**
|
|
583
|
+
* Emitted before the calendar is rendered. Useful to remove any manually added elements.
|
|
584
|
+
* @event
|
|
585
|
+
* @name "beforeRenderCalendar.daterangepicker"
|
|
586
|
+
* @param {DateRangePicker} this - The daterangepicker object
|
|
587
|
+
*/
|
|
588
|
+
onBeforeRenderCalendar: { type: "beforeRenderCalendar.daterangepicker", param: this },
|
|
589
|
+
/**
|
|
590
|
+
* Emitted when the picker is shown
|
|
591
|
+
* @event
|
|
592
|
+
* @name "show.daterangepicker"
|
|
593
|
+
* @param {DateRangePicker} this - The daterangepicker object
|
|
594
|
+
*/
|
|
595
|
+
onShow: { type: "show.daterangepicker", param: this },
|
|
596
|
+
/**
|
|
597
|
+
* Emitted before the picker will hide. When EventHandler returns `true`, then picker remains visible
|
|
598
|
+
* @event
|
|
599
|
+
* @name "beforeHide.daterangepicker"
|
|
600
|
+
* @param {DateRangePicker} this - The daterangepicker object
|
|
601
|
+
* @return {boolean} cancel - If `true`, then the picker remains visible
|
|
602
|
+
*/
|
|
603
|
+
onBeforeHide: { type: "beforeHide.daterangepicker", param: this },
|
|
604
|
+
/**
|
|
605
|
+
* Emitted when the picker is hidden
|
|
606
|
+
* @event
|
|
607
|
+
* @name "hide.daterangepicker"
|
|
608
|
+
* @param {DateRangePicker} this - The daterangepicker object
|
|
609
|
+
*/
|
|
610
|
+
onHide: { type: "hide.daterangepicker", param: this },
|
|
611
|
+
/**
|
|
612
|
+
* Emitted when the calendar(s) are shown.
|
|
613
|
+
* Only useful when {@link #Ranges|Ranges} are used.
|
|
614
|
+
* @event
|
|
615
|
+
* @name "showCalendar.daterangepicker"
|
|
616
|
+
* @param {DateRangePicker} this - The daterangepicker object
|
|
617
|
+
*/
|
|
618
|
+
onShowCalendar: { type: "showCalendar.daterangepicker", param: this },
|
|
619
|
+
/**
|
|
620
|
+
* Emitted when the calendar(s) are hidden. Only used when {@link #Ranges|Ranges} are used.
|
|
621
|
+
* @event
|
|
622
|
+
* @name "hideCalendar.daterangepicker"
|
|
623
|
+
* @param {DateRangePicker} this - The daterangepicker object
|
|
624
|
+
*/
|
|
625
|
+
onHideCalendar: { type: "hideCalendar.daterangepicker", param: this },
|
|
626
|
+
/**
|
|
627
|
+
* Emitted when user clicks outside the picker. Use option `onOutsideClick` to define the default action, then you may not need to handle this event.
|
|
628
|
+
* @event
|
|
629
|
+
* @name "outsideClick.daterangepicker"
|
|
630
|
+
* @param {DateRangePicker} this - The daterangepicker object
|
|
631
|
+
*/
|
|
632
|
+
onOutsideClick: { type: "outsideClick.daterangepicker", param: this },
|
|
633
|
+
/**
|
|
634
|
+
* Emitted when the date changed. Does not trigger when time is changed, use {@link #event_timeChange.daterangepicker|"timeChange.daterangepicker"} to handle it
|
|
635
|
+
* @event
|
|
636
|
+
* @name "dateChange.daterangepicker"
|
|
637
|
+
* @param {DateRangePicker} this - The daterangepicker object
|
|
638
|
+
* @param {string} side - Either `'start'` or `'end'` indicating whether startDate or endDate was changed. `null` when `singleDatePicker: true`
|
|
639
|
+
*/
|
|
640
|
+
onDateChange: { type: "dateChange.daterangepicker", param: (side) => [this, side] },
|
|
641
|
+
/**
|
|
642
|
+
* Emitted when the time changed. Does not trigger when date is changed
|
|
643
|
+
* @event
|
|
644
|
+
* @name "timeChange.daterangepicker"
|
|
645
|
+
* @param {DateRangePicker} this - The daterangepicker object
|
|
646
|
+
* @param {string} side - Either `'start'` or `'end'` indicating whether startDate or endDate was changed
|
|
647
|
+
*/
|
|
648
|
+
onTimeChange: { type: "timeChange.daterangepicker", param: (side) => [this, side] },
|
|
649
|
+
/**
|
|
650
|
+
* Emitted when the `Apply` button is clicked, or when a predefined {@link #Ranges|Ranges} is clicked
|
|
651
|
+
* @event
|
|
652
|
+
* @name "apply.daterangepicker"
|
|
653
|
+
* @param {DateRangePicker} this - The daterangepicker object
|
|
654
|
+
*/
|
|
655
|
+
onApply: { type: "apply.daterangepicker", param: this },
|
|
656
|
+
/**
|
|
657
|
+
* Emitted when the `Cancel` button is clicked
|
|
658
|
+
* @event
|
|
659
|
+
* @name "cancel.daterangepicker"
|
|
660
|
+
* @param {DateRangePicker} this - The daterangepicker object
|
|
661
|
+
*/
|
|
662
|
+
onCancel: { type: "cancel.daterangepicker", param: this },
|
|
663
|
+
/**
|
|
664
|
+
* Emitted when the date is changed through `<input>` element. Event is only triggered when date string is valid and date value has changed
|
|
665
|
+
* @event
|
|
666
|
+
* @name "inputChanged.daterangepicker"
|
|
667
|
+
* @param {DateRangePicker} this - The daterangepicker object
|
|
668
|
+
*/
|
|
669
|
+
onInputChanged: { type: "inputChanged.daterangepicker", param: this },
|
|
670
|
+
/**
|
|
671
|
+
* Emitted after month view changed, for example by click on 'prev' or 'next'
|
|
672
|
+
* @event
|
|
673
|
+
* @name "monthViewChanged.daterangepicker"
|
|
674
|
+
* @param {DateRangePicker} this - The daterangepicker object
|
|
675
|
+
*/
|
|
676
|
+
onMonthViewChanged: { type: "monthViewChanged.daterangepicker", param: this }
|
|
677
|
+
};
|
|
678
|
+
get events() {
|
|
679
|
+
return this.#events;
|
|
680
|
+
}
|
|
535
681
|
/* #region Set startDate/endDate */
|
|
536
682
|
/**
|
|
537
683
|
* Sets the date range picker's currently selected start date to the provided date.<br>
|
|
@@ -559,6 +705,7 @@ class DateRangePicker {
|
|
|
559
705
|
return violations;
|
|
560
706
|
}
|
|
561
707
|
}
|
|
708
|
+
const monthChanged = !this.#startDate.hasSame(newDate, "month");
|
|
562
709
|
this.#startDate = newDate;
|
|
563
710
|
this.#endDate = this.#startDate;
|
|
564
711
|
if (!this.timePicker) {
|
|
@@ -567,7 +714,7 @@ class DateRangePicker {
|
|
|
567
714
|
}
|
|
568
715
|
this.updateElement();
|
|
569
716
|
if (updateView)
|
|
570
|
-
this.updateView();
|
|
717
|
+
this.updateView(monthChanged);
|
|
571
718
|
return violations;
|
|
572
719
|
}
|
|
573
720
|
/**
|
|
@@ -614,6 +761,7 @@ class DateRangePicker {
|
|
|
614
761
|
return violations;
|
|
615
762
|
}
|
|
616
763
|
}
|
|
764
|
+
const monthChanged = !this.#startDate.hasSame(newDate[0], "month") || !this.#endDate.hasSame(newDate[1], "month");
|
|
617
765
|
this.#startDate = newDate[0];
|
|
618
766
|
this.#endDate = newDate[1];
|
|
619
767
|
if (!this.timePicker) {
|
|
@@ -622,7 +770,7 @@ class DateRangePicker {
|
|
|
622
770
|
}
|
|
623
771
|
this.updateElement();
|
|
624
772
|
if (updateView)
|
|
625
|
-
this.updateView();
|
|
773
|
+
this.updateView(monthChanged);
|
|
626
774
|
return violations;
|
|
627
775
|
}
|
|
628
776
|
/**
|
|
@@ -708,42 +856,6 @@ class DateRangePicker {
|
|
|
708
856
|
}
|
|
709
857
|
}
|
|
710
858
|
/**
|
|
711
|
-
* Emitted when the date is changed through `<input>` element or via {@link #DateRangePicker+setStartDate|setStartDate} or
|
|
712
|
-
* {@link #DateRangePicker+setRange|setRange} and date is not valid due to
|
|
713
|
-
* `minDate`, `maxDate`, `minSpan`, `maxSpan`, `invalidDate` and `invalidTime` constraints.<br>
|
|
714
|
-
* Event is only triggered when date string is valid and date value is changing<br>
|
|
715
|
-
* @event
|
|
716
|
-
* @name "violated.daterangepicker"
|
|
717
|
-
* @param {Object} this - The event object
|
|
718
|
-
* @param {DateRangePicker} picker - The daterangepicker object
|
|
719
|
-
* @param {InputViolation} result - The violation object, see example of `validateInput()`
|
|
720
|
-
* @param {Object} newDate - Object of {startDate, endDate}
|
|
721
|
-
* @return {boolean}=undefined - If handler returns `true`, then values from `newDate` object are used
|
|
722
|
-
* @example
|
|
723
|
-
*
|
|
724
|
-
* $('#picker').daterangepicker({
|
|
725
|
-
* startDate: DateTime.now(),
|
|
726
|
-
* // allow only dates from current year
|
|
727
|
-
* minDate: DateTime.now().startOf('year'),
|
|
728
|
-
* manDate: DateTime.now().endOf('year'),
|
|
729
|
-
* singleDatePicker: true,
|
|
730
|
-
* locale: {
|
|
731
|
-
* format: DateTime.DATETIME_SHORT
|
|
732
|
-
* }
|
|
733
|
-
* }).on('violated.daterangepicker', (ev, picker, result, newDate) => {
|
|
734
|
-
* newDate.startDate = DateTime.now().minus({ days: 3 }).startOf('day');
|
|
735
|
-
* return true;
|
|
736
|
-
* });
|
|
737
|
-
*
|
|
738
|
-
* // Try to set date outside permitted range at <input> elemet
|
|
739
|
-
* $('#picker').val(DateTime.now().minus({ years: 10 })).toLocaleString(DateTime.DATETIME_SHORT).trigger('keyup');
|
|
740
|
-
|
|
741
|
-
* // Try to set date outside permitted range by code
|
|
742
|
-
* const drp = $('#picker').data('daterangepicker').setStartDate(DateTime.now().minus({ years: 10 })
|
|
743
|
-
*
|
|
744
|
-
* // -> Calendar selects and shows "today - 3 days"
|
|
745
|
-
*/
|
|
746
|
-
/**
|
|
747
859
|
* @typedef InputViolation
|
|
748
860
|
* @type {Object}
|
|
749
861
|
* @property {external:DateTime} startDate - Violation of startDate
|
|
@@ -843,7 +955,7 @@ class DateRangePicker {
|
|
|
843
955
|
return null;
|
|
844
956
|
if (dipatch) {
|
|
845
957
|
let newValues = { startDate };
|
|
846
|
-
const ret = this.
|
|
958
|
+
const ret = this.triggerHandler(this.#events.onViolated, result, newValues);
|
|
847
959
|
if (ret) {
|
|
848
960
|
result.newDate = newValues;
|
|
849
961
|
return result;
|
|
@@ -919,7 +1031,7 @@ class DateRangePicker {
|
|
|
919
1031
|
return null;
|
|
920
1032
|
if (dipatch) {
|
|
921
1033
|
let newValues = { startDate, endDate };
|
|
922
|
-
const ret = this.
|
|
1034
|
+
const ret = this.triggerHandler(this.#events.onViolated, result, newValues);
|
|
923
1035
|
if (ret) {
|
|
924
1036
|
result.newDate = newValues;
|
|
925
1037
|
return result;
|
|
@@ -933,11 +1045,12 @@ class DateRangePicker {
|
|
|
933
1045
|
/**
|
|
934
1046
|
* Updates the picker when calendar is initiated or any date has been selected.
|
|
935
1047
|
* Could be useful after running {@link #DateRangePicker+setStartDate|setStartDate} or {@link #DateRangePicker+setEndDate|setRange}
|
|
1048
|
+
* @param {boolean} monthChanged - If `true` then monthView changed
|
|
936
1049
|
* @emits "beforeRenderTimePicker.daterangepicker"
|
|
937
1050
|
*/
|
|
938
|
-
updateView() {
|
|
1051
|
+
updateView(monthChanged) {
|
|
939
1052
|
if (this.timePicker) {
|
|
940
|
-
this.
|
|
1053
|
+
this.triggerEvent(this.#events.onBeforeRenderTimePicker);
|
|
941
1054
|
this.renderTimePicker("start");
|
|
942
1055
|
this.renderTimePicker("end");
|
|
943
1056
|
if (!this.#endDate) {
|
|
@@ -948,7 +1061,7 @@ class DateRangePicker {
|
|
|
948
1061
|
}
|
|
949
1062
|
this.updateLabel();
|
|
950
1063
|
this.updateMonthsInView();
|
|
951
|
-
this.updateCalendars();
|
|
1064
|
+
this.updateCalendars(monthChanged);
|
|
952
1065
|
this.setApplyBtnState();
|
|
953
1066
|
}
|
|
954
1067
|
/**
|
|
@@ -987,9 +1100,11 @@ class DateRangePicker {
|
|
|
987
1100
|
/**
|
|
988
1101
|
* Updates the selected day value from calendar with selected time values
|
|
989
1102
|
* @emits "beforeRenderCalendar.daterangepicker"
|
|
1103
|
+
* @emits "monthViewChanged.daterangepicker"
|
|
1104
|
+
* @param {boolean} monthChanged - If `true` then monthView changed
|
|
990
1105
|
* @private
|
|
991
1106
|
*/
|
|
992
|
-
updateCalendars() {
|
|
1107
|
+
updateCalendars(monthChanged) {
|
|
993
1108
|
if (this.timePicker) {
|
|
994
1109
|
var hour, minute, second;
|
|
995
1110
|
if (this.#endDate) {
|
|
@@ -1033,9 +1148,11 @@ class DateRangePicker {
|
|
|
1033
1148
|
if (!this.singleMonthView)
|
|
1034
1149
|
this.rightCalendar.month = this.rightCalendar.month.set({ hour: 0, minute: 0, second: 0 });
|
|
1035
1150
|
}
|
|
1036
|
-
this.
|
|
1151
|
+
this.triggerEvent(this.#events.onBeforeRenderCalendar);
|
|
1037
1152
|
this.renderCalendar("left");
|
|
1038
1153
|
this.renderCalendar("right");
|
|
1154
|
+
if (monthChanged)
|
|
1155
|
+
this.triggerEvent(this.#events.onMonthViewChanged);
|
|
1039
1156
|
this.container.find(".ranges li").removeClass("active");
|
|
1040
1157
|
if (this.#endDate == null) return;
|
|
1041
1158
|
this.calculateChosenLabel();
|
|
@@ -1478,10 +1595,10 @@ class DateRangePicker {
|
|
|
1478
1595
|
}.bind(this));
|
|
1479
1596
|
this.oldStartDate = this.#startDate;
|
|
1480
1597
|
this.oldEndDate = this.#endDate;
|
|
1481
|
-
this.updateView();
|
|
1598
|
+
this.updateView(false);
|
|
1482
1599
|
this.container.show();
|
|
1483
1600
|
this.move();
|
|
1484
|
-
this.
|
|
1601
|
+
this.triggerEvent(this.#events.onShow);
|
|
1485
1602
|
this.isShowing = true;
|
|
1486
1603
|
}
|
|
1487
1604
|
/**
|
|
@@ -1498,12 +1615,12 @@ class DateRangePicker {
|
|
|
1498
1615
|
if (!this.#startDate.equals(this.oldStartDate) || !this.#endDate.equals(this.oldEndDate))
|
|
1499
1616
|
this.callback(this.startDate, this.endDate, this.chosenLabel);
|
|
1500
1617
|
this.updateElement();
|
|
1501
|
-
if (this.
|
|
1618
|
+
if (this.triggerHandler(this.#events.onBeforeHide))
|
|
1502
1619
|
return;
|
|
1503
1620
|
$(document).off(".daterangepicker");
|
|
1504
1621
|
$(window).off(".daterangepicker");
|
|
1505
1622
|
this.container.hide();
|
|
1506
|
-
this.
|
|
1623
|
+
this.triggerEvent(this.#events.onHide);
|
|
1507
1624
|
this.isShowing = false;
|
|
1508
1625
|
}
|
|
1509
1626
|
/**
|
|
@@ -1523,7 +1640,7 @@ class DateRangePicker {
|
|
|
1523
1640
|
showCalendars() {
|
|
1524
1641
|
this.container.addClass("show-calendar");
|
|
1525
1642
|
this.move();
|
|
1526
|
-
this.
|
|
1643
|
+
this.triggerEvent(this.#events.onShowCalendar);
|
|
1527
1644
|
}
|
|
1528
1645
|
/**
|
|
1529
1646
|
* Hides calendar when user selects a predefined range
|
|
@@ -1531,7 +1648,7 @@ class DateRangePicker {
|
|
|
1531
1648
|
*/
|
|
1532
1649
|
hideCalendars() {
|
|
1533
1650
|
this.container.removeClass("show-calendar");
|
|
1534
|
-
this.
|
|
1651
|
+
this.triggerEvent(this.#events.onHideCalendar);
|
|
1535
1652
|
}
|
|
1536
1653
|
/* #endregion */
|
|
1537
1654
|
/* #region Handle mouse related events */
|
|
@@ -1552,7 +1669,7 @@ class DateRangePicker {
|
|
|
1552
1669
|
this.#endDate = this.oldEndDate;
|
|
1553
1670
|
}
|
|
1554
1671
|
this.hide();
|
|
1555
|
-
this.
|
|
1672
|
+
this.triggerEvent(this.#events.onOutsideClick);
|
|
1556
1673
|
}
|
|
1557
1674
|
/**
|
|
1558
1675
|
* Move calendar to previous month
|
|
@@ -1568,7 +1685,7 @@ class DateRangePicker {
|
|
|
1568
1685
|
} else {
|
|
1569
1686
|
this.rightCalendar.month = this.rightCalendar.month.minus({ month: 1 });
|
|
1570
1687
|
}
|
|
1571
|
-
this.updateCalendars();
|
|
1688
|
+
this.updateCalendars(true);
|
|
1572
1689
|
}
|
|
1573
1690
|
/**
|
|
1574
1691
|
* Move calendar to next month
|
|
@@ -1584,7 +1701,7 @@ class DateRangePicker {
|
|
|
1584
1701
|
if (this.linkedCalendars)
|
|
1585
1702
|
this.leftCalendar.month = this.leftCalendar.month.plus({ month: 1 });
|
|
1586
1703
|
}
|
|
1587
|
-
this.updateCalendars();
|
|
1704
|
+
this.updateCalendars(true);
|
|
1588
1705
|
}
|
|
1589
1706
|
/**
|
|
1590
1707
|
* User hovers over date values
|
|
@@ -1689,17 +1806,18 @@ class DateRangePicker {
|
|
|
1689
1806
|
if (label == this.locale.customRangeLabel) {
|
|
1690
1807
|
this.showCalendars();
|
|
1691
1808
|
} else {
|
|
1692
|
-
var
|
|
1693
|
-
this.#startDate
|
|
1694
|
-
this.#
|
|
1809
|
+
var newDate = this.ranges[label];
|
|
1810
|
+
const monthChanged = !this.#startDate.hasSame(newDate[0], "month") || !this.#endDate.hasSame(newDate[1], "month");
|
|
1811
|
+
this.#startDate = newDate[0];
|
|
1812
|
+
this.#endDate = newDate[1];
|
|
1695
1813
|
if (!this.timePicker) {
|
|
1696
1814
|
this.#startDate.startOf("day");
|
|
1697
1815
|
this.#endDate.endOf("day");
|
|
1698
1816
|
}
|
|
1699
1817
|
if (!this.alwaysShowCalendars)
|
|
1700
1818
|
this.hideCalendars();
|
|
1701
|
-
if (this.
|
|
1702
|
-
this.updateView();
|
|
1819
|
+
if (this.triggerHandler(this.#events.onBeforeHide))
|
|
1820
|
+
this.updateView(monthChanged);
|
|
1703
1821
|
this.clickApply();
|
|
1704
1822
|
}
|
|
1705
1823
|
}
|
|
@@ -1778,11 +1896,11 @@ class DateRangePicker {
|
|
|
1778
1896
|
this.clickApply();
|
|
1779
1897
|
side = null;
|
|
1780
1898
|
}
|
|
1781
|
-
this.updateView();
|
|
1899
|
+
this.updateView(false);
|
|
1782
1900
|
e.stopPropagation();
|
|
1783
1901
|
if (this.autoUpdateInput)
|
|
1784
1902
|
this.updateElement();
|
|
1785
|
-
this.
|
|
1903
|
+
this.triggerEvent(this.#events.onDateChange, side);
|
|
1786
1904
|
}
|
|
1787
1905
|
/**
|
|
1788
1906
|
* Hightlight selected predefined range in calendar
|
|
@@ -1865,14 +1983,14 @@ class DateRangePicker {
|
|
|
1865
1983
|
} else if (this.#endDate) {
|
|
1866
1984
|
this.#endDate = this.#endDate.set({ hour, minute, second });
|
|
1867
1985
|
}
|
|
1868
|
-
this.updateCalendars();
|
|
1986
|
+
this.updateCalendars(false);
|
|
1869
1987
|
this.setApplyBtnState();
|
|
1870
|
-
this.
|
|
1988
|
+
this.triggerEvent(this.#events.onBeforeRenderTimePicker);
|
|
1871
1989
|
this.renderTimePicker("start");
|
|
1872
1990
|
this.renderTimePicker("end");
|
|
1873
1991
|
if (this.autoUpdateInput)
|
|
1874
1992
|
this.updateElement();
|
|
1875
|
-
this.
|
|
1993
|
+
this.triggerEvent(this.#events.onTimeChange, this.singleDatePicker ? null : side);
|
|
1876
1994
|
}
|
|
1877
1995
|
/**
|
|
1878
1996
|
* Calender month moved
|
|
@@ -1883,6 +2001,7 @@ class DateRangePicker {
|
|
|
1883
2001
|
var isLeft = $(e.target).closest(".drp-calendar").hasClass("left"), leftOrRight = isLeft ? "left" : "right", cal = this.container.find(".drp-calendar." + leftOrRight);
|
|
1884
2002
|
var month = parseInt(cal.find(".monthselect").val(), 10);
|
|
1885
2003
|
var year = cal.find(".yearselect").val();
|
|
2004
|
+
let monthChanged = false;
|
|
1886
2005
|
if (!isLeft) {
|
|
1887
2006
|
if (year < this.#startDate.year || year == this.#startDate.year && month < this.#startDate.month) {
|
|
1888
2007
|
month = this.#startDate.month;
|
|
@@ -1902,15 +2021,17 @@ class DateRangePicker {
|
|
|
1902
2021
|
}
|
|
1903
2022
|
}
|
|
1904
2023
|
if (isLeft) {
|
|
2024
|
+
monthChanged = !DateTime.fromObject({ year, month }).hasSame(this.leftCalendar.month, "month");
|
|
1905
2025
|
this.leftCalendar.month = this.leftCalendar.month.set({ year, month });
|
|
1906
2026
|
if (this.linkedCalendars)
|
|
1907
2027
|
this.rightCalendar.month = this.leftCalendar.month.plus({ month: 1 });
|
|
1908
2028
|
} else {
|
|
2029
|
+
monthChanged = !DateTime.fromObject({ year, month }).hasSame(this.leftCalendar.month, "month");
|
|
1909
2030
|
this.rightCalendar.month = this.rightCalendar.month.set({ year, month });
|
|
1910
2031
|
if (this.linkedCalendars)
|
|
1911
2032
|
this.leftCalendar.month = this.rightCalendar.month.minus({ month: 1 });
|
|
1912
2033
|
}
|
|
1913
|
-
this.updateCalendars();
|
|
2034
|
+
this.updateCalendars(monthChanged);
|
|
1914
2035
|
}
|
|
1915
2036
|
/**
|
|
1916
2037
|
* User clicked `Apply` button
|
|
@@ -1919,7 +2040,7 @@ class DateRangePicker {
|
|
|
1919
2040
|
*/
|
|
1920
2041
|
clickApply() {
|
|
1921
2042
|
this.hide();
|
|
1922
|
-
this.
|
|
2043
|
+
this.triggerEvent(this.#events.onApply);
|
|
1923
2044
|
}
|
|
1924
2045
|
/**
|
|
1925
2046
|
* User clicked `Cancel` button
|
|
@@ -1930,7 +2051,7 @@ class DateRangePicker {
|
|
|
1930
2051
|
this.#startDate = this.oldStartDate;
|
|
1931
2052
|
this.#endDate = this.oldEndDate;
|
|
1932
2053
|
this.hide();
|
|
1933
|
-
this.
|
|
2054
|
+
this.triggerEvent(this.#events.onCancel);
|
|
1934
2055
|
}
|
|
1935
2056
|
/* #endregion */
|
|
1936
2057
|
/**
|
|
@@ -1944,6 +2065,7 @@ class DateRangePicker {
|
|
|
1944
2065
|
if (!this.element.val().length) return;
|
|
1945
2066
|
const format = typeof this.locale.format === "string" ? this.locale.format : DateTime.parseFormatForOpts(this.locale.format);
|
|
1946
2067
|
const dateString = this.element.val().split(this.locale.separator);
|
|
2068
|
+
let monthChanged = false;
|
|
1947
2069
|
if (this.singleDatePicker) {
|
|
1948
2070
|
let newDate = DateTime.fromFormat(this.element.val(), format, { locale: DateTime.now().locale });
|
|
1949
2071
|
const oldDate = this.#startDate;
|
|
@@ -1957,6 +2079,7 @@ class DateRangePicker {
|
|
|
1957
2079
|
return;
|
|
1958
2080
|
}
|
|
1959
2081
|
}
|
|
2082
|
+
monthChanged = !this.#startDate.hasSame(newDate, "month");
|
|
1960
2083
|
this.#startDate = newDate;
|
|
1961
2084
|
this.#endDate = this.#startDate;
|
|
1962
2085
|
if (!this.timePicker) {
|
|
@@ -1977,6 +2100,7 @@ class DateRangePicker {
|
|
|
1977
2100
|
return;
|
|
1978
2101
|
}
|
|
1979
2102
|
}
|
|
2103
|
+
monthChanged = !this.#startDate.hasSame(newDate[0], "month") || !this.#endDate.hasSame(newDate[1], "month");
|
|
1980
2104
|
this.#startDate = newDate[0];
|
|
1981
2105
|
this.#endDate = newDate[1];
|
|
1982
2106
|
if (!this.timePicker) {
|
|
@@ -1986,9 +2110,9 @@ class DateRangePicker {
|
|
|
1986
2110
|
} else {
|
|
1987
2111
|
return;
|
|
1988
2112
|
}
|
|
1989
|
-
this.updateView();
|
|
2113
|
+
this.updateView(monthChanged);
|
|
1990
2114
|
this.updateElement();
|
|
1991
|
-
this.
|
|
2115
|
+
this.triggerEvent(this.#events.onInputChanged);
|
|
1992
2116
|
}
|
|
1993
2117
|
/**
|
|
1994
2118
|
* Handles key press, IE 11 compatibility
|
|
@@ -2068,6 +2192,34 @@ class DateRangePicker {
|
|
|
2068
2192
|
this.element.off(".daterangepicker");
|
|
2069
2193
|
this.element.removeData();
|
|
2070
2194
|
}
|
|
2195
|
+
/**
|
|
2196
|
+
* Helper function to trigger events
|
|
2197
|
+
* @param {Event} ev - From this.#events
|
|
2198
|
+
* @param {...any} args - Argument spread
|
|
2199
|
+
* @private
|
|
2200
|
+
*/
|
|
2201
|
+
triggerEvent(ev, ...args) {
|
|
2202
|
+
if (args.length === 0) {
|
|
2203
|
+
this.element.trigger(ev.type, ev.param);
|
|
2204
|
+
} else {
|
|
2205
|
+
const params = ev.param(...args);
|
|
2206
|
+
this.element.trigger(ev.type, params);
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
/**
|
|
2210
|
+
* Helper function to trigger events
|
|
2211
|
+
* @param {Event} ev - From this.#events
|
|
2212
|
+
* @param {...any} args - Argument spread
|
|
2213
|
+
* @private
|
|
2214
|
+
*/
|
|
2215
|
+
triggerHandler(ev, ...args) {
|
|
2216
|
+
if (args.length === 0) {
|
|
2217
|
+
return this.element.triggerHandler(ev.type, ev.param);
|
|
2218
|
+
} else {
|
|
2219
|
+
const params = ev.param(...args);
|
|
2220
|
+
return this.element.triggerHandler(ev.type, params);
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2071
2223
|
}
|
|
2072
2224
|
if (!$.fn.daterangepicker) {
|
|
2073
2225
|
$.fn.daterangepicker = function(options, callback) {
|