|
1 | 1 | /**
|
2 |
| -* @version: 2.1.13 |
| 2 | +* @version: 2.1.17 |
3 | 3 | * @author: Dan Grossman http://www.dangrossman.info/
|
4 | 4 | * @copyright: Copyright (c) 2012-2015 Dan Grossman. All rights reserved.
|
5 | 5 | * @license: Licensed under the MIT license. See http://www.opensource.org/licenses/mit-license.php
|
|
320 | 320 | //Support unicode chars in the range names.
|
321 | 321 | var elem = document.createElement('textarea');
|
322 | 322 | elem.innerHTML = range;
|
323 |
| - rangeHtml = elem.value; |
| 323 | + var rangeHtml = elem.value; |
324 | 324 |
|
325 | 325 | this.ranges[rangeHtml] = [start, end];
|
326 | 326 | }
|
|
488 | 488 | if (this.dateLimit && this.startDate.clone().add(this.dateLimit).isBefore(this.endDate))
|
489 | 489 | this.endDate = this.startDate.clone().add(this.dateLimit);
|
490 | 490 |
|
| 491 | + this.previousRightTime = this.endDate.clone(); |
| 492 | + |
491 | 493 | if (!this.isShowing)
|
492 | 494 | this.updateElement();
|
493 | 495 |
|
|
567 | 569 | minute = parseInt(this.container.find('.right .minuteselect').val(), 10);
|
568 | 570 | second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;
|
569 | 571 | if (!this.timePicker24Hour) {
|
570 |
| - var ampm = this.container.find('.left .ampmselect').val(); |
| 572 | + var ampm = this.container.find('.right .ampmselect').val(); |
571 | 573 | if (ampm === 'PM' && hour < 12)
|
572 | 574 | hour += 12;
|
573 | 575 | if (ampm === 'AM' && hour === 12)
|
|
844 | 846 | selected = this.startDate.clone();
|
845 | 847 | minDate = this.minDate;
|
846 | 848 | } else if (side == 'right') {
|
847 |
| - selected = this.endDate ? this.endDate.clone() : this.startDate.clone(); |
| 849 | + selected = this.endDate ? this.endDate.clone() : this.previousRightTime.clone(); |
848 | 850 | minDate = this.startDate;
|
| 851 | + |
| 852 | + //Preserve the time already selected |
| 853 | + var timeSelector = this.container.find('.calendar.right .calendar-time div'); |
| 854 | + if (timeSelector.html() != '') { |
| 855 | + |
| 856 | + selected.hour(timeSelector.find('.hourselect option:selected').val() || selected.hour()); |
| 857 | + selected.minute(timeSelector.find('.minuteselect option:selected').val() || selected.minute()); |
| 858 | + selected.second(timeSelector.find('.secondselect option:selected').val() || selected.second()); |
| 859 | + |
| 860 | + if (!this.timePicker24Hour) { |
| 861 | + var ampm = timeSelector.find('.ampmselect option:selected').val(); |
| 862 | + if (ampm === 'PM' && selected.hour() < 12) |
| 863 | + selected.hour(selected.hour() + 12); |
| 864 | + if (ampm === 'AM' && selected.hour() === 12) |
| 865 | + selected.hour(0); |
| 866 | + } |
| 867 | + |
| 868 | + if (selected.isBefore(this.startDate)) |
| 869 | + selected = this.startDate.clone(); |
| 870 | + |
| 871 | + if (selected.isAfter(maxDate)) |
| 872 | + selected = maxDate.clone(); |
| 873 | + |
| 874 | + } |
849 | 875 | }
|
850 | 876 |
|
851 | 877 | //
|
|
1062 | 1088 |
|
1063 | 1089 | this.oldStartDate = this.startDate.clone();
|
1064 | 1090 | this.oldEndDate = this.endDate.clone();
|
| 1091 | + this.previousRightTime = this.endDate.clone(); |
1065 | 1092 |
|
1066 | 1093 | this.updateView();
|
1067 | 1094 | this.container.show();
|
|
1254 | 1281 | // * if single date picker mode, and time picker isn't enabled, apply the selection immediately
|
1255 | 1282 | //
|
1256 | 1283 |
|
1257 |
| - if (this.endDate || date.isBefore(this.startDate)) { |
| 1284 | + if (this.endDate || date.isBefore(this.startDate, 'day')) { |
1258 | 1285 | if (this.timePicker) {
|
1259 | 1286 | var hour = parseInt(this.container.find('.left .hourselect').val(), 10);
|
1260 | 1287 | if (!this.timePicker24Hour) {
|
|
1270 | 1297 | }
|
1271 | 1298 | this.endDate = null;
|
1272 | 1299 | this.setStartDate(date.clone());
|
| 1300 | + } else if (!this.endDate && date.isBefore(this.startDate)) { |
| 1301 | + //special case: clicking the same date for start/end, |
| 1302 | + //but the time of the end date is before the start date |
| 1303 | + this.setEndDate(this.startDate.clone()); |
1273 | 1304 | } else {
|
1274 | 1305 | if (this.timePicker) {
|
1275 | 1306 | var hour = parseInt(this.container.find('.right .hourselect').val(), 10);
|
|
1489 | 1520 | });
|
1490 | 1521 | return this;
|
1491 | 1522 | };
|
| 1523 | + |
| 1524 | + return DateRangePicker; |
1492 | 1525 |
|
1493 | 1526 | }));
|
0 commit comments