';
this.parentEl = (options.parentEl && $(options.parentEl).length) ? $(options.parentEl) : $(this.parentEl);
this.container = $(options.template).appendTo(this.parentEl);
@@ -148,19 +138,19 @@
this.locale.daysOfWeek = options.locale.daysOfWeek.slice();
if (typeof options.locale.monthNames === 'object')
- this.locale.monthNames = options.locale.monthNames.slice();
+ this.locale.monthNames = options.locale.monthNames.slice();
if (typeof options.locale.firstDay === 'number')
- this.locale.firstDay = options.locale.firstDay;
+ this.locale.firstDay = options.locale.firstDay;
if (typeof options.locale.applyLabel === 'string')
- this.locale.applyLabel = options.locale.applyLabel;
+ this.locale.applyLabel = options.locale.applyLabel;
if (typeof options.locale.cancelLabel === 'string')
- this.locale.cancelLabel = options.locale.cancelLabel;
+ this.locale.cancelLabel = options.locale.cancelLabel;
if (typeof options.locale.weekLabel === 'string')
- this.locale.weekLabel = options.locale.weekLabel;
+ this.locale.weekLabel = options.locale.weekLabel;
if (typeof options.locale.customRangeLabel === 'string'){
//Support unicode chars in the custom range name.
@@ -204,14 +194,23 @@
if (this.maxDate && this.endDate.isAfter(this.maxDate))
this.endDate = this.maxDate.clone();
- if (typeof options.applyClass === 'string')
- this.applyClass = options.applyClass;
+ if (typeof options.applyButtonClasses === 'string')
+ this.applyButtonClasses = options.applyButtonClasses;
- if (typeof options.cancelClass === 'string')
- this.cancelClass = options.cancelClass;
+ if (typeof options.applyClass === 'string') //backwards compat
+ this.applyButtonClasses = options.applyClass;
- if (typeof options.dateLimit === 'object')
- this.dateLimit = options.dateLimit;
+ if (typeof options.cancelButtonClasses === 'string')
+ this.cancelButtonClasses = options.cancelButtonClasses;
+
+ if (typeof options.cancelClass === 'string') //backwards compat
+ this.cancelButtonClasses = options.cancelClass;
+
+ if (typeof options.maxSpan === 'object')
+ this.maxSpan = options.maxSpan;
+
+ if (typeof options.dateLimit === 'object') //backwards compat
+ this.maxSpan = options.dateLimit;
if (typeof options.opens === 'string')
this.opens = options.opens;
@@ -234,6 +233,12 @@
if (typeof options.showDropdowns === 'boolean')
this.showDropdowns = options.showDropdowns;
+ if (typeof options.minYear === 'number')
+ this.minYear = options.minYear;
+
+ if (typeof options.maxYear === 'number')
+ this.maxYear = options.maxYear;
+
if (typeof options.showCustomRangeLabel === 'boolean')
this.showCustomRangeLabel = options.showCustomRangeLabel;
@@ -286,7 +291,7 @@
//if no start/end dates set, check if an input element contains initial values
if (typeof options.startDate === 'undefined' && typeof options.endDate === 'undefined') {
- if ($(this.element).is('input[type=text]')) {
+ if ($(this.element).is(':text')) {
var val = $(this.element).val(),
split = val.split(this.locale.separator);
@@ -319,21 +324,21 @@
else
end = moment(options.ranges[range][1]);
- // If the start or end date exceed those allowed by the minDate or dateLimit
+ // If the start or end date exceed those allowed by the minDate or maxSpan
// options, shorten the range to the allowable period.
if (this.minDate && start.isBefore(this.minDate))
start = this.minDate.clone();
var maxDate = this.maxDate;
- if (this.dateLimit && maxDate && start.clone().add(this.dateLimit).isAfter(maxDate))
- maxDate = start.clone().add(this.dateLimit);
+ if (this.maxSpan && maxDate && start.clone().add(this.maxSpan).isAfter(maxDate))
+ maxDate = start.clone().add(this.maxSpan);
if (maxDate && end.isAfter(maxDate))
end = maxDate.clone();
// If the end of the range is before the minimum or the start of the range is
// after the maximum, don't display this range option at all.
if ((this.minDate && end.isBefore(this.minDate, this.timepicker ? 'minute' : 'day'))
- || (maxDate && start.isAfter(maxDate, this.timepicker ? 'minute' : 'day')))
+ || (maxDate && start.isAfter(maxDate, this.timepicker ? 'minute' : 'day')))
continue;
//Support unicode chars in the range names.
@@ -369,22 +374,20 @@
if (this.timePicker && this.autoApply)
this.autoApply = false;
- if (this.autoApply && typeof options.ranges !== 'object') {
- this.container.find('.ranges').hide();
- } else if (this.autoApply) {
- this.container.find('.applyBtn, .cancelBtn').addClass('hide');
+ if (this.autoApply) {
+ this.container.addClass('auto-apply');
}
+ if (typeof options.ranges === 'object')
+ this.container.addClass('show-ranges');
+
if (this.singleDatePicker) {
this.container.addClass('single');
- this.container.find('.calendar.left').addClass('single');
- this.container.find('.calendar.left').show();
- this.container.find('.calendar.right').hide();
- this.container.find('.daterangepicker_input input, .daterangepicker_input > i').hide();
- if (this.timePicker) {
- this.container.find('.ranges ul').hide();
- } else {
- this.container.find('.ranges').hide();
+ this.container.find('.drp-calendar.left').addClass('single');
+ this.container.find('.drp-calendar.left').show();
+ this.container.find('.drp-calendar.right').hide();
+ if (!this.timePicker) {
+ this.container.addClass('auto-apply');
}
}
@@ -394,17 +397,12 @@
this.container.addClass('opens' + this.opens);
- //swap the position of the predefined ranges if opens right
- if (typeof options.ranges !== 'undefined' && this.opens == 'right') {
- this.container.find('.ranges').prependTo( this.container.find('.calendar.left').parent() );
- }
-
//apply CSS classes and labels to buttons
this.container.find('.applyBtn, .cancelBtn').addClass(this.buttonClasses);
- if (this.applyClass.length)
- this.container.find('.applyBtn').addClass(this.applyClass);
- if (this.cancelClass.length)
- this.container.find('.cancelBtn').addClass(this.cancelClass);
+ if (this.applyButtonClasses.length)
+ this.container.find('.applyBtn').addClass(this.applyButtonClasses);
+ if (this.cancelButtonClasses.length)
+ this.container.find('.cancelBtn').addClass(this.cancelButtonClasses);
this.container.find('.applyBtn').html(this.locale.applyLabel);
this.container.find('.cancelBtn').html(this.locale.cancelLabel);
@@ -412,35 +410,29 @@
// event listeners
//
- this.container.find('.calendar')
+ this.container.find('.drp-calendar')
.on('click.daterangepicker', '.prev', $.proxy(this.clickPrev, this))
.on('click.daterangepicker', '.next', $.proxy(this.clickNext, this))
.on('mousedown.daterangepicker', 'td.available', $.proxy(this.clickDate, this))
.on('mouseenter.daterangepicker', 'td.available', $.proxy(this.hoverDate, this))
- .on('mouseleave.daterangepicker', 'td.available', $.proxy(this.updateFormInputs, this))
.on('change.daterangepicker', 'select.yearselect', $.proxy(this.monthOrYearChanged, this))
.on('change.daterangepicker', 'select.monthselect', $.proxy(this.monthOrYearChanged, this))
.on('change.daterangepicker', 'select.hourselect,select.minuteselect,select.secondselect,select.ampmselect', $.proxy(this.timeChanged, this))
- .on('click.daterangepicker', '.daterangepicker_input input', $.proxy(this.showCalendars, this))
- .on('focus.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsFocused, this))
- .on('blur.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsBlurred, this))
- .on('change.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsChanged, this))
- .on('keydown.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsKeydown, this));
this.container.find('.ranges')
+ .on('click.daterangepicker', 'li', $.proxy(this.clickRange, this))
+
+ this.container.find('.drp-buttons')
.on('click.daterangepicker', 'button.applyBtn', $.proxy(this.clickApply, this))
.on('click.daterangepicker', 'button.cancelBtn', $.proxy(this.clickCancel, this))
- .on('click.daterangepicker', 'li', $.proxy(this.clickRange, this))
- .on('mouseenter.daterangepicker', 'li', $.proxy(this.hoverRange, this))
- .on('mouseleave.daterangepicker', 'li', $.proxy(this.updateFormInputs, this));
if (this.element.is('input') || this.element.is('button')) {
this.element.on({
- 'click.daterangepicker': $.proxy(this.show, this),
- 'focus.daterangepicker': $.proxy(this.show, this),
- 'keyup.daterangepicker': $.proxy(this.elementChanged, this),
- 'keydown.daterangepicker': $.proxy(this.keydown, this) //IE 11 compatibility
- });
+ 'click.daterangepicker': $.proxy(this.show, this),
+ 'focus.daterangepicker': $.proxy(this.show, this),
+ 'keyup.daterangepicker': $.proxy(this.elementChanged, this),
+ 'keydown.daterangepicker': $.proxy(this.keydown, this) //IE 11 compatibility
+ });
} else {
this.element.on('click.daterangepicker', $.proxy(this.toggle, this));
this.element.on('keydown.daterangepicker', $.proxy(this.toggle, this));
@@ -450,13 +442,7 @@
// if attached to a text input, set the initial value
//
- 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');
- }
+ this.updateElement();
};
@@ -514,11 +500,13 @@
if (this.maxDate && this.endDate.isAfter(this.maxDate))
this.endDate = this.maxDate.clone();
- if (this.dateLimit && this.startDate.clone().add(this.dateLimit).isBefore(this.endDate))
- this.endDate = this.startDate.clone().add(this.dateLimit);
+ if (this.maxSpan && this.startDate.clone().add(this.maxSpan).isBefore(this.endDate))
+ this.endDate = this.startDate.clone().add(this.maxSpan);
this.previousRightTime = this.endDate.clone();
+ this.container.find('.drp-selected').html(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));
+
if (!this.isShowing)
this.updateElement();
@@ -543,13 +531,8 @@
this.container.find('.right .calendar-time select').removeAttr('disabled').removeClass('disabled');
}
}
- if (this.endDate) {
- this.container.find('input[name="daterangepicker_end"]').removeClass('active');
- this.container.find('input[name="daterangepicker_start"]').addClass('active');
- } else {
- this.container.find('input[name="daterangepicker_end"]').addClass('active');
- this.container.find('input[name="daterangepicker_start"]').removeClass('active');
- }
+ if (this.endDate)
+ this.container.find('.drp-selected').html(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));
this.updateMonthsInView();
this.updateCalendars();
this.updateFormInputs();
@@ -563,7 +546,7 @@
(this.startDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.startDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM'))
&&
(this.endDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.endDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM'))
- ) {
+ ) {
return;
}
@@ -581,8 +564,8 @@
}
}
if (this.maxDate && this.linkedCalendars && !this.singleDatePicker && this.rightCalendar.month > this.maxDate) {
- this.rightCalendar.month = this.maxDate.clone().date(2);
- this.leftCalendar.month = this.maxDate.clone().date(2).subtract(1, 'month');
+ this.rightCalendar.month = this.maxDate.clone().date(2);
+ this.leftCalendar.month = this.maxDate.clone().date(2).subtract(1, 'month');
}
},
@@ -710,7 +693,7 @@
html += '
';
if ((!minDate || minDate.isBefore(calendar.firstDay)) && (!this.linkedCalendars || side == 'left')) {
- html += '
';
+ html += '
';
} else {
html += '
';
}
@@ -720,8 +703,8 @@
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;
@@ -729,12 +712,12 @@
for (var m = 0; m < 12; m++) {
if ((!inMinYear || m >= minDate.month()) && (!inMaxYear || m <= maxDate.month())) {
monthHtml += "";
+ (m === currentMonth ? " selected='selected'" : "") +
+ ">" + this.locale.monthNames[m] + "";
} else {
monthHtml += "";
+ (m === currentMonth ? " selected='selected'" : "") +
+ " disabled='disabled'>" + this.locale.monthNames[m] + "";
}
}
monthHtml += "";
@@ -742,8 +725,8 @@
var yearHtml = '';
@@ -752,7 +735,7 @@
html += '
' + dateHtml + '
';
if ((!maxDate || maxDate.isAfter(calendar.lastDay)) && (!this.linkedCalendars || side == 'right' || this.singleDatePicker)) {
- html += '
';
+ html += '
';
} else {
html += '
';
}
@@ -772,10 +755,10 @@
html += '';
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;
}
@@ -857,7 +840,7 @@
html += '';
html += '';
- this.container.find('.calendar.' + side + ' .calendar-table').html(html);
+ this.container.find('.drp-calendar.' + side + ' .calendar-table').html(html);
},
@@ -869,8 +852,8 @@
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).isAfter(this.maxDate)))
+ maxDate = this.startDate.clone().add(this.maxSpan);
if (side == 'left') {
selected = this.startDate.clone();
@@ -880,12 +863,12 @@
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(selected.hour() || timeSelector.find('.hourselect option:selected').val());
+ selected.minute(selected.minute() || timeSelector.find('.minuteselect option:selected').val());
+ selected.second(selected.second() || timeSelector.find('.secondselect option:selected').val());
if (!this.timePicker24Hour) {
var ampm = timeSelector.find('.ampmselect option:selected').val();
@@ -1018,20 +1001,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 {
@@ -1056,44 +1031,44 @@
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');
+ 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'
- });
+ top: containerTop,
+ right: parentRightEdge - this.element.offset().left - this.element.outerWidth(),
+ left: 'auto'
+ });
if (this.container.offset().left < 0) {
this.container.css({
- right: 'auto',
- left: 9
- });
+ right: 'auto',
+ left: 9
+ });
}
} 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'
- });
+ 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) {
this.container.css({
- right: 'auto',
- left: 9
- });
+ right: 'auto',
+ left: 9
+ });
}
} else {
this.container.css({
- top: containerTop,
- left: this.element.offset().left - parentOffset.left,
- right: 'auto'
- });
+ top: containerTop,
+ left: this.element.offset().left - parentOffset.left,
+ right: 'auto'
+ });
if (this.container.offset().left + this.container.outerWidth() > $(window).width()) {
this.container.css({
- left: 'auto',
- right: 0
- });
+ left: 'auto',
+ right: 0
+ });
}
}
},
@@ -1106,13 +1081,13 @@
// Bind global datepicker mousedown for hiding and
$(document)
- .on('mousedown.daterangepicker', this._outsideClickProxy)
- // also support mobile devices
- .on('touchend.daterangepicker', this._outsideClickProxy)
- // also explicitly play nice with Bootstrap dropdowns, which stopPropagation when clicking them
- .on('click.daterangepicker', '[data-toggle=dropdown]', this._outsideClickProxy)
- // and also close when focus changes to outside the picker (eg. tabbing between controls)
- .on('focusin.daterangepicker', this._outsideClickProxy);
+ .on('mousedown.daterangepicker', this._outsideClickProxy)
+ // also support mobile devices
+ .on('touchend.daterangepicker', this._outsideClickProxy)
+ // also explicitly play nice with Bootstrap dropdowns, which stopPropagation when clicking them
+ .on('click.daterangepicker', '[data-toggle=dropdown]', this._outsideClickProxy)
+ // and also close when focus changes to outside the picker (eg. tabbing between controls)
+ .on('focusin.daterangepicker', this._outsideClickProxy);
// Reposition the picker if the window is resized while it's open
$(window).on('resize.daterangepicker', $.proxy(function(e) { this.move(e); }, this));
@@ -1139,7 +1114,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();
@@ -1165,11 +1140,11 @@
// itself then call this.hide()
if (
// ie modal dialog fix
- e.type == "focusin" ||
- target.closest(this.element).length ||
- target.closest(this.container).length ||
- target.closest('.calendar-table').length
- ) return;
+ e.type == "focusin" ||
+ target.closest(this.element).length ||
+ target.closest(this.container).length ||
+ target.closest('.calendar-table').length
+ ) return;
this.hide();
this.element.trigger('outsideClick.daterangepicker', this);
},
@@ -1185,24 +1160,6 @@
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.getAttribute('data-range-key');
-
- 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.getAttribute('data-range-key');
this.chosenLabel = label;
@@ -1225,7 +1182,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)
@@ -1237,7 +1194,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 {
@@ -1250,32 +1207,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]').is(":focus")) {
- this.container.find('input[name=daterangepicker_start]').val(date.format(this.locale.format));
- } else if (!this.endDate && !this.container.find('input[name=daterangepicker_end]').is(":focus")) {
- 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 tbody 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;
@@ -1283,7 +1229,7 @@
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)) || dt.isSame(date, 'day')) {
@@ -1304,7 +1250,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];
//
@@ -1352,8 +1298,8 @@
}
this.setEndDate(date.clone());
if (this.autoApply) {
- this.calculateChosenLabel();
- this.clickApply();
+ this.calculateChosenLabel();
+ this.clickApply();
}
}
@@ -1374,19 +1320,19 @@
var customRange = true;
var i = 0;
for (var range in this.ranges) {
- if (this.timePicker) {
- var format = this.timePickerSeconds ? "YYYY-MM-DD hh:mm:ss" : "YYYY-MM-DD hh:mm";
+ if (this.timePicker) {
+ 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').html();
+ 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').html();
+ this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').attr('data-range-key');
break;
}
}
@@ -1394,7 +1340,7 @@
}
if (customRange) {
if (this.showCustomRangeLabel) {
- this.chosenLabel = this.container.find('.ranges li:last').addClass('active').html();
+ this.chosenLabel = this.container.find('.ranges li:last').addClass('active').attr('data-range-key');
} else {
this.chosenLabel = null;
}
@@ -1415,9 +1361,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);
@@ -1458,7 +1404,7 @@
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);
@@ -1504,81 +1450,6 @@
},
- 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.updateView();
- },
-
- formInputsFocused: function(e) {
-
- // Highlight the focused input
- this.container.find('input[name="daterangepicker_start"], input[name="daterangepicker_end"]').removeClass('active');
- $(e.target).addClass('active');
-
- // Set the state such that if the user goes back to using a mouse,
- // the calendars are aware we're selecting the end of the range, not
- // the start. This allows someone to edit the end of a date range without
- // re-selecting the beginning, by clicking on the end date input then
- // using the calendar.
- var isRight = $(e.target).closest('.calendar').hasClass('right');
- if (isRight) {
- this.endDate = null;
- this.setStartDate(this.startDate.clone());
- this.updateView();
- }
-
- },
-
- formInputsBlurred: function(e) {
-
- // this function has one purpose right now: if you tab from the first
- // text input to the second in the UI, the endDate is nulled so that
- // you can click another, but if you tab out without clicking anything
- // or changing the input value, the old endDate should be retained
-
- if (!this.endDate) {
- var val = this.container.find('input[name="daterangepicker_end"]').val();
- var end = moment(val, this.locale.format);
- if (end.isValid()) {
- this.setEndDate(end);
- this.updateView();
- }
- }
-
- },
-
- formInputsKeydown: function(e) {
- // This function ensures that if the 'enter' key was pressed in the input, then the calendars
- // are updated with the startDate and endDate.
- // This behaviour is automatic in Chrome/Firefox/Edge but not in IE 11 hence why this exists.
- // Other browsers and versions of IE are untested and the behaviour is unknown.
- if (e.keyCode === 13) {
- // Prevent the calendar from being updated twice on Chrome/Firefox/Edge
- e.preventDefault();
- this.formInputsChanged(e);
- }
- },
-
-
elementChanged: function() {
if (!this.element.is('input')) return;
if (!this.element.val().length) return;
@@ -1620,12 +1491,14 @@
},
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');
+ }
}
},
@@ -1650,4 +1523,4 @@
return DateRangePicker;
-}));
\ No newline at end of file
+}));