PageSourceSearch

https://mediumslateblue-tarsier-840752.hostingersite.com/wp-conten…/listeo/js/daterangepicker.js?ver=1.9.54

js mediumslateblue-tarsier-840752.hostingersite.com collected 2026-10-03 04:41:37 UTC 65,492 bytes, 1,565 lines download raw bytes

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

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.