vendor: 36,420 bytes, lines 1-1005
1/* Please do not update this library because it has some custom edits */ 2/** 3* @version: 3.0.3 4* @author: Dan Grossman http://www.dangrossman.info/ 5* @copyright: Copyright (c) 2012-2018 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 return factory(moment, jquery); 16 }); 17 } else if (typeof module === 'object' && module.exports) { 18 // Node / Browserify 19 //isomorphic issue 20 var jQuery = (typeof window != 'undefined') ? window.jQuery : undefined; 21 if (!jQuery) { 22 jQuery = require('jquery'); 23 if (!jQuery.fn) jQuery.fn = {}; 24 } 25 var moment = (typeof window != 'undefined' && typeof window.moment != 'undefined') ? window.moment : require('moment'); 26 module.exports = factory(moment, jQuery); 27 } else { 28 // Browser globals 29 root.daterangepicker = factory(root.moment, root.jQuery); 30 } 31}(this, function(moment, $) { 32 var DateRangePicker = function(element, options, cb) { 33 34 //default settings for options 35 this.parentEl = 'body'; 36 this.element = $(element); 37 this.startDate = moment().startOf('day'); 38 this.endDate = moment().endOf('day'); 39 this.minDate = false; 40 this.maxDate = false; 41 this.maxSpan = false; 42 this.minSpan = 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.maxSpan === 'object') 211 this.maxSpan = options.maxSpan; 212 213 if (typeof options.dateLimit === 'object') //backwards compat 214 this.maxSpan = options.dateLimit; 215 216 if (typeof options.minSpan === 'object') 217 this.minSpan = options.minSpan; 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.addRate === 'function') 283 this.addRate = options.addRate; 284 285 if (typeof options.alwaysShowCalendars === 'boolean') 286 this.alwaysShowCalendars = options.alwaysShowCalendars; 287 288 // update day names order to firstDay 289 if (this.locale.firstDay != 0) { 290 var iterator = this.locale.firstDay; 291 while (iterator > 0) { 292 this.locale.daysOfWeek.push(this.locale.daysOfWeek.shift()); 293 iterator--; 294 } 295 } 296 297 var start, end, range; 298 299 //if no start/end dates set, check if an input element contains initial values 300 if (typeof options.startDate === 'undefined' && typeof options.endDate === 'undefined') { 301 if ($(this.element).is(':text')) { 302 var val = $(this.element).val(), 303 split = val.split(this.locale.separator); 304 305 start = end = null; 306 307 if (split.length == 2) { 308 start = moment(split[0], this.locale.format); 309 end = moment(split[1], this.locale.format); 310 } else if (this.singleDatePicker && val !== "") { 311 start = moment(val, this.locale.format); 312 end = moment(val, this.locale.format); 313 } 314 if (start !== null && end !== null) { 315 this.setStartDate(start); 316 this.setEndDate(end); 317 } 318 } 319 } 320 321 if (typeof options.ranges === 'object') { 322 for (range in options.ranges) { 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 if (maxDate && end.isAfter(maxDate)) 343 end = maxDate.clone(); 344 345 // if minSpan is set, set the length to the minimum 346 // note that this could conflict with maxDate 347 if (this.minSpan) { 348 var minEndDate = moment(this.startDate).add(this.minSpan); 349 if (this.endDate.isBefore(minEndDate)) { 350 this.endDate = minEndDate.clone(); 351 } 352 } 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.add(1,'d').startOf('day').subtract(1,'second'); 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 if (this.minSpan && this.startDate.clone().add(this.minSpan).isAfter(this.endDate)) 523 this.endDate = this.startDate.clone().add(this.minSpan); 524 525 this.previousRightTime = this.endDate.clone(); 526 527 this.container.find('.drp-selected').html(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format)); 528 529 if (!this.isShowing) 530 this.updateElement(); 531 532 this.updateMonthsInView(); 533 }, 534 535 isInvalidDate: function() { 536 return false; 537 }, 538 539 isCustomDate: function() { 540 return false; 541 }, 542 543 addRate: function() { 544 return false; 545 }, 546 547 updateView: function() { 548 if (this.timePicker) { 549 this.renderTimePicker('left'); 550 this.renderTimePicker('right'); 551 if (!this.endDate) { 552 this.container.find('.right .calendar-time select').attr('disabled', 'disabled').addClass('disabled'); 553 } else { 554 this.container.find('.right .calendar-time select').removeAttr('disabled').removeClass('disabled'); 555 } 556 } 557 if (this.endDate) 558 this.container.find('.drp-selected').html(this.startDate.format(this.locale.format) + this.locale.separator + this.endDate.format(this.locale.format)); 559 this.updateMonthsInView(); 560 this.updateCalendars(); 561 this.updateFormInputs(); 562 }, 563 564 updateMonthsInView: function() { 565 if (this.endDate) { 566 567 //if both dates are visible already, do nothing 568 if (!this.singleDatePicker && this.leftCalendar.month && this.rightCalendar.month && 569 (this.startDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.startDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM')) 570 && 571 (this.endDate.format('YYYY-MM') == this.leftCalendar.month.format('YYYY-MM') || this.endDate.format('YYYY-MM') == this.rightCalendar.month.format('YYYY-MM')) 572 ) { 573 return; 574 } 575 576 this.leftCalendar.month = this.startDate.clone().date(2); 577 if (!this.linkedCalendars && (this.endDate.month() != this.startDate.month() || this.endDate.year() != this.startDate.year())) { 578 this.rightCalendar.month = this.endDate.clone().date(2); 579 } else { 580 this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month'); 581 } 582 583 } else { 584 if (this.leftCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM') && this.rightCalendar.month.format('YYYY-MM') != this.startDate.format('YYYY-MM')) { 585 this.leftCalendar.month = this.startDate.clone().date(2); 586 this.rightCalendar.month = this.startDate.clone().date(2).add(1, 'month'); 587 } 588 } 589 if (this.maxDate && this.linkedCalendars && !this.singleDatePicker && this.rightCalendar.month > this.maxDate) { 590 this.rightCalendar.month = this.maxDate.clone().date(2); 591 this.leftCalendar.month = this.maxDate.clone().date(2).subtract(1, 'month'); 592 } 593 }, 594 595 updateCalendars: function() { 596 597 if (this.timePicker) { 598 var hour, minute, second; 599 if (this.endDate) { 600 hour = parseInt(this.container.find('.left .hourselect').val(), 10); 601 minute = parseInt(this.container.find('.left .minuteselect').val(), 10); 602 second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0; 603 if (!this.timePicker24Hour) { 604 var ampm = this.container.find('.left .ampmselect').val(); 605 if (ampm === 'PM' && hour < 12) 606 hour += 12; 607 if (ampm === 'AM' && hour === 12) 608 hour = 0; 609 } 610 } else { 611 hour = parseInt(this.container.find('.right .hourselect').val(), 10); 612 minute = parseInt(this.container.find('.right .minuteselect').val(), 10); 613 second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0; 614 if (!this.timePicker24Hour) { 615 var ampm = this.container.find('.right .ampmselect').val(); 616 if (ampm === 'PM' && hour < 12) 617 hour += 12; 618 if (ampm === 'AM' && hour === 12) 619 hour = 0; 620 } 621 } 622 this.leftCalendar.month.hour(hour).minute(minute).second(second); 623 this.rightCalendar.month.hour(hour).minute(minute).second(second); 624 } 625 626 this.renderCalendar('left'); 627 this.renderCalendar('right'); 628 629 //highlight any predefined range matching the current start and end dates 630 this.container.find('.ranges li').removeClass('active'); 631 if (this.endDate == null) return; 632 633 this.calculateChosenLabel(); 634 }, 635 636 renderCalendar: function(side, rates) { 637 638 // 639 // Build the matrix of dates that will populate the calendar 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">'; 734 for (var m = 0; m < 12; m++) { 735 if ((!inMinYear || m >= minDate.month()) && (!inMaxYear || 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">'; 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 // if minSpan is set, calculate minimum end date 790 if (this.endDate == null && this.minSpan) { 791 var minEndDate = this.startDate.clone().add(this.minSpan).endOf('day'); 792 } 793 794 for (var row = 0; row < 6; row++) { 795 html += '<tr>'; 796 797 // add week number 798 if (this.showWeekNumbers) 799 html += '<td class="week">' + calendar[row][0].week() + '</td>'; 800 else if (this.showISOWeekNumbers) 801 html += '<td class="week">' + calendar[row][0].isoWeek() + '</td>'; 802 803 for (var col = 0; col < 7; col++) { 804 805 var classes = []; 806 807 //highlight today's date 808 if (calendar[row][col].isSame(new Date(), "day")) 809 classes.push('today'); 810 811 //highlight weekends 812 if (calendar[row][col].isoWeekday() > 5) 813 classes.push('weekend'); 814 815 //grey out the dates in other months displayed at beginning and end of this calendar 816 if (calendar[row][col].month() != calendar[1][1].month()) 817 classes.push('off'); 818 819 //don't allow selection of dates before the minimum date 820 if (this.minDate && calendar[row][col].isBefore(this.minDate, 'day')) 821 classes.push('off', 'disabled'); 822 823 //don't allow selection of dates after the maximum date 824 if (maxDate && calendar[row][col].isAfter(maxDate, 'day')) 825 classes.push('off', 'disabled'); 826 827 //don't allow selection of date if a custom function decides it's invalid 828 if (this.isInvalidDate(calendar[row][col])) 829 classes.push('off', 'disabled'); 830 831 //highlight the currently selected start date 832 if (calendar[row][col].format('YYYY-MM-DD') == this.startDate.format('YYYY-MM-DD')) 833 classes.push('active', 'start-date'); 834 835 //highlight the currently selected end date 836 if (this.endDate != null && calendar[row][col].format('YYYY-MM-DD') == this.endDate.format('YYYY-MM-DD')) 837 classes.push('active', 'end-date'); 838 839 //highlight dates in-between the selected dates 840 if (this.endDate != null && calendar[row][col] > this.startDate && calendar[row][col] < this.endDate) 841 classes.push('in-range'); 842 843 // don't allow selection if the date is before the minimum end date 844 if (minEndDate && calendar[row][col].isBefore(minEndDate, 'day') && 845 classes.indexOf('start-date') < 0) { 846 classes.push('off', 'disabled'); 847 } 848 849 //apply custom rate for this date 850 var addRate = this.addRate(calendar[row][col]); 851 var rate = ''; 852 var rateInCalendar = ''; 853 if (addRate && addRate.length > 0 && addRate !== false) { 854 rate = addRate[0]; 855 if(addRate[1] == 1){ 856 rateInCalendar = '<small class="c_daily_rate">'+rate+'</small>'; 857 } 858 } 859 860 //apply custom classes for this date 861 var isCustom = this.isCustomDate(calendar[row][col]); 862 if (isCustom !== false) { 863 if (typeof isCustom === 'string') 864 classes.push(isCustom); 865 else 866 Array.prototype.push.apply(classes, isCustom); 867 } 868 869 var cname = '', disabled = false; 870 for (var i = 0; i < classes.length; i++) { 871 cname += classes[i] + ' '; 872 if (classes[i] == 'disabled') 873 disabled = true; 874 } 875 if (!disabled) 876 cname += 'available'; 877 878 html += '<td class="' + cname.replace(/^\s+|\s+$/g, '') + '" data-title="' + 'r' + row + 'c' + col + '" title="'+rate+'">' + calendar[row][col].date() + ''+rateInCalendar+'</td>'; 879 880 } 881 html += '</tr>'; 882 } 883 884 html += '</tbody>'; 885 html += '</table>'; 886 887 this.container.find('.drp-calendar.' + side + ' .calendar-table').html(html); 888 889 }, 890 891 renderTimePicker: function(side) { 892 893 // Don't bother updating the time picker if it's currently disabled 894 // because an end date hasn't been clicked yet 895 if (side == 'right' && !this.endDate) return; 896 897 var html, selected, minDate, maxDate = this.maxDate; 898 899 if (this.maxSpan && (!this.maxDate || this.startDate.clone().add(this.maxSpan).isAfter(this.maxDate))) 900 maxDate = this.startDate.clone().add(this.maxSpan); 901 902 if (side == 'left') { 903 selected = this.startDate.clone(); 904 minDate = this.minDate; 905 } else if (side == 'right') { 906 selected = this.endDate.clone(); 907 minDate = this.startDate; 908 909 //Preserve the time already selected 910 var timeSelector = this.container.find('.drp-calendar.right .calendar-time'); 911 if (timeSelector.html() != '') { 912 913 selected.hour(selected.hour() || timeSelector.find('.hourselect option:selected').val()); 914 selected.minute(selected.minute() || timeSelector.find('.minuteselect option:selected').val()); 915 selected.second(selected.second() || timeSelector.find('.secondselect option:selected').val()); 916 917 if (!this.timePicker24Hour) { 918 var ampm = timeSelector.find('.ampmselect option:selected').val(); 919 if (ampm === 'PM' && selected.hour() < 12) 920 selected.hour(selected.hour() + 12); 921 if (ampm === 'AM' && selected.hour() === 12) 922 selected.hour(0); 923 } 924 925 } 926 927 if (selected.isBefore(this.startDate)) 928 selected = this.startDate.clone(); 929 930 if (maxDate && selected.isAfter(maxDate)) 931 selected = maxDate.clone(); 932 933 } 934 935 // 936 // hours 937 // 938 939 html = '<select class="hourselect">'; 940 941 var start = this.timePicker24Hour ? 0 : 1; 942 var end = this.timePicker24Hour ? 23 : 12; 943 944 for (var i = start; i <= end; i++) { 945 var i_in_24 = i; 946 if (!this.timePicker24Hour) 947 i_in_24 = selected.hour() >= 12 ? (i == 12 ? 12 : i + 12) : (i == 12 ? 0 : i); 948 949 var time = selected.clone().hour(i_in_24); 950 var disabled = false; 951 if (minDate && time.minute(59).isBefore(minDate)) 952 disabled = true; 953 if (maxDate && time.minute(0).isAfter(maxDate)) 954 disabled = true; 955 956 if (i_in_24 == selected.hour() && !disabled) { 957 html += '<option value="' + i + '" selected="selected">' + i + '</option>'; 958 } else if (disabled) { 959 html += '<option value="' + i + '" disabled="disabled" class="disabled">' + i + '</option>'; 960 } else { 961 html += '<option value="' + i + '">' + i + '</option>'; 962 } 963 } 964 965 html += '</select> '; 966 967 // 968 // minutes 969 // 970 971 html += ': <select class="minuteselect">'; 972 973 for (var i = 0; i < 60; i += this.timePickerIncrement) { 974 var padded = i < 10 ? '0' + i : i; 975 var time = selected.clone().minute(i); 976 977 var disabled = false; 978 if (minDate && time.second(59).isBefore(minDate)) 979 disabled = true; 980 if (maxDate && time.second(0).isAfter(maxDate)) 981 disabled = true; 982 983 if (selected.minute() == i && !disabled) { 984 html += '<option value="' + i + '" selected="selected">' + padded + '</option>'; 985 } else if (disabled) { 986 html += '<option value="' + i + '" disabled="disabled" class="disabled">' + padded + '</option>'; 987 } else { 988 html += '<option value="' + i + '">' + padded + '</option>'; 989 } 990 } 991 992 html += '</select> '; 993 994 // 995 // seconds 996 // 997 998 if (this.timePickerSeconds) { 999 html += ': <select class="secondselect">'; 1000 1001 for (var i = 0; i < 60; i++) { 1002 var padded = i < 10 ? '0' + i : i; 1003 var time = selected.clone().second(i); 1004 1005 var disabled = false;
1006 if (minDate && time.isBefore(minDate)) 1007 disabled = true; 1008 if (maxDate && time.isAfter(maxDate)) 1009 disabled = true; 1010 1011 if (selected.second() == i && !disabled) { 1012 html += '<option value="' + i + '" selected="selected">' + padded + '</option>'; 1013 } else if (disabled) { 1014 html += '<option value="' + i + '" disabled="disabled" class="disabled">' + padded + '</option>'; 1015 } else { 1016 html += '<option value="' + i + '">' + padded + '</option>'; 1017 } 1018 } 1019 1020 html += '</select> '; 1021 } 1022 1023 // 1024 // AM/PM 1025 // 1026 1027 if (!this.timePicker24Hour) { 1028 html += '<select class="ampmselect">'; 1029 1030 var am_html = ''; 1031 var pm_html = ''; 1032 1033 if (minDate && selected.clone().hour(12).minute(0).second(0).isBefore(minDate)) 1034 am_html = ' disabled="disabled" class="disabled"'; 1035 1036 if (maxDate && selected.clone().hour(0).minute(0).second(0).isAfter(maxDate)) 1037 pm_html = ' disabled="disabled" class="disabled"'; 1038 1039 if (selected.hour() >= 12) { 1040 html += '<option value="AM"' + am_html + '>AM</option><option value="PM" selected="selected"' + pm_html + '>PM</option>'; 1041 } else { 1042 html += '<option value="AM" selected="selected"' + am_html + '>AM</option><option value="PM"' + pm_html + '>PM</option>'; 1043 } 1044 1045 html += '</select>'; 1046 } 1047 1048 this.container.find('.drp-calendar.' + side + ' .calendar-time').html(html); 1049 1050 }, 1051 1052 updateFormInputs: function() { 1053 1054 if (this.singleDatePicker || (this.endDate && (this.startDate.isBefore(this.endDate) || this.startDate.isSame(this.endDate)))) { 1055 this.container.find('button.applyBtn').removeAttr('disabled'); 1056 } else { 1057 this.container.find('button.applyBtn').attr('disabled', 'disabled'); 1058 } 1059 1060 }, 1061 1062 move: function() { 1063 var parentOffset = { top: 0, left: 0 }, 1064 containerTop; 1065 var parentRightEdge = $(window).width(); 1066 if (!this.parentEl.is('body')) { 1067 parentOffset = { 1068 top: this.parentEl.offset().top - this.parentEl.scrollTop(), 1069 left: this.parentEl.offset().left - this.parentEl.scrollLeft() 1070 }; 1071 parentRightEdge = this.parentEl[0].clientWidth + this.parentEl.offset().left; 1072 } 1073 1074 if (this.drops == 'up') 1075 containerTop = this.element.offset().top - this.container.outerHeight() - parentOffset.top; 1076 else 1077 containerTop = this.element.offset().top + this.element.outerHeight() - parentOffset.top; 1078 this.container[this.drops == 'up' ? 'addClass' : 'removeClass']('drop-up'); 1079 1080 if (this.opens == 'left') { 1081 this.container.css({ 1082 top: containerTop, 1083 right: parentRightEdge - this.element.offset().left - this.element.outerWidth(), 1084 left: 'auto' 1085 }); 1086 if (this.container.offset().left < 0) { 1087 this.container.css({ 1088 right: 'auto', 1089 left: 9 1090 }); 1091 } 1092 } else if (this.opens == 'center') { 1093 this.container.css({ 1094 top: containerTop, 1095 left: this.element.offset().left - parentOffset.left + this.element.outerWidth() / 2 1096 - this.container.outerWidth() / 2, 1097 right: 'auto' 1098 }); 1099 if (this.container.offset().left < 0) { 1100 this.container.css({ 1101 right: 'auto', 1102 left: 9 1103 }); 1104 } 1105 } else { 1106 this.container.css({ 1107 top: containerTop, 1108 left: this.element.offset().left - parentOffset.left, 1109 right: 'auto' 1110 }); 1111 if (this.container.offset().left + this.container.outerWidth() > $(window).width()) { 1112 this.container.css({ 1113 left: 'auto', 1114 right: 0 1115 }); 1116 } 1117 } 1118 }, 1119 1120 show: function(e) { 1121 if (this.isShowing) return; 1122 1123 // Create a click proxy that is private to this instance of datepicker, for unbinding 1124 this._outsideClickProxy = $.proxy(function(e) { this.outsideClick(e); }, this); 1125 1126 // Bind global datepicker mousedown for hiding and 1127 $(document) 1128 .on('mousedown.daterangepicker', this._outsideClickProxy) 1129 // also support mobile devices 1130 .on('touchend.daterangepicker', this._outsideClickProxy) 1131 // also explicitly play nice with Bootstrap dropdowns, which stopPropagation when clicking them 1132 .on('click.daterangepicker', '[data-toggle=dropdown]', this._outsideClickProxy)
vendor: 14,928 bytes, lines 1133-1575
1133 // and also close when focus changes to outside the picker (eg. tabbing between controls) 1134 .on('focusin.daterangepicker', this._outsideClickProxy); 1135 1136 // Reposition the picker if the window is resized while it's open 1137 $(window).on('resize.daterangepicker', $.proxy(function(e) { this.move(e); }, this)); 1138 1139 this.oldStartDate = this.startDate.clone(); 1140 this.oldEndDate = this.endDate.clone(); 1141 this.previousRightTime = this.endDate.clone(); 1142 1143 this.updateView(); 1144 this.container.show(); 1145 this.move(); 1146 this.element.trigger('show.daterangepicker', this); 1147 this.isShowing = true; 1148 }, 1149 1150 hide: function(e) { 1151 if (!this.isShowing) return; 1152 1153 //incomplete date selection, revert to last values 1154 if (!this.endDate) { 1155 this.startDate = this.oldStartDate.clone(); 1156 this.endDate = this.oldEndDate.clone(); 1157 } 1158 1159 //if a new date range was selected, invoke the user callback function 1160 if (!this.startDate.isSame(this.oldStartDate) || !this.endDate.isSame(this.oldEndDate)) 1161 this.callback(this.startDate.clone(), this.endDate.clone(), this.chosenLabel); 1162 1163 //if picker is attached to a text input, update it 1164 this.updateElement(); 1165 1166 $(document).off('.daterangepicker'); 1167 $(window).off('.daterangepicker'); 1168 this.container.hide(); 1169 this.element.trigger('hide.daterangepicker', this); 1170 this.isShowing = false; 1171 }, 1172 1173 toggle: function(e) { 1174 if (this.isShowing) { 1175 this.hide(); 1176 } else { 1177 this.show(); 1178 } 1179 }, 1180 1181 outsideClick: function(e) { 1182 var target = $(e.target); 1183 // if the page is clicked anywhere except within the daterangerpicker/button 1184 // itself then call this.hide() 1185 if ( 1186 // ie modal dialog fix 1187 e.type == "focusin" || 1188 target.closest(this.element).length || 1189 target.closest(this.container).length || 1190 target.closest('.calendar-table').length 1191 ) return; 1192 this.hide(); 1193 this.element.trigger('outsideClick.daterangepicker', this); 1194 }, 1195 1196 showCalendars: function() { 1197 this.container.addClass('show-calendar'); 1198 this.move(); 1199 this.element.trigger('showCalendar.daterangepicker', this); 1200 }, 1201 1202 hideCalendars: function() { 1203 this.container.removeClass('show-calendar'); 1204 this.element.trigger('hideCalendar.daterangepicker', this); 1205 }, 1206 1207 clickRange: function(e) { 1208 var label = e.target.getAttribute('data-range-key'); 1209 this.chosenLabel = label; 1210 if (label == this.locale.customRangeLabel) { 1211 this.showCalendars(); 1212 } else { 1213 var dates = this.ranges[label]; 1214 this.startDate = dates[0]; 1215 this.endDate = dates[1]; 1216 1217 if (!this.timePicker) { 1218 this.startDate.startOf('day'); 1219 this.endDate.endOf('day'); 1220 } 1221 1222 if (!this.alwaysShowCalendars) 1223 this.hideCalendars(); 1224 this.clickApply(); 1225 } 1226 }, 1227 1228 clickPrev: function(e) { 1229 var cal = $(e.target).parents('.drp-calendar'); 1230 if (cal.hasClass('left')) { 1231 this.leftCalendar.month.subtract(1, 'month'); 1232 if (this.linkedCalendars) 1233 this.rightCalendar.month.subtract(1, 'month'); 1234 } else { 1235 this.rightCalendar.month.subtract(1, 'month'); 1236 } 1237 this.updateCalendars(); 1238 }, 1239 1240 clickNext: function(e) { 1241 var cal = $(e.target).parents('.drp-calendar'); 1242 if (cal.hasClass('left')) { 1243 this.leftCalendar.month.add(1, 'month'); 1244 } else { 1245 this.rightCalendar.month.add(1, 'month'); 1246 if (this.linkedCalendars) 1247 this.leftCalendar.month.add(1, 'month'); 1248 } 1249 this.updateCalendars(); 1250 }, 1251 1252 hoverDate: function(e) { 1253 1254 //ignore dates that can't be selected 1255 if (!$(e.target).hasClass('available')) return; 1256 1257 var title = $(e.target).attr('data-title'); 1258 var row = title.substr(1, 1); 1259 var col = title.substr(3, 1); 1260 var cal = $(e.target).parents('.drp-calendar'); 1261 var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col]; 1262 1263 //highlight the dates between the start date and the date being hovered as a potential end date 1264 var leftCalendar = this.leftCalendar; 1265 var rightCalendar = this.rightCalendar; 1266 var startDate = this.startDate; 1267 if (!this.endDate) { 1268 this.container.find('.drp-calendar tbody td').each(function(index, el) { 1269 1270 //skip week numbers, only look at dates 1271 if ($(el).hasClass('week')) return; 1272 1273 var title = $(el).attr('data-title'); 1274 var row = title.substr(1, 1); 1275 var col = title.substr(3, 1); 1276 var cal = $(el).parents('.drp-calendar'); 1277 var dt = cal.hasClass('left') ? leftCalendar.calendar[row][col] : rightCalendar.calendar[row][col]; 1278 1279 if ((dt.isAfter(startDate) && dt.isBefore(date)) || dt.isSame(date, 'day')) { 1280 $(el).addClass('in-range'); 1281 } else { 1282 $(el).removeClass('in-range'); 1283 } 1284 1285 }); 1286 } 1287 1288 }, 1289 1290 clickDate: function(e) { 1291 1292 if (!$(e.target).hasClass('available')) return; 1293 1294 var title = $(e.target).attr('data-title'); 1295 var row = title.substr(1, 1); 1296 var col = title.substr(3, 1); 1297 var cal = $(e.target).parents('.drp-calendar'); 1298 var date = cal.hasClass('left') ? this.leftCalendar.calendar[row][col] : this.rightCalendar.calendar[row][col]; 1299 1300 // 1301 // this function needs to do a few things: 1302 // * alternate between selecting a start and end date for the range, 1303 // * if the time picker is enabled, apply the hour/minute/second from the select boxes to the clicked date 1304 // * if autoapply is enabled, and an end date was chosen, apply the selection 1305 // * if single date picker mode, and time picker isn't enabled, apply the selection immediately 1306 // * if one of the inputs above the calendars was focused, cancel that manual input 1307 // 1308 1309 if (this.endDate || date.isBefore(this.startDate, 'day')) { //picking start 1310 this.element.trigger('startDateClick.daterangepicker', this); 1311 if (this.timePicker) { 1312 var hour = parseInt(this.container.find('.left .hourselect').val(), 10); 1313 if (!this.timePicker24Hour) { 1314 var ampm = this.container.find('.left .ampmselect').val(); 1315 if (ampm === 'PM' && hour < 12) 1316 hour += 12; 1317 if (ampm === 'AM' && hour === 12) 1318 hour = 0; 1319 } 1320 var minute = parseInt(this.container.find('.left .minuteselect').val(), 10); 1321 var second = this.timePickerSeconds ? parseInt(this.container.find('.left .secondselect').val(), 10) : 0; 1322 date = date.clone().hour(hour).minute(minute).second(second); 1323 } 1324 this.endDate = null; 1325 this.setStartDate(date.clone()); 1326 } else if (!this.endDate && date.isBefore(this.startDate)) { 1327 //special case: clicking the same date for start/end, 1328 //but the time of the end date is before the start date 1329 this.setEndDate(this.startDate.clone()); 1330 } else { // picking end 1331 if (this.timePicker) { 1332 var hour = parseInt(this.container.find('.right .hourselect').val(), 10); 1333 if (!this.timePicker24Hour) { 1334 var ampm = this.container.find('.right .ampmselect').val(); 1335 if (ampm === 'PM' && hour < 12) 1336 hour += 12; 1337 if (ampm === 'AM' && hour === 12) 1338 hour = 0; 1339 } 1340 var minute = parseInt(this.container.find('.right .minuteselect').val(), 10); 1341 var second = this.timePickerSeconds ? parseInt(this.container.find('.right .secondselect').val(), 10) : 0; 1342 date = date.clone().hour(hour).minute(minute).second(second); 1343 } 1344 this.setEndDate(date.clone()); 1345 if (this.autoApply) { 1346 this.calculateChosenLabel(); 1347 this.clickApply(); 1348 } 1349 } 1350 1351 if (this.singleDatePicker) { 1352 this.setEndDate(this.startDate); 1353 if (!this.timePicker) 1354 this.clickApply(); 1355 } 1356 1357 this.updateView(); 1358 1359 //This is to cancel the blur event handler if the mouse was in one of the inputs 1360 e.stopPropagation(); 1361 1362 }, 1363 1364 calculateChosenLabel: function () { 1365 var customRange = true; 1366 var i = 0; 1367 for (var range in this.ranges) { 1368 if (this.timePicker) { 1369 var format = this.timePickerSeconds ? "YYYY-MM-DD hh:mm:ss" : "YYYY-MM-DD hh:mm"; 1370 //ignore times when comparing dates if time picker seconds is not enabled 1371 if (this.startDate.format(format) == this.ranges[range][0].format(format) && this.endDate.format(format) == this.ranges[range][1].format(format)) { 1372 customRange = false; 1373 this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').attr('data-range-key'); 1374 break; 1375 } 1376 } else { 1377 //ignore times when comparing dates if time picker is not enabled 1378 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')) { 1379 customRange = false; 1380 this.chosenLabel = this.container.find('.ranges li:eq(' + i + ')').addClass('active').attr('data-range-key'); 1381 break; 1382 } 1383 } 1384 i++; 1385 } 1386 if (customRange) { 1387 if (this.showCustomRangeLabel) { 1388 this.chosenLabel = this.container.find('.ranges li:last').addClass('active').attr('data-range-key'); 1389 } else { 1390 this.chosenLabel = null; 1391 } 1392 this.showCalendars(); 1393 } 1394 }, 1395 1396 clickApply: function(e) { 1397 this.hide(); 1398 this.element.trigger('apply.daterangepicker', this); 1399 }, 1400 1401 clickCancel: function(e) { 1402 this.startDate = this.oldStartDate; 1403 this.endDate = this.oldEndDate; 1404 this.hide(); 1405 this.element.trigger('cancel.daterangepicker', this); 1406 }, 1407 1408 monthOrYearChanged: function(e) { 1409 var isLeft = $(e.target).closest('.drp-calendar').hasClass('left'), 1410 leftOrRight = isLeft ? 'left' : 'right', 1411 cal = this.container.find('.drp-calendar.'+leftOrRight); 1412 1413 // Month must be Number for new moment versions 1414 var month = parseInt(cal.find('.monthselect').val(), 10); 1415 var year = cal.find('.yearselect').val(); 1416 1417 if (!isLeft) { 1418 if (year < this.startDate.year() || (year == this.startDate.year() && month < this.startDate.month())) { 1419 month = this.startDate.month(); 1420 year = this.startDate.year(); 1421 } 1422 } 1423 1424 if (this.minDate) { 1425 if (year < this.minDate.year() || (year == this.minDate.year() && month < this.minDate.month())) { 1426 month = this.minDate.month(); 1427 year = this.minDate.year(); 1428 } 1429 } 1430 1431 if (this.maxDate) { 1432 if (year > this.maxDate.year() || (year == this.maxDate.year() && month > this.maxDate.month())) { 1433 month = this.maxDate.month(); 1434 year = this.maxDate.year(); 1435 } 1436 } 1437 1438 if (isLeft) { 1439 this.leftCalendar.month.month(month).year(year); 1440 if (this.linkedCalendars) 1441 this.rightCalendar.month = this.leftCalendar.month.clone().add(1, 'month'); 1442 } else { 1443 this.rightCalendar.month.month(month).year(year); 1444 if (this.linkedCalendars) 1445 this.leftCalendar.month = this.rightCalendar.month.clone().subtract(1, 'month'); 1446 } 1447 this.updateCalendars(); 1448 }, 1449 1450 timeChanged: function(e) { 1451 1452 var cal = $(e.target).closest('.drp-calendar'), 1453 isLeft = cal.hasClass('left'); 1454 1455 var hour = parseInt(cal.find('.hourselect').val(), 10); 1456 var minute = parseInt(cal.find('.minuteselect').val(), 10); 1457 var second = this.timePickerSeconds ? parseInt(cal.find('.secondselect').val(), 10) : 0; 1458 1459 if (!this.timePicker24Hour) { 1460 var ampm = cal.find('.ampmselect').val(); 1461 if (ampm === 'PM' && hour < 12) 1462 hour += 12; 1463 if (ampm === 'AM' && hour === 12) 1464 hour = 0; 1465 } 1466 1467 if (isLeft) { 1468 var start = this.startDate.clone(); 1469 start.hour(hour); 1470 start.minute(minute); 1471 start.second(second); 1472 this.setStartDate(start); 1473 if (this.singleDatePicker) { 1474 this.endDate = this.startDate.clone(); 1475 } else if (this.endDate && this.endDate.format('YYYY-MM-DD') == start.format('YYYY-MM-DD') && this.endDate.isBefore(start)) { 1476 this.setEndDate(start.clone()); 1477 } 1478 } else if (this.endDate) { 1479 var end = this.endDate.clone(); 1480 end.hour(hour); 1481 end.minute(minute); 1482 end.second(second); 1483 this.setEndDate(end); 1484 } 1485 1486 //update the calendars so all clickable dates reflect the new time component 1487 this.updateCalendars(); 1488 1489 //update the form inputs above the calendars with the new time 1490 this.updateFormInputs(); 1491 1492 //re-render the time pickers because changing one selection can affect what's enabled in another 1493 this.renderTimePicker('left'); 1494 this.renderTimePicker('right'); 1495 1496 }, 1497 1498 elementChanged: function() { 1499 if (!this.element.is('input')) return; 1500 if (!this.element.val().length) return; 1501 1502 var dateString = this.element.val().split(this.locale.separator), 1503 start = null, 1504 end = null; 1505 1506 if (dateString.length === 2) { 1507 start = moment(dateString[0], this.locale.format); 1508 end = moment(dateString[1], this.locale.format); 1509 } 1510 1511 if (this.singleDatePicker || start === null || end === null) { 1512 start = moment(this.element.val(), this.locale.format); 1513 end = start; 1514 } 1515 1516 if (!start.isValid() || !end.isValid()) return; 1517 1518 this.setStartDate(start); 1519 this.setEndDate(end); 1520 this.updateView(); 1521 }, 1522 1523 keydown: function(e) { 1524 //hide on tab or enter 1525 if ((e.keyCode === 9) || (e.keyCode === 13)) { 1526 this.hide(); 1527 } 1528 1529 //hide on esc and prevent propagation 1530 if (e.keyCode === 27) { 1531 e.preventDefault(); 1532 e.stopPropagation(); 1533 1534 this.hide(); 1535 } 1536 }, 1537 1538 updateElement: function() { 1539 if (this.element.is('input') && this.autoUpdateInput) { 1540 var newValue = this.startDate.format(this.locale.format); 1541 if (!this.singleDatePicker) { 1542 newValue += this.locale.separator + this.endDate.format(this.locale.format); 1543 } 1544 if (newValue !== this.element.val()) { 1545 this.element.val(newValue).trigger('change'); 1546 } 1547 } 1548 }, 1549 1550 remove: function() { 1551 this.container.remove(); 1552 this.element.off('.daterangepicker'); 1553 this.element.removeData(); 1554 }, 1555 1556 addRates: function(rates){ 1557 this.renderCalendar(null,rates) 1558 } 1559 1560 }; 1561 1562 $.fn.daterangepicker = function(options, callback) { 1563 var implementOptions = $.extend(true, {}, $.fn.daterangepicker.defaultOptions, options); 1564 this.each(function() { 1565 var el = $(this); 1566 if (el.data('daterangepicker')) 1567 el.data('daterangepicker').remove(); 1568 el.data('daterangepicker', new DateRangePicker(el, implementOptions, callback)); 1569 }); 1570 return this; 1571 }; 1572 1573 return DateRangePicker; 1574 1575}));
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.