Commit 9c19afa5 authored by Paul Brown's avatar Paul Brown

update bootstrap daterangepicker to 1.3.22

parent f176ee6c
/*! /*!
* Stylesheet for the Date Range Picker, for use with Bootstrap 2.x * Stylesheet for the Date Range Picker, for use with Bootstrap 2.x
* *
* Copyright 2013 Dan Grossman ( http://www.dangrossman.info ) * Copyright 2013-2015 Dan Grossman ( http://www.dangrossman.info )
* Licensed under the Apache License v2.0 * Licensed under the MIT license. See http://www.opensource.org/licenses/mit-license.php
* http://www.apache.org/licenses/LICENSE-2.0
* *
* Built for http://www.improvely.com * Built for http://www.improvely.com
*/ */
...@@ -144,7 +143,7 @@ ...@@ -144,7 +143,7 @@
.daterangepicker.openscenter:before { .daterangepicker.openscenter:before {
position: absolute; position: absolute;
top: -7px; top: -7px;
left: 0; left: 0;
right: 0; right: 0;
width: 0; width: 0;
margin-left: auto; margin-left: auto;
...@@ -160,8 +159,8 @@ ...@@ -160,8 +159,8 @@
.daterangepicker.openscenter:after { .daterangepicker.openscenter:after {
position: absolute; position: absolute;
top: -6px; top: -6px;
left: 0; left: 0;
right: 0; right: 0;
width: 0; width: 0;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
...@@ -195,6 +194,22 @@ ...@@ -195,6 +194,22 @@
content: ''; content: '';
} }
.daterangepicker.dropup{
margin-top: -5px;
}
.daterangepicker.dropup:before{
top: initial;
bottom:-7px;
border-bottom: initial;
border-top: 7px solid #ccc;
}
.daterangepicker.dropup:after{
top: initial;
bottom:-6px;
border-bottom: initial;
border-top: 6px solid #fff;
}
.daterangepicker table { .daterangepicker table {
width: 100%; width: 100%;
margin: 0; margin: 0;
...@@ -219,7 +234,7 @@ ...@@ -219,7 +234,7 @@
color: #999; color: #999;
} }
.daterangepicker td.available:hover, .daterangepicker th.available:hover { .daterangepicker td.available:hover, .daterangepicker td.available.today, .daterangepicker th.available:hover {
background: #eee; background: #eee;
} }
...@@ -230,7 +245,7 @@ ...@@ -230,7 +245,7 @@
border-radius: 0; border-radius: 0;
} }
.daterangepicker td.active, .daterangepicker td.active:hover { .daterangepicker td.today.active, .daterangepicker td.active, .daterangepicker td.active:hover {
background-color: #006dcc; background-color: #006dcc;
background-image: -moz-linear-gradient(top, #0088cc, #0044cc); background-image: -moz-linear-gradient(top, #0088cc, #0044cc);
background-image: -ms-linear-gradient(top, #0088cc, #0044cc); background-image: -ms-linear-gradient(top, #0088cc, #0044cc);
...@@ -269,7 +284,7 @@ ...@@ -269,7 +284,7 @@
width: 40%; width: 40%;
} }
.daterangepicker select.hourselect, .daterangepicker select.minuteselect, .daterangepicker select.ampmselect { .daterangepicker select.hourselect, .daterangepicker select.minuteselect, .daterangepicker select.secondselect, .daterangepicker select.ampmselect {
width: 60px; width: 60px;
margin-bottom: 0; margin-bottom: 0;
} }
...@@ -279,7 +294,7 @@ ...@@ -279,7 +294,7 @@
} }
.daterangepicker_end_input { .daterangepicker_end_input {
float: left; float: left;
padding-left: 11px padding-left: 11px
} }
......
/*! /*!
* Stylesheet for the Date Range Picker, for use with Bootstrap 3.x * Stylesheet for the Date Range Picker, for use with Bootstrap 3.x
* *
* Copyright 2013 Dan Grossman ( http://www.dangrossman.info ) * Copyright 2013-2015 Dan Grossman ( http://www.dangrossman.info )
* Licensed under the Apache License v2.0 * Licensed under the MIT license. See http://www.opensource.org/licenses/mit-license.php
* http://www.apache.org/licenses/LICENSE-2.0
* *
* Built for http://www.improvely.com * Built for http://www.improvely.com
*/ */
...@@ -169,7 +168,7 @@ ...@@ -169,7 +168,7 @@
.daterangepicker.openscenter:before { .daterangepicker.openscenter:before {
position: absolute; position: absolute;
top: -7px; top: -7px;
left: 0; left: 0;
right: 0; right: 0;
width: 0; width: 0;
margin-left: auto; margin-left: auto;
...@@ -185,8 +184,8 @@ ...@@ -185,8 +184,8 @@
.daterangepicker.openscenter:after { .daterangepicker.openscenter:after {
position: absolute; position: absolute;
top: -6px; top: -6px;
left: 0; left: 0;
right: 0; right: 0;
width: 0; width: 0;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
...@@ -220,6 +219,22 @@ ...@@ -220,6 +219,22 @@
content: ''; content: '';
} }
.daterangepicker.dropup{
margin-top: -5px;
}
.daterangepicker.dropup:before{
top: initial;
bottom:-7px;
border-bottom: initial;
border-top: 7px solid #ccc;
}
.daterangepicker.dropup:after{
top: initial;
bottom:-6px;
border-bottom: initial;
border-top: 6px solid #fff;
}
.daterangepicker table { .daterangepicker table {
width: 100%; width: 100%;
margin: 0; margin: 0;
...@@ -244,7 +259,7 @@ ...@@ -244,7 +259,7 @@
color: #999; color: #999;
} }
.daterangepicker td.available:hover, .daterangepicker th.available:hover { .daterangepicker td.available:hover, .daterangepicker td.available.today, .daterangepicker th.available:hover {
background: #eee; background: #eee;
} }
...@@ -273,7 +288,7 @@ ...@@ -273,7 +288,7 @@
border-radius: 4px; border-radius: 4px;
} }
.daterangepicker td.active, .daterangepicker td.active:hover { .daterangepicker td.today.active, .daterangepicker td.active, .daterangepicker td.active:hover {
background-color: #357ebd; background-color: #357ebd;
border-color: #3071a9; border-color: #3071a9;
color: #fff; color: #fff;
...@@ -301,7 +316,7 @@ ...@@ -301,7 +316,7 @@
width: 40%; width: 40%;
} }
.daterangepicker select.hourselect, .daterangepicker select.minuteselect, .daterangepicker select.ampmselect { .daterangepicker select.hourselect, .daterangepicker select.minuteselect, .daterangepicker select.secondselect, .daterangepicker select.ampmselect {
width: 50px; width: 50px;
margin-bottom: 0; margin-bottom: 0;
} }
...@@ -311,7 +326,7 @@ ...@@ -311,7 +326,7 @@
} }
.daterangepicker_end_input { .daterangepicker_end_input {
float: left; float: left;
padding-left: 11px padding-left: 11px
} }
......
/** /**
* @version: 1.3.15 * @version: 1.3.22
* @author: Dan Grossman http://www.dangrossman.info/ * @author: Dan Grossman http://www.dangrossman.info/
* @date: 2014-10-20 * @copyright: Copyright (c) 2012-2015 Dan Grossman. All rights reserved.
* @copyright: Copyright (c) 2012-2014 Dan Grossman. All rights reserved. * @license: Licensed under the MIT license. See http://www.opensource.org/licenses/mit-license.php
* @license: Licensed under Apache License v2.0. See http://www.apache.org/licenses/LICENSE-2.0 * @website: https://www.improvely.com/
* @website: http://www.improvely.com/
*/ */
(function(root, factory) { (function(root, factory) {
...@@ -28,7 +27,7 @@ ...@@ -28,7 +27,7 @@
// Finally, as a browser global. // Finally, as a browser global.
} else { } else {
root.daterangepicker = factory(root, {}, root.moment, (root.jQuery || root.Zepto || root.ender || root.$)); root.daterangepicker = factory(root, {}, root.moment || moment, (root.jQuery || root.Zepto || root.ender || root.$));
} }
}(this, function(root, daterangepicker, moment, $) { }(this, function(root, daterangepicker, moment, $) {
...@@ -46,8 +45,8 @@ ...@@ -46,8 +45,8 @@
//create the picker HTML object //create the picker HTML object
var DRPTemplate = '<div class="daterangepicker dropdown-menu">' + var DRPTemplate = '<div class="daterangepicker dropdown-menu">' +
'<div class="calendar left"></div>' + '<div class="calendar first left"></div>' +
'<div class="calendar right"></div>' + '<div class="calendar second right"></div>' +
'<div class="ranges">' + '<div class="ranges">' +
'<div class="range_inputs">' + '<div class="range_inputs">' +
'<div class="daterangepicker_start_input">' + '<div class="daterangepicker_start_input">' +
...@@ -58,8 +57,8 @@ ...@@ -58,8 +57,8 @@
'<label for="daterangepicker_end"></label>' + '<label for="daterangepicker_end"></label>' +
'<input class="input-mini" type="text" name="daterangepicker_end" value="" />' + '<input class="input-mini" type="text" name="daterangepicker_end" value="" />' +
'</div>' + '</div>' +
'<button class="applyBtn" disabled="disabled"></button>&nbsp;' + '<button class="applyBtn" disabled="disabled" type="button"></button>&nbsp;' +
'<button class="cancelBtn"></button>' + '<button class="cancelBtn" type="button"></button>' +
'</div>' + '</div>' +
'</div>' + '</div>' +
'</div>'; '</div>';
...@@ -71,24 +70,13 @@ ...@@ -71,24 +70,13 @@
this.parentEl = (typeof options === 'object' && options.parentEl && $(options.parentEl).length) ? $(options.parentEl) : $(this.parentEl); this.parentEl = (typeof options === 'object' && options.parentEl && $(options.parentEl).length) ? $(options.parentEl) : $(this.parentEl);
this.container = $(DRPTemplate).appendTo(this.parentEl); this.container = $(DRPTemplate).appendTo(this.parentEl);
//allow setting options with data attributes
//data-api options will be overwritten with custom javascript options
options = $.extend(this.element.data(), options);
this.setOptions(options, cb); this.setOptions(options, cb);
//apply CSS classes and labels to buttons
var c = this.container;
$.each(this.buttonClasses, function (idx, val) {
c.find('button').addClass(val);
});
this.container.find('.daterangepicker_start_input label').html(this.locale.fromLabel);
this.container.find('.daterangepicker_end_input label').html(this.locale.toLabel);
if (this.applyClass.length)
this.container.find('.applyBtn').addClass(this.applyClass);
if (this.cancelClass.length)
this.container.find('.cancelBtn').addClass(this.cancelClass);
this.container.find('.applyBtn').html(this.locale.applyLabel);
this.container.find('.cancelBtn').html(this.locale.cancelLabel);
//event listeners //event listeners
this.container.find('.calendar') this.container.find('.calendar')
.on('click.daterangepicker', '.prev', $.proxy(this.clickPrev, this)) .on('click.daterangepicker', '.prev', $.proxy(this.clickPrev, this))
.on('click.daterangepicker', '.next', $.proxy(this.clickNext, this)) .on('click.daterangepicker', '.next', $.proxy(this.clickNext, this))
...@@ -97,7 +85,7 @@ ...@@ -97,7 +85,7 @@
.on('mouseleave.daterangepicker', 'td.available', $.proxy(this.updateFormInputs, this)) .on('mouseleave.daterangepicker', 'td.available', $.proxy(this.updateFormInputs, this))
.on('change.daterangepicker', 'select.yearselect', $.proxy(this.updateMonthYear, this)) .on('change.daterangepicker', 'select.yearselect', $.proxy(this.updateMonthYear, this))
.on('change.daterangepicker', 'select.monthselect', $.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') this.container.find('.ranges')
.on('click.daterangepicker', 'button.applyBtn', $.proxy(this.clickApply, this)) .on('click.daterangepicker', 'button.applyBtn', $.proxy(this.clickApply, this))
...@@ -113,7 +101,8 @@ ...@@ -113,7 +101,8 @@
this.element.on({ this.element.on({
'click.daterangepicker': $.proxy(this.show, this), 'click.daterangepicker': $.proxy(this.show, this),
'focus.daterangepicker': $.proxy(this.show, this), 'focus.daterangepicker': $.proxy(this.show, this),
'keyup.daterangepicker': $.proxy(this.updateFromControl, this) 'keyup.daterangepicker': $.proxy(this.updateFromControl, this),
'keydown.daterangepicker': $.proxy(this.keydown, this)
}); });
} else { } else {
this.element.on('click.daterangepicker', $.proxy(this.toggle, this)); this.element.on('click.daterangepicker', $.proxy(this.toggle, this));
...@@ -129,6 +118,7 @@ ...@@ -129,6 +118,7 @@
this.startDate = moment().startOf('day'); this.startDate = moment().startOf('day');
this.endDate = moment().endOf('day'); this.endDate = moment().endOf('day');
this.timeZone = moment().utcOffset();
this.minDate = false; this.minDate = false;
this.maxDate = false; this.maxDate = false;
this.dateLimit = false; this.dateLimit = false;
...@@ -136,8 +126,10 @@ ...@@ -136,8 +126,10 @@
this.showDropdowns = false; this.showDropdowns = false;
this.showWeekNumbers = false; this.showWeekNumbers = false;
this.timePicker = false; this.timePicker = false;
this.timePickerSeconds = false;
this.timePickerIncrement = 30; this.timePickerIncrement = 30;
this.timePicker12Hour = true; this.timePicker12Hour = true;
this.autoApply = false;
this.singleDatePicker = false; this.singleDatePicker = false;
this.ranges = {}; this.ranges = {};
...@@ -145,6 +137,10 @@ ...@@ -145,6 +137,10 @@
if (this.element.hasClass('pull-right')) if (this.element.hasClass('pull-right'))
this.opens = 'left'; this.opens = 'left';
this.drops = 'down';
if (this.element.hasClass('dropup'))
this.drops = 'up';
this.buttonClasses = ['btn', 'btn-small btn-sm']; this.buttonClasses = ['btn', 'btn-small btn-sm'];
this.applyClass = 'btn-success'; this.applyClass = 'btn-success';
this.cancelClass = 'btn-default'; this.cancelClass = 'btn-default';
...@@ -249,6 +245,9 @@ ...@@ -249,6 +245,9 @@
if (typeof options.opens === 'string') if (typeof options.opens === 'string')
this.opens = options.opens; this.opens = options.opens;
if (typeof options.drops === 'string')
this.drops = options.drops;
if (typeof options.showWeekNumbers === 'boolean') { if (typeof options.showWeekNumbers === 'boolean') {
this.showWeekNumbers = options.showWeekNumbers; this.showWeekNumbers = options.showWeekNumbers;
} }
...@@ -276,6 +275,10 @@ ...@@ -276,6 +275,10 @@
this.timePicker = options.timePicker; this.timePicker = options.timePicker;
} }
if (typeof options.timePickerSeconds === 'boolean') {
this.timePickerSeconds = options.timePickerSeconds;
}
if (typeof options.timePickerIncrement === 'number') { if (typeof options.timePickerIncrement === 'number') {
this.timePickerIncrement = options.timePickerIncrement; this.timePickerIncrement = options.timePickerIncrement;
} }
...@@ -284,6 +287,12 @@ ...@@ -284,6 +287,12 @@
this.timePicker12Hour = options.timePicker12Hour; this.timePicker12Hour = options.timePicker12Hour;
} }
if (typeof options.autoApply === 'boolean') {
this.autoApply = options.autoApply;
if (this.autoApply)
this.container.find('.applyBtn, .cancelBtn').addClass('hide');
}
// update day names order to firstDay // update day names order to firstDay
if (this.locale.firstDay != 0) { if (this.locale.firstDay != 0) {
var iterator = this.locale.firstDay; var iterator = this.locale.firstDay;
...@@ -298,11 +307,11 @@ ...@@ -298,11 +307,11 @@
//if no start/end dates set, check if an input element contains initial values //if no start/end dates set, check if an input element contains initial values
if (typeof options.startDate === 'undefined' && typeof options.endDate === 'undefined') { if (typeof options.startDate === 'undefined' && typeof options.endDate === 'undefined') {
if ($(this.element).is('input[type=text]')) { if ($(this.element).is('input[type=text]')) {
var val = $(this.element).val(), var val = $(this.element).val(),
split = val.split(this.separator); split = val.split(this.separator);
start = end = null; start = end = null;
if (split.length == 2) { if (split.length == 2) {
start = moment(split[0], this.format); start = moment(split[0], this.format);
end = moment(split[1], this.format); end = moment(split[1], this.format);
...@@ -317,6 +326,19 @@ ...@@ -317,6 +326,19 @@
} }
} }
// 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') { if (typeof options.ranges === 'object') {
for (range in options.ranges) { for (range in options.ranges) {
...@@ -369,7 +391,7 @@ ...@@ -369,7 +391,7 @@
} }
if (this.singleDatePicker) { if (this.singleDatePicker) {
this.opens = 'right'; this.opens = this.opens || 'right';
this.container.addClass('single'); this.container.addClass('single');
this.container.find('.calendar.right').show(); this.container.find('.calendar.right').show();
this.container.find('.calendar.left').hide(); this.container.find('.calendar.left').hide();
...@@ -383,6 +405,7 @@ ...@@ -383,6 +405,7 @@
} else { } else {
this.container.removeClass('single'); this.container.removeClass('single');
this.container.find('.calendar.right').removeClass('single'); this.container.find('.calendar.right').removeClass('single');
this.container.find('.calendar.left').show();
this.container.find('.ranges').show(); this.container.find('.ranges').show();
} }
...@@ -391,31 +414,31 @@ ...@@ -391,31 +414,31 @@
this.oldChosenLabel = this.chosenLabel; this.oldChosenLabel = this.chosenLabel;
this.leftCalendar = { 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: [] calendar: []
}; };
this.rightCalendar = { 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: [] calendar: []
}; };
if (this.opens == 'right' || this.opens == 'center') { if (this.opens == 'right' || this.opens == 'center') {
//swap calendar positions //swap calendar positions
var left = this.container.find('.calendar.left'); var first = this.container.find('.calendar.first');
var right = this.container.find('.calendar.right'); var second = this.container.find('.calendar.second');
if (right.hasClass('single')) { if (second.hasClass('single')) {
right.removeClass('single'); second.removeClass('single');
left.addClass('single'); first.addClass('single');
} }
left.removeClass('left').addClass('right'); first.removeClass('left').addClass('right');
right.removeClass('right').addClass('left'); second.removeClass('right').addClass('left');
if (this.singleDatePicker) { if (this.singleDatePicker) {
left.show(); first.show();
right.hide(); second.hide();
} }
} }
...@@ -423,16 +446,29 @@ ...@@ -423,16 +446,29 @@
this.container.addClass('show-calendar'); this.container.addClass('show-calendar');
} }
this.container.addClass('opens' + this.opens); this.container.removeClass('opensleft opensright').addClass('opens' + this.opens);
this.updateView(); this.updateView();
this.updateCalendars(); this.updateCalendars();
//apply CSS classes and labels to buttons
var c = this.container;
$.each(this.buttonClasses, function (idx, val) {
c.find('button').addClass(val);
});
this.container.find('.daterangepicker_start_input label').html(this.locale.fromLabel);
this.container.find('.daterangepicker_end_input label').html(this.locale.toLabel);
if (this.applyClass.length)
this.container.find('.applyBtn').addClass(this.applyClass);
if (this.cancelClass.length)
this.container.find('.cancelBtn').addClass(this.cancelClass);
this.container.find('.applyBtn').html(this.locale.applyLabel);
this.container.find('.cancelBtn').html(this.locale.cancelLabel);
}, },
setStartDate: function(startDate) { setStartDate: function(startDate) {
if (typeof startDate === 'string') if (typeof startDate === 'string')
this.startDate = moment(startDate, this.format); this.startDate = moment(startDate, this.format).utcOffset(this.timeZone);
if (typeof startDate === 'object') if (typeof startDate === 'object')
this.startDate = moment(startDate); this.startDate = moment(startDate);
...@@ -449,7 +485,7 @@ ...@@ -449,7 +485,7 @@
setEndDate: function(endDate) { setEndDate: function(endDate) {
if (typeof endDate === 'string') if (typeof endDate === 'string')
this.endDate = moment(endDate, this.format); this.endDate = moment(endDate, this.format).utcOffset(this.timeZone);
if (typeof endDate === 'object') if (typeof endDate === 'object')
this.endDate = moment(endDate); this.endDate = moment(endDate);
...@@ -490,12 +526,12 @@ ...@@ -490,12 +526,12 @@
end = null; end = null;
if(dateString.length === 2) { if(dateString.length === 2) {
start = moment(dateString[0], this.format); start = moment(dateString[0], this.format).utcOffset(this.timeZone);
end = moment(dateString[1], this.format); end = moment(dateString[1], this.format).utcOffset(this.timeZone);
} }
if (this.singleDatePicker || start === null || end === null) { if (this.singleDatePicker || start === null || end === null) {
start = moment(this.element.val(), this.format); start = moment(this.element.val(), this.format).utcOffset(this.timeZone);
end = start; end = start;
} }
...@@ -512,14 +548,23 @@ ...@@ -512,14 +548,23 @@
this.updateCalendars(); this.updateCalendars();
}, },
keydown: function (e) {
//hide on tab or enter
if ((e.keyCode === 9) || (e.keyCode === 13)) {
this.hide();
}
},
notify: function () { notify: function () {
this.updateView(); this.updateView();
this.updateInputText();
this.cb(this.startDate, this.endDate, this.chosenLabel); this.cb(this.startDate, this.endDate, this.chosenLabel);
}, },
move: function () { move: function () {
var parentOffset = { top: 0, left: 0 }; var parentOffset = { top: 0, left: 0 },
containerTop;
var parentRightEdge = $(window).width(); var parentRightEdge = $(window).width();
if (!this.parentEl.is('body')) { if (!this.parentEl.is('body')) {
parentOffset = { parentOffset = {
...@@ -528,10 +573,16 @@ ...@@ -528,10 +573,16 @@
}; };
parentRightEdge = this.parentEl[0].clientWidth + this.parentEl.offset().left; parentRightEdge = this.parentEl[0].clientWidth + this.parentEl.offset().left;
} }
if (this.drops == 'up')
containerTop = this.element.offset().top - this.container.outerHeight() - parentOffset.top;
else
containerTop = this.element.offset().top + this.element.outerHeight() - parentOffset.top;
this.container[this.drops == 'up' ? 'addClass' : 'removeClass']('dropup');
if (this.opens == 'left') { if (this.opens == 'left') {
this.container.css({ this.container.css({
top: this.element.offset().top + this.element.outerHeight() - parentOffset.top, top: containerTop,
right: parentRightEdge - this.element.offset().left - this.element.outerWidth(), right: parentRightEdge - this.element.offset().left - this.element.outerWidth(),
left: 'auto' left: 'auto'
}); });
...@@ -543,7 +594,7 @@ ...@@ -543,7 +594,7 @@
} }
} else if (this.opens == 'center') { } else if (this.opens == 'center') {
this.container.css({ this.container.css({
top: this.element.offset().top + this.element.outerHeight() - parentOffset.top, top: containerTop,
left: this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2 left: this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2
- this.container.outerWidth() / 2, - this.container.outerWidth() / 2,
right: 'auto' right: 'auto'
...@@ -556,7 +607,7 @@ ...@@ -556,7 +607,7 @@
} }
} else { } else {
this.container.css({ this.container.css({
top: this.element.offset().top + this.element.outerHeight() - parentOffset.top, top: containerTop,
left: this.element.offset().left - parentOffset.left, left: this.element.offset().left - parentOffset.left,
right: 'auto' right: 'auto'
}); });
...@@ -589,6 +640,8 @@ ...@@ -589,6 +640,8 @@
// Bind global datepicker mousedown for hiding and // Bind global datepicker mousedown for hiding and
$(document) $(document)
.on('mousedown.daterangepicker', this._outsideClickProxy) .on('mousedown.daterangepicker', this._outsideClickProxy)
// also support mobile devices
.on('touchend.daterangepicker', this._outsideClickProxy)
// also explicitly play nice with Bootstrap dropdowns, which stopPropagation when clicking them // also explicitly play nice with Bootstrap dropdowns, which stopPropagation when clicking them
.on('click.daterangepicker', '[data-toggle=dropdown]', this._outsideClickProxy) .on('click.daterangepicker', '[data-toggle=dropdown]', this._outsideClickProxy)
// and also close when focus changes to outside the picker (eg. tabbing between controls) // and also close when focus changes to outside the picker (eg. tabbing between controls)
...@@ -603,6 +656,8 @@ ...@@ -603,6 +656,8 @@
// if the page is clicked anywhere except within the daterangerpicker/button // if the page is clicked anywhere except within the daterangerpicker/button
// itself then call this.hide() // itself then call this.hide()
if ( if (
// ie modal dialog fix
e.type == "focusin" ||
target.closest(this.element).length || target.closest(this.element).length ||
target.closest(this.container).length || target.closest(this.container).length ||
target.closest('.calendar-date').length target.closest('.calendar-date').length
...@@ -614,9 +669,7 @@ ...@@ -614,9 +669,7 @@
if (!this.isShowing) return; if (!this.isShowing) return;
$(document) $(document)
.off('mousedown.daterangepicker') .off('.daterangepicker');
.off('click.daterangepicker', '[data-toggle=dropdown]')
.off('focusin.daterangepicker');
this.element.removeClass('active'); this.element.removeClass('active');
this.container.hide(); this.container.hide();
...@@ -662,11 +715,23 @@ ...@@ -662,11 +715,23 @@
var startDate, endDate; var startDate, endDate;
if (el.attr('name') === 'daterangepicker_start') { if (el.attr('name') === 'daterangepicker_start') {
startDate = date; startDate = (false !== this.minDate && date.isBefore(this.minDate)) ? this.minDate : date;
endDate = this.endDate; endDate = this.endDate;
if (typeof this.dateLimit === 'object') {
var maxDate = moment(startDate).add(this.dateLimit).endOf('day');
if (endDate.isAfter(maxDate)) {
endDate = maxDate;
}
}
} else { } else {
startDate = this.startDate; startDate = this.startDate;
endDate = date; endDate = (false !== this.maxDate && date.isAfter(this.maxDate)) ? this.maxDate : date.endOf('day');
if (typeof this.dateLimit === 'object') {
var minDate = moment(endDate).subtract(this.dateLimit).startOf('day');
if (startDate.isBefore(minDate)) {
startDate = minDate;
}
}
} }
this.setCustomDates(startDate, endDate); this.setCustomDates(startDate, endDate);
}, },
...@@ -681,8 +746,10 @@ ...@@ -681,8 +746,10 @@
updateInputText: function() { updateInputText: function() {
if (this.element.is('input') && !this.singleDatePicker) { if (this.element.is('input') && !this.singleDatePicker) {
this.element.val(this.startDate.format(this.format) + this.separator + this.endDate.format(this.format)); this.element.val(this.startDate.format(this.format) + this.separator + this.endDate.format(this.format));
this.element.trigger('change');
} else if (this.element.is('input')) { } else if (this.element.is('input')) {
this.element.val(this.endDate.format(this.format)); this.element.val(this.endDate.format(this.format));
this.element.trigger('change');
} }
}, },
...@@ -711,6 +778,11 @@ ...@@ -711,6 +778,11 @@
this.hideCalendars(); this.hideCalendars();
this.hide(); this.hide();
this.element.trigger('apply.daterangepicker', this); this.element.trigger('apply.daterangepicker', this);
if (this.autoApply) {
this.notify();
}
} }
}, },
...@@ -752,12 +824,20 @@ ...@@ -752,12 +824,20 @@
if (startDate.isAfter(endDate)) { if (startDate.isAfter(endDate)) {
var difference = this.endDate.diff(this.startDate); var difference = this.endDate.diff(this.startDate);
endDate = moment(startDate).add(difference, 'ms'); endDate = moment(startDate).add(difference, 'ms');
if (this.maxDate && endDate.isAfter(this.maxDate)) {
endDate = this.maxDate.clone();
}
} }
this.startDate = startDate; this.startDate = startDate;
this.endDate = endDate; this.endDate = endDate;
this.updateView(); this.updateView();
this.updateCalendars(); this.updateCalendars();
if (this.autoApply) {
this.notify();
this.element.trigger('apply.daterangepicker', this);
}
}, },
clickDate: function (e) { clickDate: function (e) {
...@@ -771,7 +851,7 @@ ...@@ -771,7 +851,7 @@
startDate = this.leftCalendar.calendar[row][col]; startDate = this.leftCalendar.calendar[row][col];
endDate = this.endDate; endDate = this.endDate;
if (typeof this.dateLimit === 'object') { if (typeof this.dateLimit === 'object') {
var maxDate = moment(startDate).add(this.dateLimit).startOf('day'); var maxDate = moment(startDate).add(this.dateLimit).endOf('day');
if (endDate.isAfter(maxDate)) { if (endDate.isAfter(maxDate)) {
endDate = maxDate; endDate = maxDate;
} }
...@@ -831,6 +911,28 @@ ...@@ -831,6 +911,28 @@
var month = parseInt(cal.find('.monthselect').val(), 10); var month = parseInt(cal.find('.monthselect').val(), 10);
var year = cal.find('.yearselect').val(); var year = cal.find('.yearselect').val();
if (!isLeft && !this.singleDatePicker) {
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[leftOrRight+'Calendar'].month.month(month).year(year);
this.updateCalendars(); this.updateCalendars();
}, },
...@@ -842,6 +944,11 @@ ...@@ -842,6 +944,11 @@
var hour = parseInt(cal.find('.hourselect').val(), 10); var hour = parseInt(cal.find('.hourselect').val(), 10);
var minute = parseInt(cal.find('.minuteselect').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) { if (this.timePicker12Hour) {
var ampm = cal.find('.ampmselect').val(); var ampm = cal.find('.ampmselect').val();
...@@ -855,30 +962,37 @@ ...@@ -855,30 +962,37 @@
var start = this.startDate.clone(); var start = this.startDate.clone();
start.hour(hour); start.hour(hour);
start.minute(minute); start.minute(minute);
start.second(second);
this.startDate = start; this.startDate = start;
this.leftCalendar.month.hour(hour).minute(minute); this.leftCalendar.month.hour(hour).minute(minute).second(second);
if (this.singleDatePicker) if (this.singleDatePicker)
this.endDate = start.clone(); this.endDate = start.clone();
} else { } else {
var end = this.endDate.clone(); var end = this.endDate.clone();
end.hour(hour); end.hour(hour);
end.minute(minute); end.minute(minute);
end.second(second);
this.endDate = end; this.endDate = end;
if (this.singleDatePicker) if (this.singleDatePicker)
this.startDate = end.clone(); this.startDate = end.clone();
this.rightCalendar.month.hour(hour).minute(minute); this.rightCalendar.month.hour(hour).minute(minute).second(second);
} }
this.updateView(); this.updateView();
this.updateCalendars(); this.updateCalendars();
if (this.autoApply) {
this.notify();
this.element.trigger('apply.daterangepicker', this);
}
}, },
updateCalendars: function () { 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.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(), 'right'); 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.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('.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'); this.container.find('.ranges li').removeClass('active');
var customRange = true; var customRange = true;
var i = 0; var i = 0;
...@@ -905,7 +1019,7 @@ ...@@ -905,7 +1019,7 @@
} }
}, },
buildCalendar: function (month, year, hour, minute, side) { buildCalendar: function (month, year, hour, minute, second, side) {
var daysInMonth = moment([year, month]).daysInMonth(); var daysInMonth = moment([year, month]).daysInMonth();
var firstDay = moment([year, month, 1]); var firstDay = moment([year, month, 1]);
var lastDay = moment([year, month, daysInMonth]); var lastDay = moment([year, month, daysInMonth]);
...@@ -935,7 +1049,9 @@ ...@@ -935,7 +1049,9 @@
if (dayOfWeek == this.locale.firstDay) if (dayOfWeek == this.locale.firstDay)
startDay = daysInLastMonth - 6; startDay = daysInLastMonth - 6;
var curDate = moment([lastYear, lastMonth, startDay, 12, minute]); // 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);
var col, row; var col, row;
for (i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add(24, 'hour')) { for (i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add(24, 'hour')) {
if (i > 0 && col % 7 === 0) { if (i > 0 && col % 7 === 0) {
...@@ -1002,7 +1118,7 @@ ...@@ -1002,7 +1118,7 @@
html += '<th></th>'; html += '<th></th>';
if (!minDate || minDate.isBefore(calendar.firstDay)) { if (!minDate || minDate.isBefore(calendar.firstDay)) {
html += '<th class="prev available"><i class="fa fa-arrow-left icon-arrow-left glyphicon glyphicon-arrow-left"></i></th>'; html += '<th class="prev available"><i class="fa fa-arrow-left icon icon-arrow-left glyphicon glyphicon-arrow-left"></i></th>';
} else { } else {
html += '<th></th>'; html += '<th></th>';
} }
...@@ -1015,7 +1131,7 @@ ...@@ -1015,7 +1131,7 @@
html += '<th colspan="5" class="month">' + dateHtml + '</th>'; html += '<th colspan="5" class="month">' + dateHtml + '</th>';
if (!maxDate || maxDate.isAfter(calendar.lastDay)) { if (!maxDate || maxDate.isAfter(calendar.lastDay)) {
html += '<th class="next available"><i class="fa fa-arrow-right icon-arrow-right glyphicon glyphicon-arrow-right"></i></th>'; html += '<th class="next available"><i class="fa fa-arrow-right icon icon-arrow-right glyphicon glyphicon-arrow-right"></i></th>';
} else { } else {
html += '<th></th>'; html += '<th></th>';
} }
...@@ -1045,6 +1161,10 @@ ...@@ -1045,6 +1161,10 @@
for (var col = 0; col < 7; col++) { for (var col = 0; col < 7; col++) {
var cname = 'available '; var cname = 'available ';
cname += (calendar[row][col].month() == calendar[1][1].month()) ? '' : 'off'; cname += (calendar[row][col].month() == calendar[1][1].month()) ? '' : 'off';
if(calendar[row][col].isSame(new Date(), "day") ) {
cname += ' today ';
}
if ((minDate && calendar[row][col].isBefore(minDate, 'day')) || (maxDate && calendar[row][col].isAfter(maxDate, 'day'))) { if ((minDate && calendar[row][col].isBefore(minDate, 'day')) || (maxDate && calendar[row][col].isAfter(maxDate, 'day'))) {
cname = ' off disabled '; cname = ' off disabled ';
...@@ -1158,6 +1278,23 @@ ...@@ -1158,6 +1278,23 @@
html += '</select> '; 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) { if (this.timePicker12Hour) {
html += '<select class="ampmselect">'; html += '<select class="ampmselect">';
...@@ -1209,4 +1346,4 @@ ...@@ -1209,4 +1346,4 @@
return this; return this;
}; };
})); }));
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment