|
@@ -1,12 +1,36 @@
|
|
|
/**
|
|
|
-* @version: 1.3.4
|
|
|
+* @version: 1.3.18
|
|
|
* @author: Dan Grossman http://www.dangrossman.info/
|
|
|
-* @date: 2014-03-19
|
|
|
-* @copyright: Copyright (c) 2012-2014 Dan Grossman. All rights reserved.
|
|
|
-* @license: Licensed under Apache License v2.0. See http://www.apache.org/licenses/LICENSE-2.0
|
|
|
-* @website: http://www.improvely.com/
|
|
|
+* @copyright: Copyright (c) 2012-2015 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 ($, moment) {
|
|
|
+
|
|
|
+(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;
|
|
|
+ try {
|
|
|
+ jQuery = require('jquery');
|
|
|
+ } catch (err) {
|
|
|
+ jQuery = window.jQuery;
|
|
|
+ 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, (root.jQuery || root.Zepto || root.ender || root.$));
|
|
|
+ }
|
|
|
+
|
|
|
+}(this, function(root, daterangepicker, moment, $) {
|
|
|
|
|
|
var DateRangePicker = function (element, options, cb) {
|
|
|
|
|
@@ -16,19 +40,22 @@
|
|
|
//element that triggered the date range picker
|
|
|
this.element = $(element);
|
|
|
|
|
|
+ //tracks visible state
|
|
|
+ this.isShowing = false;
|
|
|
+
|
|
|
//create the picker HTML object
|
|
|
var DRPTemplate = '<div class="daterangepicker dropdown-menu">' +
|
|
|
- '<div class="calendar left"></div>' +
|
|
|
- '<div class="calendar right"></div>' +
|
|
|
+ '<div class="calendar first left"></div>' +
|
|
|
+ '<div class="calendar second right"></div>' +
|
|
|
'<div class="ranges">' +
|
|
|
'<div class="range_inputs">' +
|
|
|
'<div class="daterangepicker_start_input">' +
|
|
|
'<label for="daterangepicker_start"></label>' +
|
|
|
- '<input class="input-mini" type="text" name="daterangepicker_start" value="" disabled="disabled" />' +
|
|
|
+ '<input class="input-mini" type="text" name="daterangepicker_start" value="" />' +
|
|
|
'</div>' +
|
|
|
'<div class="daterangepicker_end_input">' +
|
|
|
'<label for="daterangepicker_end"></label>' +
|
|
|
- '<input class="input-mini" type="text" name="daterangepicker_end" value="" disabled="disabled" />' +
|
|
|
+ '<input class="input-mini" type="text" name="daterangepicker_end" value="" />' +
|
|
|
'</div>' +
|
|
|
'<button class="applyBtn" disabled="disabled"></button> ' +
|
|
|
'<button class="cancelBtn"></button>' +
|
|
@@ -40,7 +67,7 @@
|
|
|
if (typeof options !== 'object' || options === null)
|
|
|
options = {};
|
|
|
|
|
|
- this.parentEl = (typeof options === 'object' && options.parentEl && $(options.parentEl).length) || $(this.parentEl);
|
|
|
+ this.parentEl = (typeof options === 'object' && options.parentEl && $(options.parentEl).length) ? $(options.parentEl) : $(this.parentEl);
|
|
|
this.container = $(DRPTemplate).appendTo(this.parentEl);
|
|
|
|
|
|
this.setOptions(options, cb);
|
|
@@ -65,16 +92,18 @@
|
|
|
.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('mouseenter.daterangepicker', 'td.available', $.proxy(this.enterDate, 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.updateMonthYear, this))
|
|
|
.on('change.daterangepicker', 'select.monthselect', $.proxy(this.updateMonthYear, this))
|
|
|
- .on('change.daterangepicker', 'select.hourselect,select.minuteselect,select.ampmselect', $.proxy(this.updateTime, this));
|
|
|
+ .on('change.daterangepicker', 'select.hourselect,select.minuteselect,select.secondselect,select.ampmselect', $.proxy(this.updateTime, this));
|
|
|
|
|
|
this.container.find('.ranges')
|
|
|
.on('click.daterangepicker', 'button.applyBtn', $.proxy(this.clickApply, this))
|
|
|
.on('click.daterangepicker', 'button.cancelBtn', $.proxy(this.clickCancel, this))
|
|
|
.on('click.daterangepicker', '.daterangepicker_start_input,.daterangepicker_end_input', $.proxy(this.showCalendars, this))
|
|
|
+ .on('change.daterangepicker', '.daterangepicker_start_input,.daterangepicker_end_input', $.proxy(this.inputsChanged, this))
|
|
|
+ .on('keydown.daterangepicker', '.daterangepicker_start_input,.daterangepicker_end_input', $.proxy(this.inputsKeydown, this))
|
|
|
.on('click.daterangepicker', 'li', $.proxy(this.clickRange, this))
|
|
|
.on('mouseenter.daterangepicker', 'li', $.proxy(this.enterRange, this))
|
|
|
.on('mouseleave.daterangepicker', 'li', $.proxy(this.updateFormInputs, this));
|
|
@@ -99,6 +128,7 @@
|
|
|
|
|
|
this.startDate = moment().startOf('day');
|
|
|
this.endDate = moment().endOf('day');
|
|
|
+ this.timeZone = moment().utcOffset();
|
|
|
this.minDate = false;
|
|
|
this.maxDate = false;
|
|
|
this.dateLimit = false;
|
|
@@ -106,6 +136,7 @@
|
|
|
this.showDropdowns = false;
|
|
|
this.showWeekNumbers = false;
|
|
|
this.timePicker = false;
|
|
|
+ this.timePickerSeconds = false;
|
|
|
this.timePickerIncrement = 30;
|
|
|
this.timePicker12Hour = true;
|
|
|
this.singleDatePicker = false;
|
|
@@ -115,7 +146,7 @@
|
|
|
if (this.element.hasClass('pull-right'))
|
|
|
this.opens = 'left';
|
|
|
|
|
|
- this.buttonClasses = ['btn', 'btn-small'];
|
|
|
+ this.buttonClasses = ['btn', 'btn-small btn-sm'];
|
|
|
this.applyClass = 'btn-success';
|
|
|
this.cancelClass = 'btn-default';
|
|
|
|
|
@@ -129,9 +160,9 @@
|
|
|
toLabel: 'To',
|
|
|
weekLabel: 'W',
|
|
|
customRangeLabel: 'Custom Range',
|
|
|
- daysOfWeek: moment()._lang._weekdaysMin.slice(),
|
|
|
- monthNames: moment()._lang._monthsShort.slice(),
|
|
|
- firstDay: 0
|
|
|
+ daysOfWeek: moment.weekdaysMin(),
|
|
|
+ monthNames: moment.monthsShort(),
|
|
|
+ firstDay: moment.localeData()._week.dow
|
|
|
};
|
|
|
|
|
|
this.cb = function () { };
|
|
@@ -175,7 +206,6 @@
|
|
|
if (typeof options.dateLimit === 'object')
|
|
|
this.dateLimit = options.dateLimit;
|
|
|
|
|
|
- // update day names order to firstDay
|
|
|
if (typeof options.locale === 'object') {
|
|
|
|
|
|
if (typeof options.locale.daysOfWeek === 'object') {
|
|
@@ -189,12 +219,7 @@
|
|
|
}
|
|
|
|
|
|
if (typeof options.locale.firstDay === 'number') {
|
|
|
- this.locale.firstDay = options.locale.firstDay;
|
|
|
- var iterator = options.locale.firstDay;
|
|
|
- while (iterator > 0) {
|
|
|
- this.locale.daysOfWeek.push(this.locale.daysOfWeek.shift());
|
|
|
- iterator--;
|
|
|
- }
|
|
|
+ this.locale.firstDay = options.locale.firstDay;
|
|
|
}
|
|
|
|
|
|
if (typeof options.locale.applyLabel === 'string') {
|
|
@@ -243,12 +268,19 @@
|
|
|
|
|
|
if (typeof options.singleDatePicker === 'boolean') {
|
|
|
this.singleDatePicker = options.singleDatePicker;
|
|
|
+ if (this.singleDatePicker) {
|
|
|
+ this.endDate = this.startDate.clone();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (typeof options.timePicker === 'boolean') {
|
|
|
this.timePicker = options.timePicker;
|
|
|
}
|
|
|
|
|
|
+ if (typeof options.timePickerSeconds === 'boolean') {
|
|
|
+ this.timePickerSeconds = options.timePickerSeconds;
|
|
|
+ }
|
|
|
+
|
|
|
if (typeof options.timePickerIncrement === 'number') {
|
|
|
this.timePickerIncrement = options.timePickerIncrement;
|
|
|
}
|
|
@@ -257,18 +289,29 @@
|
|
|
this.timePicker12Hour = options.timePicker12Hour;
|
|
|
}
|
|
|
|
|
|
+ // update day names order to firstDay
|
|
|
+ if (this.locale.firstDay != 0) {
|
|
|
+ var iterator = this.locale.firstDay;
|
|
|
+ while (iterator > 0) {
|
|
|
+ this.locale.daysOfWeek.push(this.locale.daysOfWeek.shift());
|
|
|
+ iterator--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
var start, end, range;
|
|
|
|
|
|
//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]')) {
|
|
|
- var val = $(this.element).val();
|
|
|
- var split = val.split(this.separator);
|
|
|
+ var val = $(this.element).val(),
|
|
|
+ split = val.split(this.separator);
|
|
|
+
|
|
|
start = end = null;
|
|
|
+
|
|
|
if (split.length == 2) {
|
|
|
start = moment(split[0], this.format);
|
|
|
end = moment(split[1], this.format);
|
|
|
- } else if (this.singleDatePicker) {
|
|
|
+ } else if (this.singleDatePicker && val !== "") {
|
|
|
start = moment(val, this.format);
|
|
|
end = moment(val, this.format);
|
|
|
}
|
|
@@ -279,11 +322,27 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 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') {
|
|
|
+ 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) {
|
|
|
|
|
|
- start = moment(options.ranges[range][0]);
|
|
|
- end = moment(options.ranges[range][1]);
|
|
|
+ if (typeof options.ranges[range][0] === 'string')
|
|
|
+ start = moment(options.ranges[range][0], this.format);
|
|
|
+ else
|
|
|
+ start = moment(options.ranges[range][0]);
|
|
|
+
|
|
|
+ if (typeof options.ranges[range][1] === 'string')
|
|
|
+ end = moment(options.ranges[range][1], this.format);
|
|
|
+ else
|
|
|
+ end = moment(options.ranges[range][1]);
|
|
|
|
|
|
// If we have a min/max date set, bound this range
|
|
|
// to it, but only if it would otherwise fall
|
|
@@ -325,12 +384,18 @@
|
|
|
|
|
|
if (this.singleDatePicker) {
|
|
|
this.opens = 'right';
|
|
|
+ this.container.addClass('single');
|
|
|
this.container.find('.calendar.right').show();
|
|
|
this.container.find('.calendar.left').hide();
|
|
|
- this.container.find('.ranges').hide();
|
|
|
+ if (!this.timePicker) {
|
|
|
+ this.container.find('.ranges').hide();
|
|
|
+ } else {
|
|
|
+ this.container.find('.ranges .daterangepicker_start_input, .ranges .daterangepicker_end_input').hide();
|
|
|
+ }
|
|
|
if (!this.container.find('.calendar.right').hasClass('single'))
|
|
|
this.container.find('.calendar.right').addClass('single');
|
|
|
} else {
|
|
|
+ this.container.removeClass('single');
|
|
|
this.container.find('.calendar.right').removeClass('single');
|
|
|
this.container.find('.ranges').show();
|
|
|
}
|
|
@@ -340,21 +405,32 @@
|
|
|
this.oldChosenLabel = this.chosenLabel;
|
|
|
|
|
|
this.leftCalendar = {
|
|
|
- month: moment([this.startDate.year(), this.startDate.month(), 1, this.startDate.hour(), this.startDate.minute()]),
|
|
|
+ month: moment([this.startDate.year(), this.startDate.month(), 1, this.startDate.hour(), this.startDate.minute(), this.startDate.second()]),
|
|
|
calendar: []
|
|
|
};
|
|
|
|
|
|
this.rightCalendar = {
|
|
|
- month: moment([this.endDate.year(), this.endDate.month(), 1, this.endDate.hour(), this.endDate.minute()]),
|
|
|
+ month: moment([this.endDate.year(), this.endDate.month(), 1, this.endDate.hour(), this.endDate.minute(), this.endDate.second()]),
|
|
|
calendar: []
|
|
|
};
|
|
|
|
|
|
- if (this.opens == 'right') {
|
|
|
+ if (this.opens == 'right' || this.opens == 'center') {
|
|
|
//swap calendar positions
|
|
|
- var left = this.container.find('.calendar.left');
|
|
|
- var right = this.container.find('.calendar.right');
|
|
|
- left.removeClass('left').addClass('right');
|
|
|
- right.removeClass('right').addClass('left');
|
|
|
+ var first = this.container.find('.calendar.first');
|
|
|
+ var second = this.container.find('.calendar.second');
|
|
|
+
|
|
|
+ if (second.hasClass('single')) {
|
|
|
+ second.removeClass('single');
|
|
|
+ first.addClass('single');
|
|
|
+ }
|
|
|
+
|
|
|
+ first.removeClass('left').addClass('right');
|
|
|
+ second.removeClass('right').addClass('left');
|
|
|
+
|
|
|
+ if (this.singleDatePicker) {
|
|
|
+ first.show();
|
|
|
+ second.hide();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (typeof options.ranges === 'undefined' && !this.singleDatePicker) {
|
|
@@ -370,7 +446,7 @@
|
|
|
|
|
|
setStartDate: function(startDate) {
|
|
|
if (typeof startDate === 'string')
|
|
|
- this.startDate = moment(startDate, this.format);
|
|
|
+ this.startDate = moment(startDate, this.format).utcOffset(this.timeZone);
|
|
|
|
|
|
if (typeof startDate === 'object')
|
|
|
this.startDate = moment(startDate);
|
|
@@ -382,11 +458,12 @@
|
|
|
|
|
|
this.updateView();
|
|
|
this.updateCalendars();
|
|
|
+ this.updateInputText();
|
|
|
},
|
|
|
|
|
|
setEndDate: function(endDate) {
|
|
|
if (typeof endDate === 'string')
|
|
|
- this.endDate = moment(endDate, this.format);
|
|
|
+ this.endDate = moment(endDate, this.format).utcOffset(this.timeZone);
|
|
|
|
|
|
if (typeof endDate === 'object')
|
|
|
this.endDate = moment(endDate);
|
|
@@ -398,11 +475,12 @@
|
|
|
|
|
|
this.updateView();
|
|
|
this.updateCalendars();
|
|
|
+ this.updateInputText();
|
|
|
},
|
|
|
|
|
|
updateView: function () {
|
|
|
- this.leftCalendar.month.month(this.startDate.month()).year(this.startDate.year());
|
|
|
- this.rightCalendar.month.month(this.endDate.month()).year(this.endDate.year());
|
|
|
+ this.leftCalendar.month.month(this.startDate.month()).year(this.startDate.year()).hour(this.startDate.hour()).minute(this.startDate.minute());
|
|
|
+ this.rightCalendar.month.month(this.endDate.month()).year(this.endDate.year()).hour(this.endDate.hour()).minute(this.endDate.minute());
|
|
|
this.updateFormInputs();
|
|
|
},
|
|
|
|
|
@@ -421,12 +499,17 @@
|
|
|
if (!this.element.is('input')) return;
|
|
|
if (!this.element.val().length) return;
|
|
|
|
|
|
- var dateString = this.element.val().split(this.separator);
|
|
|
- var start = moment(dateString[0], this.format);
|
|
|
- var end = moment(dateString[1], this.format);
|
|
|
+ var dateString = this.element.val().split(this.separator),
|
|
|
+ start = null,
|
|
|
+ end = null;
|
|
|
|
|
|
- if (this.singleDatePicker) {
|
|
|
- start = moment(this.element.val(), this.format);
|
|
|
+ if(dateString.length === 2) {
|
|
|
+ start = moment(dateString[0], this.format).utcOffset(this.timeZone);
|
|
|
+ end = moment(dateString[1], this.format).utcOffset(this.timeZone);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.singleDatePicker || start === null || end === null) {
|
|
|
+ start = moment(this.element.val(), this.format).utcOffset(this.timeZone);
|
|
|
end = start;
|
|
|
}
|
|
|
|
|
@@ -451,17 +534,19 @@
|
|
|
|
|
|
move: function () {
|
|
|
var parentOffset = { top: 0, left: 0 };
|
|
|
+ var parentRightEdge = $(window).width();
|
|
|
if (!this.parentEl.is('body')) {
|
|
|
parentOffset = {
|
|
|
top: this.parentEl.offset().top - this.parentEl.scrollTop(),
|
|
|
left: this.parentEl.offset().left - this.parentEl.scrollLeft()
|
|
|
};
|
|
|
+ parentRightEdge = this.parentEl[0].clientWidth + this.parentEl.offset().left;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (this.opens == 'left') {
|
|
|
this.container.css({
|
|
|
top: this.element.offset().top + this.element.outerHeight() - parentOffset.top,
|
|
|
- right: $(window).width() - this.element.offset().left - this.element.outerWidth() - parentOffset.left,
|
|
|
+ right: parentRightEdge - this.element.offset().left - this.element.outerWidth(),
|
|
|
left: 'auto'
|
|
|
});
|
|
|
if (this.container.offset().left < 0) {
|
|
@@ -470,6 +555,19 @@
|
|
|
left: 9
|
|
|
});
|
|
|
}
|
|
|
+ } else if (this.opens == 'center') {
|
|
|
+ this.container.css({
|
|
|
+ top: this.element.offset().top + this.element.outerHeight() - parentOffset.top,
|
|
|
+ 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
|
|
|
+ });
|
|
|
+ }
|
|
|
} else {
|
|
|
this.container.css({
|
|
|
top: this.element.offset().top + this.element.outerHeight() - parentOffset.top,
|
|
@@ -494,14 +592,25 @@
|
|
|
},
|
|
|
|
|
|
show: function (e) {
|
|
|
+ if (this.isShowing) return;
|
|
|
+
|
|
|
this.element.addClass('active');
|
|
|
this.container.show();
|
|
|
this.move();
|
|
|
|
|
|
- $(document).on('click.daterangepicker', $.proxy(this.outsideClick, this));
|
|
|
- // also explicitly play nice with Bootstrap dropdowns, which stopPropagation when clicking them
|
|
|
- $(document).on('click.daterangepicker', '[data-toggle=dropdown]', $.proxy(this.outsideClick, this));
|
|
|
-
|
|
|
+ // 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)
|
|
|
+ // 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);
|
|
|
+
|
|
|
+ this.isShowing = true;
|
|
|
this.element.trigger('show.daterangepicker', this);
|
|
|
},
|
|
|
|
|
@@ -510,14 +619,21 @@
|
|
|
// if the page is clicked anywhere except within the daterangerpicker/button
|
|
|
// 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-date').length
|
|
|
+ target.closest('.calendar-date').length
|
|
|
) return;
|
|
|
this.hide();
|
|
|
},
|
|
|
|
|
|
hide: function (e) {
|
|
|
+ if (!this.isShowing) return;
|
|
|
+
|
|
|
+ $(document)
|
|
|
+ .off('.daterangepicker');
|
|
|
+
|
|
|
this.element.removeClass('active');
|
|
|
this.container.hide();
|
|
|
|
|
@@ -527,7 +643,7 @@
|
|
|
this.oldStartDate = this.startDate.clone();
|
|
|
this.oldEndDate = this.endDate.clone();
|
|
|
|
|
|
- $(document).off('click.daterangepicker', this.outsideClick);
|
|
|
+ this.isShowing = false;
|
|
|
this.element.trigger('hide.daterangepicker', this);
|
|
|
},
|
|
|
|
|
@@ -546,17 +662,43 @@
|
|
|
showCalendars: function() {
|
|
|
this.container.addClass('show-calendar');
|
|
|
this.move();
|
|
|
+ this.element.trigger('showCalendar.daterangepicker', this);
|
|
|
},
|
|
|
|
|
|
hideCalendars: function() {
|
|
|
this.container.removeClass('show-calendar');
|
|
|
+ this.element.trigger('hideCalendar.daterangepicker', this);
|
|
|
+ },
|
|
|
+
|
|
|
+ // when a date is typed into the start to end date textboxes
|
|
|
+ inputsChanged: function (e) {
|
|
|
+ var el = $(e.target);
|
|
|
+ var date = moment(el.val(), this.format);
|
|
|
+ if (!date.isValid()) return;
|
|
|
+
|
|
|
+ var startDate, endDate;
|
|
|
+ if (el.attr('name') === 'daterangepicker_start') {
|
|
|
+ startDate = (false !== this.minDate && date.isBefore(this.minDate)) ? this.minDate : date;
|
|
|
+ endDate = this.endDate;
|
|
|
+ } else {
|
|
|
+ startDate = this.startDate;
|
|
|
+ endDate = (false !== this.maxDate && date.isAfter(this.maxDate)) ? this.maxDate : date;
|
|
|
+ }
|
|
|
+ this.setCustomDates(startDate, endDate);
|
|
|
+ },
|
|
|
+
|
|
|
+ inputsKeydown: function(e) {
|
|
|
+ if (e.keyCode === 13) {
|
|
|
+ this.inputsChanged(e);
|
|
|
+ this.notify();
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
updateInputText: function() {
|
|
|
if (this.element.is('input') && !this.singleDatePicker) {
|
|
|
this.element.val(this.startDate.format(this.format) + this.separator + this.endDate.format(this.format));
|
|
|
} else if (this.element.is('input')) {
|
|
|
- this.element.val(this.startDate.format(this.format));
|
|
|
+ this.element.val(this.endDate.format(this.format));
|
|
|
}
|
|
|
},
|
|
|
|
|
@@ -591,9 +733,9 @@
|
|
|
clickPrev: function (e) {
|
|
|
var cal = $(e.target).parents('.calendar');
|
|
|
if (cal.hasClass('left')) {
|
|
|
- this.leftCalendar.month.subtract('month', 1);
|
|
|
+ this.leftCalendar.month.subtract(1, 'month');
|
|
|
} else {
|
|
|
- this.rightCalendar.month.subtract('month', 1);
|
|
|
+ this.rightCalendar.month.subtract(1, 'month');
|
|
|
}
|
|
|
this.updateCalendars();
|
|
|
},
|
|
@@ -601,15 +743,14 @@
|
|
|
clickNext: function (e) {
|
|
|
var cal = $(e.target).parents('.calendar');
|
|
|
if (cal.hasClass('left')) {
|
|
|
- this.leftCalendar.month.add('month', 1);
|
|
|
+ this.leftCalendar.month.add(1, 'month');
|
|
|
} else {
|
|
|
- this.rightCalendar.month.add('month', 1);
|
|
|
+ this.rightCalendar.month.add(1, 'month');
|
|
|
}
|
|
|
this.updateCalendars();
|
|
|
},
|
|
|
|
|
|
- enterDate: function (e) {
|
|
|
-
|
|
|
+ hoverDate: function (e) {
|
|
|
var title = $(e.target).attr('data-title');
|
|
|
var row = title.substr(1, 1);
|
|
|
var col = title.substr(3, 1);
|
|
@@ -620,7 +761,22 @@
|
|
|
} else {
|
|
|
this.container.find('input[name=daterangepicker_end]').val(this.rightCalendar.calendar[row][col].format(this.format));
|
|
|
}
|
|
|
+ },
|
|
|
|
|
|
+ setCustomDates: function(startDate, endDate) {
|
|
|
+ this.chosenLabel = this.locale.customRangeLabel;
|
|
|
+ if (startDate.isAfter(endDate)) {
|
|
|
+ var difference = this.endDate.diff(this.startDate);
|
|
|
+ endDate = moment(startDate).add(difference, 'ms');
|
|
|
+ if (this.maxDate && endDate.isAfter(this.maxDate)) {
|
|
|
+ endDate = this.maxDate;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.startDate = startDate;
|
|
|
+ this.endDate = endDate;
|
|
|
+
|
|
|
+ this.updateView();
|
|
|
+ this.updateCalendars();
|
|
|
},
|
|
|
|
|
|
clickDate: function (e) {
|
|
@@ -658,26 +814,14 @@
|
|
|
|
|
|
cal.find('td').removeClass('active');
|
|
|
|
|
|
- if (startDate.isSame(endDate) || startDate.isBefore(endDate)) {
|
|
|
- $(e.target).addClass('active');
|
|
|
- this.startDate = startDate;
|
|
|
- this.endDate = endDate;
|
|
|
- this.chosenLabel = this.locale.customRangeLabel;
|
|
|
- } else if (startDate.isAfter(endDate)) {
|
|
|
- $(e.target).addClass('active');
|
|
|
- var difference = this.endDate.diff(this.startDate);
|
|
|
- this.startDate = startDate;
|
|
|
- this.endDate = moment(startDate).add('ms', difference);
|
|
|
- this.chosenLabel = this.locale.customRangeLabel;
|
|
|
- }
|
|
|
+ $(e.target).addClass('active');
|
|
|
|
|
|
- this.leftCalendar.month.month(this.startDate.month()).year(this.startDate.year());
|
|
|
- this.rightCalendar.month.month(this.endDate.month()).year(this.endDate.year());
|
|
|
- this.updateCalendars();
|
|
|
+ this.setCustomDates(startDate, endDate);
|
|
|
|
|
|
- endDate.endOf('day');
|
|
|
+ if (!this.timePicker)
|
|
|
+ endDate.endOf('day');
|
|
|
|
|
|
- if (this.singleDatePicker)
|
|
|
+ if (this.singleDatePicker && !this.timePicker)
|
|
|
this.clickApply();
|
|
|
},
|
|
|
|
|
@@ -706,17 +850,44 @@
|
|
|
var month = parseInt(cal.find('.monthselect').val(), 10);
|
|
|
var year = cal.find('.yearselect').val();
|
|
|
|
|
|
+ if (!isLeft) {
|
|
|
+ if (year < this.startDate.year() || (year == this.startDate.year() && month < this.startDate.month())) {
|
|
|
+ month = this.startDate.month();
|
|
|
+ year = this.startDate.year();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.minDate) {
|
|
|
+ if (year < this.minDate.year() || (year == this.minDate.year() && month < this.minDate.month())) {
|
|
|
+ month = this.minDate.month();
|
|
|
+ year = this.minDate.year();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.maxDate) {
|
|
|
+ if (year > this.maxDate.year() || (year == this.maxDate.year() && month > this.maxDate.month())) {
|
|
|
+ month = this.maxDate.month();
|
|
|
+ year = this.maxDate.year();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
this[leftOrRight+'Calendar'].month.month(month).year(year);
|
|
|
this.updateCalendars();
|
|
|
},
|
|
|
|
|
|
updateTime: function(e) {
|
|
|
- var isLeft = $(e.target).closest('.calendar').hasClass('left'),
|
|
|
- leftOrRight = isLeft ? 'left' : 'right',
|
|
|
- cal = this.container.find('.calendar.'+leftOrRight);
|
|
|
+
|
|
|
+ var cal = $(e.target).closest('.calendar'),
|
|
|
+ isLeft = cal.hasClass('left');
|
|
|
|
|
|
var hour = parseInt(cal.find('.hourselect').val(), 10);
|
|
|
var minute = parseInt(cal.find('.minuteselect').val(), 10);
|
|
|
+ var second = 0;
|
|
|
+
|
|
|
+ if (this.timePickerSeconds) {
|
|
|
+ second = parseInt(cal.find('.secondselect').val(), 10);
|
|
|
+ }
|
|
|
|
|
|
if (this.timePicker12Hour) {
|
|
|
var ampm = cal.find('.ampmselect').val();
|
|
@@ -730,24 +901,31 @@
|
|
|
var start = this.startDate.clone();
|
|
|
start.hour(hour);
|
|
|
start.minute(minute);
|
|
|
+ start.second(second);
|
|
|
this.startDate = start;
|
|
|
- this.leftCalendar.month.hour(hour).minute(minute);
|
|
|
+ this.leftCalendar.month.hour(hour).minute(minute).second(second);
|
|
|
+ if (this.singleDatePicker)
|
|
|
+ this.endDate = start.clone();
|
|
|
} else {
|
|
|
var end = this.endDate.clone();
|
|
|
end.hour(hour);
|
|
|
end.minute(minute);
|
|
|
+ end.second(second);
|
|
|
this.endDate = end;
|
|
|
- this.rightCalendar.month.hour(hour).minute(minute);
|
|
|
+ if (this.singleDatePicker)
|
|
|
+ this.startDate = end.clone();
|
|
|
+ this.rightCalendar.month.hour(hour).minute(minute).second(second);
|
|
|
}
|
|
|
|
|
|
+ this.updateView();
|
|
|
this.updateCalendars();
|
|
|
},
|
|
|
|
|
|
updateCalendars: function () {
|
|
|
- this.leftCalendar.calendar = this.buildCalendar(this.leftCalendar.month.month(), this.leftCalendar.month.year(), this.leftCalendar.month.hour(), this.leftCalendar.month.minute(), 'left');
|
|
|
- this.rightCalendar.calendar = this.buildCalendar(this.rightCalendar.month.month(), this.rightCalendar.month.year(), this.rightCalendar.month.hour(), this.rightCalendar.month.minute(), 'right');
|
|
|
- this.container.find('.calendar.left').html(this.renderCalendar(this.leftCalendar.calendar, this.startDate, this.minDate, this.maxDate));
|
|
|
- this.container.find('.calendar.right').html(this.renderCalendar(this.rightCalendar.calendar, this.endDate, this.startDate, this.maxDate));
|
|
|
+ this.leftCalendar.calendar = this.buildCalendar(this.leftCalendar.month.month(), this.leftCalendar.month.year(), this.leftCalendar.month.hour(), this.leftCalendar.month.minute(), this.leftCalendar.month.second(), 'left');
|
|
|
+ this.rightCalendar.calendar = this.buildCalendar(this.rightCalendar.month.month(), this.rightCalendar.month.year(), this.rightCalendar.month.hour(), this.rightCalendar.month.minute(), this.rightCalendar.month.second(), 'right');
|
|
|
+ this.container.find('.calendar.left').empty().html(this.renderCalendar(this.leftCalendar.calendar, this.startDate, this.minDate, this.maxDate, 'left'));
|
|
|
+ this.container.find('.calendar.right').empty().html(this.renderCalendar(this.rightCalendar.calendar, this.endDate, this.singleDatePicker ? this.minDate : this.startDate, this.maxDate, 'right'));
|
|
|
|
|
|
this.container.find('.ranges li').removeClass('active');
|
|
|
var customRange = true;
|
|
@@ -770,15 +948,17 @@
|
|
|
i++;
|
|
|
}
|
|
|
if (customRange) {
|
|
|
- this.chosenLabel = this.container.find('.ranges li:last')
|
|
|
- .addClass('active').html();
|
|
|
+ this.chosenLabel = this.container.find('.ranges li:last').addClass('active').html();
|
|
|
+ this.showCalendars();
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- buildCalendar: function (month, year, hour, minute, side) {
|
|
|
+ buildCalendar: function (month, year, hour, minute, second, side) {
|
|
|
+ var daysInMonth = moment([year, month]).daysInMonth();
|
|
|
var firstDay = moment([year, month, 1]);
|
|
|
- var lastMonth = moment(firstDay).subtract('month', 1).month();
|
|
|
- var lastYear = moment(firstDay).subtract('month', 1).year();
|
|
|
+ var lastDay = moment([year, month, daysInMonth]);
|
|
|
+ var lastMonth = moment(firstDay).subtract(1, 'month').month();
|
|
|
+ var lastYear = moment(firstDay).subtract(1, 'month').year();
|
|
|
|
|
|
var daysInLastMonth = moment([lastYear, lastMonth]).daysInMonth();
|
|
|
|
|
@@ -788,6 +968,9 @@
|
|
|
|
|
|
//initialize a 6 rows x 7 columns array for the calendar
|
|
|
var calendar = [];
|
|
|
+ calendar.firstDay = firstDay;
|
|
|
+ calendar.lastDay = lastDay;
|
|
|
+
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
calendar[i] = [];
|
|
|
}
|
|
@@ -800,15 +983,25 @@
|
|
|
if (dayOfWeek == this.locale.firstDay)
|
|
|
startDay = daysInLastMonth - 6;
|
|
|
|
|
|
- var curDate = moment([lastYear, lastMonth, startDay, 12, minute]);
|
|
|
+ var curDate = moment([lastYear, lastMonth, startDay, 12, minute, second]).utcOffset(this.timeZone);
|
|
|
+
|
|
|
var col, row;
|
|
|
- for (i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add('hour', 24)) {
|
|
|
+ for (i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add(24, 'hour')) {
|
|
|
if (i > 0 && col % 7 === 0) {
|
|
|
col = 0;
|
|
|
row++;
|
|
|
}
|
|
|
calendar[row][col] = curDate.clone().hour(hour);
|
|
|
curDate.hour(12);
|
|
|
+
|
|
|
+ if (this.minDate && calendar[row][col].format('YYYY-MM-DD') == this.minDate.format('YYYY-MM-DD') && calendar[row][col].isBefore(this.minDate) && side == 'left') {
|
|
|
+ calendar[row][col] = this.minDate.clone();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.maxDate && calendar[row][col].format('YYYY-MM-DD') == this.maxDate.format('YYYY-MM-DD') && calendar[row][col].isAfter(this.maxDate) && side == 'right') {
|
|
|
+ calendar[row][col] = this.maxDate.clone();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return calendar;
|
|
@@ -816,9 +1009,13 @@
|
|
|
|
|
|
renderDropdowns: function (selected, minDate, maxDate) {
|
|
|
var currentMonth = selected.month();
|
|
|
+ var currentYear = selected.year();
|
|
|
+ var maxYear = (maxDate && maxDate.year()) || (currentYear + 5);
|
|
|
+ var minYear = (minDate && minDate.year()) || (currentYear - 50);
|
|
|
+
|
|
|
var monthHtml = '<select class="monthselect">';
|
|
|
- var inMinYear = false;
|
|
|
- var inMaxYear = false;
|
|
|
+ var inMinYear = currentYear == minYear;
|
|
|
+ var inMaxYear = currentYear == maxYear;
|
|
|
|
|
|
for (var m = 0; m < 12; m++) {
|
|
|
if ((!inMinYear || m >= minDate.month()) && (!inMaxYear || m <= maxDate.month())) {
|
|
@@ -829,9 +1026,6 @@
|
|
|
}
|
|
|
monthHtml += "</select>";
|
|
|
|
|
|
- var currentYear = selected.year();
|
|
|
- var maxYear = (maxDate && maxDate.year()) || (currentYear + 5);
|
|
|
- var minYear = (minDate && minDate.year()) || (currentYear - 50);
|
|
|
var yearHtml = '<select class="yearselect">';
|
|
|
|
|
|
for (var y = minYear; y <= maxYear; y++) {
|
|
@@ -845,7 +1039,7 @@
|
|
|
return monthHtml + yearHtml;
|
|
|
},
|
|
|
|
|
|
- renderCalendar: function (calendar, selected, minDate, maxDate) {
|
|
|
+ renderCalendar: function (calendar, selected, minDate, maxDate, side) {
|
|
|
|
|
|
var html = '<div class="calendar-date">';
|
|
|
html += '<table class="table-condensed">';
|
|
@@ -856,8 +1050,8 @@
|
|
|
if (this.showWeekNumbers)
|
|
|
html += '<th></th>';
|
|
|
|
|
|
- if (!minDate || minDate.isBefore(calendar[1][1])) {
|
|
|
- html += '<th class="prev available"><i class="fa fa-arrow-left icon-arrow-left glyphicon glyphicon-arrow-left"></i></th>';
|
|
|
+ if (!minDate || minDate.isBefore(calendar.firstDay)) {
|
|
|
+ html += '<th class="prev available"><i class="fa fa-arrow-left icon icon-arrow-left glyphicon glyphicon-arrow-left"></i></th>';
|
|
|
} else {
|
|
|
html += '<th></th>';
|
|
|
}
|
|
@@ -869,8 +1063,8 @@
|
|
|
}
|
|
|
|
|
|
html += '<th colspan="5" class="month">' + dateHtml + '</th>';
|
|
|
- if (!maxDate || maxDate.isAfter(calendar[1][1])) {
|
|
|
- html += '<th class="next available"><i class="fa fa-arrow-right icon-arrow-right glyphicon glyphicon-arrow-right"></i></th>';
|
|
|
+ if (!maxDate || maxDate.isAfter(calendar.lastDay)) {
|
|
|
+ html += '<th class="next available"><i class="fa fa-arrow-right icon icon-arrow-right glyphicon glyphicon-arrow-right"></i></th>';
|
|
|
} else {
|
|
|
html += '<th></th>';
|
|
|
}
|
|
@@ -901,7 +1095,7 @@
|
|
|
var cname = 'available ';
|
|
|
cname += (calendar[row][col].month() == calendar[1][1].month()) ? '' : 'off';
|
|
|
|
|
|
- if ((minDate && calendar[row][col].isBefore(minDate)) || (maxDate && calendar[row][col].isAfter(maxDate))) {
|
|
|
+ if ((minDate && calendar[row][col].isBefore(minDate, 'day')) || (maxDate && calendar[row][col].isAfter(maxDate, 'day'))) {
|
|
|
cname = ' off disabled ';
|
|
|
} else if (calendar[row][col].format('YYYY-MM-DD') == selected.format('YYYY-MM-DD')) {
|
|
|
cname += ' active ';
|
|
@@ -932,6 +1126,29 @@
|
|
|
|
|
|
html += '<div class="calendar-time">';
|
|
|
html += '<select class="hourselect">';
|
|
|
+
|
|
|
+ // Disallow selections before the minDate or after the maxDate
|
|
|
+ var min_hour = 0;
|
|
|
+ var max_hour = 23;
|
|
|
+
|
|
|
+ if (minDate && (side == 'left' || this.singleDatePicker) && selected.format('YYYY-MM-DD') == minDate.format('YYYY-MM-DD')) {
|
|
|
+ min_hour = minDate.hour();
|
|
|
+ if (selected.hour() < min_hour)
|
|
|
+ selected.hour(min_hour);
|
|
|
+ if (this.timePicker12Hour && min_hour >= 12 && selected.hour() >= 12)
|
|
|
+ min_hour -= 12;
|
|
|
+ if (this.timePicker12Hour && min_hour == 12)
|
|
|
+ min_hour = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (maxDate && (side == 'right' || this.singleDatePicker) && selected.format('YYYY-MM-DD') == maxDate.format('YYYY-MM-DD')) {
|
|
|
+ max_hour = maxDate.hour();
|
|
|
+ if (selected.hour() > max_hour)
|
|
|
+ selected.hour(max_hour);
|
|
|
+ if (this.timePicker12Hour && max_hour >= 12 && selected.hour() >= 12)
|
|
|
+ max_hour -= 12;
|
|
|
+ }
|
|
|
+
|
|
|
var start = 0;
|
|
|
var end = 23;
|
|
|
var selected_hour = selected.hour();
|
|
@@ -945,8 +1162,11 @@
|
|
|
}
|
|
|
|
|
|
for (i = start; i <= end; i++) {
|
|
|
+
|
|
|
if (i == selected_hour) {
|
|
|
html += '<option value="' + i + '" selected="selected">' + i + '</option>';
|
|
|
+ } else if (i < min_hour || i > max_hour) {
|
|
|
+ html += '<option value="' + i + '" disabled="disabled" class="disabled">' + i + '</option>';
|
|
|
} else {
|
|
|
html += '<option value="' + i + '">' + i + '</option>';
|
|
|
}
|
|
@@ -956,12 +1176,30 @@
|
|
|
|
|
|
html += '<select class="minuteselect">';
|
|
|
|
|
|
+ // Disallow selections before the minDate or after the maxDate
|
|
|
+ var min_minute = 0;
|
|
|
+ var max_minute = 59;
|
|
|
+
|
|
|
+ if (minDate && (side == 'left' || this.singleDatePicker) && selected.format('YYYY-MM-DD h A') == minDate.format('YYYY-MM-DD h A')) {
|
|
|
+ min_minute = minDate.minute();
|
|
|
+ if (selected.minute() < min_minute)
|
|
|
+ selected.minute(min_minute);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (maxDate && (side == 'right' || this.singleDatePicker) && selected.format('YYYY-MM-DD h A') == maxDate.format('YYYY-MM-DD h A')) {
|
|
|
+ max_minute = maxDate.minute();
|
|
|
+ if (selected.minute() > max_minute)
|
|
|
+ selected.minute(max_minute);
|
|
|
+ }
|
|
|
+
|
|
|
for (i = 0; i < 60; i += this.timePickerIncrement) {
|
|
|
var num = i;
|
|
|
if (num < 10)
|
|
|
num = '0' + num;
|
|
|
if (i == selected.minute()) {
|
|
|
html += '<option value="' + i + '" selected="selected">' + num + '</option>';
|
|
|
+ } else if (i < min_minute || i > max_minute) {
|
|
|
+ html += '<option value="' + i + '" disabled="disabled" class="disabled">' + num + '</option>';
|
|
|
} else {
|
|
|
html += '<option value="' + i + '">' + num + '</option>';
|
|
|
}
|
|
@@ -969,12 +1207,42 @@
|
|
|
|
|
|
html += '</select> ';
|
|
|
|
|
|
+ if (this.timePickerSeconds) {
|
|
|
+ html += ': <select class="secondselect">';
|
|
|
+
|
|
|
+ for (i = 0; i < 60; i += this.timePickerIncrement) {
|
|
|
+ var num = i;
|
|
|
+ if (num < 10)
|
|
|
+ num = '0' + num;
|
|
|
+ if (i == selected.second()) {
|
|
|
+ html += '<option value="' + i + '" selected="selected">' + num + '</option>';
|
|
|
+ } else {
|
|
|
+ html += '<option value="' + i + '">' + num + '</option>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ html += '</select>';
|
|
|
+ }
|
|
|
+
|
|
|
if (this.timePicker12Hour) {
|
|
|
html += '<select class="ampmselect">';
|
|
|
+
|
|
|
+ // Disallow selection before the minDate or after the maxDate
|
|
|
+ var am_html = '';
|
|
|
+ var pm_html = '';
|
|
|
+
|
|
|
+ if (minDate && (side == 'left' || this.singleDatePicker) && selected.format('YYYY-MM-DD') == minDate.format('YYYY-MM-DD') && minDate.hour() >= 12) {
|
|
|
+ am_html = ' disabled="disabled" class="disabled"';
|
|
|
+ }
|
|
|
+
|
|
|
+ if (maxDate && (side == 'right' || this.singleDatePicker) && selected.format('YYYY-MM-DD') == maxDate.format('YYYY-MM-DD') && maxDate.hour() < 12) {
|
|
|
+ pm_html = ' disabled="disabled" class="disabled"';
|
|
|
+ }
|
|
|
+
|
|
|
if (selected.hour() >= 12) {
|
|
|
- html += '<option value="AM">AM</option><option value="PM" selected="selected">PM</option>';
|
|
|
+ html += '<option value="AM"' + am_html + '>AM</option><option value="PM" selected="selected"' + pm_html + '>PM</option>';
|
|
|
} else {
|
|
|
- html += '<option value="AM" selected="selected">AM</option><option value="PM">PM</option>';
|
|
|
+ html += '<option value="AM" selected="selected"' + am_html + '>AM</option><option value="PM"' + pm_html + '>PM</option>';
|
|
|
}
|
|
|
html += '</select>';
|
|
|
}
|
|
@@ -1007,4 +1275,4 @@
|
|
|
return this;
|
|
|
};
|
|
|
|
|
|
-}(window.jQuery, window.moment);
|
|
|
+}));
|