diff --git a/CHANGELOG.md b/CHANGELOG.md index b1d15ab..9fbc4d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 1.0.1 (Nov 14, 2018) + +- Fix position problem in scrollable modal (#121). +- Fix the issue of the datepicker is replaced after picked a day (#128). + ## 1.0.0 (Aug 5, 2018) - Show full month name in date picker header (#133). diff --git a/dist/datepicker.common.js b/dist/datepicker.common.js index 5b2ffdc..5c123ce 100644 --- a/dist/datepicker.common.js +++ b/dist/datepicker.common.js @@ -1,11 +1,11 @@ /*! - * Datepicker v1.0.0 + * Datepicker v1.0.1 * https://fengyuanchen.github.io/datepicker * * Copyright 2014-present Chen Fengyuan * Released under the MIT license * - * Date: 2018-08-05T03:02:19.812Z + * Date: 2018-11-14T13:59:48.051Z */ 'use strict'; @@ -14,96 +14,90 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau var $ = _interopDefault(require('jquery')); +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 - + 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: '
' + '
' + '' + '' + '
' + '
' + '' + '' + '
' + '
' + '' + '' + '' + '
' + '
', - // 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, @@ -112,14 +106,15 @@ var DEFAULTS = { var WINDOW = typeof window !== 'undefined' ? window : {}; var NAMESPACE = 'datepicker'; -var EVENT_CLICK = 'click.' + NAMESPACE; -var EVENT_FOCUS = 'focus.' + NAMESPACE; -var EVENT_HIDE = 'hide.' + NAMESPACE; -var EVENT_KEYUP = 'keyup.' + NAMESPACE; -var EVENT_PICK = 'pick.' + NAMESPACE; -var EVENT_RESIZE = 'resize.' + NAMESPACE; -var EVENT_SHOW = 'show.' + NAMESPACE; -var CLASS_HIDE = NAMESPACE + '-hide'; +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 CLASS_HIDE = "".concat(NAMESPACE, "-hide"); var LANGUAGES = {}; var VIEWS = { DAYS: 0, @@ -128,62 +123,48 @@ var VIEWS = { }; 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'; } - function proxy(fn, context) { - for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { + 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 = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + 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="' + 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); @@ -196,7 +177,6 @@ function parseFormat(format) { source: source, parts: parts }; - $.each(parts, function (i, part) { switch (part) { case 'dd': @@ -217,12 +197,27 @@ function parseFormat(format) { default: } }); - return format; } +function getScrollParent(element) { + var includeHidden = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var $element = $(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 = $(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 ? $(element.ownerDocument || document) : scrollParent; +} var REGEXP_DIGITS = /\d+/g; - var methods = { // Show the datepicker show: function show() { @@ -243,14 +238,13 @@ var methods = { this.showView(this.options.startView); if (!this.inline) { + this.$scrollParent.on(EVENT_SCROLL, $.proxy(this.place, this)); $(window).on(EVENT_RESIZE, this.onResize = proxy(this.place, this)); $(document).on(EVENT_CLICK, this.onGlobalClick = proxy(this.globalClick, this)); $(document).on(EVENT_KEYUP, this.onGlobalKeyup = proxy(this.globalKeyup, this)); this.place(); } }, - - // Hide the datepicker hide: function hide() { if (!this.shown) { @@ -265,6 +259,7 @@ var methods = { this.$picker.addClass(CLASS_HIDE).off(EVENT_CLICK, this.click); if (!this.inline) { + this.$scrollParent.off(EVENT_SCROLL, this.place); $(window).off(EVENT_RESIZE, this.onResize); $(document).off(EVENT_CLICK, this.onGlobalClick); $(document).off(EVENT_KEYUP, this.onGlobalKeyup); @@ -277,8 +272,6 @@ var methods = { this.show(); } }, - - // Update the datepicker with the current input value update: function update() { var value = this.getValue(); @@ -291,7 +284,6 @@ var methods = { this.oldValue = value; }, - /** * Pick the current date to the element * @@ -301,7 +293,6 @@ var methods = { var $this = this.$element; var date = this.date; - if (this.trigger(EVENT_PICK, { view: _view || '', date: date @@ -317,8 +308,6 @@ var methods = { $this.trigger('change'); } }, - - // Reset the datepicker reset: function reset() { this.setDate(this.initialDate, true); @@ -329,7 +318,6 @@ var methods = { } }, - /** * Get the month name with given argument or the current date * @@ -342,7 +330,6 @@ var methods = { var monthsShort = options.monthsShort; var months = options.months; - if ($.isNumeric(month)) { month = Number(month); } else if (isUndefined(shortForm)) { @@ -356,7 +343,6 @@ var methods = { return months[isNumber(month) ? month : this.date.getMonth()]; }, - /** * Get the day name with given argument or the current date * @@ -369,7 +355,6 @@ var methods = { var options = this.options; var days = options.days; - if ($.isNumeric(day)) { day = Number(day); } else { @@ -391,7 +376,6 @@ var methods = { return days[isNumber(day) ? day : this.date.getDay()]; }, - /** * Get the current date * @@ -400,12 +384,9 @@ var methods = { */ getDate: function getDate(formatted) { var date = this.date; - - return formatted ? this.formatDate(date) : new Date(date); }, - /** * Set the current date with a new date * @@ -415,7 +396,6 @@ var methods = { setDate: function setDate(date, _updated) { var filter = this.options.filter; - if (isDate(date) || isString(date)) { date = this.parseDate(date); @@ -436,7 +416,6 @@ var methods = { } }, - /** * Set the start view date with a new date * @@ -454,7 +433,6 @@ var methods = { } }, - /** * Set the end view date with a new date * @@ -472,7 +450,6 @@ var methods = { } }, - /** * Parse a date string with the set date format * @@ -481,7 +458,6 @@ var methods = { */ parseDate: function parseDate(date) { var format = this.format; - var parts = []; if (isDate(date)) { @@ -493,9 +469,7 @@ var methods = { } date = new Date(); - var length = format.parts.length; - var year = date.getFullYear(); var day = date.getDate(); var month = date.getMonth(); @@ -531,7 +505,6 @@ var methods = { return new Date(year, month, day); }, - /** * Format a date object to a string with the set date format * @@ -540,7 +513,6 @@ var methods = { */ formatDate: function formatDate(date) { var format = this.format; - var formatted = ''; if (isDate(date)) { @@ -551,7 +523,6 @@ var methods = { yy: year.toString().substring(2), yyyy: year }; - values.dd = (values.d < 10 ? '0' : '') + values.d; values.mm = (values.m < 10 ? '0' : '') + values.m; formatted = format.source; @@ -562,8 +533,6 @@ var methods = { return formatted; }, - - // Destroy the datepicker and remove the instance from the target element destroy: function destroy() { this.unbind(); @@ -578,8 +547,6 @@ var handlers = { var options = this.options, viewDate = this.viewDate, format = this.format; - - e.stopPropagation(); e.preventDefault(); @@ -726,7 +693,6 @@ var handlers = { var target = _ref.target; var element = this.element, $trigger = this.$trigger; - var trigger = $trigger[0]; var hidden = true; @@ -767,11 +733,9 @@ var render = { var _this = this; var items = []; - var _options = this.options, - weekStart = _options.weekStart, - daysMin = _options.daysMin; - - + 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)); $.each(daysMin, function (i, day) { @@ -779,7 +743,6 @@ var render = { text: day })); }); - this.$week.html(items.join('')); }, renderYears: function renderYears() { @@ -789,7 +752,6 @@ var render = { var disabledClass = options.disabledClass, filter = options.filter, yearSuffix = options.yearSuffix; - var viewYear = this.viewDate.getFullYear(); var now = new Date(); var thisYear = now.getFullYear(); @@ -799,7 +761,7 @@ var render = { var items = []; var prevDisabled = false; var nextDisabled = false; - var i = void 0; + var i; for (i = start; i <= end; i += 1) { var date = new Date(viewYear + i, 1, 1); @@ -827,7 +789,6 @@ var render = { var picked = viewYear + i === year; var view = picked ? 'year picked' : 'year'; - items.push(this.createItem({ picked: picked, disabled: disabled, @@ -839,7 +800,7 @@ var render = { this.$yearsPrev.toggleClass(disabledClass, prevDisabled); this.$yearsNext.toggleClass(disabledClass, nextDisabled); - this.$yearsCurrent.toggleClass(disabledClass, true).html(viewYear + start + yearSuffix + ' - ' + (viewYear + end) + yearSuffix); + this.$yearsCurrent.toggleClass(disabledClass, true).html("".concat(viewYear + start + yearSuffix, " - ").concat(viewYear + end).concat(yearSuffix)); this.$years.html(items.join('')); }, renderMonths: function renderMonths() { @@ -847,7 +808,6 @@ var render = { startDate = this.startDate, endDate = this.endDate, viewDate = this.viewDate; - var disabledClass = options.disabledClass || ''; var months = options.monthsShort; var filter = $.isFunction(options.filter) && options.filter; @@ -860,7 +820,7 @@ var render = { var items = []; var prevDisabled = false; var nextDisabled = false; - var i = void 0; + var i; for (i = 0; i <= 11; i += 1) { var date = new Date(viewYear, i, 1); @@ -882,7 +842,6 @@ var render = { var picked = viewYear === year && i === month; var view = picked ? 'month picked' : 'month'; - items.push(this.createItem({ disabled: disabled, picked: picked, @@ -910,7 +869,6 @@ var render = { months = options.months, weekStart = options.weekStart, yearSuffix = options.yearSuffix; - var viewYear = viewDate.getFullYear(); var viewMonth = viewDate.getMonth(); var now = new Date(); @@ -920,11 +878,9 @@ var render = { var year = currentDate.getFullYear(); var month = currentDate.getMonth(); var day = currentDate.getDate(); - var length = void 0; - var i = void 0; - var n = void 0; - - // Days of prev month + var length; + var i; + var n; // Days of prev month // ----------------------------------------------------------------------- var prevItems = []; @@ -937,19 +893,16 @@ var render = { prevViewMonth = 11; } else { prevViewMonth -= 1; - } + } // The length of the days of prev month - // 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); + length = getDaysInMonth(prevViewYear, prevViewMonth); // The first day of current month - // The visible length of the days of prev 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] + 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; } @@ -978,11 +931,10 @@ var render = { text: i, view: 'day prev' })); - } - - // Days of next month + } // Days of next month // ----------------------------------------------------------------------- + var nextItems = []; var nextViewYear = viewYear; var nextViewMonth = viewMonth; @@ -993,15 +945,13 @@ var render = { nextViewMonth = 0; } else { nextViewMonth += 1; - } + } // The length of the days of current month + - // The length of the days of current month - length = getDaysInMonth(viewYear, viewMonth); + length = getDaysInMonth(viewYear, viewMonth); // The visible length of next month (42 means 6 rows and 7 columns) - // The visible length of next month (42 means 6 rows and 7 columns) - n = 42 - (prevItems.length + length); + n = 42 - (prevItems.length + length); // The last day of current month - // The last day of current month var lastDate = new Date(viewYear, viewMonth, length); if (endDate) { @@ -1029,15 +979,15 @@ var render = { text: i, view: 'day next' })); - } - - // Days of current month + } // 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) { @@ -1053,8 +1003,8 @@ var render = { } var _picked = viewYear === year && viewMonth === month && i === day; - var view = _picked ? 'day picked' : 'day'; + var view = _picked ? 'day picked' : 'day'; items.push(this.createItem({ disabled: _disabled2, picked: _picked, @@ -1062,30 +1012,26 @@ var render = { text: i, view: _disabled2 ? 'day disabled' : view })); - } - - // Render days picker + } // Render days picker // ----------------------------------------------------------------------- + this.$monthPrev.toggleClass(disabledClass, prevDisabled); this.$monthNext.toggleClass(disabledClass, nextDisabled); - this.$monthCurrent.toggleClass(disabledClass, prevDisabled && nextDisabled).html(options.yearFirst ? viewYear + yearSuffix + ' ' + months[viewMonth] : months[viewMonth] + ' ' + viewYear + yearSuffix); + 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 _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -// Classes -var CLASS_TOP_LEFT = NAMESPACE + '-top-left'; -var CLASS_TOP_RIGHT = NAMESPACE + '-top-right'; -var CLASS_BOTTOM_LEFT = NAMESPACE + '-bottom-left'; -var CLASS_BOTTOM_RIGHT = NAMESPACE + '-bottom-right'; +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 = function () { +var Datepicker = +/*#__PURE__*/ +function () { function Datepicker(element) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; @@ -1094,6 +1040,7 @@ var Datepicker = function () { this.$element = $(element); this.element = element; this.options = $.extend({}, DEFAULTS, LANGUAGES[options.language], $.isPlainObject(options) && options); + this.$scrollParent = getScrollParent(element, true); this.built = false; this.shown = false; this.isInput = false; @@ -1106,22 +1053,18 @@ var Datepicker = function () { } _createClass(Datepicker, [{ - key: 'init', + key: "init", value: function init() { var $this = this.$element, options = this.options; var startDate = options.startDate, endDate = options.endDate, date = options.date; - - this.$trigger = $(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); @@ -1164,37 +1107,31 @@ var Datepicker = function () { } } }, { - key: 'build', + key: "build", value: function build() { if (this.built) { return; } this.built = true; - var $this = this.$element, options = this.options; - var $picker = $(options.template); - this.$picker = $picker; - this.$week = $picker.find(selectorOf('week')); + this.$week = $picker.find(selectorOf('week')); // Years view - // 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')); + this.$years = $picker.find(selectorOf('years')); // Months view - // 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')); + this.$months = $picker.find(selectorOf('months')); // Days view - // Days view this.$daysPicker = $picker.find(selectorOf('days picker')); this.$monthPrev = $picker.find(selectorOf('month prev')); this.$monthNext = $picker.find(selectorOf('month next')); @@ -1202,16 +1139,18 @@ var Datepicker = function () { this.$days = $picker.find(selectorOf('days')); if (this.inline) { - $(options.container || $this).append($picker.addClass(NAMESPACE + '-inline')); + $(options.container || $this).append($picker.addClass("".concat(NAMESPACE, "-inline"))); } else { - $(document.body).append($picker.addClass(NAMESPACE + '-dropdown')); - $picker.addClass(CLASS_HIDE); + $(document.body).append($picker.addClass("".concat(NAMESPACE, "-dropdown"))); + $picker.addClass(CLASS_HIDE).css({ + zIndex: parseInt(options.zIndex, 10) + }); } this.renderWeek(); } }, { - key: 'unbuild', + key: "unbuild", value: function unbuild() { if (!this.built) { return; @@ -1221,12 +1160,11 @@ var Datepicker = function () { this.$picker.remove(); } }, { - key: 'bind', + key: "bind", value: function bind() { var options = this.options, $this = this.$element; - if ($.isFunction(options.show)) { $this.on(EVENT_SHOW, options.show); } @@ -1254,12 +1192,11 @@ var Datepicker = function () { } } }, { - key: 'unbind', + key: "unbind", value: function unbind() { var $this = this.$element, options = this.options; - if ($.isFunction(options.show)) { $this.off(EVENT_SHOW, options.show); } @@ -1287,14 +1224,13 @@ var Datepicker = function () { } } }, { - key: 'showView', + 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: @@ -1324,8 +1260,8 @@ var Datepicker = function () { } break; - // case VIEWS.DAYS: + default: $yearsPicker.addClass(CLASS_HIDE); $monthsPicker.addClass(CLASS_HIDE); @@ -1337,18 +1273,19 @@ var Datepicker = function () { } else { this.showView(VIEWS.MONTHS); } + } } } }, { - key: 'hideView', + key: "hideView", value: function hideView() { if (!this.inline && this.options.autoHide) { this.hide(); } } }, { - key: 'place', + key: "place", value: function place() { if (this.inline) { return; @@ -1357,7 +1294,6 @@ var Datepicker = function () { var $this = this.$element, options = this.options, $picker = this.$picker; - var containerWidth = $(document).outerWidth(); var containerHeight = $(document).outerHeight(); var elementWidth = $this.outerWidth(); @@ -1390,28 +1326,22 @@ var Datepicker = function () { $picker.removeClass(CLASS_PLACEMENTS).addClass(placement).css({ top: top, - left: left, - zIndex: parseInt(options.zIndex, 10) + left: left }); - } - - // A shortcut for triggering custom events + } // A shortcut for triggering custom events }, { - key: 'trigger', + key: "trigger", value: function trigger(type, data) { var e = $.Event(type, data); - this.$element.trigger(e); - return e; } }, { - key: 'createItem', + key: "createItem", value: function createItem(data) { var options = this.options; var itemTag = options.itemTag; - var item = { text: '', view: '', @@ -1421,7 +1351,6 @@ var Datepicker = function () { highlighted: false }; var classes = []; - $.extend(item, data); if (item.muted) { @@ -1440,33 +1369,30 @@ var Datepicker = function () { classes.push(options.disabledClass); } - return '<' + itemTag + ' class="' + classes.join(' ') + '" data-view="' + item.view + '">' + item.text + ''; + return "<".concat(itemTag, " class=\"").concat(classes.join(' '), "\" data-view=\"").concat(item.view, "\">").concat(item.text, ""); } }, { - key: 'getValue', + key: "getValue", value: function getValue() { var $this = this.$element; - return this.isInput ? $this.val() : $this.text(); } }, { - key: 'setValue', + 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 { + } else if (!this.inline || this.options.container) { $this.text(value); } } }], [{ - key: 'setDefaults', + key: "setDefaults", value: function setDefaults() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - $.extend(DEFAULTS, LANGUAGES[options.language], $.isPlainObject(options) && options); } }]); @@ -1482,12 +1408,11 @@ if ($.fn) { var AnotherDatepicker = $.fn.datepicker; $.fn.datepicker = function jQueryDatepicker(option) { - for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + 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 = void 0; - + var result; this.each(function (i, element) { var $element = $(element); var isDestroy = option === 'destroy'; @@ -1499,7 +1424,6 @@ if ($.fn) { } var options = $.extend({}, $element.data(), $.isPlainObject(option) && option); - datepicker = new Datepicker(element, options); $element.data(NAMESPACE, datepicker); } @@ -1516,13 +1440,13 @@ if ($.fn) { } } }); - return !isUndefined(result) ? result : this; }; $.fn.datepicker.Constructor = Datepicker; $.fn.datepicker.languages = LANGUAGES; $.fn.datepicker.setDefaults = Datepicker.setDefaults; + $.fn.datepicker.noConflict = function noConflict() { $.fn.datepicker = AnotherDatepicker; return this; diff --git a/dist/datepicker.css b/dist/datepicker.css index 35a3766..5a1cb1f 100644 --- a/dist/datepicker.css +++ b/dist/datepicker.css @@ -1,11 +1,11 @@ /*! - * Datepicker v1.0.0 + * Datepicker v1.0.1 * https://fengyuanchen.github.io/datepicker * * Copyright 2014-present Chen Fengyuan * Released under the MIT license * - * Date: 2018-08-05T03:02:13.513Z + * Date: 2018-11-14T13:59:44.094Z */ .datepicker-container { diff --git a/dist/datepicker.esm.js b/dist/datepicker.esm.js index d2ebad1..c9930ff 100644 --- a/dist/datepicker.esm.js +++ b/dist/datepicker.esm.js @@ -1,105 +1,99 @@ /*! - * Datepicker v1.0.0 + * Datepicker v1.0.1 * https://fengyuanchen.github.io/datepicker * * Copyright 2014-present Chen Fengyuan * Released under the MIT license * - * Date: 2018-08-05T03:02:19.812Z + * Date: 2018-11-14T13:59:48.051Z */ import $ from 'jquery'; +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 - + 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: '
' + '
' + '' + '' + '
' + '
' + '' + '' + '
' + '
' + '' + '' + '' + '
' + '
', - // 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, @@ -108,14 +102,15 @@ var DEFAULTS = { var WINDOW = typeof window !== 'undefined' ? window : {}; var NAMESPACE = 'datepicker'; -var EVENT_CLICK = 'click.' + NAMESPACE; -var EVENT_FOCUS = 'focus.' + NAMESPACE; -var EVENT_HIDE = 'hide.' + NAMESPACE; -var EVENT_KEYUP = 'keyup.' + NAMESPACE; -var EVENT_PICK = 'pick.' + NAMESPACE; -var EVENT_RESIZE = 'resize.' + NAMESPACE; -var EVENT_SHOW = 'show.' + NAMESPACE; -var CLASS_HIDE = NAMESPACE + '-hide'; +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 CLASS_HIDE = "".concat(NAMESPACE, "-hide"); var LANGUAGES = {}; var VIEWS = { DAYS: 0, @@ -124,62 +119,48 @@ var VIEWS = { }; 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'; } - function proxy(fn, context) { - for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { + 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 = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + 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="' + 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); @@ -192,7 +173,6 @@ function parseFormat(format) { source: source, parts: parts }; - $.each(parts, function (i, part) { switch (part) { case 'dd': @@ -213,12 +193,27 @@ function parseFormat(format) { default: } }); - return format; } +function getScrollParent(element) { + var includeHidden = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var $element = $(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 = $(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 ? $(element.ownerDocument || document) : scrollParent; +} var REGEXP_DIGITS = /\d+/g; - var methods = { // Show the datepicker show: function show() { @@ -239,14 +234,13 @@ var methods = { this.showView(this.options.startView); if (!this.inline) { + this.$scrollParent.on(EVENT_SCROLL, $.proxy(this.place, this)); $(window).on(EVENT_RESIZE, this.onResize = proxy(this.place, this)); $(document).on(EVENT_CLICK, this.onGlobalClick = proxy(this.globalClick, this)); $(document).on(EVENT_KEYUP, this.onGlobalKeyup = proxy(this.globalKeyup, this)); this.place(); } }, - - // Hide the datepicker hide: function hide() { if (!this.shown) { @@ -261,6 +255,7 @@ var methods = { this.$picker.addClass(CLASS_HIDE).off(EVENT_CLICK, this.click); if (!this.inline) { + this.$scrollParent.off(EVENT_SCROLL, this.place); $(window).off(EVENT_RESIZE, this.onResize); $(document).off(EVENT_CLICK, this.onGlobalClick); $(document).off(EVENT_KEYUP, this.onGlobalKeyup); @@ -273,8 +268,6 @@ var methods = { this.show(); } }, - - // Update the datepicker with the current input value update: function update() { var value = this.getValue(); @@ -287,7 +280,6 @@ var methods = { this.oldValue = value; }, - /** * Pick the current date to the element * @@ -297,7 +289,6 @@ var methods = { var $this = this.$element; var date = this.date; - if (this.trigger(EVENT_PICK, { view: _view || '', date: date @@ -313,8 +304,6 @@ var methods = { $this.trigger('change'); } }, - - // Reset the datepicker reset: function reset() { this.setDate(this.initialDate, true); @@ -325,7 +314,6 @@ var methods = { } }, - /** * Get the month name with given argument or the current date * @@ -338,7 +326,6 @@ var methods = { var monthsShort = options.monthsShort; var months = options.months; - if ($.isNumeric(month)) { month = Number(month); } else if (isUndefined(shortForm)) { @@ -352,7 +339,6 @@ var methods = { return months[isNumber(month) ? month : this.date.getMonth()]; }, - /** * Get the day name with given argument or the current date * @@ -365,7 +351,6 @@ var methods = { var options = this.options; var days = options.days; - if ($.isNumeric(day)) { day = Number(day); } else { @@ -387,7 +372,6 @@ var methods = { return days[isNumber(day) ? day : this.date.getDay()]; }, - /** * Get the current date * @@ -396,12 +380,9 @@ var methods = { */ getDate: function getDate(formatted) { var date = this.date; - - return formatted ? this.formatDate(date) : new Date(date); }, - /** * Set the current date with a new date * @@ -411,7 +392,6 @@ var methods = { setDate: function setDate(date, _updated) { var filter = this.options.filter; - if (isDate(date) || isString(date)) { date = this.parseDate(date); @@ -432,7 +412,6 @@ var methods = { } }, - /** * Set the start view date with a new date * @@ -450,7 +429,6 @@ var methods = { } }, - /** * Set the end view date with a new date * @@ -468,7 +446,6 @@ var methods = { } }, - /** * Parse a date string with the set date format * @@ -477,7 +454,6 @@ var methods = { */ parseDate: function parseDate(date) { var format = this.format; - var parts = []; if (isDate(date)) { @@ -489,9 +465,7 @@ var methods = { } date = new Date(); - var length = format.parts.length; - var year = date.getFullYear(); var day = date.getDate(); var month = date.getMonth(); @@ -527,7 +501,6 @@ var methods = { return new Date(year, month, day); }, - /** * Format a date object to a string with the set date format * @@ -536,7 +509,6 @@ var methods = { */ formatDate: function formatDate(date) { var format = this.format; - var formatted = ''; if (isDate(date)) { @@ -547,7 +519,6 @@ var methods = { yy: year.toString().substring(2), yyyy: year }; - values.dd = (values.d < 10 ? '0' : '') + values.d; values.mm = (values.m < 10 ? '0' : '') + values.m; formatted = format.source; @@ -558,8 +529,6 @@ var methods = { return formatted; }, - - // Destroy the datepicker and remove the instance from the target element destroy: function destroy() { this.unbind(); @@ -574,8 +543,6 @@ var handlers = { var options = this.options, viewDate = this.viewDate, format = this.format; - - e.stopPropagation(); e.preventDefault(); @@ -722,7 +689,6 @@ var handlers = { var target = _ref.target; var element = this.element, $trigger = this.$trigger; - var trigger = $trigger[0]; var hidden = true; @@ -763,11 +729,9 @@ var render = { var _this = this; var items = []; - var _options = this.options, - weekStart = _options.weekStart, - daysMin = _options.daysMin; - - + 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)); $.each(daysMin, function (i, day) { @@ -775,7 +739,6 @@ var render = { text: day })); }); - this.$week.html(items.join('')); }, renderYears: function renderYears() { @@ -785,7 +748,6 @@ var render = { var disabledClass = options.disabledClass, filter = options.filter, yearSuffix = options.yearSuffix; - var viewYear = this.viewDate.getFullYear(); var now = new Date(); var thisYear = now.getFullYear(); @@ -795,7 +757,7 @@ var render = { var items = []; var prevDisabled = false; var nextDisabled = false; - var i = void 0; + var i; for (i = start; i <= end; i += 1) { var date = new Date(viewYear + i, 1, 1); @@ -823,7 +785,6 @@ var render = { var picked = viewYear + i === year; var view = picked ? 'year picked' : 'year'; - items.push(this.createItem({ picked: picked, disabled: disabled, @@ -835,7 +796,7 @@ var render = { this.$yearsPrev.toggleClass(disabledClass, prevDisabled); this.$yearsNext.toggleClass(disabledClass, nextDisabled); - this.$yearsCurrent.toggleClass(disabledClass, true).html(viewYear + start + yearSuffix + ' - ' + (viewYear + end) + yearSuffix); + this.$yearsCurrent.toggleClass(disabledClass, true).html("".concat(viewYear + start + yearSuffix, " - ").concat(viewYear + end).concat(yearSuffix)); this.$years.html(items.join('')); }, renderMonths: function renderMonths() { @@ -843,7 +804,6 @@ var render = { startDate = this.startDate, endDate = this.endDate, viewDate = this.viewDate; - var disabledClass = options.disabledClass || ''; var months = options.monthsShort; var filter = $.isFunction(options.filter) && options.filter; @@ -856,7 +816,7 @@ var render = { var items = []; var prevDisabled = false; var nextDisabled = false; - var i = void 0; + var i; for (i = 0; i <= 11; i += 1) { var date = new Date(viewYear, i, 1); @@ -878,7 +838,6 @@ var render = { var picked = viewYear === year && i === month; var view = picked ? 'month picked' : 'month'; - items.push(this.createItem({ disabled: disabled, picked: picked, @@ -906,7 +865,6 @@ var render = { months = options.months, weekStart = options.weekStart, yearSuffix = options.yearSuffix; - var viewYear = viewDate.getFullYear(); var viewMonth = viewDate.getMonth(); var now = new Date(); @@ -916,11 +874,9 @@ var render = { var year = currentDate.getFullYear(); var month = currentDate.getMonth(); var day = currentDate.getDate(); - var length = void 0; - var i = void 0; - var n = void 0; - - // Days of prev month + var length; + var i; + var n; // Days of prev month // ----------------------------------------------------------------------- var prevItems = []; @@ -933,19 +889,16 @@ var render = { prevViewMonth = 11; } else { prevViewMonth -= 1; - } + } // The length of the days of prev month - // 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); + length = getDaysInMonth(prevViewYear, prevViewMonth); // The first day of current month - // The visible length of the days of prev 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] + 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; } @@ -974,11 +927,10 @@ var render = { text: i, view: 'day prev' })); - } - - // Days of next month + } // Days of next month // ----------------------------------------------------------------------- + var nextItems = []; var nextViewYear = viewYear; var nextViewMonth = viewMonth; @@ -989,15 +941,13 @@ var render = { nextViewMonth = 0; } else { nextViewMonth += 1; - } + } // The length of the days of current month + - // The length of the days of current month - length = getDaysInMonth(viewYear, viewMonth); + length = getDaysInMonth(viewYear, viewMonth); // The visible length of next month (42 means 6 rows and 7 columns) - // The visible length of next month (42 means 6 rows and 7 columns) - n = 42 - (prevItems.length + length); + n = 42 - (prevItems.length + length); // The last day of current month - // The last day of current month var lastDate = new Date(viewYear, viewMonth, length); if (endDate) { @@ -1025,15 +975,15 @@ var render = { text: i, view: 'day next' })); - } - - // Days of current month + } // 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) { @@ -1049,8 +999,8 @@ var render = { } var _picked = viewYear === year && viewMonth === month && i === day; - var view = _picked ? 'day picked' : 'day'; + var view = _picked ? 'day picked' : 'day'; items.push(this.createItem({ disabled: _disabled2, picked: _picked, @@ -1058,30 +1008,26 @@ var render = { text: i, view: _disabled2 ? 'day disabled' : view })); - } - - // Render days picker + } // Render days picker // ----------------------------------------------------------------------- + this.$monthPrev.toggleClass(disabledClass, prevDisabled); this.$monthNext.toggleClass(disabledClass, nextDisabled); - this.$monthCurrent.toggleClass(disabledClass, prevDisabled && nextDisabled).html(options.yearFirst ? viewYear + yearSuffix + ' ' + months[viewMonth] : months[viewMonth] + ' ' + viewYear + yearSuffix); + 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 _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -// Classes -var CLASS_TOP_LEFT = NAMESPACE + '-top-left'; -var CLASS_TOP_RIGHT = NAMESPACE + '-top-right'; -var CLASS_BOTTOM_LEFT = NAMESPACE + '-bottom-left'; -var CLASS_BOTTOM_RIGHT = NAMESPACE + '-bottom-right'; +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 = function () { +var Datepicker = +/*#__PURE__*/ +function () { function Datepicker(element) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; @@ -1090,6 +1036,7 @@ var Datepicker = function () { this.$element = $(element); this.element = element; this.options = $.extend({}, DEFAULTS, LANGUAGES[options.language], $.isPlainObject(options) && options); + this.$scrollParent = getScrollParent(element, true); this.built = false; this.shown = false; this.isInput = false; @@ -1102,22 +1049,18 @@ var Datepicker = function () { } _createClass(Datepicker, [{ - key: 'init', + key: "init", value: function init() { var $this = this.$element, options = this.options; var startDate = options.startDate, endDate = options.endDate, date = options.date; - - this.$trigger = $(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); @@ -1160,37 +1103,31 @@ var Datepicker = function () { } } }, { - key: 'build', + key: "build", value: function build() { if (this.built) { return; } this.built = true; - var $this = this.$element, options = this.options; - var $picker = $(options.template); - this.$picker = $picker; - this.$week = $picker.find(selectorOf('week')); + this.$week = $picker.find(selectorOf('week')); // Years view - // 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')); + this.$years = $picker.find(selectorOf('years')); // Months view - // 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')); + this.$months = $picker.find(selectorOf('months')); // Days view - // Days view this.$daysPicker = $picker.find(selectorOf('days picker')); this.$monthPrev = $picker.find(selectorOf('month prev')); this.$monthNext = $picker.find(selectorOf('month next')); @@ -1198,16 +1135,18 @@ var Datepicker = function () { this.$days = $picker.find(selectorOf('days')); if (this.inline) { - $(options.container || $this).append($picker.addClass(NAMESPACE + '-inline')); + $(options.container || $this).append($picker.addClass("".concat(NAMESPACE, "-inline"))); } else { - $(document.body).append($picker.addClass(NAMESPACE + '-dropdown')); - $picker.addClass(CLASS_HIDE); + $(document.body).append($picker.addClass("".concat(NAMESPACE, "-dropdown"))); + $picker.addClass(CLASS_HIDE).css({ + zIndex: parseInt(options.zIndex, 10) + }); } this.renderWeek(); } }, { - key: 'unbuild', + key: "unbuild", value: function unbuild() { if (!this.built) { return; @@ -1217,12 +1156,11 @@ var Datepicker = function () { this.$picker.remove(); } }, { - key: 'bind', + key: "bind", value: function bind() { var options = this.options, $this = this.$element; - if ($.isFunction(options.show)) { $this.on(EVENT_SHOW, options.show); } @@ -1250,12 +1188,11 @@ var Datepicker = function () { } } }, { - key: 'unbind', + key: "unbind", value: function unbind() { var $this = this.$element, options = this.options; - if ($.isFunction(options.show)) { $this.off(EVENT_SHOW, options.show); } @@ -1283,14 +1220,13 @@ var Datepicker = function () { } } }, { - key: 'showView', + 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: @@ -1320,8 +1256,8 @@ var Datepicker = function () { } break; - // case VIEWS.DAYS: + default: $yearsPicker.addClass(CLASS_HIDE); $monthsPicker.addClass(CLASS_HIDE); @@ -1333,18 +1269,19 @@ var Datepicker = function () { } else { this.showView(VIEWS.MONTHS); } + } } } }, { - key: 'hideView', + key: "hideView", value: function hideView() { if (!this.inline && this.options.autoHide) { this.hide(); } } }, { - key: 'place', + key: "place", value: function place() { if (this.inline) { return; @@ -1353,7 +1290,6 @@ var Datepicker = function () { var $this = this.$element, options = this.options, $picker = this.$picker; - var containerWidth = $(document).outerWidth(); var containerHeight = $(document).outerHeight(); var elementWidth = $this.outerWidth(); @@ -1386,28 +1322,22 @@ var Datepicker = function () { $picker.removeClass(CLASS_PLACEMENTS).addClass(placement).css({ top: top, - left: left, - zIndex: parseInt(options.zIndex, 10) + left: left }); - } - - // A shortcut for triggering custom events + } // A shortcut for triggering custom events }, { - key: 'trigger', + key: "trigger", value: function trigger(type, data) { var e = $.Event(type, data); - this.$element.trigger(e); - return e; } }, { - key: 'createItem', + key: "createItem", value: function createItem(data) { var options = this.options; var itemTag = options.itemTag; - var item = { text: '', view: '', @@ -1417,7 +1347,6 @@ var Datepicker = function () { highlighted: false }; var classes = []; - $.extend(item, data); if (item.muted) { @@ -1436,33 +1365,30 @@ var Datepicker = function () { classes.push(options.disabledClass); } - return '<' + itemTag + ' class="' + classes.join(' ') + '" data-view="' + item.view + '">' + item.text + ''; + return "<".concat(itemTag, " class=\"").concat(classes.join(' '), "\" data-view=\"").concat(item.view, "\">").concat(item.text, ""); } }, { - key: 'getValue', + key: "getValue", value: function getValue() { var $this = this.$element; - return this.isInput ? $this.val() : $this.text(); } }, { - key: 'setValue', + 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 { + } else if (!this.inline || this.options.container) { $this.text(value); } } }], [{ - key: 'setDefaults', + key: "setDefaults", value: function setDefaults() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - $.extend(DEFAULTS, LANGUAGES[options.language], $.isPlainObject(options) && options); } }]); @@ -1478,12 +1404,11 @@ if ($.fn) { var AnotherDatepicker = $.fn.datepicker; $.fn.datepicker = function jQueryDatepicker(option) { - for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + 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 = void 0; - + var result; this.each(function (i, element) { var $element = $(element); var isDestroy = option === 'destroy'; @@ -1495,7 +1420,6 @@ if ($.fn) { } var options = $.extend({}, $element.data(), $.isPlainObject(option) && option); - datepicker = new Datepicker(element, options); $element.data(NAMESPACE, datepicker); } @@ -1512,13 +1436,13 @@ if ($.fn) { } } }); - return !isUndefined(result) ? result : this; }; $.fn.datepicker.Constructor = Datepicker; $.fn.datepicker.languages = LANGUAGES; $.fn.datepicker.setDefaults = Datepicker.setDefaults; + $.fn.datepicker.noConflict = function noConflict() { $.fn.datepicker = AnotherDatepicker; return this; diff --git a/dist/datepicker.js b/dist/datepicker.js index a4b85c6..c3d5936 100644 --- a/dist/datepicker.js +++ b/dist/datepicker.js @@ -1,11 +1,11 @@ /*! - * Datepicker v1.0.0 + * Datepicker v1.0.1 * https://fengyuanchen.github.io/datepicker * * Copyright 2014-present Chen Fengyuan * Released under the MIT license * - * Date: 2018-08-05T03:02:19.812Z + * Date: 2018-11-14T13:59:48.051Z */ (function (global, factory) { @@ -16,96 +16,90 @@ $ = $ && $.hasOwnProperty('default') ? $['default'] : $; + 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 - + 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: '
' + '
' + '' + '' + '
' + '
' + '' + '' + '
' + '
' + '' + '' + '' + '
' + '
', - // 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, @@ -114,14 +108,15 @@ var WINDOW = typeof window !== 'undefined' ? window : {}; var NAMESPACE = 'datepicker'; - var EVENT_CLICK = 'click.' + NAMESPACE; - var EVENT_FOCUS = 'focus.' + NAMESPACE; - var EVENT_HIDE = 'hide.' + NAMESPACE; - var EVENT_KEYUP = 'keyup.' + NAMESPACE; - var EVENT_PICK = 'pick.' + NAMESPACE; - var EVENT_RESIZE = 'resize.' + NAMESPACE; - var EVENT_SHOW = 'show.' + NAMESPACE; - var CLASS_HIDE = NAMESPACE + '-hide'; + 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 CLASS_HIDE = "".concat(NAMESPACE, "-hide"); var LANGUAGES = {}; var VIEWS = { DAYS: 0, @@ -130,62 +125,48 @@ }; 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'; } - function proxy(fn, context) { - for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { + 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 = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + 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="' + 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); @@ -198,7 +179,6 @@ source: source, parts: parts }; - $.each(parts, function (i, part) { switch (part) { case 'dd': @@ -219,12 +199,27 @@ default: } }); - return format; } + function getScrollParent(element) { + var includeHidden = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var $element = $(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 = $(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 ? $(element.ownerDocument || document) : scrollParent; + } var REGEXP_DIGITS = /\d+/g; - var methods = { // Show the datepicker show: function show() { @@ -245,14 +240,13 @@ this.showView(this.options.startView); if (!this.inline) { + this.$scrollParent.on(EVENT_SCROLL, $.proxy(this.place, this)); $(window).on(EVENT_RESIZE, this.onResize = proxy(this.place, this)); $(document).on(EVENT_CLICK, this.onGlobalClick = proxy(this.globalClick, this)); $(document).on(EVENT_KEYUP, this.onGlobalKeyup = proxy(this.globalKeyup, this)); this.place(); } }, - - // Hide the datepicker hide: function hide() { if (!this.shown) { @@ -267,6 +261,7 @@ this.$picker.addClass(CLASS_HIDE).off(EVENT_CLICK, this.click); if (!this.inline) { + this.$scrollParent.off(EVENT_SCROLL, this.place); $(window).off(EVENT_RESIZE, this.onResize); $(document).off(EVENT_CLICK, this.onGlobalClick); $(document).off(EVENT_KEYUP, this.onGlobalKeyup); @@ -279,8 +274,6 @@ this.show(); } }, - - // Update the datepicker with the current input value update: function update() { var value = this.getValue(); @@ -293,7 +286,6 @@ this.oldValue = value; }, - /** * Pick the current date to the element * @@ -303,7 +295,6 @@ var $this = this.$element; var date = this.date; - if (this.trigger(EVENT_PICK, { view: _view || '', date: date @@ -319,8 +310,6 @@ $this.trigger('change'); } }, - - // Reset the datepicker reset: function reset() { this.setDate(this.initialDate, true); @@ -331,7 +320,6 @@ } }, - /** * Get the month name with given argument or the current date * @@ -344,7 +332,6 @@ var monthsShort = options.monthsShort; var months = options.months; - if ($.isNumeric(month)) { month = Number(month); } else if (isUndefined(shortForm)) { @@ -358,7 +345,6 @@ return months[isNumber(month) ? month : this.date.getMonth()]; }, - /** * Get the day name with given argument or the current date * @@ -371,7 +357,6 @@ var options = this.options; var days = options.days; - if ($.isNumeric(day)) { day = Number(day); } else { @@ -393,7 +378,6 @@ return days[isNumber(day) ? day : this.date.getDay()]; }, - /** * Get the current date * @@ -402,12 +386,9 @@ */ getDate: function getDate(formatted) { var date = this.date; - - return formatted ? this.formatDate(date) : new Date(date); }, - /** * Set the current date with a new date * @@ -417,7 +398,6 @@ setDate: function setDate(date, _updated) { var filter = this.options.filter; - if (isDate(date) || isString(date)) { date = this.parseDate(date); @@ -438,7 +418,6 @@ } }, - /** * Set the start view date with a new date * @@ -456,7 +435,6 @@ } }, - /** * Set the end view date with a new date * @@ -474,7 +452,6 @@ } }, - /** * Parse a date string with the set date format * @@ -483,7 +460,6 @@ */ parseDate: function parseDate(date) { var format = this.format; - var parts = []; if (isDate(date)) { @@ -495,9 +471,7 @@ } date = new Date(); - var length = format.parts.length; - var year = date.getFullYear(); var day = date.getDate(); var month = date.getMonth(); @@ -533,7 +507,6 @@ return new Date(year, month, day); }, - /** * Format a date object to a string with the set date format * @@ -542,7 +515,6 @@ */ formatDate: function formatDate(date) { var format = this.format; - var formatted = ''; if (isDate(date)) { @@ -553,7 +525,6 @@ yy: year.toString().substring(2), yyyy: year }; - values.dd = (values.d < 10 ? '0' : '') + values.d; values.mm = (values.m < 10 ? '0' : '') + values.m; formatted = format.source; @@ -564,8 +535,6 @@ return formatted; }, - - // Destroy the datepicker and remove the instance from the target element destroy: function destroy() { this.unbind(); @@ -580,8 +549,6 @@ var options = this.options, viewDate = this.viewDate, format = this.format; - - e.stopPropagation(); e.preventDefault(); @@ -728,7 +695,6 @@ var target = _ref.target; var element = this.element, $trigger = this.$trigger; - var trigger = $trigger[0]; var hidden = true; @@ -769,11 +735,9 @@ var _this = this; var items = []; - var _options = this.options, - weekStart = _options.weekStart, - daysMin = _options.daysMin; - - + 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)); $.each(daysMin, function (i, day) { @@ -781,7 +745,6 @@ text: day })); }); - this.$week.html(items.join('')); }, renderYears: function renderYears() { @@ -791,7 +754,6 @@ var disabledClass = options.disabledClass, filter = options.filter, yearSuffix = options.yearSuffix; - var viewYear = this.viewDate.getFullYear(); var now = new Date(); var thisYear = now.getFullYear(); @@ -801,7 +763,7 @@ var items = []; var prevDisabled = false; var nextDisabled = false; - var i = void 0; + var i; for (i = start; i <= end; i += 1) { var date = new Date(viewYear + i, 1, 1); @@ -829,7 +791,6 @@ var picked = viewYear + i === year; var view = picked ? 'year picked' : 'year'; - items.push(this.createItem({ picked: picked, disabled: disabled, @@ -841,7 +802,7 @@ this.$yearsPrev.toggleClass(disabledClass, prevDisabled); this.$yearsNext.toggleClass(disabledClass, nextDisabled); - this.$yearsCurrent.toggleClass(disabledClass, true).html(viewYear + start + yearSuffix + ' - ' + (viewYear + end) + yearSuffix); + this.$yearsCurrent.toggleClass(disabledClass, true).html("".concat(viewYear + start + yearSuffix, " - ").concat(viewYear + end).concat(yearSuffix)); this.$years.html(items.join('')); }, renderMonths: function renderMonths() { @@ -849,7 +810,6 @@ startDate = this.startDate, endDate = this.endDate, viewDate = this.viewDate; - var disabledClass = options.disabledClass || ''; var months = options.monthsShort; var filter = $.isFunction(options.filter) && options.filter; @@ -862,7 +822,7 @@ var items = []; var prevDisabled = false; var nextDisabled = false; - var i = void 0; + var i; for (i = 0; i <= 11; i += 1) { var date = new Date(viewYear, i, 1); @@ -884,7 +844,6 @@ var picked = viewYear === year && i === month; var view = picked ? 'month picked' : 'month'; - items.push(this.createItem({ disabled: disabled, picked: picked, @@ -912,7 +871,6 @@ months = options.months, weekStart = options.weekStart, yearSuffix = options.yearSuffix; - var viewYear = viewDate.getFullYear(); var viewMonth = viewDate.getMonth(); var now = new Date(); @@ -922,11 +880,9 @@ var year = currentDate.getFullYear(); var month = currentDate.getMonth(); var day = currentDate.getDate(); - var length = void 0; - var i = void 0; - var n = void 0; - - // Days of prev month + var length; + var i; + var n; // Days of prev month // ----------------------------------------------------------------------- var prevItems = []; @@ -939,19 +895,16 @@ prevViewMonth = 11; } else { prevViewMonth -= 1; - } + } // The length of the days of prev month - // 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); + length = getDaysInMonth(prevViewYear, prevViewMonth); // The first day of current month - // The visible length of the days of prev 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] + 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; } @@ -980,11 +933,10 @@ text: i, view: 'day prev' })); - } - - // Days of next month + } // Days of next month // ----------------------------------------------------------------------- + var nextItems = []; var nextViewYear = viewYear; var nextViewMonth = viewMonth; @@ -995,15 +947,13 @@ nextViewMonth = 0; } else { nextViewMonth += 1; - } + } // The length of the days of current month + - // The length of the days of current month - length = getDaysInMonth(viewYear, viewMonth); + length = getDaysInMonth(viewYear, viewMonth); // The visible length of next month (42 means 6 rows and 7 columns) - // The visible length of next month (42 means 6 rows and 7 columns) - n = 42 - (prevItems.length + length); + n = 42 - (prevItems.length + length); // The last day of current month - // The last day of current month var lastDate = new Date(viewYear, viewMonth, length); if (endDate) { @@ -1031,15 +981,15 @@ text: i, view: 'day next' })); - } - - // Days of current month + } // 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) { @@ -1055,8 +1005,8 @@ } var _picked = viewYear === year && viewMonth === month && i === day; - var view = _picked ? 'day picked' : 'day'; + var view = _picked ? 'day picked' : 'day'; items.push(this.createItem({ disabled: _disabled2, picked: _picked, @@ -1064,30 +1014,26 @@ text: i, view: _disabled2 ? 'day disabled' : view })); - } - - // Render days picker + } // Render days picker // ----------------------------------------------------------------------- + this.$monthPrev.toggleClass(disabledClass, prevDisabled); this.$monthNext.toggleClass(disabledClass, nextDisabled); - this.$monthCurrent.toggleClass(disabledClass, prevDisabled && nextDisabled).html(options.yearFirst ? viewYear + yearSuffix + ' ' + months[viewMonth] : months[viewMonth] + ' ' + viewYear + yearSuffix); + 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 _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - - // Classes - var CLASS_TOP_LEFT = NAMESPACE + '-top-left'; - var CLASS_TOP_RIGHT = NAMESPACE + '-top-right'; - var CLASS_BOTTOM_LEFT = NAMESPACE + '-bottom-left'; - var CLASS_BOTTOM_RIGHT = NAMESPACE + '-bottom-right'; + 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 = function () { + var Datepicker = + /*#__PURE__*/ + function () { function Datepicker(element) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; @@ -1096,6 +1042,7 @@ this.$element = $(element); this.element = element; this.options = $.extend({}, DEFAULTS, LANGUAGES[options.language], $.isPlainObject(options) && options); + this.$scrollParent = getScrollParent(element, true); this.built = false; this.shown = false; this.isInput = false; @@ -1108,22 +1055,18 @@ } _createClass(Datepicker, [{ - key: 'init', + key: "init", value: function init() { var $this = this.$element, options = this.options; var startDate = options.startDate, endDate = options.endDate, date = options.date; - - this.$trigger = $(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); @@ -1166,37 +1109,31 @@ } } }, { - key: 'build', + key: "build", value: function build() { if (this.built) { return; } this.built = true; - var $this = this.$element, options = this.options; - var $picker = $(options.template); - this.$picker = $picker; - this.$week = $picker.find(selectorOf('week')); + this.$week = $picker.find(selectorOf('week')); // Years view - // 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')); + this.$years = $picker.find(selectorOf('years')); // Months view - // 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')); + this.$months = $picker.find(selectorOf('months')); // Days view - // Days view this.$daysPicker = $picker.find(selectorOf('days picker')); this.$monthPrev = $picker.find(selectorOf('month prev')); this.$monthNext = $picker.find(selectorOf('month next')); @@ -1204,16 +1141,18 @@ this.$days = $picker.find(selectorOf('days')); if (this.inline) { - $(options.container || $this).append($picker.addClass(NAMESPACE + '-inline')); + $(options.container || $this).append($picker.addClass("".concat(NAMESPACE, "-inline"))); } else { - $(document.body).append($picker.addClass(NAMESPACE + '-dropdown')); - $picker.addClass(CLASS_HIDE); + $(document.body).append($picker.addClass("".concat(NAMESPACE, "-dropdown"))); + $picker.addClass(CLASS_HIDE).css({ + zIndex: parseInt(options.zIndex, 10) + }); } this.renderWeek(); } }, { - key: 'unbuild', + key: "unbuild", value: function unbuild() { if (!this.built) { return; @@ -1223,12 +1162,11 @@ this.$picker.remove(); } }, { - key: 'bind', + key: "bind", value: function bind() { var options = this.options, $this = this.$element; - if ($.isFunction(options.show)) { $this.on(EVENT_SHOW, options.show); } @@ -1256,12 +1194,11 @@ } } }, { - key: 'unbind', + key: "unbind", value: function unbind() { var $this = this.$element, options = this.options; - if ($.isFunction(options.show)) { $this.off(EVENT_SHOW, options.show); } @@ -1289,14 +1226,13 @@ } } }, { - key: 'showView', + 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: @@ -1326,8 +1262,8 @@ } break; - // case VIEWS.DAYS: + default: $yearsPicker.addClass(CLASS_HIDE); $monthsPicker.addClass(CLASS_HIDE); @@ -1339,18 +1275,19 @@ } else { this.showView(VIEWS.MONTHS); } + } } } }, { - key: 'hideView', + key: "hideView", value: function hideView() { if (!this.inline && this.options.autoHide) { this.hide(); } } }, { - key: 'place', + key: "place", value: function place() { if (this.inline) { return; @@ -1359,7 +1296,6 @@ var $this = this.$element, options = this.options, $picker = this.$picker; - var containerWidth = $(document).outerWidth(); var containerHeight = $(document).outerHeight(); var elementWidth = $this.outerWidth(); @@ -1392,28 +1328,22 @@ $picker.removeClass(CLASS_PLACEMENTS).addClass(placement).css({ top: top, - left: left, - zIndex: parseInt(options.zIndex, 10) + left: left }); - } - - // A shortcut for triggering custom events + } // A shortcut for triggering custom events }, { - key: 'trigger', + key: "trigger", value: function trigger(type, data) { var e = $.Event(type, data); - this.$element.trigger(e); - return e; } }, { - key: 'createItem', + key: "createItem", value: function createItem(data) { var options = this.options; var itemTag = options.itemTag; - var item = { text: '', view: '', @@ -1423,7 +1353,6 @@ highlighted: false }; var classes = []; - $.extend(item, data); if (item.muted) { @@ -1442,33 +1371,30 @@ classes.push(options.disabledClass); } - return '<' + itemTag + ' class="' + classes.join(' ') + '" data-view="' + item.view + '">' + item.text + ''; + return "<".concat(itemTag, " class=\"").concat(classes.join(' '), "\" data-view=\"").concat(item.view, "\">").concat(item.text, ""); } }, { - key: 'getValue', + key: "getValue", value: function getValue() { var $this = this.$element; - return this.isInput ? $this.val() : $this.text(); } }, { - key: 'setValue', + 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 { + } else if (!this.inline || this.options.container) { $this.text(value); } } }], [{ - key: 'setDefaults', + key: "setDefaults", value: function setDefaults() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - $.extend(DEFAULTS, LANGUAGES[options.language], $.isPlainObject(options) && options); } }]); @@ -1484,12 +1410,11 @@ var AnotherDatepicker = $.fn.datepicker; $.fn.datepicker = function jQueryDatepicker(option) { - for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + 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 = void 0; - + var result; this.each(function (i, element) { var $element = $(element); var isDestroy = option === 'destroy'; @@ -1501,7 +1426,6 @@ } var options = $.extend({}, $element.data(), $.isPlainObject(option) && option); - datepicker = new Datepicker(element, options); $element.data(NAMESPACE, datepicker); } @@ -1518,13 +1442,13 @@ } } }); - return !isUndefined(result) ? result : this; }; $.fn.datepicker.Constructor = Datepicker; $.fn.datepicker.languages = LANGUAGES; $.fn.datepicker.setDefaults = Datepicker.setDefaults; + $.fn.datepicker.noConflict = function noConflict() { $.fn.datepicker = AnotherDatepicker; return this; diff --git a/dist/datepicker.min.css b/dist/datepicker.min.css index 4b3c2bb..bf893ec 100644 --- a/dist/datepicker.min.css +++ b/dist/datepicker.min.css @@ -1,9 +1,9 @@ /*! - * Datepicker v1.0.0 + * Datepicker v1.0.1 * https://fengyuanchen.github.io/datepicker * * Copyright 2014-present Chen Fengyuan * Released under the MIT license * - * Date: 2018-08-05T03:02:13.513Z - */.datepicker-container{-moz-user-select:none;-ms-touch-action:none;-ms-user-select:none;-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none;-webkit-user-select:none;background-color:#fff;direction:ltr;font-size:12px;left:0;line-height:30px;position:fixed;top:0;touch-action:none;user-select:none;width:210px;z-index:-1}.datepicker-container:after,.datepicker-container:before{border:5px solid rgba(0,0,0,0);content:" ";display:block;height:0;position:absolute;width:0}.datepicker-dropdown{-webkit-box-shadow:0 3px 6px #ccc;-webkit-box-sizing:content-box;border:1px solid #ccc;box-shadow:0 3px 6px #ccc;box-sizing:content-box;position:absolute;z-index:1}.datepicker-inline{position:static}.datepicker-top-left,.datepicker-top-right{border-top-color:#39f}.datepicker-top-left:after,.datepicker-top-left:before,.datepicker-top-right:after,.datepicker-top-right:before{border-top:0;left:10px;top:-5px}.datepicker-top-left:before,.datepicker-top-right:before{border-bottom-color:#39f}.datepicker-top-left:after,.datepicker-top-right:after{border-bottom-color:#fff;top:-4px}.datepicker-bottom-left,.datepicker-bottom-right{border-bottom-color:#39f}.datepicker-bottom-left:after,.datepicker-bottom-left:before,.datepicker-bottom-right:after,.datepicker-bottom-right:before{border-bottom:0;bottom:-5px;left:10px}.datepicker-bottom-left:before,.datepicker-bottom-right:before{border-top-color:#39f}.datepicker-bottom-left:after,.datepicker-bottom-right:after{border-top-color:#fff;bottom:-4px}.datepicker-bottom-right:after,.datepicker-bottom-right:before,.datepicker-top-right:after,.datepicker-top-right:before{left:auto;right:10px}.datepicker-panel>ul{margin:0;padding:0;width:102%}.datepicker-panel>ul:after,.datepicker-panel>ul:before{content:" ";display:table}.datepicker-panel>ul:after{clear:both}.datepicker-panel>ul>li{background-color:#fff;cursor:pointer;float:left;height:30px;list-style:none;margin:0;padding:0;text-align:center;width:30px}.datepicker-panel>ul>li:hover{background-color:#e5f2ff}.datepicker-panel>ul>li.muted,.datepicker-panel>ul>li.muted:hover{color:#999}.datepicker-panel>ul>li.highlighted{background-color:#e5f2ff}.datepicker-panel>ul>li.highlighted:hover{background-color:#cce5ff}.datepicker-panel>ul>li.picked,.datepicker-panel>ul>li.picked:hover{color:#39f}.datepicker-panel>ul>li.disabled,.datepicker-panel>ul>li.disabled:hover{background-color:#fff;color:#ccc;cursor:default}.datepicker-panel>ul>li.disabled.highlighted,.datepicker-panel>ul>li.disabled:hover.highlighted{background-color:#e5f2ff}.datepicker-panel>ul>li[data-view="month next"],.datepicker-panel>ul>li[data-view="month prev"],.datepicker-panel>ul>li[data-view="year next"],.datepicker-panel>ul>li[data-view="year prev"],.datepicker-panel>ul>li[data-view="years next"],.datepicker-panel>ul>li[data-view="years prev"],.datepicker-panel>ul>li[data-view=next]{font-size:18px}.datepicker-panel>ul>li[data-view="month current"],.datepicker-panel>ul>li[data-view="year current"],.datepicker-panel>ul>li[data-view="years current"]{width:150px}.datepicker-panel>ul[data-view=months]>li,.datepicker-panel>ul[data-view=years]>li{height:52.5px;line-height:52.5px;width:52.5px}.datepicker-panel>ul[data-view=week]>li,.datepicker-panel>ul[data-view=week]>li:hover{background-color:#fff;cursor:default}.datepicker-hide{display:none} \ No newline at end of file + * Date: 2018-11-14T13:59:44.094Z + */.datepicker-container{background-color:#fff;direction:ltr;font-size:12px;left:0;line-height:30px;position:fixed;top:0;-ms-touch-action:none;touch-action:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;width:210px;z-index:-1;-webkit-tap-highlight-color:transparent;-webkit-touch-callout:none}.datepicker-container:after,.datepicker-container:before{border:5px solid rgba(0,0,0,0);content:" ";display:block;height:0;position:absolute;width:0}.datepicker-dropdown{border:1px solid #ccc;-webkit-box-shadow:0 3px 6px #ccc;box-shadow:0 3px 6px #ccc;-webkit-box-sizing:content-box;box-sizing:content-box;position:absolute;z-index:1}.datepicker-inline{position:static}.datepicker-top-left,.datepicker-top-right{border-top-color:#39f}.datepicker-top-left:after,.datepicker-top-left:before,.datepicker-top-right:after,.datepicker-top-right:before{border-top:0;left:10px;top:-5px}.datepicker-top-left:before,.datepicker-top-right:before{border-bottom-color:#39f}.datepicker-top-left:after,.datepicker-top-right:after{border-bottom-color:#fff;top:-4px}.datepicker-bottom-left,.datepicker-bottom-right{border-bottom-color:#39f}.datepicker-bottom-left:after,.datepicker-bottom-left:before,.datepicker-bottom-right:after,.datepicker-bottom-right:before{border-bottom:0;bottom:-5px;left:10px}.datepicker-bottom-left:before,.datepicker-bottom-right:before{border-top-color:#39f}.datepicker-bottom-left:after,.datepicker-bottom-right:after{border-top-color:#fff;bottom:-4px}.datepicker-bottom-right:after,.datepicker-bottom-right:before,.datepicker-top-right:after,.datepicker-top-right:before{left:auto;right:10px}.datepicker-panel>ul{margin:0;padding:0;width:102%}.datepicker-panel>ul:after,.datepicker-panel>ul:before{content:" ";display:table}.datepicker-panel>ul:after{clear:both}.datepicker-panel>ul>li{background-color:#fff;cursor:pointer;float:left;height:30px;list-style:none;margin:0;padding:0;text-align:center;width:30px}.datepicker-panel>ul>li:hover{background-color:#e5f2ff}.datepicker-panel>ul>li.muted,.datepicker-panel>ul>li.muted:hover{color:#999}.datepicker-panel>ul>li.highlighted{background-color:#e5f2ff}.datepicker-panel>ul>li.highlighted:hover{background-color:#cce5ff}.datepicker-panel>ul>li.picked,.datepicker-panel>ul>li.picked:hover{color:#39f}.datepicker-panel>ul>li.disabled,.datepicker-panel>ul>li.disabled:hover{background-color:#fff;color:#ccc;cursor:default}.datepicker-panel>ul>li.disabled.highlighted,.datepicker-panel>ul>li.disabled:hover.highlighted{background-color:#e5f2ff}.datepicker-panel>ul>li[data-view="month next"],.datepicker-panel>ul>li[data-view="month prev"],.datepicker-panel>ul>li[data-view="year next"],.datepicker-panel>ul>li[data-view="year prev"],.datepicker-panel>ul>li[data-view="years next"],.datepicker-panel>ul>li[data-view="years prev"],.datepicker-panel>ul>li[data-view=next]{font-size:18px}.datepicker-panel>ul>li[data-view="month current"],.datepicker-panel>ul>li[data-view="year current"],.datepicker-panel>ul>li[data-view="years current"]{width:150px}.datepicker-panel>ul[data-view=months]>li,.datepicker-panel>ul[data-view=years]>li{height:52.5px;line-height:52.5px;width:52.5px}.datepicker-panel>ul[data-view=week]>li,.datepicker-panel>ul[data-view=week]>li:hover{background-color:#fff;cursor:default}.datepicker-hide{display:none} \ No newline at end of file diff --git a/dist/datepicker.min.js b/dist/datepicker.min.js index ddf2638..aa56b8d 100644 --- a/dist/datepicker.min.js +++ b/dist/datepicker.min.js @@ -1,10 +1,10 @@ /*! - * Datepicker v1.0.0 + * Datepicker v1.0.1 * https://fengyuanchen.github.io/datepicker * * Copyright 2014-present Chen Fengyuan * Released under the MIT license * - * Date: 2018-08-05T03:02:19.812Z + * Date: 2018-11-14T13:59:48.051Z */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],t):t(e.jQuery)}(this,function(D){"use strict";D=D&&D.hasOwnProperty("default")?D.default:D;var a={autoShow:!1,autoHide:!1,autoPick:!1,inline:!1,container:null,trigger:null,language:"",format:"mm/dd/yyyy",date:null,startDate:null,endDate:null,startView:0,weekStart:0,yearFirst:!1,yearSuffix:"",days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],daysShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],daysMin:["Su","Mo","Tu","We","Th","Fr","Sa"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],monthsShort:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],itemTag:"li",mutedClass:"muted",pickedClass:"picked",disabledClass:"disabled",highlightedClass:"highlighted",template:'
',offset:10,zIndex:1e3,filter:null,show:null,hide:null,pick:null},e="undefined"!=typeof window?window:{},d="datepicker",s="click."+d,n="focus."+d,r="hide."+d,h="keyup."+d,o="pick."+d,t="resize."+d,l="show."+d,u=d+"-hide",c={},p=0,f=1,g=2,i=Object.prototype.toString;function y(e){return"string"==typeof e}var v=Number.isNaN||e.isNaN;function m(e){return"number"==typeof e&&!v(e)}function w(e){return void 0===e}function k(e){return"date"===(t=e,i.call(t).slice(8,-1).toLowerCase());var t}function b(a,s){for(var e=arguments.length,n=Array(2i.getFullYear(),6===c&&(u=f)),!f&&s&&(f=!1===s.call(this.$element,p,"year"));var g=r+c===o,y=g?"year picked":"year";l.push(this.createItem({picked:g,disabled:f,text:r+c,view:f?"year disabled":y,highlighted:p.getFullYear()===h}))}this.$yearsPrev.toggleClass(a,d),this.$yearsNext.toggleClass(a,u),this.$yearsCurrent.toggleClass(a,!0).html(r+-5+n+" - "+(r+6)+n),this.$years.html(l.join(""))},renderMonths:function(){var e=this.options,t=this.startDate,i=this.endDate,a=this.viewDate,s=e.disabledClass||"",n=e.monthsShort,r=D.isFunction(e.filter)&&e.filter,h=a.getFullYear(),o=new Date,l=o.getFullYear(),d=o.getMonth(),u=this.date.getFullYear(),c=this.date.getMonth(),p=[],f=!1,g=!1,y=void 0;for(y=0;y<=11;y+=1){var v=new Date(h,y,1),m=!1;t&&(m=(f=v.getFullYear()===t.getFullYear())&&v.getMonth()i.getMonth()),!m&&r&&(m=!1===r.call(this.$element,v,"month"));var w=h===u&&y===c,k=w?"month picked":"month";p.push(this.createItem({disabled:m,picked:w,highlighted:h===l&&v.getMonth()===d,index:y,text:n[y],view:m?"month disabled":k}))}this.$yearPrev.toggleClass(s,f),this.$yearNext.toggleClass(s,g),this.$yearCurrent.toggleClass(s,f&&g).html(h+e.yearSuffix||""),this.$months.html(p.join(""))},renderDays:function(){var e=this.$element,t=this.options,i=this.startDate,a=this.endDate,s=this.viewDate,n=this.date,r=t.disabledClass,h=t.filter,o=t.months,l=t.weekStart,d=t.yearSuffix,u=s.getFullYear(),c=s.getMonth(),p=new Date,f=p.getFullYear(),g=p.getMonth(),y=p.getDate(),v=n.getFullYear(),m=n.getMonth(),w=n.getDate(),k=void 0,D=void 0,b=void 0,C=[],$=u,x=c,F=!1;0===c?($-=1,x=11):x-=1,k=G($,x);var M=new Date(u,c,1);for((b=M.getDay()-parseInt(l,10)%7)<=0&&(b+=7),i&&(F=M.getTime()<=i.getTime()),D=k-(b-1);D<=k;D+=1){var V=new Date($,x,D),Y=!1;i&&(Y=V.getTime()=a.getTime()),D=1;D<=b;D+=1){var j=new Date(T,S,D),q=T===v&&S===m&&D===w,A=!1;a&&(A=j.getTime()>a.getTime()),!A&&h&&(A=!1===h.call(e,j,"day")),I.push(this.createItem({disabled:A,picked:q,highlighted:T===f&&S===g&&j.getDate()===y,muted:!0,text:D,view:"day next"}))}var O=[];for(D=1;D<=k;D+=1){var W=new Date(u,c,D),z=!1;i&&(z=W.getTime()a.getTime()),!z&&h&&(z=!1===h.call(e,W,"day"));var J=u===v&&c===m&&D===w,E=J?"day picked":"day";O.push(this.createItem({disabled:z,picked:J,highlighted:u===f&&c===g&&W.getDate()===y,text:D,view:z?"day disabled":E}))}this.$monthPrev.toggleClass(r,F),this.$monthNext.toggleClass(r,P),this.$monthCurrent.toggleClass(r,F&&P).html(t.yearFirst?u+d+" "+o[c]:o[c]+" "+u+d),this.$days.html(C.join("")+O.join("")+I.join(""))}},I=function(){function a(e,t){for(var i=0;ia.getTime()&&(s=new Date(a)),this.endDate=a),this.date=s,this.viewDate=new Date(s),this.initialDate=new Date(this.date),this.bind(),(t.autoShow||this.inline)&&this.show(),t.autoPick&&this.pick()}},{key:"build",value:function(){if(!this.built){this.built=!0;var e=this.$element,t=this.options,i=D(t.template);this.$picker=i,this.$week=i.find(C("week")),this.$yearsPicker=i.find(C("years picker")),this.$yearsPrev=i.find(C("years prev")),this.$yearsNext=i.find(C("years next")),this.$yearsCurrent=i.find(C("years current")),this.$years=i.find(C("years")),this.$monthsPicker=i.find(C("months picker")),this.$yearPrev=i.find(C("year prev")),this.$yearNext=i.find(C("year next")),this.$yearCurrent=i.find(C("year current")),this.$months=i.find(C("months")),this.$daysPicker=i.find(C("days picker")),this.$monthPrev=i.find(C("month prev")),this.$monthNext=i.find(C("month next")),this.$monthCurrent=i.find(C("month current")),this.$days=i.find(C("days")),this.inline?D(t.container||e).append(i.addClass(d+"-inline")):(D(document.body).append(i.addClass(d+"-dropdown")),i.addClass(u)),this.renderWeek()}}},{key:"unbuild",value:function(){this.built&&(this.built=!1,this.$picker.remove())}},{key:"bind",value:function(){var e=this.options,t=this.$element;D.isFunction(e.show)&&t.on(l,e.show),D.isFunction(e.hide)&&t.on(r,e.hide),D.isFunction(e.pick)&&t.on(o,e.pick),this.isInput&&t.on(h,D.proxy(this.keyup,this)),this.inline||(e.trigger?this.$trigger.on(s,D.proxy(this.toggle,this)):this.isInput?t.on(n,D.proxy(this.show,this)):t.on(s,D.proxy(this.show,this)))}},{key:"unbind",value:function(){var e=this.$element,t=this.options;D.isFunction(t.show)&&e.off(l,t.show),D.isFunction(t.hide)&&e.off(r,t.hide),D.isFunction(t.pick)&&e.off(o,t.pick),this.isInput&&e.off(h,this.keyup),this.inline||(t.trigger?this.$trigger.off(s,this.toggle):this.isInput?e.off(n,this.show):e.off(s,this.show))}},{key:"showView",value:function(e){var t=this.$yearsPicker,i=this.$monthsPicker,a=this.$daysPicker,s=this.format;if(s.hasYear||s.hasMonth||s.hasDay)switch(Number(e)){case g:i.addClass(u),a.addClass(u),s.hasYear?(this.renderYears(),t.removeClass(u),this.place()):this.showView(p);break;case f:t.addClass(u),a.addClass(u),s.hasMonth?(this.renderMonths(),i.removeClass(u),this.place()):this.showView(g);break;default:t.addClass(u),i.addClass(u),s.hasDay?(this.renderDays(),a.removeClass(u),this.place()):this.showView(f)}}},{key:"hideView",value:function(){!this.inline&&this.options.autoHide&&this.hide()}},{key:"place",value:function(){if(!this.inline){var e=this.$element,t=this.options,i=this.$picker,a=D(document).outerWidth(),s=D(document).outerHeight(),n=e.outerWidth(),r=e.outerHeight(),h=i.width(),o=i.height(),l=e.offset(),d=l.left,u=l.top,c=parseFloat(t.offset),p=T;v(c)&&(c=10),o'+a.text+""}},{key:"getValue",value:function(){var e=this.$element;return this.isInput?e.val():e.text()}},{key:"setValue",value:function(){var e=0
          ',offset:10,zIndex:1e3,filter:null,show:null,hide:null,pick:null},e="undefined"!=typeof window?window:{},d="datepicker",r="click.".concat(d),h="focus.".concat(d),o="hide.".concat(d),l="keyup.".concat(d),c="pick.".concat(d),t="resize.".concat(d),i="scroll.".concat(d),u="show.".concat(d),p="".concat(d,"-hide"),f={},g=0,y=1,v=2,a=Object.prototype.toString;function m(e){return"string"==typeof e}var w=Number.isNaN||e.isNaN;function k(e){return"number"==typeof e&&!w(e)}function b(e){return void 0===e}function C(e){return"date"===(t=e,a.call(t).slice(8,-1).toLowerCase());var t}function $(a,s){for(var e=arguments.length,n=new Array(2a.getFullYear(),6===e&&(u=f)),!f&&n&&(f=!1===n.call(this.$element,p,"year"));var g=h+e===l,y=g?"year picked":"year";d.push(this.createItem({picked:g,disabled:f,text:h+e,view:f?"year disabled":y,highlighted:p.getFullYear()===o}))}this.$yearsPrev.toggleClass(s,c),this.$yearsNext.toggleClass(s,u),this.$yearsCurrent.toggleClass(s,!0).html("".concat(h+-5+r," - ").concat(h+6).concat(r)),this.$years.html(d.join(""))},renderMonths:function(){var e,t=this.options,i=this.startDate,a=this.endDate,s=this.viewDate,n=t.disabledClass||"",r=t.monthsShort,h=D.isFunction(t.filter)&&t.filter,o=s.getFullYear(),l=new Date,d=l.getFullYear(),c=l.getMonth(),u=this.date.getFullYear(),p=this.date.getMonth(),f=[],g=!1,y=!1;for(e=0;e<=11;e+=1){var v=new Date(o,e,1),m=!1;i&&(m=(g=v.getFullYear()===i.getFullYear())&&v.getMonth()a.getMonth()),!m&&h&&(m=!1===h.call(this.$element,v,"month"));var w=o===u&&e===p,k=w?"month picked":"month";f.push(this.createItem({disabled:m,picked:w,highlighted:o===d&&v.getMonth()===c,index:e,text:r[e],view:m?"month disabled":k}))}this.$yearPrev.toggleClass(n,g),this.$yearNext.toggleClass(n,y),this.$yearCurrent.toggleClass(n,g&&y).html(o+t.yearSuffix||""),this.$months.html(f.join(""))},renderDays:function(){var e,t,i,a=this.$element,s=this.options,n=this.startDate,r=this.endDate,h=this.viewDate,o=this.date,l=s.disabledClass,d=s.filter,c=s.months,u=s.weekStart,p=s.yearSuffix,f=h.getFullYear(),g=h.getMonth(),y=new Date,v=y.getFullYear(),m=y.getMonth(),w=y.getDate(),k=o.getFullYear(),D=o.getMonth(),b=o.getDate(),C=[],$=f,x=g,F=!1;0===g?($-=1,x=11):x-=1,e=G($,x);var M=new Date(f,g,1);for((i=M.getDay()-parseInt(u,10)%7)<=0&&(i+=7),n&&(F=M.getTime()<=n.getTime()),t=e-(i-1);t<=e;t+=1){var V=new Date($,x,t),Y=!1;n&&(Y=V.getTime()=r.getTime()),t=1;t<=i;t+=1){var j=new Date(T,S,t),q=T===k&&S===D&&t===b,A=!1;r&&(A=j.getTime()>r.getTime()),!A&&d&&(A=!1===d.call(a,j,"day")),I.push(this.createItem({disabled:A,picked:q,highlighted:T===v&&S===m&&j.getDate()===w,muted:!0,text:t,view:"day next"}))}var O=[];for(t=1;t<=e;t+=1){var W=new Date(f,g,t),z=!1;n&&(z=W.getTime()r.getTime()),!z&&d&&(z=!1===d.call(a,W,"day"));var J=f===k&&g===D&&t===b,E=J?"day picked":"day";O.push(this.createItem({disabled:z,picked:J,highlighted:f===v&&g===m&&W.getDate()===w,text:t,view:z?"day disabled":E}))}this.$monthPrev.toggleClass(l,F),this.$monthNext.toggleClass(l,P),this.$monthCurrent.toggleClass(l,F&&P).html(s.yearFirst?"".concat(f+p," ").concat(c[g]):"".concat(c[g]," ").concat(f).concat(p)),this.$days.html(C.join("")+O.join("")+I.join(""))}},S="".concat(d,"-top-left"),P="".concat(d,"-top-right"),N="".concat(d,"-bottom-left"),j="".concat(d,"-bottom-right"),q=[S,P,N,j].join(" "),A=function(){function i(e){var t=1a.getTime()&&(s=new Date(a)),this.endDate=a),this.date=s,this.viewDate=new Date(s),this.initialDate=new Date(this.date),this.bind(),(t.autoShow||this.inline)&&this.show(),t.autoPick&&this.pick()}},{key:"build",value:function(){if(!this.built){this.built=!0;var e=this.$element,t=this.options,i=D(t.template);this.$picker=i,this.$week=i.find(x("week")),this.$yearsPicker=i.find(x("years picker")),this.$yearsPrev=i.find(x("years prev")),this.$yearsNext=i.find(x("years next")),this.$yearsCurrent=i.find(x("years current")),this.$years=i.find(x("years")),this.$monthsPicker=i.find(x("months picker")),this.$yearPrev=i.find(x("year prev")),this.$yearNext=i.find(x("year next")),this.$yearCurrent=i.find(x("year current")),this.$months=i.find(x("months")),this.$daysPicker=i.find(x("days picker")),this.$monthPrev=i.find(x("month prev")),this.$monthNext=i.find(x("month next")),this.$monthCurrent=i.find(x("month current")),this.$days=i.find(x("days")),this.inline?D(t.container||e).append(i.addClass("".concat(d,"-inline"))):(D(document.body).append(i.addClass("".concat(d,"-dropdown"))),i.addClass(p).css({zIndex:parseInt(t.zIndex,10)})),this.renderWeek()}}},{key:"unbuild",value:function(){this.built&&(this.built=!1,this.$picker.remove())}},{key:"bind",value:function(){var e=this.options,t=this.$element;D.isFunction(e.show)&&t.on(u,e.show),D.isFunction(e.hide)&&t.on(o,e.hide),D.isFunction(e.pick)&&t.on(c,e.pick),this.isInput&&t.on(l,D.proxy(this.keyup,this)),this.inline||(e.trigger?this.$trigger.on(r,D.proxy(this.toggle,this)):this.isInput?t.on(h,D.proxy(this.show,this)):t.on(r,D.proxy(this.show,this)))}},{key:"unbind",value:function(){var e=this.$element,t=this.options;D.isFunction(t.show)&&e.off(u,t.show),D.isFunction(t.hide)&&e.off(o,t.hide),D.isFunction(t.pick)&&e.off(c,t.pick),this.isInput&&e.off(l,this.keyup),this.inline||(t.trigger?this.$trigger.off(r,this.toggle):this.isInput?e.off(h,this.show):e.off(r,this.show))}},{key:"showView",value:function(e){var t=this.$yearsPicker,i=this.$monthsPicker,a=this.$daysPicker,s=this.format;if(s.hasYear||s.hasMonth||s.hasDay)switch(Number(e)){case v:i.addClass(p),a.addClass(p),s.hasYear?(this.renderYears(),t.removeClass(p),this.place()):this.showView(g);break;case y:t.addClass(p),a.addClass(p),s.hasMonth?(this.renderMonths(),i.removeClass(p),this.place()):this.showView(v);break;default:t.addClass(p),i.addClass(p),s.hasDay?(this.renderDays(),a.removeClass(p),this.place()):this.showView(y)}}},{key:"hideView",value:function(){!this.inline&&this.options.autoHide&&this.hide()}},{key:"place",value:function(){if(!this.inline){var e=this.$element,t=this.options,i=this.$picker,a=D(document).outerWidth(),s=D(document).outerHeight(),n=e.outerWidth(),r=e.outerHeight(),h=i.width(),o=i.height(),l=e.offset(),d=l.left,c=l.top,u=parseFloat(t.offset),p=S;w(u)&&(u=10),o').concat(a.text,"")}},{key:"getValue",value:function(){var e=this.$element;return this.isInput?e.val():e.text()}},{key:"setValue",value:function(){var e=0 Datepicker - + @@ -45,7 +45,7 @@
          -

          Datepicker v1.0.0

          +

          Datepicker v1.0.1

          A simple jQuery datepicker plugin.

          @@ -303,7 +303,7 @@ - + diff --git a/docs/js/datepicker.js b/docs/js/datepicker.js index a4b85c6..c3d5936 100644 --- a/docs/js/datepicker.js +++ b/docs/js/datepicker.js @@ -1,11 +1,11 @@ /*! - * Datepicker v1.0.0 + * Datepicker v1.0.1 * https://fengyuanchen.github.io/datepicker * * Copyright 2014-present Chen Fengyuan * Released under the MIT license * - * Date: 2018-08-05T03:02:19.812Z + * Date: 2018-11-14T13:59:48.051Z */ (function (global, factory) { @@ -16,96 +16,90 @@ $ = $ && $.hasOwnProperty('default') ? $['default'] : $; + 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 - + 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: '
          ' + '
          ' + '
            ' + '
          • ' + '
          • ' + '
          • ' + '
          ' + '
            ' + '
            ' + '
            ' + '
              ' + '
            • ' + '
            • ' + '
            • ' + '
            ' + '
              ' + '
              ' + '
              ' + '
                ' + '
              • ' + '
              • ' + '
              • ' + '
              ' + '
                ' + '
                  ' + '
                  ' + '
                  ', - // 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, @@ -114,14 +108,15 @@ var WINDOW = typeof window !== 'undefined' ? window : {}; var NAMESPACE = 'datepicker'; - var EVENT_CLICK = 'click.' + NAMESPACE; - var EVENT_FOCUS = 'focus.' + NAMESPACE; - var EVENT_HIDE = 'hide.' + NAMESPACE; - var EVENT_KEYUP = 'keyup.' + NAMESPACE; - var EVENT_PICK = 'pick.' + NAMESPACE; - var EVENT_RESIZE = 'resize.' + NAMESPACE; - var EVENT_SHOW = 'show.' + NAMESPACE; - var CLASS_HIDE = NAMESPACE + '-hide'; + 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 CLASS_HIDE = "".concat(NAMESPACE, "-hide"); var LANGUAGES = {}; var VIEWS = { DAYS: 0, @@ -130,62 +125,48 @@ }; 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'; } - function proxy(fn, context) { - for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { + 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 = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + 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="' + 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); @@ -198,7 +179,6 @@ source: source, parts: parts }; - $.each(parts, function (i, part) { switch (part) { case 'dd': @@ -219,12 +199,27 @@ default: } }); - return format; } + function getScrollParent(element) { + var includeHidden = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var $element = $(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 = $(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 ? $(element.ownerDocument || document) : scrollParent; + } var REGEXP_DIGITS = /\d+/g; - var methods = { // Show the datepicker show: function show() { @@ -245,14 +240,13 @@ this.showView(this.options.startView); if (!this.inline) { + this.$scrollParent.on(EVENT_SCROLL, $.proxy(this.place, this)); $(window).on(EVENT_RESIZE, this.onResize = proxy(this.place, this)); $(document).on(EVENT_CLICK, this.onGlobalClick = proxy(this.globalClick, this)); $(document).on(EVENT_KEYUP, this.onGlobalKeyup = proxy(this.globalKeyup, this)); this.place(); } }, - - // Hide the datepicker hide: function hide() { if (!this.shown) { @@ -267,6 +261,7 @@ this.$picker.addClass(CLASS_HIDE).off(EVENT_CLICK, this.click); if (!this.inline) { + this.$scrollParent.off(EVENT_SCROLL, this.place); $(window).off(EVENT_RESIZE, this.onResize); $(document).off(EVENT_CLICK, this.onGlobalClick); $(document).off(EVENT_KEYUP, this.onGlobalKeyup); @@ -279,8 +274,6 @@ this.show(); } }, - - // Update the datepicker with the current input value update: function update() { var value = this.getValue(); @@ -293,7 +286,6 @@ this.oldValue = value; }, - /** * Pick the current date to the element * @@ -303,7 +295,6 @@ var $this = this.$element; var date = this.date; - if (this.trigger(EVENT_PICK, { view: _view || '', date: date @@ -319,8 +310,6 @@ $this.trigger('change'); } }, - - // Reset the datepicker reset: function reset() { this.setDate(this.initialDate, true); @@ -331,7 +320,6 @@ } }, - /** * Get the month name with given argument or the current date * @@ -344,7 +332,6 @@ var monthsShort = options.monthsShort; var months = options.months; - if ($.isNumeric(month)) { month = Number(month); } else if (isUndefined(shortForm)) { @@ -358,7 +345,6 @@ return months[isNumber(month) ? month : this.date.getMonth()]; }, - /** * Get the day name with given argument or the current date * @@ -371,7 +357,6 @@ var options = this.options; var days = options.days; - if ($.isNumeric(day)) { day = Number(day); } else { @@ -393,7 +378,6 @@ return days[isNumber(day) ? day : this.date.getDay()]; }, - /** * Get the current date * @@ -402,12 +386,9 @@ */ getDate: function getDate(formatted) { var date = this.date; - - return formatted ? this.formatDate(date) : new Date(date); }, - /** * Set the current date with a new date * @@ -417,7 +398,6 @@ setDate: function setDate(date, _updated) { var filter = this.options.filter; - if (isDate(date) || isString(date)) { date = this.parseDate(date); @@ -438,7 +418,6 @@ } }, - /** * Set the start view date with a new date * @@ -456,7 +435,6 @@ } }, - /** * Set the end view date with a new date * @@ -474,7 +452,6 @@ } }, - /** * Parse a date string with the set date format * @@ -483,7 +460,6 @@ */ parseDate: function parseDate(date) { var format = this.format; - var parts = []; if (isDate(date)) { @@ -495,9 +471,7 @@ } date = new Date(); - var length = format.parts.length; - var year = date.getFullYear(); var day = date.getDate(); var month = date.getMonth(); @@ -533,7 +507,6 @@ return new Date(year, month, day); }, - /** * Format a date object to a string with the set date format * @@ -542,7 +515,6 @@ */ formatDate: function formatDate(date) { var format = this.format; - var formatted = ''; if (isDate(date)) { @@ -553,7 +525,6 @@ yy: year.toString().substring(2), yyyy: year }; - values.dd = (values.d < 10 ? '0' : '') + values.d; values.mm = (values.m < 10 ? '0' : '') + values.m; formatted = format.source; @@ -564,8 +535,6 @@ return formatted; }, - - // Destroy the datepicker and remove the instance from the target element destroy: function destroy() { this.unbind(); @@ -580,8 +549,6 @@ var options = this.options, viewDate = this.viewDate, format = this.format; - - e.stopPropagation(); e.preventDefault(); @@ -728,7 +695,6 @@ var target = _ref.target; var element = this.element, $trigger = this.$trigger; - var trigger = $trigger[0]; var hidden = true; @@ -769,11 +735,9 @@ var _this = this; var items = []; - var _options = this.options, - weekStart = _options.weekStart, - daysMin = _options.daysMin; - - + 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)); $.each(daysMin, function (i, day) { @@ -781,7 +745,6 @@ text: day })); }); - this.$week.html(items.join('')); }, renderYears: function renderYears() { @@ -791,7 +754,6 @@ var disabledClass = options.disabledClass, filter = options.filter, yearSuffix = options.yearSuffix; - var viewYear = this.viewDate.getFullYear(); var now = new Date(); var thisYear = now.getFullYear(); @@ -801,7 +763,7 @@ var items = []; var prevDisabled = false; var nextDisabled = false; - var i = void 0; + var i; for (i = start; i <= end; i += 1) { var date = new Date(viewYear + i, 1, 1); @@ -829,7 +791,6 @@ var picked = viewYear + i === year; var view = picked ? 'year picked' : 'year'; - items.push(this.createItem({ picked: picked, disabled: disabled, @@ -841,7 +802,7 @@ this.$yearsPrev.toggleClass(disabledClass, prevDisabled); this.$yearsNext.toggleClass(disabledClass, nextDisabled); - this.$yearsCurrent.toggleClass(disabledClass, true).html(viewYear + start + yearSuffix + ' - ' + (viewYear + end) + yearSuffix); + this.$yearsCurrent.toggleClass(disabledClass, true).html("".concat(viewYear + start + yearSuffix, " - ").concat(viewYear + end).concat(yearSuffix)); this.$years.html(items.join('')); }, renderMonths: function renderMonths() { @@ -849,7 +810,6 @@ startDate = this.startDate, endDate = this.endDate, viewDate = this.viewDate; - var disabledClass = options.disabledClass || ''; var months = options.monthsShort; var filter = $.isFunction(options.filter) && options.filter; @@ -862,7 +822,7 @@ var items = []; var prevDisabled = false; var nextDisabled = false; - var i = void 0; + var i; for (i = 0; i <= 11; i += 1) { var date = new Date(viewYear, i, 1); @@ -884,7 +844,6 @@ var picked = viewYear === year && i === month; var view = picked ? 'month picked' : 'month'; - items.push(this.createItem({ disabled: disabled, picked: picked, @@ -912,7 +871,6 @@ months = options.months, weekStart = options.weekStart, yearSuffix = options.yearSuffix; - var viewYear = viewDate.getFullYear(); var viewMonth = viewDate.getMonth(); var now = new Date(); @@ -922,11 +880,9 @@ var year = currentDate.getFullYear(); var month = currentDate.getMonth(); var day = currentDate.getDate(); - var length = void 0; - var i = void 0; - var n = void 0; - - // Days of prev month + var length; + var i; + var n; // Days of prev month // ----------------------------------------------------------------------- var prevItems = []; @@ -939,19 +895,16 @@ prevViewMonth = 11; } else { prevViewMonth -= 1; - } + } // The length of the days of prev month - // 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); + length = getDaysInMonth(prevViewYear, prevViewMonth); // The first day of current month - // The visible length of the days of prev 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] + 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; } @@ -980,11 +933,10 @@ text: i, view: 'day prev' })); - } - - // Days of next month + } // Days of next month // ----------------------------------------------------------------------- + var nextItems = []; var nextViewYear = viewYear; var nextViewMonth = viewMonth; @@ -995,15 +947,13 @@ nextViewMonth = 0; } else { nextViewMonth += 1; - } + } // The length of the days of current month + - // The length of the days of current month - length = getDaysInMonth(viewYear, viewMonth); + length = getDaysInMonth(viewYear, viewMonth); // The visible length of next month (42 means 6 rows and 7 columns) - // The visible length of next month (42 means 6 rows and 7 columns) - n = 42 - (prevItems.length + length); + n = 42 - (prevItems.length + length); // The last day of current month - // The last day of current month var lastDate = new Date(viewYear, viewMonth, length); if (endDate) { @@ -1031,15 +981,15 @@ text: i, view: 'day next' })); - } - - // Days of current month + } // 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) { @@ -1055,8 +1005,8 @@ } var _picked = viewYear === year && viewMonth === month && i === day; - var view = _picked ? 'day picked' : 'day'; + var view = _picked ? 'day picked' : 'day'; items.push(this.createItem({ disabled: _disabled2, picked: _picked, @@ -1064,30 +1014,26 @@ text: i, view: _disabled2 ? 'day disabled' : view })); - } - - // Render days picker + } // Render days picker // ----------------------------------------------------------------------- + this.$monthPrev.toggleClass(disabledClass, prevDisabled); this.$monthNext.toggleClass(disabledClass, nextDisabled); - this.$monthCurrent.toggleClass(disabledClass, prevDisabled && nextDisabled).html(options.yearFirst ? viewYear + yearSuffix + ' ' + months[viewMonth] : months[viewMonth] + ' ' + viewYear + yearSuffix); + 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 _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - - function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - - // Classes - var CLASS_TOP_LEFT = NAMESPACE + '-top-left'; - var CLASS_TOP_RIGHT = NAMESPACE + '-top-right'; - var CLASS_BOTTOM_LEFT = NAMESPACE + '-bottom-left'; - var CLASS_BOTTOM_RIGHT = NAMESPACE + '-bottom-right'; + 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 = function () { + var Datepicker = + /*#__PURE__*/ + function () { function Datepicker(element) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; @@ -1096,6 +1042,7 @@ this.$element = $(element); this.element = element; this.options = $.extend({}, DEFAULTS, LANGUAGES[options.language], $.isPlainObject(options) && options); + this.$scrollParent = getScrollParent(element, true); this.built = false; this.shown = false; this.isInput = false; @@ -1108,22 +1055,18 @@ } _createClass(Datepicker, [{ - key: 'init', + key: "init", value: function init() { var $this = this.$element, options = this.options; var startDate = options.startDate, endDate = options.endDate, date = options.date; - - this.$trigger = $(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); @@ -1166,37 +1109,31 @@ } } }, { - key: 'build', + key: "build", value: function build() { if (this.built) { return; } this.built = true; - var $this = this.$element, options = this.options; - var $picker = $(options.template); - this.$picker = $picker; - this.$week = $picker.find(selectorOf('week')); + this.$week = $picker.find(selectorOf('week')); // Years view - // 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')); + this.$years = $picker.find(selectorOf('years')); // Months view - // 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')); + this.$months = $picker.find(selectorOf('months')); // Days view - // Days view this.$daysPicker = $picker.find(selectorOf('days picker')); this.$monthPrev = $picker.find(selectorOf('month prev')); this.$monthNext = $picker.find(selectorOf('month next')); @@ -1204,16 +1141,18 @@ this.$days = $picker.find(selectorOf('days')); if (this.inline) { - $(options.container || $this).append($picker.addClass(NAMESPACE + '-inline')); + $(options.container || $this).append($picker.addClass("".concat(NAMESPACE, "-inline"))); } else { - $(document.body).append($picker.addClass(NAMESPACE + '-dropdown')); - $picker.addClass(CLASS_HIDE); + $(document.body).append($picker.addClass("".concat(NAMESPACE, "-dropdown"))); + $picker.addClass(CLASS_HIDE).css({ + zIndex: parseInt(options.zIndex, 10) + }); } this.renderWeek(); } }, { - key: 'unbuild', + key: "unbuild", value: function unbuild() { if (!this.built) { return; @@ -1223,12 +1162,11 @@ this.$picker.remove(); } }, { - key: 'bind', + key: "bind", value: function bind() { var options = this.options, $this = this.$element; - if ($.isFunction(options.show)) { $this.on(EVENT_SHOW, options.show); } @@ -1256,12 +1194,11 @@ } } }, { - key: 'unbind', + key: "unbind", value: function unbind() { var $this = this.$element, options = this.options; - if ($.isFunction(options.show)) { $this.off(EVENT_SHOW, options.show); } @@ -1289,14 +1226,13 @@ } } }, { - key: 'showView', + 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: @@ -1326,8 +1262,8 @@ } break; - // case VIEWS.DAYS: + default: $yearsPicker.addClass(CLASS_HIDE); $monthsPicker.addClass(CLASS_HIDE); @@ -1339,18 +1275,19 @@ } else { this.showView(VIEWS.MONTHS); } + } } } }, { - key: 'hideView', + key: "hideView", value: function hideView() { if (!this.inline && this.options.autoHide) { this.hide(); } } }, { - key: 'place', + key: "place", value: function place() { if (this.inline) { return; @@ -1359,7 +1296,6 @@ var $this = this.$element, options = this.options, $picker = this.$picker; - var containerWidth = $(document).outerWidth(); var containerHeight = $(document).outerHeight(); var elementWidth = $this.outerWidth(); @@ -1392,28 +1328,22 @@ $picker.removeClass(CLASS_PLACEMENTS).addClass(placement).css({ top: top, - left: left, - zIndex: parseInt(options.zIndex, 10) + left: left }); - } - - // A shortcut for triggering custom events + } // A shortcut for triggering custom events }, { - key: 'trigger', + key: "trigger", value: function trigger(type, data) { var e = $.Event(type, data); - this.$element.trigger(e); - return e; } }, { - key: 'createItem', + key: "createItem", value: function createItem(data) { var options = this.options; var itemTag = options.itemTag; - var item = { text: '', view: '', @@ -1423,7 +1353,6 @@ highlighted: false }; var classes = []; - $.extend(item, data); if (item.muted) { @@ -1442,33 +1371,30 @@ classes.push(options.disabledClass); } - return '<' + itemTag + ' class="' + classes.join(' ') + '" data-view="' + item.view + '">' + item.text + ''; + return "<".concat(itemTag, " class=\"").concat(classes.join(' '), "\" data-view=\"").concat(item.view, "\">").concat(item.text, ""); } }, { - key: 'getValue', + key: "getValue", value: function getValue() { var $this = this.$element; - return this.isInput ? $this.val() : $this.text(); } }, { - key: 'setValue', + 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 { + } else if (!this.inline || this.options.container) { $this.text(value); } } }], [{ - key: 'setDefaults', + key: "setDefaults", value: function setDefaults() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - $.extend(DEFAULTS, LANGUAGES[options.language], $.isPlainObject(options) && options); } }]); @@ -1484,12 +1410,11 @@ var AnotherDatepicker = $.fn.datepicker; $.fn.datepicker = function jQueryDatepicker(option) { - for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + 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 = void 0; - + var result; this.each(function (i, element) { var $element = $(element); var isDestroy = option === 'destroy'; @@ -1501,7 +1426,6 @@ } var options = $.extend({}, $element.data(), $.isPlainObject(option) && option); - datepicker = new Datepicker(element, options); $element.data(NAMESPACE, datepicker); } @@ -1518,13 +1442,13 @@ } } }); - return !isUndefined(result) ? result : this; }; $.fn.datepicker.Constructor = Datepicker; $.fn.datepicker.languages = LANGUAGES; $.fn.datepicker.setDefaults = Datepicker.setDefaults; + $.fn.datepicker.noConflict = function noConflict() { $.fn.datepicker = AnotherDatepicker; return this; diff --git a/package-lock.json b/package-lock.json index 59bf4dd..b119db1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@chenfengyuan/datepicker", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -14,62 +14,111 @@ } }, "@babel/core": { - "version": "7.1.5", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.1.5.tgz", - "integrity": "sha512-vOyH020C56tQvte++i+rX2yokZcRfbv/kKcw+/BCRw/cK6dvsr47aCzm8oC1XHwMSEWbqrZKzZRLzLnq6SFMsg==", + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.1.6.tgz", + "integrity": "sha512-Hz6PJT6e44iUNpAn8AoyAs6B3bl60g7MJQaI0rZEar6ECzh6+srYO1xlIdssio34mPaUtAb1y+XlkkSJzok3yw==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", - "@babel/generator": "^7.1.5", + "@babel/generator": "^7.1.6", "@babel/helpers": "^7.1.5", - "@babel/parser": "^7.1.5", + "@babel/parser": "^7.1.6", "@babel/template": "^7.1.2", - "@babel/traverse": "^7.1.5", - "@babel/types": "^7.1.5", + "@babel/traverse": "^7.1.6", + "@babel/types": "^7.1.6", "convert-source-map": "^1.1.0", - "debug": "^3.1.0", - "json5": "^0.5.0", + "debug": "^4.1.0", + "json5": "^2.1.0", "lodash": "^4.17.10", "resolve": "^1.3.2", "semver": "^5.4.1", "source-map": "^0.5.0" }, "dependencies": { + "@babel/types": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.1.6.tgz", + "integrity": "sha512-DMiUzlY9DSjVsOylJssxLHSgj6tWM9PRFJOGW/RaOglVOK9nzTxoOMfTfRQXGUCUQ/HmlG2efwC+XqUEJ5ay4w==", + "dev": true, + "requires": { + "esutils": "^2.0.2", + "lodash": "^4.17.10", + "to-fast-properties": "^2.0.0" + } + }, "debug": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", - "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.0.tgz", + "integrity": "sha512-heNPJUJIqC+xB6ayLAMHaIrmN9HKa7aQO8MGqKpvCA+uJYVcvR6l5kgdrhRuwPFHU7P5/A1w0BjByPHwpfTDKg==", "dev": true, "requires": { "ms": "^2.1.1" } }, + "json5": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.1.0.tgz", + "integrity": "sha512-8Mh9h6xViijj36g7Dxi+Y4S6hNGV96vcJZr/SrlHh1LR/pEn/8j/+qIBbs44YKl69Lrfctp4QD+AdWLTMqEZAQ==", + "dev": true, + "requires": { + "minimist": "^1.2.0" + } + }, + "minimist": { + "version": "1.2.0", + "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "dev": true + }, "ms": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", "dev": true + }, + "to-fast-properties": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", + "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", + "dev": true } } }, "@babel/generator": { - "version": "7.1.5", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.1.5.tgz", - "integrity": "sha512-IO31r62xfMI+wBJVmgx0JR9ZOHty8HkoYpQAjRWUGG9vykBTlGHdArZ8zoFtpUu2gs17K7qTl/TtPpiSi6t+MA==", + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.1.6.tgz", + "integrity": "sha512-brwPBtVvdYdGxtenbQgfCdDPmtkmUBZPjUoK5SXJEBuHaA5BCubh9ly65fzXz7R6o5rA76Rs22ES8Z+HCc0YIQ==", "dev": true, "requires": { - "@babel/types": "^7.1.5", + "@babel/types": "^7.1.6", "jsesc": "^2.5.1", "lodash": "^4.17.10", "source-map": "^0.5.0", "trim-right": "^1.0.1" }, "dependencies": { + "@babel/types": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.1.6.tgz", + "integrity": "sha512-DMiUzlY9DSjVsOylJssxLHSgj6tWM9PRFJOGW/RaOglVOK9nzTxoOMfTfRQXGUCUQ/HmlG2efwC+XqUEJ5ay4w==", + "dev": true, + "requires": { + "esutils": "^2.0.2", + "lodash": "^4.17.10", + "to-fast-properties": "^2.0.0" + } + }, "jsesc": { "version": "2.5.2", "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==", "dev": true + }, + "to-fast-properties": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", + "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", + "dev": true } } }, @@ -331,9 +380,9 @@ } }, "@babel/parser": { - "version": "7.1.5", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.1.5.tgz", - "integrity": "sha512-WXKf5K5HT6X0kKiCOezJZFljsfxKV1FpU8Tf1A7ZpGvyd/Q4hlrJm2EwoH2onaUq3O4tLDp+4gk0hHPsMyxmOg==", + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.1.6.tgz", + "integrity": "sha512-dWP6LJm9nKT6ALaa+bnL247GHHMWir3vSlZ2+IHgHgktZQx0L3Uvq2uAWcuzIe+fujRsYWBW2q622C5UvGK9iQ==", "dev": true }, "@babel/plugin-proposal-async-generator-functions": { @@ -386,43 +435,6 @@ "@babel/helper-plugin-utils": "^7.0.0", "@babel/helper-regex": "^7.0.0", "regexpu-core": "^4.2.0" - }, - "dependencies": { - "jsesc": { - "version": "0.5.0", - "resolved": "http://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", - "integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=", - "dev": true - }, - "regexpu-core": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-4.2.0.tgz", - "integrity": "sha512-Z835VSnJJ46CNBttalHD/dB+Sj2ezmY6Xp38npwU87peK6mqOzOpV8eYktdkLTEkzzD+JsTcxd84ozd8I14+rw==", - "dev": true, - "requires": { - "regenerate": "^1.4.0", - "regenerate-unicode-properties": "^7.0.0", - "regjsgen": "^0.4.0", - "regjsparser": "^0.3.0", - "unicode-match-property-ecmascript": "^1.0.4", - "unicode-match-property-value-ecmascript": "^1.0.2" - } - }, - "regjsgen": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/regjsgen/-/regjsgen-0.4.0.tgz", - "integrity": "sha512-X51Lte1gCYUdlwhF28+2YMO0U6WeN0GLpgpA7LK7mbdDnkQYiwvEpmpe0F/cv5L14EbxgrdayAG3JETBv0dbXA==", - "dev": true - }, - "regjsparser": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.3.0.tgz", - "integrity": "sha512-zza72oZBBHzt64G7DxdqrOo/30bhHkwMUoT0WqfGu98XLd7N+1tsy5MJ96Bk4MD0y74n629RhmrGW6XlnLLwCA==", - "dev": true, - "requires": { - "jsesc": "~0.5.0" - } - } } }, "@babel/plugin-syntax-async-generators": { @@ -551,43 +563,6 @@ "@babel/helper-plugin-utils": "^7.0.0", "@babel/helper-regex": "^7.0.0", "regexpu-core": "^4.1.3" - }, - "dependencies": { - "jsesc": { - "version": "0.5.0", - "resolved": "http://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", - "integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=", - "dev": true - }, - "regexpu-core": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-4.2.0.tgz", - "integrity": "sha512-Z835VSnJJ46CNBttalHD/dB+Sj2ezmY6Xp38npwU87peK6mqOzOpV8eYktdkLTEkzzD+JsTcxd84ozd8I14+rw==", - "dev": true, - "requires": { - "regenerate": "^1.4.0", - "regenerate-unicode-properties": "^7.0.0", - "regjsgen": "^0.4.0", - "regjsparser": "^0.3.0", - "unicode-match-property-ecmascript": "^1.0.4", - "unicode-match-property-value-ecmascript": "^1.0.2" - } - }, - "regjsgen": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/regjsgen/-/regjsgen-0.4.0.tgz", - "integrity": "sha512-X51Lte1gCYUdlwhF28+2YMO0U6WeN0GLpgpA7LK7mbdDnkQYiwvEpmpe0F/cv5L14EbxgrdayAG3JETBv0dbXA==", - "dev": true - }, - "regjsparser": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.3.0.tgz", - "integrity": "sha512-zza72oZBBHzt64G7DxdqrOo/30bhHkwMUoT0WqfGu98XLd7N+1tsy5MJ96Bk4MD0y74n629RhmrGW6XlnLLwCA==", - "dev": true, - "requires": { - "jsesc": "~0.5.0" - } - } } }, "@babel/plugin-transform-duplicate-keys": { @@ -715,17 +690,6 @@ "dev": true, "requires": { "regenerator-transform": "^0.13.3" - }, - "dependencies": { - "regenerator-transform": { - "version": "0.13.3", - "resolved": "https://registry.npmjs.org/regenerator-transform/-/regenerator-transform-0.13.3.tgz", - "integrity": "sha512-5ipTrZFSq5vU2YoGoww4uaRVAK4wyYC4TSICibbfEPOruUu8FFP7ErV0BjmbIOEpn3O/k9na9UEdYR/3m7N6uA==", - "dev": true, - "requires": { - "private": "^0.1.6" - } - } } }, "@babel/plugin-transform-shorthand-properties": { @@ -784,49 +748,12 @@ "@babel/helper-plugin-utils": "^7.0.0", "@babel/helper-regex": "^7.0.0", "regexpu-core": "^4.1.3" - }, - "dependencies": { - "jsesc": { - "version": "0.5.0", - "resolved": "http://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", - "integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=", - "dev": true - }, - "regexpu-core": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-4.2.0.tgz", - "integrity": "sha512-Z835VSnJJ46CNBttalHD/dB+Sj2ezmY6Xp38npwU87peK6mqOzOpV8eYktdkLTEkzzD+JsTcxd84ozd8I14+rw==", - "dev": true, - "requires": { - "regenerate": "^1.4.0", - "regenerate-unicode-properties": "^7.0.0", - "regjsgen": "^0.4.0", - "regjsparser": "^0.3.0", - "unicode-match-property-ecmascript": "^1.0.4", - "unicode-match-property-value-ecmascript": "^1.0.2" - } - }, - "regjsgen": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/regjsgen/-/regjsgen-0.4.0.tgz", - "integrity": "sha512-X51Lte1gCYUdlwhF28+2YMO0U6WeN0GLpgpA7LK7mbdDnkQYiwvEpmpe0F/cv5L14EbxgrdayAG3JETBv0dbXA==", - "dev": true - }, - "regjsparser": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.3.0.tgz", - "integrity": "sha512-zza72oZBBHzt64G7DxdqrOo/30bhHkwMUoT0WqfGu98XLd7N+1tsy5MJ96Bk4MD0y74n629RhmrGW6XlnLLwCA==", - "dev": true, - "requires": { - "jsesc": "~0.5.0" - } - } } }, "@babel/preset-env": { - "version": "7.1.5", - "resolved": "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.1.5.tgz", - "integrity": "sha512-pQ+2o0YyCp98XG0ODOHJd9z4GsSoV5jicSedRwCrU8uiqcJahwQiOq0asSZEb/m/lwyu6X5INvH/DSiwnQKncw==", + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.1.6.tgz", + "integrity": "sha512-YIBfpJNQMBkb6MCkjz/A9J76SNCSuGVamOVBgoUkLzpJD/z8ghHi9I42LQ4pulVX68N/MmImz6ZTixt7Azgexw==", "dev": true, "requires": { "@babel/helper-module-imports": "^7.0.0", @@ -870,40 +797,6 @@ "invariant": "^2.2.2", "js-levenshtein": "^1.1.3", "semver": "^5.3.0" - }, - "dependencies": { - "browserslist": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.3.4.tgz", - "integrity": "sha512-u5iz+ijIMUlmV8blX82VGFrB9ecnUg5qEt55CMZ/YJEhha+d8qpBfOFuutJ6F/VKRXjZoD33b6uvarpPxcl3RA==", - "dev": true, - "requires": { - "caniuse-lite": "^1.0.30000899", - "electron-to-chromium": "^1.3.82", - "node-releases": "^1.0.1" - } - }, - "caniuse-lite": { - "version": "1.0.30000907", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000907.tgz", - "integrity": "sha512-No5sQ/OB2Nmka8MNOOM6nJx+Hxt6MQ6h7t7kgJFu9oTuwjykyKRSBP/+i/QAyFHxeHB+ddE0Da1CG5ihx9oehQ==", - "dev": true - }, - "electron-to-chromium": { - "version": "1.3.84", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.84.tgz", - "integrity": "sha512-IYhbzJYOopiTaNWMBp7RjbecUBsbnbDneOP86f3qvS0G0xfzwNSvMJpTrvi5/Y1gU7tg2NAgeg8a8rCYvW9Whw==", - "dev": true - }, - "node-releases": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.0.3.tgz", - "integrity": "sha512-ZaZWMsbuDcetpHmYeKWPO6e63pSXLb50M7lJgCbcM2nC/nQC3daNifmtp5a2kp7EWwYfhuvH6zLPWkrF8IiDdw==", - "dev": true, - "requires": { - "semver": "^5.3.0" - } - } } }, "@babel/template": { @@ -918,26 +811,37 @@ } }, "@babel/traverse": { - "version": "7.1.5", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.1.5.tgz", - "integrity": "sha512-eU6XokWypl0MVJo+MTSPUtlfPePkrqsF26O+l1qFGlCKWwmiYAYy2Sy44Qw8m2u/LbPCsxYt90rghmqhYMGpPA==", + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.1.6.tgz", + "integrity": "sha512-CXedit6GpISz3sC2k2FsGCUpOhUqKdyL0lqNrImQojagnUMXf8hex4AxYFRuMkNGcvJX5QAFGzB5WJQmSv8SiQ==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", - "@babel/generator": "^7.1.5", + "@babel/generator": "^7.1.6", "@babel/helper-function-name": "^7.1.0", "@babel/helper-split-export-declaration": "^7.0.0", - "@babel/parser": "^7.1.5", - "@babel/types": "^7.1.5", - "debug": "^3.1.0", + "@babel/parser": "^7.1.6", + "@babel/types": "^7.1.6", + "debug": "^4.1.0", "globals": "^11.1.0", "lodash": "^4.17.10" }, "dependencies": { + "@babel/types": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.1.6.tgz", + "integrity": "sha512-DMiUzlY9DSjVsOylJssxLHSgj6tWM9PRFJOGW/RaOglVOK9nzTxoOMfTfRQXGUCUQ/HmlG2efwC+XqUEJ5ay4w==", + "dev": true, + "requires": { + "esutils": "^2.0.2", + "lodash": "^4.17.10", + "to-fast-properties": "^2.0.0" + } + }, "debug": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", - "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.0.tgz", + "integrity": "sha512-heNPJUJIqC+xB6ayLAMHaIrmN9HKa7aQO8MGqKpvCA+uJYVcvR6l5kgdrhRuwPFHU7P5/A1w0BjByPHwpfTDKg==", "dev": true, "requires": { "ms": "^2.1.1" @@ -954,6 +858,12 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", "dev": true + }, + "to-fast-properties": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", + "integrity": "sha1-3F5pjL0HkmW8c+A3doGk5Og/YW4=", + "dev": true } } }, @@ -10873,6 +10783,15 @@ "integrity": "sha512-/aA0kLeRb5N9K0d4fw7ooEbI+xDe+DKD499EQqygGqeS8N3xto15p09uY2xj7ixP81sNPXvRLnAQIqdVStgb1A==", "dev": true }, + "regenerator-transform": { + "version": "0.13.3", + "resolved": "https://registry.npmjs.org/regenerator-transform/-/regenerator-transform-0.13.3.tgz", + "integrity": "sha512-5ipTrZFSq5vU2YoGoww4uaRVAK4wyYC4TSICibbfEPOruUu8FFP7ErV0BjmbIOEpn3O/k9na9UEdYR/3m7N6uA==", + "dev": true, + "requires": { + "private": "^0.1.6" + } + }, "regex-cache": { "version": "0.4.4", "resolved": "https://registry.npmjs.org/regex-cache/-/regex-cache-0.4.4.tgz", @@ -10898,6 +10817,20 @@ "integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==", "dev": true }, + "regexpu-core": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-4.2.0.tgz", + "integrity": "sha512-Z835VSnJJ46CNBttalHD/dB+Sj2ezmY6Xp38npwU87peK6mqOzOpV8eYktdkLTEkzzD+JsTcxd84ozd8I14+rw==", + "dev": true, + "requires": { + "regenerate": "^1.4.0", + "regenerate-unicode-properties": "^7.0.0", + "regjsgen": "^0.4.0", + "regjsparser": "^0.3.0", + "unicode-match-property-ecmascript": "^1.0.4", + "unicode-match-property-value-ecmascript": "^1.0.2" + } + }, "registry-auth-token": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/registry-auth-token/-/registry-auth-token-3.3.1.tgz", @@ -10917,6 +10850,29 @@ "rc": "^1.0.1" } }, + "regjsgen": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/regjsgen/-/regjsgen-0.4.0.tgz", + "integrity": "sha512-X51Lte1gCYUdlwhF28+2YMO0U6WeN0GLpgpA7LK7mbdDnkQYiwvEpmpe0F/cv5L14EbxgrdayAG3JETBv0dbXA==", + "dev": true + }, + "regjsparser": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.3.0.tgz", + "integrity": "sha512-zza72oZBBHzt64G7DxdqrOo/30bhHkwMUoT0WqfGu98XLd7N+1tsy5MJ96Bk4MD0y74n629RhmrGW6XlnLLwCA==", + "dev": true, + "requires": { + "jsesc": "~0.5.0" + }, + "dependencies": { + "jsesc": { + "version": "0.5.0", + "resolved": "http://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", + "integrity": "sha1-597mbjXW/Bb3EP6R1c9p9w8IkR0=", + "dev": true + } + } + }, "remove-trailing-separator": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz", diff --git a/package.json b/package.json index c4a71fa..45d55d5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@chenfengyuan/datepicker", "description": "A simple jQuery datepicker plugin.", - "version": "1.0.0", + "version": "1.0.1", "main": "dist/datepicker.common.js", "module": "dist/datepicker.esm.js", "unpkg": "dist/datepicker.js", @@ -49,8 +49,8 @@ "watch:js": "rollup -c -m -w" }, "devDependencies": { - "@babel/core": "^7.1.5", - "@babel/preset-env": "^7.1.5", + "@babel/core": "^7.1.6", + "@babel/preset-env": "^7.1.6", "@commitlint/cli": "^7.2.1", "@commitlint/config-conventional": "^7.1.2", "autoprefixer": "^9.3.1",