PageSourceSearch

https://hotelsbyweek.com/libs/daterange/daterangepicker.min.js

js hotelsbyweek.com collected 2026-10-01 15:39:02 UTC 67,077 bytes, 1,596 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.