LaravelTest
1578 строк · 64.7 Кб
1/**
2* @version: 3.1
3* @author: Dan Grossman http://www.dangrossman.info/
4* @copyright: Copyright (c) 2012-2019 Dan Grossman. All rights reserved.
5* @license: Licensed under the MIT license. See http://www.opensource.org/licenses/mit-license.php
6* @website: http://www.daterangepicker.com/
7*/
8// Following the UMD template https://github.com/umdjs/umd/blob/master/templates/returnExportsGlobal.js
9(function (root, factory) {10if (typeof define === 'function' && define.amd) {11// AMD. Make globaly available as well12define(['moment', 'jquery'], function (moment, jquery) {13if (!jquery.fn) jquery.fn = {}; // webpack server rendering14if (typeof moment !== 'function' && moment.hasOwnProperty('default')) moment = moment['default']15return factory(moment, jquery);16});17} else if (typeof module === 'object' && module.exports) {18// Node / Browserify19//isomorphic issue20var jQuery = (typeof window != 'undefined') ? window.jQuery : undefined;21if (!jQuery) {22jQuery = require('jquery');23if (!jQuery.fn) jQuery.fn = {};24}25var moment = (typeof window != 'undefined' && typeof window.moment != 'undefined') ? window.moment : require('moment');26module.exports = factory(moment, jQuery);27} else {28// Browser globals29root.daterangepicker = factory(root.moment, root.jQuery);30}31}(this, function(moment, $) {32var DateRangePicker = function(element, options, cb) {33
34//default settings for options35this.parentEl = 'body';36this.element = $(element);37this.startDate = moment().startOf('day');38this.endDate = moment().endOf('day');39this.minDate = false;40this.maxDate = false;41this.maxSpan = false;42this.autoApply = false;43this.singleDatePicker = false;44this.showDropdowns = false;45this.minYear = moment().subtract(100, 'year').format('YYYY');46this.maxYear = moment().add(100, 'year').format('YYYY');47this.showWeekNumbers = false;48this.showISOWeekNumbers = false;49this.showCustomRangeLabel = true;50this.timePicker = false;51this.timePicker24Hour = false;52this.timePickerIncrement = 1;53this.timePickerSeconds = false;54this.linkedCalendars = true;55this.autoUpdateInput = true;56this.alwaysShowCalendars = false;57this.ranges = {};58
59this.opens = 'right';60if (this.element.hasClass('pull-right'))61this.opens = 'left';62
63this.drops = 'down';64if (this.element.hasClass('dropup'))65this.drops = 'up';66
67this.buttonClasses = 'btn btn-sm';68this.applyButtonClasses = 'btn-primary';69this.cancelButtonClasses = 'btn-default';70
71this.locale = {72direction: 'ltr',73format: moment.localeData().longDateFormat('L'),74separator: ' - ',75applyLabel: 'Apply',76cancelLabel: 'Cancel',77weekLabel: 'W',78customRangeLabel: 'Custom Range',79daysOfWeek: moment.weekdaysMin(),80monthNames: moment.monthsShort(),81firstDay: moment.localeData().firstDayOfWeek()82};83
84this.callback = function() { };85
86//some state information87this.isShowing = false;88this.leftCalendar = {};89this.rightCalendar = {};90
91//custom options from user92if (typeof options !== 'object' || options === null)93options = {};94
95//allow setting options with data attributes96//data-api options will be overwritten with custom javascript options97options = $.extend(this.element.data(), options);98
99//html template for the picker UI100if (typeof options.template !== 'string' && !(options.template instanceof $))101options.template =102'<div class="daterangepicker">' +103'<div class="ranges"></div>' +104'<div class="drp-calendar left">' +105'<div class="calendar-table"></div>' +106'<div class="calendar-time"></div>' +107'</div>' +108'<div class="drp-calendar right">' +109'<div class="calendar-table"></div>' +110'<div class="calendar-time"></div>' +111'</div>' +112'<div class="drp-buttons">' +113'<span class="drp-selected"></span>' +114'<button class="cancelBtn" type="button"></button>' +115'<button class="applyBtn" disabled="disabled" type="button"></button> ' +116'</div>' +117'</div>';118
119this.parentEl = (options.parentEl && $(options.parentEl).length) ? $(options.parentEl) : $(this.parentEl);120this.container = $(options.template).appendTo(this.parentEl);121
122//123// handle all the possible options overriding defaults124//125
126if (typeof options.locale === 'object') {127
128if (typeof options.locale.direction === 'string')129this.locale.direction = options.locale.direction;130
131if (typeof options.locale.format === 'string')132this.locale.format = options.locale.format;133
134if (typeof options.locale.separator === 'string')135this.locale.separator = options.locale.separator;136
137if (typeof options.locale.daysOfWeek === 'object')138this.locale.daysOfWeek = options.locale.daysOfWeek.slice();139
140if (typeof options.locale.monthNames === 'object')141this.locale.monthNames = options.locale.monthNames.slice();142
143if (typeof options.locale.firstDay === 'number')144this.locale.firstDay = options.locale.firstDay;145
146if (typeof options.locale.applyLabel === 'string')147this.locale.applyLabel = options.locale.applyLabel;148
149if (typeof options.locale.cancelLabel === 'string')150this.locale.cancelLabel = options.locale.cancelLabel;151
152if (typeof options.locale.weekLabel === 'string')153this.locale.weekLabel = options.locale.weekLabel;154
155if (typeof options.locale.customRangeLabel === 'string'){156//Support unicode chars in the custom range name.157var elem = document.createElement('textarea');158elem.innerHTML = options.locale.customRangeLabel;159var rangeHtml = elem.value;160this.locale.customRangeLabel = rangeHtml;161}162}163this.container.addClass(this.locale.direction);164
165if (typeof options.startDate === 'string')166this.startDate = moment(options.startDate, this.locale.format);167
168if (typeof options.endDate === 'string')169this.endDate = moment(options.endDate, this.locale.format);170
171if (typeof options.minDate === 'string')172this.minDate = moment(options.minDate, this.locale.format);173
174if (typeof options.maxDate === 'string')175this.maxDate = moment(options.maxDate, this.locale.format);176
177if (typeof options.startDate === 'object')178this.startDate = moment(options.startDate);179
180if (typeof options.endDate === 'object')181this.endDate = moment(options.endDate);182
183if (typeof options.minDate === 'object')184this.minDate = moment(options.minDate);185
186if (typeof options.maxDate === 'object')187this.maxDate = moment(options.maxDate);188
189// sanity check for bad options190if (this.minDate && this.startDate.isBefore(this.minDate))191this.startDate = this.minDate.clone();192
193// sanity check for bad options194if (this.maxDate && this.endDate.isAfter(this.maxDate))195this.endDate = this.maxDate.clone();196
197if (typeof options.applyButtonClasses === 'string')198this.applyButtonClasses = options.applyButtonClasses;199
200if (typeof options.applyClass === 'string') //backwards compat201this.applyButtonClasses = options.applyClass;202
203if (typeof options.cancelButtonClasses === 'string')204this.cancelButtonClasses = options.cancelButtonClasses;205
206if (typeof options.cancelClass === 'string') //backwards compat207this.cancelButtonClasses = options.cancelClass;208
209if (typeof options.maxSpan === 'object')210this.maxSpan = options.maxSpan;211
212if (typeof options.dateLimit === 'object') //backwards compat213this.maxSpan = options.dateLimit;214
215if (typeof options.opens === 'string')216this.opens = options.opens;217
218if (typeof options.drops === 'string')219this.drops = options.drops;220
221if (typeof options.showWeekNumbers === 'boolean')222this.showWeekNumbers = options.showWeekNumbers;223
224if (typeof options.showISOWeekNumbers === 'boolean')225this.showISOWeekNumbers = options.showISOWeekNumbers;226
227if (typeof options.buttonClasses === 'string')228this.buttonClasses = options.buttonClasses;229
230if (typeof options.buttonClasses === 'object')231this.buttonClasses = options.buttonClasses.join(' ');232
233if (typeof options.showDropdowns === 'boolean')234this.showDropdowns = options.showDropdowns;235
236if (typeof options.minYear === 'number')237this.minYear = options.minYear;238
239if (typeof options.maxYear === 'number')240this.maxYear = options.maxYear;241
242if (typeof options.showCustomRangeLabel === 'boolean')243this.showCustomRangeLabel = options.showCustomRangeLabel;244
245if (typeof options.singleDatePicker === 'boolean') {246this.singleDatePicker = options.singleDatePicker;247if (this.singleDatePicker)248this.endDate = this.startDate.clone();249}250
251if (typeof options.timePicker === 'boolean')252this.timePicker = options.timePicker;253
254if (typeof options.timePickerSeconds === 'boolean')255this.timePickerSeconds = options.timePickerSeconds;256
257if (typeof options.timePickerIncrement === 'number')258this.timePickerIncrement = options.timePickerIncrement;259
260if (typeof options.timePicker24Hour === 'boolean')261this.timePicker24Hour = options.timePicker24Hour;262
263if (typeof options.autoApply === 'boolean')264this.autoApply = options.autoApply;265
266if (typeof options.autoUpdateInput === 'boolean')267this.autoUpdateInput = options.autoUpdateInput;268
269if (typeof options.linkedCalendars === 'boolean')270this.linkedCalendars = options.linkedCalendars;271
272if (typeof options.isInvalidDate === 'function')273this.isInvalidDate = options.isInvalidDate;274
275if (typeof options.isCustomDate === 'function')276this.isCustomDate = options.isCustomDate;277
278if (typeof options.alwaysShowCalendars === 'boolean')279this.alwaysShowCalendars = options.alwaysShowCalendars;280
281// update day names order to firstDay282if (this.locale.firstDay != 0) {283var iterator = this.locale.firstDay;284while (iterator > 0) {285this.locale.daysOfWeek.push(this.locale.daysOfWeek.shift());286iterator--;287}288}289
290var start, end, range;291
292//if no start/end dates set, check if an input element contains initial values293if (typeof options.startDate === 'undefined' && typeof options.endDate === 'undefined') {294if ($(this.element).is(':text')) {295var val = $(this.element).val(),296split = val.split(this.locale.separator);297
298start = end = null;299
300if (split.length == 2) {301start = moment(split[0], this.locale.format);302end = moment(split[1], this.locale.format);303} else if (this.singleDatePicker && val !== "") {304start = moment(val, this.locale.format);305end = moment(val, this.locale.format);306}307if (start !== null && end !== null) {308this.setStartDate(start);309this.setEndDate(end);310}311}312}313
314if (typeof options.ranges === 'object') {315for (range in options.ranges) {316
317if (typeof options.ranges[range][0] === 'string')318start = moment(options.ranges[range][0], this.locale.format);319else320start = moment(options.ranges[range][0]);321
322if (typeof options.ranges[range][1] === 'string')323end = moment(options.ranges[range][1], this.locale.format);324else325end = moment(options.ranges[range][1]);326
327// If the start or end date exceed those allowed by the minDate or maxSpan328// options, shorten the range to the allowable period.329if (this.minDate && start.isBefore(this.minDate))330start = this.minDate.clone();331
332var maxDate = this.maxDate;333if (this.maxSpan && maxDate && start.clone().add(this.maxSpan).isAfter(maxDate))334maxDate = start.clone().add(this.maxSpan);335if (maxDate && end.isAfter(maxDate))336end = maxDate.clone();337
338// If the end of the range is before the minimum or the start of the range is339// after the maximum, don't display this range option at all.340if ((this.minDate && end.isBefore(this.minDate, this.timepicker ? 'minute' : 'day'))341|| (maxDate && start.isAfter(maxDate, this.timepicker ? 'minute' : 'day')))342continue;343
344//Support unicode chars in the range names.345var elem = document.createElement('textarea');346elem.innerHTML = range;347var rangeHtml = elem.value;348
349this.ranges[rangeHtml] = [start, end];350}351
352var list = '<ul>';353for (range in this.ranges) {354list += '<li data-range-key="' + range + '">' + range + '</li>';355}356if (this.showCustomRangeLabel) {357list += '<li data-range-key="' + this.locale.customRangeLabel + '">' + this.locale.customRangeLabel + '</li>';358}359list += '</ul>';360this.container.find('.ranges').prepend(list);361}362
363if (typeof cb === 'function') {364this.callback = cb;365}366
367if (!this.timePicker) {368this.startDate = this.startDate.startOf('day');369this.endDate = this.endDate.endOf('day');370this.container.find('.calendar-time').hide();371}372
373//can't be used together for now374if (this.timePicker && this.autoApply)375this.autoApply = false;376
377if (this.autoApply) {378this.container.addClass('auto-apply');379}380
381if (typeof options.ranges === 'object')382this.container.addClass('show-ranges');383
384if (this.singleDatePicker) {385this.container.addClass('single');386this.container.find('.drp-calendar.left').addClass('single');387this.container.find('.drp-calendar.left').show();388this.container.find('.drp-calendar.right').hide();389if (!this.timePicker && this.autoApply) {390this.container.addClass('auto-apply');391}392}393
394if ((typeof options.ranges === 'undefined' && !this.singleDatePicker) || this.alwaysShowCalendars) {395this.container.addClass('show-calendar');396}397
398this.container.addClass('opens' + this.opens);399
400//apply CSS classes and labels to buttons401this.container.find('.applyBtn, .cancelBtn').addClass(this.buttonClasses);402if (this.applyButtonClasses.length)403this.container.find('.applyBtn').addClass(this.applyButtonClasses);404if (this.cancelButtonClasses.length)405this.container.find('.cancelBtn').addClass(this.cancelButtonClasses);406this.container.find('.applyBtn').html(this.locale.applyLabel);407this.container.find('.cancelBtn').html(this.locale.cancelLabel);408
409//410// event listeners411//412
413this.container.find('.drp-calendar')414.on('click.daterangepicker', '.prev', $.proxy(this.clickPrev, this))415.on('click.daterangepicker', '.next', $.proxy(this.clickNext, this))416.on('mousedown.daterangepicker', 'td.available', $.proxy(this.clickDate, this))417.on('mouseenter.daterangepicker', 'td.available', $.proxy(this.hoverDate, this))418.on('change.daterangepicker', 'select.yearselect', $.proxy(this.monthOrYearChanged, this))419.on('change.daterangepicker', 'select.monthselect', $.proxy(this.monthOrYearChanged, this))420.on('change.daterangepicker', 'select.hourselect,select.minuteselect,select.secondselect,select.ampmselect', $.proxy(this.timeChanged, this));421
422this.container.find('.ranges')423.on('click.daterangepicker', 'li', $.proxy(this.clickRange, this));424
425this.container.find('.drp-buttons')426.on('click.daterangepicker', 'button.applyBtn', $.proxy(this.clickApply, this))427.on('click.daterangepicker', 'button.cancelBtn', $.proxy(this.clickCancel, this));428
429if (this.element.is('input') || this.element.is('button')) {430this.element.on({431'click.daterangepicker': $.proxy(this.show, this),432'focus.daterangepicker': $.proxy(this.show, this),433'keyup.daterangepicker': $.proxy(this.elementChanged, this),434'keydown.daterangepicker': $.proxy(this.keydown, this) //IE 11 compatibility435});436} else {437this.element.on('click.daterangepicker', $.proxy(this.toggle, this));438this.element.on('keydown.daterangepicker', $.proxy(this.toggle, this));439}440
441//442// if attached to a text input, set the initial value443//444
445this.updateElement();446
447};448
449DateRangePicker.prototype = {450
451constructor: DateRangePicker,452
453setStartDate: function(startDate) {454if (typeof startDate === 'string')455this.startDate = moment(startDate, this.locale.format);456
457if (typeof startDate === 'object')458this.startDate = moment(startDate);459
460if (!this.timePicker)461this.startDate = this.startDate.startOf('day');462
463if (this.timePicker && this.timePickerIncrement)464this.startDate.minute(Math.round(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);465
466if (this.minDate && this.startDate.isBefore(this.minDate)) {467this.startDate = this.minDate.clone();468if (this.timePicker && this.timePickerIncrement)469this.startDate.minute(Math.round(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);470}471
472if (this.maxDate && this.startDate.isAfter(this.maxDate)) {473this.startDate = this.maxDate.clone();474if (this.timePicker && this.timePickerIncrement)475this.startDate.minute(Math.floor(this.startDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);476}477
478if (!this.isShowing)479this.updateElement();480
481this.updateMonthsInView();482},483
484setEndDate: function(endDate) {485if (typeof endDate === 'string')486this.endDate = moment(endDate, this.locale.format);487
488if (typeof endDate === 'object')489this.endDate = moment(endDate);490
491if (!this.timePicker)492this.endDate = this.endDate.endOf('day');493
494if (this.timePicker && this.timePickerIncrement)495this.endDate.minute(Math.round(this.endDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);496
497if (this.endDate.isBefore(this.startDate))498this.endDate = this.startDate.clone();499
500if (this.maxDate && this.endDate.isAfter(this.maxDate))501this.endDate = this.maxDate.clone();502
503if (this.maxSpan && this.startDate.clone().add(this.maxSpan).isBefore(this.endDate))504this.endDate = this.startDate.clone().add(this.maxSpan);505
506this.previousRightTime = this.endDate.clone();507
508this.container.find('.drp-selected').html(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));509
510if (!this.isShowing)511this.updateElement();512
513this.updateMonthsInView();514},515
516isInvalidDate: function() {517return false;518},519
520isCustomDate: function() {521return false;522},523
524updateView: function() {525if (this.timePicker) {526this.renderTimePicker('left');527this.renderTimePicker('right');528if (!this.endDate) {529this.container.find('.right .calendar-time select').prop('disabled', true).addClass('disabled');530} else {531this.container.find('.right .calendar-time select').prop('disabled', false).removeClass('disabled');532}533}534if (this.endDate)535this.container.find('.drp-selected').html(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));536this.updateMonthsInView();537this.updateCalendars();538this.updateFormInputs();539},540
541updateMonthsInView: function() {542if (this.endDate) {543
544//if both dates are visible already, do nothing545if (!this.singleDatePicker && this.leftCalendar.month && this.rightCalendar.month &&546(this.startDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.startDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM'))547&&548(this.endDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.endDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM'))549) {550return;551}552
553this.leftCalendar.month = this.startDate.clone().date(2);554if (!this.linkedCalendars && (this.endDate.month() != this.startDate.month() || this.endDate.year() != this.startDate.year())) {555this.rightCalendar.month = this.endDate.clone().date(2);556} else {557this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month');558}559
560} else {561if (this.leftCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM') && this.rightCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM')) {562this.leftCalendar.month = this.startDate.clone().date(2);563this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month');564}565}566if (this.maxDate && this.linkedCalendars && !this.singleDatePicker && this.rightCalendar.month > this.maxDate) {567this.rightCalendar.month = this.maxDate.clone().date(2);568this.leftCalendar.month = this.maxDate.clone().date(2).subtract(1, 'month');569}570},571
572updateCalendars: function() {573
574if (this.timePicker) {575var hour, minute, second;576if (this.endDate) {577hour = parseInt(this.container.find('.left .hourselect').val(), 10);578minute = parseInt(this.container.find('.left .minuteselect').val(), 10);579if (isNaN(minute)) {580minute = parseInt(this.container.find('.left .minuteselect option:last').val(), 10);581}582second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0;583if (!this.timePicker24Hour) {584var ampm = this.container.find('.left .ampmselect').val();585if (ampm === 'PM' && hour < 12)586hour += 12;587if (ampm === 'AM' && hour === 12)588hour = 0;589}590} else {591hour = parseInt(this.container.find('.right .hourselect').val(), 10);592minute = parseInt(this.container.find('.right .minuteselect').val(), 10);593if (isNaN(minute)) {594minute = parseInt(this.container.find('.right .minuteselect option:last').val(), 10);595}596second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;597if (!this.timePicker24Hour) {598var ampm = this.container.find('.right .ampmselect').val();599if (ampm === 'PM' && hour < 12)600hour += 12;601if (ampm === 'AM' && hour === 12)602hour = 0;603}604}605this.leftCalendar.month.hour(hour).minute(minute).second(second);606this.rightCalendar.month.hour(hour).minute(minute).second(second);607}608
609this.renderCalendar('left');610this.renderCalendar('right');611
612//highlight any predefined range matching the current start and end dates613this.container.find('.ranges li').removeClass('active');614if (this.endDate == null) return;615
616this.calculateChosenLabel();617},618
619renderCalendar: function(side) {620
621//622// Build the matrix of dates that will populate the calendar623//624
625var calendar = side == 'left' ? this.leftCalendar : this.rightCalendar;626var month = calendar.month.month();627var year = calendar.month.year();628var hour = calendar.month.hour();629var minute = calendar.month.minute();630var second = calendar.month.second();631var daysInMonth = moment([year, month]).daysInMonth();632var firstDay = moment([year, month, 1]);633var lastDay = moment([year, month, daysInMonth]);634var lastMonth = moment(firstDay).subtract(1, 'month').month();635var lastYear = moment(firstDay).subtract(1, 'month').year();636var daysInLastMonth = moment([lastYear, lastMonth]).daysInMonth();637var dayOfWeek = firstDay.day();638
639//initialize a 6 rows x 7 columns array for the calendar640var calendar = [];641calendar.firstDay = firstDay;642calendar.lastDay = lastDay;643
644for (var i = 0; i < 6; i++) {645calendar[i] = [];646}647
648//populate the calendar with date objects649var startDay = daysInLastMonth - dayOfWeek + this.locale.firstDay + 1;650if (startDay > daysInLastMonth)651startDay -= 7;652
653if (dayOfWeek == this.locale.firstDay)654startDay = daysInLastMonth - 6;655
656var curDate = moment([lastYear, lastMonth, startDay, 12, minute, second]);657
658var col, row;659for (var i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add(24, 'hour')) {660if (i > 0 && col % 7 === 0) {661col = 0;662row++;663}664calendar[row][col] = curDate.clone().hour(hour).minute(minute).second(second);665curDate.hour(12);666
667if (this.minDate && calendar[row][col].format('YYYY-MM-DD') == this.minDate.format('YYYY-MM-DD') && calendar[row][col].isBefore(this.minDate) && side == 'left') {668calendar[row][col] = this.minDate.clone();669}670
671if (this.maxDate && calendar[row][col].format('YYYY-MM-DD') == this.maxDate.format('YYYY-MM-DD') && calendar[row][col].isAfter(this.maxDate) && side == 'right') {672calendar[row][col] = this.maxDate.clone();673}674
675}676
677//make the calendar object available to hoverDate/clickDate678if (side == 'left') {679this.leftCalendar.calendar = calendar;680} else {681this.rightCalendar.calendar = calendar;682}683
684//685// Display the calendar686//687
688var minDate = side == 'left' ? this.minDate : this.startDate;689var maxDate = this.maxDate;690var selected = side == 'left' ? this.startDate : this.endDate;691var arrow = this.locale.direction == 'ltr' ? {left: 'chevron-left', right: 'chevron-right'} : {left: 'chevron-right', right: 'chevron-left'};692
693var html = '<table class="table-condensed">';694html += '<thead>';695html += '<tr>';696
697// add empty cell for week number698if (this.showWeekNumbers || this.showISOWeekNumbers)699html += '<th></th>';700
701if ((!minDate || minDate.isBefore(calendar.firstDay)) && (!this.linkedCalendars || side == 'left')) {702html += '<th class="prev available"><span></span></th>';703} else {704html += '<th></th>';705}706
707var dateHtml = this.locale.monthNames[calendar[1][1].month()] + calendar[1][1].format(" YYYY");708
709if (this.showDropdowns) {710var currentMonth = calendar[1][1].month();711var currentYear = calendar[1][1].year();712var maxYear = (maxDate && maxDate.year()) || (this.maxYear);713var minYear = (minDate && minDate.year()) || (this.minYear);714var inMinYear = currentYear == minYear;715var inMaxYear = currentYear == maxYear;716
717var monthHtml = '<select class="monthselect">';718for (var m = 0; m < 12; m++) {719if ((!inMinYear || (minDate && m >= minDate.month())) && (!inMaxYear || (maxDate && m <= maxDate.month()))) {720monthHtml += "<option value='" + m + "'" +721(m === currentMonth ? " selected='selected'" : "") +722">" + this.locale.monthNames[m] + "</option>";723} else {724monthHtml += "<option value='" + m + "'" +725(m === currentMonth ? " selected='selected'" : "") +726" disabled='disabled'>" + this.locale.monthNames[m] + "</option>";727}728}729monthHtml += "</select>";730
731var yearHtml = '<select class="yearselect">';732for (var y = minYear; y <= maxYear; y++) {733yearHtml += '<option value="' + y + '"' +734(y === currentYear ? ' selected="selected"' : '') +735'>' + y + '</option>';736}737yearHtml += '</select>';738
739dateHtml = monthHtml + yearHtml;740}741
742html += '<th colspan="5" class="month">' + dateHtml + '</th>';743if ((!maxDate || maxDate.isAfter(calendar.lastDay)) && (!this.linkedCalendars || side == 'right' || this.singleDatePicker)) {744html += '<th class="next available"><span></span></th>';745} else {746html += '<th></th>';747}748
749html += '</tr>';750html += '<tr>';751
752// add week number label753if (this.showWeekNumbers || this.showISOWeekNumbers)754html += '<th class="week">' + this.locale.weekLabel + '</th>';755
756$.each(this.locale.daysOfWeek, function(index, dayOfWeek) {757html += '<th>' + dayOfWeek + '</th>';758});759
760html += '</tr>';761html += '</thead>';762html += '<tbody>';763
764//adjust maxDate to reflect the maxSpan setting in order to765//grey out end dates beyond the maxSpan766if (this.endDate == null && this.maxSpan) {767var maxLimit = this.startDate.clone().add(this.maxSpan).endOf('day');768if (!maxDate || maxLimit.isBefore(maxDate)) {769maxDate = maxLimit;770}771}772
773for (var row = 0; row < 6; row++) {774html += '<tr>';775
776// add week number777if (this.showWeekNumbers)778html += '<td class="week">' + calendar[row][0].week() + '</td>';779else if (this.showISOWeekNumbers)780html += '<td class="week">' + calendar[row][0].isoWeek() + '</td>';781
782for (var col = 0; col < 7; col++) {783
784var classes = [];785
786//highlight today's date787if (calendar[row][col].isSame(new Date(), "day"))788classes.push('today');789
790//highlight weekends791if (calendar[row][col].isoWeekday() > 5)792classes.push('weekend');793
794//grey out the dates in other months displayed at beginning and end of this calendar795if (calendar[row][col].month() != calendar[1][1].month())796classes.push('off', 'ends');797
798//don't allow selection of dates before the minimum date799if (this.minDate && calendar[row][col].isBefore(this.minDate, 'day'))800classes.push('off', 'disabled');801
802//don't allow selection of dates after the maximum date803if (maxDate && calendar[row][col].isAfter(maxDate, 'day'))804classes.push('off', 'disabled');805
806//don't allow selection of date if a custom function decides it's invalid807if (this.isInvalidDate(calendar[row][col]))808classes.push('off', 'disabled');809
810//highlight the currently selected start date811if (calendar[row][col].format('YYYY-MM-DD') == this.startDate.format('YYYY-MM-DD'))812classes.push('active', 'start-date');813
814//highlight the currently selected end date815if (this.endDate != null && calendar[row][col].format('YYYY-MM-DD') == this.endDate.format('YYYY-MM-DD'))816classes.push('active', 'end-date');817
818//highlight dates in-between the selected dates819if (this.endDate != null && calendar[row][col] > this.startDate && calendar[row][col] < this.endDate)820classes.push('in-range');821
822//apply custom classes for this date823var isCustom = this.isCustomDate(calendar[row][col]);824if (isCustom !== false) {825if (typeof isCustom === 'string')826classes.push(isCustom);827else828Array.prototype.push.apply(classes, isCustom);829}830
831var cname = '', disabled = false;832for (var i = 0; i < classes.length; i++) {833cname += classes[i] + ' ';834if (classes[i] == 'disabled')835disabled = true;836}837if (!disabled)838cname += 'available';839
840html += '<td class="' + cname.replace(/^\s+|\s+$/g, '') + '" data-title="' + 'r' + row + 'c' + col + '">' + calendar[row][col].date() + '</td>';841
842}843html += '</tr>';844}845
846html += '</tbody>';847html += '</table>';848
849this.container.find('.drp-calendar.' + side + ' .calendar-table').html(html);850
851},852
853renderTimePicker: function(side) {854
855// Don't bother updating the time picker if it's currently disabled856// because an end date hasn't been clicked yet857if (side == 'right' && !this.endDate) return;858
859var html, selected, minDate, maxDate = this.maxDate;860
861if (this.maxSpan && (!this.maxDate || this.startDate.clone().add(this.maxSpan).isBefore(this.maxDate)))862maxDate = this.startDate.clone().add(this.maxSpan);863
864if (side == 'left') {865selected = this.startDate.clone();866minDate = this.minDate;867} else if (side == 'right') {868selected = this.endDate.clone();869minDate = this.startDate;870
871//Preserve the time already selected872var timeSelector = this.container.find('.drp-calendar.right .calendar-time');873if (timeSelector.html() != '') {874
875selected.hour(!isNaN(selected.hour()) ? selected.hour() : timeSelector.find('.hourselect option:selected').val());876selected.minute(!isNaN(selected.minute()) ? selected.minute() : timeSelector.find('.minuteselect option:selected').val());877selected.second(!isNaN(selected.second()) ? selected.second() : timeSelector.find('.secondselect option:selected').val());878
879if (!this.timePicker24Hour) {880var ampm = timeSelector.find('.ampmselect option:selected').val();881if (ampm === 'PM' && selected.hour() < 12)882selected.hour(selected.hour() + 12);883if (ampm === 'AM' && selected.hour() === 12)884selected.hour(0);885}886
887}888
889if (selected.isBefore(this.startDate))890selected = this.startDate.clone();891
892if (maxDate && selected.isAfter(maxDate))893selected = maxDate.clone();894
895}896
897//898// hours899//900
901html = '<select class="hourselect">';902
903var start = this.timePicker24Hour ? 0 : 1;904var end = this.timePicker24Hour ? 23 : 12;905
906for (var i = start; i <= end; i++) {907var i_in_24 = i;908if (!this.timePicker24Hour)909i_in_24 = selected.hour() >= 12 ? (i == 12 ? 12 : i + 12) : (i == 12 ? 0 : i);910
911var time = selected.clone().hour(i_in_24);912var disabled = false;913if (minDate && time.minute(59).isBefore(minDate))914disabled = true;915if (maxDate && time.minute(0).isAfter(maxDate))916disabled = true;917
918if (i_in_24 == selected.hour() && !disabled) {919html += '<option value="' + i + '" selected="selected">' + i + '</option>';920} else if (disabled) {921html += '<option value="' + i + '" disabled="disabled" class="disabled">' + i + '</option>';922} else {923html += '<option value="' + i + '">' + i + '</option>';924}925}926
927html += '</select> ';928
929//930// minutes931//932
933html += ': <select class="minuteselect">';934
935for (var i = 0; i < 60; i += this.timePickerIncrement) {936var padded = i < 10 ? '0' + i : i;937var time = selected.clone().minute(i);938
939var disabled = false;940if (minDate && time.second(59).isBefore(minDate))941disabled = true;942if (maxDate && time.second(0).isAfter(maxDate))943disabled = true;944
945if (selected.minute() == i && !disabled) {946html += '<option value="' + i + '" selected="selected">' + padded + '</option>';947} else if (disabled) {948html += '<option value="' + i + '" disabled="disabled" class="disabled">' + padded + '</option>';949} else {950html += '<option value="' + i + '">' + padded + '</option>';951}952}953
954html += '</select> ';955
956//957// seconds958//959
960if (this.timePickerSeconds) {961html += ': <select class="secondselect">';962
963for (var i = 0; i < 60; i++) {964var padded = i < 10 ? '0' + i : i;965var time = selected.clone().second(i);966
967var disabled = false;968if (minDate && time.isBefore(minDate))969disabled = true;970if (maxDate && time.isAfter(maxDate))971disabled = true;972
973if (selected.second() == i && !disabled) {974html += '<option value="' + i + '" selected="selected">' + padded + '</option>';975} else if (disabled) {976html += '<option value="' + i + '" disabled="disabled" class="disabled">' + padded + '</option>';977} else {978html += '<option value="' + i + '">' + padded + '</option>';979}980}981
982html += '</select> ';983}984
985//986// AM/PM987//988
989if (!this.timePicker24Hour) {990html += '<select class="ampmselect">';991
992var am_html = '';993var pm_html = '';994
995if (minDate && selected.clone().hour(12).minute(0).second(0).isBefore(minDate))996am_html = ' disabled="disabled" class="disabled"';997
998if (maxDate && selected.clone().hour(0).minute(0).second(0).isAfter(maxDate))999pm_html = ' disabled="disabled" class="disabled"';1000
1001if (selected.hour() >= 12) {1002html += '<option value="AM"' + am_html + '>AM</option><option value="PM" selected="selected"' + pm_html + '>PM</option>';1003} else {1004html += '<option value="AM" selected="selected"' + am_html + '>AM</option><option value="PM"' + pm_html + '>PM</option>';1005}1006
1007html += '</select>';1008}1009
1010this.container.find('.drp-calendar.' + side + ' .calendar-time').html(html);1011
1012},1013
1014updateFormInputs: function() {1015
1016if (this.singleDatePicker || (this.endDate && (this.startDate.isBefore(this.endDate) || this.startDate.isSame(this.endDate)))) {1017this.container.find('button.applyBtn').prop('disabled', false);1018} else {1019this.container.find('button.applyBtn').prop('disabled', true);1020}1021
1022},1023
1024move: function() {1025var parentOffset = { top: 0, left: 0 },1026containerTop,1027drops = this.drops;1028
1029var parentRightEdge = $(window).width();1030if (!this.parentEl.is('body')) {1031parentOffset = {1032top: this.parentEl.offset().top - this.parentEl.scrollTop(),1033left: this.parentEl.offset().left - this.parentEl.scrollLeft()1034};1035parentRightEdge = this.parentEl[0].clientWidth + this.parentEl.offset().left;1036}1037
1038switch (drops) {1039case 'auto':1040containerTop = this.element.offset().top + this.element.outerHeight() - parentOffset.top;1041if (containerTop + this.container.outerHeight() >= this.parentEl[0].scrollHeight) {1042containerTop = this.element.offset().top - this.container.outerHeight() - parentOffset.top;1043drops = 'up';1044}1045break;1046case 'up':1047containerTop = this.element.offset().top - this.container.outerHeight() - parentOffset.top;1048break;1049default:1050containerTop = this.element.offset().top + this.element.outerHeight() - parentOffset.top;1051break;1052}1053
1054// Force the container to it's actual width1055this.container.css({1056top: 0,1057left: 0,1058right: 'auto'1059});1060var containerWidth = this.container.outerWidth();1061
1062this.container.toggleClass('drop-up', drops == 'up');1063
1064if (this.opens == 'left') {1065var containerRight = parentRightEdge - this.element.offset().left - this.element.outerWidth();1066if (containerWidth + containerRight > $(window).width()) {1067this.container.css({1068top: containerTop,1069right: 'auto',1070left: 91071});1072} else {1073this.container.css({1074top: containerTop,1075right: containerRight,1076left: 'auto'1077});1078}1079} else if (this.opens == 'center') {1080var containerLeft = this.element.offset().left - parentOffset.left + this.element.outerWidth() / 21081- containerWidth / 2;1082if (containerLeft < 0) {1083this.container.css({1084top: containerTop,1085right: 'auto',1086left: 91087});1088} else if (containerLeft + containerWidth > $(window).width()) {1089this.container.css({1090top: containerTop,1091left: 'auto',1092right: 01093});1094} else {1095this.container.css({1096top: containerTop,1097left: containerLeft,1098right: 'auto'1099});1100}1101} else {1102var containerLeft = this.element.offset().left - parentOffset.left;1103if (containerLeft + containerWidth > $(window).width()) {1104this.container.css({1105top: containerTop,1106left: 'auto',1107right: 01108});1109} else {1110this.container.css({1111top: containerTop,1112left: containerLeft,1113right: 'auto'1114});1115}1116}1117},1118
1119show: function(e) {1120if (this.isShowing) return;1121
1122// Create a click proxy that is private to this instance of datepicker, for unbinding1123this._outsideClickProxy = $.proxy(function(e) { this.outsideClick(e); }, this);1124
1125// Bind global datepicker mousedown for hiding and1126$(document)1127.on('mousedown.daterangepicker', this._outsideClickProxy)1128// also support mobile devices1129.on('touchend.daterangepicker', this._outsideClickProxy)1130// also explicitly play nice with Bootstrap dropdowns, which stopPropagation when clicking them1131.on('click.daterangepicker', '[data-toggle=dropdown]', this._outsideClickProxy)1132// and also close when focus changes to outside the picker (eg. tabbing between controls)1133.on('focusin.daterangepicker', this._outsideClickProxy);1134
1135// Reposition the picker if the window is resized while it's open1136$(window).on('resize.daterangepicker', $.proxy(function(e) { this.move(e); }, this));1137
1138this.oldStartDate = this.startDate.clone();1139this.oldEndDate = this.endDate.clone();1140this.previousRightTime = this.endDate.clone();1141
1142this.updateView();1143this.container.show();1144this.move();1145this.element.trigger('show.daterangepicker', this);1146this.isShowing = true;1147},1148
1149hide: function(e) {1150if (!this.isShowing) return;1151
1152//incomplete date selection, revert to last values1153if (!this.endDate) {1154this.startDate = this.oldStartDate.clone();1155this.endDate = this.oldEndDate.clone();1156}1157
1158//if a new date range was selected, invoke the user callback function1159if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate))1160this.callback(this.startDate.clone(), this.endDate.clone(), this.chosenLabel);1161
1162//if picker is attached to a text input, update it1163this.updateElement();1164
1165$(document).off('.daterangepicker');1166$(window).off('.daterangepicker');1167this.container.hide();1168this.element.trigger('hide.daterangepicker', this);1169this.isShowing = false;1170},1171
1172toggle: function(e) {1173if (this.isShowing) {1174this.hide();1175} else {1176this.show();1177}1178},1179
1180outsideClick: function(e) {1181var target = $(e.target);1182// if the page is clicked anywhere except within the daterangerpicker/button1183// itself then call this.hide()1184if (1185// ie modal dialog fix1186e.type == "focusin" ||1187target.closest(this.element).length ||1188target.closest(this.container).length ||1189target.closest('.calendar-table').length1190) return;1191this.hide();1192this.element.trigger('outsideClick.daterangepicker', this);1193},1194
1195showCalendars: function() {1196this.container.addClass('show-calendar');1197this.move();1198this.element.trigger('showCalendar.daterangepicker', this);1199},1200
1201hideCalendars: function() {1202this.container.removeClass('show-calendar');1203this.element.trigger('hideCalendar.daterangepicker', this);1204},1205
1206clickRange: function(e) {1207var label = e.target.getAttribute('data-range-key');1208this.chosenLabel = label;1209if (label == this.locale.customRangeLabel) {1210this.showCalendars();1211} else {1212var dates = this.ranges[label];1213this.startDate = dates[0];1214this.endDate = dates[1];1215
1216if (!this.timePicker) {1217this.startDate.startOf('day');1218this.endDate.endOf('day');1219}1220
1221if (!this.alwaysShowCalendars)1222this.hideCalendars();1223this.clickApply();1224}1225},1226
1227clickPrev: function(e) {1228var cal = $(e.target).parents('.drp-calendar');1229if (cal.hasClass('left')) {1230this.leftCalendar.month.subtract(1, 'month');1231if (this.linkedCalendars)1232this.rightCalendar.month.subtract(1, 'month');1233} else {1234this.rightCalendar.month.subtract(1, 'month');1235}1236this.updateCalendars();1237},1238
1239clickNext: function(e) {1240var cal = $(e.target).parents('.drp-calendar');1241if (cal.hasClass('left')) {1242this.leftCalendar.month.add(1, 'month');1243} else {1244this.rightCalendar.month.add(1, 'month');1245if (this.linkedCalendars)1246this.leftCalendar.month.add(1, 'month');1247}1248this.updateCalendars();1249},1250
1251hoverDate: function(e) {1252
1253//ignore dates that can't be selected1254if (!$(e.target).hasClass('available')) return;1255
1256var title = $(e.target).attr('data-title');1257var row = title.substr(1, 1);1258var col = title.substr(3, 1);1259var cal = $(e.target).parents('.drp-calendar');1260var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col];1261
1262//highlight the dates between the start date and the date being hovered as a potential end date1263var leftCalendar = this.leftCalendar;1264var rightCalendar = this.rightCalendar;1265var startDate = this.startDate;1266if (!this.endDate) {1267this.container.find('.drp-calendar tbody td').each(function(index, el) {1268
1269//skip week numbers, only look at dates1270if ($(el).hasClass('week')) return;1271
1272var title = $(el).attr('data-title');1273var row = title.substr(1, 1);1274var col = title.substr(3, 1);1275var cal = $(el).parents('.drp-calendar');1276var dt = cal.hasClass('left') ? leftCalendar.calendar[row][col] : rightCalendar.calendar[row][col];1277
1278if ((dt.isAfter(startDate) && dt.isBefore(date)) || dt.isSame(date, 'day')) {1279$(el).addClass('in-range');1280} else {1281$(el).removeClass('in-range');1282}1283
1284});1285}1286
1287},1288
1289clickDate: function(e) {1290
1291if (!$(e.target).hasClass('available')) return;1292
1293var title = $(e.target).attr('data-title');1294var row = title.substr(1, 1);1295var col = title.substr(3, 1);1296var cal = $(e.target).parents('.drp-calendar');1297var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col];1298
1299//1300// this function needs to do a few things:1301// * alternate between selecting a start and end date for the range,1302// * if the time picker is enabled, apply the hour/minute/second from the select boxes to the clicked date1303// * if autoapply is enabled, and an end date was chosen, apply the selection1304// * if single date picker mode, and time picker isn't enabled, apply the selection immediately1305// * if one of the inputs above the calendars was focused, cancel that manual input1306//1307
1308if (this.endDate || date.isBefore(this.startDate, 'day')) { //picking start1309if (this.timePicker) {1310var hour = parseInt(this.container.find('.left .hourselect').val(), 10);1311if (!this.timePicker24Hour) {1312var ampm = this.container.find('.left .ampmselect').val();1313if (ampm === 'PM' && hour < 12)1314hour += 12;1315if (ampm === 'AM' && hour === 12)1316hour = 0;1317}1318var minute = parseInt(this.container.find('.left .minuteselect').val(), 10);1319if (isNaN(minute)) {1320minute = parseInt(this.container.find('.left .minuteselect option:last').val(), 10);1321}1322var second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0;1323date = date.clone().hour(hour).minute(minute).second(second);1324}1325this.endDate = null;1326this.setStartDate(date.clone());1327} else if (!this.endDate && date.isBefore(this.startDate)) {1328//special case: clicking the same date for start/end,1329//but the time of the end date is before the start date1330this.setEndDate(this.startDate.clone());1331} else { // picking end1332if (this.timePicker) {1333var hour = parseInt(this.container.find('.right .hourselect').val(), 10);1334if (!this.timePicker24Hour) {1335var ampm = this.container.find('.right .ampmselect').val();1336if (ampm === 'PM' && hour < 12)1337hour += 12;1338if (ampm === 'AM' && hour === 12)1339hour = 0;1340}1341var minute = parseInt(this.container.find('.right .minuteselect').val(), 10);1342if (isNaN(minute)) {1343minute = parseInt(this.container.find('.right .minuteselect option:last').val(), 10);1344}1345var second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;1346date = date.clone().hour(hour).minute(minute).second(second);1347}1348this.setEndDate(date.clone());1349if (this.autoApply) {1350this.calculateChosenLabel();1351this.clickApply();1352}1353}1354
1355if (this.singleDatePicker) {1356this.setEndDate(this.startDate);1357if (!this.timePicker && this.autoApply)1358this.clickApply();1359}1360
1361this.updateView();1362
1363//This is to cancel the blur event handler if the mouse was in one of the inputs1364e.stopPropagation();1365
1366},1367
1368calculateChosenLabel: function () {1369var customRange = true;1370var i = 0;1371for (var range in this.ranges) {1372if (this.timePicker) {1373var format = this.timePickerSeconds ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD HH:mm";1374//ignore times when comparing dates if time picker seconds is not enabled1375if (this.startDate.format(format) == this.ranges[range][0].format(format) && this.endDate.format(format) == this.ranges[range][1].format(format)) {1376customRange = false;1377this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').attr('data-range-key');1378break;1379}1380} else {1381//ignore times when comparing dates if time picker is not enabled1382if (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')) {1383customRange = false;1384this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').attr('data-range-key');1385break;1386}1387}1388i++;1389}1390if (customRange) {1391if (this.showCustomRangeLabel) {1392this.chosenLabel = this.container.find('.ranges li:last').addClass('active').attr('data-range-key');1393} else {1394this.chosenLabel = null;1395}1396this.showCalendars();1397}1398},1399
1400clickApply: function(e) {1401this.hide();1402this.element.trigger('apply.daterangepicker', this);1403},1404
1405clickCancel: function(e) {1406this.startDate = this.oldStartDate;1407this.endDate = this.oldEndDate;1408this.hide();1409this.element.trigger('cancel.daterangepicker', this);1410},1411
1412monthOrYearChanged: function(e) {1413var isLeft = $(e.target).closest('.drp-calendar').hasClass('left'),1414leftOrRight = isLeft ? 'left' : 'right',1415cal = this.container.find('.drp-calendar.'+leftOrRight);1416
1417// Month must be Number for new moment versions1418var month = parseInt(cal.find('.monthselect').val(), 10);1419var year = cal.find('.yearselect').val();1420
1421if (!isLeft) {1422if (year < this.startDate.year() || (year == this.startDate.year() && month < this.startDate.month())) {1423month = this.startDate.month();1424year = this.startDate.year();1425}1426}1427
1428if (this.minDate) {1429if (year < this.minDate.year() || (year == this.minDate.year() && month < this.minDate.month())) {1430month = this.minDate.month();1431year = this.minDate.year();1432}1433}1434
1435if (this.maxDate) {1436if (year > this.maxDate.year() || (year == this.maxDate.year() && month > this.maxDate.month())) {1437month = this.maxDate.month();1438year = this.maxDate.year();1439}1440}1441
1442if (isLeft) {1443this.leftCalendar.month.month(month).year(year);1444if (this.linkedCalendars)1445this.rightCalendar.month = this.leftCalendar.month.clone().add(1, 'month');1446} else {1447this.rightCalendar.month.month(month).year(year);1448if (this.linkedCalendars)1449this.leftCalendar.month = this.rightCalendar.month.clone().subtract(1, 'month');1450}1451this.updateCalendars();1452},1453
1454timeChanged: function(e) {1455
1456var cal = $(e.target).closest('.drp-calendar'),1457isLeft = cal.hasClass('left');1458
1459var hour = parseInt(cal.find('.hourselect').val(), 10);1460var minute = parseInt(cal.find('.minuteselect').val(), 10);1461if (isNaN(minute)) {1462minute = parseInt(cal.find('.minuteselect option:last').val(), 10);1463}1464var second = this.timePickerSeconds ? parseInt(cal.find('.secondselect').val(), 10) : 0;1465
1466if (!this.timePicker24Hour) {1467var ampm = cal.find('.ampmselect').val();1468if (ampm === 'PM' && hour < 12)1469hour += 12;1470if (ampm === 'AM' && hour === 12)1471hour = 0;1472}1473
1474if (isLeft) {1475var start = this.startDate.clone();1476start.hour(hour);1477start.minute(minute);1478start.second(second);1479this.setStartDate(start);1480if (this.singleDatePicker) {1481this.endDate = this.startDate.clone();1482} else if (this.endDate && this.endDate.format('YYYY-MM-DD') == start.format('YYYY-MM-DD') && this.endDate.isBefore(start)) {1483this.setEndDate(start.clone());1484}1485} else if (this.endDate) {1486var end = this.endDate.clone();1487end.hour(hour);1488end.minute(minute);1489end.second(second);1490this.setEndDate(end);1491}1492
1493//update the calendars so all clickable dates reflect the new time component1494this.updateCalendars();1495
1496//update the form inputs above the calendars with the new time1497this.updateFormInputs();1498
1499//re-render the time pickers because changing one selection can affect what's enabled in another1500this.renderTimePicker('left');1501this.renderTimePicker('right');1502
1503},1504
1505elementChanged: function() {1506if (!this.element.is('input')) return;1507if (!this.element.val().length) return;1508
1509var dateString = this.element.val().split(this.locale.separator),1510start = null,1511end = null;1512
1513if (dateString.length === 2) {1514start = moment(dateString[0], this.locale.format);1515end = moment(dateString[1], this.locale.format);1516}1517
1518if (this.singleDatePicker || start === null || end === null) {1519start = moment(this.element.val(), this.locale.format);1520end = start;1521}1522
1523if (!start.isValid() || !end.isValid()) return;1524
1525this.setStartDate(start);1526this.setEndDate(end);1527this.updateView();1528},1529
1530keydown: function(e) {1531//hide on tab or enter1532if ((e.keyCode === 9) || (e.keyCode === 13)) {1533this.hide();1534}1535
1536//hide on esc and prevent propagation1537if (e.keyCode === 27) {1538e.preventDefault();1539e.stopPropagation();1540
1541this.hide();1542}1543},1544
1545updateElement: function() {1546if (this.element.is('input') && this.autoUpdateInput) {1547var newValue = this.startDate.format(this.locale.format);1548if (!this.singleDatePicker) {1549newValue += this.locale.separator + this.endDate.format(this.locale.format);1550}1551if (newValue !== this.element.val()) {1552this.element.val(newValue).trigger('change');1553}1554}1555},1556
1557remove: function() {1558this.container.remove();1559this.element.off('.daterangepicker');1560this.element.removeData();1561}1562
1563};1564
1565$.fn.daterangepicker = function(options, callback) {1566var implementOptions = $.extend(true, {}, $.fn.daterangepicker.defaultOptions, options);1567this.each(function() {1568var el = $(this);1569if (el.data('daterangepicker'))1570el.data('daterangepicker').remove();1571el.data('daterangepicker', new DateRangePicker(el, implementOptions, callback));1572});1573return this;1574};1575
1576return DateRangePicker;1577
1578}));1579