|
1 | 1 | /**
|
2 |
| -* @version: 3.0.3 |
| 2 | +* @version: 3.0.5 |
3 | 3 | * @author: Dan Grossman http://www.dangrossman.info/
|
4 |
| -* @copyright: Copyright (c) 2012-2018 Dan Grossman. All rights reserved. |
| 4 | +* @copyright: Copyright (c) 2012-2019 Dan Grossman. All rights reserved. |
5 | 5 | * @license: Licensed under the MIT license. See http://www.opensource.org/licenses/mit-license.php
|
6 | 6 | * @website: http://www.daterangepicker.com/
|
7 | 7 | */
|
|
11 | 11 | // AMD. Make globaly available as well
|
12 | 12 | define(['moment', 'jquery'], function (moment, jquery) {
|
13 | 13 | if (!jquery.fn) jquery.fn = {}; // webpack server rendering
|
| 14 | + if (typeof moment !== 'function' && moment.default) moment = moment.default |
14 | 15 | return factory(moment, jquery);
|
15 | 16 | });
|
16 | 17 | } else if (typeof module === 'object' && module.exports) {
|
|
488 | 489 | this.endDate = moment(endDate);
|
489 | 490 |
|
490 | 491 | if (!this.timePicker)
|
491 |
| - this.endDate = this.endDate.add(1,'d').startOf('day').subtract(1,'second'); |
| 492 | + this.endDate = this.endDate.endOf('day'); |
492 | 493 |
|
493 | 494 | if (this.timePicker && this.timePickerIncrement)
|
494 | 495 | this.endDate.minute(Math.round(this.endDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
|
|
575 | 576 | if (this.endDate) {
|
576 | 577 | hour = parseInt(this.container.find('.left .hourselect').val(), 10);
|
577 | 578 | minute = parseInt(this.container.find('.left .minuteselect').val(), 10);
|
| 579 | + if (isNaN(minute)) { |
| 580 | + minute = parseInt(this.container.find('.left .minuteselect option:last').val(), 10); |
| 581 | + } |
578 | 582 | second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0;
|
579 | 583 | if (!this.timePicker24Hour) {
|
580 | 584 | var ampm = this.container.find('.left .ampmselect').val();
|
|
586 | 590 | } else {
|
587 | 591 | hour = parseInt(this.container.find('.right .hourselect').val(), 10);
|
588 | 592 | minute = parseInt(this.container.find('.right .minuteselect').val(), 10);
|
| 593 | + if (isNaN(minute)) { |
| 594 | + minute = parseInt(this.container.find('.right .minuteselect option:last').val(), 10); |
| 595 | + } |
589 | 596 | second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;
|
590 | 597 | if (!this.timePicker24Hour) {
|
591 | 598 | var ampm = this.container.find('.right .ampmselect').val();
|
|
709 | 716 |
|
710 | 717 | var monthHtml = '<select class="monthselect">';
|
711 | 718 | for (var m = 0; m < 12; m++) {
|
712 |
| - if ((!inMinYear || m >= minDate.month()) && (!inMaxYear || m <= maxDate.month())) { |
| 719 | + if ((!inMinYear || (minDate && m >= minDate.month())) && (!inMaxYear || (maxDate && m <= maxDate.month()))) { |
713 | 720 | monthHtml += "<option value='" + m + "'" +
|
714 | 721 | (m === currentMonth ? " selected='selected'" : "") +
|
715 | 722 | ">" + this.locale.monthNames[m] + "</option>";
|
|
786 | 793 |
|
787 | 794 | //grey out the dates in other months displayed at beginning and end of this calendar
|
788 | 795 | if (calendar[row][col].month() != calendar[1][1].month())
|
789 |
| - classes.push('off'); |
| 796 | + classes.push('off', 'ends'); |
790 | 797 |
|
791 | 798 | //don't allow selection of dates before the minimum date
|
792 | 799 | if (this.minDate && calendar[row][col].isBefore(this.minDate, 'day'))
|
|
851 | 858 |
|
852 | 859 | var html, selected, minDate, maxDate = this.maxDate;
|
853 | 860 |
|
854 |
| - if (this.maxSpan && (!this.maxDate || this.startDate.clone().add(this.maxSpan).isAfter(this.maxDate))) |
| 861 | + if (this.maxSpan && (!this.maxDate || this.startDate.clone().add(this.maxSpan).isBefore(this.maxDate))) |
855 | 862 | maxDate = this.startDate.clone().add(this.maxSpan);
|
856 | 863 |
|
857 | 864 | if (side == 'left') {
|
|
865 | 872 | var timeSelector = this.container.find('.drp-calendar.right .calendar-time');
|
866 | 873 | if (timeSelector.html() != '') {
|
867 | 874 |
|
868 |
| - selected.hour(selected.hour() || timeSelector.find('.hourselect option:selected').val()); |
869 |
| - selected.minute(selected.minute() || timeSelector.find('.minuteselect option:selected').val()); |
870 |
| - selected.second(selected.second() || timeSelector.find('.secondselect option:selected').val()); |
| 875 | + selected.hour(!isNaN(selected.hour()) ? selected.hour() : timeSelector.find('.hourselect option:selected').val()); |
| 876 | + selected.minute(!isNaN(selected.minute()) ? selected.minute() : timeSelector.find('.minuteselect option:selected').val()); |
| 877 | + selected.second(!isNaN(selected.second()) ? selected.second() : timeSelector.find('.secondselect option:selected').val()); |
871 | 878 |
|
872 | 879 | if (!this.timePicker24Hour) {
|
873 | 880 | var ampm = timeSelector.find('.ampmselect option:selected').val();
|
|
1030 | 1037 | containerTop = this.element.offset().top - this.container.outerHeight() - parentOffset.top;
|
1031 | 1038 | else
|
1032 | 1039 | containerTop = this.element.offset().top + this.element.outerHeight() - parentOffset.top;
|
| 1040 | + |
| 1041 | + // Force the container to it's actual width |
| 1042 | + this.container.css({ |
| 1043 | + top: 0, |
| 1044 | + left: 0, |
| 1045 | + right: 'auto' |
| 1046 | + }); |
| 1047 | + var containerWidth = this.container.outerWidth(); |
| 1048 | + |
1033 | 1049 | this.container[this.drops == 'up' ? 'addClass' : 'removeClass']('drop-up');
|
1034 | 1050 |
|
1035 | 1051 | if (this.opens == 'left') {
|
1036 |
| - this.container.css({ |
1037 |
| - top: containerTop, |
1038 |
| - right: parentRightEdge - this.element.offset().left - this.element.outerWidth(), |
1039 |
| - left: 'auto' |
1040 |
| - }); |
1041 |
| - if (this.container.offset().left < 0) { |
| 1052 | + var containerRight = parentRightEdge - this.element.offset().left - this.element.outerWidth(); |
| 1053 | + if (containerWidth + containerRight > $(window).width()) { |
1042 | 1054 | this.container.css({
|
| 1055 | + top: containerTop, |
1043 | 1056 | right: 'auto',
|
1044 | 1057 | left: 9
|
1045 | 1058 | });
|
| 1059 | + } else { |
| 1060 | + this.container.css({ |
| 1061 | + top: containerTop, |
| 1062 | + right: containerRight, |
| 1063 | + left: 'auto' |
| 1064 | + }); |
1046 | 1065 | }
|
1047 | 1066 | } else if (this.opens == 'center') {
|
1048 |
| - this.container.css({ |
1049 |
| - top: containerTop, |
1050 |
| - left: this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2 |
1051 |
| - - this.container.outerWidth() / 2, |
1052 |
| - right: 'auto' |
1053 |
| - }); |
1054 |
| - if (this.container.offset().left < 0) { |
| 1067 | + var containerLeft = this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2 |
| 1068 | + - containerWidth / 2; |
| 1069 | + if (containerLeft < 0) { |
1055 | 1070 | this.container.css({
|
| 1071 | + top: containerTop, |
1056 | 1072 | right: 'auto',
|
1057 | 1073 | left: 9
|
1058 | 1074 | });
|
| 1075 | + } else if (containerLeft + containerWidth > $(window).width()) { |
| 1076 | + this.container.css({ |
| 1077 | + top: containerTop, |
| 1078 | + left: 'auto', |
| 1079 | + right: 0 |
| 1080 | + }); |
| 1081 | + } else { |
| 1082 | + this.container.css({ |
| 1083 | + top: containerTop, |
| 1084 | + left: containerLeft, |
| 1085 | + right: 'auto' |
| 1086 | + }); |
1059 | 1087 | }
|
1060 | 1088 | } else {
|
1061 |
| - this.container.css({ |
1062 |
| - top: containerTop, |
1063 |
| - left: this.element.offset().left - parentOffset.left, |
1064 |
| - right: 'auto' |
1065 |
| - }); |
1066 |
| - if (this.container.offset().left + this.container.outerWidth() > $(window).width()) { |
| 1089 | + var containerLeft = this.element.offset().left - parentOffset.left; |
| 1090 | + if (containerLeft + containerWidth > $(window).width()) { |
1067 | 1091 | this.container.css({
|
| 1092 | + top: containerTop, |
1068 | 1093 | left: 'auto',
|
1069 | 1094 | right: 0
|
1070 | 1095 | });
|
| 1096 | + } else { |
| 1097 | + this.container.css({ |
| 1098 | + top: containerTop, |
| 1099 | + left: containerLeft, |
| 1100 | + right: 'auto' |
| 1101 | + }); |
1071 | 1102 | }
|
1072 | 1103 | }
|
1073 | 1104 | },
|
|
1272 | 1303 | hour = 0;
|
1273 | 1304 | }
|
1274 | 1305 | var minute = parseInt(this.container.find('.left .minuteselect').val(), 10);
|
| 1306 | + if (isNaN(minute)) { |
| 1307 | + minute = parseInt(this.container.find('.left .minuteselect option:last').val(), 10); |
| 1308 | + } |
1275 | 1309 | var second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0;
|
1276 | 1310 | date = date.clone().hour(hour).minute(minute).second(second);
|
1277 | 1311 | }
|
|
1292 | 1326 | hour = 0;
|
1293 | 1327 | }
|
1294 | 1328 | var minute = parseInt(this.container.find('.right .minuteselect').val(), 10);
|
| 1329 | + if (isNaN(minute)) { |
| 1330 | + minute = parseInt(this.container.find('.right .minuteselect option:last').val(), 10); |
| 1331 | + } |
1295 | 1332 | var second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;
|
1296 | 1333 | date = date.clone().hour(hour).minute(minute).second(second);
|
1297 | 1334 | }
|
|
1320 | 1357 | var i = 0;
|
1321 | 1358 | for (var range in this.ranges) {
|
1322 | 1359 | if (this.timePicker) {
|
1323 |
| - var format = this.timePickerSeconds ? "YYYY-MM-DD hh:mm:ss" : "YYYY-MM-DD hh:mm"; |
| 1360 | + var format = this.timePickerSeconds ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD HH:mm"; |
1324 | 1361 | //ignore times when comparing dates if time picker seconds is not enabled
|
1325 | 1362 | if (this.startDate.format(format) == this.ranges[range][0].format(format) && this.endDate.format(format) == this.ranges[range][1].format(format)) {
|
1326 | 1363 | customRange = false;
|
|
1408 | 1445 |
|
1409 | 1446 | var hour = parseInt(cal.find('.hourselect').val(), 10);
|
1410 | 1447 | var minute = parseInt(cal.find('.minuteselect').val(), 10);
|
| 1448 | + if (isNaN(minute)) { |
| 1449 | + minute = parseInt(cal.find('.minuteselect option:last').val(), 10); |
| 1450 | + } |
1411 | 1451 | var second = this.timePickerSeconds ? parseInt(cal.find('.secondselect').val(), 10) : 0;
|
1412 | 1452 |
|
1413 | 1453 | if (!this.timePicker24Hour) {
|
|
0 commit comments