Lots of updated libraries.

Signed-off-by: James Cole <thegrumpydictator@gmail.com>
This commit is contained in:
James Cole
2016-09-15 19:14:55 +02:00
parent 7d5bb72b0c
commit 3aad78e6ef
32 changed files with 1240 additions and 558 deletions

View File

@@ -1,38 +1,31 @@
/**
* @version: 2.0.11
* @version: 2.1.24
* @author: Dan Grossman http://www.dangrossman.info/
* @copyright: Copyright (c) 2012-2015 Dan Grossman. All rights reserved.
* @copyright: Copyright (c) 2012-2016 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/
*/
(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 = window.jQuery;
if (jQuery === undefined) {
try {
jQuery = require('jquery');
} catch (err) {
if (!jQuery) throw new Error('jQuery dependency not found');
}
// 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) {
return (root.daterangepicker = 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 = {};
}
module.exports = factory(require('moment'), jQuery);
} else {
// Browser globals
root.daterangepicker = factory(root.moment, root.jQuery);
}
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, function(moment, $) {
var DateRangePicker = function(element, options, cb) {
//default settings for options
@@ -40,7 +33,6 @@
this.element = $(element);
this.startDate = moment().startOf('day');
this.endDate = moment().endOf('day');
this.timeZone = moment().utcOffset();
this.minDate = false;
this.maxDate = false;
this.dateLimit = false;
@@ -48,12 +40,15 @@
this.singleDatePicker = false;
this.showDropdowns = false;
this.showWeekNumbers = false;
this.showISOWeekNumbers = false;
this.showCustomRangeLabel = true;
this.timePicker = false;
this.timePicker24Hour = false;
this.timePickerIncrement = 1;
this.timePickerSeconds = false;
this.linkedCalendars = true;
this.autoUpdateInput = true;
this.alwaysShowCalendars = false;
this.ranges = {};
this.opens = 'right';
@@ -69,6 +64,7 @@
this.cancelClass = 'btn-default';
this.locale = {
direction: 'ltr',
format: 'MM/DD/YYYY',
separator: ' - ',
applyLabel: 'Apply',
@@ -96,11 +92,11 @@
options = $.extend(this.element.data(), options);
//html template for the picker UI
if (typeof options.template !== 'string')
if (typeof options.template !== 'string' && !(options.template instanceof $))
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>' +
@@ -111,7 +107,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>' +
@@ -137,6 +133,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;
@@ -165,6 +164,7 @@
this.locale.customRangeLabel = options.locale.customRangeLabel;
}
this.container.addClass(this.locale.direction);
if (typeof options.startDate === 'string')
this.startDate = moment(options.startDate, this.locale.format);
@@ -216,6 +216,9 @@
if (typeof options.showWeekNumbers === 'boolean')
this.showWeekNumbers = options.showWeekNumbers;
if (typeof options.showISOWeekNumbers === 'boolean')
this.showISOWeekNumbers = options.showISOWeekNumbers;
if (typeof options.buttonClasses === 'string')
this.buttonClasses = options.buttonClasses;
@@ -225,6 +228,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)
@@ -255,6 +261,12 @@
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;
// update day names order to firstDay
if (this.locale.firstDay != 0) {
var iterator = this.locale.firstDay;
@@ -288,19 +300,6 @@
}
}
// bind the time zone used to build the calendar to either the timeZone passed in through the options or the zone of the startDate (which will be the local time zone by default)
if (typeof options.timeZone === 'string' || typeof options.timeZone === 'number') {
if (typeof options.timeZone === 'string' && typeof moment.tz !== 'undefined') {
this.timeZone = moment.tz.zone(options.timeZone).parse(new Date) * -1; // Offset is positive if the timezone is behind UTC and negative if it is ahead.
} else {
this.timeZone = options.timeZone;
}
this.startDate.utcOffset(this.timeZone);
this.endDate.utcOffset(this.timeZone);
} else {
this.timeZone = moment(this.startDate).utcOffset();
}
if (typeof options.ranges === 'object') {
for (range in options.ranges) {
@@ -320,24 +319,32 @@
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;
this.ranges[range] = [start, end];
//Support unicode chars in the range names.
var elem = document.createElement('textarea');
elem.innerHTML = range;
var rangeHtml = elem.value;
this.ranges[rangeHtml] = [start, end];
}
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,13 +374,15 @@
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();
}
}
if (typeof options.ranges === 'undefined' && !this.singleDatePicker) {
if ((typeof options.ranges === 'undefined' && !this.singleDatePicker) || this.alwaysShowCalendars) {
this.container.addClass('show-calendar');
}
@@ -381,10 +390,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,14 +409,15 @@
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('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));
this.container.find('.ranges')
@@ -420,7 +427,7 @@
.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),
@@ -451,7 +458,7 @@
setStartDate: function(startDate) {
if (typeof startDate === 'string')
this.startDate = moment(startDate, this.locale.format).utcOffset(this.timeZone);
this.startDate = moment(startDate, this.locale.format);
if (typeof startDate === 'object')
this.startDate = moment(startDate);
@@ -462,11 +469,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))
if (this.minDate && this.startDate.isBefore(this.minDate)) {
this.startDate = this.minDate;
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))
if (this.maxDate && this.startDate.isAfter(this.maxDate)) {
this.startDate = this.maxDate;
if (this.timePicker && this.timePickerIncrement)
this.startDate.minute(Math.floor(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
}
if (!this.isShowing)
this.updateElement();
@@ -476,7 +489,7 @@
setEndDate: function(endDate) {
if (typeof endDate === 'string')
this.endDate = moment(endDate, this.locale.format).utcOffset(this.timeZone);
this.endDate = moment(endDate, this.locale.format);
if (typeof endDate === 'object')
this.endDate = moment(endDate);
@@ -496,6 +509,8 @@
if (this.dateLimit && this.startDate.clone().add(this.dateLimit).isBefore(this.endDate))
this.endDate = this.startDate.clone().add(this.dateLimit);
this.previousRightTime = this.endDate.clone();
if (!this.isShowing)
this.updateElement();
@@ -506,6 +521,10 @@
return false;
},
isCustomDate: function() {
return false;
},
updateView: function() {
if (this.timePicker) {
this.renderTimePicker('left');
@@ -532,7 +551,7 @@
if (this.endDate) {
//if both dates are visible already, do nothing
if (this.leftCalendar.month && this.rightCalendar.month &&
if (!this.singleDatePicker && this.leftCalendar.month && this.rightCalendar.month &&
(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'))
@@ -546,13 +565,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() {
@@ -575,7 +598,7 @@
minute = parseInt(this.container.find('.right .minuteselect').val(), 10);
second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;
if (!this.timePicker24Hour) {
var ampm = this.container.find('.left .ampmselect').val();
var ampm = this.container.find('.right .ampmselect').val();
if (ampm === 'PM' && hour < 12)
hour += 12;
if (ampm === 'AM' && hour === 12)
@@ -593,30 +616,7 @@
this.container.find('.ranges li').removeClass('active');
if (this.endDate == null) return;
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();
}
this.calculateChosenLabel();
},
renderCalendar: function(side) {
@@ -656,8 +656,7 @@
if (dayOfWeek == this.locale.firstDay)
startDay = daysInLastMonth - 6;
// Possible patch for issue #626 https://github.com/dangrossman/bootstrap-daterangepicker/issues/626
var curDate = moment([lastYear, lastMonth, startDay, 12, minute, second]).utcOffset(this.timeZone); // .utcOffset(this.timeZone);
var curDate = moment([lastYear, lastMonth, startDay, 12, minute, second]);
var col, row;
for (var i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add(24, 'hour')) {
@@ -692,17 +691,18 @@
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>';
html += '<tr>';
// add empty cell for week number
if (this.showWeekNumbers)
if (this.showWeekNumbers || this.showISOWeekNumbers)
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>';
}
@@ -744,7 +744,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>';
}
@@ -753,7 +753,7 @@
html += '<tr>';
// add week number label
if (this.showWeekNumbers)
if (this.showWeekNumbers || this.showISOWeekNumbers)
html += '<th class="week">' + this.locale.weekLabel + '</th>';
$.each(this.locale.daysOfWeek, function(index, dayOfWeek) {
@@ -779,6 +779,8 @@
// add week number
if (this.showWeekNumbers)
html += '<td class="week">' + calendar[row][0].week() + '</td>';
else if (this.showISOWeekNumbers)
html += '<td class="week">' + calendar[row][0].isoWeek() + '</td>';
for (var col = 0; col < 7; col++) {
@@ -820,6 +822,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] + ' ';
@@ -844,6 +855,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)))
@@ -853,8 +868,33 @@
selected = this.startDate.clone();
minDate = this.minDate;
} else if (side == 'right') {
selected = this.endDate ? this.endDate.clone() : this.startDate.clone();
selected = this.endDate.clone();
minDate = this.startDate;
//Preserve the time already selected
var timeSelector = this.container.find('.calendar.right .calendar-time div');
if (!this.endDate && 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());
if (!this.timePicker24Hour) {
var ampm = timeSelector.find('.ampmselect option:selected').val();
if (ampm === 'PM' && selected.hour() < 12)
selected.hour(selected.hour() + 12);
if (ampm === 'AM' && selected.hour() === 12)
selected.hour(0);
}
}
if (selected.isBefore(this.startDate))
selected = this.startDate.clone();
if (maxDate && selected.isAfter(maxDate))
selected = maxDate.clone();
}
//
@@ -1055,6 +1095,7 @@
// Create a click proxy that is private to this instance of datepicker, for unbinding
this._outsideClickProxy = $.proxy(function(e) { this.outsideClick(e); }, this);
// Bind global datepicker mousedown for hiding and
$(document)
.on('mousedown.daterangepicker', this._outsideClickProxy)
@@ -1065,8 +1106,12 @@
// 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));
this.oldStartDate = this.startDate.clone();
this.oldEndDate = this.endDate.clone();
this.previousRightTime = this.endDate.clone();
this.updateView();
this.container.show();
@@ -1092,6 +1137,7 @@
this.updateElement();
$(document).off('.daterangepicker');
$(window).off('.daterangepicker');
this.container.hide();
this.element.trigger('hide.daterangepicker', this);
this.isShowing = false;
@@ -1117,6 +1163,7 @@
target.closest('.calendar-table').length
) return;
this.hide();
this.element.trigger('outsideClick.daterangepicker', this);
},
showCalendars: function() {
@@ -1136,7 +1183,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 {
@@ -1144,11 +1192,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();
@@ -1162,7 +1210,8 @@
this.endDate.endOf('day');
}
this.hideCalendars();
if (!this.alwaysShowCalendars)
this.hideCalendars();
this.clickApply();
}
},
@@ -1194,8 +1243,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;
@@ -1207,9 +1256,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 +1278,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');
@@ -1256,13 +1305,14 @@
// * 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)) {
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) {
var ampm = cal.find('.ampmselect').val();
var ampm = this.container.find('.left .ampmselect').val();
if (ampm === 'PM' && hour < 12)
hour += 12;
if (ampm === 'AM' && hour === 12)
@@ -1274,7 +1324,11 @@
}
this.endDate = null;
this.setStartDate(date.clone());
} else {
} else if (!this.endDate && date.isBefore(this.startDate)) {
//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 { // picking end
if (this.timePicker) {
var hour = parseInt(this.container.find('.right .hourselect').val(), 10);
if (!this.timePicker24Hour) {
@@ -1289,8 +1343,10 @@
date = date.clone().hour(hour).minute(minute).second(second);
}
this.setEndDate(date.clone());
if (this.autoApply)
this.clickApply();
if (this.autoApply) {
this.calculateChosenLabel();
this.clickApply();
}
}
if (this.singleDatePicker) {
@@ -1301,6 +1357,35 @@
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) {
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.showCustomRangeLabel) {
this.chosenLabel = this.container.find('.ranges li:last').addClass('active').html();
this.showCalendars();
}
},
clickApply: function(e) {
@@ -1380,8 +1465,11 @@
start.minute(minute);
start.second(second);
this.setStartDate(start);
if (this.singleDatePicker)
if (this.singleDatePicker) {
this.endDate = this.startDate.clone();
} else if (this.endDate && this.endDate.format('YYYY-MM-DD') == start.format('YYYY-MM-DD') && this.endDate.isBefore(start)) {
this.setEndDate(start.clone());
}
} else if (this.endDate) {
var end = this.endDate.clone();
end.hour(hour);
@@ -1404,8 +1492,8 @@
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).utcOffset(this.timeZone);
var end = moment(this.container.find('input[name="daterangepicker_end"]').val(), this.locale.format).utcOffset(this.timeZone);
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()) {
@@ -1423,31 +1511,68 @@
}
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();
}
}
},
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,
end = null;
if (dateString.length === 2) {
start = moment(dateString[0], this.locale.format).utcOffset(this.timeZone);
end = moment(dateString[1], this.locale.format).utcOffset(this.timeZone);
start = moment(dateString[0], this.locale.format);
end = moment(dateString[1], this.locale.format);
}
if (this.singleDatePicker || start === null || end === null) {
start = moment(this.element.val(), this.locale.format).utcOffset(this.timeZone);
start = moment(this.element.val(), this.locale.format);
end = start;
}
if (!start.isValid() || !end.isValid()) return;
this.setStartDate(start);
this.setEndDate(end);
this.updateView();
@@ -1488,4 +1613,6 @@
return this;
};
}));
return DateRangePicker;
}));