diff --git a/dist/js/datepicker.js b/dist/js/datepicker.js index 750ce7b..fe81739 100644 --- a/dist/js/datepicker.js +++ b/dist/js/datepicker.js @@ -62,6 +62,17 @@ years: 'yyyy1 - yyyy2' }, + // timepicker + timepicker: false, + dateTimeSeparator: ' ', + timeFormat: '', + minHours: 0, + maxHours: 24, + minMinutes: 0, + maxMinutes: 59, + hoursStep: 1, + minutesStep: 1, + // events onSelect: '', onChangeMonth: '', @@ -155,11 +166,17 @@ this.$datepicker.addClass(this.opts.classes) } + if (this.opts.timepicker) { + this.timepicker = new Datepicker.Timepicker(this, this.opts); + this._bindTimepickerEvents(); + } + 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.$el.on('clickCell.adp', this._onClickCell.bind(this)); this.$datepicker.on('mouseenter', '.datepicker--cell', this._onMouseEnterCell.bind(this)); this.$datepicker.on('mouseleave', '.datepicker--cell', this._onMouseLeaveCell.bind(this)); @@ -173,9 +190,11 @@ _bindEvents : function () { this.$el.on(this.opts.showEvent + '.adp', this._onShowEvent.bind(this)); + this.$el.on('mouseup.adp', this._onMouseUpEl.bind(this)); this.$el.on('blur.adp', this._onBlur.bind(this)); this.$el.on('input.adp', this._onInput.bind(this)); $(window).on('resize.adp', this._onResize.bind(this)); + $('body').on('mouseup.adp', this._onMouseUpBody.bind(this)); }, _bindKeyboardEvents: function () { @@ -184,6 +203,10 @@ this.$el.on('hotKey.adp', this._onHotKey.bind(this)); }, + _bindTimepickerEvents: function () { + this.$el.on('timeChange.adp', this._onTimeChange.bind(this)); + }, + isWeekend: function (day) { return this.opts.weekends.indexOf(day) !== -1; }, @@ -205,9 +228,24 @@ this.loc.dateFormat = this.opts.dateFormat } + if (this.opts.timeFormat) { + this.loc.timeFormat = this.opts.timeFormat + } + if (this.opts.firstDay !== '') { this.loc.firstDay = this.opts.firstDay } + + if (this.opts.timepicker) { + this.loc.dateFormat = [this.loc.dateFormat, this.loc.timeFormat].join(this.opts.dateTimeSeparator); + } + + var boundary = this._getWordBoundaryRegExp; + if (this.loc.timeFormat.match(boundary('aa')) || + this.loc.timeFormat.match(boundary('AA')) + ) { + this.ampm = true; + } }, _buildDatepickersContainer: function () { @@ -244,7 +282,13 @@ parsedSelected = datepicker.getParsedDate(selectedDates[0]), formattedDates, _this = this, - dates = new Date(parsedSelected.year, parsedSelected.month, parsedSelected.date); + dates = new Date( + parsedSelected.year, + parsedSelected.month, + parsedSelected.date, + parsedSelected.hours, + parsedSelected.minutes + ); formattedDates = selectedDates.map(function (date) { return _this.formatDate(_this.loc.dateFormat, date) @@ -254,7 +298,13 @@ if (this.opts.multipleDates || this.opts.range) { dates = selectedDates.map(function(date) { var parsedDate = datepicker.getParsedDate(date); - return new Date(parsedDate.year, parsedDate.month, parsedDate.date) + return new Date( + parsedSelected.year, + parsedSelected.month, + parsedSelected.date, + parsedSelected.hours, + parsedSelected.minutes + ); }) } @@ -304,12 +354,28 @@ var result = string, boundary = this._getWordBoundaryRegExp, locale = this.loc, + leadingZero = datepicker.getLeadingZeroNum, decade = datepicker.getDecade(date), - d = datepicker.getParsedDate(date); + d = datepicker.getParsedDate(date), + fullHours = d.fullHours, + hours = d.hours, + dayPeriod = 'am', + validHours; + + if (this.opts.timepicker && this.timepicker && this.ampm) { + validHours = this.timepicker._getValidHoursFromDate(date); + fullHours = leadingZero(validHours.hours); + hours = validHours.hours; + dayPeriod = validHours.dayPeriod; + } switch (true) { case /@/.test(result): result = result.replace(/@/, date.getTime()); + case /aa/.test(result): + result = result.replace(boundary('aa'), dayPeriod); + case /AA/.test(result): + result = result.replace(boundary('AA'), dayPeriod.toUpperCase()); case /dd/.test(result): result = result.replace(boundary('dd'), d.fullDate); case /d/.test(result): @@ -326,6 +392,14 @@ result = result.replace(boundary('MM'), this.loc.months[d.month]); case /M/.test(result): result = result.replace(boundary('M'), locale.monthsShort[d.month]); + case /ii/.test(result): + result = result.replace(boundary('ii'), d.fullMinutes); + case /i/.test(result): + result = result.replace(boundary('i'), d.minutes); + case /hh/.test(result): + result = result.replace(boundary('hh'), fullHours); + case /h/.test(result): + result = result.replace(boundary('h'), hours); case /yyyy/.test(result): result = result.replace(boundary('yyyy'), d.year); case /yyyy1/.test(result): @@ -353,6 +427,25 @@ if (!(date instanceof Date)) return; + this.lastSelectedDate = date; + + // Set new time values from Date + if (this.timepicker) { + this.timepicker.hours = date.getHours(); + this.timepicker.minutes = date.getMinutes(); + } + + // On this step timepicker will set valid values in it's instance + _this._trigger('selectDate', date); + + // Set correct time values after timepicker's validation + // Prevent from setting hours or minutes which values are lesser then `min` value or + // greater then `max` value + if (this.timepicker) { + date.setHours(this.timepicker.hours) + date.setMinutes(this.timepicker.minutes) + } + if (_this.view == 'days') { if (date.getMonth() != d.month && opts.moveToOtherMonthsOnSelect) { newDate = new Date(date.getFullYear(), date.getMonth(), 1); @@ -429,6 +522,9 @@ if (!_this.selectedDates.length) { _this.minRange = ''; _this.maxRange = ''; + _this.lastSelectedDate = ''; + } else { + _this.lastSelectedDate = _this.selectedDates[_this.selectedDates.length - 1]; } _this.views[_this.currentView]._render(); @@ -468,6 +564,7 @@ */ update: function (param, value) { var len = arguments.length; + if (len == 2) { this.opts[param] = value; } else if (len == 1 && typeof param == 'object') { @@ -492,6 +589,19 @@ this.$datepicker.addClass(this.opts.classes) } + if (this.opts.timepicker) { + this.timepicker._handleDate(this.lastSelectedDate); + this.timepicker._updateRanges(); + this.timepicker._updateCurrentTime(); + // Change hours and minutes if it's values have been changed through min/max hours/minutes + if (this.lastSelectedDate) { + this.lastSelectedDate.setHours(this.timepicker.hours); + this.lastSelectedDate.setMinutes(this.timepicker.minutes); + } + } + + this._setInputValue(); + return this; }, @@ -929,7 +1039,8 @@ _onMouseUpDatepicker: function (e) { this.inFocus = false; - this.$el.focus() + e.originalEvent.inFocus = true; + if (!e.originalEvent.timepickerFocus) this.$el.focus(); }, _onInput: function () { @@ -946,6 +1057,18 @@ } }, + _onMouseUpBody: function (e) { + if (e.originalEvent.inFocus) return; + + if (this.visible && !this.inFocus) { + this.hide(); + } + }, + + _onMouseUpEl: function (e) { + e.originalEvent.inFocus = true; + }, + _onKeyDown: function (e) { var code = e.which; this._registerKey(code); @@ -1026,6 +1149,37 @@ this.silent = false; }, + _onTimeChange: function (e, h, m) { + var date = new Date(), + selectedDates = this.selectedDates, + selected = false; + + if (selectedDates.length) { + selected = true; + date = this.lastSelectedDate; + } + + date.setHours(h); + date.setMinutes(m); + + if (!selected && !this._getCell(date).hasClass('-disabled-')) { + this.selectDate(date); + } else { + this._setInputValue(); + if (this.opts.onSelect) { + this._triggerOnChange(); + } + } + }, + + _onClickCell: function (e, date) { + if (this.timepicker) { + date.setHours(this.timepicker.hours); + date.setMinutes(this.timepicker.minutes); + } + this.selectDate(date); + }, + set focused(val) { if (!val && this.focused) { var $cell = this._getCell(this.focused); @@ -1141,7 +1295,11 @@ fullMonth: (date.getMonth() + 1) < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1, // One based date: date.getDate(), fullDate: date.getDate() < 10 ? '0' + date.getDate() : date.getDate(), - day: date.getDay() + day: date.getDay(), + hours: date.getHours(), + fullHours: date.getHours() < 10 ? '0' + date.getHours() : date.getHours() , + minutes: date.getMinutes(), + fullMinutes: date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes() } }; @@ -1184,6 +1342,10 @@ return date.getTime() > dateCompareTo.getTime(); }; + datepicker.getLeadingZeroNum = function (num) { + return parseInt(num) < 10 ? '0' + num : num; + }; + Datepicker.language = { ru: { days: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'], @@ -1194,6 +1356,7 @@ today: 'Сегодня', clear: 'Очистить', dateFormat: 'dd.mm.yyyy', + timeFormat: 'hh:ii', firstDay: 1 } }; @@ -1217,6 +1380,7 @@ }) })(); + ;(function () { var templates = { days:'' + @@ -1509,7 +1673,7 @@ alreadySelected = this.d._isSelected(selectedDate, this.d.cellType); if (!alreadySelected) { - this.d.selectDate(selectedDate); + this.d._trigger('clickCell', selectedDate); } else if (alreadySelected && this.opts.toggleSelected){ this.d.removeDate(selectedDate); } @@ -1666,4 +1830,258 @@ } })(); + +;(function () { + var template = '
' + + '
' + + ' #{hourValue}' + + ' :' + + ' #{minValue}' + + '
' + + '
' + + '
' + + ' ' + + '
' + + '
' + + ' ' + + '
' + + '
' + + '
', + datepicker = Datepicker; + + datepicker.Timepicker = function (inst, opts) { + this.d = inst; + this.opts = opts; + + this.init(); + }; + + datepicker.Timepicker.prototype = { + init: function () { + var input = 'input'; + this._setInitialTime(this.d.date); + this._buildHTML(); + + if (navigator.userAgent.match(/trident/gi)) { + input = 'change'; + } + + this.d.$el.on('selectDate', this._onSelectDate.bind(this)); + this.$ranges.on(input, this._onChangeRange.bind(this)); + this.$ranges.on('mouseenter', this._onMouseEnterRange.bind(this)); + this.$ranges.on('mouseout blur', this._onMouseOutRange.bind(this)); + }, + + _setInitialTime: function (date, parse) { + var _date = datepicker.getParsedDate(date); + + this._handleDate(date); + this.hours = _date.hours < this.minHours ? this.minHours : _date.hours; + this.minutes = _date.minutes < this.minMinutes ? this.minMinutes : _date.minutes; + }, + + _setMinTimeFromDate: function (date) { + this.minHours = date.getHours(); + this.minMinutes = date.getMinutes(); + }, + + _setMaxTimeFromDate: function (date) { + this.maxHours = date.getHours(); + this.maxMinutes = date.getMinutes(); + }, + + _setDefaultMinMaxTime: function () { + var maxHours = 23, + maxMinutes = 59, + opts = this.opts; + + this.minHours = opts.minHours < 0 || opts.minHours > maxHours ? 0 : opts.minHours; + this.minMinutes = opts.minMinutes < 0 || opts.minMinutes > maxMinutes ? 0 : opts.minMinutes; + this.maxHours = opts.maxHours < 0 || opts.maxHours > maxHours ? maxHours : opts.maxHours; + this.maxMinutes = opts.maxMinutes < 0 || opts.maxMinutes > maxMinutes ? maxMinutes : opts.maxMinutes; + }, + + /** + * Looks for min/max hours/minutes and if current values + * are out of range sets valid values. + * @private + */ + _validateHoursMinutes: function (date) { + if (this.hours < this.minHours) { + this.hours = this.minHours; + } else if (this.hours > this.maxHours) { + this.hours = this.maxHours; + } + + if (this.minutes < this.minMinutes) { + this.minutes = this.minMinutes; + } else if (this.minutes > this.maxMinutes) { + this.minutes = this.maxMinutes; + } + }, + + _buildHTML: function () { + var lz = datepicker.getLeadingZeroNum, + data = { + hourMin: this.minHours, + hourMax: lz(this.maxHours), + hourStep: this.opts.hoursStep, + hourValue: lz(this.displayHours), + minMin: this.minMinutes, + minMax: lz(this.maxMinutes), + minStep: this.opts.minutesStep, + minValue: lz(this.minutes) + }, + _template = datepicker.template(template, data); + + this.$timepicker = $(_template).appendTo(this.d.$datepicker); + this.$ranges = $('[type="range"]', this.$timepicker); + this.$hours = $('[name="hours"]', this.$timepicker); + this.$minutes = $('[name="minutes"]', this.$timepicker); + this.$hoursText = $('.datepicker--time-current-hours', this.$timepicker); + this.$minutesText = $('.datepicker--time-current-minutes', this.$timepicker); + + if (this.d.ampm) { + this.$ampm = $('') + .appendTo($('.datepicker--time-current', this.$timepicker)) + .html(this.dayPeriod); + + this.$timepicker.addClass('-am-pm-'); + } + }, + + _updateCurrentTime: function () { + var h = datepicker.getLeadingZeroNum(this.displayHours), + m = datepicker.getLeadingZeroNum(this.minutes); + + this.$hoursText.html(h); + this.$minutesText.html(m); + + if (this.d.ampm) { + this.$ampm.html(this.dayPeriod); + } + }, + + _updateRanges: function () { + this.$hours.attr({ + min: this.minHours, + max: this.maxHours, + value: this.hours + }); + + this.$minutes.attr({ + min: this.minMinutes, + max: this.maxMinutes, + value: this.minutes + }); + }, + + /** + * Sets minHours, minMinutes etc. from date. If date is not passed, than sets + * values from options + * @param [date] {object} - Date object, to get values from + * @private + */ + _handleDate: function (date) { + this._setDefaultMinMaxTime(); + + if (date) { + if (datepicker.isSame(date, this.d.opts.minDate)) { + this._setMinTimeFromDate(this.d.opts.minDate); + } else if (datepicker.isSame(date, this.d.opts.maxDate)) { + this._setMaxTimeFromDate(this.d.opts.maxDate); + } + } + + this._validateHoursMinutes(date); + }, + + update: function () { + this._updateRanges(); + this._updateCurrentTime(); + }, + + /** + * Calculates valid hour value to display in text input and datepicker's body. + * @param date {Date|Number} - date or hours + * @returns {{hours: *, dayPeriod: string}} + * @private + */ + _getValidHoursFromDate: function (date) { + var d = date, + hours = date; + + if (date instanceof Date) { + d = datepicker.getParsedDate(date); + hours = d.hours; + } + + var ampm = this.d.ampm, + dayPeriod = 'am'; + + if (ampm) { + switch(true) { + case hours == 0: + hours = 12; + break; + case hours == 12: + dayPeriod = 'pm'; + break; + case hours > 11: + hours = hours - 12; + dayPeriod = 'pm'; + break; + default: + break; + } + } + + return { + hours: hours, + dayPeriod: dayPeriod + } + }, + + set hours (val) { + this._hours = val; + + var displayHours = this._getValidHoursFromDate(val); + + this.displayHours = displayHours.hours; + this.dayPeriod = displayHours.dayPeriod; + }, + + get hours() { + return this._hours; + }, + + // Events + // ------------------------------------------------- + + _onChangeRange: function (e) { + var $target = $(e.target), + name = $target.attr('name'); + + this[name] = $target.val(); + this._updateCurrentTime(); + this.d._trigger('timeChange', [this.hours, this.minutes]) + }, + + _onSelectDate: function (e, data) { + this._handleDate(data); + this.update(); + }, + + _onMouseEnterRange: function (e) { + var name = $(e.target).attr('name'); + $('.datepicker--time-current-' + name, this.$timepicker).addClass('-focus-'); + }, + + _onMouseOutRange: function (e) { + var name = $(e.target).attr('name'); + if (this.d.inFocus) return; // Prevent removing focus when mouse out of range slider + $('.datepicker--time-current-' + name, this.$timepicker).removeClass('-focus-'); + } + }; +})() })(window, jQuery); \ No newline at end of file diff --git a/dist/js/datepicker.min.js b/dist/js/datepicker.min.js index a96c81c..c94e522 100644 --- a/dist/js/datepicker.min.js +++ b/dist/js/datepicker.min.js @@ -1 +1,2 @@ -!function(e,t,s){e.Datepicker="",function(){var i,a,n,h="datepicker",o=".datepicker-here",r=!1,c='
',d={classes:"",inline:!1,language:"ru",startDate:new Date,firstDay:"",weekends:[6,0],dateFormat:"",altField:"",altFieldDateFormat:"@",toggleSelected:!0,keyboardNav:!0,position:"bottom left",offset:12,view:"days",minView:"days",showOtherMonths:!0,selectOtherMonths:!0,moveToOtherMonthsOnSelect:!0,showOtherYears:!0,selectOtherYears:!0,moveToOtherYearsOnSelect:!0,minDate:"",maxDate:"",disableNavWhenOutOfRange:!0,multipleDates:!1,multipleDatesSeparator:",",range:!1,todayButton:!1,clearButton:!1,showEvent:"focus",autoClose:!1,monthsField:"monthsShort",prevHtml:'',nextHtml:'',navTitles:{days:"MM, yyyy",months:"yyyy",years:"yyyy1 - yyyy2"},onSelect:"",onChangeMonth:"",onChangeYear:"",onChangeDecade:"",onChangeView:"",onRenderCell:""},l={ctrlRight:[17,39],ctrlUp:[17,38],ctrlLeft:[17,37],ctrlDown:[17,40],shiftRight:[16,39],shiftUp:[16,38],shiftLeft:[16,37],shiftDown:[16,40],altUp:[18,38],altRight:[18,39],altLeft:[18,37],altDown:[18,40],ctrlShiftUp:[16,17,38]};Datepicker=function(e,a){this.el=e,this.$el=t(e),this.opts=t.extend(!0,{},d,a,this.$el.data()),i==s&&(i=t("body")),this.opts.startDate||(this.opts.startDate=new Date),"INPUT"==this.el.nodeName&&(this.elIsInput=!0),this.opts.altField&&(this.$altField="string"==typeof this.opts.altField?t(this.opts.altField):this.opts.altField),this.inited=!1,this.visible=!1,this.silent=!1,this.currentDate=this.opts.startDate,this.currentView=this.opts.view,this._createShortCuts(),this.selectedDates=[],this.views={},this.keys=[],this.minRange="",this.maxRange="",this.init()},n=Datepicker,n.prototype={viewIndexes:["days","months","years"],init:function(){r||this.opts.inline||!this.elIsInput||this._buildDatepickersContainer(),this._buildBaseHtml(),this._defineLocale(this.opts.language),this._syncWithMinMaxDates(),this.elIsInput&&(this.opts.inline||(this._setPositionClasses(this.opts.position),this._bindEvents()),this.opts.keyboardNav&&this._bindKeyboardEvents(),this.$datepicker.on("mousedown",this._onMouseDownDatepicker.bind(this)),this.$datepicker.on("mouseup",this._onMouseUpDatepicker.bind(this))),this.opts.classes&&this.$datepicker.addClass(this.opts.classes),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.$datepicker.on("mouseenter",".datepicker--cell",this._onMouseEnterCell.bind(this)),this.$datepicker.on("mouseleave",".datepicker--cell",this._onMouseLeaveCell.bind(this)),this.inited=!0},_createShortCuts:function(){this.minDate=this.opts.minDate?this.opts.minDate:new Date(-86399999136e5),this.maxDate=this.opts.maxDate?this.opts.maxDate:new Date(86399999136e5)},_bindEvents:function(){this.$el.on(this.opts.showEvent+".adp",this._onShowEvent.bind(this)),this.$el.on("blur.adp",this._onBlur.bind(this)),this.$el.on("input.adp",this._onInput.bind(this)),t(e).on("resize.adp",this._onResize.bind(this))},_bindKeyboardEvents:function(){this.$el.on("keydown.adp",this._onKeyDown.bind(this)),this.$el.on("keyup.adp",this._onKeyUp.bind(this)),this.$el.on("hotKey.adp",this._onHotKey.bind(this))},isWeekend:function(e){return-1!==this.opts.weekends.indexOf(e)},_defineLocale:function(e){"string"==typeof e?(this.loc=Datepicker.language[e],this.loc||(console.warn("Can't find language \""+e+'" in Datepicker.language, will use "ru" instead'),this.loc=t.extend(!0,{},Datepicker.language.ru)),this.loc=t.extend(!0,{},Datepicker.language.ru,Datepicker.language[e])):this.loc=t.extend(!0,{},Datepicker.language.ru,e),this.opts.dateFormat&&(this.loc.dateFormat=this.opts.dateFormat),""!==this.opts.firstDay&&(this.loc.firstDay=this.opts.firstDay)},_buildDatepickersContainer:function(){r=!0,i.append('
'),a=t("#datepickers-container")},_buildBaseHtml:function(){var e,s=t('
');e="INPUT"==this.el.nodeName?this.opts.inline?s.insertAfter(this.$el):a:s.appendTo(this.$el),this.$datepicker=t(c).appendTo(e),this.$content=t(".datepicker--content",this.$datepicker),this.$nav=t(".datepicker--nav",this.$datepicker)},_triggerOnChange:function(){if(!this.selectedDates.length)return this.opts.onSelect("","",this);var e,t=this.selectedDates,s=n.getParsedDate(t[0]),i=this,a=new Date(s.year,s.month,s.date);e=t.map(function(e){return i.formatDate(i.loc.dateFormat,e)}).join(this.opts.multipleDatesSeparator),(this.opts.multipleDates||this.opts.range)&&(a=t.map(function(e){var t=n.getParsedDate(e);return new Date(t.year,t.month,t.date)})),this.opts.onSelect(e,a,this)},next:function(){var e=this.parsedDate,t=this.opts;switch(this.view){case"days":this.date=new Date(e.year,e.month+1,1),t.onChangeMonth&&t.onChangeMonth(this.parsedDate.month,this.parsedDate.year);break;case"months":this.date=new Date(e.year+1,e.month,1),t.onChangeYear&&t.onChangeYear(this.parsedDate.year);break;case"years":this.date=new Date(e.year+10,0,1),t.onChangeDecade&&t.onChangeDecade(this.curDecade)}},prev:function(){var e=this.parsedDate,t=this.opts;switch(this.view){case"days":this.date=new Date(e.year,e.month-1,1),t.onChangeMonth&&t.onChangeMonth(this.parsedDate.month,this.parsedDate.year);break;case"months":this.date=new Date(e.year-1,e.month,1),t.onChangeYear&&t.onChangeYear(this.parsedDate.year);break;case"years":this.date=new Date(e.year-10,0,1),t.onChangeDecade&&t.onChangeDecade(this.curDecade)}},formatDate:function(e,t){t=t||this.date;var s=e,i=this._getWordBoundaryRegExp,a=this.loc,h=n.getDecade(t),o=n.getParsedDate(t);switch(!0){case/@/.test(s):s=s.replace(/@/,t.getTime());case/dd/.test(s):s=s.replace(i("dd"),o.fullDate);case/d/.test(s):s=s.replace(i("d"),o.date);case/DD/.test(s):s=s.replace(i("DD"),a.days[o.day]);case/D/.test(s):s=s.replace(i("D"),a.daysShort[o.day]);case/mm/.test(s):s=s.replace(i("mm"),o.fullMonth);case/m/.test(s):s=s.replace(i("m"),o.month+1);case/MM/.test(s):s=s.replace(i("MM"),this.loc.months[o.month]);case/M/.test(s):s=s.replace(i("M"),a.monthsShort[o.month]);case/yyyy/.test(s):s=s.replace(i("yyyy"),o.year);case/yyyy1/.test(s):s=s.replace(i("yyyy1"),h[0]);case/yyyy2/.test(s):s=s.replace(i("yyyy2"),h[1]);case/yy/.test(s):s=s.replace(i("yy"),o.year.toString().slice(-2))}return s},_getWordBoundaryRegExp:function(e){return new RegExp("\\b(?=[a-zA-Z0-9äöüßÄÖÜ<])"+e+"(?![>a-zA-Z0-9äöüßÄÖÜ])")},selectDate:function(e){var t=this,s=t.opts,i=t.parsedDate,a=t.selectedDates,n=a.length,h="";if(e instanceof Date){if("days"==t.view&&e.getMonth()!=i.month&&s.moveToOtherMonthsOnSelect&&(h=new Date(e.getFullYear(),e.getMonth(),1)),"years"==t.view&&e.getFullYear()!=i.year&&s.moveToOtherYearsOnSelect&&(h=new Date(e.getFullYear(),0,1)),h&&(t.silent=!0,t.date=h,t.silent=!1,t.nav._render()),s.multipleDates&&!s.range){if(n===s.multipleDates)return;t._isSelected(e)||t.selectedDates.push(e)}else s.range?2==n?(t.selectedDates=[e],t.minRange=e,t.maxRange=""):1==n?(t.selectedDates.push(e),t.maxRange?t.minRange=e:t.maxRange=e,t.selectedDates=[t.minRange,t.maxRange]):(t.selectedDates=[e],t.minRange=e):t.selectedDates=[e];t._setInputValue(),s.onSelect&&t._triggerOnChange(),s.autoClose&&(s.multipleDates||s.range?s.range&&2==t.selectedDates.length&&t.hide():t.hide()),t.views[this.currentView]._render()}},removeDate:function(e){var t=this.selectedDates,s=this;if(e instanceof Date)return t.some(function(i,a){return n.isSame(i,e)?(t.splice(a,1),s.selectedDates.length||(s.minRange="",s.maxRange=""),s.views[s.currentView]._render(),s._setInputValue(),s.opts.onSelect&&s._triggerOnChange(),!0):void 0})},today:function(){this.silent=!0,this.view=this.opts.minView,this.silent=!1,this.date=new Date},clear:function(){this.selectedDates=[],this.minRange="",this.maxRange="",this.views[this.currentView]._render(),this._setInputValue(),this.opts.onSelect&&this._triggerOnChange()},update:function(e,s){var i=arguments.length;return 2==i?this.opts[e]=s:1==i&&"object"==typeof e&&(this.opts=t.extend(!0,this.opts,e)),this._createShortCuts(),this._syncWithMinMaxDates(),this._defineLocale(this.opts.language),this.nav._addButtonsIfNeed(),this.nav._render(),this.views[this.currentView]._render(),this.elIsInput&&!this.opts.inline&&(this._setPositionClasses(this.opts.position),this.visible&&this.setPosition(this.opts.position)),this.opts.classes&&this.$datepicker.addClass(this.opts.classes),this},_syncWithMinMaxDates:function(){var e=this.date.getTime();this.silent=!0,this.minTime>e&&(this.date=this.minDate),this.maxTime=this.minTime&&s<=this.maxTime,month:o>=this.minTime&&r<=this.maxTime,year:i.year>=a.year&&i.year<=h.year};return t?c[t]:c.day},_getDimensions:function(e){var t=e.offset();return{width:e.outerWidth(),height:e.outerHeight(),left:t.left,top:t.top}},_getDateFromCell:function(e){var t=this.parsedDate,i=e.data("year")||t.year,a=e.data("month")==s?t.month:e.data("month"),n=e.data("date")||1;return new Date(i,a,n)},_setPositionClasses:function(e){e=e.split(" ");var t=e[0],s=e[1],i="datepicker -"+t+"-"+s+"- -from-"+t+"-";this.visible&&(i+=" active"),this.$datepicker.removeAttr("class").addClass(i)},setPosition:function(e){e=e||this.opts.position;var t,s,i=this._getDimensions(this.$el),a=this._getDimensions(this.$datepicker),n=e.split(" "),h=this.opts.offset,o=n[0],r=n[1];switch(o){case"top":t=i.top-a.height-h;break;case"right":s=i.left+i.width+h;break;case"bottom":t=i.top+i.height+h;break;case"left":s=i.left-a.width-h}switch(r){case"top":t=i.top;break;case"right":s=i.left+i.width-a.width;break;case"bottom":t=i.top+i.height-a.height;break;case"left":s=i.left;break;case"center":/left|right/.test(o)?t=i.top+i.height/2-a.height/2:s=i.left+i.width/2-a.width/2}this.$datepicker.css({left:s,top:t})},show:function(){this.setPosition(this.opts.position),this.$datepicker.addClass("active"),this.visible=!0},hide:function(){this.$datepicker.removeClass("active").css({left:"-100000px"}),this.focused="",this.keys=[],this.inFocus=!1,this.visible=!1,this.$el.blur()},down:function(e){this._changeView(e,"down")},up:function(e){this._changeView(e,"up")},_changeView:function(e,t){e=e||this.focused||this.date;var s="up"==t?this.viewIndex+1:this.viewIndex-1;s>2&&(s=2),0>s&&(s=0),this.silent=!0,this.date=new Date(e.getFullYear(),e.getMonth(),1),this.silent=!1,this.view=this.viewIndexes[s]},_handleHotKey:function(e){var t,s,i,a=n.getParsedDate(this._getFocusedDate()),h=this.opts,o=!1,r=!1,c=!1,d=a.year,l=a.month,u=a.date;switch(e){case"ctrlRight":case"ctrlUp":l+=1,o=!0;break;case"ctrlLeft":case"ctrlDown":l-=1,o=!0;break;case"shiftRight":case"shiftUp":r=!0,d+=1;break;case"shiftLeft":case"shiftDown":r=!0,d-=1;break;case"altRight":case"altUp":c=!0,d+=10;break;case"altLeft":case"altDown":c=!0,d-=10;break;case"ctrlShiftUp":this.up()}i=n.getDaysCount(new Date(d,l)),s=new Date(d,l,u),u>i&&(u=i),s.getTime()this.maxTime&&(s=this.maxDate),this.focused=s,t=n.getParsedDate(s),o&&h.onChangeMonth&&h.onChangeMonth(t.month,t.year),r&&h.onChangeYear&&h.onChangeYear(t.year),c&&h.onChangeDecade&&h.onChangeDecade(this.curDecade)},_registerKey:function(e){var t=this.keys.some(function(t){return t==e});t||this.keys.push(e)},_unRegisterKey:function(e){var t=this.keys.indexOf(e);this.keys.splice(t,1)},_isHotKeyPressed:function(){var e,t=!1,s=this,i=this.keys.sort();for(var a in l)e=l[a],i.length==e.length&&e.every(function(e,t){return e==i[t]})&&(s._trigger("hotKey",a),t=!0);return t},_trigger:function(e,t){this.$el.trigger(e,t)},_focusNextCell:function(e,t){t=t||this.cellType;var s=n.getParsedDate(this._getFocusedDate()),i=s.year,a=s.month,h=s.date;if(!this._isHotKeyPressed()){switch(e){case 37:"day"==t?h-=1:"","month"==t?a-=1:"","year"==t?i-=1:"";break;case 38:"day"==t?h-=7:"","month"==t?a-=3:"","year"==t?i-=4:"";break;case 39:"day"==t?h+=1:"","month"==t?a+=1:"","year"==t?i+=1:"";break;case 40:"day"==t?h+=7:"","month"==t?a+=3:"","year"==t?i+=4:""}var o=new Date(i,a,h);o.getTime()this.maxTime&&(o=this.maxDate),this.focused=o}},_getFocusedDate:function(){var e=this.focused||this.selectedDates[this.selectedDates.length-1],t=this.parsedDate;if(!e)switch(this.view){case"days":e=new Date(t.year,t.month,(new Date).getDate());break;case"months":e=new Date(t.year,t.month,1);break;case"years":e=new Date(t.year,0,1)}return e},_getCell:function(e,t){t=t||this.cellType;var s,i=n.getParsedDate(e),a='.datepicker--cell[data-year="'+i.year+'"]';switch(t){case"month":a='[data-month="'+i.month+'"]';break;case"day":a+='[data-month="'+i.month+'"][data-date="'+i.date+'"]'}return s=this.views[this.currentView].$el.find(a),s.length?s:""},destroy:function(){var e=this;e.$el.off(".adp").data("datepicker",""),e.selectedDates=[],e.focused="",e.views={},e.keys=[],e.minRange="",e.maxRange="",e.opts.inline||!e.elIsInput?e.$datepicker.closest(".datepicker-inline").remove():e.$datepicker.remove()},_onShowEvent:function(){this.visible||this.show()},_onBlur:function(){!this.inFocus&&this.visible&&this.hide()},_onMouseDownDatepicker:function(e){this.inFocus=!0},_onMouseUpDatepicker:function(e){this.inFocus=!1,this.$el.focus()},_onInput:function(){var e=this.$el.val();e||this.clear()},_onResize:function(){this.visible&&this.setPosition()},_onKeyDown:function(e){var t=e.which;if(this._registerKey(t),t>=37&&40>=t&&(e.preventDefault(),this._focusNextCell(t)),13==t&&this.focused){if(this._getCell(this.focused).hasClass("-disabled-"))return;if(this.view!=this.opts.minView)this.down();else{var s=this._isSelected(this.focused,this.cellType);s?s&&this.opts.toggleSelected&&this.removeDate(this.focused):this.selectDate(this.focused)}}27==t&&this.hide()},_onKeyUp:function(e){var t=e.which;this._unRegisterKey(t)},_onHotKey:function(e,t){this._handleHotKey(t)},_onMouseEnterCell:function(e){var s=t(e.target).closest(".datepicker--cell"),i=this._getDateFromCell(s);this.silent=!0,this.focused&&(this.focused=""),s.addClass("-focus-"),this.focused=i,this.silent=!1,this.opts.range&&1==this.selectedDates.length&&(this.minRange=this.selectedDates[0],this.maxRange="",n.less(this.minRange,this.focused)&&(this.maxRange=this.minRange,this.minRange=""),this.views[this.currentView]._update())},_onMouseLeaveCell:function(e){var s=t(e.target).closest(".datepicker--cell");s.removeClass("-focus-"),this.silent=!0,this.focused="",this.silent=!1},set focused(e){if(!e&&this.focused){var t=this._getCell(this.focused);t.length&&t.removeClass("-focus-")}this._focused=e,this.opts.range&&1==this.selectedDates.length&&(this.minRange=this.selectedDates[0],this.maxRange="",n.less(this.minRange,this._focused)&&(this.maxRange=this.minRange,this.minRange="")),this.silent||(this.date=e)},get focused(){return this._focused},get parsedDate(){return n.getParsedDate(this.date)},set date(e){return e instanceof Date?(this.currentDate=e,this.inited&&!this.silent&&(this.views[this.view]._render(),this.nav._render(),this.visible&&this.elIsInput&&this.setPosition()),e):void 0},get date(){return this.currentDate},set view(e){return this.viewIndex=this.viewIndexes.indexOf(e),this.viewIndex<0?void 0:(this.prevView=this.currentView,this.currentView=e,this.inited&&(this.views[e]?this.views[e]._render():this.views[e]=new Datepicker.Body(this,e,this.opts),this.views[this.prevView].hide(),this.views[e].show(),this.nav._render(),this.opts.onChangeView&&this.opts.onChangeView(e),this.elIsInput&&this.visible&&this.setPosition()),e)},get view(){return this.currentView},get cellType(){return this.view.substring(0,this.view.length-1)},get minTime(){var e=n.getParsedDate(this.minDate);return new Date(e.year,e.month,e.date).getTime()},get maxTime(){var e=n.getParsedDate(this.maxDate);return new Date(e.year,e.month,e.date).getTime()},get curDecade(){return n.getDecade(this.date)}},n.getDaysCount=function(e){return new Date(e.getFullYear(),e.getMonth()+1,0).getDate()},n.getParsedDate=function(e){return{year:e.getFullYear(),month:e.getMonth(),fullMonth:e.getMonth()+1<10?"0"+(e.getMonth()+1):e.getMonth()+1,date:e.getDate(),fullDate:e.getDate()<10?"0"+e.getDate():e.getDate(),day:e.getDay()}},n.getDecade=function(e){var t=10*Math.floor(e.getFullYear()/10);return[t,t+9]},n.template=function(e,t){return e.replace(/#\{([\w]+)\}/g,function(e,s){return t[s]||0===t[s]?t[s]:void 0})},n.isSame=function(e,t,s){if(!e||!t)return!1;var i=n.getParsedDate(e),a=n.getParsedDate(t),h=s?s:"day",o={day:i.date==a.date&&i.month==a.month&&i.year==a.year,month:i.month==a.month&&i.year==a.year,year:i.year==a.year};return o[h]},n.less=function(e,t,s){return e&&t?t.getTime()e.getTime():!1},Datepicker.language={ru:{days:["Воскресенье","Понедельник","Вторник","Среда","Четверг","Пятница","Суббота"],daysShort:["Вос","Пон","Вто","Сре","Чет","Пят","Суб"],daysMin:["Вс","Пн","Вт","Ср","Чт","Пт","Сб"],months:["Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь","Декабрь"],monthsShort:["Янв","Фев","Мар","Апр","Май","Июн","Июл","Авг","Сен","Окт","Ноя","Дек"],today:"Сегодня",clear:"Очистить",dateFormat:"dd.mm.yyyy",firstDay:1}},t.fn[h]=function(e){return this.each(function(){if(t.data(this,h)){var s=t.data(this,h);s.opts=t.extend(!0,s.opts,e),s.update()}else t.data(this,h,new Datepicker(this,e))})},t(function(){t(o).datepicker()})}(),function(){var e={days:'
',months:'
',years:'
'},i=Datepicker;i.Body=function(e,t,s){this.d=e,this.type=t,this.opts=s,this.init()},i.Body.prototype={init:function(){this._buildBaseHtml(),this._render(),this._bindEvents()},_bindEvents:function(){this.$el.on("click",".datepicker--cell",t.proxy(this._onClickCell,this))},_buildBaseHtml:function(){this.$el=t(e[this.type]).appendTo(this.d.$content),this.$names=t(".datepicker--days-names",this.$el),this.$cells=t(".datepicker--cells",this.$el)},_getDayNamesHtml:function(e,t,i,a){return t=t!=s?t:e,i=i?i:"",a=a!=s?a:0,a>7?i:7==t?this._getDayNamesHtml(e,0,i,++a):(i+='
'+this.d.loc.daysMin[t]+"
",this._getDayNamesHtml(e,++t,i,++a))},_getCellContents:function(e,t){var s="datepicker--cell datepicker--cell-"+t,a=new Date,n=this.d,h=n.opts,o=i.getParsedDate(e),r={},c=o.date;switch(h.onRenderCell&&(r=h.onRenderCell(e,t)||{},c=r.html?r.html:c,s+=r.classes?" "+r.classes:""),t){case"day":n.isWeekend(o.day)&&(s+=" -weekend-"),o.month!=this.d.parsedDate.month&&(s+=" -other-month-",h.selectOtherMonths||(s+=" -disabled-"),h.showOtherMonths||(c=""));break;case"month":c=n.loc[n.opts.monthsField][o.month];break;case"year":var d=n.curDecade;c=o.year,(o.yeard[1])&&(s+=" -other-decade-",h.selectOtherYears||(s+=" -disabled-"),h.showOtherYears||(c=""))}return h.onRenderCell&&(r=h.onRenderCell(e,t)||{},c=r.html?r.html:c,s+=r.classes?" "+r.classes:""),h.range&&(i.isSame(n.minRange,e,t)&&(s+=" -range-from-"),i.isSame(n.maxRange,e,t)&&(s+=" -range-to-"),1==n.selectedDates.length&&n.focused?((i.bigger(n.minRange,e)&&i.less(n.focused,e)||i.less(n.maxRange,e)&&i.bigger(n.focused,e))&&(s+=" -in-range-"),i.less(n.maxRange,e)&&i.isSame(n.focused,e)&&(s+=" -range-from-"),i.bigger(n.minRange,e)&&i.isSame(n.focused,e)&&(s+=" -range-to-")):2==n.selectedDates.length&&i.bigger(n.minRange,e)&&i.less(n.maxRange,e)&&(s+=" -in-range-")),i.isSame(a,e,t)&&(s+=" -current-"),n.focused&&i.isSame(e,n.focused,t)&&(s+=" -focus-"),n._isSelected(e,t)&&(s+=" -selected-"),(!n._isInRange(e,t)||r.disabled)&&(s+=" -disabled-"),{html:c,classes:s}},_getDaysHtml:function(e){var t=i.getDaysCount(e),s=new Date(e.getFullYear(),e.getMonth(),1).getDay(),a=new Date(e.getFullYear(),e.getMonth(),t).getDay(),n=s-this.d.loc.firstDay,h=6-a+this.d.loc.firstDay;n=0>n?n+7:n,h=h>6?h-7:h;for(var o,r,c=-n+1,d="",l=c,u=t+h;u>=l;l++)r=e.getFullYear(),o=e.getMonth(),d+=this._getDayHtml(new Date(r,o,l));return d},_getDayHtml:function(e){var t=this._getCellContents(e,"day");return'
'+t.html+"
"},_getMonthsHtml:function(e){for(var t="",s=i.getParsedDate(e),a=0;12>a;)t+=this._getMonthHtml(new Date(s.year,a)),a++;return t},_getMonthHtml:function(e){var t=this._getCellContents(e,"month");return'
'+t.html+"
"},_getYearsHtml:function(e){var t=(i.getParsedDate(e),i.getDecade(e)),s=t[0]-1,a="",n=s;for(n;n<=t[1]+1;n++)a+=this._getYearHtml(new Date(n,0));return a},_getYearHtml:function(e){var t=this._getCellContents(e,"year");return'
'+t.html+"
"},_renderTypes:{days:function(){var e=this._getDayNamesHtml(this.d.loc.firstDay),t=this._getDaysHtml(this.d.currentDate);this.$cells.html(t),this.$names.html(e)},months:function(){var e=this._getMonthsHtml(this.d.currentDate);this.$cells.html(e)},years:function(){var e=this._getYearsHtml(this.d.currentDate);this.$cells.html(e)}},_render:function(){this._renderTypes[this.type].bind(this)()},_update:function(){var e,s,i,a=t(".datepicker--cell",this.$cells),n=this;a.each(function(a,h){s=t(this),i=n.d._getDateFromCell(t(this)),e=n._getCellContents(i,n.d.cellType),s.attr("class",e.classes)})},show:function(){this.$el.addClass("active"),this.acitve=!0},hide:function(){this.$el.removeClass("active"),this.active=!1},_handleClick:function(e){var t=e.data("date")||1,s=e.data("month")||0,i=e.data("year")||this.d.parsedDate.year;if(this.d.view!=this.opts.minView)return void this.d.down(new Date(i,s,t));var a=new Date(i,s,t),n=this.d._isSelected(a,this.d.cellType);n?n&&this.opts.toggleSelected&&this.d.removeDate(a):this.d.selectDate(a)},_onClickCell:function(e){var s=t(e.target).closest(".datepicker--cell");s.hasClass("-disabled-")||this._handleClick.bind(this)(s)}}}(),function(){var e='
#{prevHtml}
#{title}
#{nextHtml}
',s='
',i='#{label}';Datepicker.Navigation=function(e,t){this.d=e,this.opts=t,this.$buttonsContainer="",this.init()},Datepicker.Navigation.prototype={init:function(){this._buildBaseHtml(),this._bindEvents()},_bindEvents:function(){this.d.$nav.on("click",".datepicker--nav-action",t.proxy(this._onClickNavButton,this)),this.d.$nav.on("click",".datepicker--nav-title",t.proxy(this._onClickNavTitle,this)),this.d.$datepicker.on("click",".datepicker--button",t.proxy(this._onClickNavButton,this))},_buildBaseHtml:function(){this._render(),this._addButtonsIfNeed()},_addButtonsIfNeed:function(){this.opts.todayButton&&this._addButton("today"),this.opts.clearButton&&this._addButton("clear")},_render:function(){var s=this._getTitle(this.d.currentDate),i=Datepicker.template(e,t.extend({title:s},this.opts));this.d.$nav.html(i),"years"==this.d.view&&t(".datepicker--nav-title",this.d.$nav).addClass("-disabled-"),this.setNavStatus()},_getTitle:function(e){return this.d.formatDate(this.opts.navTitles[this.d.view],e)},_addButton:function(e){this.$buttonsContainer.length||this._addButtonsContainer();var s={action:e,label:this.d.loc[e]},a=Datepicker.template(i,s);t("[data-action="+e+"]",this.$buttonsContainer).length||this.$buttonsContainer.append(a)},_addButtonsContainer:function(){this.d.$datepicker.append(s),this.$buttonsContainer=t(".datepicker--buttons",this.d.$datepicker)},setNavStatus:function(){if((this.opts.minDate||this.opts.maxDate)&&this.opts.disableNavWhenOutOfRange){var e=this.d.parsedDate,t=e.month,s=e.year,i=e.date;switch(this.d.view){case"days":this.d._isInRange(new Date(s,t-1,i),"month")||this._disableNav("prev"),this.d._isInRange(new Date(s,t+1,i),"month")||this._disableNav("next");break;case"months":this.d._isInRange(new Date(s-1,t,i),"year")||this._disableNav("prev"),this.d._isInRange(new Date(s+1,t,i),"year")||this._disableNav("next");break;case"years":this.d._isInRange(new Date(s-10,t,i),"year")||this._disableNav("prev"),this.d._isInRange(new Date(s+10,t,i),"year")||this._disableNav("next")}}},_disableNav:function(e){t('[data-action="'+e+'"]',this.d.$nav).addClass("-disabled-")},_activateNav:function(e){t('[data-action="'+e+'"]',this.d.$nav).removeClass("-disabled-")},_onClickNavButton:function(e){var s=t(e.target).closest("[data-action]"),i=s.data("action");this.d[i]()},_onClickNavTitle:function(e){return t(e.target).hasClass("-disabled-")?void 0:"days"==this.d.view?this.d.view="months":void(this.d.view="years")}}}()}(window,jQuery); \ No newline at end of file +!function(t,e,i){t.Datepicker="",function(){var s,a,n,h="datepicker",r=".datepicker-here",o=!1,c='
',d={classes:"",inline:!1,language:"ru",startDate:new Date,firstDay:"",weekends:[6,0],dateFormat:"",altField:"",altFieldDateFormat:"@",toggleSelected:!0,keyboardNav:!0,position:"bottom left",offset:12,view:"days",minView:"days",showOtherMonths:!0,selectOtherMonths:!0,moveToOtherMonthsOnSelect:!0,showOtherYears:!0,selectOtherYears:!0,moveToOtherYearsOnSelect:!0,minDate:"",maxDate:"",disableNavWhenOutOfRange:!0,multipleDates:!1,multipleDatesSeparator:",",range:!1,todayButton:!1,clearButton:!1,showEvent:"focus",autoClose:!1,monthsField:"monthsShort",prevHtml:'',nextHtml:'',navTitles:{days:"MM, yyyy",months:"yyyy",years:"yyyy1 - yyyy2"},timepicker:!1,dateTimeSeparator:" ",timeFormat:"",minHours:0,maxHours:24,minMinutes:0,maxMinutes:59,hoursStep:1,minutesStep:1,onSelect:"",onChangeMonth:"",onChangeYear:"",onChangeDecade:"",onChangeView:"",onRenderCell:""},l={ctrlRight:[17,39],ctrlUp:[17,38],ctrlLeft:[17,37],ctrlDown:[17,40],shiftRight:[16,39],shiftUp:[16,38],shiftLeft:[16,37],shiftDown:[16,40],altUp:[18,38],altRight:[18,39],altLeft:[18,37],altDown:[18,40],ctrlShiftUp:[16,17,38]};Datepicker=function(t,a){this.el=t,this.$el=e(t),this.opts=e.extend(!0,{},d,a,this.$el.data()),s==i&&(s=e("body")),this.opts.startDate||(this.opts.startDate=new Date),"INPUT"==this.el.nodeName&&(this.elIsInput=!0),this.opts.altField&&(this.$altField="string"==typeof this.opts.altField?e(this.opts.altField):this.opts.altField),this.inited=!1,this.visible=!1,this.silent=!1,this.currentDate=this.opts.startDate,this.currentView=this.opts.view,this._createShortCuts(),this.selectedDates=[],this.views={},this.keys=[],this.minRange="",this.maxRange="",this.init()},n=Datepicker,n.prototype={viewIndexes:["days","months","years"],init:function(){o||this.opts.inline||!this.elIsInput||this._buildDatepickersContainer(),this._buildBaseHtml(),this._defineLocale(this.opts.language),this._syncWithMinMaxDates(),this.elIsInput&&(this.opts.inline||(this._setPositionClasses(this.opts.position),this._bindEvents()),this.opts.keyboardNav&&this._bindKeyboardEvents(),this.$datepicker.on("mousedown",this._onMouseDownDatepicker.bind(this)),this.$datepicker.on("mouseup",this._onMouseUpDatepicker.bind(this))),this.opts.classes&&this.$datepicker.addClass(this.opts.classes),this.opts.timepicker&&(this.timepicker=new Datepicker.Timepicker(this,this.opts),this._bindTimepickerEvents()),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.$el.on("clickCell.adp",this._onClickCell.bind(this)),this.$datepicker.on("mouseenter",".datepicker--cell",this._onMouseEnterCell.bind(this)),this.$datepicker.on("mouseleave",".datepicker--cell",this._onMouseLeaveCell.bind(this)),this.inited=!0},_createShortCuts:function(){this.minDate=this.opts.minDate?this.opts.minDate:new Date(-86399999136e5),this.maxDate=this.opts.maxDate?this.opts.maxDate:new Date(86399999136e5)},_bindEvents:function(){this.$el.on(this.opts.showEvent+".adp",this._onShowEvent.bind(this)),this.$el.on("mouseup.adp",this._onMouseUpEl.bind(this)),this.$el.on("blur.adp",this._onBlur.bind(this)),this.$el.on("input.adp",this._onInput.bind(this)),e(t).on("resize.adp",this._onResize.bind(this)),e("body").on("mouseup.adp",this._onMouseUpBody.bind(this))},_bindKeyboardEvents:function(){this.$el.on("keydown.adp",this._onKeyDown.bind(this)),this.$el.on("keyup.adp",this._onKeyUp.bind(this)),this.$el.on("hotKey.adp",this._onHotKey.bind(this))},_bindTimepickerEvents:function(){this.$el.on("timeChange.adp",this._onTimeChange.bind(this))},isWeekend:function(t){return-1!==this.opts.weekends.indexOf(t)},_defineLocale:function(t){"string"==typeof t?(this.loc=Datepicker.language[t],this.loc||(console.warn("Can't find language \""+t+'" in Datepicker.language, will use "ru" instead'),this.loc=e.extend(!0,{},Datepicker.language.ru)),this.loc=e.extend(!0,{},Datepicker.language.ru,Datepicker.language[t])):this.loc=e.extend(!0,{},Datepicker.language.ru,t),this.opts.dateFormat&&(this.loc.dateFormat=this.opts.dateFormat),this.opts.timeFormat&&(this.loc.timeFormat=this.opts.timeFormat),""!==this.opts.firstDay&&(this.loc.firstDay=this.opts.firstDay),this.opts.timepicker&&(this.loc.dateFormat=[this.loc.dateFormat,this.loc.timeFormat].join(this.opts.dateTimeSeparator));var i=this._getWordBoundaryRegExp;(this.loc.timeFormat.match(i("aa"))||this.loc.timeFormat.match(i("AA")))&&(this.ampm=!0)},_buildDatepickersContainer:function(){o=!0,s.append('
'),a=e("#datepickers-container")},_buildBaseHtml:function(){var t,i=e('
');t="INPUT"==this.el.nodeName?this.opts.inline?i.insertAfter(this.$el):a:i.appendTo(this.$el),this.$datepicker=e(c).appendTo(t),this.$content=e(".datepicker--content",this.$datepicker),this.$nav=e(".datepicker--nav",this.$datepicker)},_triggerOnChange:function(){if(!this.selectedDates.length)return this.opts.onSelect("","",this);var t,e=this.selectedDates,i=n.getParsedDate(e[0]),s=this,a=new Date(i.year,i.month,i.date,i.hours,i.minutes);t=e.map(function(t){return s.formatDate(s.loc.dateFormat,t)}).join(this.opts.multipleDatesSeparator),(this.opts.multipleDates||this.opts.range)&&(a=e.map(function(t){n.getParsedDate(t);return new Date(i.year,i.month,i.date,i.hours,i.minutes)})),this.opts.onSelect(t,a,this)},next:function(){var t=this.parsedDate,e=this.opts;switch(this.view){case"days":this.date=new Date(t.year,t.month+1,1),e.onChangeMonth&&e.onChangeMonth(this.parsedDate.month,this.parsedDate.year);break;case"months":this.date=new Date(t.year+1,t.month,1),e.onChangeYear&&e.onChangeYear(this.parsedDate.year);break;case"years":this.date=new Date(t.year+10,0,1),e.onChangeDecade&&e.onChangeDecade(this.curDecade)}},prev:function(){var t=this.parsedDate,e=this.opts;switch(this.view){case"days":this.date=new Date(t.year,t.month-1,1),e.onChangeMonth&&e.onChangeMonth(this.parsedDate.month,this.parsedDate.year);break;case"months":this.date=new Date(t.year-1,t.month,1),e.onChangeYear&&e.onChangeYear(this.parsedDate.year);break;case"years":this.date=new Date(t.year-10,0,1),e.onChangeDecade&&e.onChangeDecade(this.curDecade)}},formatDate:function(t,e){e=e||this.date;var i,s=t,a=this._getWordBoundaryRegExp,h=this.loc,r=n.getLeadingZeroNum,o=n.getDecade(e),c=n.getParsedDate(e),d=c.fullHours,l=c.hours,u="am";switch(this.opts.timepicker&&this.timepicker&&this.ampm&&(i=this.timepicker._getValidHoursFromDate(e),d=r(i.hours),l=i.hours,u=i.dayPeriod),!0){case/@/.test(s):s=s.replace(/@/,e.getTime());case/aa/.test(s):s=s.replace(a("aa"),u);case/AA/.test(s):s=s.replace(a("AA"),u.toUpperCase());case/dd/.test(s):s=s.replace(a("dd"),c.fullDate);case/d/.test(s):s=s.replace(a("d"),c.date);case/DD/.test(s):s=s.replace(a("DD"),h.days[c.day]);case/D/.test(s):s=s.replace(a("D"),h.daysShort[c.day]);case/mm/.test(s):s=s.replace(a("mm"),c.fullMonth);case/m/.test(s):s=s.replace(a("m"),c.month+1);case/MM/.test(s):s=s.replace(a("MM"),this.loc.months[c.month]);case/M/.test(s):s=s.replace(a("M"),h.monthsShort[c.month]);case/ii/.test(s):s=s.replace(a("ii"),c.fullMinutes);case/i/.test(s):s=s.replace(a("i"),c.minutes);case/hh/.test(s):s=s.replace(a("hh"),d);case/h/.test(s):s=s.replace(a("h"),l);case/yyyy/.test(s):s=s.replace(a("yyyy"),c.year);case/yyyy1/.test(s):s=s.replace(a("yyyy1"),o[0]);case/yyyy2/.test(s):s=s.replace(a("yyyy2"),o[1]);case/yy/.test(s):s=s.replace(a("yy"),c.year.toString().slice(-2))}return s},_getWordBoundaryRegExp:function(t){return new RegExp("\\b(?=[a-zA-Z0-9äöüßÄÖÜ<])"+t+"(?![>a-zA-Z0-9äöüßÄÖÜ])")},selectDate:function(t){var e=this,i=e.opts,s=e.parsedDate,a=e.selectedDates,n=a.length,h="";if(t instanceof Date){if(this.lastSelectedDate=t,this.timepicker&&(this.timepicker.hours=t.getHours(),this.timepicker.minutes=t.getMinutes()),e._trigger("selectDate",t),this.timepicker&&(t.setHours(this.timepicker.hours),t.setMinutes(this.timepicker.minutes)),"days"==e.view&&t.getMonth()!=s.month&&i.moveToOtherMonthsOnSelect&&(h=new Date(t.getFullYear(),t.getMonth(),1)),"years"==e.view&&t.getFullYear()!=s.year&&i.moveToOtherYearsOnSelect&&(h=new Date(t.getFullYear(),0,1)),h&&(e.silent=!0,e.date=h,e.silent=!1,e.nav._render()),i.multipleDates&&!i.range){if(n===i.multipleDates)return;e._isSelected(t)||e.selectedDates.push(t)}else i.range?2==n?(e.selectedDates=[t],e.minRange=t,e.maxRange=""):1==n?(e.selectedDates.push(t),e.maxRange?e.minRange=t:e.maxRange=t,e.selectedDates=[e.minRange,e.maxRange]):(e.selectedDates=[t],e.minRange=t):e.selectedDates=[t];e._setInputValue(),i.onSelect&&e._triggerOnChange(),i.autoClose&&(i.multipleDates||i.range?i.range&&2==e.selectedDates.length&&e.hide():e.hide()),e.views[this.currentView]._render()}},removeDate:function(t){var e=this.selectedDates,i=this;if(t instanceof Date)return e.some(function(s,a){return n.isSame(s,t)?(e.splice(a,1),i.selectedDates.length?i.lastSelectedDate=i.selectedDates[i.selectedDates.length-1]:(i.minRange="",i.maxRange="",i.lastSelectedDate=""),i.views[i.currentView]._render(),i._setInputValue(),i.opts.onSelect&&i._triggerOnChange(),!0):void 0})},today:function(){this.silent=!0,this.view=this.opts.minView,this.silent=!1,this.date=new Date},clear:function(){this.selectedDates=[],this.minRange="",this.maxRange="",this.views[this.currentView]._render(),this._setInputValue(),this.opts.onSelect&&this._triggerOnChange()},update:function(t,i){var s=arguments.length;return 2==s?this.opts[t]=i:1==s&&"object"==typeof t&&(this.opts=e.extend(!0,this.opts,t)),this._createShortCuts(),this._syncWithMinMaxDates(),this._defineLocale(this.opts.language),this.nav._addButtonsIfNeed(),this.nav._render(),this.views[this.currentView]._render(),this.elIsInput&&!this.opts.inline&&(this._setPositionClasses(this.opts.position),this.visible&&this.setPosition(this.opts.position)),this.opts.classes&&this.$datepicker.addClass(this.opts.classes),this.opts.timepicker&&(this.timepicker._handleDate(this.lastSelectedDate),this.timepicker._updateRanges(),this.timepicker._updateCurrentTime(),this.lastSelectedDate&&(this.lastSelectedDate.setHours(this.timepicker.hours),this.lastSelectedDate.setMinutes(this.timepicker.minutes))),this._setInputValue(),this},_syncWithMinMaxDates:function(){var t=this.date.getTime();this.silent=!0,this.minTime>t&&(this.date=this.minDate),this.maxTime=this.minTime&&i<=this.maxTime,month:r>=this.minTime&&o<=this.maxTime,year:s.year>=a.year&&s.year<=h.year};return e?c[e]:c.day},_getDimensions:function(t){var e=t.offset();return{width:t.outerWidth(),height:t.outerHeight(),left:e.left,top:e.top}},_getDateFromCell:function(t){var e=this.parsedDate,s=t.data("year")||e.year,a=t.data("month")==i?e.month:t.data("month"),n=t.data("date")||1;return new Date(s,a,n)},_setPositionClasses:function(t){t=t.split(" ");var e=t[0],i=t[1],s="datepicker -"+e+"-"+i+"- -from-"+e+"-";this.visible&&(s+=" active"),this.$datepicker.removeAttr("class").addClass(s)},setPosition:function(t){t=t||this.opts.position;var e,i,s=this._getDimensions(this.$el),a=this._getDimensions(this.$datepicker),n=t.split(" "),h=this.opts.offset,r=n[0],o=n[1];switch(r){case"top":e=s.top-a.height-h;break;case"right":i=s.left+s.width+h;break;case"bottom":e=s.top+s.height+h;break;case"left":i=s.left-a.width-h}switch(o){case"top":e=s.top;break;case"right":i=s.left+s.width-a.width;break;case"bottom":e=s.top+s.height-a.height;break;case"left":i=s.left;break;case"center":/left|right/.test(r)?e=s.top+s.height/2-a.height/2:i=s.left+s.width/2-a.width/2}this.$datepicker.css({left:i,top:e})},show:function(){this.setPosition(this.opts.position),this.$datepicker.addClass("active"),this.visible=!0},hide:function(){this.$datepicker.removeClass("active").css({left:"-100000px"}),this.focused="",this.keys=[],this.inFocus=!1,this.visible=!1,this.$el.blur()},down:function(t){this._changeView(t,"down")},up:function(t){this._changeView(t,"up")},_changeView:function(t,e){t=t||this.focused||this.date;var i="up"==e?this.viewIndex+1:this.viewIndex-1;i>2&&(i=2),0>i&&(i=0),this.silent=!0,this.date=new Date(t.getFullYear(),t.getMonth(),1),this.silent=!1,this.view=this.viewIndexes[i]},_handleHotKey:function(t){var e,i,s,a=n.getParsedDate(this._getFocusedDate()),h=this.opts,r=!1,o=!1,c=!1,d=a.year,l=a.month,u=a.date;switch(t){case"ctrlRight":case"ctrlUp":l+=1,r=!0;break;case"ctrlLeft":case"ctrlDown":l-=1,r=!0;break;case"shiftRight":case"shiftUp":o=!0,d+=1;break;case"shiftLeft":case"shiftDown":o=!0,d-=1;break;case"altRight":case"altUp":c=!0,d+=10;break;case"altLeft":case"altDown":c=!0,d-=10;break;case"ctrlShiftUp":this.up()}s=n.getDaysCount(new Date(d,l)),i=new Date(d,l,u),u>s&&(u=s),i.getTime()this.maxTime&&(i=this.maxDate),this.focused=i,e=n.getParsedDate(i),r&&h.onChangeMonth&&h.onChangeMonth(e.month,e.year),o&&h.onChangeYear&&h.onChangeYear(e.year),c&&h.onChangeDecade&&h.onChangeDecade(this.curDecade)},_registerKey:function(t){var e=this.keys.some(function(e){return e==t});e||this.keys.push(t)},_unRegisterKey:function(t){var e=this.keys.indexOf(t);this.keys.splice(e,1)},_isHotKeyPressed:function(){var t,e=!1,i=this,s=this.keys.sort();for(var a in l)t=l[a],s.length==t.length&&t.every(function(t,e){return t==s[e]})&&(i._trigger("hotKey",a),e=!0);return e},_trigger:function(t,e){this.$el.trigger(t,e)},_focusNextCell:function(t,e){e=e||this.cellType;var i=n.getParsedDate(this._getFocusedDate()),s=i.year,a=i.month,h=i.date;if(!this._isHotKeyPressed()){switch(t){case 37:"day"==e?h-=1:"","month"==e?a-=1:"","year"==e?s-=1:"";break;case 38:"day"==e?h-=7:"","month"==e?a-=3:"","year"==e?s-=4:"";break;case 39:"day"==e?h+=1:"","month"==e?a+=1:"","year"==e?s+=1:"";break;case 40:"day"==e?h+=7:"","month"==e?a+=3:"","year"==e?s+=4:""}var r=new Date(s,a,h);r.getTime()this.maxTime&&(r=this.maxDate),this.focused=r}},_getFocusedDate:function(){var t=this.focused||this.selectedDates[this.selectedDates.length-1],e=this.parsedDate;if(!t)switch(this.view){case"days":t=new Date(e.year,e.month,(new Date).getDate());break;case"months":t=new Date(e.year,e.month,1);break;case"years":t=new Date(e.year,0,1)}return t},_getCell:function(t,e){e=e||this.cellType;var i,s=n.getParsedDate(t),a='.datepicker--cell[data-year="'+s.year+'"]';switch(e){case"month":a='[data-month="'+s.month+'"]';break;case"day":a+='[data-month="'+s.month+'"][data-date="'+s.date+'"]'}return i=this.views[this.currentView].$el.find(a),i.length?i:""},destroy:function(){var t=this;t.$el.off(".adp").data("datepicker",""),t.selectedDates=[],t.focused="",t.views={},t.keys=[],t.minRange="",t.maxRange="",t.opts.inline||!t.elIsInput?t.$datepicker.closest(".datepicker-inline").remove():t.$datepicker.remove()},_onShowEvent:function(){this.visible||this.show()},_onBlur:function(){!this.inFocus&&this.visible&&this.hide()},_onMouseDownDatepicker:function(t){this.inFocus=!0},_onMouseUpDatepicker:function(t){this.inFocus=!1,t.originalEvent.inFocus=!0,t.originalEvent.timepickerFocus||this.$el.focus()},_onInput:function(){var t=this.$el.val();t||this.clear()},_onResize:function(){this.visible&&this.setPosition()},_onMouseUpBody:function(t){t.originalEvent.inFocus||this.visible&&!this.inFocus&&this.hide()},_onMouseUpEl:function(t){t.originalEvent.inFocus=!0},_onKeyDown:function(t){var e=t.which;if(this._registerKey(e),e>=37&&40>=e&&(t.preventDefault(),this._focusNextCell(e)),13==e&&this.focused){if(this._getCell(this.focused).hasClass("-disabled-"))return;if(this.view!=this.opts.minView)this.down();else{var i=this._isSelected(this.focused,this.cellType);i?i&&this.opts.toggleSelected&&this.removeDate(this.focused):this.selectDate(this.focused)}}27==e&&this.hide()},_onKeyUp:function(t){var e=t.which;this._unRegisterKey(e)},_onHotKey:function(t,e){this._handleHotKey(e)},_onMouseEnterCell:function(t){var i=e(t.target).closest(".datepicker--cell"),s=this._getDateFromCell(i);this.silent=!0,this.focused&&(this.focused=""),i.addClass("-focus-"),this.focused=s,this.silent=!1,this.opts.range&&1==this.selectedDates.length&&(this.minRange=this.selectedDates[0],this.maxRange="",n.less(this.minRange,this.focused)&&(this.maxRange=this.minRange,this.minRange=""),this.views[this.currentView]._update())},_onMouseLeaveCell:function(t){var i=e(t.target).closest(".datepicker--cell");i.removeClass("-focus-"),this.silent=!0,this.focused="",this.silent=!1},_onTimeChange:function(t,e,i){var s=new Date,a=this.selectedDates,n=!1;a.length&&(n=!0,s=this.lastSelectedDate),s.setHours(e),s.setMinutes(i),n||this._getCell(s).hasClass("-disabled-")?(this._setInputValue(),this.opts.onSelect&&this._triggerOnChange()):this.selectDate(s)},_onClickCell:function(t,e){this.timepicker&&(e.setHours(this.timepicker.hours),e.setMinutes(this.timepicker.minutes)),this.selectDate(e)},set focused(t){if(!t&&this.focused){var e=this._getCell(this.focused);e.length&&e.removeClass("-focus-")}this._focused=t,this.opts.range&&1==this.selectedDates.length&&(this.minRange=this.selectedDates[0],this.maxRange="",n.less(this.minRange,this._focused)&&(this.maxRange=this.minRange,this.minRange="")),this.silent||(this.date=t)},get focused(){return this._focused},get parsedDate(){return n.getParsedDate(this.date)},set date(t){return t instanceof Date?(this.currentDate=t,this.inited&&!this.silent&&(this.views[this.view]._render(),this.nav._render(),this.visible&&this.elIsInput&&this.setPosition()),t):void 0},get date(){return this.currentDate},set view(t){return this.viewIndex=this.viewIndexes.indexOf(t),this.viewIndex<0?void 0:(this.prevView=this.currentView,this.currentView=t,this.inited&&(this.views[t]?this.views[t]._render():this.views[t]=new Datepicker.Body(this,t,this.opts),this.views[this.prevView].hide(),this.views[t].show(),this.nav._render(),this.opts.onChangeView&&this.opts.onChangeView(t),this.elIsInput&&this.visible&&this.setPosition()),t)},get view(){return this.currentView},get cellType(){return this.view.substring(0,this.view.length-1)},get minTime(){var t=n.getParsedDate(this.minDate);return new Date(t.year,t.month,t.date).getTime()},get maxTime(){var t=n.getParsedDate(this.maxDate);return new Date(t.year,t.month,t.date).getTime()},get curDecade(){return n.getDecade(this.date)}},n.getDaysCount=function(t){return new Date(t.getFullYear(),t.getMonth()+1,0).getDate()},n.getParsedDate=function(t){return{year:t.getFullYear(),month:t.getMonth(),fullMonth:t.getMonth()+1<10?"0"+(t.getMonth()+1):t.getMonth()+1,date:t.getDate(),fullDate:t.getDate()<10?"0"+t.getDate():t.getDate(),day:t.getDay(),hours:t.getHours(),fullHours:t.getHours()<10?"0"+t.getHours():t.getHours(),minutes:t.getMinutes(),fullMinutes:t.getMinutes()<10?"0"+t.getMinutes():t.getMinutes()}},n.getDecade=function(t){var e=10*Math.floor(t.getFullYear()/10);return[e,e+9]},n.template=function(t,e){return t.replace(/#\{([\w]+)\}/g,function(t,i){return e[i]||0===e[i]?e[i]:void 0})},n.isSame=function(t,e,i){if(!t||!e)return!1;var s=n.getParsedDate(t),a=n.getParsedDate(e),h=i?i:"day",r={day:s.date==a.date&&s.month==a.month&&s.year==a.year,month:s.month==a.month&&s.year==a.year,year:s.year==a.year};return r[h]},n.less=function(t,e,i){return t&&e?e.getTime()t.getTime():!1},n.getLeadingZeroNum=function(t){return parseInt(t)<10?"0"+t:t},Datepicker.language={ru:{days:["Воскресенье","Понедельник","Вторник","Среда","Четверг","Пятница","Суббота"],daysShort:["Вос","Пон","Вто","Сре","Чет","Пят","Суб"],daysMin:["Вс","Пн","Вт","Ср","Чт","Пт","Сб"],months:["Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь","Декабрь"],monthsShort:["Янв","Фев","Мар","Апр","Май","Июн","Июл","Авг","Сен","Окт","Ноя","Дек"],today:"Сегодня",clear:"Очистить",dateFormat:"dd.mm.yyyy",timeFormat:"hh:ii",firstDay:1}},e.fn[h]=function(t){return this.each(function(){if(e.data(this,h)){var i=e.data(this,h);i.opts=e.extend(!0,i.opts,t),i.update()}else e.data(this,h,new Datepicker(this,t))})},e(function(){e(r).datepicker()})}(),function(){var t={days:'
',months:'
',years:'
'},s=Datepicker;s.Body=function(t,e,i){this.d=t,this.type=e,this.opts=i,this.init()},s.Body.prototype={init:function(){this._buildBaseHtml(),this._render(),this._bindEvents()},_bindEvents:function(){this.$el.on("click",".datepicker--cell",e.proxy(this._onClickCell,this))},_buildBaseHtml:function(){this.$el=e(t[this.type]).appendTo(this.d.$content),this.$names=e(".datepicker--days-names",this.$el),this.$cells=e(".datepicker--cells",this.$el)},_getDayNamesHtml:function(t,e,s,a){return e=e!=i?e:t,s=s?s:"",a=a!=i?a:0,a>7?s:7==e?this._getDayNamesHtml(t,0,s,++a):(s+='
'+this.d.loc.daysMin[e]+"
",this._getDayNamesHtml(t,++e,s,++a))},_getCellContents:function(t,e){var i="datepicker--cell datepicker--cell-"+e,a=new Date,n=this.d,h=n.opts,r=s.getParsedDate(t),o={},c=r.date;switch(h.onRenderCell&&(o=h.onRenderCell(t,e)||{},c=o.html?o.html:c,i+=o.classes?" "+o.classes:""),e){case"day":n.isWeekend(r.day)&&(i+=" -weekend-"),r.month!=this.d.parsedDate.month&&(i+=" -other-month-",h.selectOtherMonths||(i+=" -disabled-"),h.showOtherMonths||(c=""));break;case"month":c=n.loc[n.opts.monthsField][r.month];break;case"year":var d=n.curDecade;c=r.year,(r.yeard[1])&&(i+=" -other-decade-",h.selectOtherYears||(i+=" -disabled-"),h.showOtherYears||(c=""))}return h.onRenderCell&&(o=h.onRenderCell(t,e)||{},c=o.html?o.html:c,i+=o.classes?" "+o.classes:""),h.range&&(s.isSame(n.minRange,t,e)&&(i+=" -range-from-"),s.isSame(n.maxRange,t,e)&&(i+=" -range-to-"),1==n.selectedDates.length&&n.focused?((s.bigger(n.minRange,t)&&s.less(n.focused,t)||s.less(n.maxRange,t)&&s.bigger(n.focused,t))&&(i+=" -in-range-"),s.less(n.maxRange,t)&&s.isSame(n.focused,t)&&(i+=" -range-from-"),s.bigger(n.minRange,t)&&s.isSame(n.focused,t)&&(i+=" -range-to-")):2==n.selectedDates.length&&s.bigger(n.minRange,t)&&s.less(n.maxRange,t)&&(i+=" -in-range-")),s.isSame(a,t,e)&&(i+=" -current-"),n.focused&&s.isSame(t,n.focused,e)&&(i+=" -focus-"),n._isSelected(t,e)&&(i+=" -selected-"),(!n._isInRange(t,e)||o.disabled)&&(i+=" -disabled-"),{html:c,classes:i}},_getDaysHtml:function(t){var e=s.getDaysCount(t),i=new Date(t.getFullYear(),t.getMonth(),1).getDay(),a=new Date(t.getFullYear(),t.getMonth(),e).getDay(),n=i-this.d.loc.firstDay,h=6-a+this.d.loc.firstDay;n=0>n?n+7:n,h=h>6?h-7:h;for(var r,o,c=-n+1,d="",l=c,u=e+h;u>=l;l++)o=t.getFullYear(),r=t.getMonth(),d+=this._getDayHtml(new Date(o,r,l));return d},_getDayHtml:function(t){var e=this._getCellContents(t,"day");return'
'+e.html+"
"},_getMonthsHtml:function(t){for(var e="",i=s.getParsedDate(t),a=0;12>a;)e+=this._getMonthHtml(new Date(i.year,a)),a++;return e},_getMonthHtml:function(t){var e=this._getCellContents(t,"month");return'
'+e.html+"
"},_getYearsHtml:function(t){var e=(s.getParsedDate(t),s.getDecade(t)),i=e[0]-1,a="",n=i;for(n;n<=e[1]+1;n++)a+=this._getYearHtml(new Date(n,0));return a},_getYearHtml:function(t){var e=this._getCellContents(t,"year");return'
'+e.html+"
"},_renderTypes:{days:function(){var t=this._getDayNamesHtml(this.d.loc.firstDay),e=this._getDaysHtml(this.d.currentDate);this.$cells.html(e),this.$names.html(t)},months:function(){var t=this._getMonthsHtml(this.d.currentDate);this.$cells.html(t)},years:function(){var t=this._getYearsHtml(this.d.currentDate);this.$cells.html(t)}},_render:function(){this._renderTypes[this.type].bind(this)()},_update:function(){var t,i,s,a=e(".datepicker--cell",this.$cells),n=this;a.each(function(a,h){i=e(this),s=n.d._getDateFromCell(e(this)),t=n._getCellContents(s,n.d.cellType),i.attr("class",t.classes)})},show:function(){this.$el.addClass("active"),this.acitve=!0},hide:function(){this.$el.removeClass("active"),this.active=!1},_handleClick:function(t){var e=t.data("date")||1,i=t.data("month")||0,s=t.data("year")||this.d.parsedDate.year;if(this.d.view!=this.opts.minView)return void this.d.down(new Date(s,i,e));var a=new Date(s,i,e),n=this.d._isSelected(a,this.d.cellType);n?n&&this.opts.toggleSelected&&this.d.removeDate(a):this.d._trigger("clickCell",a)},_onClickCell:function(t){var i=e(t.target).closest(".datepicker--cell");i.hasClass("-disabled-")||this._handleClick.bind(this)(i)}}}(),function(){var t='
#{prevHtml}
#{title}
#{nextHtml}
',i='
',s='#{label}';Datepicker.Navigation=function(t,e){this.d=t,this.opts=e,this.$buttonsContainer="",this.init()},Datepicker.Navigation.prototype={init:function(){this._buildBaseHtml(),this._bindEvents()},_bindEvents:function(){this.d.$nav.on("click",".datepicker--nav-action",e.proxy(this._onClickNavButton,this)),this.d.$nav.on("click",".datepicker--nav-title",e.proxy(this._onClickNavTitle,this)),this.d.$datepicker.on("click",".datepicker--button",e.proxy(this._onClickNavButton,this))},_buildBaseHtml:function(){this._render(),this._addButtonsIfNeed()},_addButtonsIfNeed:function(){this.opts.todayButton&&this._addButton("today"),this.opts.clearButton&&this._addButton("clear")},_render:function(){var i=this._getTitle(this.d.currentDate),s=Datepicker.template(t,e.extend({title:i},this.opts));this.d.$nav.html(s),"years"==this.d.view&&e(".datepicker--nav-title",this.d.$nav).addClass("-disabled-"),this.setNavStatus()},_getTitle:function(t){return this.d.formatDate(this.opts.navTitles[this.d.view],t)},_addButton:function(t){this.$buttonsContainer.length||this._addButtonsContainer();var i={action:t,label:this.d.loc[t]},a=Datepicker.template(s,i);e("[data-action="+t+"]",this.$buttonsContainer).length||this.$buttonsContainer.append(a)},_addButtonsContainer:function(){this.d.$datepicker.append(i),this.$buttonsContainer=e(".datepicker--buttons",this.d.$datepicker)},setNavStatus:function(){if((this.opts.minDate||this.opts.maxDate)&&this.opts.disableNavWhenOutOfRange){var t=this.d.parsedDate,e=t.month,i=t.year,s=t.date;switch(this.d.view){case"days":this.d._isInRange(new Date(i,e-1,s),"month")||this._disableNav("prev"),this.d._isInRange(new Date(i,e+1,s),"month")||this._disableNav("next");break;case"months":this.d._isInRange(new Date(i-1,e,s),"year")||this._disableNav("prev"),this.d._isInRange(new Date(i+1,e,s),"year")||this._disableNav("next");break;case"years":this.d._isInRange(new Date(i-10,e,s),"year")||this._disableNav("prev"),this.d._isInRange(new Date(i+10,e,s),"year")||this._disableNav("next")}}},_disableNav:function(t){e('[data-action="'+t+'"]',this.d.$nav).addClass("-disabled-")},_activateNav:function(t){e('[data-action="'+t+'"]',this.d.$nav).removeClass("-disabled-")},_onClickNavButton:function(t){var i=e(t.target).closest("[data-action]"),s=i.data("action");this.d[s]()},_onClickNavTitle:function(t){return e(t.target).hasClass("-disabled-")?void 0:"days"==this.d.view?this.d.view="months":void(this.d.view="years")}}}(),function(){var t='
#{hourValue} : #{minValue}
',i=Datepicker;i.Timepicker=function(t,e){this.d=t,this.opts=e,this.init()},i.Timepicker.prototype={init:function(){var t="input";this._setInitialTime(this.d.date),this._buildHTML(),navigator.userAgent.match(/trident/gi)&&(t="change"),this.d.$el.on("selectDate",this._onSelectDate.bind(this)),this.$ranges.on(t,this._onChangeRange.bind(this)),this.$ranges.on("mouseenter",this._onMouseEnterRange.bind(this)),this.$ranges.on("mouseout blur",this._onMouseOutRange.bind(this))},_setInitialTime:function(t,e){var s=i.getParsedDate(t);this._handleDate(t),this.hours=s.hourst?0:i.minHours,this.minMinutes=i.minMinutes<0||i.minMinutes>e?0:i.minMinutes,this.maxHours=i.maxHours<0||i.maxHours>t?t:i.maxHours,this.maxMinutes=i.maxMinutes<0||i.maxMinutes>e?e:i.maxMinutes},_validateHoursMinutes:function(t){this.hoursthis.maxHours&&(this.hours=this.maxHours),this.minutesthis.maxMinutes&&(this.minutes=this.maxMinutes)},_buildHTML:function(){var s=i.getLeadingZeroNum,a={hourMin:this.minHours,hourMax:s(this.maxHours),hourStep:this.opts.hoursStep,hourValue:s(this.displayHours),minMin:this.minMinutes,minMax:s(this.maxMinutes),minStep:this.opts.minutesStep,minValue:s(this.minutes)},n=i.template(t,a);this.$timepicker=e(n).appendTo(this.d.$datepicker),this.$ranges=e('[type="range"]',this.$timepicker),this.$hours=e('[name="hours"]',this.$timepicker),this.$minutes=e('[name="minutes"]',this.$timepicker),this.$hoursText=e(".datepicker--time-current-hours",this.$timepicker),this.$minutesText=e(".datepicker--time-current-minutes",this.$timepicker),this.d.ampm&&(this.$ampm=e('').appendTo(e(".datepicker--time-current",this.$timepicker)).html(this.dayPeriod),this.$timepicker.addClass("-am-pm-"))},_updateCurrentTime:function(){var t=i.getLeadingZeroNum(this.displayHours),e=i.getLeadingZeroNum(this.minutes);this.$hoursText.html(t),this.$minutesText.html(e),this.d.ampm&&this.$ampm.html(this.dayPeriod)},_updateRanges:function(){this.$hours.attr({min:this.minHours,max:this.maxHours,value:this.hours}),this.$minutes.attr({min:this.minMinutes,max:this.maxMinutes,value:this.minutes})},_handleDate:function(t){ +this._setDefaultMinMaxTime(),t&&(i.isSame(t,this.d.opts.minDate)?this._setMinTimeFromDate(this.d.opts.minDate):i.isSame(t,this.d.opts.maxDate)&&this._setMaxTimeFromDate(this.d.opts.maxDate)),this._validateHoursMinutes(t)},update:function(){this._updateRanges(),this._updateCurrentTime()},_getValidHoursFromDate:function(t){var e=t,s=t;t instanceof Date&&(e=i.getParsedDate(t),s=e.hours);var a=this.d.ampm,n="am";if(a)switch(!0){case 0==s:s=12;break;case 12==s:n="pm";break;case s>11:s-=12,n="pm"}return{hours:s,dayPeriod:n}},set hours(t){this._hours=t;var e=this._getValidHoursFromDate(t);this.displayHours=e.hours,this.dayPeriod=e.dayPeriod},get hours(){return this._hours},_onChangeRange:function(t){var i=e(t.target),s=i.attr("name");this[s]=i.val(),this._updateCurrentTime(),this.d._trigger("timeChange",[this.hours,this.minutes])},_onSelectDate:function(t,e){this._handleDate(e),this.update()},_onMouseEnterRange:function(t){var i=e(t.target).attr("name");e(".datepicker--time-current-"+i,this.$timepicker).addClass("-focus-")},_onMouseOutRange:function(t){var i=e(t.target).attr("name");this.d.inFocus||e(".datepicker--time-current-"+i,this.$timepicker).removeClass("-focus-")}}}()}(window,jQuery); \ No newline at end of file diff --git a/src/js/timepicker.js b/src/js/timepicker.js index d6606a4..8810567 100644 --- a/src/js/timepicker.js +++ b/src/js/timepicker.js @@ -1,4 +1,4 @@ -(function (window, $, datepicker) { +;(function () { var template = '
' + '
' + ' #{hourValue}' + @@ -13,7 +13,8 @@ ' ' + '
' + '
' + - '
'; + '
', + datepicker = Datepicker; datepicker.Timepicker = function (inst, opts) { this.d = inst; @@ -249,4 +250,4 @@ $('.datepicker--time-current-' + name, this.$timepicker).removeClass('-focus-'); } }; -})(window, jQuery, Datepicker); +})()