PageSourceSearch

https://holtriem.de/wp-content/plugins/bookly-responsive-appointme…/resources/js/daterangepicker.js?ver=25.9

js holtriem.de collected 2026-10-02 18:21:06 UTC 67,204 bytes, 1,594 lines download raw bytes

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

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.