vendor: 4,574 bytes, lines 1-108
1/*! 2 * Datepicker v1.0.6 3 * https://fengyuanchen.github.io/datepicker 4 * 5 * Copyright 2014-present Chen Fengyuan 6 * Released under the MIT license 7 * 8 * Date: 2019-01-19T09:15:49.236Z 9 */ 10 11(function (global, factory) { 12 typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jquery')) : 13 typeof define === 'function' && define.amd ? define(['jquery'], factory) : 14 (global = global || self, factory(global.jQuery)); 15}(this, function ($) { 'use strict'; 16 17 $ = $ && $.hasOwnProperty('default') ? $['default'] : $; 18 19 function _classCallCheck(instance, Constructor) { 20 if (!(instance instanceof Constructor)) { 21 throw new TypeError("Cannot call a class as a function"); 22 } 23 } 24 25 function _defineProperties(target, props) { 26 for (var i = 0; i < props.length; i++) { 27 var descriptor = props[i]; 28 descriptor.enumerable = descriptor.enumerable || false; 29 descriptor.configurable = true; 30 if ("value" in descriptor) descriptor.writable = true; 31 Object.defineProperty(target, descriptor.key, descriptor); 32 } 33 } 34 35 function _createClass(Constructor, protoProps, staticProps) { 36 if (protoProps) _defineProperties(Constructor.prototype, protoProps); 37 if (staticProps) _defineProperties(Constructor, staticProps); 38 return Constructor; 39 } 40 41 var DEFAULTS = { 42 // Show the datepicker automatically when initialized 43 autoShow: false, 44 // Hide the datepicker automatically when picked 45 autoHide: false, 46 // Pick the initial date automatically when initialized 47 autoPick: false, 48 // Enable inline mode 49 inline: false, 50 // A element (or selector) for putting the datepicker 51 container: null, 52 // A element (or selector) for triggering the datepicker 53 trigger: null, 54 // The ISO language code (built-in: en-US) 55 language: '', 56 // The date string format 57 format: 'mm/dd/yyyy', 58 // The initial date 59 date: null, 60 // The start view date 61 startDate: null, 62 // The end view date 63 endDate: null, 64 // The start view when initialized 65 startView: 0, 66 // 0 for days, 1 for months, 2 for years 67 // The start day of the week 68 // 0 for Sunday, 1 for Monday, 2 for Tuesday, 3 for Wednesday, 69 // 4 for Thursday, 5 for Friday, 6 for Saturday 70 weekStart: 0, 71 // Show year before month on the datepicker header 72 yearFirst: false, 73 // A string suffix to the year number. 74 yearSuffix: '', 75 // Days' name of the week. 76 days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], 77 // Shorter days' name 78 daysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], 79 // Shortest days' name 80 daysMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], 81 // Months' name 82 months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], 83 // Shorter months' name 84 monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], 85 // A element tag for each item of years, months and days 86 itemTag: 'li', 87 // A class (CSS) for muted date item 88 mutedClass: 'muted', 89 // A class (CSS) for picked date item 90 pickedClass: 'picked', 91 // A class (CSS) for disabled date item 92 disabledClass: 'disabled', 93 // A class (CSS) for highlight date item 94 highlightedClass: 'highlighted', 95 // The template of the datepicker 96 template: '<div class="datepicker-container">' + '<div class="datepicker-panel" data-view="years picker">' + '<ul>' + '<li data-view="years prev">‹</li>' + '<li data-view="years current"></li>' + '<li data-view="years next">›</li>' + '</ul>' + '<ul data-view="years"></ul>' + '</div>' + '<div class="datepicker-panel" data-view="months picker">' + '<ul>' + '<li data-view="year prev">‹</li>' + '<li data-view="year current"></li>' + '<li data-view="year next">›</li>' + '</ul>' + '<ul data-view="months"></ul>' + '</div>' + '<div class="datepicker-panel" data-view="days picker">' + '<ul>' + '<li data-view="month prev">‹</li>' + '<li data-view="month current"></li>' + '<li data-view="month next">›</li>' + '</ul>' + '<ul data-view="week"></ul>' + '<ul data-view="days"></ul>' + '</div>' + '</div>', 97 // The offset top or bottom of the datepicker from the element 98 offset: 10, 99 // The `z-index` of the datepicker 100 zIndex: 1000, 101 // Filter each date item (return `false` to disable a date item) 102 filter: null, 103 // Event shortcuts 104 show: null, 105 hide: null, 106 pick: null 107 }; 108
vendor: 17,081 bytes, lines 109-743
109 var IS_BROWSER = typeof window !== 'undefined'; 110 var WINDOW = IS_BROWSER ? window : {}; 111 var IS_TOUCH_DEVICE = IS_BROWSER ? 'ontouchstart' in WINDOW.document.documentElement : false; 112 var NAMESPACE = 'datepicker'; 113 var EVENT_CLICK = "click.".concat(NAMESPACE); 114 var EVENT_FOCUS = "focus.".concat(NAMESPACE); 115 var EVENT_HIDE = "hide.".concat(NAMESPACE); 116 var EVENT_KEYUP = "keyup.".concat(NAMESPACE); 117 var EVENT_PICK = "pick.".concat(NAMESPACE); 118 var EVENT_RESIZE = "resize.".concat(NAMESPACE); 119 var EVENT_SCROLL = "scroll.".concat(NAMESPACE); 120 var EVENT_SHOW = "show.".concat(NAMESPACE); 121 var EVENT_TOUCH_START = "touchstart.".concat(NAMESPACE); 122 var CLASS_HIDE = "".concat(NAMESPACE, "-hide"); 123 var LANGUAGES = {}; 124 var VIEWS = { 125 DAYS: 0, 126 MONTHS: 1, 127 YEARS: 2 128 }; 129 130 var toString = Object.prototype.toString; 131 function typeOf(obj) { 132 return toString.call(obj).slice(8, -1).toLowerCase(); 133 } 134 function isString(value) { 135 return typeof value === 'string'; 136 } 137 var isNaN = Number.isNaN || WINDOW.isNaN; 138 function isNumber(value) { 139 return typeof value === 'number' && !isNaN(value); 140 } 141 function isUndefined(value) { 142 return typeof value === 'undefined'; 143 } 144 function isDate(value) { 145 return typeOf(value) === 'date' && !isNaN(value.getTime()); 146 } 147 function proxy(fn, context) { 148 for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { 149 args[_key - 2] = arguments[_key]; 150 } 151 152 return function () { 153 for (var _len2 = arguments.length, args2 = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { 154 args2[_key2] = arguments[_key2]; 155 } 156 157 return fn.apply(context, args.concat(args2)); 158 }; 159 } 160 function selectorOf(view) { 161 return "[data-view=\"".concat(view, "\"]"); 162 } 163 function isLeapYear(year) { 164 return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0; 165 } 166 function getDaysInMonth(year, month) { 167 return [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]; 168 } 169 function getMinDay(year, month, day) { 170 return Math.min(day, getDaysInMonth(year, month)); 171 } 172 var formatParts = /(y|m|d)+/g; 173 function parseFormat(format) { 174 var source = String(format).toLowerCase(); 175 var parts = source.match(formatParts); 176 177 if (!parts || parts.length === 0) { 178 throw new Error('Invalid date format.'); 179 } 180 181 format = { 182 source: source, 183 parts: parts 184 }; 185 $.each(parts, function (i, part) { 186 switch (part) { 187 case 'dd': 188 case 'd': 189 format.hasDay = true; 190 break; 191 192 case 'mm': 193 case 'm': 194 format.hasMonth = true; 195 break; 196 197 case 'yyyy': 198 case 'yy': 199 format.hasYear = true; 200 break; 201 202 default: 203 } 204 }); 205 return format; 206 } 207 function getScrollParent(element) { 208 var includeHidden = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; 209 var $element = $(element); 210 var position = $element.css('position'); 211 var excludeStaticParent = position === 'absolute'; 212 var overflowRegex = includeHidden ? /auto|scroll|hidden/ : /auto|scroll/; 213 var scrollParent = $element.parents().filter(function (index, parent) { 214 var $parent = $(parent); 215 216 if (excludeStaticParent && $parent.css('position') === 'static') { 217 return false; 218 } 219 220 return overflowRegex.test($parent.css('overflow') + $parent.css('overflow-y') + $parent.css('overflow-x')); 221 }).eq(0); 222 return position === 'fixed' || !scrollParent.length ? $(element.ownerDocument || document) : scrollParent; 223 } 224 /** 225 * Add leading zeroes to the given value 226 * @param {number} value - The value to add. 227 * @param {number} [length=1] - The expected value length. 228 * @returns {string} Returns converted value. 229 */ 230 231 function addLeadingZero(value) { 232 var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; 233 var str = String(Math.abs(value)); 234 var i = str.length; 235 var result = ''; 236 237 if (value < 0) { 238 result += '-'; 239 } 240 241 while (i < length) { 242 i += 1; 243 result += '0'; 244 } 245 246 return result + str; 247 } 248 249 var REGEXP_DIGITS = /\d+/g; 250 var methods = { 251 // Show the datepicker 252 show: function show() { 253 if (!this.built) { 254 this.build(); 255 } 256 257 if (this.shown) { 258 return; 259 } 260 261 if (this.trigger(EVENT_SHOW).isDefaultPrevented()) { 262 return; 263 } 264 265 this.shown = true; 266 this.$picker.removeClass(CLASS_HIDE).on(EVENT_CLICK, $.proxy(this.click, this)); 267 this.showView(this.options.startView); 268 269 if (!this.inline) { 270 this.$scrollParent.on(EVENT_SCROLL, $.proxy(this.place, this)); 271 $(window).on(EVENT_RESIZE, this.onResize = proxy(this.place, this)); 272 $(document).on(EVENT_CLICK, this.onGlobalClick = proxy(this.globalClick, this)); 273 $(document).on(EVENT_KEYUP, this.onGlobalKeyup = proxy(this.globalKeyup, this)); 274 275 if (IS_TOUCH_DEVICE) { 276 $(document).on(EVENT_TOUCH_START, this.onTouchStart = proxy(this.touchstart, this)); 277 } 278 279 this.place(); 280 } 281 }, 282 // Hide the datepicker 283 hide: function hide() { 284 if (!this.shown) { 285 return; 286 } 287 288 if (this.trigger(EVENT_HIDE).isDefaultPrevented()) { 289 return; 290 } 291 292 this.shown = false; 293 this.$picker.addClass(CLASS_HIDE).off(EVENT_CLICK, this.click); 294 295 if (!this.inline) { 296 this.$scrollParent.off(EVENT_SCROLL, this.place); 297 $(window).off(EVENT_RESIZE, this.onResize); 298 $(document).off(EVENT_CLICK, this.onGlobalClick); 299 $(document).off(EVENT_KEYUP, this.onGlobalKeyup); 300 301 if (IS_TOUCH_DEVICE) { 302 $(document).off(EVENT_TOUCH_START, this.onTouchStart); 303 } 304 } 305 }, 306 toggle: function toggle() { 307 if (this.shown) { 308 this.hide(); 309 } else { 310 this.show(); 311 } 312 }, 313 // Update the datepicker with the current input value 314 update: function update() { 315 var value = this.getValue(); 316 317 if (value === this.oldValue) { 318 return; 319 } 320 321 this.setDate(value, true); 322 this.oldValue = value; 323 }, 324 325 /** 326 * Pick the current date to the element 327 * 328 * @param {String} _view (private) 329 */ 330 pick: function pick(_view) { 331 var $this = this.$element; 332 var date = this.date; 333 334 if (this.trigger(EVENT_PICK, { 335 view: _view || '', 336 date: date 337 }).isDefaultPrevented()) { 338 return; 339 } 340 341 date = this.formatDate(this.date); 342 this.setValue(date); 343 344 if (this.isInput) { 345 $this.trigger('input'); 346 $this.trigger('change'); 347 } 348 }, 349 // Reset the datepicker 350 reset: function reset() { 351 this.setDate(this.initialDate, true); 352 this.setValue(this.initialValue); 353 354 if (this.shown) { 355 this.showView(this.options.startView); 356 } 357 }, 358 359 /** 360 * Get the month name with given argument or the current date 361 * 362 * @param {Number} month (optional) 363 * @param {Boolean} shortForm (optional) 364 * @return {String} (month name) 365 */ 366 getMonthName: function getMonthName(month, shortForm) { 367 var options = this.options; 368 var monthsShort = options.monthsShort; 369 var months = options.months; 370 371 if ($.isNumeric(month)) { 372 month = Number(month); 373 } else if (isUndefined(shortForm)) { 374 shortForm = month; 375 } 376 377 if (shortForm === true) { 378 months = monthsShort; 379 } 380 381 return months[isNumber(month) ? month : this.date.getMonth()]; 382 }, 383 384 /** 385 * Get the day name with given argument or the current date 386 * 387 * @param {Number} day (optional) 388 * @param {Boolean} shortForm (optional) 389 * @param {Boolean} min (optional) 390 * @return {String} (day name) 391 */ 392 getDayName: function getDayName(day, shortForm, min) { 393 var options = this.options; 394 var days = options.days; 395 396 if ($.isNumeric(day)) { 397 day = Number(day); 398 } else { 399 if (isUndefined(min)) { 400 min = shortForm; 401 } 402 403 if (isUndefined(shortForm)) { 404 shortForm = day; 405 } 406 } 407 408 if (min) { 409 days = options.daysMin; 410 } else if (shortForm) { 411 days = options.daysShort; 412 } 413 414 return days[isNumber(day) ? day : this.date.getDay()]; 415 }, 416 417 /** 418 * Get the current date 419 * 420 * @param {Boolean} formatted (optional) 421 * @return {Date|String} (date) 422 */ 423 getDate: function getDate(formatted) { 424 var date = this.date; 425 return formatted ? this.formatDate(date) : new Date(date); 426 }, 427 428 /** 429 * Set the current date with a new date 430 * 431 * @param {Date} date 432 * @param {Boolean} _updated (private) 433 */ 434 setDate: function setDate(date, _updated) { 435 var filter = this.options.filter; 436 437 if (isDate(date) || isString(date)) { 438 date = this.parseDate(date); 439 440 if ($.isFunction(filter) && filter.call(this.$element, date, 'day') === false) { 441 return; 442 } 443 444 this.date = date; 445 this.viewDate = new Date(date); 446 447 if (!_updated) { 448 this.pick(); 449 } 450 451 if (this.built) { 452 this.render(); 453 } 454 } 455 }, 456 457 /** 458 * Set the start view date with a new date 459 * 460 * @param {Date|string|null} date 461 */ 462 setStartDate: function setStartDate(date) { 463 if (isDate(date) || isString(date)) { 464 this.startDate = this.parseDate(date); 465 } else { 466 this.startDate = null; 467 } 468 469 if (this.built) { 470 this.render(); 471 } 472 }, 473 474 /** 475 * Set the end view date with a new date 476 * 477 * @param {Date|string|null} date 478 */ 479 setEndDate: function setEndDate(date) { 480 if (isDate(date) || isString(date)) { 481 this.endDate = this.parseDate(date); 482 } else { 483 this.endDate = null; 484 } 485 486 if (this.built) { 487 this.render(); 488 } 489 }, 490 491 /** 492 * Parse a date string with the set date format 493 * 494 * @param {String} date 495 * @return {Date} (parsed date) 496 */ 497 parseDate: function parseDate(date) { 498 var format = this.format; 499 var parts = []; 500 501 if (!isDate(date)) { 502 if (isString(date)) { 503 parts = date.match(REGEXP_DIGITS) || []; 504 } 505 506 date = date ? new Date(date) : new Date(); 507 508 if (!isDate(date)) { 509 date = new Date(); 510 } 511 512 if (parts.length === format.parts.length) { 513 $.each(parts, function (i, part) { 514 var value = parseInt(part, 10); 515 516 switch (format.parts[i]) { 517 case 'dd': 518 case 'd': 519 date.setDate(value); 520 break; 521 522 case 'mm': 523 case 'm': 524 date.setMonth(value - 1); 525 break; 526 527 case 'yy': 528 date.setFullYear(2000 + value); 529 break; 530 531 case 'yyyy': 532 // Converts 2-digit year to 2000+ 533 date.setFullYear(part.length === 2 ? 2000 + value : value); 534 break; 535 536 default: 537 } 538 }); 539 } 540 } // Ignore hours, minutes, seconds and milliseconds to avoid side effect (#192) 541 542 543 return new Date(date.getFullYear(), date.getMonth(), date.getDate()); 544 }, 545 546 /** 547 * Format a date object to a string with the set date format 548 * 549 * @param {Date} date 550 * @return {String} (formatted date) 551 */ 552 formatDate: function formatDate(date) { 553 var format = this.format; 554 var formatted = ''; 555 556 if (isDate(date)) { 557 var year = date.getFullYear(); 558 var month = date.getMonth(); 559 var day = date.getDate(); 560 var values = { 561 d: day, 562 dd: addLeadingZero(day, 2), 563 m: month + 1, 564 mm: addLeadingZero(month + 1, 2), 565 yy: String(year).substring(2), 566 yyyy: addLeadingZero(year, 4) 567 }; 568 formatted = format.source; 569 $.each(format.parts, function (i, part) { 570 formatted = formatted.replace(part, values[part]); 571 }); 572 } 573 574 return formatted; 575 }, 576 // Destroy the datepicker and remove the instance from the target element 577 destroy: function destroy() { 578 this.unbind(); 579 this.unbuild(); 580 this.$element.removeData(NAMESPACE); 581 } 582 }; 583 584 var handlers = { 585 click: function click(e) { 586 var $target = $(e.target); 587 var options = this.options, 588 date = this.date, 589 viewDate = this.viewDate, 590 format = this.format; 591 e.stopPropagation(); 592 e.preventDefault(); 593 594 if ($target.hasClass('disabled')) { 595 return; 596 } 597 598 var view = $target.data('view'); 599 var viewYear = viewDate.getFullYear(); 600 var viewMonth = viewDate.getMonth(); 601 var viewDay = viewDate.getDate(); 602 603 switch (view) { 604 case 'years prev': 605 case 'years next': 606 { 607 viewYear = view === 'years prev' ? viewYear - 10 : viewYear + 10; 608 viewDate.setFullYear(viewYear); 609 viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay)); 610 this.renderYears(); 611 break; 612 } 613 614 case 'year prev': 615 case 'year next': 616 viewYear = view === 'year prev' ? viewYear - 1 : viewYear + 1; 617 viewDate.setFullYear(viewYear); 618 viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay)); 619 this.renderMonths(); 620 break; 621 622 case 'year current': 623 if (format.hasYear) { 624 this.showView(VIEWS.YEARS); 625 } 626 627 break; 628 629 case 'year picked': 630 if (format.hasMonth) { 631 this.showView(VIEWS.MONTHS); 632 } else { 633 $target.addClass(options.pickedClass).siblings().removeClass(options.pickedClass); 634 this.hideView(); 635 } 636 637 this.pick('year'); 638 break; 639 640 case 'year': 641 viewYear = parseInt($target.text(), 10); 642 date.setFullYear(viewYear); 643 date.setDate(getMinDay(viewYear, viewMonth, viewDay)); 644 viewDate.setFullYear(viewYear); 645 viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay)); 646 647 if (format.hasMonth) { 648 this.showView(VIEWS.MONTHS); 649 } else { 650 $target.addClass(options.pickedClass).siblings().removeClass(options.pickedClass); 651 this.hideView(); 652 } 653 654 this.pick('year'); 655 break; 656 657 case 'month prev': 658 case 'month next': 659 viewMonth = view === 'month prev' ? viewMonth - 1 : viewMonth + 1; 660 661 if (viewMonth < 0) { 662 viewYear -= 1; 663 viewMonth += 12; 664 } else if (viewMonth > 11) { 665 viewYear += 1; 666 viewMonth -= 12; 667 } 668 669 viewDate.setFullYear(viewYear); 670 viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay)); 671 viewDate.setMonth(viewMonth); 672 this.renderDays(); 673 break; 674 675 case 'month current': 676 if (format.hasMonth) { 677 this.showView(VIEWS.MONTHS); 678 } 679 680 break; 681 682 case 'month picked': 683 if (format.hasDay) { 684 this.showView(VIEWS.DAYS); 685 } else { 686 $target.addClass(options.pickedClass).siblings().removeClass(options.pickedClass); 687 this.hideView(); 688 } 689 690 this.pick('month'); 691 break; 692 693 case 'month': 694 viewMonth = $.inArray($target.text(), options.monthsShort); 695 date.setFullYear(viewYear); // Set date before month to avoid month changing (#195) 696 697 date.setDate(getMinDay(viewYear, viewMonth, viewDay)); 698 date.setMonth(viewMonth); 699 viewDate.setFullYear(viewYear); 700 viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay)); 701 viewDate.setMonth(viewMonth); 702 703 if (format.hasDay) { 704 this.showView(VIEWS.DAYS); 705 } else { 706 $target.addClass(options.pickedClass).siblings().removeClass(options.pickedClass); 707 this.hideView(); 708 } 709 710 this.pick('month'); 711 break; 712 713 case 'day prev': 714 case 'day next': 715 case 'day': 716 if (view === 'day prev') { 717 viewMonth -= 1; 718 } else if (view === 'day next') { 719 viewMonth += 1; 720 } 721 722 viewDay = parseInt($target.text(), 10); 723 date.setFullYear(viewYear); 724 date.setMonth(viewMonth); 725 date.setDate(viewDay); 726 viewDate.setFullYear(viewYear); 727 viewDate.setMonth(viewMonth); 728 viewDate.setDate(viewDay); 729 this.renderDays(); 730 731 if (view === 'day') { 732 this.hideView(); 733 } 734 735 this.pick('day'); 736 break; 737 738 case 'day picked': 739 this.hideView(); 740 this.pick('day'); 741 break; 742 743 default:
vendor: 11,631 bytes, lines 743-1095
743 744 } 745 }, 746 globalClick: function globalClick(_ref) { 747 var target = _ref.target; 748 var element = this.element, 749 $trigger = this.$trigger; 750 var trigger = $trigger[0]; 751 var hidden = true; 752 753 while (target !== document) { 754 if (target === trigger || target === element) { 755 hidden = false; 756 break; 757 } 758 759 target = target.parentNode; 760 } 761 762 if (hidden) { 763 this.hide(); 764 } 765 }, 766 keyup: function keyup() { 767 this.update(); 768 }, 769 globalKeyup: function globalKeyup(_ref2) { 770 var target = _ref2.target, 771 key = _ref2.key, 772 keyCode = _ref2.keyCode; 773 774 if (this.isInput && target !== this.element && this.shown && (key === 'Tab' || keyCode === 9)) { 775 this.hide(); 776 } 777 }, 778 touchstart: function touchstart(_ref3) { 779 var target = _ref3.target; 780 781 // Emulate click in touch devices to support hiding the picker automatically (#197). 782 if (this.isInput && target !== this.element && !$.contains(this.$picker[0], target)) { 783 this.hide(); 784 this.element.blur(); 785 } 786 } 787 }; 788 789 var render = { 790 render: function render() { 791 this.renderYears(); 792 this.renderMonths(); 793 this.renderDays(); 794 }, 795 renderWeek: function renderWeek() { 796 var _this = this; 797 798 var items = []; 799 var _this$options = this.options, 800 weekStart = _this$options.weekStart, 801 daysMin = _this$options.daysMin; 802 weekStart = parseInt(weekStart, 10) % 7; 803 daysMin = daysMin.slice(weekStart).concat(daysMin.slice(0, weekStart)); 804 $.each(daysMin, function (i, day) { 805 items.push(_this.createItem({ 806 text: day 807 })); 808 }); 809 this.$week.html(items.join('')); 810 }, 811 renderYears: function renderYears() { 812 var options = this.options, 813 startDate = this.startDate, 814 endDate = this.endDate; 815 var disabledClass = options.disabledClass, 816 filter = options.filter, 817 yearSuffix = options.yearSuffix; 818 var viewYear = this.viewDate.getFullYear(); 819 var now = new Date(); 820 var thisYear = now.getFullYear(); 821 var year = this.date.getFullYear(); 822 var start = -5; 823 var end = 6; 824 var items = []; 825 var prevDisabled = false; 826 var nextDisabled = false; 827 var i; 828 829 for (i = start; i <= end; i += 1) { 830 var date = new Date(viewYear + i, 1, 1); 831 var disabled = false; 832 833 if (startDate) { 834 disabled = date.getFullYear() < startDate.getFullYear(); 835 836 if (i === start) { 837 prevDisabled = disabled; 838 } 839 } 840 841 if (!disabled && endDate) { 842 disabled = date.getFullYear() > endDate.getFullYear(); 843 844 if (i === end) { 845 nextDisabled = disabled; 846 } 847 } 848 849 if (!disabled && filter) { 850 disabled = filter.call(this.$element, date, 'year') === false; 851 } 852 853 var picked = viewYear + i === year; 854 var view = picked ? 'year picked' : 'year'; 855 items.push(this.createItem({ 856 picked: picked, 857 disabled: disabled, 858 text: viewYear + i, 859 view: disabled ? 'year disabled' : view, 860 highlighted: date.getFullYear() === thisYear 861 })); 862 } 863 864 this.$yearsPrev.toggleClass(disabledClass, prevDisabled); 865 this.$yearsNext.toggleClass(disabledClass, nextDisabled); 866 this.$yearsCurrent.toggleClass(disabledClass, true).html("".concat(viewYear + start + yearSuffix, " - ").concat(viewYear + end).concat(yearSuffix)); 867 this.$years.html(items.join('')); 868 }, 869 renderMonths: function renderMonths() { 870 var options = this.options, 871 startDate = this.startDate, 872 endDate = this.endDate, 873 viewDate = this.viewDate; 874 var disabledClass = options.disabledClass || ''; 875 var months = options.monthsShort; 876 var filter = $.isFunction(options.filter) && options.filter; 877 var viewYear = viewDate.getFullYear(); 878 var now = new Date(); 879 var thisYear = now.getFullYear(); 880 var thisMonth = now.getMonth(); 881 var year = this.date.getFullYear(); 882 var month = this.date.getMonth(); 883 var items = []; 884 var prevDisabled = false; 885 var nextDisabled = false; 886 var i; 887 888 for (i = 0; i <= 11; i += 1) { 889 var date = new Date(viewYear, i, 1); 890 var disabled = false; 891 892 if (startDate) { 893 prevDisabled = date.getFullYear() === startDate.getFullYear(); 894 disabled = prevDisabled && date.getMonth() < startDate.getMonth(); 895 } 896 897 if (!disabled && endDate) { 898 nextDisabled = date.getFullYear() === endDate.getFullYear(); 899 disabled = nextDisabled && date.getMonth() > endDate.getMonth(); 900 } 901 902 if (!disabled && filter) { 903 disabled = filter.call(this.$element, date, 'month') === false; 904 } 905 906 var picked = viewYear === year && i === month; 907 var view = picked ? 'month picked' : 'month'; 908 items.push(this.createItem({ 909 disabled: disabled, 910 picked: picked, 911 highlighted: viewYear === thisYear && date.getMonth() === thisMonth, 912 index: i, 913 text: months[i], 914 view: disabled ? 'month disabled' : view 915 })); 916 } 917 918 this.$yearPrev.toggleClass(disabledClass, prevDisabled); 919 this.$yearNext.toggleClass(disabledClass, nextDisabled); 920 this.$yearCurrent.toggleClass(disabledClass, prevDisabled && nextDisabled).html(viewYear + options.yearSuffix || ''); 921 this.$months.html(items.join('')); 922 }, 923 renderDays: function renderDays() { 924 var $element = this.$element, 925 options = this.options, 926 startDate = this.startDate, 927 endDate = this.endDate, 928 viewDate = this.viewDate, 929 currentDate = this.date; 930 var disabledClass = options.disabledClass, 931 filter = options.filter, 932 months = options.months, 933 weekStart = options.weekStart, 934 yearSuffix = options.yearSuffix; 935 var viewYear = viewDate.getFullYear(); 936 var viewMonth = viewDate.getMonth(); 937 var now = new Date(); 938 var thisYear = now.getFullYear(); 939 var thisMonth = now.getMonth(); 940 var thisDay = now.getDate(); 941 var year = currentDate.getFullYear(); 942 var month = currentDate.getMonth(); 943 var day = currentDate.getDate(); 944 var length; 945 var i; 946 var n; // Days of prev month 947 // ----------------------------------------------------------------------- 948 949 var prevItems = []; 950 var prevViewYear = viewYear; 951 var prevViewMonth = viewMonth; 952 var prevDisabled = false; 953 954 if (viewMonth === 0) { 955 prevViewYear -= 1; 956 prevViewMonth = 11; 957 } else { 958 prevViewMonth -= 1; 959 } // The length of the days of prev month 960 961 962 length = getDaysInMonth(prevViewYear, prevViewMonth); // The first day of current month 963 964 var firstDay = new Date(viewYear, viewMonth, 1); // The visible length of the days of prev month 965 // [0,1,2,3,4,5,6] - [0,1,2,3,4,5,6] => [-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6] 966 967 n = firstDay.getDay() - parseInt(weekStart, 10) % 7; // [-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6] => [1,2,3,4,5,6,7] 968 969 if (n <= 0) { 970 n += 7; 971 } 972 973 if (startDate) { 974 prevDisabled = firstDay.getTime() <= startDate.getTime(); 975 } 976 977 for (i = length - (n - 1); i <= length; i += 1) { 978 var prevViewDate = new Date(prevViewYear, prevViewMonth, i); 979 var disabled = false; 980 981 if (startDate) { 982 disabled = prevViewDate.getTime() < startDate.getTime(); 983 } 984 985 if (!disabled && filter) { 986 disabled = filter.call($element, prevViewDate, 'day') === false; 987 } 988 989 prevItems.push(this.createItem({ 990 disabled: disabled, 991 highlighted: prevViewYear === thisYear && prevViewMonth === thisMonth && prevViewDate.getDate() === thisDay, 992 muted: true, 993 picked: prevViewYear === year && prevViewMonth === month && i === day, 994 text: i, 995 view: 'day prev' 996 })); 997 } // Days of next month 998 // ----------------------------------------------------------------------- 999 1000 1001 var nextItems = []; 1002 var nextViewYear = viewYear; 1003 var nextViewMonth = viewMonth; 1004 var nextDisabled = false; 1005 1006 if (viewMonth === 11) { 1007 nextViewYear += 1; 1008 nextViewMonth = 0; 1009 } else { 1010 nextViewMonth += 1; 1011 } // The length of the days of current month 1012 1013 1014 length = getDaysInMonth(viewYear, viewMonth); // The visible length of next month (42 means 6 rows and 7 columns) 1015 1016 n = 42 - (prevItems.length + length); // The last day of current month 1017 1018 var lastDate = new Date(viewYear, viewMonth, length); 1019 1020 if (endDate) { 1021 nextDisabled = lastDate.getTime() >= endDate.getTime(); 1022 } 1023 1024 for (i = 1; i <= n; i += 1) { 1025 var date = new Date(nextViewYear, nextViewMonth, i); 1026 var picked = nextViewYear === year && nextViewMonth === month && i === day; 1027 var _disabled = false; 1028 1029 if (endDate) { 1030 _disabled = date.getTime() > endDate.getTime(); 1031 } 1032 1033 if (!_disabled && filter) { 1034 _disabled = filter.call($element, date, 'day') === false; 1035 } 1036 1037 nextItems.push(this.createItem({ 1038 disabled: _disabled, 1039 picked: picked, 1040 highlighted: nextViewYear === thisYear && nextViewMonth === thisMonth && date.getDate() === thisDay, 1041 muted: true, 1042 text: i, 1043 view: 'day next' 1044 })); 1045 } // Days of current month 1046 // ----------------------------------------------------------------------- 1047 1048 1049 var items = []; 1050 1051 for (i = 1; i <= length; i += 1) { 1052 var _date = new Date(viewYear, viewMonth, i); 1053 1054 var _disabled2 = false; 1055 1056 if (startDate) { 1057 _disabled2 = _date.getTime() < startDate.getTime(); 1058 } 1059 1060 if (!_disabled2 && endDate) { 1061 _disabled2 = _date.getTime() > endDate.getTime(); 1062 } 1063 1064 if (!_disabled2 && filter) { 1065 _disabled2 = filter.call($element, _date, 'day') === false; 1066 } 1067 1068 var _picked = viewYear === year && viewMonth === month && i === day; 1069 1070 var view = _picked ? 'day picked' : 'day'; 1071 items.push(this.createItem({ 1072 disabled: _disabled2, 1073 picked: _picked, 1074 highlighted: viewYear === thisYear && viewMonth === thisMonth && _date.getDate() === thisDay, 1075 text: i, 1076 view: _disabled2 ? 'day disabled' : view 1077 })); 1078 } // Render days picker 1079 // ----------------------------------------------------------------------- 1080 1081 1082 this.$monthPrev.toggleClass(disabledClass, prevDisabled); 1083 this.$monthNext.toggleClass(disabledClass, nextDisabled); 1084 this.$monthCurrent.toggleClass(disabledClass, prevDisabled && nextDisabled).html(options.yearFirst ? "".concat(viewYear + yearSuffix, " ").concat(months[viewMonth]) : "".concat(months[viewMonth], " ").concat(viewYear).concat(yearSuffix)); 1085 this.$days.html(prevItems.join('') + items.join('') + nextItems.join('')); 1086 } 1087 }; 1088 1089 var CLASS_TOP_LEFT = "".concat(NAMESPACE, "-top-left"); 1090 var CLASS_TOP_RIGHT = "".concat(NAMESPACE, "-top-right"); 1091 var CLASS_BOTTOM_LEFT = "".concat(NAMESPACE, "-bottom-left"); 1092 var CLASS_BOTTOM_RIGHT = "".concat(NAMESPACE, "-bottom-right"); 1093 var CLASS_PLACEMENTS = [CLASS_TOP_LEFT, CLASS_TOP_RIGHT, CLASS_BOTTOM_LEFT, CLASS_BOTTOM_RIGHT].join(' '); 1094 1095 var Datepicker =
1095 1096 /*#__PURE__*/ 1097
vendor: 12,282 bytes, lines 1097-1519
1097function () { 1098 function Datepicker(element) { 1099 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 1100 1101 _classCallCheck(this, Datepicker); 1102 1103 this.$element = $(element); 1104 this.element = element; 1105 this.options = $.extend({}, DEFAULTS, LANGUAGES[options.language], $.isPlainObject(options) && options); 1106 this.$scrollParent = getScrollParent(element, true); 1107 this.built = false; 1108 this.shown = false; 1109 this.isInput = false; 1110 this.inline = false; 1111 this.initialValue = ''; 1112 this.initialDate = null; 1113 this.startDate = null; 1114 this.endDate = null; 1115 this.init(); 1116 } 1117 1118 _createClass(Datepicker, [{ 1119 key: "init", 1120 value: function init() { 1121 var $this = this.$element, 1122 options = this.options; 1123 var startDate = options.startDate, 1124 endDate = options.endDate, 1125 date = options.date; 1126 this.$trigger = $(options.trigger); 1127 this.isInput = $this.is('input') || $this.is('textarea'); 1128 this.inline = options.inline && (options.container || !this.isInput); 1129 this.format = parseFormat(options.format); 1130 var initialValue = this.getValue(); 1131 this.initialValue = initialValue; 1132 this.oldValue = initialValue; 1133 date = this.parseDate(date || initialValue); 1134 1135 if (startDate) { 1136 startDate = this.parseDate(startDate); 1137 1138 if (date.getTime() < startDate.getTime()) { 1139 date = new Date(startDate); 1140 } 1141 1142 this.startDate = startDate; 1143 } 1144 1145 if (endDate) { 1146 endDate = this.parseDate(endDate); 1147 1148 if (startDate && endDate.getTime() < startDate.getTime()) { 1149 endDate = new Date(startDate); 1150 } 1151 1152 if (date.getTime() > endDate.getTime()) { 1153 date = new Date(endDate); 1154 } 1155 1156 this.endDate = endDate; 1157 } 1158 1159 this.date = date; 1160 this.viewDate = new Date(date); 1161 this.initialDate = new Date(this.date); 1162 this.bind(); 1163 1164 if (options.autoShow || this.inline) { 1165 this.show(); 1166 } 1167 1168 if (options.autoPick) { 1169 this.pick(); 1170 } 1171 } 1172 }, { 1173 key: "build", 1174 value: function build() { 1175 if (this.built) { 1176 return; 1177 } 1178 1179 this.built = true; 1180 var $this = this.$element, 1181 options = this.options; 1182 var $picker = $(options.template); 1183 this.$picker = $picker; 1184 this.$week = $picker.find(selectorOf('week')); // Years view 1185 1186 this.$yearsPicker = $picker.find(selectorOf('years picker')); 1187 this.$yearsPrev = $picker.find(selectorOf('years prev')); 1188 this.$yearsNext = $picker.find(selectorOf('years next')); 1189 this.$yearsCurrent = $picker.find(selectorOf('years current')); 1190 this.$years = $picker.find(selectorOf('years')); // Months view 1191 1192 this.$monthsPicker = $picker.find(selectorOf('months picker')); 1193 this.$yearPrev = $picker.find(selectorOf('year prev')); 1194 this.$yearNext = $picker.find(selectorOf('year next')); 1195 this.$yearCurrent = $picker.find(selectorOf('year current')); 1196 this.$months = $picker.find(selectorOf('months')); // Days view 1197 1198 this.$daysPicker = $picker.find(selectorOf('days picker')); 1199 this.$monthPrev = $picker.find(selectorOf('month prev')); 1200 this.$monthNext = $picker.find(selectorOf('month next')); 1201 this.$monthCurrent = $picker.find(selectorOf('month current')); 1202 this.$days = $picker.find(selectorOf('days')); 1203 1204 if (this.inline) { 1205 $(options.container || $this).append($picker.addClass("".concat(NAMESPACE, "-inline"))); 1206 } else { 1207 $(document.body).append($picker.addClass("".concat(NAMESPACE, "-dropdown"))); 1208 $picker.addClass(CLASS_HIDE).css({ 1209 zIndex: parseInt(options.zIndex, 10) 1210 }); 1211 } 1212 1213 this.renderWeek(); 1214 } 1215 }, { 1216 key: "unbuild", 1217 value: function unbuild() { 1218 if (!this.built) { 1219 return; 1220 } 1221 1222 this.built = false; 1223 this.$picker.remove(); 1224 } 1225 }, { 1226 key: "bind", 1227 value: function bind() { 1228 var options = this.options, 1229 $this = this.$element; 1230 1231 if ($.isFunction(options.show)) { 1232 $this.on(EVENT_SHOW, options.show); 1233 } 1234 1235 if ($.isFunction(options.hide)) { 1236 $this.on(EVENT_HIDE, options.hide); 1237 } 1238 1239 if ($.isFunction(options.pick)) { 1240 $this.on(EVENT_PICK, options.pick); 1241 } 1242 1243 if (this.isInput) { 1244 $this.on(EVENT_KEYUP, $.proxy(this.keyup, this)); 1245 } 1246 1247 if (!this.inline) { 1248 if (options.trigger) { 1249 this.$trigger.on(EVENT_CLICK, $.proxy(this.toggle, this)); 1250 } else if (this.isInput) { 1251 $this.on(EVENT_FOCUS, $.proxy(this.show, this)); 1252 } else { 1253 $this.on(EVENT_CLICK, $.proxy(this.show, this)); 1254 } 1255 } 1256 } 1257 }, { 1258 key: "unbind", 1259 value: function unbind() { 1260 var $this = this.$element, 1261 options = this.options; 1262 1263 if ($.isFunction(options.show)) { 1264 $this.off(EVENT_SHOW, options.show); 1265 } 1266 1267 if ($.isFunction(options.hide)) { 1268 $this.off(EVENT_HIDE, options.hide); 1269 } 1270 1271 if ($.isFunction(options.pick)) { 1272 $this.off(EVENT_PICK, options.pick); 1273 } 1274 1275 if (this.isInput) { 1276 $this.off(EVENT_KEYUP, this.keyup); 1277 } 1278 1279 if (!this.inline) { 1280 if (options.trigger) { 1281 this.$trigger.off(EVENT_CLICK, this.toggle); 1282 } else if (this.isInput) { 1283 $this.off(EVENT_FOCUS, this.show); 1284 } else { 1285 $this.off(EVENT_CLICK, this.show); 1286 } 1287 } 1288 } 1289 }, { 1290 key: "showView", 1291 value: function showView(view) { 1292 var $yearsPicker = this.$yearsPicker, 1293 $monthsPicker = this.$monthsPicker, 1294 $daysPicker = this.$daysPicker, 1295 format = this.format; 1296 1297 if (format.hasYear || format.hasMonth || format.hasDay) { 1298 switch (Number(view)) { 1299 case VIEWS.YEARS: 1300 $monthsPicker.addClass(CLASS_HIDE); 1301 $daysPicker.addClass(CLASS_HIDE); 1302 1303 if (format.hasYear) { 1304 this.renderYears(); 1305 $yearsPicker.removeClass(CLASS_HIDE); 1306 this.place(); 1307 } else { 1308 this.showView(VIEWS.DAYS); 1309 } 1310 1311 break; 1312 1313 case VIEWS.MONTHS: 1314 $yearsPicker.addClass(CLASS_HIDE); 1315 $daysPicker.addClass(CLASS_HIDE); 1316 1317 if (format.hasMonth) { 1318 this.renderMonths(); 1319 $monthsPicker.removeClass(CLASS_HIDE); 1320 this.place(); 1321 } else { 1322 this.showView(VIEWS.YEARS); 1323 } 1324 1325 break; 1326 // case VIEWS.DAYS: 1327 1328 default: 1329 $yearsPicker.addClass(CLASS_HIDE); 1330 $monthsPicker.addClass(CLASS_HIDE); 1331 1332 if (format.hasDay) { 1333 this.renderDays(); 1334 $daysPicker.removeClass(CLASS_HIDE); 1335 this.place(); 1336 } else { 1337 this.showView(VIEWS.MONTHS); 1338 } 1339 1340 } 1341 } 1342 } 1343 }, { 1344 key: "hideView", 1345 value: function hideView() { 1346 if (!this.inline && this.options.autoHide) { 1347 this.hide(); 1348 } 1349 } 1350 }, { 1351 key: "place", 1352 value: function place() { 1353 if (this.inline) { 1354 return; 1355 } 1356 1357 var $this = this.$element, 1358 options = this.options, 1359 $picker = this.$picker; 1360 var containerWidth = $(document).outerWidth(); 1361 var containerHeight = $(document).outerHeight(); 1362 var elementWidth = $this.outerWidth(); 1363 var elementHeight = $this.outerHeight(); 1364 var width = $picker.width(); 1365 var height = $picker.height(); 1366 1367 var _$this$offset = $this.offset(), 1368 left = _$this$offset.left, 1369 top = _$this$offset.top; 1370 1371 var offset = parseFloat(options.offset); 1372 var placement = CLASS_TOP_LEFT; 1373 1374 if (isNaN(offset)) { 1375 offset = 10; 1376 } 1377 1378 if (top > height && top + elementHeight + height > containerHeight) { 1379 top -= height + offset; 1380 placement = CLASS_BOTTOM_LEFT; 1381 } else { 1382 top += elementHeight + offset; 1383 } 1384 1385 if (left + width > containerWidth) { 1386 left += elementWidth - width; 1387 placement = placement.replace('left', 'right'); 1388 } 1389 1390 $picker.removeClass(CLASS_PLACEMENTS).addClass(placement).css({ 1391 top: top, 1392 left: left 1393 }); 1394 } // A shortcut for triggering custom events 1395 1396 }, { 1397 key: "trigger", 1398 value: function trigger(type, data) { 1399 var e = $.Event(type, data); 1400 this.$element.trigger(e); 1401 return e; 1402 } 1403 }, { 1404 key: "createItem", 1405 value: function createItem(data) { 1406 var options = this.options; 1407 var itemTag = options.itemTag; 1408 var item = { 1409 text: '', 1410 view: '', 1411 muted: false, 1412 picked: false, 1413 disabled: false, 1414 highlighted: false 1415 }; 1416 var classes = []; 1417 $.extend(item, data); 1418 1419 if (item.muted) { 1420 classes.push(options.mutedClass); 1421 } 1422 1423 if (item.highlighted) { 1424 classes.push(options.highlightedClass); 1425 } 1426 1427 if (item.picked) { 1428 classes.push(options.pickedClass); 1429 } 1430 1431 if (item.disabled) { 1432 classes.push(options.disabledClass); 1433 } 1434 1435 return "<".concat(itemTag, " class=\"").concat(classes.join(' '), "\" data-view=\"").concat(item.view, "\">").concat(item.text, "</").concat(itemTag, ">"); 1436 } 1437 }, { 1438 key: "getValue", 1439 value: function getValue() { 1440 var $this = this.$element; 1441 return this.isInput ? $this.val() : $this.text(); 1442 } 1443 }, { 1444 key: "setValue", 1445 value: function setValue() { 1446 var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''; 1447 var $this = this.$element; 1448 1449 if (this.isInput) { 1450 $this.val(value); 1451 } else if (!this.inline || this.options.container) { 1452 $this.text(value); 1453 } 1454 } 1455 }], [{ 1456 key: "setDefaults", 1457 value: function setDefaults() { 1458 var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; 1459 $.extend(DEFAULTS, LANGUAGES[options.language], $.isPlainObject(options) && options); 1460 } 1461 }]); 1462 1463 return Datepicker; 1464 }(); 1465 1466 if ($.extend) { 1467 $.extend(Datepicker.prototype, render, handlers, methods); 1468 } 1469 1470 if ($.fn) { 1471 var AnotherDatepicker = $.fn.datepicker; 1472 1473 $.fn.datepicker = function jQueryDatepicker(option) { 1474 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { 1475 args[_key - 1] = arguments[_key]; 1476 } 1477 1478 var result; 1479 this.each(function (i, element) { 1480 var $element = $(element); 1481 var isDestroy = option === 'destroy'; 1482 var datepicker = $element.data(NAMESPACE); 1483 1484 if (!datepicker) { 1485 if (isDestroy) { 1486 return; 1487 } 1488 1489 var options = $.extend({}, $element.data(), $.isPlainObject(option) && option); 1490 datepicker = new Datepicker(element, options); 1491 $element.data(NAMESPACE, datepicker); 1492 } 1493 1494 if (isString(option)) { 1495 var fn = datepicker[option]; 1496 1497 if ($.isFunction(fn)) { 1498 result = fn.apply(datepicker, args); 1499 1500 if (isDestroy) { 1501 $element.removeData(NAMESPACE); 1502 } 1503 } 1504 } 1505 }); 1506 return !isUndefined(result) ? result : this; 1507 }; 1508 1509 $.fn.datepicker.Constructor = Datepicker; 1510 $.fn.datepicker.languages = LANGUAGES; 1511 $.fn.datepicker.setDefaults = Datepicker.setDefaults; 1512 1513 $.fn.datepicker.noConflict = function noConflict() { 1514 $.fn.datepicker = AnotherDatepicker; 1515 return this; 1516 }; 1517 } 1518 1519}))
1519;
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.