diff --git a/dist/css/datepicker.css b/dist/css/datepicker.css index 788c05f..62ef3b7 100644 --- a/dist/css/datepicker.css +++ b/dist/css/datepicker.css @@ -77,6 +77,23 @@ cursor: default; background: none; } +.datepicker--buttons { + display: flex; + margin: 4px 2px; } + +.datepicker--button { + background: #f2f2f2; + cursor: pointer; + border-radius: 2px; + margin: 0 2px; + flex: 1; + display: inline-flex; + justify-content: center; + align-items: center; + height: 24px; } + .datepicker--button:hover { + background: #eaeaea; } + .datepicker--cell-day.-other-month-, .datepicker--cell-year.-other-decade- { color: #ddd; font-size: .9em; } diff --git a/dist/js/datepicker.js b/dist/js/datepicker.js index ec33fc6..a8235dd 100644 --- a/dist/js/datepicker.js +++ b/dist/js/datepicker.js @@ -11,7 +11,7 @@ var Datepicker; defaults = { //TODO сделать работу с инпутом inline: true, - region: 'ru', + language: 'ru', start: '', // Start date firstDay: 1, // Week's first day weekends: [6, 0], @@ -36,6 +36,9 @@ var Datepicker; multipleDates: false, // Boolean or Number multipleDatesSeparator: ',', + todayButton: false, + clearButton: false, + // navigation prevHtml: '«', nextHtml: '»', @@ -57,7 +60,7 @@ var Datepicker; this._buildDatepickersContainer(); } - this.loc = Datepicker.region[this.opts.region]; + this.loc = Datepicker.language[this.opts.language]; if ($body == undefined) { $body = $('body'); @@ -84,9 +87,9 @@ var Datepicker; init: function () { this._buildBaseHtml(); - this.nav = new Datepicker.Navigation(this, this.opts); this.views[this.currentView] = new Datepicker.Body(this, this.currentView, this.opts); this.views[this.currentView].show(); + this.nav = new Datepicker.Navigation(this, this.opts); this.view = this.currentView; this.inited = true; @@ -116,7 +119,7 @@ var Datepicker; }, - _triggerOnChange: function (cellType) { + _triggerOnChange: function () { if (!this.selectedDates.length) { return this.opts.onChange('', '', this); } @@ -187,6 +190,8 @@ var Datepicker; result = result.replace('m',d.month + 1); case /MM/.test(result): result = result.replace('MM', this.loc.months[d.month]); + case /M/.test(result): + result = result.replace('M', this.loc.monthsShort[d.month]); case /yyyy/.test(result): result = result.replace('yyyy', d.year); case /yy/.test(result): @@ -245,6 +250,19 @@ var Datepicker; }) }, + today: function () { + this.silent = true; + this.view = this.opts.minView; + this.silent = false; + this.date = new Date(); + }, + + clear: function () { + this.selectedDates = []; + this.views[this.currentView]._render(); + this._triggerOnChange() + }, + _isSelected: function (checkDate, cellType) { return this.selectedDates.some(function (date) { return Datepicker.isSame(date, checkDate, cellType) @@ -316,6 +334,10 @@ var Datepicker; return this.currentView; }, + get cellType() { + return this.view.substring(0, this.view.length - 1) + }, + get minTime() { var min = Datepicker.getParsedDate(this.minDate); return new Date(min.year, min.month, min.date).getTime() @@ -392,25 +414,31 @@ var Datepicker; }; })(window, jQuery, ''); -;(function () { - Datepicker.region = { - 'ru': { - days: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'], - months: ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'] - } +Datepicker.language = { + ru: { + days: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'], + daysShort: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'], + months: ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'], + monthsShort: ['Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек'], + today: 'Сегодня', + clear: 'Очистить' } -})(); +}; ;(function () { var template = '' + '