@@ -151,17 +151,17 @@ export interface DatepickerOptions extends BaseOptions {
151
151
onDraw : ( ( ) => void ) | null ;
152
152
153
153
/** Field used for internal calculations DO NOT CHANGE IT */
154
- minYear ?: any ;
154
+ minYear ?: number ;
155
155
/** Field used for internal calculations DO NOT CHANGE IT */
156
- maxYear ?: any ;
156
+ maxYear ?: number ;
157
157
/** Field used for internal calculations DO NOT CHANGE IT */
158
- minMonth ?: any ;
158
+ minMonth ?: number ;
159
159
/** Field used for internal calculations DO NOT CHANGE IT */
160
- maxMonth ?: any ;
160
+ maxMonth ?: number ;
161
161
/** Field used for internal calculations DO NOT CHANGE IT */
162
- startRange ?: any ;
162
+ startRange ?: Date ;
163
163
/** Field used for internal calculations DO NOT CHANGE IT */
164
- endRange ?: any ;
164
+ endRange ?: Date ;
165
165
}
166
166
167
167
let _defaults : DatepickerOptions = {
@@ -276,10 +276,10 @@ export class Datepicker extends Component<DatepickerOptions> {
276
276
/** The selected Date. */
277
277
date : Date ;
278
278
endDate : null | Date ;
279
- formats : any ;
280
- calendars : any ;
281
- private _y : any ;
282
- private _m : any ;
279
+ formats : object ;
280
+ calendars : [ { month : number ; year : number } ] ;
281
+ private _y : number ;
282
+ private _m : number ;
283
283
static _template : string ;
284
284
285
285
constructor ( el : HTMLInputElement , options : Partial < DatepickerOptions > ) {
@@ -645,15 +645,14 @@ export class Datepicker extends Component<DatepickerOptions> {
645
645
}
646
646
647
647
render ( year , month , randId ) {
648
- let opts = this . options ,
649
- now = new Date ( ) ,
648
+ const now = new Date ( ) ,
650
649
days = Datepicker . _getDaysInMonth ( year , month ) ,
651
- before = new Date ( year , month , 1 ) . getDay ( ) ,
652
- data = [ ] ,
650
+ data = [ ] ;
651
+ let before = new Date ( year , month , 1 ) . getDay ( ) ,
653
652
row = [ ] ;
654
653
Datepicker . _setToStartOfDay ( now ) ;
655
- if ( opts . firstDay > 0 ) {
656
- before -= opts . firstDay ;
654
+ if ( this . options . firstDay > 0 ) {
655
+ before -= this . options . firstDay ;
657
656
if ( before < 0 ) {
658
657
before += 7 ;
659
658
}
@@ -671,23 +670,23 @@ export class Datepicker extends Component<DatepickerOptions> {
671
670
cells += 7 - after ;
672
671
let isWeekSelected = false ;
673
672
for ( let i = 0 , r = 0 ; i < cells ; i ++ ) {
674
- let day = new Date ( year , month , 1 + ( i - before ) ) ,
673
+ const day = new Date ( year , month , 1 + ( i - before ) ) ,
675
674
isToday = Datepicker . _compareDates ( day , now ) ,
676
- hasEvent = opts . events . indexOf ( day . toDateString ( ) ) !== - 1 ,
675
+ hasEvent = this . options . events . indexOf ( day . toDateString ( ) ) !== - 1 ,
677
676
isEmpty = i < before || i >= days + before ,
678
- dayNumber = 1 + ( i - before ) ,
679
- monthNumber = month ,
680
- yearNumber = year ,
681
- isStartRange = opts . startRange && Datepicker . _compareDates ( opts . startRange , day ) ,
682
- isEndRange = opts . endRange && Datepicker . _compareDates ( opts . endRange , day ) ,
677
+ isStartRange = this . options . startRange && Datepicker . _compareDates ( this . options . startRange , day ) ,
678
+ isEndRange = this . options . endRange && Datepicker . _compareDates ( this . options . endRange , day ) ,
683
679
isInRange =
684
- opts . startRange && opts . endRange && opts . startRange < day && day < opts . endRange ,
680
+ this . options . startRange && this . options . endRange && this . options . startRange < day && day < this . options . endRange ,
685
681
isDisabled =
686
- ( opts . minDate && day < opts . minDate ) ||
687
- ( opts . maxDate && day > opts . maxDate ) ||
688
- ( opts . disableWeekends && Datepicker . _isWeekend ( day ) ) ||
689
- ( opts . disableDayFn && opts . disableDayFn ( day ) ) ,
690
- isDateRange = opts . isDateRange && Datepicker . _isDate ( this . endDate ) && Datepicker . _compareWithinRange ( day , this . date , this . endDate ) ;
682
+ ( this . options . minDate && day < this . options . minDate ) ||
683
+ ( this . options . maxDate && day > this . options . maxDate ) ||
684
+ ( this . options . disableWeekends && Datepicker . _isWeekend ( day ) ) ||
685
+ ( this . options . disableDayFn && this . options . disableDayFn ( day ) ) ,
686
+ isDateRange = this . options . isDateRange && Datepicker . _isDate ( this . endDate ) && Datepicker . _compareWithinRange ( day , this . date , this . endDate ) ;
687
+ let dayNumber = 1 + ( i - before ) ,
688
+ monthNumber = month ,
689
+ yearNumber = year ;
691
690
692
691
let isSelected = false ;
693
692
if ( Datepicker . _isDate ( this . date ) ) {
@@ -722,20 +721,20 @@ export class Datepicker extends Component<DatepickerOptions> {
722
721
isStartRange : isStartRange ,
723
722
isEndRange : isEndRange ,
724
723
isInRange : isInRange ,
725
- showDaysInNextAndPreviousMonths : opts . showDaysInNextAndPreviousMonths ,
724
+ showDaysInNextAndPreviousMonths : this . options . showDaysInNextAndPreviousMonths ,
726
725
isDateRange : isDateRange ,
727
726
} ;
728
727
729
728
row . push ( this . renderDay ( dayConfig ) ) ;
730
729
731
730
if ( ++ r === 7 ) {
732
- data . push ( this . renderRow ( row , opts . isRTL , isWeekSelected ) ) ;
731
+ data . push ( this . renderRow ( row , this . options . isRTL , isWeekSelected ) ) ;
733
732
row = [ ] ;
734
733
r = 0 ;
735
734
isWeekSelected = false ;
736
735
}
737
736
}
738
- return this . renderTable ( opts , data , randId ) ;
737
+ return this . renderTable ( this . options , data , randId ) ;
739
738
}
740
739
741
740
renderDay ( opts ) {
@@ -749,29 +748,42 @@ export class Datepicker extends Component<DatepickerOptions> {
749
748
return '<td class="is-empty"></td>' ;
750
749
}
751
750
}
751
+
752
+ // @todo wouldn't it be better defining opts class mapping and looping trough opts?
752
753
if ( opts . isDisabled ) {
753
754
arr . push ( 'is-disabled' ) ;
754
755
}
755
756
756
757
if ( opts . isToday ) {
757
758
arr . push ( 'is-today' ) ;
758
759
}
760
+
759
761
if ( opts . isSelected ) {
760
762
arr . push ( 'is-selected' ) ;
761
763
ariaSelected = 'true' ;
762
764
}
765
+
766
+ // @todo should we create this additional css class?
763
767
if ( opts . hasEvent ) {
764
768
arr . push ( 'has-event' ) ;
765
769
}
770
+
771
+ // @todo should we create this additional css class?
766
772
if ( opts . isInRange ) {
767
773
arr . push ( 'is-inrange' ) ;
768
774
}
775
+
776
+ // @todo should we create this additional css class?
769
777
if ( opts . isStartRange ) {
770
778
arr . push ( 'is-startrange' ) ;
771
779
}
780
+
781
+ // @todo should we create this additional css class?
772
782
if ( opts . isEndRange ) {
773
783
arr . push ( 'is-endrange' ) ;
774
784
}
785
+
786
+ // @todo create additional css class
775
787
if ( opts . isDateRange ) {
776
788
arr . push ( 'is-daterange' ) ;
777
789
}
@@ -804,8 +816,8 @@ export class Datepicker extends Component<DatepickerOptions> {
804
816
}
805
817
806
818
renderHead ( opts ) {
807
- let i ,
808
- arr = [ ] ;
819
+ const arr = [ ] ;
820
+ let i
809
821
for ( i = 0 ; i < 7 ; i ++ ) {
810
822
arr . push (
811
823
`<th scope="col"><abbr title="${ this . renderDayName ( opts , i ) } ">${ this . renderDayName (
@@ -823,22 +835,20 @@ export class Datepicker extends Component<DatepickerOptions> {
823
835
}
824
836
825
837
renderTitle ( instance , c , year , month , refYear , randId ) {
838
+ const opts = this . options ,
839
+ isMinYear = year === opts . minYear ,
840
+ isMaxYear = year === opts . maxYear ;
826
841
let i ,
827
842
j ,
828
- arr ,
829
- opts = this . options ,
830
- isMinYear = year === opts . minYear ,
831
- isMaxYear = year === opts . maxYear ,
843
+ arr = [ ] ,
832
844
html =
833
845
'<div id="' +
834
846
randId +
835
847
'" class="datepicker-controls" role="heading" aria-live="assertive">' ,
836
- monthHtml ,
837
- yearHtml ,
838
848
prev = true ,
839
849
next = true ;
840
850
841
- for ( arr = [ ] , i = 0 ; i < 12 ; i ++ ) {
851
+ for ( i = 0 ; i < 12 ; i ++ ) {
842
852
arr . push (
843
853
'<option value="' +
844
854
( year === refYear ? i - c : 12 + i - c ) +
@@ -853,7 +863,7 @@ export class Datepicker extends Component<DatepickerOptions> {
853
863
) ;
854
864
}
855
865
856
- monthHtml = '<select class="datepicker-select orig-select-month" tabindex="-1">' + arr . join ( '' ) + '</select>' ;
866
+ const monthHtml = '<select class="datepicker-select orig-select-month" tabindex="-1">' + arr . join ( '' ) + '</select>' ;
857
867
858
868
if ( Array . isArray ( opts . yearRange ) ) {
859
869
i = opts . yearRange [ 0 ] ;
@@ -871,7 +881,7 @@ export class Datepicker extends Component<DatepickerOptions> {
871
881
}
872
882
if ( opts . yearRangeReverse ) arr . reverse ( ) ;
873
883
874
- yearHtml = `<select class="datepicker-select orig-select-year" tabindex="-1">${ arr . join ( '' ) } </select>` ;
884
+ const yearHtml = `<select class="datepicker-select orig-select-year" tabindex="-1">${ arr . join ( '' ) } </select>` ;
875
885
876
886
let leftArrow =
877
887
'<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M15.41 16.09l-4.58-4.59 4.58-4.59L14 5.5l-6 6 6 6z"/><path d="M0-.5h24v24H0z" fill="none"/></svg>' ;
@@ -907,13 +917,12 @@ export class Datepicker extends Component<DatepickerOptions> {
907
917
// refresh HTML
908
918
draw ( force : boolean = false ) {
909
919
if ( ! this . isOpen && ! force ) return ;
910
- let opts = this . options ,
920
+ const opts = this . options ,
911
921
minYear = opts . minYear ,
912
922
maxYear = opts . maxYear ,
913
923
minMonth = opts . minMonth ,
914
- maxMonth = opts . maxMonth ,
915
- html = '' ,
916
- randId ;
924
+ maxMonth = opts . maxMonth ;
925
+ let html = '' ;
917
926
918
927
if ( this . _y <= minYear ) {
919
928
this . _y = minYear ;
@@ -928,7 +937,7 @@ export class Datepicker extends Component<DatepickerOptions> {
928
937
}
929
938
}
930
939
931
- randId =
940
+ const randId =
932
941
'datepicker-title-' +
933
942
Math . random ( )
934
943
. toString ( 36 )
0 commit comments