|
@@ -1,39 +1,33 @@
|
|
|
/**
|
|
|
-* @version: 2.1.19
|
|
|
+* @version: 2.1.27
|
|
|
* @author: Dan Grossman http://www.dangrossman.info/
|
|
|
-* @copyright: Copyright (c) 2012-2015 Dan Grossman. All rights reserved.
|
|
|
+* @copyright: Copyright (c) 2012-2017 Dan Grossman. All rights reserved.
|
|
|
* @license: Licensed under the MIT license. See http://www.opensource.org/licenses/mit-license.php
|
|
|
-* @website: https://www.improvely.com/
|
|
|
+* @website: http://www.daterangepicker.com/
|
|
|
*/
|
|
|
-
|
|
|
-(function(root, factory) {
|
|
|
-
|
|
|
- if (typeof define === 'function' && define.amd) {
|
|
|
- define(['moment', 'jquery', 'exports'], function(momentjs, $, exports) {
|
|
|
- root.daterangepicker = factory(root, exports, momentjs, $);
|
|
|
- });
|
|
|
-
|
|
|
- } else if (typeof exports !== 'undefined') {
|
|
|
- var momentjs = require('moment');
|
|
|
- var jQuery = (typeof window != 'undefined') ? window.jQuery : undefined; //isomorphic issue
|
|
|
- if (!jQuery) {
|
|
|
- try {
|
|
|
- jQuery = require('jquery');
|
|
|
- if (!jQuery.fn) jQuery.fn = {}; //isomorphic issue
|
|
|
- } catch (err) {
|
|
|
- if (!jQuery) throw new Error('jQuery dependency not found');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- factory(root, exports, momentjs, jQuery);
|
|
|
-
|
|
|
- // Finally, as a browser global.
|
|
|
- } else {
|
|
|
- root.daterangepicker = factory(root, {}, root.moment || moment, (root.jQuery || root.Zepto || root.ender || root.$));
|
|
|
- }
|
|
|
-
|
|
|
-}(this || {}, function(root, daterangepicker, moment, $) { // 'this' doesn't exist on a server
|
|
|
-
|
|
|
+// Follow the UMD template https://github.com/umdjs/umd/blob/master/templates/returnExportsGlobal.js
|
|
|
+(function (root, factory) {
|
|
|
+ if (typeof define === 'function' && define.amd) {
|
|
|
+ // AMD. Make globaly available as well
|
|
|
+ define(['moment', 'jquery'], function (moment, jquery) {
|
|
|
+ if (!jquery.fn) jquery.fn = {}; // webpack server rendering
|
|
|
+ return factory(moment, jquery);
|
|
|
+ });
|
|
|
+ } else if (typeof module === 'object' && module.exports) {
|
|
|
+ // Node / Browserify
|
|
|
+ //isomorphic issue
|
|
|
+ var jQuery = (typeof window != 'undefined') ? window.jQuery : undefined;
|
|
|
+ if (!jQuery) {
|
|
|
+ jQuery = require('jquery');
|
|
|
+ if (!jQuery.fn) jQuery.fn = {};
|
|
|
+ }
|
|
|
+ var moment = (typeof window != 'undefined' && typeof window.moment != 'undefined') ? window.moment : require('moment');
|
|
|
+ module.exports = factory(moment, jQuery);
|
|
|
+ } else {
|
|
|
+ // Browser globals
|
|
|
+ root.daterangepicker = factory(root.moment, root.jQuery);
|
|
|
+ }
|
|
|
+}(this, function(moment, $) {
|
|
|
var DateRangePicker = function(element, options, cb) {
|
|
|
|
|
|
//default settings for options
|
|
@@ -49,6 +43,7 @@
|
|
|
this.showDropdowns = false;
|
|
|
this.showWeekNumbers = false;
|
|
|
this.showISOWeekNumbers = false;
|
|
|
+ this.showCustomRangeLabel = true;
|
|
|
this.timePicker = false;
|
|
|
this.timePicker24Hour = false;
|
|
|
this.timePickerIncrement = 1;
|
|
@@ -71,7 +66,8 @@
|
|
|
this.cancelClass = 'btn-default';
|
|
|
|
|
|
this.locale = {
|
|
|
- format: 'MM/DD/YYYY',
|
|
|
+ direction: 'ltr',
|
|
|
+ format: moment.localeData().longDateFormat('L'),
|
|
|
separator: ' - ',
|
|
|
applyLabel: 'Apply',
|
|
|
cancelLabel: 'Cancel',
|
|
@@ -102,7 +98,7 @@
|
|
|
options.template = '<div class="daterangepicker dropdown-menu">' +
|
|
|
'<div class="calendar left">' +
|
|
|
'<div class="daterangepicker_input">' +
|
|
|
- '<input class="input-mini" type="text" name="daterangepicker_start" value="" />' +
|
|
|
+ '<input class="input-mini form-control" type="text" name="daterangepicker_start" value="" />' +
|
|
|
'<i class="fa fa-calendar glyphicon glyphicon-calendar"></i>' +
|
|
|
'<div class="calendar-time">' +
|
|
|
'<div></div>' +
|
|
@@ -113,7 +109,7 @@
|
|
|
'</div>' +
|
|
|
'<div class="calendar right">' +
|
|
|
'<div class="daterangepicker_input">' +
|
|
|
- '<input class="input-mini" type="text" name="daterangepicker_end" value="" />' +
|
|
|
+ '<input class="input-mini form-control" type="text" name="daterangepicker_end" value="" />' +
|
|
|
'<i class="fa fa-calendar glyphicon glyphicon-calendar"></i>' +
|
|
|
'<div class="calendar-time">' +
|
|
|
'<div></div>' +
|
|
@@ -139,6 +135,9 @@
|
|
|
|
|
|
if (typeof options.locale === 'object') {
|
|
|
|
|
|
+ if (typeof options.locale.direction === 'string')
|
|
|
+ this.locale.direction = options.locale.direction;
|
|
|
+
|
|
|
if (typeof options.locale.format === 'string')
|
|
|
this.locale.format = options.locale.format;
|
|
|
|
|
@@ -163,10 +162,15 @@
|
|
|
if (typeof options.locale.weekLabel === 'string')
|
|
|
this.locale.weekLabel = options.locale.weekLabel;
|
|
|
|
|
|
- if (typeof options.locale.customRangeLabel === 'string')
|
|
|
- this.locale.customRangeLabel = options.locale.customRangeLabel;
|
|
|
-
|
|
|
+ if (typeof options.locale.customRangeLabel === 'string'){
|
|
|
+ //Support unicode chars in the custom range name.
|
|
|
+ var elem = document.createElement('textarea');
|
|
|
+ elem.innerHTML = options.locale.customRangeLabel;
|
|
|
+ var rangeHtml = elem.value;
|
|
|
+ this.locale.customRangeLabel = rangeHtml;
|
|
|
+ }
|
|
|
}
|
|
|
+ this.container.addClass(this.locale.direction);
|
|
|
|
|
|
if (typeof options.startDate === 'string')
|
|
|
this.startDate = moment(options.startDate, this.locale.format);
|
|
@@ -230,6 +234,9 @@
|
|
|
if (typeof options.showDropdowns === 'boolean')
|
|
|
this.showDropdowns = options.showDropdowns;
|
|
|
|
|
|
+ if (typeof options.showCustomRangeLabel === 'boolean')
|
|
|
+ this.showCustomRangeLabel = options.showCustomRangeLabel;
|
|
|
+
|
|
|
if (typeof options.singleDatePicker === 'boolean') {
|
|
|
this.singleDatePicker = options.singleDatePicker;
|
|
|
if (this.singleDatePicker)
|
|
@@ -260,6 +267,9 @@
|
|
|
if (typeof options.isInvalidDate === 'function')
|
|
|
this.isInvalidDate = options.isInvalidDate;
|
|
|
|
|
|
+ if (typeof options.isCustomDate === 'function')
|
|
|
+ this.isCustomDate = options.isCustomDate;
|
|
|
+
|
|
|
if (typeof options.alwaysShowCalendars === 'boolean')
|
|
|
this.alwaysShowCalendars = options.alwaysShowCalendars;
|
|
|
|
|
@@ -315,16 +325,17 @@
|
|
|
start = this.minDate.clone();
|
|
|
|
|
|
var maxDate = this.maxDate;
|
|
|
- if (this.dateLimit && start.clone().add(this.dateLimit).isAfter(maxDate))
|
|
|
+ if (this.dateLimit && maxDate && start.clone().add(this.dateLimit).isAfter(maxDate))
|
|
|
maxDate = start.clone().add(this.dateLimit);
|
|
|
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)) || (maxDate && start.isAfter(maxDate)))
|
|
|
+ if ((this.minDate && end.isBefore(this.minDate, this.timepicker ? 'minute' : 'day'))
|
|
|
+ || (maxDate && start.isAfter(maxDate, this.timepicker ? 'minute' : 'day')))
|
|
|
continue;
|
|
|
-
|
|
|
+
|
|
|
//Support unicode chars in the range names.
|
|
|
var elem = document.createElement('textarea');
|
|
|
elem.innerHTML = range;
|
|
@@ -335,9 +346,11 @@
|
|
|
|
|
|
var list = '<ul>';
|
|
|
for (range in this.ranges) {
|
|
|
- list += '<li>' + range + '</li>';
|
|
|
+ list += '<li data-range-key="' + range + '">' + range + '</li>';
|
|
|
+ }
|
|
|
+ if (this.showCustomRangeLabel) {
|
|
|
+ list += '<li data-range-key="' + this.locale.customRangeLabel + '">' + this.locale.customRangeLabel + '</li>';
|
|
|
}
|
|
|
- list += '<li>' + this.locale.customRangeLabel + '</li>';
|
|
|
list += '</ul>';
|
|
|
this.container.find('.ranges').prepend(list);
|
|
|
}
|
|
@@ -367,8 +380,10 @@
|
|
|
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('.daterangepicker_input input, .daterangepicker_input > i').hide();
|
|
|
+ if (this.timePicker) {
|
|
|
+ this.container.find('.ranges ul').hide();
|
|
|
+ } else {
|
|
|
this.container.find('.ranges').hide();
|
|
|
}
|
|
|
}
|
|
@@ -381,10 +396,7 @@
|
|
|
|
|
|
//swap the position of the predefined ranges if opens right
|
|
|
if (typeof options.ranges !== 'undefined' && this.opens == 'right') {
|
|
|
- var ranges = this.container.find('.ranges');
|
|
|
- var html = ranges.clone();
|
|
|
- ranges.remove();
|
|
|
- this.container.find('.calendar.left').parent().prepend(html);
|
|
|
+ this.container.find('.ranges').prependTo( this.container.find('.calendar.left').parent() );
|
|
|
}
|
|
|
|
|
|
//apply CSS classes and labels to buttons
|
|
@@ -403,15 +415,17 @@
|
|
|
this.container.find('.calendar')
|
|
|
.on('click.daterangepicker', '.prev', $.proxy(this.clickPrev, this))
|
|
|
.on('click.daterangepicker', '.next', $.proxy(this.clickNext, this))
|
|
|
- .on('click.daterangepicker', 'td.available', $.proxy(this.clickDate, 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('keyup.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsChanged, this))
|
|
|
- .on('change.daterangepicker', '.daterangepicker_input input', $.proxy(this.formInputsChanged, 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', 'button.applyBtn', $.proxy(this.clickApply, this))
|
|
@@ -420,15 +434,16 @@
|
|
|
.on('mouseenter.daterangepicker', 'li', $.proxy(this.hoverRange, this))
|
|
|
.on('mouseleave.daterangepicker', 'li', $.proxy(this.updateFormInputs, this));
|
|
|
|
|
|
- if (this.element.is('input')) {
|
|
|
+ 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)
|
|
|
+ '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));
|
|
|
}
|
|
|
|
|
|
//
|
|
@@ -462,11 +477,17 @@
|
|
|
if (this.timePicker && this.timePickerIncrement)
|
|
|
this.startDate.minute(Math.round(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
|
|
|
|
|
|
- if (this.minDate && this.startDate.isBefore(this.minDate))
|
|
|
- this.startDate = this.minDate;
|
|
|
+ if (this.minDate && this.startDate.isBefore(this.minDate)) {
|
|
|
+ this.startDate = this.minDate.clone();
|
|
|
+ if (this.timePicker && this.timePickerIncrement)
|
|
|
+ this.startDate.minute(Math.round(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
|
|
|
+ }
|
|
|
|
|
|
- if (this.maxDate && this.startDate.isAfter(this.maxDate))
|
|
|
- this.startDate = this.maxDate;
|
|
|
+ if (this.maxDate && this.startDate.isAfter(this.maxDate)) {
|
|
|
+ this.startDate = this.maxDate.clone();
|
|
|
+ if (this.timePicker && this.timePickerIncrement)
|
|
|
+ this.startDate.minute(Math.floor(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
|
|
|
+ }
|
|
|
|
|
|
if (!this.isShowing)
|
|
|
this.updateElement();
|
|
@@ -482,7 +503,7 @@
|
|
|
this.endDate = moment(endDate);
|
|
|
|
|
|
if (!this.timePicker)
|
|
|
- this.endDate = this.endDate.endOf('day');
|
|
|
+ this.endDate = this.endDate.add(1,'d').startOf('day').subtract(1,'second');
|
|
|
|
|
|
if (this.timePicker && this.timePickerIncrement)
|
|
|
this.endDate.minute(Math.round(this.endDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
|
|
@@ -491,7 +512,7 @@
|
|
|
this.endDate = this.startDate.clone();
|
|
|
|
|
|
if (this.maxDate && this.endDate.isAfter(this.maxDate))
|
|
|
- this.endDate = 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);
|
|
@@ -508,6 +529,10 @@
|
|
|
return false;
|
|
|
},
|
|
|
|
|
|
+ isCustomDate: function() {
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+
|
|
|
updateView: function() {
|
|
|
if (this.timePicker) {
|
|
|
this.renderTimePicker('left');
|
|
@@ -548,13 +573,17 @@
|
|
|
} else {
|
|
|
this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
} else {
|
|
|
if (this.leftCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM') && this.rightCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM')) {
|
|
|
this.leftCalendar.month = this.startDate.clone().date(2);
|
|
|
this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month');
|
|
|
}
|
|
|
}
|
|
|
+ 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');
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
updateCalendars: function() {
|
|
@@ -670,6 +699,7 @@
|
|
|
var minDate = side == 'left' ? this.minDate : this.startDate;
|
|
|
var maxDate = this.maxDate;
|
|
|
var selected = side == 'left' ? this.startDate : this.endDate;
|
|
|
+ var arrow = this.locale.direction == 'ltr' ? {left: 'chevron-left', right: 'chevron-right'} : {left: 'chevron-right', right: 'chevron-left'};
|
|
|
|
|
|
var html = '<table class="table-condensed">';
|
|
|
html += '<thead>';
|
|
@@ -680,7 +710,7 @@
|
|
|
html += '<th></th>';
|
|
|
|
|
|
if ((!minDate || minDate.isBefore(calendar.firstDay)) && (!this.linkedCalendars || side == 'left')) {
|
|
|
- html += '<th class="prev available"><i class="fa fa-chevron-left glyphicon glyphicon-chevron-left"></i></th>';
|
|
|
+ html += '<th class="prev available"><i class="fa fa-' + arrow.left + ' glyphicon glyphicon-' + arrow.left + '"></i></th>';
|
|
|
} else {
|
|
|
html += '<th></th>';
|
|
|
}
|
|
@@ -722,7 +752,7 @@
|
|
|
|
|
|
html += '<th colspan="5" class="month">' + dateHtml + '</th>';
|
|
|
if ((!maxDate || maxDate.isAfter(calendar.lastDay)) && (!this.linkedCalendars || side == 'right' || this.singleDatePicker)) {
|
|
|
- html += '<th class="next available"><i class="fa fa-chevron-right glyphicon glyphicon-chevron-right"></i></th>';
|
|
|
+ html += '<th class="next available"><i class="fa fa-' + arrow.right + ' glyphicon glyphicon-' + arrow.right + '"></i></th>';
|
|
|
} else {
|
|
|
html += '<th></th>';
|
|
|
}
|
|
@@ -800,6 +830,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] + ' ';
|
|
@@ -824,6 +863,10 @@
|
|
|
|
|
|
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)))
|
|
@@ -833,7 +876,7 @@
|
|
|
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
|
|
@@ -852,13 +895,14 @@
|
|
|
selected.hour(0);
|
|
|
}
|
|
|
|
|
|
- if (selected.isBefore(this.startDate))
|
|
|
- selected = this.startDate.clone();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (selected.isBefore(this.startDate))
|
|
|
+ selected = this.startDate.clone();
|
|
|
|
|
|
- if (selected.isAfter(maxDate))
|
|
|
- selected = maxDate.clone();
|
|
|
+ if (maxDate && selected.isAfter(maxDate))
|
|
|
+ selected = maxDate.clone();
|
|
|
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
//
|
|
@@ -1127,6 +1171,7 @@
|
|
|
target.closest('.calendar-table').length
|
|
|
) return;
|
|
|
this.hide();
|
|
|
+ this.element.trigger('outsideClick.daterangepicker', this);
|
|
|
},
|
|
|
|
|
|
showCalendars: function() {
|
|
@@ -1146,7 +1191,8 @@
|
|
|
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;
|
|
|
+ var label = e.target.getAttribute('data-range-key');
|
|
|
+
|
|
|
if (label == this.locale.customRangeLabel) {
|
|
|
this.updateView();
|
|
|
} else {
|
|
@@ -1154,11 +1200,11 @@
|
|
|
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();
|
|
@@ -1205,8 +1251,8 @@
|
|
|
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;
|
|
|
+ //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;
|
|
@@ -1218,9 +1264,9 @@
|
|
|
var cal = $(e.target).parents('.calendar');
|
|
|
var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col];
|
|
|
|
|
|
- if (this.endDate) {
|
|
|
+ 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 {
|
|
|
+ } 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));
|
|
|
}
|
|
|
|
|
@@ -1229,7 +1275,7 @@
|
|
|
var rightCalendar = this.rightCalendar;
|
|
|
var startDate = this.startDate;
|
|
|
if (!this.endDate) {
|
|
|
- this.container.find('.calendar td').each(function(index, el) {
|
|
|
+ this.container.find('.calendar tbody td').each(function(index, el) {
|
|
|
|
|
|
//skip week numbers, only look at dates
|
|
|
if ($(el).hasClass('week')) return;
|
|
@@ -1240,7 +1286,7 @@
|
|
|
var cal = $(el).parents('.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');
|
|
@@ -1267,9 +1313,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) {
|
|
@@ -1286,10 +1333,10 @@
|
|
|
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) {
|
|
@@ -1318,32 +1365,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').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) {
|
|
|
+ if (this.showCustomRangeLabel) {
|
|
|
+ this.chosenLabel = this.container.find('.ranges li:last').addClass('active').html();
|
|
|
+ } else {
|
|
|
+ this.chosenLabel = null;
|
|
|
+ }
|
|
|
+ this.showCalendars();
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
clickApply: function(e) {
|
|
@@ -1469,17 +1525,63 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- this.updateCalendars();
|
|
|
- if (this.timePicker) {
|
|
|
- this.renderTimePicker('left');
|
|
|
- this.renderTimePicker('right');
|
|
|
+ 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;
|
|
|
- if (this.element.val().length < this.locale.format.length) return;
|
|
|
|
|
|
var dateString = this.element.val().split(this.locale.separator),
|
|
|
start = null,
|
|
@@ -1507,6 +1609,14 @@
|
|
|
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() {
|
|
@@ -1528,15 +1638,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;
|
|
|
|
|
|
}));
|