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