diff --git a/plugins/daterangepicker/daterangepicker.js b/plugins/daterangepicker/daterangepicker.js index 228612b9b..be710052f 100755 --- a/plugins/daterangepicker/daterangepicker.js +++ b/plugins/daterangepicker/daterangepicker.js @@ -1,5 +1,5 @@ /** -* @version: 1.3.21 +* @version: 2.1.19 * @author: Dan Grossman http://www.dangrossman.info/ * @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 @@ -14,544 +14,991 @@ }); } 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'); - } + var momentjs = require('moment'); + var jQuery = (typeof window != 'undefined') ? window.jQuery : undefined; //isomorphic issue + if (!jQuery) { + try { + jQuery = require('jquery'); + if (!jQuery.fn) jQuery.fn = {}; //isomorphic issue + } catch (err) { + if (!jQuery) throw new Error('jQuery dependency not found'); + } + } factory(root, exports, momentjs, jQuery); // Finally, as a browser global. } else { - root.daterangepicker = factory(root, {}, root.moment, (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, $) { // 'this' doesn't exist on a server - var DateRangePicker = function (element, options, cb) { + var DateRangePicker = function(element, options, cb) { - // by default, the daterangepicker element is placed at the bottom of HTML body + //default settings for options this.parentEl = 'body'; - - //element that triggered the date range picker this.element = $(element); - - //tracks visible state + this.startDate = moment().startOf('day'); + this.endDate = moment().endOf('day'); + this.minDate = false; + this.maxDate = false; + this.dateLimit = false; + this.autoApply = false; + this.singleDatePicker = false; + this.showDropdowns = false; + this.showWeekNumbers = false; + this.showISOWeekNumbers = false; + this.timePicker = false; + this.timePicker24Hour = false; + this.timePickerIncrement = 1; + this.timePickerSeconds = false; + this.linkedCalendars = true; + this.autoUpdateInput = true; + this.alwaysShowCalendars = false; + this.ranges = {}; + + this.opens = 'right'; + if (this.element.hasClass('pull-right')) + this.opens = 'left'; + + this.drops = 'down'; + if (this.element.hasClass('dropup')) + this.drops = 'up'; + + this.buttonClasses = 'btn btn-sm'; + this.applyClass = 'btn-success'; + this.cancelClass = 'btn-default'; + + this.locale = { + format: 'MM/DD/YYYY', + separator: ' - ', + applyLabel: 'Apply', + cancelLabel: 'Cancel', + weekLabel: 'W', + customRangeLabel: 'Custom Range', + daysOfWeek: moment.weekdaysMin(), + monthNames: moment.monthsShort(), + firstDay: moment.localeData().firstDayOfWeek() + }; + + this.callback = function() { }; + + //some state information this.isShowing = false; + this.leftCalendar = {}; + this.rightCalendar = {}; - //create the picker HTML object - var DRPTemplate = '
'; - // 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); + if ((!minDate || minDate.isBefore(calendar.firstDay)) && (!this.linkedCalendars || side == 'left')) { + html += ' | '; } else { - this.timeZone = moment(this.startDate).utcOffset(); + html += ' | '; } - if (typeof options.ranges === 'object') { - for (range in options.ranges) { - - 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 - // outside of the min/max. - if (this.minDate && start.isBefore(this.minDate)) - start = moment(this.minDate); - - if (this.maxDate && end.isAfter(this.maxDate)) - end = moment(this.maxDate); - - // If the end of the range is before the minimum (if min is set) OR - // the start of the range is after the max (also if set) don't display this - // range option. - if ((this.minDate && end.isBefore(this.minDate)) || (this.maxDate && start.isAfter(this.maxDate))) { - continue; - } + var dateHtml = this.locale.monthNames[calendar[1][1].month()] + calendar[1][1].format(" YYYY"); - this.ranges[range] = [start, end]; + if (this.showDropdowns) { + var currentMonth = calendar[1][1].month(); + var currentYear = calendar[1][1].year(); + var maxYear = (maxDate && maxDate.year()) || (currentYear + 5); + var minYear = (minDate && minDate.year()) || (currentYear - 50); + var inMinYear = currentYear == minYear; + var inMaxYear = currentYear == maxYear; + + var monthHtml = '"; - var list = ' | ' + dateHtml + ' | '; + if ((!maxDate || maxDate.isAfter(calendar.lastDay)) && (!this.linkedCalendars || side == 'right' || this.singleDatePicker)) { + html += ''; } else { - this.container.removeClass('single'); - this.container.find('.calendar.right').removeClass('single'); - this.container.find('.ranges').show(); + html += ' | '; } - this.oldStartDate = this.startDate.clone(); - this.oldEndDate = this.endDate.clone(); - this.oldChosenLabel = this.chosenLabel; - - this.leftCalendar = { - 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(), this.endDate.second()]), - calendar: [] - }; - - if (this.opens == 'right' || this.opens == 'center') { - //swap calendar positions - var first = this.container.find('.calendar.first'); - var second = this.container.find('.calendar.second'); - - if (second.hasClass('single')) { - second.removeClass('single'); - first.addClass('single'); - } + html += ' | ||||
---|---|---|---|---|---|---|---|---|---|
' + this.locale.weekLabel + ' | '; - if (this.singleDatePicker) { - first.show(); - second.hide(); + $.each(this.locale.daysOfWeek, function(index, dayOfWeek) { + html += '' + dayOfWeek + ' | '; + }); + + html += '||||||||
' + calendar[row][0].week() + ' | '; + else if (this.showISOWeekNumbers) + html += '' + calendar[row][0].isoWeek() + ' | '; + + for (var col = 0; col < 7; col++) { + + var classes = []; + + //highlight today's date + if (calendar[row][col].isSame(new Date(), "day")) + classes.push('today'); + + //highlight weekends + if (calendar[row][col].isoWeekday() > 5) + classes.push('weekend'); + + //grey out the dates in other months displayed at beginning and end of this calendar + if (calendar[row][col].month() != calendar[1][1].month()) + classes.push('off'); + + //don't allow selection of dates before the minimum date + if (this.minDate && calendar[row][col].isBefore(this.minDate, 'day')) + classes.push('off', 'disabled'); + + //don't allow selection of dates after the maximum date + if (maxDate && calendar[row][col].isAfter(maxDate, 'day')) + classes.push('off', 'disabled'); + + //don't allow selection of date if a custom function decides it's invalid + if (this.isInvalidDate(calendar[row][col])) + classes.push('off', 'disabled'); + + //highlight the currently selected start date + if (calendar[row][col].format('YYYY-MM-DD') == this.startDate.format('YYYY-MM-DD')) + classes.push('active', 'start-date'); + + //highlight the currently selected end date + if (this.endDate != null && calendar[row][col].format('YYYY-MM-DD') == this.endDate.format('YYYY-MM-DD')) + classes.push('active', 'end-date'); + + //highlight dates in-between the selected dates + if (this.endDate != null && calendar[row][col] > this.startDate && calendar[row][col] < this.endDate) + classes.push('in-range'); + + var cname = '', disabled = false; + for (var i = 0; i < classes.length; i++) { + cname += classes[i] + ' '; + if (classes[i] == 'disabled') + disabled = true; + } + if (!disabled) + cname += 'available'; + + html += '' + calendar[row][col].date() + ' | '; + + } + html += '
'; - - if (!minDate || minDate.isBefore(calendar.firstDay)) { - html += ' | '; - } else { - html += ' | '; - } + elementChanged: function() { + if (!this.element.is('input')) return; + if (!this.element.val().length) return; + if (this.element.val().length < this.locale.format.length) return; - var dateHtml = this.locale.monthNames[calendar[1][1].month()] + calendar[1][1].format(" YYYY"); + var dateString = this.element.val().split(this.locale.separator), + start = null, + end = null; - if (this.showDropdowns) { - dateHtml = this.renderDropdowns(calendar[1][1], minDate, maxDate); + if (dateString.length === 2) { + start = moment(dateString[0], this.locale.format); + end = moment(dateString[1], this.locale.format); } - html += ' | ' + dateHtml + ' | '; - if (!maxDate || maxDate.isAfter(calendar.lastDay)) { - html += ''; - } else { - html += ' | '; + if (this.singleDatePicker || start === null || end === null) { + start = moment(this.element.val(), this.locale.format); + end = start; } - html += ' | ||||
---|---|---|---|---|---|---|---|---|---|
' + this.locale.weekLabel + ' | '; - - $.each(this.locale.daysOfWeek, function (index, dayOfWeek) { - html += '' + dayOfWeek + ' | '; - }); - - html += '||||||||
' + calendar[row][0].week() + ' | '; + if (!start.isValid() || !end.isValid()) return; - for (var col = 0; col < 7; col++) { - var cname = 'available '; - cname += (calendar[row][col].month() == calendar[1][1].month()) ? '' : 'off'; - - 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 '; - if (calendar[row][col].format('YYYY-MM-DD') == this.startDate.format('YYYY-MM-DD')) { - cname += ' start-date '; - } - if (calendar[row][col].format('YYYY-MM-DD') == this.endDate.format('YYYY-MM-DD')) { - cname += ' end-date '; - } - } else if (calendar[row][col] >= this.startDate && calendar[row][col] <= this.endDate) { - cname += ' in-range '; - if (calendar[row][col].isSame(this.startDate)) { cname += ' start-date '; } - if (calendar[row][col].isSame(this.endDate)) { cname += ' end-date '; } - } + this.setStartDate(start); + this.setEndDate(end); + this.updateView(); + }, - var title = 'r' + row + 'c' + col; - html += '' + calendar[row][col].date() + ' | '; - } - html += '