PageSourceSearch

https://uzdroje.cz/wp-content/themes/listeo/js/daterangepicker.js?ver=1.7

js uzdroje.cz collected 2026-10-05 11:13:24 UTC 64,972 bytes, 1,547 lines download raw bytes

vendor: 40,748 bytes, lines 1-954
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        setEndDate: function(endDate) {
502            if (typeof endDate === 'string')
503                this.endDate = moment(endDate, this.locale.format);
504
505            if (typeof endDate === 'object')
506                this.endDate = moment(endDate);
507
508            if (!this.timePicker)
509                this.endDate = this.endDate.add(1,'d').startOf('day').subtract(1,'second');
510
511            if (this.timePicker && this.timePickerIncrement)
512                this.endDate.minute(Math.round(this.endDate.minute() / this.timePickerIncrement) * this.timePickerIncrement);
513
514            if (this.endDate.isBefore(this.startDate))
515                this.endDate = this.startDate.clone();
516
517            if (this.minSpan && this.endDate.clone().isBefore(this.startDate.clone().add(this.minSpan))) {
518                this.endDate = this.startDate.clone().add(this.minSpan).subtract(1, 'day').endOf('day');
519            }
520
521            if (this.maxDate && this.endDate.isAfter(this.maxDate))
522                this.endDate = this.maxDate.clone();
523
524            if (this.maxSpan && this.startDate.clone().add(this.maxSpan).isBefore(this.endDate))
525                this.endDate = this.startDate.clone().add(this.maxSpan);
526
527            this.previousRightTime = this.endDate.clone();
528
529            this.container.find('.drp-selected').html(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));
530
531            if (!this.isShowing)
532                this.updateElement();
533
534            this.updateMonthsInView();
535        },
536
537        isInvalidDate: function() {
538            return false;
539        },
540
541        isCustomDate: function() {
542            return false;
543        },
544
545        updateView: function() {
546            if (this.timePicker) {
547                this.renderTimePicker('left');
548                this.renderTimePicker('right');
549                if (!this.endDate) {
550                    this.container.find('.right .calendar-time select').attr('disabled', 'disabled').addClass('disabled');
551                } else {
552                    this.container.find('.right .calendar-time select').removeAttr('disabled').removeClass('disabled');
553                }
554            }
555            if (this.endDate)
556                this.container.find('.drp-selected').html(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format));
557            this.updateMonthsInView();
558            this.updateCalendars();
559            this.updateFormInputs();
560        },
561
562        updateMonthsInView: function() {
563            if (this.endDate) {
564
565                //if both dates are visible already, do nothing
566                if (!this.singleDatePicker && this.leftCalendar.month && this.rightCalendar.month &&
567                    (this.startDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.startDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM'))
568                    &&
569                    (this.endDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.endDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM'))
570                    ) {
571                    return;
572                }
573
574                this.leftCalendar.month = this.startDate.clone().date(2);
575                if (!this.linkedCalendars && (this.endDate.month() != this.startDate.month() || this.endDate.year() != this.startDate.year())) {
576                    this.rightCalendar.month = this.endDate.clone().date(2);
577                } else {
578                    this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month');
579                }
580
581            } else {
582                if (this.leftCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM') && this.rightCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM')) {
583                    this.leftCalendar.month = this.startDate.clone().date(2);
584                    this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month');
585                }
586            }
587            if (this.maxDate && this.linkedCalendars && !this.singleDatePicker && this.rightCalendar.month > this.maxDate) {
588              this.rightCalendar.month = this.maxDate.clone().date(2);
589              this.leftCalendar.month = this.maxDate.clone().date(2).subtract(1, 'month');
590            }
591        },
592
593        updateCalendars: function() {
594
595            if (this.timePicker) {
596                var hour, minute, second;
597                if (this.endDate) {
598                    hour = parseInt(this.container.find('.left .hourselect').val(), 10);
599                    minute = parseInt(this.container.find('.left .minuteselect').val(), 10);
600                    second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0;
601                    if (!this.timePicker24Hour) {
602                        var ampm = this.container.find('.left .ampmselect').val();
603                        if (ampm === 'PM' && hour < 12)
604                            hour += 12;
605                        if (ampm === 'AM' && hour === 12)
606                            hour = 0;
607                    }
608                } else {
609                    hour = parseInt(this.container.find('.right .hourselect').val(), 10);
610                    minute = parseInt(this.container.find('.right .minuteselect').val(), 10);
611                    second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;
612                    if (!this.timePicker24Hour) {
613                        var ampm = this.container.find('.right .ampmselect').val();
614                        if (ampm === 'PM' && hour < 12)
615                            hour += 12;
616                        if (ampm === 'AM' && hour === 12)
617                            hour = 0;
618                    }
619                }
620                this.leftCalendar.month.hour(hour).minute(minute).second(second);
621                this.rightCalendar.month.hour(hour).minute(minute).second(second);
622            }
623
624            this.renderCalendar('left');
625            this.renderCalendar('right');
626
627            //highlight any predefined range matching the current start and end dates
628            this.container.find('.ranges li').removeClass('active');
629            if (this.endDate == null) return;
630
631            this.calculateChosenLabel();
632        },
633
634        renderCalendar: function(side) {
635
636            //
637            // Build the matrix of dates that will populate the calendar
638            //
639
640            var calendar = side == 'left' ? this.leftCalendar : this.rightCalendar;
641            var month = calendar.month.month();
642            var year = calendar.month.year();
643            var hour = calendar.month.hour();
644            var minute = calendar.month.minute();
645            var second = calendar.month.second();
646            var daysInMonth = moment([year, month]).daysInMonth();
647            var firstDay = moment([year, month, 1]);
648            var lastDay = moment([year, month, daysInMonth]);
649            var lastMonth = moment(firstDay).subtract(1, 'month').month();
650            var lastYear = moment(firstDay).subtract(1, 'month').year();
651            var daysInLastMonth = moment([lastYear, lastMonth]).daysInMonth();
652            var dayOfWeek = firstDay.day();
653
654            //initialize a 6 rows x 7 columns array for the calendar
655            var calendar = [];
656            calendar.firstDay = firstDay;
657            calendar.lastDay = lastDay;
658
659            for (var i = 0; i < 6; i++) {
660                calendar[i] = [];
661            }
662
663            //populate the calendar with date objects
664            var startDay = daysInLastMonth - dayOfWeek + this.locale.firstDay + 1;
665            if (startDay > daysInLastMonth)
666                startDay -= 7;
667
668            if (dayOfWeek == this.locale.firstDay)
669                startDay = daysInLastMonth - 6;
670
671            var curDate = moment([lastYear, lastMonth, startDay, 12, minute, second]);
672
673            var col, row;
674            for (var i = 0, col = 0, row = 0; i < 42; i++, col++, curDate = moment(curDate).add(24, 'hour')) {
675                if (i > 0 && col % 7 === 0) {
676                    col = 0;
677                    row++;
678                }
679                calendar[row][col] = curDate.clone().hour(hour).minute(minute).second(second);
680                curDate.hour(12);
681
682                if (this.minDate && calendar[row][col].format('YYYY-MM-DD') == this.minDate.format('YYYY-MM-DD') && calendar[row][col].isBefore(this.minDate) && side == 'left') {
683                    calendar[row][col] = this.minDate.clone();
684                }
685
686                if (this.maxDate && calendar[row][col].format('YYYY-MM-DD') == this.maxDate.format('YYYY-MM-DD') && calendar[row][col].isAfter(this.maxDate) && side == 'right') {
687                    calendar[row][col] = this.maxDate.clone();
688                }
689
690            }
691
692            //make the calendar object available to hoverDate/clickDate
693            if (side == 'left') {
694                this.leftCalendar.calendar = calendar;
695            } else {
696                this.rightCalendar.calendar = calendar;
697            }
698
699            //
700            // Display the calendar
701            //
702
703            var minDate = side == 'left' ? this.minDate : this.startDate;
704            var maxDate = this.maxDate;
705            var selected = side == 'left' ? this.startDate : this.endDate;
706            var arrow = this.locale.direction == 'ltr' ? {left: 'chevron-left', right: 'chevron-right'} : {left: 'chevron-right', right: 'chevron-left'};
707
708            var html = '<table class="table-condensed">';
709            html += '<thead>';
710            html += '<tr>';
711
712            // add empty cell for week number
713            if (this.showWeekNumbers || this.showISOWeekNumbers)
714                html += '<th></th>';
715
716            if ((!minDate || minDate.isBefore(calendar.firstDay)) && (!this.linkedCalendars || side == 'left')) {
717                html += '<th class="prev available"><span></span></th>';
718            } else {
719                html += '<th></th>';
720            }
721
722            var dateHtml = this.locale.monthNames[calendar[1][1].month()] + calendar[1][1].format(" YYYY");
723
724            if (this.showDropdowns) {
725                var currentMonth = calendar[1][1].month();
726                var currentYear = calendar[1][1].year();
727                var maxYear = (maxDate && maxDate.year()) || (this.maxYear);
728                var minYear = (minDate && minDate.year()) || (this.minYear);
729                var inMinYear = currentYear == minYear;
730                var inMaxYear = currentYear == maxYear;
731
732                var monthHtml = '<select class="monthselect">';
733                for (var m = 0; m < 12; m++) {
734                    if ((!inMinYear || m >= minDate.month()) && (!inMaxYear || m <= maxDate.month())) {
735                        monthHtml += "<option value='" + m + "'" +
736                            (m === currentMonth ? " selected='selected'" : "") +
737                            ">" + this.locale.monthNames[m] + "</option>";
738                    } else {
739                        monthHtml += "<option value='" + m + "'" +
740                            (m === currentMonth ? " selected='selected'" : "") +
741                            " disabled='disabled'>" + this.locale.monthNames[m] + "</option>";
742                    }
743                }
744                monthHtml += "</select>";
745
746                var yearHtml = '<select class="yearselect">';
747                for (var y = minYear; y <= maxYear; y++) {
748                    yearHtml += '<option value="' + y + '"' +
749                        (y === currentYear ? ' selected="selected"' : '') +
750                        '>' + y + '</option>';
751                }
752                yearHtml += '</select>';
753
754                dateHtml = monthHtml + yearHtml;
755            }
756
757            html += '<th colspan="5" class="month">' + dateHtml + '</th>';
758            if ((!maxDate || maxDate.isAfter(calendar.lastDay)) && (!this.linkedCalendars || side == 'right' || this.singleDatePicker)) {
759                html += '<th class="next available"><span></span></th>';
760            } else {
761                html += '<th></th>';
762            }
763
764            html += '</tr>';
765            html += '<tr>';
766
767            // add week number label
768            if (this.showWeekNumbers || this.showISOWeekNumbers)
769                html += '<th class="week">' + this.locale.weekLabel + '</th>';
770
771            $.each(this.locale.daysOfWeek, function(index, dayOfWeek) {
772                html += '<th>' + dayOfWeek + '</th>';
773            });
774
775            html += '</tr>';
776            html += '</thead>';
777            html += '<tbody>';
778
779            //adjust maxDate to reflect the maxSpan setting in order to
780            //grey out end dates beyond the maxSpan
781            if (this.endDate == null && this.maxSpan) {
782                var maxLimit = this.startDate.clone().add(this.maxSpan).endOf('day');
783                if (!maxDate || maxLimit.isBefore(maxDate)) {
784                    maxDate = maxLimit;
785                }
786            }
787
788            for (var row = 0; row < 6; row++) {
789                html += '<tr>';
790
791                // add week number
792                if (this.showWeekNumbers)
793                    html += '<td class="week">' + calendar[row][0].week() + '</td>';
794                else if (this.showISOWeekNumbers)
795                    html += '<td class="week">' + calendar[row][0].isoWeek() + '</td>';
796
797                for (var col = 0; col < 7; col++) {
798
799                    var classes = [];
800
801                    //highlight today's date
802                    if (calendar[row][col].isSame(new Date(), "day"))
803                        classes.push('today');
804
805                    //highlight weekends
806                    if (calendar[row][col].isoWeekday() > 5)
807                        classes.push('weekend');
808
809                    //grey out the dates in other months displayed at beginning and end of this calendar
810                    if (calendar[row][col].month() != calendar[1][1].month())
811                        classes.push('off');
812
813                    //don't allow selection of dates before the minimum date
814                    if (this.minDate && calendar[row][col].isBefore(this.minDate, 'day'))
815                        classes.push('off', 'disabled');
816
817                    //don't allow selection of dates after the maximum date
818                    if (maxDate && calendar[row][col].isAfter(maxDate, 'day'))
819                        classes.push('off', 'disabled');
820
821                    //don't allow selection of date if a custom function decides it's invalid
822                    if (this.isInvalidDate(calendar[row][col]))
823                        classes.push('off', 'disabled');
824
825                    //highlight the currently selected start date
826                    if (calendar[row][col].format('YYYY-MM-DD') == this.startDate.format('YYYY-MM-DD'))
827                        classes.push('active', 'start-date');
828
829                    //highlight the currently selected end date
830                    if (this.endDate != null && calendar[row][col].format('YYYY-MM-DD') == this.endDate.format('YYYY-MM-DD'))
831                        classes.push('active', 'end-date');
832
833                    //highlight dates in-between the selected dates
834                    if (this.endDate != null && calendar[row][col] > this.startDate && calendar[row][col] < this.endDate)
835                        classes.push('in-range');
836
837                    //apply custom classes for this date
838                    var isCustom = this.isCustomDate(calendar[row][col]);
839                    if (isCustom !== false) {
840                        if (typeof isCustom === 'string')
841                            classes.push(isCustom);
842                        else
843                            Array.prototype.push.apply(classes, isCustom);
844                    }
845
846                    var cname = '', disabled = false;
847                    for (var i = 0; i < classes.length; i++) {
848                        cname += classes[i] + ' ';
849                        if (classes[i] == 'disabled')
850                            disabled = true;
851                    }
852                    if (!disabled)
853                        cname += 'available';
854
855                    html += '<td class="' + cname.replace(/^\s+|\s+$/g, '') + '" data-title="' + 'r' + row + 'c' + col + '">' + calendar[row][col].date() + '</td>';
856
857                }
858                html += '</tr>';
859            }
860
861            html += '</tbody>';
862            html += '</table>';
863
864            this.container.find('.drp-calendar.' + side + ' .calendar-table').html(html);
865
866        },
867
868        renderTimePicker: function(side) {
869
870            // Don't bother updating the time picker if it's currently disabled
871            // because an end date hasn't been clicked yet
872            if (side == 'right' && !this.endDate) return;
873
874            var html, selected, minDate, maxDate = this.maxDate;
875
876            if (this.maxSpan && (!this.maxDate || this.startDate.clone().add(this.maxSpan).isAfter(this.maxDate)))
877                maxDate = this.startDate.clone().add(this.maxSpan);
878
879            if (side == 'left') {
880                selected = this.startDate.clone();
881                minDate = this.minDate;
882            } else if (side == 'right') {
883                selected = this.endDate.clone();
884                minDate = this.startDate;
885
886                //Preserve the time already selected
887                var timeSelector = this.container.find('.drp-calendar.right .calendar-time');
888                if (timeSelector.html() != '') {
889
890                    selected.hour(selected.hour() || timeSelector.find('.hourselect option:selected').val());
891                    selected.minute(selected.minute() || timeSelector.find('.minuteselect option:selected').val());
892                    selected.second(selected.second() || timeSelector.find('.secondselect option:selected').val());
893
894                    if (!this.timePicker24Hour) {
895                        var ampm = timeSelector.find('.ampmselect option:selected').val();
896                        if (ampm === 'PM' && selected.hour() < 12)
897                            selected.hour(selected.hour() + 12);
898                        if (ampm === 'AM' && selected.hour() === 12)
899                            selected.hour(0);
900                    }
901
902                }
903
904                if (selected.isBefore(this.startDate))
905                    selected = this.startDate.clone();
906
907                if (maxDate && selected.isAfter(maxDate))
908                    selected = maxDate.clone();
909
910            }
911
912            //
913            // hours
914            //
915
916            html = '<select class="hourselect">';
917
918            var start = this.timePicker24Hour ? 0 : 1;
919            var end = this.timePicker24Hour ? 23 : 12;
920
921            for (var i = start; i <= end; i++) {
922                var i_in_24 = i;
923                if (!this.timePicker24Hour)
924                    i_in_24 = selected.hour() >= 12 ? (i == 12 ? 12 : i + 12) : (i == 12 ? 0 : i);
925
926                var time = selected.clone().hour(i_in_24);
927                var disabled = false;
928                if (minDate && time.minute(59).isBefore(minDate))
929                    disabled = true;
930                if (maxDate && time.minute(0).isAfter(maxDate))
931                    disabled = true;
932
933                if (i_in_24 == selected.hour() && !disabled) {
934                    html += '<option value="' + i + '" selected="selected">' + i + '</option>';
935                } else if (disabled) {
936                    html += '<option value="' + i + '" disabled="disabled" class="disabled">' + i + '</option>';
937                } else {
938                    html += '<option value="' + i + '">' + i + '</option>';
939                }
940            }
941
942            html += '</select> ';
943
944            //
945            // minutes
946            //
947
948            html += ': <select class="minuteselect">';
949
950            for (var i = 0; i < 60; i += this.timePickerIncrement) {
951                var padded = i < 10 ? '0' + i : i;
952                var time = selected.clone().minute(i);
953
954                var disabled = false;
955                if (minDate && time.second(59).isBefore(minDate))
956                    disabled = true;
957                if (maxDate && time.second(0).isAfter(maxDate))
958                    disabled = true;
959
960                if (selected.minute() == i && !disabled) {
961                    html += '<option value="' + i + '" selected="selected">' + padded + '</option>';
962                } else if (disabled) {
963                    html += '<option value="' + i + '" disabled="disabled" class="disabled">' + padded + '</option>';
964                } else {
965                    html += '<option value="' + i + '">' + padded + '</option>';
966                }
967            }
968
969            html += '</select> ';
970
971            //
972            // seconds
973            //
974
975            if (this.timePickerSeconds) {
976                html += ': <select class="secondselect">';
977
978                for (var i = 0; i < 60; i++) {
979                    var padded = i < 10 ? '0' + i : i;
980                    var time = selected.clone().second(i);
981
982                    var disabled = false;
983                    if (minDate && time.isBefore(minDate))
984                        disabled = true;
985                    if (maxDate && time.isAfter(maxDate))
986                        disabled = true;
987
988                    if (selected.second() == i && !disabled) {
989                        html += '<option value="' + i + '" selected="selected">' + padded + '</option>';
990                    } else if (disabled) {
991                        html += '<option value="' + i + '" disabled="disabled" class="disabled">' + padded + '</option>';
992                    } else {
993                        html += '<option value="' + i + '">' + padded + '</option>';
994                    }
995                }
996
997                html += '</select> ';
998            }
999
1000            //
1001            // AM/PM
1002            //
1003
1004            if (!this.timePicker24Hour) {
1005                html += '<select class="ampmselect">';
1006
1007                var am_html = '';
1008                var pm_html = '';
1009
1010                if (minDate && selected.clone().hour(12).minute(0).second(0).isBefore(minDate))
1011                    am_html = ' disabled="disabled" class="disabled"';
1012
1013                if (maxDate && selected.clone().hour(0).minute(0).second(0).isAfter(maxDate))
1014                    pm_html = ' disabled="disabled" class="disabled"';
1015
1016                if (selected.hour() >= 12) {
1017                    html += '<option value="AM"' + am_html + '>AM</option><option value="PM" selected="selected"' + pm_html + '>PM</option>';
1018                } else {
1019                    html += '<option value="AM" selected="selected"' + am_html + '>AM</option><option value="PM"' + pm_html + '>PM</option>';
1020                }
1021
1022                html += '</select>';
1023            }
1024
1025            this.container.find('.drp-calendar.' + side + ' .calendar-time').html(html);
1026
1027        },
1028
1029        updateFormInputs: function() {
1030
1031            if (this.singleDatePicker || (this.endDate && (this.startDate.isBefore(this.endDate) || this.startDate.isSame(this.endDate)))) {
1032                this.container.find('button.applyBtn').removeAttr('disabled');
1033            } else {
1034                this.container.find('button.applyBtn').attr('disabled', 'disabled');
1035            }
1036
1037        },
1038
1039        move: function() {
1040            var parentOffset = { top: 0, left: 0 },
1041                containerTop;
1042            var parentRightEdge = $(window).width();
1043            if (!this.parentEl.is('body')) {
1044                parentOffset = {
1045                    top: this.parentEl.offset().top - this.parentEl.scrollTop(),
1046                    left: this.parentEl.offset().left - this.parentEl.scrollLeft()
1047                };
1048                parentRightEdge = this.parentEl[0].clientWidth + this.parentEl.offset().left;
1049            }
1050
1051            if (this.drops == 'up')
1052                containerTop = this.element.offset().top - this.container.outerHeight() - parentOffset.top;
1053            else
1054                containerTop = this.element.offset().top + this.element.outerHeight() - parentOffset.top;
1055            this.container[this.drops == 'up' ? 'addClass' : 'removeClass']('drop-up');
1056
1057            if (this.opens == 'left') {
1058                this.container.css({
1059                    top: containerTop,
1060                    right: parentRightEdge - this.element.offset().left - this.element.outerWidth(),
1061                    left: 'auto'
1062                });
1063                if (this.container.offset().left < 0) {
1064                    this.container.css({
1065                        right: 'auto',
1066                        left: 9
1067                    });
1068                }
1069            } else if (this.opens == 'center') {
1070                this.container.css({
1071                    top: containerTop,
1072                    left: this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2
1073                            - this.container.outerWidth() / 2,
1074                    right: 'auto'
1075                });
1076                if (this.container.offset().left < 0) {
1077                    this.container.css({
1078                        right: 'auto',
1079                        left: 9
1080                    });
1081                }
1082            } else {
1083                this.container.css({
1084                    top: containerTop,
1085                    left: this.element.offset().left - parentOffset.left,
1086                    right: 'auto'
1087                });
1088                if (this.container.offset().left + this.container.outerWidth() > $(window).width()) {
1089                    this.container.css({
1090                        left: 'auto',
1091                        right: 0
1092                    });
1093                }
1094            }
1095        },
1096
1097        show: function(e) {
1098            if (this.isShowing) return;
1099
1100            // Create a click proxy that is private to this instance of datepicker, for unbinding
1101            this._outsideClickProxy = $.proxy(function(e) { this.outsideClick(e); }, this);
1102
1103            // Bind global datepicker mousedown for hiding and
1104            $(document)
1105              .on('mousedown.daterangepicker', this._outsideClickProxy)
1106              // also support mobile devices
1107              .on('touchend.daterangepicker', this._outsideClickProxy)
1108              // also explicitly play nice with Bootstrap dropdowns, which stopPropagation when clicking them
1109              .on('click.daterangepicker', '[data-toggle=dropdown]', this._outsideClickProxy)
vendor: 17,783 bytes, lines 1110-1547
1110              // and also close when focus changes to outside the picker (eg. tabbing between controls)
1111              .on('focusin.daterangepicker', this._outsideClickProxy);
1112
1113            // Reposition the picker if the window is resized while it's open
1114            $(window).on('resize.daterangepicker', $.proxy(function(e) { this.move(e); }, this));
1115
1116            this.oldStartDate = this.startDate.clone();
1117            this.oldEndDate = this.endDate.clone();
1118            this.previousRightTime = this.endDate.clone();
1119
1120            this.updateView();
1121            this.container.show();
1122            this.move();
1123            this.element.trigger('show.daterangepicker', this);
1124            this.isShowing = true;
1125        },
1126
1127        hide: function(e) {
1128            if (!this.isShowing) return;
1129
1130            //incomplete date selection, revert to last values
1131            if (!this.endDate) {
1132                this.startDate = this.oldStartDate.clone();
1133                this.endDate = this.oldEndDate.clone();
1134            }
1135
1136            //if a new date range was selected, invoke the user callback function
1137            if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate))
1138                this.callback(this.startDate.clone(), this.endDate.clone(), this.chosenLabel);
1139
1140            //if picker is attached to a text input, update it
1141            this.updateElement();
1142
1143            $(document).off('.daterangepicker');
1144            $(window).off('.daterangepicker');
1145            this.container.hide();
1146            this.element.trigger('hide.daterangepicker', this);
1147            this.isShowing = false;
1148        },
1149
1150        toggle: function(e) {
1151            if (this.isShowing) {
1152                this.hide();
1153            } else {
1154                this.show();
1155            }
1156        },
1157
1158        outsideClick: function(e) {
1159            var target = $(e.target);
1160            // if the page is clicked anywhere except within the daterangerpicker/button
1161            // itself then call this.hide()
1162            if (
1163                // ie modal dialog fix
1164                e.type == "focusin" ||
1165                target.closest(this.element).length ||
1166                target.closest(this.container).length ||
1167                target.closest('.calendar-table').length
1168                ) return;
1169            this.hide();
1170            this.element.trigger('outsideClick.daterangepicker', this);
1171        },
1172
1173        showCalendars: function() {
1174            this.container.addClass('show-calendar');
1175            this.move();
1176            this.element.trigger('showCalendar.daterangepicker', this);
1177        },
1178
1179        hideCalendars: function() {
1180            this.container.removeClass('show-calendar');
1181            this.element.trigger('hideCalendar.daterangepicker', this);
1182        },
1183
1184        clickRange: function(e) {
1185            var label = e.target.getAttribute('data-range-key');
1186            this.chosenLabel = label;
1187            if (label == this.locale.customRangeLabel) {
1188                this.showCalendars();
1189            } else {
1190                var dates = this.ranges[label];
1191                this.startDate = dates[0];
1192                this.endDate = dates[1];
1193
1194                if (!this.timePicker) {
1195                    this.startDate.startOf('day');
1196                    this.endDate.endOf('day');
1197                }
1198
1199                if (!this.alwaysShowCalendars)
1200                    this.hideCalendars();
1201                this.clickApply();
1202            }
1203        },
1204
1205        clickPrev: function(e) {
1206            var cal = $(e.target).parents('.drp-calendar');
1207            if (cal.hasClass('left')) {
1208                this.leftCalendar.month.subtract(1, 'month');
1209                if (this.linkedCalendars)
1210                    this.rightCalendar.month.subtract(1, 'month');
1211            } else {
1212                this.rightCalendar.month.subtract(1, 'month');
1213            }
1214            this.updateCalendars();
1215        },
1216
1217        clickNext: function(e) {
1218            var cal = $(e.target).parents('.drp-calendar');
1219            if (cal.hasClass('left')) {
1220                this.leftCalendar.month.add(1, 'month');
1221            } else {
1222                this.rightCalendar.month.add(1, 'month');
1223                if (this.linkedCalendars)
1224                    this.leftCalendar.month.add(1, 'month');
1225            }
1226            this.updateCalendars();
1227        },
1228
1229        hoverDate: function(e) {
1230
1231            //ignore dates that can't be selected
1232            if (!$(e.target).hasClass('available')) return;
1233
1234            var title = $(e.target).attr('data-title');
1235            var row = title.substr(1, 1);
1236            var col = title.substr(3, 1);
1237            var cal = $(e.target).parents('.drp-calendar');
1238            var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col];
1239
1240            //highlight the dates between the start date and the date being hovered as a potential end date
1241            var leftCalendar = this.leftCalendar;
1242            var rightCalendar = this.rightCalendar;
1243            var startDate = this.startDate;
1244            if (!this.endDate) {
1245                this.container.find('.drp-calendar tbody td').each(function(index, el) {
1246
1247                    //skip week numbers, only look at dates
1248                    if ($(el).hasClass('week')) return;
1249
1250                    var title = $(el).attr('data-title');
1251                    var row = title.substr(1, 1);
1252                    var col = title.substr(3, 1);
1253                    var cal = $(el).parents('.drp-calendar');
1254                    var dt = cal.hasClass('left') ? leftCalendar.calendar[row][col] : rightCalendar.calendar[row][col];
1255
1256                    if ((dt.isAfter(startDate) && dt.isBefore(date)) || dt.isSame(date, 'day')) {
1257                        $(el).addClass('in-range');
1258                    } else {
1259                        $(el).removeClass('in-range');
1260                    }
1261
1262                });
1263            }
1264
1265        },
1266
1267        clickDate: function(e) {
1268
1269            if (!$(e.target).hasClass('available')) return;
1270
1271            var title = $(e.target).attr('data-title');
1272            var row = title.substr(1, 1);
1273            var col = title.substr(3, 1);
1274            var cal = $(e.target).parents('.drp-calendar');
1275            var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col];
1276
1277            //
1278            // this function needs to do a few things:
1279            // * alternate between selecting a start and end date for the range,
1280            // * if the time picker is enabled, apply the hour/minute/second from the select boxes to the clicked date
1281            // * if autoapply is enabled, and an end date was chosen, apply the selection
1282            // * if single date picker mode, and time picker isn't enabled, apply the selection immediately
1283            // * if one of the inputs above the calendars was focused, cancel that manual input
1284            //
1285
1286            if (this.endDate || date.isBefore(this.startDate, 'day')) { //picking start
1287                if (this.timePicker) {
1288                    var hour = parseInt(this.container.find('.left .hourselect').val(), 10);
1289                    if (!this.timePicker24Hour) {
1290                        var ampm = this.container.find('.left .ampmselect').val();
1291                        if (ampm === 'PM' && hour < 12)
1292                            hour += 12;
1293                        if (ampm === 'AM' && hour === 12)
1294                            hour = 0;
1295                    }
1296                    var minute = parseInt(this.container.find('.left .minuteselect').val(), 10);
1297                    var second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0;
1298                    date = date.clone().hour(hour).minute(minute).second(second);
1299                }
1300                this.endDate = null;
1301                this.setStartDate(date.clone());
1302            } else if (!this.endDate && date.isBefore(this.startDate)) {
1303                //special case: clicking the same date for start/end,
1304                //but the time of the end date is before the start date
1305                this.setEndDate(this.startDate.clone());
1306            } else { // picking end
1307                if (this.timePicker) {
1308                    var hour = parseInt(this.container.find('.right .hourselect').val(), 10);
1309                    if (!this.timePicker24Hour) {
1310                        var ampm = this.container.find('.right .ampmselect').val();
1311                        if (ampm === 'PM' && hour < 12)
1312                            hour += 12;
1313                        if (ampm === 'AM' && hour === 12)
1314                            hour = 0;
1315                    }
1316                    var minute = parseInt(this.container.find('.right .minuteselect').val(), 10);
1317                    var second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0;
1318                    date = date.clone().hour(hour).minute(minute).second(second);
1319                }
1320                this.setEndDate(date.clone());
1321                if (this.autoApply) {
1322                  this.calculateChosenLabel();
1323                  this.clickApply();
1324                }
1325            }
1326
1327            if (this.singleDatePicker) {
1328                this.setEndDate(this.startDate);
1329                if (!this.timePicker)
1330                    this.clickApply();
1331            }
1332
1333            this.updateView();
1334
1335            //This is to cancel the blur event handler if the mouse was in one of the inputs
1336            e.stopPropagation();
1337
1338        },
1339
1340        calculateChosenLabel: function () {
1341            var customRange = true;
1342            var i = 0;
1343            for (var range in this.ranges) {
1344              if (this.timePicker) {
1345                    var format = this.timePickerSeconds ? "YYYY-MM-DD HH:mm:ss" : "YYYY-MM-DD HH:mm";
1346                    //ignore times when comparing dates if time picker seconds is not enabled
1347                    if (this.startDate.format(format) == this.ranges[range][0].format(format) && this.endDate.format(format) == this.ranges[range][1].format(format)) {
1348                        customRange = false;
1349                        this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').attr('data-range-key');
1350                        break;
1351                    }
1352                } else {
1353                    //ignore times when comparing dates if time picker is not enabled
1354                    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')) {
1355                        customRange = false;
1356                        this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').attr('data-range-key');
1357                        break;
1358                    }
1359                }
1360                i++;
1361            }
1362            if (customRange) {
1363                if (this.showCustomRangeLabel) {
1364                    this.chosenLabel = this.container.find('.ranges li:last').addClass('active').attr('data-range-key');
1365                } else {
1366                    this.chosenLabel = null;
1367                }
1368                this.showCalendars();
1369            }
1370        },
1371
1372        clickApply: function(e) {
1373            this.hide();
1374            this.element.trigger('apply.daterangepicker', this);
1375        },
1376
1377        clickCancel: function(e) {
1378            this.startDate = this.oldStartDate;
1379            this.endDate = this.oldEndDate;
1380            this.hide();
1381            this.element.trigger('cancel.daterangepicker', this);
1382        },
1383
1384        monthOrYearChanged: function(e) {
1385            var isLeft = $(e.target).closest('.drp-calendar').hasClass('left'),
1386                leftOrRight = isLeft ? 'left' : 'right',
1387                cal = this.container.find('.drp-calendar.'+leftOrRight);
1388
1389            // Month must be Number for new moment versions
1390            var month = parseInt(cal.find('.monthselect').val(), 10);
1391            var year = cal.find('.yearselect').val();
1392
1393            if (!isLeft) {
1394                if (year < this.startDate.year() || (year == this.startDate.year() && month < this.startDate.month())) {
1395                    month = this.startDate.month();
1396                    year = this.startDate.year();
1397                }
1398            }
1399
1400            if (this.minDate) {
1401                if (year < this.minDate.year() || (year == this.minDate.year() && month < this.minDate.month())) {
1402                    month = this.minDate.month();
1403                    year = this.minDate.year();
1404                }
1405            }
1406
1407            if (this.maxDate) {
1408                if (year > this.maxDate.year() || (year == this.maxDate.year() && month > this.maxDate.month())) {
1409                    month = this.maxDate.month();
1410                    year = this.maxDate.year();
1411                }
1412            }
1413
1414            if (isLeft) {
1415                this.leftCalendar.month.month(month).year(year);
1416                if (this.linkedCalendars)
1417                    this.rightCalendar.month = this.leftCalendar.month.clone().add(1, 'month');
1418            } else {
1419                this.rightCalendar.month.month(month).year(year);
1420                if (this.linkedCalendars)
1421                    this.leftCalendar.month = this.rightCalendar.month.clone().subtract(1, 'month');
1422            }
1423            this.updateCalendars();
1424        },
1425
1426        timeChanged: function(e) {
1427
1428            var cal = $(e.target).closest('.drp-calendar'),
1429                isLeft = cal.hasClass('left');
1430
1431            var hour = parseInt(cal.find('.hourselect').val(), 10);
1432            var minute = parseInt(cal.find('.minuteselect').val(), 10);
1433            var second = this.timePickerSeconds ? parseInt(cal.find('.secondselect').val(), 10) : 0;
1434
1435            if (!this.timePicker24Hour) {
1436                var ampm = cal.find('.ampmselect').val();
1437                if (ampm === 'PM' && hour < 12)
1438                    hour += 12;
1439                if (ampm === 'AM' && hour === 12)
1440                    hour = 0;
1441            }
1442
1443            if (isLeft) {
1444                var start = this.startDate.clone();
1445                start.hour(hour);
1446                start.minute(minute);
1447                start.second(second);
1448                this.setStartDate(start);
1449                if (this.singleDatePicker) {
1450                    this.endDate = this.startDate.clone();
1451                } else if (this.endDate && this.endDate.format('YYYY-MM-DD') == start.format('YYYY-MM-DD') && this.endDate.isBefore(start)) {
1452                    this.setEndDate(start.clone());
1453                }
1454            } else if (this.endDate) {
1455                var end = this.endDate.clone();
1456                end.hour(hour);
1457                end.minute(minute);
1458                end.second(second);
1459                this.setEndDate(end);
1460            }
1461
1462            //update the calendars so all clickable dates reflect the new time component
1463            this.updateCalendars();
1464
1465            //update the form inputs above the calendars with the new time
1466            this.updateFormInputs();
1467
1468            //re-render the time pickers because changing one selection can affect what's enabled in another
1469            this.renderTimePicker('left');
1470            this.renderTimePicker('right');
1471
1472        },
1473
1474        elementChanged: function() {
1475            if (!this.element.is('input')) return;
1476            if (!this.element.val().length) return;
1477
1478            var dateString = this.element.val().split(this.locale.separator),
1479                start = null,
1480                end = null;
1481
1482            if (dateString.length === 2) {
1483                start = moment(dateString[0], this.locale.format);
1484                end = moment(dateString[1], this.locale.format);
1485            }
1486
1487            if (this.singleDatePicker || start === null || end === null) {
1488                start = moment(this.element.val(), this.locale.format);
1489                end = start;
1490            }
1491
1492            if (!start.isValid() || !end.isValid()) return;
1493
1494            this.setStartDate(start);
1495            this.setEndDate(end);
1496            this.updateView();
1497        },
1498
1499        keydown: function(e) {
1500            //hide on tab or enter
1501            if ((e.keyCode === 9) || (e.keyCode === 13)) {
1502                this.hide();
1503            }
1504
1505            //hide on esc and prevent propagation
1506            if (e.keyCode === 27) {
1507                e.preventDefault();
1508                e.stopPropagation();
1509
1510                this.hide();
1511            }
1512        },
1513
1514        updateElement: function() {
1515            if (this.element.is('input') && this.autoUpdateInput) {
1516                var newValue = this.startDate.format(this.locale.format);
1517                if (!this.singleDatePicker) {
1518                    newValue += this.locale.separator + this.endDate.format(this.locale.format);
1519                }
1520                if (newValue !== this.element.val()) {
1521                    this.element.val(newValue).trigger('change');
1522                }
1523            }
1524        },
1525
1526        remove: function() {
1527            this.container.remove();
1528            this.element.off('.daterangepicker');
1529            this.element.removeData();
1530        }
1531
1532    };
1533
1534    $.fn.daterangepicker = function(options, callback) {
1535        var implementOptions = $.extend(true, {}, $.fn.daterangepicker.defaultOptions, options);
1536        this.each(function() {
1537            var el = $(this);
1538            if (el.data('daterangepicker'))
1539                el.data('daterangepicker').remove();
1540            el.data('daterangepicker', new DateRangePicker(el, implementOptions, callback));
1541        });
1542        return this;
1543    };
1544
1545    return DateRangePicker;
1546
1547}));

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.