ngx-animating-datepicker
Version:
An Animating Datepicker for Angular 2+, for some smooth date picking :).
1,554 lines (1,549 loc) • 210 kB
JavaScript
import { Injectable, Component, ElementRef, EventEmitter, HostBinding, Input, Output, ViewChild, ApplicationRef, ComponentFactoryResolver, Directive, HostListener, Injector, Optional, Renderer2, ViewContainerRef, NgModule } from '@angular/core';
import { __assign, __spread, __extends } from 'tslib';
import { NgControl } from '@angular/forms';
import { CommonModule } from '@angular/common';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var DatepickerService = /** @class */ (function () {
function DatepickerService() {
}
/**
* Get the formatted weekdays
*
* @param language
* @param format
* @param start
*/
/**
* Get the formatted weekdays
*
* @param {?} language
* @param {?} format
* @param {?} start
* @return {?}
*/
DatepickerService.getWeekDays = /**
* Get the formatted weekdays
*
* @param {?} language
* @param {?} format
* @param {?} start
* @return {?}
*/
function (language, format, start) {
/** @type {?} */
var days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
/** @type {?} */
var index = days.indexOf(start.toLowerCase());
if (index < 0) {
throw new Error('Invalid week day start: ' + start);
}
/** @type {?} */
var weekdays = [];
for (var day = 5; day <= 11; day++) {
weekdays.push(new Date(1970, 1 - 1, day + index).toLocaleString(language, { weekday: format }));
}
return weekdays;
};
/**
* Checks if is a value iso code
*
* @param isoCode
*/
/**
* Checks if is a value iso code
*
* @param {?} isoCode
* @return {?}
*/
DatepickerService.isValidIsoCode = /**
* Checks if is a value iso code
*
* @param {?} isoCode
* @return {?}
*/
function (isoCode) {
/** @type {?} */
var pattern = new RegExp(/([a-z]{2})-([A-Z]{2})/);
return pattern.test(isoCode);
};
/**
* Create a week array from the merged day arrays
*
* @param dayArray
*/
/**
* Create a week array from the merged day arrays
*
* @param {?} dayArray
* @return {?}
*/
DatepickerService.createWeekArray = /**
* Create a week array from the merged day arrays
*
* @param {?} dayArray
* @return {?}
*/
function (dayArray) {
/** @type {?} */
var size = 7;
/** @type {?} */
var weeks = [];
while (dayArray.length) {
weeks.push({
days: dayArray.splice(0, size)
});
}
return weeks;
};
/**
* @param {?} year
* @param {?} month
* @return {?}
*/
DatepickerService.getDaysInMonth = /**
* @param {?} year
* @param {?} month
* @return {?}
*/
function (year, month) {
return [31, DatepickerService.isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
};
/**
* @param {?} value
* @return {?}
*/
DatepickerService.isValidDate = /**
* @param {?} value
* @return {?}
*/
function (value) {
/** @type {?} */
var validDate = true;
for (var i = 0; i < value.length; i++) {
if (!DatepickerService.isDate(value[i]) && validDate) {
validDate = false;
}
}
return validDate;
};
/**
* Check if year is a leap year
*
* @param year
*/
/**
* Check if year is a leap year
*
* @param {?} year
* @return {?}
*/
DatepickerService.isLeapYear = /**
* Check if year is a leap year
*
* @param {?} year
* @return {?}
*/
function (year) {
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
};
/**
* Checks to see if value is a valid date
*
* @param value
*/
/**
* Checks to see if value is a valid date
*
* @param {?} value
* @return {?}
*/
DatepickerService.isDate = /**
* Checks to see if value is a valid date
*
* @param {?} value
* @return {?}
*/
function (value) {
return value instanceof Date;
};
/**
* Get the year of the next month
*
* @param year
* @param month
*/
/**
* Get the year of the next month
*
* @param {?} year
* @param {?} month
* @return {?}
*/
DatepickerService.getYearOfNextMonth = /**
* Get the year of the next month
*
* @param {?} year
* @param {?} month
* @return {?}
*/
function (year, month) {
return month === 11 ? year + 1 : year;
};
/**
* Get the next month
*
* @param month
*/
/**
* Get the next month
*
* @param {?} month
* @return {?}
*/
DatepickerService.getNextMonth = /**
* Get the next month
*
* @param {?} month
* @return {?}
*/
function (month) {
return month === 11 ? 0 : month + 1;
};
/**
* Get the year of the previous month
*
* @param year
* @param month
*/
/**
* Get the year of the previous month
*
* @param {?} year
* @param {?} month
* @return {?}
*/
DatepickerService.getYearOfPreviousMonth = /**
* Get the year of the previous month
*
* @param {?} year
* @param {?} month
* @return {?}
*/
function (year, month) {
return month === 0 ? year - 1 : year;
};
/**
* Get previous motnh
*
* @param month
*/
/**
* Get previous motnh
*
* @param {?} month
* @return {?}
*/
DatepickerService.getPreviousMonth = /**
* Get previous motnh
*
* @param {?} month
* @return {?}
*/
function (month) {
return month === 0 ? 11 : month - 1;
};
/**
* Check if a date is later
*
* @param date
* @param compareDate
*/
/**
* Check if a date is later
*
* @param {?} date
* @param {?} compareDate
* @return {?}
*/
DatepickerService.isLater = /**
* Check if a date is later
*
* @param {?} date
* @param {?} compareDate
* @return {?}
*/
function (date, compareDate) {
return date > compareDate;
};
/**
* Check if a date is ealrier
*
* @param date
* @param compareDate
*/
/**
* Check if a date is ealrier
*
* @param {?} date
* @param {?} compareDate
* @return {?}
*/
DatepickerService.isEarlier = /**
* Check if a date is ealrier
*
* @param {?} date
* @param {?} compareDate
* @return {?}
*/
function (date, compareDate) {
return date < compareDate;
};
DatepickerService.decorators = [
{ type: Injectable },
];
return DatepickerService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var UtilitiesService = /** @class */ (function () {
function UtilitiesService() {
}
/**
* @private
* @return {?}
*/
UtilitiesService.getScrollOffset = /**
* @private
* @return {?}
*/
function () {
/** @type {?} */
var x = window.pageXOffset || document.documentElement.scrollLeft;
/** @type {?} */
var y = window.pageYOffset || document.documentElement.scrollTop;
return { x: x, y: y };
};
/**
* @param {?} el
* @return {?}
*/
UtilitiesService.getPageOffset = /**
* @param {?} el
* @return {?}
*/
function (el) {
/** @type {?} */
var scrollOffset = UtilitiesService.getScrollOffset();
/** @type {?} */
var width = el.offsetWidth;
/** @type {?} */
var height = el.offsetHeight;
if (el.getBoundingClientRect) {
/** @type {?} */
var props = el.getBoundingClientRect();
/** @type {?} */
var position = {
top: props.top + scrollOffset.y,
left: props.left + scrollOffset.x,
right: props.left + scrollOffset.x + width,
bottom: props.top + scrollOffset.y + height,
forRight: window.innerWidth - props.left,
forBottom: window.innerHeight - (props.top + scrollOffset.y)
};
return position;
}
};
/**
* @param {?} start
* @param {?} end
* @return {?}
*/
UtilitiesService.prototype.createArray = /**
* @param {?} start
* @param {?} end
* @return {?}
*/
function (start, end) {
return new Array(end - start + 1).fill(1).map(function (_, idx) { return start + idx; });
};
UtilitiesService.decorators = [
{ type: Injectable },
];
return UtilitiesService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var DefaultOptions = {
selectMultiple: false,
// Select multiple dates
closeOnSelect: false,
// Close datepicker when date(s) selected
animationSpeed: 400,
// Animation speed in ms
easing: 'ease-in',
// Easing type string
hideRestDays: false,
// Hide the rest days
disableRestDays: true,
// Disable the click on rest days
hideNavigation: false,
// Hide the navigation
range: false,
// Use range functionality
currentDate: new Date(),
// Tne current displayed date (month, year)
timeoutBeforeClosing: 300,
// The timeout / delay before closing
weekdayFormat: 'short',
// "narrow", "short", "long"
weekStart: 'monday' // Set the week start day
};
/** @type {?} */
var DefaultDirectiveOptions = {
appendToBody: true,
// Append Datepicker to body
openDirection: 'bottom',
// The direction it should open to
closeOnBlur: true,
// Close the datepicker onBlur
useAnimatePicker: true // Use the animatepickerComponent
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var DatepickerComponent = /** @class */ (function () {
function DatepickerComponent(utils, element) {
this.utils = utils;
this.element = element;
/* ==============================================
* Internal Properties
* ============================================== */
this.date = new Date();
this.year = null;
this.month = null;
this.today = this.date;
this.months = null;
this.weekdays = ['M', 'T', 'W', 'T', 'F', 'S', 'S'];
this.selectedRange = 'startDate';
this.startDate = null;
this.endDate = null;
this.initialised = false;
this.weekStartArray = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
/* ==============================================
* Initial Options
* ============================================== */
this._options = DefaultOptions;
/* ==============================================
* External Properties
* ============================================== */
/**
* Set the the language manualy. A string with a BCP 47 language tag
* @example nl-NL
*/
this._language = navigator.language;
/**
* Minimal Date: If set the dates before it will be disabled
*/
this._minDate = null;
/**
* Maximal Date: If set the dates after it will be disabled
*/
this._maxDate = null;
/**
* Selected Dates: handles the selected dates array. Can be set both internally and externally
*/
this._selectedDates = [];
this.selectedDatesChange = new EventEmitter();
this.theme = '';
this.isOpen = true;
this.asDirective = false;
this.animate = false;
this.topPosition = null;
this.leftPosition = null;
this.bottomPosition = null;
this.rightPosition = null;
}
Object.defineProperty(DatepickerComponent.prototype, "options", {
get: /**
* @return {?}
*/
function () {
return this._options;
},
set: /**
* @param {?} options
* @return {?}
*/
function (options) {
if (options === undefined || !options) {
return;
}
this._options = __assign({}, this._options, options);
if (options.currentDate !== undefined) {
this.date = this.options.currentDate;
}
if (this.initialised) {
this.goToDate();
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(DatepickerComponent.prototype, "language", {
get: /**
* @return {?}
*/
function () {
return this._language;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
if (!value || value === undefined || !DatepickerService.isValidIsoCode(value)) {
return;
}
this._language = value;
this.renderWeekdays();
},
enumerable: true,
configurable: true
});
Object.defineProperty(DatepickerComponent.prototype, "minDate", {
get: /**
* @return {?}
*/
function () {
return this._minDate;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
if (value === undefined || value === this._minDate) {
return;
}
this._minDate = new Date(value);
this.goToDate();
},
enumerable: true,
configurable: true
});
Object.defineProperty(DatepickerComponent.prototype, "maxDate", {
get: /**
* @return {?}
*/
function () {
return this._maxDate;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
if (value === undefined || value === this._minDate) {
return;
}
this._maxDate = new Date(value);
this.goToDate();
},
enumerable: true,
configurable: true
});
Object.defineProperty(DatepickerComponent.prototype, "selectedDates", {
get: /**
* @return {?}
*/
function () {
return this._selectedDates;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
/** @type {?} */
var _value = Array.isArray(value) ? value : [value];
if (!DatepickerService.isValidDate(_value)) {
return;
}
this._selectedDates = _value;
if (this.options.range) {
this.resetRange();
}
this.goToDate();
this.selectedDatesChange.emit(this._selectedDates);
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
DatepickerComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
this.initialised = true;
if (!this.month && !this.year) {
this.goToDate(this.options.currentDate);
}
};
/**
* Creates a day array
*
* @param year
* @param month
* @param isRestDays
*/
/**
* Creates a day array
*
* @param {?} year
* @param {?} month
* @param {?=} isRestDays
* @return {?}
*/
DatepickerComponent.prototype.createDayArray = /**
* Creates a day array
*
* @param {?} year
* @param {?} month
* @param {?=} isRestDays
* @return {?}
*/
function (year, month, isRestDays) {
/** @type {?} */
var days = [];
/** @type {?} */
var daysInMonth = DatepickerService.getDaysInMonth(year, month);
for (var index = 0; index < daysInMonth; index++) {
/** @type {?} */
var dayNumber = index + 1;
/** @type {?} */
var date = new Date(year, month, dayNumber);
/** @type {?} */
var day = {
date: date,
dayNumber: dayNumber,
isFirst: dayNumber === 1,
isLast: dayNumber === daysInMonth,
isToday: this.isToday(date),
isSelected: this.isSelected(date),
isRest: isRestDays,
isHidden: isRestDays && this.options.hideRestDays,
isDisabled: ((this.minDate || this.maxDate) && this.isDisabled(date)) ||
(isRestDays && this.options.disableRestDays),
isInRange: this.isInRange(date) ||
((this.isStartDate(date) || this.isEndDate(date)) && this.startDate && this.endDate),
isStartDate: this.isStartDate(date),
isEndDate: this.isEndDate(date)
};
days.push(day);
}
return days;
};
/**
* Get the days from the next month
*
* @param year
* @param month
*/
/**
* Get the days from the next month
*
* @param {?} year
* @param {?} month
* @return {?}
*/
DatepickerComponent.prototype.getNextRestDays = /**
* Get the days from the next month
*
* @param {?} year
* @param {?} month
* @return {?}
*/
function (year, month) {
/** @type {?} */
var monthLength = DatepickerService.getDaysInMonth(year, month);
/** @type {?} */
var weekStartIndex = this.weekStartArray.indexOf(this.options.weekStart);
// Get the end of the month number minus the week start index
/** @type {?} */
var endOfTheMonth = new Date(year, month, monthLength).getDay() - weekStartIndex;
// Flip minus to plus when the end month number is minus.
// this occurs when there are less rest days then the week start index
/** @type {?} */
var _endOfTheMonth = endOfTheMonth < 0 ? 7 - Math.abs(endOfTheMonth) : endOfTheMonth;
/** @type {?} */
var nextDays = this.createDayArray(DatepickerService.getYearOfNextMonth(year, month), DatepickerService.getNextMonth(month), true).slice(0, 7 - _endOfTheMonth);
return nextDays.length > 6 ? [] : nextDays;
};
/**
* Get the days of the previous month
*
* @param year
* @param month
*/
/**
* Get the days of the previous month
*
* @param {?} year
* @param {?} month
* @return {?}
*/
DatepickerComponent.prototype.getPreviousRestDays = /**
* Get the days of the previous month
*
* @param {?} year
* @param {?} month
* @return {?}
*/
function (year, month) {
/** @type {?} */
var startOfTheMonth = new Date(year, month, 0).getDay();
/** @type {?} */
var previousDays = this.createDayArray(DatepickerService.getYearOfPreviousMonth(year, month), DatepickerService.getPreviousMonth(month), true);
/** @type {?} */
var weekStartIndex = this.weekStartArray.indexOf(this.options.weekStart);
/** @type {?} */
var _weekStartIndex = weekStartIndex === 0 ? 0 : (7 - weekStartIndex);
/** @type {?} */
var sliceIndex = previousDays.length - startOfTheMonth - _weekStartIndex;
sliceIndex = previousDays.length - sliceIndex >= 7 ? sliceIndex + 7 : sliceIndex;
return previousDays.slice(sliceIndex, previousDays.length);
};
/**
* Merge all the day arrays together
*
* @param year
* @param month
*/
/**
* Merge all the day arrays together
*
* @param {?} year
* @param {?} month
* @return {?}
*/
DatepickerComponent.prototype.getMergedDayArrays = /**
* Merge all the day arrays together
*
* @param {?} year
* @param {?} month
* @return {?}
*/
function (year, month) {
return __spread(this.getPreviousRestDays(year, month), this.createDayArray(year, month), this.getNextRestDays(year, month));
};
/**
* Create the calendar array from the week arrays
*
* @param year
* @param month
*/
/**
* Create the calendar array from the week arrays
*
* @param {?} year
* @param {?} month
* @return {?}
*/
DatepickerComponent.prototype.createCalendarArray = /**
* Create the calendar array from the week arrays
*
* @param {?} year
* @param {?} month
* @return {?}
*/
function (year, month) {
/** @type {?} */
var dayArray = this.getMergedDayArrays(year, month);
/** @type {?} */
var weeks = DatepickerService.createWeekArray(dayArray);
return [{ weeks: weeks }];
};
/**
* Update value is being triggered
*
* @param date
*/
/**
* Update value is being triggered
*
* @param {?} date
* @return {?}
*/
DatepickerComponent.prototype.updateValue = /**
* Update value is being triggered
*
* @param {?} date
* @return {?}
*/
function (date) {
if (this.options.range) {
this.selectRange(date);
}
else if (!this.isSelected(date)) {
if (this.options.selectMultiple) {
this.selectDate(date);
}
else {
this.toggleDate(date);
}
if (this.options.closeOnSelect) {
this.close(true);
}
}
else {
this.deselectDate(date);
if (this.options.closeOnSelect) {
this.close(true);
}
}
this.months = this.createCalendarArray(this.year, this.month);
};
/**
* Select range method - contains the logic to select the start- and endrange
*
* @param date
*/
/**
* Select range method - contains the logic to select the start- and endrange
*
* @param {?} date
* @return {?}
*/
DatepickerComponent.prototype.selectRange = /**
* Select range method - contains the logic to select the start- and endrange
*
* @param {?} date
* @return {?}
*/
function (date) {
if (this.isSelected(date)) {
this.deselectDate(date);
}
else if (DatepickerService.isEarlier(date, this.startDate)) {
if (this.startDate) {
this.toggleDate(date, this.startDate, true);
}
else {
this.selectDate(date);
}
this.startDate = date;
this.selectEndDate();
}
else if (this.endDate && DatepickerService.isLater(date, this.endDate)) {
this.toggleDate(date, this.endDate);
this.endDate = date;
this.selectStartDate();
}
else if (this.selectedRange === 'startDate') {
if (this.startDate) {
this.toggleDate(date, this.startDate, true);
}
else {
this.selectDate(date);
}
this.startDate = date;
this.selectEndDate();
}
else if (this.selectedRange === 'endDate') {
if (this.endDate) {
this.toggleDate(date, this.endDate);
}
else {
this.selectDate(date);
}
this.endDate = date;
this.selectStartDate();
if (this.options.closeOnSelect) {
this.close(true);
}
}
};
/**
* Reset the range if the selected dates change externally
*/
/**
* Reset the range if the selected dates change externally
* @return {?}
*/
DatepickerComponent.prototype.resetRange = /**
* Reset the range if the selected dates change externally
* @return {?}
*/
function () {
if (this._selectedDates.length === 1) {
this.startDate = this._selectedDates[0];
this.endDate = null;
}
else if (this._selectedDates.length === 0) {
this.startDate = null;
this.endDate = null;
}
};
/**
* Toggle a date. One in, on out.
*
* @param date - Date to be toggled on
* @param toggleDate - Optional set specific date to toggle off
* @param unshift - Optional set to unshift in the selectedDates array. is passed to selectDate method
*/
/**
* Toggle a date. One in, on out.
*
* @param {?} date - Date to be toggled on
* @param {?=} toggleDate - Optional set specific date to toggle off
* @param {?=} unshift - Optional set to unshift in the selectedDates array. is passed to selectDate method
* @return {?}
*/
DatepickerComponent.prototype.toggleDate = /**
* Toggle a date. One in, on out.
*
* @param {?} date - Date to be toggled on
* @param {?=} toggleDate - Optional set specific date to toggle off
* @param {?=} unshift - Optional set to unshift in the selectedDates array. is passed to selectDate method
* @return {?}
*/
function (date, toggleDate, unshift) {
if (!toggleDate) {
this.selectedDates = [date];
}
else if (unshift) {
this._selectedDates.unshift(date);
this.selectedDates = this._selectedDates.filter(function (selectedDate) {
return selectedDate.toDateString() !== toggleDate.toDateString();
});
}
else {
this._selectedDates.push(date);
this.selectedDates = this._selectedDates.filter(function (selectedDate) {
return selectedDate.toDateString() !== toggleDate.toDateString();
});
}
};
/**
* Select a date
*
* @param date
* @param unshift - Optional set to unshift instead of push the date in the selectedDates array
*/
/**
* Select a date
*
* @param {?} date
* @param {?=} unshift - Optional set to unshift instead of push the date in the selectedDates array
* @return {?}
*/
DatepickerComponent.prototype.selectDate = /**
* Select a date
*
* @param {?} date
* @param {?=} unshift - Optional set to unshift instead of push the date in the selectedDates array
* @return {?}
*/
function (date, unshift) {
/** @type {?} */
var selectedDates = __spread(this.selectedDates);
if (unshift) {
selectedDates.unshift(date);
}
else {
selectedDates.push(date);
}
this.selectedDates = selectedDates;
};
/**
* Deselect a date
*
* @param date
*/
/**
* Deselect a date
*
* @param {?} date
* @return {?}
*/
DatepickerComponent.prototype.deselectDate = /**
* Deselect a date
*
* @param {?} date
* @return {?}
*/
function (date) {
this.selectedDates = this._selectedDates.filter(function (selectedDate) {
return selectedDate.toDateString() !== date.toDateString();
});
};
/**
* Go to the next month
*/
/**
* Go to the next month
* @return {?}
*/
DatepickerComponent.prototype.goToNextMonth = /**
* Go to the next month
* @return {?}
*/
function () {
this.year = DatepickerService.getYearOfNextMonth(this.year, this.month);
this.month = DatepickerService.getNextMonth(this.month);
this.totalYearMonth = [{ month: this.month, year: this.year }];
this.months = this.createCalendarArray(this.year, this.month);
};
/**
* Go to the previous month
*/
/**
* Go to the previous month
* @return {?}
*/
DatepickerComponent.prototype.goToPreviousMonth = /**
* Go to the previous month
* @return {?}
*/
function () {
this.year = DatepickerService.getYearOfPreviousMonth(this.year, this.month);
this.month = DatepickerService.getPreviousMonth(this.month);
this.totalYearMonth = [{ month: this.month, year: this.year }];
this.months = this.createCalendarArray(this.year, this.month);
};
/**
* Go to a specific month. Is also used to rerender the datepicker
*
* @param date - default is the current date.
*/
/**
* Go to a specific month. Is also used to rerender the datepicker
*
* @param {?=} date - default is the current date.
* @return {?}
*/
DatepickerComponent.prototype.goToDate = /**
* Go to a specific month. Is also used to rerender the datepicker
*
* @param {?=} date - default is the current date.
* @return {?}
*/
function (date) {
if (date === void 0) { date = this.date; }
this.month = date.getMonth();
this.year = date.getFullYear();
this.totalYearMonth = [{ month: this.month, year: this.year }];
this.months = this.createCalendarArray(this.year, this.month);
};
/**
* Render weekdays when options or language changes
*/
/**
* Render weekdays when options or language changes
* @return {?}
*/
DatepickerComponent.prototype.renderWeekdays = /**
* Render weekdays when options or language changes
* @return {?}
*/
function () {
this.weekdays = DatepickerService.getWeekDays(this._language, this.options.weekdayFormat, this.options.weekStart);
};
/**
* Set the open state to true
*/
/**
* Set the open state to true
* @return {?}
*/
DatepickerComponent.prototype.open = /**
* Set the open state to true
* @return {?}
*/
function () {
if (this.isOpen) {
return;
}
this.isOpen = true;
};
/**
* Close the datepicker
*
* @param useTimeout - optional timeout
*/
/**
* Close the datepicker
*
* @param {?=} useTimeout - optional timeout
* @return {?}
*/
DatepickerComponent.prototype.close = /**
* Close the datepicker
*
* @param {?=} useTimeout - optional timeout
* @return {?}
*/
function (useTimeout) {
var _this = this;
if (!this.isOpen) {
return;
}
/** @type {?} */
var timeout = useTimeout ? this.options.timeoutBeforeClosing : 0;
setTimeout(function () {
_this.isOpen = false;
}, timeout);
};
/**
* Select the start date - used for range functionality
*/
/**
* Select the start date - used for range functionality
* @return {?}
*/
DatepickerComponent.prototype.selectStartDate = /**
* Select the start date - used for range functionality
* @return {?}
*/
function () {
this.selectedRange = 'startDate';
};
/**
* Select the end date - used for range functionality
*/
/**
* Select the end date - used for range functionality
* @return {?}
*/
DatepickerComponent.prototype.selectEndDate = /**
* Select the end date - used for range functionality
* @return {?}
*/
function () {
this.selectedRange = 'endDate';
};
// TODO: maybe output the startDate and Endate or just of internal use
/**
* Check if date is the start date
*/
// TODO: maybe output the startDate and Endate or just of internal use
/**
* Check if date is the start date
* @param {?} date
* @return {?}
*/
DatepickerComponent.prototype.isStartDate =
// TODO: maybe output the startDate and Endate or just of internal use
/**
* Check if date is the start date
* @param {?} date
* @return {?}
*/
function (date) {
return this.startDate && date.toDateString() === this.startDate.toDateString();
};
/**
* Check if date is the end date
*/
/**
* Check if date is the end date
* @param {?} date
* @return {?}
*/
DatepickerComponent.prototype.isEndDate = /**
* Check if date is the end date
* @param {?} date
* @return {?}
*/
function (date) {
return this.endDate && date.toDateString() === this.endDate.toDateString();
};
/**
* Check if date is today
*/
/**
* Check if date is today
* @param {?} date
* @return {?}
*/
DatepickerComponent.prototype.isToday = /**
* Check if date is today
* @param {?} date
* @return {?}
*/
function (date) {
return date.toDateString() === this.today.toDateString();
};
/**
* Check if date is selected
*/
/**
* Check if date is selected
* @param {?} dateToCheck
* @return {?}
*/
DatepickerComponent.prototype.isSelected = /**
* Check if date is selected
* @param {?} dateToCheck
* @return {?}
*/
function (dateToCheck) {
return this._selectedDates.map(function (date) { return date.toDateString(); }).indexOf(dateToCheck.toDateString()) !== -1;
};
/**
* Check if date is disabled
*/
/**
* Check if date is disabled
* @param {?} date
* @return {?}
*/
DatepickerComponent.prototype.isDisabled = /**
* Check if date is disabled
* @param {?} date
* @return {?}
*/
function (date) {
if (!this.minDate) {
return !(date < this.maxDate);
}
if (!this.maxDate) {
return !(date > this.minDate);
}
return !(date < this.maxDate && date > this.minDate);
};
/**
* Check if date is in range
*/
/**
* Check if date is in range
* @param {?} date
* @return {?}
*/
DatepickerComponent.prototype.isInRange = /**
* Check if date is in range
* @param {?} date
* @return {?}
*/
function (date) {
return this.startDate && this.endDate && this.startDate < date && date < this.endDate;
};
DatepickerComponent.decorators = [
{ type: Component, args: [{
selector: 'aa-datepicker',
template: "<div class=\"datepicker__wrapper\">\n\t<div>\n\t\t<aa-navigation\n\t\t\t\t[hideNavigation]=\"options.hideNavigation\"\n (previousClick)=\"goToPreviousMonth()\"\n\t\t\t\t(nextClick)=\"goToNextMonth()\"\n\t\t\t\t[language]=\"language\"\n\t\t\t\t[totalYearMonth]=\"totalYearMonth\"></aa-navigation>\n\t\t<div class=\"datepicker__weekdays-wrapper\">\n\t\t\t<div class=\"datepicker__weekdays-container\">\n\t\t\t\t<table class=\"datepicker__weekdays\">\n\t\t\t\t\t<thead>\n\t\t\t\t\t<td class=\"datepicker__weekday\" *ngFor=\"let weekday of weekdays; index as i\">{{weekday}}</td>\n\t\t\t\t\t</thead>\n\t\t\t\t</table>\n\t\t\t</div>\n\t\t</div>\n\t</div>\n\t<div class=\"datepicker__calendar-wrapper\">\n\t\t<div *ngFor=\"let month of months;\" class=\"datepicker__calendar-container\">\n\t\t\t<table class=\"datepicker__calendar\">\n\t\t\t\t<tbody>\n\t\t\t\t<tr *ngFor=\"let week of month.weeks; index as i\">\n\t\t\t\t\t<td class=\"datepicker__day\" *ngFor=\"let day of week.days; index as i\" [ngClass]=\"{\n\t\t\t'is-first': day.isFirst,\n\t\t\t'is-last': day.isLast,\n\t\t\t'is-hidden': day.isHidden,\n\t\t\t'is-disabled': day.isDisabled,\n\t\t\t'is-today': day.isToday,\n\t\t\t'is-selected': day.isSelected,\n\t\t\t'is-in-range': day.isInRange,\n\t\t\t'is-start-date': day.isStartDate,\n\t\t\t'is-end-date': day.isEndDate,\n\t\t\t'is-rest': day.isRest\n\t\t\t}\">\n\t\t\t\t\t\t<button class=\"datepicker__button\" [disabled]=\"day.isDisabled || day.isHidden\"\n\t\t\t\t\t\t\t\t(click)=\"updateValue(day.date)\">{{day.dayNumber}}\n\t\t\t\t\t\t</button>\n\t\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t</tbody>\n\t\t\t</table>\n\t\t</div>\n\t</div>\n\t<ng-content></ng-content>\n</div>",
styles: [":host{font-family:Arial,Helvetica,sans-serif;border:1px solid #d9d9d8;width:300px;position:relative;display:inline-block;z-index:2;border-radius:4px;box-shadow:0 1px 5px rgba(0,0,0,.15);overflow:hidden;background-color:#fff;box-sizing:border-box;visibility:hidden}:host *{box-sizing:border-box}:host .datepicker__calendar-container{padding:0 10px 10px}:host .datepicker__footer{position:relative;z-index:1}:host table{width:100%;table-layout:fixed;border-spacing:0;border-collapse:collapse}:host td{padding:0}:host .datepicker__weekdays-wrapper::after,:host .datepicker__weekdays-wrapper::before{content:' ';display:table}:host .datepicker__weekdays-wrapper::after{clear:both}:host .datepicker__weekdays-container{padding:10px 10px 0;float:left}:host .datepicker__weekdays{table-layout:fixed;width:100%}:host .datepicker__weekday{color:grey;font-size:12px;height:20px;text-align:center}:host .datepicker__day{position:relative;text-align:center;height:40px;width:auto;border:1px solid #d9d9d8}:host .datepicker__day.is-rest{border:none}:host .datepicker__button{padding:0;background-color:transparent;border:none;outline:0;font-style:inherit;cursor:pointer;color:#8e8d8a;width:100%;height:100%}:host .datepicker__button:hover{border:1px solid transparent;background-color:#f2f2f2;color:#8e8d8a}:host .is-hidden{opacity:0;display:table-cell}:host .is-rest{border:none}:host .is-rest .datepicker__button{color:#c0c0be}:host .is-today .datepicker__button{background-color:#eae7dc}:host .is-in-range .datepicker__button{background-color:#e98074;color:#fff}:host .is-in-range .datepicker__button:hover{background-color:#e66c5e}:host .is-selected .datepicker__button{background-color:#e85a4f;color:#fff;font-weight:700}:host .is-selected .datepicker__button:hover{background-color:#e23022}:host .is-start-date .datepicker__button{background-color:#e85a4f;color:#fff}:host .is-end-date .datepicker__button{background-color:#e85a4f;color:#fff}:host .is-disabled .datepicker__button{color:#d9d9d8;cursor:default}:host .is-disabled .datepicker__button:hover{background-color:transparent}:host.is-directive{visibility:hidden;position:absolute}:host.is-open{visibility:visible}:host.is-animate{transition:height .2s ease-in;width:300px}:host.is-animate .datepicker__main{transition:height .2s ease-in}:host.is-animate .datepicker__calendar-wrapper{position:absolute;width:200%;left:0}:host.is-animate .datepicker__calendar{float:left;width:100%}:host.is-animate .datepicker__calendar-container{float:left}"]
},] },
];
DatepickerComponent.ctorParameters = function () { return [
{ type: UtilitiesService },
{ type: ElementRef }
]; };
DatepickerComponent.propDecorators = {
options: [{ type: Input, args: ['options',] }],
language: [{ type: Input }],
minDate: [{ type: Input }],
maxDate: [{ type: Input }],
selectedDatesChange: [{ type: Output }],
selectedDates: [{ type: Input }],
calendarContainer: [{ type: ViewChild, args: ['calendarContainer',] }],
calendarTopContainer: [{ type: ViewChild, args: ['calendarTopContainer',] }],
theme: [{ type: HostBinding, args: ['class',] }, { type: Input }],
isOpen: [{ type: HostBinding, args: ['class.is-open',] }, { type: Input }],
asDirective: [{ type: HostBinding, args: ['class.is-directive',] }],
animate: [{ type: HostBinding, args: ['class.is-animate',] }],
topPosition: [{ type: HostBinding, args: ['style.top.px',] }],
leftPosition: [{ type: HostBinding, args: ['style.left.px',] }],
bottomPosition: [{ type: HostBinding, args: ['style.bottom.px',] }],
rightPosition: [{ type: HostBinding, args: ['style.right.px',] }]
};
return DatepickerComponent;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var AnimatepickerComponent = /** @class */ (function (_super) {
__extends(AnimatepickerComponent, _super);
function AnimatepickerComponent(elementRef, utilities) {
var _this = _super.call(this, utilities, elementRef) || this;
_this.elementRef = elementRef;
_this.utilities = utilities;
/* ==============================================
* Internal Properties
* ============================================== */
_this.animate = true;
_this.isAnimating = false;
_this.leftInnerPosition = 0;
_this.currentYearMonth = null;
_this.initialised = false;
/* ==============================================
* External Properties
* ============================================== */
/**
* Number of months: the number of months displayed
*/
_this._numberOfMonths = new Array(1);
return _this;
}
Object.defineProperty(AnimatepickerComponent.prototype, "numberOfMonths", {
get: /**
* @return {?}
*/
function () {
return this._numberOfMonths;
},
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
if (value === undefined || value === this._numberOfMonths.length) {
return;
}
this._numberOfMonths = new Array(value);
this.setDatePickerDimension();
this.goToDate(this.date);
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
AnimatepickerComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
// Get the computed width from the calendar. Set the initial width
/** @type {?} */
var computedWidth = window
.getComputedStyle(this.elementRef.nativeElement, null)
.getPropertyValue('width');
this.initialWidth = parseInt(computedWidth, 10);
this.initialised = true;
// Set the current year and month object
if (!this.month && !this.year) {
this.goToDate(this.options.currentDate);
}
};
/**
* @return {?}
*/
AnimatepickerComponent.prototype.ngAfterViewInit = /**
* @return {?}
*/
function () {
var _this = this;
setTimeout(function () {
_this.setDatePickerDimension();
_this.setDatepickerHeight(true);
});
};
/**
* Set the height and the width properties
*/
/**
* Set the height and the width properties
* @return {?}
*/
AnimatepickerComponent.prototype.setDatePickerDimension = /**
* Set the height and the width properties
* @return {?}
*/
function () {
this.datepickerHeight =
this.calendarContainer.nativeElement.offsetHeight +
this.calendarTopContainer.nativeElement.offsetHeight +
this.footer.nativeElement.offsetHeight;
this.calendarHeight = this.calendarContainer.nativeElement.offsetHeight;
this.datepickerWidth = this.initialWidth * this._numberOfMonths.length;
};
/**
* Go to a specific month
*
* @param date - optional
*/
/**
* Go to a specific month
*
* @param {?=} date - optional
* @return {?}
*/
AnimatepickerComponent.prototype.goToDate = /**
* Go to a specific month
*
* @param {?=} date - optional
* @return {?}
*/
function (date) {
if (date) {
this.currentYearMonth = this.getNextYearMonthArray(date.getFullYear(), date.getMonth());
}
this.calendarWidth = 50 / this._numberOfMonths.length;
this.months = this.getNextMonthArray(this.currentYearMonth, true);
this.resetStyle();
};
/**
* Create an array of the next year and months
*
* @param year
* @param month
*/
/**
* Create an array of the next year and months
*
* @param {?} year
* @param {?} month
* @return {?}
*/
AnimatepickerComponent.prototype.getNextYearMonthArray = /**
* Create an array of the next year and months
*
* @param {?} year
* @param {?} month
* @return {?}
*/
function (year, month) {
/** @type {?} */
var array = [];
for (var index = 0; index < this._numberOfMonths.length; index++) {
array.push({ year: year, month: month });
year = DatepickerService.getYearOfNextMonth(year, month);
month = DatepickerService.getNextMonth(month);
}
return array;
};
/**
* Create an array of the previous year and months
*
* @param year
* @param month
*/
/**
* Create an array of the previous year and months
*
* @param {?} year
* @param {?} month
* @return {?}
*/
AnimatepickerComponent.prototype.getPreviousYearMonthArray = /**
* Create an array of the previous year and months
*
* @param {?} year
* @param {?} month
* @return {?}
*/
function (year, month) {
/** @type {?} */
var array = [];
for (var index = 0; index < this._numberOfMonths.length; index++) {
array.unshift({ year: year, month: month });
year = DatepickerService.getYearOfPreviousMonth(year, month);
month = DatepickerService.getPreviousMonth(month);
}
return array;
};
/**
* Set the datepicker height, used when animating
*
* @param directionRight - Set optional when sliding to the right
*/
/**
* Set the datepicker height, used when animating
*
* @param {?=} directionRight - Set optional when sliding to the right
* @return {?}
*/
AnimatepickerComponent.prototype.setDatepickerHeight = /**
* Set the datepicker height, used when animating
*
* @param {?=} directionRight - Set optional when sliding to the right
* @return {?}
*/
function (directionRight) {
/** @type {?} */
var indexArray;
// TODO: Seperate this logic for readability purpose
if (this._numberOfMonths.length > 1) {
/** @type {?} */
var start = directionRight ? 0 : this._numberOfMonths.length;
/** @type {?} */
var end = directionRight
? this._numberOfMonths.length - 1
: this._numberOfMonths.length + this._numberOfMonths.length - 1;
indexArray = this.utilities.createArray(start, end);
}
else {
indexArray = directionRight ? [0] : [1];
}
/** @type {?} */
var that = this;
setTimeout(function () {
/** @type {?} */
var calendarArray = that.elementRef.nativeElement.querySelectorAll('.datepicker__calendar-container');
/** @type {?} */
var offsetHeight = 0;
indexArray.forEach(function (el) {
if (calendarArray[el].offsetHeight > offsetHeight) {
offsetHeight = calendarArray[el].offsetHeight;
}
});
// TODO: Merge with setHeight function.
that.datepickerHeight =
offsetHeight + that.calendarTopContainer.nativeElement.offsetHeight + that.footer.nativeElement.offsetHeight;
that.calendarHeight = offsetHeight;
});
};
/**
* Get next month array, gets multiple months.
* Used when the options animate is set or multiple months are visable
*
* @return Month[]
*/
/**
* Get next month array, gets multiple months.
* Used when the options animate is set or multiple months are visable
*
* @param {?} currentYearMonth
* @param {?=} keepDate
* @param {?=} nextMonthsYearMonthArray
* @return {?} Month[]
*/
AnimatepickerComponent.prototype.getNextMonthArray = /**
* Get next month array, gets multiple months.
* Used when the options animate is set or multiple months are visable
*
* @param {?} currentYearMonth
* @param {?=} keepDate
* @param {?=} nextMonthsYearMonthArray
* @return {?} Month[]
*/
function (currentYearMonth, keepDate, nextMonthsYearMonthArray) {
var _this = this;
if (keepDate === void 0) { keepDate = false; }
// Get the last index, used for selecting the right year month object
/** @type {?} */
var lastIndex = this._numberOfMonths.length - 1;
// Get next year and month in an Object
/** @type {?} */
var nextMonths = nextMonthsYearMonthArray ||
this.getNextYearMonthArray(DatepickerService.getYearOfNextMonth(currentYearMonth[lastIndex].year, currentYearMonth[lastIndex].month), DatepickerService.getNextMonth(currentYearMonth[lastIndex].month));
// Concatenates the two objects to create a total year and month object
this.totalYearMonth = currentYearMonth.concat(nextMonths);
// Create the calendar array using the total year and month Object
/** @type {?} */
var monthArray = [];
this.totalYearMonth.forEach(function (e) {
r