@@ -31,53 +31,57 @@ export default function DateSelectorComposer(month, year) {
31
31
this . $yearSelector = this . selected . get ( 'year-selector' ) ;
32
32
this . modalControl = new ModalController ( this ) ;
33
33
34
- this . mountSelectors = ( ) => {
35
- if ( this . yearSelector ) this . yearSelector . unmount ( ) ;
36
- if ( this . yearSelected ) this . yearSelected . unmount ( ) ;
34
+ const mountMobileSelectors = ( ) => {
37
35
if ( this . monthSelector ) this . monthSelector . unmount ( ) ;
38
- if ( this . monthSelected ) this . monthSelected . unmount ( ) ;
36
+ if ( this . yearSelector ) this . yearSelector . unmount ( ) ;
39
37
40
- this . yearArray = yearArrayGenerator ( this . year ) ;
41
38
this . monthArray = monthArrayGenerator ( this . month ) ;
39
+ this . yearArray = yearArrayGenerator ( this . year ) ;
42
40
43
- this . yearSelector = new YearSelector ( this . yearArray , 75 ) ;
44
- this . yearSelector . listen ( 'year:change' , ( newYear ) =>
45
- this . emit ( 'year:change' , newYear ) ,
41
+ this . monthSelector = new MonthSelector ( this . monthArray ) ;
42
+ this . monthSelector . mount ( this . $monthSelector ) ;
43
+ this . monthSelector . listen ( 'month:change' , ( newMonth ) =>
44
+ this . setMonth ( newMonth ) ,
46
45
) ;
47
46
48
- this . yearSelected = new DateSelected ( this . year ) ;
49
- this . yearSelected . listen ( 'item:click' , ( ) =>
50
- this . modalControl . Open ( this . yearArray ) ,
51
- ) ;
47
+ this . yearSelector = new YearSelector ( this . yearArray ) ;
48
+ this . yearSelector . mount ( this . $yearSelector ) ;
49
+ this . yearSelector . listen ( 'year:change' , ( newYear ) => this . setYear ( newYear ) ) ;
50
+ } ;
52
51
53
- this . monthSelector = new MonthSelector ( this . monthArray , 120 ) ;
54
- this . monthSelector . listen ( 'month:change' , ( newMonth ) =>
55
- this . emit ( 'month:change' , newMonth ) ,
56
- ) ;
52
+ const mountDesktopSelectors = ( ) => {
53
+ if ( this . monthSelected ) this . monthSelected . unmount ( ) ;
54
+ if ( this . yearSelected ) this . yearSelected . unmount ( ) ;
55
+
56
+ this . monthArray = monthArrayGenerator ( this . month ) ;
57
+ this . yearArray = yearArrayGenerator ( this . year ) ;
57
58
58
59
this . monthSelected = new DateSelected ( MONTHS [ this . month ] ) ;
60
+ this . monthSelected . mount ( this . $monthSelector ) ;
59
61
this . monthSelected . listen ( 'item:click' , ( ) =>
60
62
this . modalControl . Open ( this . monthArray ) ,
61
63
) ;
62
64
63
- listenBreakpoint ( 'from667' , ( matches ) => {
64
- if ( matches ) {
65
- this . monthSelector . unmount ( ) ;
66
- this . yearSelector . unmount ( ) ;
67
-
68
- this . monthSelected . mount ( this . $monthSelector ) ;
69
- this . yearSelected . mount ( this . $yearSelector ) ;
70
- } else {
71
- this . yearSelected . unmount ( ) ;
72
- this . monthSelected . unmount ( ) ;
73
-
74
- this . yearSelector . mount ( this . $yearSelector ) ;
75
- this . monthSelector . mount ( this . $monthSelector ) ;
76
- }
77
- } ) ;
65
+ this . yearSelected = new DateSelected ( this . year ) ;
66
+ this . yearSelected . mount ( this . $yearSelector ) ;
67
+ this . yearSelected . listen ( 'item:click' , ( ) =>
68
+ this . modalControl . Open ( this . yearArray ) ,
69
+ ) ;
78
70
} ;
79
71
80
- this . mountSelectors ( ) ;
72
+ listenBreakpoint ( 'from667' , ( matches ) => {
73
+ if ( matches ) {
74
+ if ( this . monthSelector ) this . monthSelector . unmount ( ) ;
75
+ if ( this . yearSelector ) this . yearSelector . unmount ( ) ;
76
+
77
+ mountDesktopSelectors ( ) ;
78
+ } else {
79
+ if ( this . monthSelected ) this . monthSelected . unmount ( ) ;
80
+ if ( this . yearSelected ) this . yearSelected . unmount ( ) ;
81
+
82
+ mountMobileSelectors ( ) ;
83
+ }
84
+ } ) ;
81
85
82
86
window . addEventListener ( 'click' , ( event ) =>
83
87
this . modalControl . CloseOnClickOutside ( event ) ,
@@ -89,14 +93,16 @@ DateSelectorComposer.prototype = Object.assign(
89
93
Component . prototype ,
90
94
{
91
95
setMonth ( month ) {
96
+ if ( this . monthSelected ) this . monthSelected . setDate ( MONTHS [ month ] ) ;
97
+
92
98
this . month = month ;
93
- this . mountSelectors ( ) ;
94
99
this . emit ( 'month:change' , month ) ;
95
100
} ,
96
101
97
102
setYear ( year ) {
103
+ if ( this . yearSelected ) this . yearSelected . setDate ( year ) ;
104
+
98
105
this . year = year ;
99
- this . mountSelectors ( ) ;
100
106
this . emit ( 'year:change' , year ) ;
101
107
} ,
102
108
} ,
0 commit comments