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