';
if ((!minDate || minDate.isBefore(calendar.firstDay)) && (!this.linkedCalendars || side == 'left')) {
- html += '
';
+ html += '
';
} else {
html += '
';
}
@@ -690,14 +709,14 @@
if (this.showDropdowns) {
var currentMonth = calendar[1][1].month();
var currentYear = calendar[1][1].year();
- var maxYear = (maxDate && maxDate.year()) || (currentYear + 5);
- var minYear = (minDate && minDate.year()) || (currentYear - 50);
+ var maxYear = (maxDate && maxDate.year()) || (this.maxYear);
+ var minYear = (minDate && minDate.year()) || (this.minYear);
var inMinYear = currentYear == minYear;
var inMaxYear = currentYear == maxYear;
var monthHtml = '';
html += '';
- //adjust maxDate to reflect the dateLimit setting in order to
- //grey out end dates beyond the dateLimit
- if (this.endDate == null && this.dateLimit) {
- var maxLimit = this.startDate.clone().add(this.dateLimit).endOf('day');
+ //adjust maxDate to reflect the maxSpan setting in order to
+ //grey out end dates beyond the maxSpan
+ if (this.endDate == null && this.maxSpan) {
+ var maxLimit = this.startDate.clone().add(this.maxSpan).endOf('day');
if (!maxDate || maxLimit.isBefore(maxDate)) {
maxDate = maxLimit;
}
@@ -774,7 +793,7 @@
//grey out the dates in other months displayed at beginning and end of this calendar
if (calendar[row][col].month() != calendar[1][1].month())
- classes.push('off');
+ classes.push('off', 'ends');
//don't allow selection of dates before the minimum date
if (this.minDate && calendar[row][col].isBefore(this.minDate, 'day'))
@@ -800,6 +819,15 @@
if (this.endDate != null && calendar[row][col] > this.startDate && calendar[row][col] < this.endDate)
classes.push('in-range');
+ //apply custom classes for this date
+ var isCustom = this.isCustomDate(calendar[row][col]);
+ if (isCustom !== false) {
+ if (typeof isCustom === 'string')
+ classes.push(isCustom);
+ else
+ Array.prototype.push.apply(classes, isCustom);
+ }
+
var cname = '', disabled = false;
for (var i = 0; i < classes.length; i++) {
cname += classes[i] + ' ';
@@ -818,31 +846,35 @@
html += '';
html += '
';
- this.container.find('.calendar.' + side + ' .calendar-table').html(html);
+ this.container.find('.drp-calendar.' + side + ' .calendar-table').html(html);
},
renderTimePicker: function(side) {
+ // Don't bother updating the time picker if it's currently disabled
+ // because an end date hasn't been clicked yet
+ if (side == 'right' && !this.endDate) return;
+
var html, selected, minDate, maxDate = this.maxDate;
- if (this.dateLimit && (!this.maxDate || this.startDate.clone().add(this.dateLimit).isAfter(this.maxDate)))
- maxDate = this.startDate.clone().add(this.dateLimit);
+ if (this.maxSpan && (!this.maxDate || this.startDate.clone().add(this.maxSpan).isBefore(this.maxDate)))
+ maxDate = this.startDate.clone().add(this.maxSpan);
if (side == 'left') {
selected = this.startDate.clone();
minDate = this.minDate;
} else if (side == 'right') {
- selected = this.endDate ? this.endDate.clone() : this.previousRightTime.clone();
+ selected = this.endDate.clone();
minDate = this.startDate;
//Preserve the time already selected
- var timeSelector = this.container.find('.calendar.right .calendar-time div');
+ var timeSelector = this.container.find('.drp-calendar.right .calendar-time');
if (timeSelector.html() != '') {
- selected.hour(timeSelector.find('.hourselect option:selected').val() || selected.hour());
- selected.minute(timeSelector.find('.minuteselect option:selected').val() || selected.minute());
- selected.second(timeSelector.find('.secondselect option:selected').val() || selected.second());
+ selected.hour(!isNaN(selected.hour()) ? selected.hour() : timeSelector.find('.hourselect option:selected').val());
+ selected.minute(!isNaN(selected.minute()) ? selected.minute() : timeSelector.find('.minuteselect option:selected').val());
+ selected.second(!isNaN(selected.second()) ? selected.second() : timeSelector.find('.secondselect option:selected').val());
if (!this.timePicker24Hour) {
var ampm = timeSelector.find('.ampmselect option:selected').val();
@@ -852,13 +884,14 @@
selected.hour(0);
}
- if (selected.isBefore(this.startDate))
- selected = this.startDate.clone();
-
- if (selected.isAfter(maxDate))
- selected = maxDate.clone();
-
}
+
+ if (selected.isBefore(this.startDate))
+ selected = this.startDate.clone();
+
+ if (maxDate && selected.isAfter(maxDate))
+ selected = maxDate.clone();
+
}
//
@@ -974,20 +1007,12 @@
html += '';
}
- this.container.find('.calendar.' + side + ' .calendar-time div').html(html);
+ this.container.find('.drp-calendar.' + side + ' .calendar-time').html(html);
},
updateFormInputs: function() {
- //ignore mouse movements while an above-calendar text input has focus
- if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus"))
- return;
-
- this.container.find('input[name=daterangepicker_start]').val(this.startDate.format(this.locale.format));
- if (this.endDate)
- this.container.find('input[name=daterangepicker_end]').val(this.endDate.format(this.locale.format));
-
if (this.singleDatePicker || (this.endDate && (this.startDate.isBefore(this.endDate) || this.startDate.isSame(this.endDate)))) {
this.container.find('button.applyBtn').removeAttr('disabled');
} else {
@@ -1012,44 +1037,68 @@
containerTop = this.element.offset().top - this.container.outerHeight() - parentOffset.top;
else
containerTop = this.element.offset().top + this.element.outerHeight() - parentOffset.top;
- this.container[this.drops == 'up' ? 'addClass' : 'removeClass']('dropup');
+
+ // Force the container to it's actual width
+ this.container.css({
+ top: 0,
+ left: 0,
+ right: 'auto'
+ });
+ var containerWidth = this.container.outerWidth();
+
+ this.container[this.drops == 'up' ? 'addClass' : 'removeClass']('drop-up');
if (this.opens == 'left') {
- this.container.css({
- top: containerTop,
- right: parentRightEdge - this.element.offset().left - this.element.outerWidth(),
- left: 'auto'
- });
- if (this.container.offset().left < 0) {
+ var containerRight = parentRightEdge - this.element.offset().left - this.element.outerWidth();
+ if (containerWidth + containerRight > $(window).width()) {
this.container.css({
+ top: containerTop,
right: 'auto',
left: 9
});
+ } else {
+ this.container.css({
+ top: containerTop,
+ right: containerRight,
+ left: 'auto'
+ });
}
} else if (this.opens == 'center') {
- this.container.css({
- top: containerTop,
- left: this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2
- - this.container.outerWidth() / 2,
- right: 'auto'
- });
- if (this.container.offset().left < 0) {
+ var containerLeft = this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2
+ - containerWidth / 2;
+ if (containerLeft < 0) {
this.container.css({
+ top: containerTop,
right: 'auto',
left: 9
});
- }
- } else {
- this.container.css({
- top: containerTop,
- left: this.element.offset().left - parentOffset.left,
- right: 'auto'
- });
- if (this.container.offset().left + this.container.outerWidth() > $(window).width()) {
+ } else if (containerLeft + containerWidth > $(window).width()) {
this.container.css({
+ top: containerTop,
left: 'auto',
right: 0
});
+ } else {
+ this.container.css({
+ top: containerTop,
+ left: containerLeft,
+ right: 'auto'
+ });
+ }
+ } else {
+ var containerLeft = this.element.offset().left - parentOffset.left;
+ if (containerLeft + containerWidth > $(window).width()) {
+ this.container.css({
+ top: containerTop,
+ left: 'auto',
+ right: 0
+ });
+ } else {
+ this.container.css({
+ top: containerTop,
+ left: containerLeft,
+ right: 'auto'
+ });
}
}
},
@@ -1095,7 +1144,7 @@
//if a new date range was selected, invoke the user callback function
if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate))
- this.callback(this.startDate, this.endDate, this.chosenLabel);
+ this.callback(this.startDate.clone(), this.endDate.clone(), this.chosenLabel);
//if picker is attached to a text input, update it
this.updateElement();
@@ -1127,6 +1176,7 @@
target.closest('.calendar-table').length
) return;
this.hide();
+ this.element.trigger('outsideClick.daterangepicker', this);
},
showCalendars: function() {
@@ -1140,25 +1190,8 @@
this.element.trigger('hideCalendar.daterangepicker', this);
},
- hoverRange: function(e) {
-
- //ignore mouse movements while an above-calendar text input has focus
- if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus"))
- return;
-
- var label = e.target.innerHTML;
- if (label == this.locale.customRangeLabel) {
- this.updateView();
- } else {
- var dates = this.ranges[label];
- this.container.find('input[name=daterangepicker_start]').val(dates[0].format(this.locale.format));
- this.container.find('input[name=daterangepicker_end]').val(dates[1].format(this.locale.format));
- }
-
- },
-
clickRange: function(e) {
- var label = e.target.innerHTML;
+ var label = e.target.getAttribute('data-range-key');
this.chosenLabel = label;
if (label == this.locale.customRangeLabel) {
this.showCalendars();
@@ -1179,7 +1212,7 @@
},
clickPrev: function(e) {
- var cal = $(e.target).parents('.calendar');
+ var cal = $(e.target).parents('.drp-calendar');
if (cal.hasClass('left')) {
this.leftCalendar.month.subtract(1, 'month');
if (this.linkedCalendars)
@@ -1191,7 +1224,7 @@
},
clickNext: function(e) {
- var cal = $(e.target).parents('.calendar');
+ var cal = $(e.target).parents('.drp-calendar');
if (cal.hasClass('left')) {
this.leftCalendar.month.add(1, 'month');
} else {
@@ -1204,32 +1237,21 @@
hoverDate: function(e) {
- //ignore mouse movements while an above-calendar text input has focus
- if (this.container.find('input[name=daterangepicker_start]').is(":focus") || this.container.find('input[name=daterangepicker_end]').is(":focus"))
- return;
-
//ignore dates that can't be selected
if (!$(e.target).hasClass('available')) return;
- //have the text inputs above calendars reflect the date being hovered over
var title = $(e.target).attr('data-title');
var row = title.substr(1, 1);
var col = title.substr(3, 1);
- var cal = $(e.target).parents('.calendar');
+ var cal = $(e.target).parents('.drp-calendar');
var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col];
- if (this.endDate) {
- this.container.find('input[name=daterangepicker_start]').val(date.format(this.locale.format));
- } else {
- this.container.find('input[name=daterangepicker_end]').val(date.format(this.locale.format));
- }
-
//highlight the dates between the start date and the date being hovered as a potential end date
var leftCalendar = this.leftCalendar;
var rightCalendar = this.rightCalendar;
var startDate = this.startDate;
if (!this.endDate) {
- this.container.find('.calendar td').each(function(index, el) {
+ this.container.find('.drp-calendar tbody td').each(function(index, el) {
//skip week numbers, only look at dates
if ($(el).hasClass('week')) return;
@@ -1237,10 +1259,10 @@
var title = $(el).attr('data-title');
var row = title.substr(1, 1);
var col = title.substr(3, 1);
- var cal = $(el).parents('.calendar');
+ var cal = $(el).parents('.drp-calendar');
var dt = cal.hasClass('left') ? leftCalendar.calendar[row][col] : rightCalendar.calendar[row][col];
- if (dt.isAfter(startDate) && dt.isBefore(date)) {
+ if ((dt.isAfter(startDate) && dt.isBefore(date)) || dt.isSame(date, 'day')) {
$(el).addClass('in-range');
} else {
$(el).removeClass('in-range');
@@ -1258,7 +1280,7 @@
var title = $(e.target).attr('data-title');
var row = title.substr(1, 1);
var col = title.substr(3, 1);
- var cal = $(e.target).parents('.calendar');
+ var cal = $(e.target).parents('.drp-calendar');
var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col];
//
@@ -1267,9 +1289,10 @@
// * if the time picker is enabled, apply the hour/minute/second from the select boxes to the clicked date
// * if autoapply is enabled, and an end date was chosen, apply the selection
// * if single date picker mode, and time picker isn't enabled, apply the selection immediately
+ // * if one of the inputs above the calendars was focused, cancel that manual input
//
- if (this.endDate || date.isBefore(this.startDate, 'day')) {
+ if (this.endDate || date.isBefore(this.startDate, 'day')) { //picking start
if (this.timePicker) {
var hour = parseInt(this.container.find('.left .hourselect').val(), 10);
if (!this.timePicker24Hour) {
@@ -1280,16 +1303,19 @@
hour = 0;
}
var minute = parseInt(this.container.find('.left .minuteselect').val(), 10);
+ if (isNaN(minute)) {
+ minute = parseInt(this.container.find('.left .minuteselect option:last').val(), 10);
+ }
var second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0;
date = date.clone().hour(hour).minute(minute).second(second);
}
this.endDate = null;
this.setStartDate(date.clone());
} else if (!this.endDate && date.isBefore(this.startDate)) {
- //special case: clicking the same date for start/end,
+ //special case: clicking the same date for start/end,
//but the time of the end date is before the start date
this.setEndDate(this.startDate.clone());
- } else {
+ } else { // picking end
if (this.timePicker) {
var hour = parseInt(this.container.find('.right .hourselect').val(), 10);
if (!this.timePicker24Hour) {
@@ -1300,6 +1326,9 @@
hour = 0;
}
var minute = parseInt(this.container.find('.right .minuteselect').val(), 10);
+ if (isNaN(minute)) {
+ minute = parseInt(this.container.find('.right .minuteselect option:last').val(), 10);
+ }
var second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;
date = date.clone().hour(hour).minute(minute).second(second);
}
@@ -1318,32 +1347,41 @@
this.updateView();
+ //This is to cancel the blur event handler if the mouse was in one of the inputs
+ e.stopPropagation();
+
},
- calculateChosenLabel: function() {
- var customRange = true;
- var i = 0;
- for (var range in this.ranges) {
+ calculateChosenLabel: function () {
+ var customRange = true;
+ var i = 0;
+ for (var range in this.ranges) {
if (this.timePicker) {
- if (this.startDate.isSame(this.ranges[range][0]) && this.endDate.isSame(this.ranges[range][1])) {
- customRange = false;
- this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').html();
- break;
- }
- } else {
- //ignore times when comparing dates if time picker is not enabled
- if (this.startDate.format('YYYY-MM-DD') == this.ranges[range][0].format('YYYY-MM-DD') && this.endDate.format('YYYY-MM-DD') == this.ranges[range][1].format('YYYY-MM-DD')) {
- customRange = false;
- this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').html();
- break;
- }
- }
- i++;
- }
- if (customRange) {
- this.chosenLabel = this.container.find('.ranges li:last').addClass('active').html();
- this.showCalendars();
- }
+ var format = this.timePickerSeconds ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD HH:mm";
+ //ignore times when comparing dates if time picker seconds is not enabled
+ if (this.startDate.format(format) == this.ranges[range][0].format(format) && this.endDate.format(format) == this.ranges[range][1].format(format)) {
+ customRange = false;
+ this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').attr('data-range-key');
+ break;
+ }
+ } else {
+ //ignore times when comparing dates if time picker is not enabled
+ if (this.startDate.format('YYYY-MM-DD') == this.ranges[range][0].format('YYYY-MM-DD') && this.endDate.format('YYYY-MM-DD') == this.ranges[range][1].format('YYYY-MM-DD')) {
+ customRange = false;
+ this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').attr('data-range-key');
+ break;
+ }
+ }
+ i++;
+ }
+ if (customRange) {
+ if (this.showCustomRangeLabel) {
+ this.chosenLabel = this.container.find('.ranges li:last').addClass('active').attr('data-range-key');
+ } else {
+ this.chosenLabel = null;
+ }
+ this.showCalendars();
+ }
},
clickApply: function(e) {
@@ -1359,9 +1397,9 @@
},
monthOrYearChanged: function(e) {
- var isLeft = $(e.target).closest('.calendar').hasClass('left'),
+ var isLeft = $(e.target).closest('.drp-calendar').hasClass('left'),
leftOrRight = isLeft ? 'left' : 'right',
- cal = this.container.find('.calendar.'+leftOrRight);
+ cal = this.container.find('.drp-calendar.'+leftOrRight);
// Month must be Number for new moment versions
var month = parseInt(cal.find('.monthselect').val(), 10);
@@ -1402,11 +1440,14 @@
timeChanged: function(e) {
- var cal = $(e.target).closest('.calendar'),
+ var cal = $(e.target).closest('.drp-calendar'),
isLeft = cal.hasClass('left');
var hour = parseInt(cal.find('.hourselect').val(), 10);
var minute = parseInt(cal.find('.minuteselect').val(), 10);
+ if (isNaN(minute)) {
+ minute = parseInt(cal.find('.minuteselect option:last').val(), 10);
+ }
var second = this.timePickerSeconds ? parseInt(cal.find('.secondselect').val(), 10) : 0;
if (!this.timePicker24Hour) {
@@ -1448,38 +1489,9 @@
},
- formInputsChanged: function(e) {
- var isRight = $(e.target).closest('.calendar').hasClass('right');
- var start = moment(this.container.find('input[name="daterangepicker_start"]').val(), this.locale.format);
- var end = moment(this.container.find('input[name="daterangepicker_end"]').val(), this.locale.format);
-
- if (start.isValid() && end.isValid()) {
-
- if (isRight && end.isBefore(start))
- start = end.clone();
-
- this.setStartDate(start);
- this.setEndDate(end);
-
- if (isRight) {
- this.container.find('input[name="daterangepicker_start"]').val(this.startDate.format(this.locale.format));
- } else {
- this.container.find('input[name="daterangepicker_end"]').val(this.endDate.format(this.locale.format));
- }
-
- }
-
- this.updateCalendars();
- if (this.timePicker) {
- this.renderTimePicker('left');
- this.renderTimePicker('right');
- }
- },
-
elementChanged: function() {
if (!this.element.is('input')) return;
if (!this.element.val().length) return;
- if (this.element.val().length < this.locale.format.length) return;
var dateString = this.element.val().split(this.locale.separator),
start = null,
@@ -1507,15 +1519,25 @@
if ((e.keyCode === 9) || (e.keyCode === 13)) {
this.hide();
}
+
+ //hide on esc and prevent propagation
+ if (e.keyCode === 27) {
+ e.preventDefault();
+ e.stopPropagation();
+
+ this.hide();
+ }
},
updateElement: function() {
- if (this.element.is('input') && !this.singleDatePicker && this.autoUpdateInput) {
- this.element.val(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));
- this.element.trigger('change');
- } else if (this.element.is('input') && this.autoUpdateInput) {
- this.element.val(this.startDate.format(this.locale.format));
- this.element.trigger('change');
+ if (this.element.is('input') && this.autoUpdateInput) {
+ var newValue = this.startDate.format(this.locale.format);
+ if (!this.singleDatePicker) {
+ newValue += this.locale.separator + this.endDate.format(this.locale.format);
+ }
+ if (newValue !== this.element.val()) {
+ this.element.val(newValue).trigger('change');
+ }
}
},
@@ -1528,15 +1550,16 @@
};
$.fn.daterangepicker = function(options, callback) {
+ var implementOptions = $.extend(true, {}, $.fn.daterangepicker.defaultOptions, options);
this.each(function() {
var el = $(this);
if (el.data('daterangepicker'))
el.data('daterangepicker').remove();
- el.data('daterangepicker', new DateRangePicker(el, options, callback));
+ el.data('daterangepicker', new DateRangePicker(el, implementOptions, callback));
});
return this;
};
-
+
return DateRangePicker;
}));
diff --git a/settings.php b/settings.php
index e9423ecb..128f23c2 100644
--- a/settings.php
+++ b/settings.php
@@ -46,7 +46,7 @@ if (isset($_POST["submit"])) {