12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520 |
- /*!
- * Datepicker v1.0.10
- * https://fengyuanchen.github.io/datepicker
- *
- * Copyright 2014-present Chen Fengyuan
- * Released under the MIT license
- *
- * Date: 2020-09-29T14:46:10.983Z
- */
- 'use strict';
- var $ = require('jquery');
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
- var $__default = /*#__PURE__*/_interopDefaultLegacy($);
- function _classCallCheck(instance, Constructor) {
- if (!(instance instanceof Constructor)) {
- throw new TypeError("Cannot call a class as a function");
- }
- }
- function _defineProperties(target, props) {
- for (var i = 0; i < props.length; i++) {
- var descriptor = props[i];
- descriptor.enumerable = descriptor.enumerable || false;
- descriptor.configurable = true;
- if ("value" in descriptor) descriptor.writable = true;
- Object.defineProperty(target, descriptor.key, descriptor);
- }
- }
- function _createClass(Constructor, protoProps, staticProps) {
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
- if (staticProps) _defineProperties(Constructor, staticProps);
- return Constructor;
- }
- var DEFAULTS = {
- // Show the datepicker automatically when initialized
- autoShow: false,
- // Hide the datepicker automatically when picked
- autoHide: false,
- // Pick the initial date automatically when initialized
- autoPick: false,
- // Enable inline mode
- inline: false,
- // A element (or selector) for putting the datepicker
- container: null,
- // A element (or selector) for triggering the datepicker
- trigger: null,
- // The ISO language code (built-in: en-US)
- language: '',
- // The date string format
- format: 'mm/dd/yyyy',
- // The initial date
- date: null,
- // The start view date
- startDate: null,
- // The end view date
- endDate: null,
- // The start view when initialized
- startView: 0,
- // 0 for days, 1 for months, 2 for years
- // The start day of the week
- // 0 for Sunday, 1 for Monday, 2 for Tuesday, 3 for Wednesday,
- // 4 for Thursday, 5 for Friday, 6 for Saturday
- weekStart: 0,
- // Show year before month on the datepicker header
- yearFirst: false,
- // A string suffix to the year number.
- yearSuffix: '',
- // Days' name of the week.
- days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
- // Shorter days' name
- daysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
- // Shortest days' name
- daysMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
- // Months' name
- months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
- // Shorter months' name
- monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
- // A element tag for each item of years, months and days
- itemTag: 'li',
- // A class (CSS) for muted date item
- mutedClass: 'muted',
- // A class (CSS) for picked date item
- pickedClass: 'picked',
- // A class (CSS) for disabled date item
- disabledClass: 'disabled',
- // A class (CSS) for highlight date item
- highlightedClass: 'highlighted',
- // The template of the datepicker
- 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>',
- // The offset top or bottom of the datepicker from the element
- offset: 10,
- // The `z-index` of the datepicker
- zIndex: 1000,
- // Filter each date item (return `false` to disable a date item)
- filter: null,
- // Event shortcuts
- show: null,
- hide: null,
- pick: null
- };
- var IS_BROWSER = typeof window !== 'undefined';
- var WINDOW = IS_BROWSER ? window : {};
- var IS_TOUCH_DEVICE = IS_BROWSER ? 'ontouchstart' in WINDOW.document.documentElement : false;
- var NAMESPACE = 'datepicker';
- var EVENT_CLICK = "click.".concat(NAMESPACE);
- var EVENT_FOCUS = "focus.".concat(NAMESPACE);
- var EVENT_HIDE = "hide.".concat(NAMESPACE);
- var EVENT_KEYUP = "keyup.".concat(NAMESPACE);
- var EVENT_PICK = "pick.".concat(NAMESPACE);
- var EVENT_RESIZE = "resize.".concat(NAMESPACE);
- var EVENT_SCROLL = "scroll.".concat(NAMESPACE);
- var EVENT_SHOW = "show.".concat(NAMESPACE);
- var EVENT_TOUCH_START = "touchstart.".concat(NAMESPACE);
- var CLASS_HIDE = "".concat(NAMESPACE, "-hide");
- var LANGUAGES = {};
- var VIEWS = {
- DAYS: 0,
- MONTHS: 1,
- YEARS: 2
- };
- var toString = Object.prototype.toString;
- function typeOf(obj) {
- return toString.call(obj).slice(8, -1).toLowerCase();
- }
- function isString(value) {
- return typeof value === 'string';
- }
- var isNaN = Number.isNaN || WINDOW.isNaN;
- function isNumber(value) {
- return typeof value === 'number' && !isNaN(value);
- }
- function isUndefined(value) {
- return typeof value === 'undefined';
- }
- function isDate(value) {
- return typeOf(value) === 'date' && !isNaN(value.getTime());
- }
- function proxy(fn, context) {
- for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
- args[_key - 2] = arguments[_key];
- }
- return function () {
- for (var _len2 = arguments.length, args2 = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
- args2[_key2] = arguments[_key2];
- }
- return fn.apply(context, args.concat(args2));
- };
- }
- function selectorOf(view) {
- return "[data-view=\"".concat(view, "\"]");
- }
- function isLeapYear(year) {
- return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
- }
- function getDaysInMonth(year, month) {
- return [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
- }
- function getMinDay(year, month, day) {
- return Math.min(day, getDaysInMonth(year, month));
- }
- var formatParts = /(y|m|d)+/g;
- function parseFormat(format) {
- var source = String(format).toLowerCase();
- var parts = source.match(formatParts);
- if (!parts || parts.length === 0) {
- throw new Error('Invalid date format.');
- }
- format = {
- source: source,
- parts: parts
- };
- $__default['default'].each(parts, function (i, part) {
- switch (part) {
- case 'dd':
- case 'd':
- format.hasDay = true;
- break;
- case 'mm':
- case 'm':
- format.hasMonth = true;
- break;
- case 'yyyy':
- case 'yy':
- format.hasYear = true;
- break;
- }
- });
- return format;
- }
- function getScrollParent(element) {
- var includeHidden = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
- var $element = $__default['default'](element);
- var position = $element.css('position');
- var excludeStaticParent = position === 'absolute';
- var overflowRegex = includeHidden ? /auto|scroll|hidden/ : /auto|scroll/;
- var scrollParent = $element.parents().filter(function (index, parent) {
- var $parent = $__default['default'](parent);
- if (excludeStaticParent && $parent.css('position') === 'static') {
- return false;
- }
- return overflowRegex.test($parent.css('overflow') + $parent.css('overflow-y') + $parent.css('overflow-x'));
- }).eq(0);
- return position === 'fixed' || !scrollParent.length ? $__default['default'](element.ownerDocument || document) : scrollParent;
- }
- /**
- * Add leading zeroes to the given value
- * @param {number} value - The value to add.
- * @param {number} [length=1] - The expected value length.
- * @returns {string} Returns converted value.
- */
- function addLeadingZero(value) {
- var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
- var str = String(Math.abs(value));
- var i = str.length;
- var result = '';
- if (value < 0) {
- result += '-';
- }
- while (i < length) {
- i += 1;
- result += '0';
- }
- return result + str;
- }
- var REGEXP_DIGITS = /\d+/g;
- var methods = {
- // Show the datepicker
- show: function show() {
- if (!this.built) {
- this.build();
- }
- if (this.shown) {
- return;
- }
- if (this.trigger(EVENT_SHOW).isDefaultPrevented()) {
- return;
- }
- this.shown = true;
- this.$picker.removeClass(CLASS_HIDE).on(EVENT_CLICK, $__default['default'].proxy(this.click, this));
- this.showView(this.options.startView);
- if (!this.inline) {
- this.$scrollParent.on(EVENT_SCROLL, $__default['default'].proxy(this.place, this));
- $__default['default'](window).on(EVENT_RESIZE, this.onResize = proxy(this.place, this));
- $__default['default'](document).on(EVENT_CLICK, this.onGlobalClick = proxy(this.globalClick, this));
- $__default['default'](document).on(EVENT_KEYUP, this.onGlobalKeyup = proxy(this.globalKeyup, this));
- if (IS_TOUCH_DEVICE) {
- $__default['default'](document).on(EVENT_TOUCH_START, this.onTouchStart = proxy(this.touchstart, this));
- }
- this.place();
- }
- },
- // Hide the datepicker
- hide: function hide() {
- if (!this.shown) {
- return;
- }
- if (this.trigger(EVENT_HIDE).isDefaultPrevented()) {
- return;
- }
- this.shown = false;
- this.$picker.addClass(CLASS_HIDE).off(EVENT_CLICK, this.click);
- if (!this.inline) {
- this.$scrollParent.off(EVENT_SCROLL, this.place);
- $__default['default'](window).off(EVENT_RESIZE, this.onResize);
- $__default['default'](document).off(EVENT_CLICK, this.onGlobalClick);
- $__default['default'](document).off(EVENT_KEYUP, this.onGlobalKeyup);
- if (IS_TOUCH_DEVICE) {
- $__default['default'](document).off(EVENT_TOUCH_START, this.onTouchStart);
- }
- }
- },
- toggle: function toggle() {
- if (this.shown) {
- this.hide();
- } else {
- this.show();
- }
- },
- // Update the datepicker with the current input value
- update: function update() {
- var value = this.getValue();
- if (value === this.oldValue) {
- return;
- }
- this.setDate(value, true);
- this.oldValue = value;
- },
- /**
- * Pick the current date to the element
- *
- * @param {String} _view (private)
- */
- pick: function pick(_view) {
- var $this = this.$element;
- var date = this.date;
- if (this.trigger(EVENT_PICK, {
- view: _view || '',
- date: date
- }).isDefaultPrevented()) {
- return;
- }
- date = this.formatDate(this.date);
- this.setValue(date);
- if (this.isInput) {
- $this.trigger('input');
- $this.trigger('change');
- }
- },
- // Reset the datepicker
- reset: function reset() {
- this.setDate(this.initialDate, true);
- this.setValue(this.initialValue);
- if (this.shown) {
- this.showView(this.options.startView);
- }
- },
- /**
- * Get the month name with given argument or the current date
- *
- * @param {Number} month (optional)
- * @param {Boolean} shortForm (optional)
- * @return {String} (month name)
- */
- getMonthName: function getMonthName(month, shortForm) {
- var options = this.options;
- var monthsShort = options.monthsShort;
- var months = options.months;
- if ($__default['default'].isNumeric(month)) {
- month = Number(month);
- } else if (isUndefined(shortForm)) {
- shortForm = month;
- }
- if (shortForm === true) {
- months = monthsShort;
- }
- return months[isNumber(month) ? month : this.date.getMonth()];
- },
- /**
- * Get the day name with given argument or the current date
- *
- * @param {Number} day (optional)
- * @param {Boolean} shortForm (optional)
- * @param {Boolean} min (optional)
- * @return {String} (day name)
- */
- getDayName: function getDayName(day, shortForm, min) {
- var options = this.options;
- var days = options.days;
- if ($__default['default'].isNumeric(day)) {
- day = Number(day);
- } else {
- if (isUndefined(min)) {
- min = shortForm;
- }
- if (isUndefined(shortForm)) {
- shortForm = day;
- }
- }
- if (min) {
- days = options.daysMin;
- } else if (shortForm) {
- days = options.daysShort;
- }
- return days[isNumber(day) ? day : this.date.getDay()];
- },
- /**
- * Get the current date
- *
- * @param {Boolean} formatted (optional)
- * @return {Date|String} (date)
- */
- getDate: function getDate(formatted) {
- var date = this.date;
- return formatted ? this.formatDate(date) : new Date(date);
- },
- /**
- * Set the current date with a new date
- *
- * @param {Date} date
- * @param {Boolean} _updated (private)
- */
- setDate: function setDate(date, _updated) {
- var filter = this.options.filter;
- if (isDate(date) || isString(date)) {
- date = this.parseDate(date);
- if ($__default['default'].isFunction(filter) && filter.call(this.$element, date, 'day') === false) {
- return;
- }
- this.date = date;
- this.viewDate = new Date(date);
- if (!_updated) {
- this.pick();
- }
- if (this.built) {
- this.render();
- }
- }
- },
- /**
- * Set the start view date with a new date
- *
- * @param {Date|string|null} date
- */
- setStartDate: function setStartDate(date) {
- if (isDate(date) || isString(date)) {
- this.startDate = this.parseDate(date);
- } else {
- this.startDate = null;
- }
- if (this.built) {
- this.render();
- }
- },
- /**
- * Set the end view date with a new date
- *
- * @param {Date|string|null} date
- */
- setEndDate: function setEndDate(date) {
- if (isDate(date) || isString(date)) {
- this.endDate = this.parseDate(date);
- } else {
- this.endDate = null;
- }
- if (this.built) {
- this.render();
- }
- },
- /**
- * Parse a date string with the set date format
- *
- * @param {String} date
- * @return {Date} (parsed date)
- */
- parseDate: function parseDate(date) {
- var format = this.format;
- var parts = [];
- if (!isDate(date)) {
- if (isString(date)) {
- parts = date.match(REGEXP_DIGITS) || [];
- }
- date = date ? new Date(date) : new Date();
- if (!isDate(date)) {
- date = new Date();
- }
- if (parts.length === format.parts.length) {
- // Set year and month first
- $__default['default'].each(parts, function (i, part) {
- var value = parseInt(part, 10);
- switch (format.parts[i]) {
- case 'yy':
- date.setFullYear(2000 + value);
- break;
- case 'yyyy':
- // Converts 2-digit year to 2000+
- date.setFullYear(part.length === 2 ? 2000 + value : value);
- break;
- case 'mm':
- case 'm':
- date.setMonth(value - 1);
- break;
- }
- }); // Set day in the last to avoid converting `31/10/2019` to `01/10/2019`
- $__default['default'].each(parts, function (i, part) {
- var value = parseInt(part, 10);
- switch (format.parts[i]) {
- case 'dd':
- case 'd':
- date.setDate(value);
- break;
- }
- });
- }
- } // Ignore hours, minutes, seconds and milliseconds to avoid side effect (#192)
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
- },
- /**
- * Format a date object to a string with the set date format
- *
- * @param {Date} date
- * @return {String} (formatted date)
- */
- formatDate: function formatDate(date) {
- var format = this.format;
- var formatted = '';
- if (isDate(date)) {
- var year = date.getFullYear();
- var month = date.getMonth();
- var day = date.getDate();
- var values = {
- d: day,
- dd: addLeadingZero(day, 2),
- m: month + 1,
- mm: addLeadingZero(month + 1, 2),
- yy: String(year).substring(2),
- yyyy: addLeadingZero(year, 4)
- };
- formatted = format.source;
- $__default['default'].each(format.parts, function (i, part) {
- formatted = formatted.replace(part, values[part]);
- });
- }
- return formatted;
- },
- // Destroy the datepicker and remove the instance from the target element
- destroy: function destroy() {
- this.unbind();
- this.unbuild();
- this.$element.removeData(NAMESPACE);
- }
- };
- var handlers = {
- click: function click(e) {
- var $target = $__default['default'](e.target);
- var options = this.options,
- date = this.date,
- viewDate = this.viewDate,
- format = this.format;
- e.stopPropagation();
- e.preventDefault();
- if ($target.hasClass('disabled')) {
- return;
- }
- var view = $target.data('view');
- var viewYear = viewDate.getFullYear();
- var viewMonth = viewDate.getMonth();
- var viewDay = viewDate.getDate();
- switch (view) {
- case 'years prev':
- case 'years next':
- {
- viewYear = view === 'years prev' ? viewYear - 10 : viewYear + 10;
- viewDate.setFullYear(viewYear);
- viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay));
- this.renderYears();
- break;
- }
- case 'year prev':
- case 'year next':
- viewYear = view === 'year prev' ? viewYear - 1 : viewYear + 1;
- viewDate.setFullYear(viewYear);
- viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay));
- this.renderMonths();
- break;
- case 'year current':
- if (format.hasYear) {
- this.showView(VIEWS.YEARS);
- }
- break;
- case 'year picked':
- if (format.hasMonth) {
- this.showView(VIEWS.MONTHS);
- } else {
- $target.siblings(".".concat(options.pickedClass)).removeClass(options.pickedClass).data('view', 'year');
- this.hideView();
- }
- this.pick('year');
- break;
- case 'year':
- viewYear = parseInt($target.text(), 10); // Set date first to avoid month changing (#195)
- date.setDate(getMinDay(viewYear, viewMonth, viewDay));
- date.setFullYear(viewYear);
- viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay));
- viewDate.setFullYear(viewYear);
- if (format.hasMonth) {
- this.showView(VIEWS.MONTHS);
- } else {
- $target.addClass(options.pickedClass).data('view', 'year picked').siblings(".".concat(options.pickedClass)).removeClass(options.pickedClass).data('view', 'year');
- this.hideView();
- }
- this.pick('year');
- break;
- case 'month prev':
- case 'month next':
- viewMonth = view === 'month prev' ? viewMonth - 1 : viewMonth + 1;
- if (viewMonth < 0) {
- viewYear -= 1;
- viewMonth += 12;
- } else if (viewMonth > 11) {
- viewYear += 1;
- viewMonth -= 12;
- }
- viewDate.setFullYear(viewYear);
- viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay));
- viewDate.setMonth(viewMonth);
- this.renderDays();
- break;
- case 'month current':
- if (format.hasMonth) {
- this.showView(VIEWS.MONTHS);
- }
- break;
- case 'month picked':
- if (format.hasDay) {
- this.showView(VIEWS.DAYS);
- } else {
- $target.siblings(".".concat(options.pickedClass)).removeClass(options.pickedClass).data('view', 'month');
- this.hideView();
- }
- this.pick('month');
- break;
- case 'month':
- viewMonth = $__default['default'].inArray($target.text(), options.monthsShort);
- date.setFullYear(viewYear); // Set date before month to avoid month changing (#195)
- date.setDate(getMinDay(viewYear, viewMonth, viewDay));
- date.setMonth(viewMonth);
- viewDate.setFullYear(viewYear);
- viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay));
- viewDate.setMonth(viewMonth);
- if (format.hasDay) {
- this.showView(VIEWS.DAYS);
- } else {
- $target.addClass(options.pickedClass).data('view', 'month picked').siblings(".".concat(options.pickedClass)).removeClass(options.pickedClass).data('view', 'month');
- this.hideView();
- }
- this.pick('month');
- break;
- case 'day prev':
- case 'day next':
- case 'day':
- if (view === 'day prev') {
- viewMonth -= 1;
- } else if (view === 'day next') {
- viewMonth += 1;
- }
- viewDay = parseInt($target.text(), 10); // Set date to 1 to avoid month changing (#195)
- date.setDate(1);
- date.setFullYear(viewYear);
- date.setMonth(viewMonth);
- date.setDate(viewDay);
- viewDate.setDate(1);
- viewDate.setFullYear(viewYear);
- viewDate.setMonth(viewMonth);
- viewDate.setDate(viewDay);
- this.renderDays();
- if (view === 'day') {
- this.hideView();
- }
- this.pick('day');
- break;
- case 'day picked':
- this.hideView();
- this.pick('day');
- break;
- }
- },
- globalClick: function globalClick(_ref) {
- var target = _ref.target;
- var element = this.element,
- $trigger = this.$trigger;
- var trigger = $trigger[0];
- var hidden = true;
- while (target !== document) {
- if (target === trigger || target === element) {
- hidden = false;
- break;
- }
- target = target.parentNode;
- }
- if (hidden) {
- this.hide();
- }
- },
- keyup: function keyup() {
- this.update();
- },
- globalKeyup: function globalKeyup(_ref2) {
- var target = _ref2.target,
- key = _ref2.key,
- keyCode = _ref2.keyCode;
- if (this.isInput && target !== this.element && this.shown && (key === 'Tab' || keyCode === 9)) {
- this.hide();
- }
- },
- touchstart: function touchstart(_ref3) {
- var target = _ref3.target;
- // Emulate click in touch devices to support hiding the picker automatically (#197).
- if (this.isInput && target !== this.element && !$__default['default'].contains(this.$picker[0], target)) {
- this.hide();
- this.element.blur();
- }
- }
- };
- var render = {
- render: function render() {
- this.renderYears();
- this.renderMonths();
- this.renderDays();
- },
- renderWeek: function renderWeek() {
- var _this = this;
- var items = [];
- var _this$options = this.options,
- weekStart = _this$options.weekStart,
- daysMin = _this$options.daysMin;
- weekStart = parseInt(weekStart, 10) % 7;
- daysMin = daysMin.slice(weekStart).concat(daysMin.slice(0, weekStart));
- $__default['default'].each(daysMin, function (i, day) {
- items.push(_this.createItem({
- text: day
- }));
- });
- this.$week.html(items.join(''));
- },
- renderYears: function renderYears() {
- var options = this.options,
- startDate = this.startDate,
- endDate = this.endDate;
- var disabledClass = options.disabledClass,
- filter = options.filter,
- yearSuffix = options.yearSuffix;
- var viewYear = this.viewDate.getFullYear();
- var now = new Date();
- var thisYear = now.getFullYear();
- var year = this.date.getFullYear();
- var start = -5;
- var end = 6;
- var items = [];
- var prevDisabled = false;
- var nextDisabled = false;
- var i;
- for (i = start; i <= end; i += 1) {
- var date = new Date(viewYear + i, 1, 1);
- var disabled = false;
- if (startDate) {
- disabled = date.getFullYear() < startDate.getFullYear();
- if (i === start) {
- prevDisabled = disabled;
- }
- }
- if (!disabled && endDate) {
- disabled = date.getFullYear() > endDate.getFullYear();
- if (i === end) {
- nextDisabled = disabled;
- }
- }
- if (!disabled && filter) {
- disabled = filter.call(this.$element, date, 'year') === false;
- }
- var picked = viewYear + i === year;
- var view = picked ? 'year picked' : 'year';
- items.push(this.createItem({
- picked: picked,
- disabled: disabled,
- text: viewYear + i,
- view: disabled ? 'year disabled' : view,
- highlighted: date.getFullYear() === thisYear
- }));
- }
- this.$yearsPrev.toggleClass(disabledClass, prevDisabled);
- this.$yearsNext.toggleClass(disabledClass, nextDisabled);
- this.$yearsCurrent.toggleClass(disabledClass, true).html("".concat(viewYear + start + yearSuffix, " - ").concat(viewYear + end).concat(yearSuffix));
- this.$years.html(items.join(''));
- },
- renderMonths: function renderMonths() {
- var options = this.options,
- startDate = this.startDate,
- endDate = this.endDate,
- viewDate = this.viewDate;
- var disabledClass = options.disabledClass || '';
- var months = options.monthsShort;
- var filter = $__default['default'].isFunction(options.filter) && options.filter;
- var viewYear = viewDate.getFullYear();
- var now = new Date();
- var thisYear = now.getFullYear();
- var thisMonth = now.getMonth();
- var year = this.date.getFullYear();
- var month = this.date.getMonth();
- var items = [];
- var prevDisabled = false;
- var nextDisabled = false;
- var i;
- for (i = 0; i <= 11; i += 1) {
- var date = new Date(viewYear, i, 1);
- var disabled = false;
- if (startDate) {
- prevDisabled = date.getFullYear() === startDate.getFullYear();
- disabled = prevDisabled && date.getMonth() < startDate.getMonth();
- }
- if (!disabled && endDate) {
- nextDisabled = date.getFullYear() === endDate.getFullYear();
- disabled = nextDisabled && date.getMonth() > endDate.getMonth();
- }
- if (!disabled && filter) {
- disabled = filter.call(this.$element, date, 'month') === false;
- }
- var picked = viewYear === year && i === month;
- var view = picked ? 'month picked' : 'month';
- items.push(this.createItem({
- disabled: disabled,
- picked: picked,
- highlighted: viewYear === thisYear && date.getMonth() === thisMonth,
- index: i,
- text: months[i],
- view: disabled ? 'month disabled' : view
- }));
- }
- this.$yearPrev.toggleClass(disabledClass, prevDisabled);
- this.$yearNext.toggleClass(disabledClass, nextDisabled);
- this.$yearCurrent.toggleClass(disabledClass, prevDisabled && nextDisabled).html(viewYear + options.yearSuffix || '');
- this.$months.html(items.join(''));
- },
- renderDays: function renderDays() {
- var $element = this.$element,
- options = this.options,
- startDate = this.startDate,
- endDate = this.endDate,
- viewDate = this.viewDate,
- currentDate = this.date;
- var disabledClass = options.disabledClass,
- filter = options.filter,
- months = options.months,
- weekStart = options.weekStart,
- yearSuffix = options.yearSuffix;
- var viewYear = viewDate.getFullYear();
- var viewMonth = viewDate.getMonth();
- var now = new Date();
- var thisYear = now.getFullYear();
- var thisMonth = now.getMonth();
- var thisDay = now.getDate();
- var year = currentDate.getFullYear();
- var month = currentDate.getMonth();
- var day = currentDate.getDate();
- var length;
- var i;
- var n; // Days of prev month
- // -----------------------------------------------------------------------
- var prevItems = [];
- var prevViewYear = viewYear;
- var prevViewMonth = viewMonth;
- var prevDisabled = false;
- if (viewMonth === 0) {
- prevViewYear -= 1;
- prevViewMonth = 11;
- } else {
- prevViewMonth -= 1;
- } // The length of the days of prev month
- length = getDaysInMonth(prevViewYear, prevViewMonth); // The first day of current month
- var firstDay = new Date(viewYear, viewMonth, 1); // The visible length of the days of prev month
- // [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]
- 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]
- if (n <= 0) {
- n += 7;
- }
- if (startDate) {
- prevDisabled = firstDay.getTime() <= startDate.getTime();
- }
- for (i = length - (n - 1); i <= length; i += 1) {
- var prevViewDate = new Date(prevViewYear, prevViewMonth, i);
- var disabled = false;
- if (startDate) {
- disabled = prevViewDate.getTime() < startDate.getTime();
- }
- if (!disabled && filter) {
- disabled = filter.call($element, prevViewDate, 'day') === false;
- }
- prevItems.push(this.createItem({
- disabled: disabled,
- highlighted: prevViewYear === thisYear && prevViewMonth === thisMonth && prevViewDate.getDate() === thisDay,
- muted: true,
- picked: prevViewYear === year && prevViewMonth === month && i === day,
- text: i,
- view: 'day prev'
- }));
- } // Days of next month
- // -----------------------------------------------------------------------
- var nextItems = [];
- var nextViewYear = viewYear;
- var nextViewMonth = viewMonth;
- var nextDisabled = false;
- if (viewMonth === 11) {
- nextViewYear += 1;
- nextViewMonth = 0;
- } else {
- nextViewMonth += 1;
- } // The length of the days of current month
- length = getDaysInMonth(viewYear, viewMonth); // The visible length of next month (42 means 6 rows and 7 columns)
- n = 42 - (prevItems.length + length); // The last day of current month
- var lastDate = new Date(viewYear, viewMonth, length);
- if (endDate) {
- nextDisabled = lastDate.getTime() >= endDate.getTime();
- }
- for (i = 1; i <= n; i += 1) {
- var date = new Date(nextViewYear, nextViewMonth, i);
- var picked = nextViewYear === year && nextViewMonth === month && i === day;
- var _disabled = false;
- if (endDate) {
- _disabled = date.getTime() > endDate.getTime();
- }
- if (!_disabled && filter) {
- _disabled = filter.call($element, date, 'day') === false;
- }
- nextItems.push(this.createItem({
- disabled: _disabled,
- picked: picked,
- highlighted: nextViewYear === thisYear && nextViewMonth === thisMonth && date.getDate() === thisDay,
- muted: true,
- text: i,
- view: 'day next'
- }));
- } // Days of current month
- // -----------------------------------------------------------------------
- var items = [];
- for (i = 1; i <= length; i += 1) {
- var _date = new Date(viewYear, viewMonth, i);
- var _disabled2 = false;
- if (startDate) {
- _disabled2 = _date.getTime() < startDate.getTime();
- }
- if (!_disabled2 && endDate) {
- _disabled2 = _date.getTime() > endDate.getTime();
- }
- if (!_disabled2 && filter) {
- _disabled2 = filter.call($element, _date, 'day') === false;
- }
- var _picked = viewYear === year && viewMonth === month && i === day;
- var view = _picked ? 'day picked' : 'day';
- items.push(this.createItem({
- disabled: _disabled2,
- picked: _picked,
- highlighted: viewYear === thisYear && viewMonth === thisMonth && _date.getDate() === thisDay,
- text: i,
- view: _disabled2 ? 'day disabled' : view
- }));
- } // Render days picker
- // -----------------------------------------------------------------------
- this.$monthPrev.toggleClass(disabledClass, prevDisabled);
- this.$monthNext.toggleClass(disabledClass, nextDisabled);
- this.$monthCurrent.toggleClass(disabledClass, prevDisabled && nextDisabled).html(options.yearFirst ? "".concat(viewYear + yearSuffix, " ").concat(months[viewMonth]) : "".concat(months[viewMonth], " ").concat(viewYear).concat(yearSuffix));
- this.$days.html(prevItems.join('') + items.join('') + nextItems.join(''));
- }
- };
- var CLASS_TOP_LEFT = "".concat(NAMESPACE, "-top-left");
- var CLASS_TOP_RIGHT = "".concat(NAMESPACE, "-top-right");
- var CLASS_BOTTOM_LEFT = "".concat(NAMESPACE, "-bottom-left");
- var CLASS_BOTTOM_RIGHT = "".concat(NAMESPACE, "-bottom-right");
- var CLASS_PLACEMENTS = [CLASS_TOP_LEFT, CLASS_TOP_RIGHT, CLASS_BOTTOM_LEFT, CLASS_BOTTOM_RIGHT].join(' ');
- var Datepicker = /*#__PURE__*/function () {
- function Datepicker(element) {
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- _classCallCheck(this, Datepicker);
- this.$element = $__default['default'](element);
- this.element = element;
- this.options = $__default['default'].extend({}, DEFAULTS, LANGUAGES[options.language], $__default['default'].isPlainObject(options) && options);
- this.$scrollParent = getScrollParent(element, true);
- this.built = false;
- this.shown = false;
- this.isInput = false;
- this.inline = false;
- this.initialValue = '';
- this.initialDate = null;
- this.startDate = null;
- this.endDate = null;
- this.init();
- }
- _createClass(Datepicker, [{
- key: "init",
- value: function init() {
- var $this = this.$element,
- options = this.options;
- var startDate = options.startDate,
- endDate = options.endDate,
- date = options.date;
- this.$trigger = $__default['default'](options.trigger);
- this.isInput = $this.is('input') || $this.is('textarea');
- this.inline = options.inline && (options.container || !this.isInput);
- this.format = parseFormat(options.format);
- var initialValue = this.getValue();
- this.initialValue = initialValue;
- this.oldValue = initialValue;
- date = this.parseDate(date || initialValue);
- if (startDate) {
- startDate = this.parseDate(startDate);
- if (date.getTime() < startDate.getTime()) {
- date = new Date(startDate);
- }
- this.startDate = startDate;
- }
- if (endDate) {
- endDate = this.parseDate(endDate);
- if (startDate && endDate.getTime() < startDate.getTime()) {
- endDate = new Date(startDate);
- }
- if (date.getTime() > endDate.getTime()) {
- date = new Date(endDate);
- }
- this.endDate = endDate;
- }
- this.date = date;
- this.viewDate = new Date(date);
- this.initialDate = new Date(this.date);
- this.bind();
- if (options.autoShow || this.inline) {
- this.show();
- }
- if (options.autoPick) {
- this.pick();
- }
- }
- }, {
- key: "build",
- value: function build() {
- if (this.built) {
- return;
- }
- this.built = true;
- var $this = this.$element,
- options = this.options;
- var $picker = $__default['default'](options.template);
- this.$picker = $picker;
- this.$week = $picker.find(selectorOf('week')); // Years view
- this.$yearsPicker = $picker.find(selectorOf('years picker'));
- this.$yearsPrev = $picker.find(selectorOf('years prev'));
- this.$yearsNext = $picker.find(selectorOf('years next'));
- this.$yearsCurrent = $picker.find(selectorOf('years current'));
- this.$years = $picker.find(selectorOf('years')); // Months view
- this.$monthsPicker = $picker.find(selectorOf('months picker'));
- this.$yearPrev = $picker.find(selectorOf('year prev'));
- this.$yearNext = $picker.find(selectorOf('year next'));
- this.$yearCurrent = $picker.find(selectorOf('year current'));
- this.$months = $picker.find(selectorOf('months')); // Days view
- this.$daysPicker = $picker.find(selectorOf('days picker'));
- this.$monthPrev = $picker.find(selectorOf('month prev'));
- this.$monthNext = $picker.find(selectorOf('month next'));
- this.$monthCurrent = $picker.find(selectorOf('month current'));
- this.$days = $picker.find(selectorOf('days'));
- if (this.inline) {
- $__default['default'](options.container || $this).append($picker.addClass("".concat(NAMESPACE, "-inline")));
- } else {
- $__default['default'](document.body).append($picker.addClass("".concat(NAMESPACE, "-dropdown")));
- $picker.addClass(CLASS_HIDE).css({
- zIndex: parseInt(options.zIndex, 10)
- });
- }
- this.renderWeek();
- }
- }, {
- key: "unbuild",
- value: function unbuild() {
- if (!this.built) {
- return;
- }
- this.built = false;
- this.$picker.remove();
- }
- }, {
- key: "bind",
- value: function bind() {
- var options = this.options,
- $this = this.$element;
- if ($__default['default'].isFunction(options.show)) {
- $this.on(EVENT_SHOW, options.show);
- }
- if ($__default['default'].isFunction(options.hide)) {
- $this.on(EVENT_HIDE, options.hide);
- }
- if ($__default['default'].isFunction(options.pick)) {
- $this.on(EVENT_PICK, options.pick);
- }
- if (this.isInput) {
- $this.on(EVENT_KEYUP, $__default['default'].proxy(this.keyup, this));
- }
- if (!this.inline) {
- if (options.trigger) {
- this.$trigger.on(EVENT_CLICK, $__default['default'].proxy(this.toggle, this));
- } else if (this.isInput) {
- $this.on(EVENT_FOCUS, $__default['default'].proxy(this.show, this));
- } else {
- $this.on(EVENT_CLICK, $__default['default'].proxy(this.show, this));
- }
- }
- }
- }, {
- key: "unbind",
- value: function unbind() {
- var $this = this.$element,
- options = this.options;
- if ($__default['default'].isFunction(options.show)) {
- $this.off(EVENT_SHOW, options.show);
- }
- if ($__default['default'].isFunction(options.hide)) {
- $this.off(EVENT_HIDE, options.hide);
- }
- if ($__default['default'].isFunction(options.pick)) {
- $this.off(EVENT_PICK, options.pick);
- }
- if (this.isInput) {
- $this.off(EVENT_KEYUP, this.keyup);
- }
- if (!this.inline) {
- if (options.trigger) {
- this.$trigger.off(EVENT_CLICK, this.toggle);
- } else if (this.isInput) {
- $this.off(EVENT_FOCUS, this.show);
- } else {
- $this.off(EVENT_CLICK, this.show);
- }
- }
- }
- }, {
- key: "showView",
- value: function showView(view) {
- var $yearsPicker = this.$yearsPicker,
- $monthsPicker = this.$monthsPicker,
- $daysPicker = this.$daysPicker,
- format = this.format;
- if (format.hasYear || format.hasMonth || format.hasDay) {
- switch (Number(view)) {
- case VIEWS.YEARS:
- $monthsPicker.addClass(CLASS_HIDE);
- $daysPicker.addClass(CLASS_HIDE);
- if (format.hasYear) {
- this.renderYears();
- $yearsPicker.removeClass(CLASS_HIDE);
- this.place();
- } else {
- this.showView(VIEWS.DAYS);
- }
- break;
- case VIEWS.MONTHS:
- $yearsPicker.addClass(CLASS_HIDE);
- $daysPicker.addClass(CLASS_HIDE);
- if (format.hasMonth) {
- this.renderMonths();
- $monthsPicker.removeClass(CLASS_HIDE);
- this.place();
- } else {
- this.showView(VIEWS.YEARS);
- }
- break;
- // case VIEWS.DAYS:
- default:
- $yearsPicker.addClass(CLASS_HIDE);
- $monthsPicker.addClass(CLASS_HIDE);
- if (format.hasDay) {
- this.renderDays();
- $daysPicker.removeClass(CLASS_HIDE);
- this.place();
- } else {
- this.showView(VIEWS.MONTHS);
- }
- }
- }
- }
- }, {
- key: "hideView",
- value: function hideView() {
- if (!this.inline && this.options.autoHide) {
- this.hide();
- }
- }
- }, {
- key: "place",
- value: function place() {
- if (this.inline) {
- return;
- }
- var $this = this.$element,
- options = this.options,
- $picker = this.$picker;
- var containerWidth = $__default['default'](document).outerWidth();
- var containerHeight = $__default['default'](document).outerHeight();
- var elementWidth = $this.outerWidth();
- var elementHeight = $this.outerHeight();
- var width = $picker.width();
- var height = $picker.height();
- var _$this$offset = $this.offset(),
- left = _$this$offset.left,
- top = _$this$offset.top;
- var offset = parseFloat(options.offset);
- var placement = CLASS_TOP_LEFT;
- if (isNaN(offset)) {
- offset = 10;
- }
- if (top > height && top + elementHeight + height > containerHeight) {
- top -= height + offset;
- placement = CLASS_BOTTOM_LEFT;
- } else {
- top += elementHeight + offset;
- }
- if (left + width > containerWidth) {
- left += elementWidth - width;
- placement = placement.replace('left', 'right');
- }
- $picker.removeClass(CLASS_PLACEMENTS).addClass(placement).css({
- top: top,
- left: left
- });
- } // A shortcut for triggering custom events
- }, {
- key: "trigger",
- value: function trigger(type, data) {
- var e = $__default['default'].Event(type, data);
- this.$element.trigger(e);
- return e;
- }
- }, {
- key: "createItem",
- value: function createItem(data) {
- var options = this.options;
- var itemTag = options.itemTag;
- var item = {
- text: '',
- view: '',
- muted: false,
- picked: false,
- disabled: false,
- highlighted: false
- };
- var classes = [];
- $__default['default'].extend(item, data);
- if (item.muted) {
- classes.push(options.mutedClass);
- }
- if (item.highlighted) {
- classes.push(options.highlightedClass);
- }
- if (item.picked) {
- classes.push(options.pickedClass);
- }
- if (item.disabled) {
- classes.push(options.disabledClass);
- }
- return "<".concat(itemTag, " class=\"").concat(classes.join(' '), "\" data-view=\"").concat(item.view, "\">").concat(item.text, "</").concat(itemTag, ">");
- }
- }, {
- key: "getValue",
- value: function getValue() {
- var $this = this.$element;
- return this.isInput ? $this.val() : $this.text();
- }
- }, {
- key: "setValue",
- value: function setValue() {
- var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
- var $this = this.$element;
- if (this.isInput) {
- $this.val(value);
- } else if (!this.inline || this.options.container) {
- $this.text(value);
- }
- }
- }], [{
- key: "setDefaults",
- value: function setDefaults() {
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
- $__default['default'].extend(DEFAULTS, LANGUAGES[options.language], $__default['default'].isPlainObject(options) && options);
- }
- }]);
- return Datepicker;
- }();
- if ($__default['default'].extend) {
- $__default['default'].extend(Datepicker.prototype, render, handlers, methods);
- }
- if ($__default['default'].fn) {
- var AnotherDatepicker = $__default['default'].fn.datepicker;
- $__default['default'].fn.datepicker = function jQueryDatepicker(option) {
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
- args[_key - 1] = arguments[_key];
- }
- var result;
- this.each(function (i, element) {
- var $element = $__default['default'](element);
- var isDestroy = option === 'destroy';
- var datepicker = $element.data(NAMESPACE);
- if (!datepicker) {
- if (isDestroy) {
- return;
- }
- var options = $__default['default'].extend({}, $element.data(), $__default['default'].isPlainObject(option) && option);
- datepicker = new Datepicker(element, options);
- $element.data(NAMESPACE, datepicker);
- }
- if (isString(option)) {
- var fn = datepicker[option];
- if ($__default['default'].isFunction(fn)) {
- result = fn.apply(datepicker, args);
- if (isDestroy) {
- $element.removeData(NAMESPACE);
- }
- }
- }
- });
- return !isUndefined(result) ? result : this;
- };
- $__default['default'].fn.datepicker.Constructor = Datepicker;
- $__default['default'].fn.datepicker.languages = LANGUAGES;
- $__default['default'].fn.datepicker.setDefaults = Datepicker.setDefaults;
- $__default['default'].fn.datepicker.noConflict = function noConflict() {
- $__default['default'].fn.datepicker = AnotherDatepicker;
- return this;
- };
- }
|