namespace TheDatepicker { export enum EventType_ { BeforeSelect = 'beforeSelect' , Select = 'select' , BeforeOpen = 'beforeOpen' , Open = 'open' , BeforeClose = 'beforeClose' , Close = 'close' , BeforeMonthChange = 'beforeMonthChange' , MonthChange = 'monthChange' , Focus = 'focus' , BeforeFocus = 'beforeFocus' } export class AvailableDateNotFoundException { } export type SelectListener = ( event : Event | null , day : Day | null , previousDay : Day | null ) => boolean ; export type OpenOrCloseListener = ( event : Event | null ) => boolean ; export type MonthChangeListener = ( event : Event | null , month : Date , previousMonth : Date ) => boolean ; export type FocusListener = ( event : Event | null , day : Day | null , previousDay : Day | null ) => boolean ; type OneOfListener = SelectListener | OpenOrCloseListener | MonthChangeListener | FocusListener ; type AnyListener = SelectListener & OpenOrCloseListener & MonthChangeListener & FocusListener ; type ListenerCaller = ( listener : ( event : Event | null , ... props : any ) => boolean ) => boolean ; interface Listeners { beforeSelect : SelectListener [ ] ; select : SelectListener [ ] ; beforeOpen : OpenOrCloseListener [ ] ; open : OpenOrCloseListener [ ] ; beforeClose : OpenOrCloseListener [ ] ; close : OpenOrCloseListener [ ] ; beforeMonthChange : MonthChangeListener [ ] ; monthChange : MonthChangeListener [ ] ; beforeFocus : FocusListener [ ] ; focus : FocusListener [ ] ; } type DateAvailabilityResolver = ( date : Date ) => boolean ; type CellContentResolver = ( day : Day ) => string ; type StructureResolverInit = ( ) => HTMLElement ; type CellContentStructureResolverUpdate = ( element : HTMLElement , day : Day ) => void ; interface CellContentStructureResolver { init : StructureResolverInit ; update : CellContentStructureResolverUpdate ; } type CellClassesResolver = ( day : Day ) => string [ ] ; type DayModifier = ( day : Day ) => void ; export class Options { public readonly translator : Translator ; public readonly classNames : ClassNames ; private hideOnBlur_ = true ; private hideOnSelect_ = true ; private minDate_ : Date | null = null ; private maxDate_ : Date | null = null ; private initialDate_ : Date | null = null ; private initialMonth_ : Date | null = null ; private initialDatePriority_ = true ; private firstDayOfWeek_ = DayOfWeek . Monday ; private dateAvailabilityResolvers_ : DateAvailabilityResolver [ ] = [ ] ; private cellContentResolver_ : CellContentResolver | null = null ; private cellContentStructureResolver_ : CellContentStructureResolver | null = null ; private headerStructureResolver_ : StructureResolverInit | null = null ; private footerStructureResolver_ : StructureResolverInit | null = null ; private cellClassesResolvers_ : CellClassesResolver [ ] = [ ] ; private dayModifiers_ : DayModifier [ ] = [ ] ; private inputFormat_ = 'j. n. Y' ; private allowInputAnyChar_ = false ; private daysOutOfMonthVisible_ = false ; private fixedRowsCount_ = false ; private toggleSelection_ = false ; private allowEmpty_ = true ; private showDeselectButton_ = true ; private showResetButton_ = false ; private monthAsDropdown_ = true ; private yearAsDropdown_ = true ; private yearSelectedFromTableOfYears_ = true ; private tableOfYearsRowsCount_ = 6 ; private tableOfYearsAlign_ : Align | null = null ; private tableOfYearsOnSwipeDown_ = true ; private yearsOutOfTableOfYearsVisible_ = true ; private monthAndYearSeparated_ = true ; private monthShort_ = false ; private changeMonthOnSwipe_ = true ; private slideAnimation_ = true ; private classesPrefix_ = 'the-datepicker__' ; private showCloseButton_ = true ; private closeOnEscPress_ = true ; private title_ = '' ; private dropdownItemsLimit_ = 200 ; private hideDropdownWithOneItem_ = true ; private goBackHtml_ = '&lt;' ; private goForwardHtml_ = '&gt;' ; private closeHtml_ = '&times;' ; private resetHtml_ = '&olarr;' ; private deselectHtml_ = '&times;' ; private positionFixing_ = true ; private fullScreenOnMobile_ = true ; private keyboardOnMobile_ = false ; private includeAria_ = true ; private today_ : Date | null = null ; private listeners_ : Listeners = { beforeSelect : [ ] , select : [ ] , beforeOpen : [ ] , open : [ ] , beforeClose : [ ] , close : [ ] , beforeMonthChange : [ ] , monthChange : [ ] , beforeFocus : [ ] , focus : [ ] } ; public constructor ( translator = null , classNames = null ) { this . translator = translator || new Translator ( ) ; this . classNames = classNames || new ClassNames ( ) ; } public clone ( ) { const options = new Options ( this . translator . clone ( ) , this . classNames . clone ( ) ) ; options . hideOnBlur_ = this . hideOnBlur_ ; options . hideOnSelect_ = this . hideOnSelect_ ; options . minDate_ = this . minDate_ ; options . maxDate_ = this . maxDate_ ; options . initialDate_ = this . initialDate_ ; options . initialMonth_ = this . initialMonth_ ; options . initialDatePriority_ = this . initialDatePriority_ ; options . firstDayOfWeek_ = this . firstDayOfWeek_ ; options . dateAvailabilityResolvers_ = this . dateAvailabilityResolvers_ . slice ( 0 ) ; options . cellContentResolver_ = this . cellContentResolver_ ; options . cellContentStructureResolver_ = this . cellContentStructureResolver_ ; options . headerStructureResolver_ = this . headerStructureResolver_ ; options . footerStructureResolver_ = this . footerStructureResolver_ ; options . cellClassesResolvers_ = this . cellClassesResolvers_ . slice ( 0 ) ; options . dayModifiers_ = this . dayModifiers_ . slice ( 0 ) ; options . inputFormat_ = this . inputFormat_ ; options . allowInputAnyChar_ = this . allowInputAnyChar_ ; options . daysOutOfMonthVisible_ = this . daysOutOfMonthVisible_ ; options . fixedRowsCount_ = this . fixedRowsCount_ ; options . toggleSelection_ = this . toggleSelection_ ; options . allowEmpty_ = this . allowEmpty_ ; options . showDeselectButton_ = this . showDeselectButton_ ; options . showResetButton_ = this . showResetButton_ ; options . monthAsDropdown_ = this . monthAsDropdown_ ; options . yearAsDropdown_ = this . yearAsDropdown_ ; options . yearSelectedFromTableOfYears_ = this . yearSelectedFromTableOfYears_ ; options . tableOfYearsRowsCount_ = this . tableOfYearsRowsCount_ ; options . tableOfYearsAlign_ = this . tableOfYearsAlign_ ; options . tableOfYearsOnSwipeDown_ = this . tableOfYearsOnSwipeDown_ ; options . monthAndYearSeparated_ = this . monthAndYearSeparated_ ; options . monthShort_ = this . monthShort_ ; options . changeMonthOnSwipe_ = this . changeMonthOnSwipe_ ; options . slideAnimation_ = this . slideAnimation_ ; options . classesPrefix_ = this . classesPrefix_ ; options . showCloseButton_ = this . showCloseButton_ ; options . closeOnEscPress_ = this . closeOnEscPress_ ; options . title_ = this . title_ ; options . dropdownItemsLimit_ = this . dropdownItemsLimit_ ; options . hideDropdownWithOneItem_ = this . hideDropdownWithOneItem_ ; options . goBackHtml_ = this . goBackHtml_ ; options . goForwardHtml_ = this . goForwardHtml_ ; options . closeHtml_ = this . closeHtml_ ; options . resetHtml_ = this . resetHtml_ ; options . deselectHtml_ = this . deselectHtml_ ; options . positionFixing_ = this . positionFixing_ ; options . fullScreenOnMobile_ = this . fullScreenOnMobile_ ; options . keyboardOnMobile_ = this . keyboardOnMobile_ ; options . includeAria_ = this . includeAria_ ; options . listeners_ . beforeSelect = this . listeners_ . beforeSelect . slice ( 0 ) ; options . listeners_ . select = this . listeners_ . select . slice ( 0 ) ; options . listeners_ . beforeOpen = this . listeners_ . beforeOpen . slice ( 0 ) ; options . listeners_ . open = this . listeners_ . open . slice ( 0 ) ; options . listeners_ . beforeClose = this . listeners_ . beforeClose . slice ( 0 ) ; options . listeners_ . close = this . listeners_ . close . slice ( 0 ) ; options . listeners_ . beforeMonthChange = this . listeners_ . beforeMonthChange . slice ( 0 ) ; options . listeners_ . monthChange = this . listeners_ . monthChange . slice ( 0 ) ; options . listeners_ . beforeFocus = this . listeners_ . beforeFocus . slice ( 0 ) ; options . listeners_ . focus = this . listeners_ . focus . slice ( 0 ) ; return options ; } public setHideOnBlur ( value ) { this . hideOnBlur_ = ! ! value ; } public setHideOnSelect ( value ) { this . hideOnSelect_ = ! ! value ; } public setMinDate ( date ) { const normalizedDate = Helper_ . normalizeDate_ ( 'Min date' , date , true , this ) ; this . checkConstraints_ ( normalizedDate , this . maxDate_ ) ; this . minDate_ = normalizedDate ; } public setMaxDate ( date ) { const normalizedDate = Helper_ . normalizeDate_ ( 'Max date' , date , true , this ) ; this . checkConstraints_ ( this . minDate_ , normalizedDate ) ; this . maxDate_ = normalizedDate ; } public setInitialMonth ( month ) { this . initialMonth_ = Helper_ . normalizeDate_ ( 'Initial month' , month , true , this ) ; } public setInitialDate ( value ) { this . initialDate_ = Helper_ . normalizeDate_ ( 'Initial date' , value , true , this ) ; } public setInitialDatePriority ( value ) { this . initialDatePriority_ = ! ! value ; } public setFirstDayOfWeek ( dayOfWeek ) { this . firstDayOfWeek_ = Helper_ . checkNumber_ ( 'First day of week' , dayOfWeek , 0 , 6 ) ; } public setDateAvailabilityResolver ( resolver ) { Helper_ . warnDeprecatedUsage_ ( 'setDateAvailabilityResolver' , [ 'addDateAvailabilityResolver' ] ) ; this . removeDateAvailabilityResolver ( ) ; this . addDateAvailabilityResolver ( resolver ) ; } public addDateAvailabilityResolver ( resolver ) { this . dateAvailabilityResolvers_ . push ( Helper_ . checkFunction_ ( 'Resolver' , resolver , false ) ) ; } public removeDateAvailabilityResolver ( resolver = null ) { this . removeCallback_ ( this . dateAvailabilityResolvers_ , 'Resolver' , resolver ) ; } public setCellContentResolver ( resolver ) { this . cellContentResolver_ = Helper_ . checkFunction_ ( 'Resolver' , resolver ) ; } public setCellContentStructureResolver ( init , update = null ) { init = Helper_ . checkFunction_ ( 'Resolver (init)' , init ) ; update = Helper_ . checkFunction_ ( 'Resolver (update)' , update ) ; this . cellContentStructureResolver_ = init ? { init , update } : null ; } public setHeaderStructureResolver ( resolver ) { this . headerStructureResolver_ = Helper_ . checkFunction_ ( 'Resolver' , resolver ) ; } public setFooterStructureResolver ( resolver ) { this . footerStructureResolver_ = Helper_ . checkFunction_ ( 'Resolver' , resolver ) ; } public addCellClassesResolver ( resolver ) { this . cellClassesResolvers_ . push ( Helper_ . checkFunction_ ( 'Resolver' , resolver , false ) ) ; } public removeCellClassesResolver ( resolver = null ) { this . removeCallback_ ( this . cellClassesResolvers_ , 'Resolver' , resolver ) ; } public addDayModifier ( modifier ) { this . dayModifiers_ . push ( Helper_ . checkFunction_ ( 'Modifier' , modifier , false ) ) ; } public removeDayModifier ( modifier = null ) { this . removeCallback_ ( this . dayModifiers_ , 'Modifier' , modifier ) ; } public setInputFormat ( format ) { this . inputFormat_ = Helper_ . checkString_ ( 'Input format' , format , true ) ; } public setAllowInputAnyChar ( value ) { this . allowInputAnyChar_ = ! ! value ; } public setDaysOutOfMonthVisible ( value ) { this . daysOutOfMonthVisible_ = ! ! value ; } public setFixedRowsCount ( value ) { this . fixedRowsCount_ = ! ! value ; } public setToggleSelection ( value ) { this . toggleSelection_ = ! ! value ; } public setShowDeselectButton ( value ) { this . showDeselectButton_ = ! ! value ; } public setAllowEmpty ( value ) { this . allowEmpty_ = ! ! value ; } public setShowResetButton ( value ) { this . showResetButton_ = ! ! value ; } public setMonthAsDropdown ( value ) { this . monthAsDropdown_ = ! ! value ; } public setYearAsDropdown ( value ) { this . yearAsDropdown_ = ! ! value ; } public setYearSelectedFromTableOfYears ( value ) { this . yearSelectedFromTableOfYears_ = ! ! value ; } public setTableOfYearsRowsCount ( count ) { this . tableOfYearsRowsCount_ = Helper_ . checkNumber_ ( 'Rows count' , count , 1 ) ; } public setTableOfYearsAlign ( align ) { this . tableOfYearsAlign_ = align ? Helper_ . checkNumber_ ( 'Align' , align , 1 , 3 ) : null ; } public setTableOfYearsOnSwipeDown ( value ) { this . tableOfYearsOnSwipeDown_ = ! ! value ; } public setYearsOutOfTableOfYearsVisible ( value ) { this . yearsOutOfTableOfYearsVisible_ = ! ! value ; } public setMonthAndYearSeparated ( value ) { this . monthAndYearSeparated_ = ! ! value ; } public setMonthShort ( value ) { this . monthShort_ = ! ! value ; } public setChangeMonthOnSwipe ( value ) { this . changeMonthOnSwipe_ = ! ! value ; } public setAnimateMonthChange ( value ) { Helper_ . warnDeprecatedUsage_ ( 'setAnimateMonthChange' , [ 'setSlideAnimation' ] ) ; this . setSlideAnimation ( value ) ; } public setSlideAnimation ( value ) { this . slideAnimation_ = ! ! value ; } public setClassesPrefix ( prefix ) { this . classesPrefix_ = Helper_ . checkString_ ( 'Prefix' , prefix ) ; } public setShowCloseButton ( value ) { this . showCloseButton_ = ! ! value ; } public setCloseOnEscPress ( value ) { this . closeOnEscPress_ = ! ! value ; } public setTitle ( title ) { this . title_ = Helper_ . checkString_ ( 'Title' , title ) ; } public setDropdownItemsLimit ( limit ) { this . dropdownItemsLimit_ = Helper_ . checkNumber_ ( 'Items limit' , limit , 1 ) ; } public setHideDropdownWithOneItem ( value ) { this . hideDropdownWithOneItem_ = ! ! value ; } public setGoBackHtml ( html ) { this . goBackHtml_ = Helper_ . checkString_ ( 'Html' , html ) ; } public setGoForwardHtml ( html ) { this . goForwardHtml_ = Helper_ . checkString_ ( 'Html' , html ) ; } public setCloseHtml ( html ) { this . closeHtml_ = Helper_ . checkString_ ( 'Html' , html ) ; } public setResetHtml ( html ) { this . resetHtml_ = Helper_ . checkString_ ( 'Html' , html ) ; } public setDeselectHtml ( html ) { this . deselectHtml_ = Helper_ . checkString_ ( 'Html' , html ) ; } public setPositionFixing ( value ) { this . positionFixing_ = ! ! value ; } public setFullScreenOnMobile ( value ) { this . fullScreenOnMobile_ = ! ! value ; } public setKeyboardOnMobile ( value ) { this . keyboardOnMobile_ = ! ! value ; } public setIncludeAria ( value ) { this . includeAria_ = ! ! value ; } public setToday ( date ) { this . today_ = Helper_ . normalizeDate_ ( 'Today' , date , true , this ) ; } public onBeforeSelect ( listener ) { this . onEvent_ ( EventType_ . BeforeSelect , listener as AnyListener ) ; } public offBeforeSelect ( listener = null ) { this . offEvent_ ( EventType_ . BeforeSelect , listener ) ; } public onSelect ( listener ) { this . onEvent_ ( EventType_ . Select , listener as AnyListener ) ; } public offSelect ( listener = null ) { this . offEvent_ ( EventType_ . Select , listener ) ; } public onBeforeOpen ( listener ) { this . onEvent_ ( EventType_ . BeforeOpen , listener as AnyListener ) ; } public offBeforeOpen ( listener = null ) { this . offEvent_ ( EventType_ . BeforeOpen , listener ) ; } public onOpen ( listener ) { this . onEvent_ ( EventType_ . Open , listener as AnyListener ) ; } public offOpen ( listener = null ) { this . offEvent_ ( EventType_ . Open , listener ) ; } public onBeforeClose ( listener ) { this . onEvent_ ( EventType_ . BeforeClose , listener as AnyListener ) ; } public offBeforeClose ( listener = null ) { this . offEvent_ ( EventType_ . BeforeClose , listener ) ; } public onClose ( listener ) { this . onEvent_ ( EventType_ . Close , listener as AnyListener ) ; } public offClose ( listener = null ) { this . offEvent_ ( EventType_ . Close , listener ) ; } public onBeforeOpenAndClose ( listener ) { Helper_ . warnDeprecatedUsage_ ( 'onBeforeOpenAndClose' , [ 'onBeforeOpen' , 'onBeforeClose' ] ) ; this . onBeforeOpen ( listener ) ; this . onBeforeClose ( listener ) ; } public offBeforeOpenAndClose ( listener = null ) { Helper_ . warnDeprecatedUsage_ ( 'offBeforeOpenAndClose' , [ 'offBeforeOpen' , 'offBeforeClose' ] ) ; this . offBeforeOpen ( listener ) ; this . offBeforeClose ( listener ) ; } public onOpenAndClose ( listener ) { Helper_ . warnDeprecatedUsage_ ( 'onOpenAndClose' , [ 'onOpen' , 'onClose' ] ) ; this . onOpen ( listener ) ; this . onClose ( listener ) ; } public offOpenAndClose ( listener = null ) { Helper_ . warnDeprecatedUsage_ ( 'offOpenAndClose' , [ 'offOpen' , 'offClose' ] ) ; this . offOpen ( listener ) ; this . offClose ( listener ) ; } public onBeforeMonthChange ( listener ) { this . onEvent_ ( EventType_ . BeforeMonthChange , listener as AnyListener ) ; } public offBeforeMonthChange ( listener = null ) { this . offEvent_ ( EventType_ . BeforeMonthChange , listener ) ; } public onMonthChange ( listener ) { this . onEvent_ ( EventType_ . MonthChange , listener as AnyListener ) ; } public offMonthChange ( listener = null ) { this . offEvent_ ( EventType_ . MonthChange , listener ) ; } public onBeforeFocus ( listener ) { this . onEvent_ ( EventType_ . BeforeFocus , listener as AnyListener ) ; } public offBeforeFocus ( listener = null ) { this . offEvent_ ( EventType_ . BeforeFocus , listener ) ; } public onFocus ( listener ) { this . onEvent_ ( EventType_ . Focus , listener as AnyListener ) ; } public offFocus ( listener = null ) { this . offEvent_ ( EventType_ . Focus , listener ) ; } public getInitialMonth ( ) { const primarySource = this . initialDatePriority_ ? this . initialDate_ : this . initialMonth_ ; const secondarySource = this . initialDatePriority_ ? this . initialMonth_ : this . initialDate_ ; const initialMonth = primarySource ? new Date ( primarySource . getTime ( ) ) : ( secondarySource ? new Date ( secondarySource . getTime ( ) ) : this . getToday ( ) ) ; initialMonth . setDate ( 1 ) ; return this . correctMonth ( initialMonth ) ; } public isMonthInValidity ( month ) { return ! this . calculateMonthCorrection_ ( month ) ; } public correctMonth ( month ) { const correctMonth = this . calculateMonthCorrection_ ( month ) ; return correctMonth || month ; } public getInitialDate ( ) { return this . findPossibleAvailableDate ( this . initialDate_ ) ; } public findPossibleAvailableDate ( date ) { if ( this . isAllowedEmpty ( ) ) { return date && this . isDateInValidity ( date ) && this . isDateAvailable ( date ) ? new Date ( date . getTime ( ) ) : null ; } date = date ? new Date ( date . getTime ( ) ) : this . getToday ( ) ; date = this . findNearestAvailableDate ( date ) ; if ( date ) { return date ; } throw new AvailableDateNotFoundException ( ) ; } public findNearestAvailableDate ( date ) { date = this . correctDate_ ( date ) ; if ( this . isDateAvailable ( date ) ) { return date ; } const minDate = this . getMinDate_ ( ) . getTime ( ) ; const maxDate = this . getMaxDate_ ( ) . getTime ( ) ; let maxLoops = 1000 ; let increasedDate = date ; let decreasedDate = new Date ( date . getTime ( ) ) ; do { if ( increasedDate ) { increasedDate . setDate ( increasedDate . getDate ( ) + 1 ) ; if ( increasedDate . getTime ( ) > maxDate ) { increasedDate = null ; } else if ( this . isDateAvailable ( increasedDate ) ) { return increasedDate ; } } if ( decreasedDate ) { decreasedDate . setDate ( decreasedDate . getDate ( ) - 1 ) ; if ( decreasedDate . getTime ( ) < minDate ) { decreasedDate = null ; } else if ( this . isDateAvailable ( decreasedDate ) ) { return decreasedDate ; } } maxLoops -- ; } while ( ( increasedDate || decreasedDate ) && maxLoops > 0 ) ; return null ; } public isDateInValidity ( date ) { return ! this . calculateDateCorrection_ ( date ) ; } private correctDate_ ( date ) { const correctDate = this . calculateDateCorrection_ ( date ) ; return correctDate || date ; } public getFirstDayOfWeek ( ) { return this . firstDayOfWeek_ ; } public areDaysOutOfMonthVisible ( ) { return this . daysOutOfMonthVisible_ ; } public hasFixedRowsCount ( ) { return this . fixedRowsCount_ ; } public hasToggleSelection ( ) { return this . allowEmpty_ && this . toggleSelection_ ; } public isAllowedEmpty ( ) { return this . allowEmpty_ ; } public isDeselectButtonShown ( ) { return this . allowEmpty_ && this . showDeselectButton_ ; } public isResetButtonShown ( ) { return this . showResetButton_ ; } public isMonthAsDropdown ( ) { return this . monthAsDropdown_ ; } public isYearAsDropdown ( ) { return this . yearAsDropdown_ ; } public isYearSelectedFromTableOfYears ( ) { return this . yearAsDropdown_ && this . yearSelectedFromTableOfYears_ ; } public getTableOfYearsRowsCount ( ) { return this . tableOfYearsRowsCount_ ; } public getTableOfYearsColumnsCount ( ) { return 4 ; } public getTableOfYearsAlign ( ) { return this . tableOfYearsAlign_ ; } public isTableOfYearsOnSwipeDownEnabled ( ) { return this . tableOfYearsOnSwipeDown_ ; } public areYearsOutOfTableOfYearsVisible ( ) { return this . yearsOutOfTableOfYearsVisible_ ; } public isMonthAndYearSeparated ( ) { return this . isYearSelectedFromTableOfYears ( ) || this . monthAndYearSeparated_ ; } public isMonthShort ( ) { return this . monthShort_ ; } public isMonthChangeOnSwipeEnabled ( ) { return this . changeMonthOnSwipe_ ; } public isMonthChangeAnimated ( ) { Helper_ . warnDeprecatedUsage_ ( 'isMonthChangeAnimated' , [ 'isSlideAnimationEnabled' ] ) ; return this . isSlideAnimationEnabled ( ) ; } public isSlideAnimationEnabled ( ) { return this . slideAnimation_ ; } public getClassesPrefix ( ) { return this . classesPrefix_ ; } public isCloseButtonShown ( ) { return this . hideOnBlur_ && this . showCloseButton_ ; } public isClosedOnEscPress ( ) { return this . hideOnBlur_ && this . closeOnEscPress_ ; } public getTitle ( ) { return this . title_ ; } public getMinDate ( ) { return this . minDate_ ? new Date ( this . minDate_ . getTime ( ) ) : null ; } public getMaxDate ( ) { return this . maxDate_ ? new Date ( this . maxDate_ . getTime ( ) ) : null ; } public getMinDate_ ( ) { const minDate = this . getMinDate ( ) ; if ( ! minDate ) { return new Date ( - 271821 , 4 , 1 ) ; } return minDate ; } public getMaxDate_ ( ) { const maxDate = this . getMaxDate ( ) ; if ( ! maxDate ) { return new Date ( 275760 , 7 , 31 ) ; } return maxDate ; } public getMinMonth ( ) { if ( ! this . minDate_ ) { return null ; } const minMonth = new Date ( this . minDate_ . getTime ( ) ) ; minMonth . setDate ( 1 ) ; return minMonth ; } public getMaxMonth ( ) { if ( ! this . maxDate_ ) { return null ; } const maxMonth = new Date ( this . maxDate_ . getTime ( ) ) ; maxMonth . setDate ( 1 ) ; return maxMonth ; } public getMinMonth_ ( ) { let minMonth = this . getMinMonth ( ) ; if ( ! minMonth ) { minMonth = this . getMinDate_ ( ) ; } return minMonth ; } public getMaxMonth_ ( ) { let maxMonth = this . getMaxMonth ( ) ; if ( ! maxMonth ) { maxMonth = this . getMaxDate_ ( ) ; maxMonth . setDate ( 1 ) ; } return maxMonth ; } public isDropdownWithOneItemHidden ( ) { return this . hideDropdownWithOneItem_ ; } public getDropdownItemsLimit ( ) { return this . dropdownItemsLimit_ ; } public isDateAvailable ( date ) { const dateAvailabilityResolvers = this . dateAvailabilityResolvers_ . slice ( 0 ) ; for ( let index = 0 ; index < dateAvailabilityResolvers . length ; index ++ ) { if ( ! dateAvailabilityResolvers [ index ] ( new Date ( date . getTime ( ) ) ) ) { return false ; } } return true ; } public getCellContent ( day ) { if ( this . cellContentResolver_ ) { return this . cellContentResolver_ ( day ) ; } return day . dayNumber + '' ; } public prefixClass_ ( name ) { return this . classesPrefix_ + name ; } public getCellStructure_ ( ) { if ( this . cellContentStructureResolver_ ) { return this . cellContentStructureResolver_ . init ( ) ; } return HtmlHelper_ . createSpan_ ( ) ; } public updateCellStructure_ ( element , day ) { if ( this . cellContentStructureResolver_ ) { this . cellContentStructureResolver_ . update ( element , day ) ; } else { element . innerText = this . getCellContent ( day ) ; } } public getHeaderStructure_ ( ) { return this . headerStructureResolver_ ? this . headerStructureResolver_ ( ) : null ; } public getFooterStructure_ ( ) { return this . footerStructureResolver_ ? this . footerStructureResolver_ ( ) : null ; } public getCellClasses ( day ) { let result = [ ] ; const cellClassesResolvers = this . cellClassesResolvers_ . slice ( 0 ) ; for ( let index = 0 ; index < cellClassesResolvers . length ; index ++ ) { const classes = cellClassesResolvers [ index ] ( day ) ; if ( typeof classes === 'string' ) { result . push ( classes ) ; } else if ( typeof classes === 'object' && classes . constructor === Array ) { result = result . concat ( classes ) ; } } return result ; } public modifyDay ( day ) { const dayModifiers = this . dayModifiers_ . slice ( 0 ) ; for ( let index = 0 ; index < dayModifiers . length ; index ++ ) { dayModifiers [ index ] ( day ) ; } } public getGoBackHtml ( ) { return this . goBackHtml_ ; } public getGoForwardHtml ( ) { return this . goForwardHtml_ ; } public getCloseHtml ( ) { return this . closeHtml_ ; } public getResetHtml ( ) { return this . resetHtml_ ; } public getDeselectHtml ( ) { return this . deselectHtml_ ; } public isHiddenOnBlur ( ) { return this . hideOnBlur_ ; } public isHiddenOnSelect ( ) { return this . hideOnBlur_ && this . hideOnSelect_ ; } public getInputFormat ( ) { return this . inputFormat_ ; } public isAllowedInputAnyChar ( ) { return this . allowInputAnyChar_ ; } public isPositionFixingEnabled ( ) { return this . hideOnBlur_ && this . positionFixing_ ; } public isFullScreenOnMobile ( ) { return this . hideOnBlur_ && this . fullScreenOnMobile_ ; } public isKeyboardOnMobile ( ) { return this . keyboardOnMobile_ ; } public isAriaIncluded ( ) { return this . includeAria_ ; } public getToday ( ) { return this . today_ ? new Date ( this . today_ . getTime ( ) ) : Helper_ . resetTime_ ( new Date ( ) ) ; } public getDateAvailabilityResolver ( ) { Helper_ . warnDeprecatedUsage_ ( 'getDateAvailabilityResolver' , [ 'getDateAvailabilityResolvers' ] ) ; return this . dateAvailabilityResolvers_ . length > 0 ? this . dateAvailabilityResolvers_ [ 0 ] : null ; } public getDateAvailabilityResolvers ( ) { return this . dateAvailabilityResolvers_ . slice ( 0 ) ; } public getCellContentResolver ( ) { return this . cellContentResolver_ ; } public getCellContentStructureResolver ( ) { return this . cellContentStructureResolver_ ; } public getHeaderStructureResolver ( ) { return this . headerStructureResolver_ ; } public getFooterStructureResolver ( ) { return this . footerStructureResolver_ ; } public getCellClassesResolvers ( ) { return this . cellClassesResolvers_ . slice ( 0 ) ; } public getDayModifiers ( ) { return this . dayModifiers_ . slice ( 0 ) ; } public getBeforeSelectListeners ( ) { return this . listeners_ . beforeSelect . slice ( 0 ) ; } public getSelectListeners ( ) { return this . listeners_ . select . slice ( 0 ) ; } public getBeforeOpenListeners ( ) { return this . listeners_ . beforeOpen . slice ( 0 ) ; } public getOpenListeners ( ) { return this . listeners_ . open . slice ( 0 ) ; } public getBeforeCloseListeners ( ) { return this . listeners_ . beforeClose . slice ( 0 ) ; } public getCloseListeners ( ) { return this . listeners_ . close . slice ( 0 ) ; } public getBeforeOpenAndCloseListeners ( ) { Helper_ . warnDeprecatedUsage_ ( 'getBeforeOpenAndCloseListeners' , [ 'getBeforeOpenListeners' , 'getBeforeCloseListeners' ] ) ; return this . listeners_ . beforeOpen . concat ( this . listeners_ . beforeClose ) ; } public getOpenAndCloseListeners ( ) { Helper_ . warnDeprecatedUsage_ ( 'getOpenAndCloseListeners' , [ 'getOpenListeners' , 'getCloseListeners' ] ) ; return this . listeners_ . open . concat ( this . listeners_ . close ) ; } public getBeforeMonthChangeListeners ( ) { return this . listeners_ . beforeMonthChange . slice ( 0 ) ; } public getMonthChangeListeners ( ) { return this . listeners_ . monthChange . slice ( 0 ) ; } public getBeforeFocusListeners ( ) { return this . listeners_ . beforeFocus . slice ( 0 ) ; } public getFocusListeners ( ) { return this . listeners_ . focus . slice ( 0 ) ; } private checkConstraints_ ( minDate , maxDate ) { if ( minDate && maxDate && minDate . getTime ( ) > maxDate . getTime ( ) ) { throw new Error ( 'Min date cannot be higher then max date.' ) ; } } private calculateMonthCorrection_ ( month ) { const minMonth = this . getMinMonth_ ( ) ; if ( month . getTime ( ) < minMonth . getTime ( ) ) { return minMonth ; } const maxMonth = this . getMaxMonth_ ( ) ; if ( month . getTime ( ) > maxMonth . getTime ( ) ) { return maxMonth ; } return null ; } private calculateDateCorrection_ ( date ) { const minDate = this . getMinDate_ ( ) ; if ( date . getTime ( ) < minDate . getTime ( ) ) { return minDate ; } const maxDate = this . getMaxDate_ ( ) ; if ( date . getTime ( ) > maxDate . getTime ( ) ) { return maxDate ; } return null ; } private removeCallback_ < Type extends Function > ( callbacksList , parameterName , callback ) { callback = Helper_ . checkFunction_ ( parameterName , callback ) ; if ( ! callback ) { callbacksList . splice ( 0 , callbacksList . length ) ; } else { const callbacks = callbacksList . slice ( 0 ) ; for ( let index = callbacks . length - 1 ; index >= 0 ; index -- ) { if ( callbacks [ index ] === callback ) { callbacksList . splice ( index , 1 ) ; } } } } private onEvent_ ( eventType , listener ) { this . listeners_ [ eventType ] . push ( Helper_ . checkFunction_ ( 'Event listener' , listener , false ) ) ; } private offEvent_ ( eventType , listener ) { listener = Helper_ . checkFunction_ ( 'Event listener' , listener ) ; if ( ! listener ) { this . listeners_ [ eventType ] = [ ] ; } else { const newListeners = [ ] ; for ( let index = 0 ; index < this . listeners_ [ eventType ] . length ; index ++ ) { if ( this . listeners_ [ eventType ] [ index ] !== listener ) { newListeners . push ( this . listeners_ [ eventType ] [ index ] ) ; } } this . listeners_ [ eventType ] = newListeners as AnyListener [ ] ; } } public triggerEvent_ ( eventType , caller ) { const listeners = this . listeners_ [ eventType ] . slice ( 0 ) ; for ( let index = 0 ; index < listeners . length ; index ++ ) { if ( caller ( listeners [ index ] ) === false ) { return false ; } } return true ; } } }